30#include "llvm/Support/Errno.h"
36#define LLDB_OPTIONS_register_read
37#include "CommandOptions.inc"
43 interpreter,
"register read",
44 "Dump the contents of one or more register values from the current "
45 "frame. If no register is specified, dumps them all.",
47 eCommandRequiresFrame | eCommandRequiresRegContext |
48 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
50 {{CommandArgumentType::eArgTypeFormat,
51 "Specify a format to be used for display. If this "
52 "is set, register fields will not be displayed."}}) {
54 CommandArgumentData register_arg;
62 arg.push_back(register_arg);
100 bool prefix_with_name = !prefix_with_altname;
113 reg_addr, so_reg_addr)) {
127 bool primitive_only =
false) {
128 uint32_t unavailable_count = 0;
129 uint32_t available_count = 0;
137 strm.
Printf(
"%s:\n", (reg_set->
name ? reg_set->
name :
"unknown"));
140 for (
size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) {
141 const uint32_t reg = reg_set->
registers[reg_idx];
144 if (primitive_only && reg_info && reg_info->
value_regs)
147 if (reg_info &&
DumpRegister(exe_ctx, strm, *reg_ctx, *reg_info,
154 if (unavailable_count) {
156 strm.
Printf(
"%u registers were unavailable.\n", unavailable_count);
160 return available_count > 0;
171 size_t num_register_sets = 1;
173 if (set_array_size > 0) {
174 for (
size_t i = 0; i < set_array_size; ++i) {
178 if (set_idx < reg_ctx->GetRegisterSetCount()) {
182 llvm::sys::StrError());
184 result.
AppendError(
"unknown error while reading registers.\n");
189 "invalid register set index: %" PRIu64
"\n", (uint64_t)set_idx);
197 for (set_idx = 0; set_idx < num_register_sets; ++set_idx) {
206 result.
AppendError(
"the --all option can't be used when registers "
207 "names are supplied as arguments\n");
209 result.
AppendError(
"the --set <set> option can't be used when "
210 "registers names are supplied as arguments\n");
212 for (
auto &entry : command) {
218 auto arg_str = entry.ref();
219 arg_str.consume_front(
"$");
229 strm.
Printf(
"%-12s = error: unavailable\n", reg_info->name);
232 arg_str.str().c_str());
250 return llvm::ArrayRef(g_register_read_options);
262 const int short_option =
GetDefinitions()[option_idx].short_option;
263 switch (short_option) {
287 llvm_unreachable(
"Unimplemented option");
308 "Modify a single register value.", nullptr,
309 eCommandRequiresFrame | eCommandRequiresRegContext |
310 eCommandProcessMustBeLaunched |
311 eCommandProcessMustBePaused) {
323 arg1.push_back(register_arg);
331 arg2.push_back(value_arg);
357 "register write takes exactly 2 arguments: <reg-name> <value>");
359 auto reg_name = command[0].ref();
360 auto value_str = command[1].ref();
367 reg_name.consume_front(
"$");
375 if (
error.Success()) {
384 if (
error.AsCString()) {
386 "Failed to write register '%s' with value '%s': %s\n",
387 reg_name.str().c_str(), value_str.str().c_str(),
391 "Failed to write register '%s' with value '%s'",
392 reg_name.str().c_str(), value_str.str().c_str());
396 reg_name.str().c_str());
408 "View information about a register.", nullptr,
409 eCommandRequiresFrame | eCommandRequiresRegContext |
410 eCommandProcessMustBeLaunched |
411 eCommandProcessMustBePaused) {
413Name The name lldb uses for the register, optionally with an alias.
414Size The size of the register in bytes and again in bits.
415Invalidates (*) The registers that would be changed if you wrote this
416 register. For example, writing to a narrower alias of a wider
417 register would change the value of the wider register.
418Read from (*) The registers that the value of this register is constructed
419 from. For example, a narrower alias of a wider register will be
420 read from the wider register.
421In sets (*) The register sets that contain this register. For example the
422 PC will be in the "General Purpose Register" set.
423Fields (*) A table of the names and bit positions of the values contained
426Fields marked with (*) may not always be present. Some information may be
427different for the same register when connected to different debug servers.)");
434 arg1.push_back(register_arg);
452 result.
AppendError(
"register info takes exactly 1 argument: <reg-name>");
456 llvm::StringRef reg_name = command[0].ref();
466 reg_name.str().c_str());
475 "Commands to access registers for the current "
476 "thread and stack frame.",
477 "register [read|write|info] ...") {
static llvm::raw_ostream & error(Stream &strm)
bool DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectRegisterInfo() override=default
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
CommandObjectRegisterInfo(CommandInterpreter &interpreter)
OptionValueArray set_indexes
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, ExecutionContext *execution_context) override
void OptionParsingStarting(ExecutionContext *execution_context) override
~CommandOptions() override=default
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
OptionValueBoolean dump_all_sets
OptionValueBoolean alternate_name
bool DumpRegisterSet(const ExecutionContext &exe_ctx, Stream &strm, RegisterContext *reg_ctx, size_t set_idx, bool primitive_only=false)
OptionGroupOptions m_option_group
CommandOptions m_command_options
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
~CommandObjectRegisterRead() override=default
bool DumpRegister(const ExecutionContext &exe_ctx, Stream &strm, RegisterContext ®_ctx, const RegisterInfo ®_info, bool print_flags)
CommandObjectRegisterRead(CommandInterpreter &interpreter)
Options * GetOptions() override
OptionGroupFormat m_format_options
bool DoExecute(Args &command, CommandReturnObject &result) override
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The input array contains a parsed version of the line.
~CommandObjectRegisterWrite() override=default
bool DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectRegisterWrite(CommandInterpreter &interpreter)
A section + offset based address class.
@ DumpStyleResolvedDescription
Display the details about what an address resolves to.
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX, bool all_ranges=false) const
Dump a description of this object to a Stream.
A command line argument class.
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
~CommandObjectRegister() override
CommandObjectRegister(CommandInterpreter &interpreter)
std::vector< CommandArgumentData > CommandArgumentEntry
virtual void SetHelpLong(llvm::StringRef str)
ExecutionContext m_exe_ctx
std::vector< CommandArgumentEntry > m_arguments
CommandInterpreter & GetCommandInterpreter()
void AppendErrorWithFormatv(const char *format, Args &&... args)
void void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
Stream & GetOutputStream()
"lldb/Utility/ArgCompletionRequest.h"
size_t GetCursorIndex() const
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool HasProcessScope() const
Returns true the ExecutionContext object contains a valid target and process.
ExecutionContextScope * GetBestExecutionContextScope() const
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
Target & GetTargetRef() const
Returns a reference to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
Thread & GetThreadRef() const
Returns a reference to the thread object.
RegisterContext * GetRegisterContext() const
void Append(OptionGroup *group)
Append options from a OptionGroup class.
bool AppendValue(const lldb::OptionValueSP &value_sp)
void SetCurrentValue(bool value)
bool GetCurrentValue() const
static lldb::OptionValueSP Create(llvm::StringRef value_str, Status &error)
bool OptionWasSet() const
std::optional< T > GetValueAs() const
A command line option parsing protocol class.
A plug-in interface definition class for debugging a process.
uint32_t GetAddressByteSize() const
virtual const RegisterSet * GetRegisterSet(size_t reg_set)=0
virtual const RegisterInfo * GetRegisterInfoAtIndex(size_t reg)=0
virtual bool WriteRegister(const RegisterInfo *reg_info, const RegisterValue ®_value)=0
virtual size_t GetRegisterSetCount()=0
const RegisterInfo * GetRegisterInfoByName(llvm::StringRef reg_name, uint32_t start_idx=0)
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue ®_value)=0
Status SetValueFromString(const RegisterInfo *reg_info, llvm::StringRef value_str)
uint64_t GetAsUInt64(uint64_t fail_value=UINT64_MAX, bool *success_ptr=nullptr) const
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, bool allow_section_end=false) const
A stream class that can stream formatted output to a file.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
size_t EOL()
Output and End of Line character to the stream.
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
void IndentMore(unsigned amount=2)
Increment the current indentation level.
SectionLoadList & GetSectionLoadList()
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
std::vector< OptionArgElement > OptionElementVector
void DumpRegisterInfo(Stream &strm, RegisterContext &ctx, const RegisterInfo &info, uint32_t terminal_width)
void DumpRegisterValue(const RegisterValue ®_val, Stream &s, const RegisterInfo ®_info, bool prefix_with_name, bool prefix_with_alt_name, lldb::Format format, uint32_t reg_name_right_align_at=0, ExecutionContextScope *exe_scope=nullptr, bool print_flags=false, lldb::TargetSP target_sp=nullptr)
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
@ eEncodingUint
unsigned integer
@ eEncodingSint
signed integer
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
std::shared_ptr< lldb_private::OptionValue > OptionValueSP
Used to build individual command argument lists.
ArgumentRepetitionType arg_repetition
lldb::CommandArgumentType arg_type
Every register is described in detail including its name, alternate name (optional),...
lldb::Encoding encoding
Encoding of the register bits.
uint32_t * value_regs
List of registers (terminated with LLDB_INVALID_REGNUM).
uint32_t byte_size
Size in bytes of the register.
Registers are grouped into register sets.
size_t num_registers
The number of registers in REGISTERS array below.
const uint32_t * registers
An array of register indices in this set.
const char * name
Name of this register set.