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."}}) {
86 bool prefix_with_name = !prefix_with_altname;
99 reg_addr, so_reg_addr)) {
113 bool primitive_only =
false) {
114 uint32_t unavailable_count = 0;
115 uint32_t available_count = 0;
123 strm.
Printf(
"%s:\n", (reg_set->
name ? reg_set->
name :
"unknown"));
126 for (
size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) {
127 const uint32_t reg = reg_set->
registers[reg_idx];
130 if (primitive_only && reg_info && reg_info->
value_regs)
133 if (reg_info &&
DumpRegister(exe_ctx, strm, *reg_ctx, *reg_info,
140 if (unavailable_count) {
142 strm.
Printf(
"%u registers were unavailable.\n", unavailable_count);
146 return available_count > 0;
157 size_t num_register_sets = 1;
159 if (set_array_size > 0) {
160 for (
size_t i = 0; i < set_array_size; ++i) {
164 if (set_idx < reg_ctx->GetRegisterSetCount()) {
168 llvm::sys::StrError());
170 result.
AppendError(
"unknown error while reading registers.\n");
175 "invalid register set index: %" PRIu64
"\n", (uint64_t)set_idx);
183 for (set_idx = 0; set_idx < num_register_sets; ++set_idx) {
192 result.
AppendError(
"the --all option can't be used when registers "
193 "names are supplied as arguments\n");
195 result.
AppendError(
"the --set <set> option can't be used when "
196 "registers names are supplied as arguments\n");
198 for (
auto &entry : command) {
204 auto arg_str = entry.ref();
205 arg_str.consume_front(
"$");
215 strm.
Printf(
"%-12s = error: unavailable\n", reg_info->name);
218 arg_str.str().c_str());
235 return llvm::ArrayRef(g_register_read_options);
247 const int short_option =
GetDefinitions()[option_idx].short_option;
248 switch (short_option) {
272 llvm_unreachable(
"Unimplemented option");
293 "Modify a single register value.", nullptr,
294 eCommandRequiresFrame | eCommandRequiresRegContext |
295 eCommandProcessMustBeLaunched |
296 eCommandProcessMustBePaused) {
308 arg1.push_back(register_arg);
316 arg2.push_back(value_arg);
342 "register write takes exactly 2 arguments: <reg-name> <value>");
344 auto reg_name = command[0].ref();
345 auto value_str = command[1].ref();
352 reg_name.consume_front(
"$");
360 if (
error.Success()) {
369 if (
error.AsCString()) {
371 "Failed to write register '%s' with value '%s': %s\n",
372 reg_name.str().c_str(), value_str.str().c_str(),
376 "Failed to write register '%s' with value '%s'",
377 reg_name.str().c_str(), value_str.str().c_str());
381 reg_name.str().c_str());
392 "View information about a register.", nullptr,
393 eCommandRequiresFrame | eCommandRequiresRegContext |
394 eCommandProcessMustBeLaunched |
395 eCommandProcessMustBePaused) {
397Name The name lldb uses for the register, optionally with an alias.
398Size The size of the register in bytes and again in bits.
399Invalidates (*) The registers that would be changed if you wrote this
400 register. For example, writing to a narrower alias of a wider
401 register would change the value of the wider register.
402Read from (*) The registers that the value of this register is constructed
403 from. For example, a narrower alias of a wider register will be
404 read from the wider register.
405In sets (*) The register sets that contain this register. For example the
406 PC will be in the "General Purpose Register" set.
407Fields (*) A table of the names and bit positions of the values contained
410Fields marked with (*) may not always be present. Some information may be
411different for the same register when connected to different debug servers.)");
429 result.
AppendError(
"register info takes exactly 1 argument: <reg-name>");
433 llvm::StringRef reg_name = command[0].ref();
443 reg_name.str().c_str());
450 "Commands to access registers for the current "
451 "thread and stack frame.",
452 "register [read|write|info] ...") {
static llvm::raw_ostream & error(Stream &strm)
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectRegisterInfo() override=default
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
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 default version handles argument definitions that have only one argument type,...
~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
void DoExecute(Args &command, CommandReturnObject &result) override
OptionGroupFormat m_format_options
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
~CommandObjectRegisterWrite() override=default
void 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, std::optional< Stream::HighlightSettings > settings=std::nullopt) 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)
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
ExecutionContext m_exe_ctx
std::vector< CommandArgumentEntry > m_arguments
CommandInterpreter & GetCommandInterpreter()
virtual void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector)
The default version handles argument definitions that have only one argument type,...
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.