blob: 6873450fc2e6b8c094f991b78e8e8823b6f05d13 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- CommandObjectRegister.cpp -------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "CommandObjectRegister.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/Core/DataExtractor.h"
Greg Clayton061b79d2011-05-09 20:18:18 +000017#include "lldb/Core/RegisterValue.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/Core/Scalar.h"
Greg Clayton63094e02010-06-23 01:19:29 +000019#include "lldb/Core/Debugger.h"
20#include "lldb/Interpreter/Args.h"
21#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Interpreter/CommandReturnObject.h"
Greg Claytonf15996e2011-04-07 22:46:35 +000023#include "lldb/Interpreter/Options.h"
Greg Claytona42880a2011-10-25 06:44:01 +000024#include "lldb/Interpreter/OptionGroupFormat.h"
Greg Clayton73844aa2012-08-22 17:17:09 +000025#include "lldb/Interpreter/OptionValueArray.h"
26#include "lldb/Interpreter/OptionValueUInt64.h"
Chris Lattner24943d22010-06-08 16:52:24 +000027#include "lldb/Target/ExecutionContext.h"
Greg Clayton55794852011-05-05 02:16:20 +000028#include "lldb/Target/Process.h"
Chris Lattner24943d22010-06-08 16:52:24 +000029#include "lldb/Target/RegisterContext.h"
Greg Clayton55794852011-05-05 02:16:20 +000030#include "lldb/Target/Thread.h"
Chris Lattner24943d22010-06-08 16:52:24 +000031
32using namespace lldb;
33using namespace lldb_private;
34
35//----------------------------------------------------------------------
36// "register read"
37//----------------------------------------------------------------------
Jim Inghamda26bd22012-06-08 21:56:10 +000038class CommandObjectRegisterRead : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +000039{
40public:
Greg Clayton238c0a12010-09-18 01:14:36 +000041 CommandObjectRegisterRead (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +000042 CommandObjectParsed (interpreter,
43 "register read",
44 "Dump the contents of one or more register values from the current frame. If no register is specified, dumps them all.",
45 NULL,
46 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
Greg Claytona42880a2011-10-25 06:44:01 +000047 m_option_group (interpreter),
48 m_format_options (eFormatDefault),
49 m_command_options ()
Chris Lattner24943d22010-06-08 16:52:24 +000050 {
Caroline Tice43b014a2010-10-04 22:28:36 +000051 CommandArgumentEntry arg;
52 CommandArgumentData register_arg;
53
54 // Define the first (and only) variant of this arg.
55 register_arg.arg_type = eArgTypeRegisterName;
56 register_arg.arg_repetition = eArgRepeatStar;
57
58 // There is only one variant this argument could be; put it into the argument entry.
59 arg.push_back (register_arg);
60
61 // Push the data for the first argument into the m_arguments vector.
62 m_arguments.push_back (arg);
Greg Claytona42880a2011-10-25 06:44:01 +000063
64 // Add the "--format"
Greg Clayton24a6bd92011-10-27 17:55:14 +000065 m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT | OptionGroupFormat::OPTION_GROUP_GDB_FMT, LLDB_OPT_SET_ALL);
Greg Claytona42880a2011-10-25 06:44:01 +000066 m_option_group.Append (&m_command_options);
67 m_option_group.Finalize();
68
Chris Lattner24943d22010-06-08 16:52:24 +000069 }
70
71 virtual
72 ~CommandObjectRegisterRead ()
73 {
74 }
75
Greg Clayton24bc5d92011-03-30 18:16:51 +000076 Options *
77 GetOptions ()
78 {
Greg Claytona42880a2011-10-25 06:44:01 +000079 return &m_option_group;
Greg Clayton24bc5d92011-03-30 18:16:51 +000080 }
81
Greg Clayton17cd9952011-04-22 03:55:06 +000082 bool
83 DumpRegister (const ExecutionContext &exe_ctx,
84 Stream &strm,
85 RegisterContext *reg_ctx,
86 const RegisterInfo *reg_info)
87 {
88 if (reg_info)
89 {
Greg Clayton061b79d2011-05-09 20:18:18 +000090 RegisterValue reg_value;
Greg Clayton17cd9952011-04-22 03:55:06 +000091
Greg Clayton061b79d2011-05-09 20:18:18 +000092 if (reg_ctx->ReadRegister (reg_info, reg_value))
Greg Clayton17cd9952011-04-22 03:55:06 +000093 {
94 strm.Indent ();
Greg Clayton17cd9952011-04-22 03:55:06 +000095
Greg Claytona42880a2011-10-25 06:44:01 +000096 bool prefix_with_altname = m_command_options.alternate_name;
Greg Clayton997b1e82011-05-15 04:12:07 +000097 bool prefix_with_name = !prefix_with_altname;
Johnny Chen9d0f5082012-06-05 23:25:10 +000098 reg_value.Dump(&strm, reg_info, prefix_with_name, prefix_with_altname, m_format_options.GetFormat(), 8);
Greg Claytonf4124de2012-02-21 00:09:25 +000099 if ((reg_info->encoding == eEncodingUint) || (reg_info->encoding == eEncodingSint))
Greg Clayton17cd9952011-04-22 03:55:06 +0000100 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000101 Process *process = exe_ctx.GetProcessPtr();
102 if (process && reg_info->byte_size == process->GetAddressByteSize())
Greg Clayton17cd9952011-04-22 03:55:06 +0000103 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000104 addr_t reg_addr = reg_value.GetAsUInt64(LLDB_INVALID_ADDRESS);
105 if (reg_addr != LLDB_INVALID_ADDRESS)
Greg Clayton17cd9952011-04-22 03:55:06 +0000106 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000107 Address so_reg_addr;
108 if (exe_ctx.GetTargetRef().GetSectionLoadList().ResolveLoadAddress(reg_addr, so_reg_addr))
109 {
110 strm.PutCString (" ");
111 so_reg_addr.Dump(&strm, exe_ctx.GetBestExecutionContextScope(), Address::DumpStyleResolvedDescription);
112 }
Greg Clayton17cd9952011-04-22 03:55:06 +0000113 }
Greg Clayton17cd9952011-04-22 03:55:06 +0000114 }
115 }
116 strm.EOL();
117 return true;
118 }
119 }
120 return false;
121 }
122
123 bool
124 DumpRegisterSet (const ExecutionContext &exe_ctx,
125 Stream &strm,
126 RegisterContext *reg_ctx,
Johnny Chen35f5dc72012-05-29 21:55:08 +0000127 uint32_t set_idx,
128 bool primitive_only=false)
Greg Clayton17cd9952011-04-22 03:55:06 +0000129 {
130 uint32_t unavailable_count = 0;
131 uint32_t available_count = 0;
132 const RegisterSet * const reg_set = reg_ctx->GetRegisterSet(set_idx);
133 if (reg_set)
134 {
135 strm.Printf ("%s:\n", reg_set->name);
136 strm.IndentMore ();
137 const uint32_t num_registers = reg_set->num_registers;
138 for (uint32_t reg_idx = 0; reg_idx < num_registers; ++reg_idx)
139 {
140 const uint32_t reg = reg_set->registers[reg_idx];
Johnny Chen35f5dc72012-05-29 21:55:08 +0000141 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg);
142 // Skip the dumping of derived register if primitive_only is true.
143 if (primitive_only && reg_info && reg_info->value_regs)
144 continue;
145 if (DumpRegister (exe_ctx, strm, reg_ctx, reg_info))
Greg Clayton17cd9952011-04-22 03:55:06 +0000146 ++available_count;
147 else
148 ++unavailable_count;
149 }
150 strm.IndentLess ();
151 if (unavailable_count)
152 {
153 strm.Indent ();
154 strm.Printf("%u registers were unavailable.\n", unavailable_count);
155 }
156 strm.EOL();
157 }
158 return available_count > 0;
159 }
160
Jim Inghamda26bd22012-06-08 21:56:10 +0000161protected:
Chris Lattner24943d22010-06-08 16:52:24 +0000162 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000163 DoExecute (Args& command, CommandReturnObject &result)
Chris Lattner24943d22010-06-08 16:52:24 +0000164 {
Greg Clayton17cd9952011-04-22 03:55:06 +0000165 Stream &strm = result.GetOutputStream();
Greg Claytonb72d0f02011-04-12 05:54:46 +0000166 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Greg Clayton17cd9952011-04-22 03:55:06 +0000167 RegisterContext *reg_ctx = exe_ctx.GetRegisterContext ();
Chris Lattner24943d22010-06-08 16:52:24 +0000168
Greg Clayton17cd9952011-04-22 03:55:06 +0000169 if (reg_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +0000170 {
171 const RegisterInfo *reg_info = NULL;
172 if (command.GetArgumentCount() == 0)
173 {
174 uint32_t set_idx;
Greg Clayton17cd9952011-04-22 03:55:06 +0000175
176 uint32_t num_register_sets = 1;
Greg Claytona42880a2011-10-25 06:44:01 +0000177 const uint32_t set_array_size = m_command_options.set_indexes.GetSize();
Greg Clayton17cd9952011-04-22 03:55:06 +0000178 if (set_array_size > 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000179 {
Greg Clayton17cd9952011-04-22 03:55:06 +0000180 for (uint32_t i=0; i<set_array_size; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000181 {
Greg Claytona42880a2011-10-25 06:44:01 +0000182 set_idx = m_command_options.set_indexes[i]->GetUInt64Value (UINT32_MAX, NULL);
Greg Clayton17cd9952011-04-22 03:55:06 +0000183 if (set_idx != UINT32_MAX)
Chris Lattner24943d22010-06-08 16:52:24 +0000184 {
Greg Clayton17cd9952011-04-22 03:55:06 +0000185 if (!DumpRegisterSet (exe_ctx, strm, reg_ctx, set_idx))
186 {
187 result.AppendErrorWithFormat ("invalid register set index: %u\n", set_idx);
188 result.SetStatus (eReturnStatusFailed);
189 break;
190 }
Chris Lattner24943d22010-06-08 16:52:24 +0000191 }
192 else
193 {
Greg Clayton17cd9952011-04-22 03:55:06 +0000194 result.AppendError ("invalid register set index\n");
195 result.SetStatus (eReturnStatusFailed);
196 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000197 }
198 }
Greg Clayton17cd9952011-04-22 03:55:06 +0000199 }
200 else
201 {
Greg Claytona42880a2011-10-25 06:44:01 +0000202 if (m_command_options.dump_all_sets)
Greg Clayton17cd9952011-04-22 03:55:06 +0000203 num_register_sets = reg_ctx->GetRegisterSetCount();
204
205 for (set_idx = 0; set_idx < num_register_sets; ++set_idx)
Chris Lattner24943d22010-06-08 16:52:24 +0000206 {
Johnny Chen35f5dc72012-05-29 21:55:08 +0000207 // When dump_all_sets option is set, dump primitive as well as derived registers.
208 DumpRegisterSet (exe_ctx, strm, reg_ctx, set_idx, !m_command_options.dump_all_sets.GetCurrentValue());
Chris Lattner24943d22010-06-08 16:52:24 +0000209 }
Chris Lattner24943d22010-06-08 16:52:24 +0000210 }
211 }
212 else
213 {
Greg Claytona42880a2011-10-25 06:44:01 +0000214 if (m_command_options.dump_all_sets)
Chris Lattner24943d22010-06-08 16:52:24 +0000215 {
Greg Clayton17cd9952011-04-22 03:55:06 +0000216 result.AppendError ("the --all option can't be used when registers names are supplied as arguments\n");
217 result.SetStatus (eReturnStatusFailed);
218 }
Greg Claytona42880a2011-10-25 06:44:01 +0000219 else if (m_command_options.set_indexes.GetSize() > 0)
Greg Clayton17cd9952011-04-22 03:55:06 +0000220 {
221 result.AppendError ("the --set <set> option can't be used when registers names are supplied as arguments\n");
222 result.SetStatus (eReturnStatusFailed);
223 }
224 else
225 {
226 const char *arg_cstr;
227 for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx)
Chris Lattner24943d22010-06-08 16:52:24 +0000228 {
Greg Clayton17cd9952011-04-22 03:55:06 +0000229 reg_info = reg_ctx->GetRegisterInfoByName(arg_cstr);
230
231 if (reg_info)
Chris Lattner24943d22010-06-08 16:52:24 +0000232 {
Greg Clayton17cd9952011-04-22 03:55:06 +0000233 if (!DumpRegister (exe_ctx, strm, reg_ctx, reg_info))
234 strm.Printf("%-12s = error: unavailable\n", reg_info->name);
Chris Lattner24943d22010-06-08 16:52:24 +0000235 }
236 else
237 {
Greg Clayton17cd9952011-04-22 03:55:06 +0000238 result.AppendErrorWithFormat ("Invalid register name '%s'.\n", arg_cstr);
Chris Lattner24943d22010-06-08 16:52:24 +0000239 }
Chris Lattner24943d22010-06-08 16:52:24 +0000240 }
241 }
242 }
243 }
244 else
245 {
246 result.AppendError ("no current frame");
247 result.SetStatus (eReturnStatusFailed);
248 }
249 return result.Succeeded();
250 }
Greg Clayton24bc5d92011-03-30 18:16:51 +0000251
Greg Claytona42880a2011-10-25 06:44:01 +0000252 class CommandOptions : public OptionGroup
Greg Clayton24bc5d92011-03-30 18:16:51 +0000253 {
254 public:
Greg Claytona42880a2011-10-25 06:44:01 +0000255 CommandOptions () :
256 OptionGroup(),
Greg Clayton17cd9952011-04-22 03:55:06 +0000257 set_indexes (OptionValue::ConvertTypeToMask (OptionValue::eTypeUInt64)),
Greg Clayton997b1e82011-05-15 04:12:07 +0000258 dump_all_sets (false, false), // Initial and default values are false
259 alternate_name (false, false)
Greg Clayton24bc5d92011-03-30 18:16:51 +0000260 {
Greg Clayton24bc5d92011-03-30 18:16:51 +0000261 }
262
263 virtual
264 ~CommandOptions ()
265 {
266 }
267
Greg Claytona42880a2011-10-25 06:44:01 +0000268
269 virtual uint32_t
270 GetNumDefinitions ();
271
272 virtual const OptionDefinition*
273 GetDefinitions ()
274 {
275 return g_option_table;
276 }
277
278 virtual void
279 OptionParsingStarting (CommandInterpreter &interpreter)
280 {
281 set_indexes.Clear();
282 dump_all_sets.Clear();
283 alternate_name.Clear();
284 }
285
Greg Clayton24bc5d92011-03-30 18:16:51 +0000286 virtual Error
Greg Claytona42880a2011-10-25 06:44:01 +0000287 SetOptionValue (CommandInterpreter &interpreter,
288 uint32_t option_idx,
289 const char *option_value)
Greg Clayton24bc5d92011-03-30 18:16:51 +0000290 {
291 Error error;
Greg Claytona42880a2011-10-25 06:44:01 +0000292 const char short_option = (char) g_option_table[option_idx].short_option;
Greg Clayton24bc5d92011-03-30 18:16:51 +0000293 switch (short_option)
294 {
Greg Clayton17cd9952011-04-22 03:55:06 +0000295 case 's':
296 {
Greg Claytona42880a2011-10-25 06:44:01 +0000297 OptionValueSP value_sp (OptionValueUInt64::Create (option_value, error));
Greg Clayton17cd9952011-04-22 03:55:06 +0000298 if (value_sp)
299 set_indexes.AppendValue (value_sp);
300 }
301 break;
302
303 case 'a':
Greg Clayton997b1e82011-05-15 04:12:07 +0000304 // When we don't use OptionValue::SetValueFromCString(const char *) to
305 // set an option value, it won't be marked as being set in the options
306 // so we make a call to let users know the value was set via option
307 dump_all_sets.SetCurrentValue (true);
308 dump_all_sets.SetOptionWasSet ();
Greg Clayton17cd9952011-04-22 03:55:06 +0000309 break;
310
Greg Clayton997b1e82011-05-15 04:12:07 +0000311 case 'A':
312 // When we don't use OptionValue::SetValueFromCString(const char *) to
313 // set an option value, it won't be marked as being set in the options
314 // so we make a call to let users know the value was set via option
315 alternate_name.SetCurrentValue (true);
316 dump_all_sets.SetOptionWasSet ();
317 break;
318
Greg Clayton24bc5d92011-03-30 18:16:51 +0000319 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000320 error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
Greg Clayton24bc5d92011-03-30 18:16:51 +0000321 break;
322 }
323 return error;
324 }
325
Greg Clayton24bc5d92011-03-30 18:16:51 +0000326 // Options table: Required for subclasses of Options.
327
Greg Claytona42880a2011-10-25 06:44:01 +0000328 static const OptionDefinition g_option_table[];
Greg Clayton24bc5d92011-03-30 18:16:51 +0000329
330 // Instance variables to hold the values for command options.
Greg Clayton17cd9952011-04-22 03:55:06 +0000331 OptionValueArray set_indexes;
332 OptionValueBoolean dump_all_sets;
Greg Clayton997b1e82011-05-15 04:12:07 +0000333 OptionValueBoolean alternate_name;
Greg Clayton24bc5d92011-03-30 18:16:51 +0000334 };
335
Greg Claytona42880a2011-10-25 06:44:01 +0000336 OptionGroupOptions m_option_group;
337 OptionGroupFormat m_format_options;
338 CommandOptions m_command_options;
Chris Lattner24943d22010-06-08 16:52:24 +0000339};
340
Johnny Chen5325ce92011-10-25 17:58:16 +0000341const OptionDefinition
Greg Clayton24bc5d92011-03-30 18:16:51 +0000342CommandObjectRegisterRead::CommandOptions::g_option_table[] =
343{
Greg Clayton997b1e82011-05-15 04:12:07 +0000344 { LLDB_OPT_SET_ALL, false, "alternate", 'A', no_argument , NULL, 0, eArgTypeNone , "Display register names using the alternate register name if there is one."},
345 { LLDB_OPT_SET_1 , false, "set" , 's', required_argument, NULL, 0, eArgTypeIndex , "Specify which register sets to dump by index."},
346 { LLDB_OPT_SET_2 , false, "all" , 'a', no_argument , NULL, 0, eArgTypeNone , "Show all register sets."},
Greg Clayton24bc5d92011-03-30 18:16:51 +0000347};
348
Greg Claytona42880a2011-10-25 06:44:01 +0000349uint32_t
350CommandObjectRegisterRead::CommandOptions::GetNumDefinitions ()
351{
352 return sizeof(g_option_table)/sizeof(OptionDefinition);
353}
Greg Clayton24bc5d92011-03-30 18:16:51 +0000354
Chris Lattner24943d22010-06-08 16:52:24 +0000355
356//----------------------------------------------------------------------
357// "register write"
358//----------------------------------------------------------------------
Jim Inghamda26bd22012-06-08 21:56:10 +0000359class CommandObjectRegisterWrite : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +0000360{
361public:
Greg Clayton238c0a12010-09-18 01:14:36 +0000362 CommandObjectRegisterWrite (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000363 CommandObjectParsed (interpreter,
364 "register write",
365 "Modify a single register value.",
366 NULL,
367 eFlagProcessMustBeLaunched | eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +0000368 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000369 CommandArgumentEntry arg1;
370 CommandArgumentEntry arg2;
371 CommandArgumentData register_arg;
372 CommandArgumentData value_arg;
373
374 // Define the first (and only) variant of this arg.
375 register_arg.arg_type = eArgTypeRegisterName;
376 register_arg.arg_repetition = eArgRepeatPlain;
377
378 // There is only one variant this argument could be; put it into the argument entry.
379 arg1.push_back (register_arg);
380
381 // Define the first (and only) variant of this arg.
382 value_arg.arg_type = eArgTypeValue;
383 value_arg.arg_repetition = eArgRepeatPlain;
384
385 // There is only one variant this argument could be; put it into the argument entry.
386 arg2.push_back (value_arg);
387
388 // Push the data for the first argument into the m_arguments vector.
389 m_arguments.push_back (arg1);
390 m_arguments.push_back (arg2);
Chris Lattner24943d22010-06-08 16:52:24 +0000391 }
392
393 virtual
394 ~CommandObjectRegisterWrite ()
395 {
396 }
397
Jim Inghamda26bd22012-06-08 21:56:10 +0000398protected:
Chris Lattner24943d22010-06-08 16:52:24 +0000399 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000400 DoExecute(Args& command, CommandReturnObject &result)
Chris Lattner24943d22010-06-08 16:52:24 +0000401 {
402 DataExtractor reg_data;
Greg Claytonb72d0f02011-04-12 05:54:46 +0000403 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Greg Clayton17cd9952011-04-22 03:55:06 +0000404 RegisterContext *reg_ctx = exe_ctx.GetRegisterContext ();
Chris Lattner24943d22010-06-08 16:52:24 +0000405
Greg Clayton17cd9952011-04-22 03:55:06 +0000406 if (reg_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +0000407 {
408 if (command.GetArgumentCount() != 2)
409 {
410 result.AppendError ("register write takes exactly 2 arguments: <reg-name> <value>");
411 result.SetStatus (eReturnStatusFailed);
412 }
413 else
414 {
415 const char *reg_name = command.GetArgumentAtIndex(0);
416 const char *value_str = command.GetArgumentAtIndex(1);
Greg Clayton17cd9952011-04-22 03:55:06 +0000417 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(reg_name);
Chris Lattner24943d22010-06-08 16:52:24 +0000418
419 if (reg_info)
420 {
Greg Clayton061b79d2011-05-09 20:18:18 +0000421 RegisterValue reg_value;
422
423 Error error (reg_value.SetValueFromCString (reg_info, value_str));
Chris Lattner24943d22010-06-08 16:52:24 +0000424 if (error.Success())
425 {
Greg Clayton061b79d2011-05-09 20:18:18 +0000426 if (reg_ctx->WriteRegister (reg_info, reg_value))
Chris Lattner24943d22010-06-08 16:52:24 +0000427 {
Greg Claytoncf5927e2012-05-18 02:38:05 +0000428 // Toss all frames and anything else in the thread
429 // after a register has been written.
430 exe_ctx.GetThreadRef().Flush();
Chris Lattner24943d22010-06-08 16:52:24 +0000431 result.SetStatus (eReturnStatusSuccessFinishNoResult);
432 return true;
433 }
434 }
Jason Molenda95536732011-08-25 01:59:13 +0000435 if (error.AsCString())
Chris Lattner24943d22010-06-08 16:52:24 +0000436 {
437 result.AppendErrorWithFormat ("Failed to write register '%s' with value '%s': %s\n",
438 reg_name,
439 value_str,
440 error.AsCString());
Chris Lattner24943d22010-06-08 16:52:24 +0000441 }
Jason Molenda95536732011-08-25 01:59:13 +0000442 else
443 {
444 result.AppendErrorWithFormat ("Failed to write register '%s' with value '%s'",
445 reg_name,
446 value_str);
447 }
448 result.SetStatus (eReturnStatusFailed);
Chris Lattner24943d22010-06-08 16:52:24 +0000449 }
450 else
451 {
452 result.AppendErrorWithFormat ("Register not found for '%s'.\n", reg_name);
453 result.SetStatus (eReturnStatusFailed);
454 }
455 }
456 }
457 else
458 {
459 result.AppendError ("no current frame");
460 result.SetStatus (eReturnStatusFailed);
461 }
462 return result.Succeeded();
463 }
464};
465
466
467//----------------------------------------------------------------------
468// CommandObjectRegister constructor
469//----------------------------------------------------------------------
Greg Clayton63094e02010-06-23 01:19:29 +0000470CommandObjectRegister::CommandObjectRegister(CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000471 CommandObjectMultiword (interpreter,
472 "register",
Caroline Ticec1ad82e2010-09-07 22:38:08 +0000473 "A set of commands to access thread registers.",
Chris Lattner24943d22010-06-08 16:52:24 +0000474 "register [read|write] ...")
475{
Greg Clayton238c0a12010-09-18 01:14:36 +0000476 LoadSubCommand ("read", CommandObjectSP (new CommandObjectRegisterRead (interpreter)));
477 LoadSubCommand ("write", CommandObjectSP (new CommandObjectRegisterWrite (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +0000478}
479
480
481//----------------------------------------------------------------------
482// Destructor
483//----------------------------------------------------------------------
484CommandObjectRegister::~CommandObjectRegister()
485{
486}