[Lldb-commits] [lldb] 2ad771c - [lldb] Change some pointers to refs in register printing code
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Mon Apr 17 00:40:21 PDT 2023
Author: David Spickett
Date: 2023-04-17T07:40:13Z
New Revision: 2ad771cf7bae513da6e54772e4e50e0e049af9ac
URL: https://github.com/llvm/llvm-project/commit/2ad771cf7bae513da6e54772e4e50e0e049af9ac
DIFF: https://github.com/llvm/llvm-project/commit/2ad771cf7bae513da6e54772e4e50e0e049af9ac.diff
LOG: [lldb] Change some pointers to refs in register printing code
No one was passing nullptr for these.
Reviewed By: JDevlieghere
Differential Revision: https://reviews.llvm.org/D148228
Added:
Modified:
lldb/include/lldb/Core/DumpRegisterValue.h
lldb/source/Commands/CommandObjectRegister.cpp
lldb/source/Core/DumpRegisterValue.cpp
lldb/source/Core/EmulateInstruction.cpp
lldb/source/Core/FormatEntity.cpp
lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
lldb/source/Target/ThreadPlanCallFunction.cpp
lldb/source/Target/ThreadPlanTracer.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/DumpRegisterValue.h b/lldb/include/lldb/Core/DumpRegisterValue.h
index 9dc579dddc975..b89b35ac0b4ab 100644
--- a/lldb/include/lldb/Core/DumpRegisterValue.h
+++ b/lldb/include/lldb/Core/DumpRegisterValue.h
@@ -24,8 +24,8 @@ class Stream;
// all.
// Set print_flags to true to print register fields if they are available.
// If you do so, target_sp must be non-null for it to work.
-void DumpRegisterValue(const RegisterValue ®_val, Stream *s,
- const RegisterInfo *reg_info, bool prefix_with_name,
+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,
diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp
index 4b0d455d90dae..8784b8b9977a8 100644
--- a/lldb/source/Commands/CommandObjectRegister.cpp
+++ b/lldb/source/Commands/CommandObjectRegister.cpp
@@ -84,42 +84,38 @@ class CommandObjectRegisterRead : public CommandObjectParsed {
Options *GetOptions() override { return &m_option_group; }
bool DumpRegister(const ExecutionContext &exe_ctx, Stream &strm,
- RegisterContext *reg_ctx, const RegisterInfo *reg_info,
+ RegisterContext ®_ctx, const RegisterInfo ®_info,
bool print_flags) {
- if (reg_info) {
- RegisterValue reg_value;
-
- if (reg_ctx->ReadRegister(reg_info, reg_value)) {
- strm.Indent();
-
- bool prefix_with_altname = (bool)m_command_options.alternate_name;
- bool prefix_with_name = !prefix_with_altname;
- DumpRegisterValue(reg_value, &strm, reg_info, prefix_with_name,
- prefix_with_altname, m_format_options.GetFormat(), 8,
- exe_ctx.GetBestExecutionContextScope(), print_flags,
- exe_ctx.GetTargetSP());
- if ((reg_info->encoding == eEncodingUint) ||
- (reg_info->encoding == eEncodingSint)) {
- Process *process = exe_ctx.GetProcessPtr();
- if (process && reg_info->byte_size == process->GetAddressByteSize()) {
- addr_t reg_addr = reg_value.GetAsUInt64(LLDB_INVALID_ADDRESS);
- if (reg_addr != LLDB_INVALID_ADDRESS) {
- Address so_reg_addr;
- if (exe_ctx.GetTargetRef()
- .GetSectionLoadList()
- .ResolveLoadAddress(reg_addr, so_reg_addr)) {
- strm.PutCString(" ");
- so_reg_addr.Dump(&strm, exe_ctx.GetBestExecutionContextScope(),
- Address::DumpStyleResolvedDescription);
- }
- }
+ RegisterValue reg_value;
+ if (!reg_ctx.ReadRegister(®_info, reg_value))
+ return false;
+
+ strm.Indent();
+
+ bool prefix_with_altname = (bool)m_command_options.alternate_name;
+ bool prefix_with_name = !prefix_with_altname;
+ DumpRegisterValue(reg_value, strm, reg_info, prefix_with_name,
+ prefix_with_altname, m_format_options.GetFormat(), 8,
+ exe_ctx.GetBestExecutionContextScope(), print_flags,
+ exe_ctx.GetTargetSP());
+ if ((reg_info.encoding == eEncodingUint) ||
+ (reg_info.encoding == eEncodingSint)) {
+ Process *process = exe_ctx.GetProcessPtr();
+ if (process && reg_info.byte_size == process->GetAddressByteSize()) {
+ addr_t reg_addr = reg_value.GetAsUInt64(LLDB_INVALID_ADDRESS);
+ if (reg_addr != LLDB_INVALID_ADDRESS) {
+ Address so_reg_addr;
+ if (exe_ctx.GetTargetRef().GetSectionLoadList().ResolveLoadAddress(
+ reg_addr, so_reg_addr)) {
+ strm.PutCString(" ");
+ so_reg_addr.Dump(&strm, exe_ctx.GetBestExecutionContextScope(),
+ Address::DumpStyleResolvedDescription);
}
}
- strm.EOL();
- return true;
}
}
- return false;
+ strm.EOL();
+ return true;
}
bool DumpRegisterSet(const ExecutionContext &exe_ctx, Stream &strm,
@@ -144,8 +140,8 @@ class CommandObjectRegisterRead : public CommandObjectParsed {
if (primitive_only && reg_info && reg_info->value_regs)
continue;
- if (DumpRegister(exe_ctx, strm, reg_ctx, reg_info,
- /*print_flags=*/false))
+ if (reg_info && DumpRegister(exe_ctx, strm, *reg_ctx, *reg_info,
+ /*print_flags=*/false))
++available_count;
else
++unavailable_count;
@@ -165,7 +161,6 @@ class CommandObjectRegisterRead : public CommandObjectParsed {
Stream &strm = result.GetOutputStream();
RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext();
- const RegisterInfo *reg_info = nullptr;
if (command.GetArgumentCount() == 0) {
size_t set_idx;
@@ -218,10 +213,9 @@ class CommandObjectRegisterRead : public CommandObjectParsed {
auto arg_str = entry.ref();
arg_str.consume_front("$");
- reg_info = reg_ctx->GetRegisterInfoByName(arg_str);
-
- if (reg_info) {
- if (!DumpRegister(m_exe_ctx, strm, reg_ctx, reg_info,
+ if (const RegisterInfo *reg_info =
+ reg_ctx->GetRegisterInfoByName(arg_str)) {
+ if (!DumpRegister(m_exe_ctx, strm, *reg_ctx, *reg_info,
/*print_flags=*/true))
strm.Printf("%-12s = error: unavailable\n", reg_info->name);
} else {
diff --git a/lldb/source/Core/DumpRegisterValue.cpp b/lldb/source/Core/DumpRegisterValue.cpp
index deeddfc96f3d4..0e85e8e9ea893 100644
--- a/lldb/source/Core/DumpRegisterValue.cpp
+++ b/lldb/source/Core/DumpRegisterValue.cpp
@@ -59,8 +59,8 @@ static void dump_type_value(lldb_private::CompilerType &fields_type, T value,
vobj_sp->Dump(strm, dump_options);
}
-void lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream *s,
- const RegisterInfo *reg_info,
+void lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream &s,
+ const RegisterInfo ®_info,
bool prefix_with_name,
bool prefix_with_alt_name, Format format,
uint32_t reg_name_right_align_at,
@@ -83,38 +83,38 @@ void lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream *s,
format_string.Printf("%%s");
std::string fmt = std::string(format_string.GetString());
if (prefix_with_name) {
- if (reg_info->name) {
- s->Printf(fmt.c_str(), reg_info->name);
+ if (reg_info.name) {
+ s.Printf(fmt.c_str(), reg_info.name);
name_printed = true;
- } else if (reg_info->alt_name) {
- s->Printf(fmt.c_str(), reg_info->alt_name);
+ } else if (reg_info.alt_name) {
+ s.Printf(fmt.c_str(), reg_info.alt_name);
prefix_with_alt_name = false;
name_printed = true;
}
}
if (prefix_with_alt_name) {
if (name_printed)
- s->PutChar('/');
- if (reg_info->alt_name) {
- s->Printf(fmt.c_str(), reg_info->alt_name);
+ s.PutChar('/');
+ if (reg_info.alt_name) {
+ s.Printf(fmt.c_str(), reg_info.alt_name);
name_printed = true;
} else if (!name_printed) {
// No alternate name but we were asked to display a name, so show the
// main name
- s->Printf(fmt.c_str(), reg_info->name);
+ s.Printf(fmt.c_str(), reg_info.name);
name_printed = true;
}
}
if (name_printed)
- s->PutCString(" = ");
+ s.PutCString(" = ");
if (format == eFormatDefault)
- format = reg_info->format;
+ format = reg_info.format;
- DumpDataExtractor(data, s,
+ DumpDataExtractor(data, &s,
0, // Offset in "data"
format, // Format to use when dumping
- reg_info->byte_size, // item_byte_size
+ reg_info.byte_size, // item_byte_size
1, // item_count
UINT32_MAX, // num_per_line
LLDB_INVALID_ADDRESS, // base_addr
@@ -122,21 +122,21 @@ void lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream *s,
0, // item_bit_offset
exe_scope);
- if (!print_flags || !reg_info->flags_type || !exe_scope || !target_sp ||
- (reg_info->byte_size != 4 && reg_info->byte_size != 8))
+ if (!print_flags || !reg_info.flags_type || !exe_scope || !target_sp ||
+ (reg_info.byte_size != 4 && reg_info.byte_size != 8))
return;
CompilerType fields_type = target_sp->GetRegisterType(
- reg_info->name, *reg_info->flags_type, reg_info->byte_size);
+ reg_info.name, *reg_info.flags_type, reg_info.byte_size);
// Use a new stream so we can remove a trailing newline later.
StreamString fields_stream;
- if (reg_info->byte_size == 4) {
- dump_type_value(fields_type, reg_val.GetAsUInt32(), exe_scope, *reg_info,
+ if (reg_info.byte_size == 4) {
+ dump_type_value(fields_type, reg_val.GetAsUInt32(), exe_scope, reg_info,
fields_stream);
} else {
- dump_type_value(fields_type, reg_val.GetAsUInt64(), exe_scope, *reg_info,
+ dump_type_value(fields_type, reg_val.GetAsUInt64(), exe_scope, reg_info,
fields_stream);
}
@@ -150,7 +150,7 @@ void lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream *s,
llvm::StringRef fields_str = fields_stream.GetString().drop_back();
// End the line that contains " foo = 0x12345678".
- s->EOL();
+ s.EOL();
// Then split the value lines and indent each one.
bool first = true;
@@ -158,18 +158,18 @@ void lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream *s,
std::pair<llvm::StringRef, llvm::StringRef> split = fields_str.split('\n');
fields_str = split.second;
// Indent as far as the register name did.
- s->Printf(fmt.c_str(), "");
+ s.Printf(fmt.c_str(), "");
// Lines after the first won't have " = " so compensate for that.
if (!first)
- (*s) << " ";
+ s << " ";
first = false;
- (*s) << split.first;
+ s << split.first;
// On the last line we don't want a newline because the command will add
// one too.
if (fields_str.size())
- s->EOL();
+ s.EOL();
}
}
diff --git a/lldb/source/Core/EmulateInstruction.cpp b/lldb/source/Core/EmulateInstruction.cpp
index ca830ccc04bc1..753bee25de6db 100644
--- a/lldb/source/Core/EmulateInstruction.cpp
+++ b/lldb/source/Core/EmulateInstruction.cpp
@@ -363,7 +363,7 @@ bool EmulateInstruction::WriteRegisterDefault(EmulateInstruction *instruction,
const RegisterValue ®_value) {
StreamFile strm(stdout, false);
strm.Printf(" Write to Register (name = %s, value = ", reg_info->name);
- DumpRegisterValue(reg_value, &strm, reg_info, false, false, eFormatDefault);
+ DumpRegisterValue(reg_value, strm, *reg_info, false, false, eFormatDefault);
strm.PutCString(", context = ");
context.Dump(strm, instruction);
strm.EOL();
diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp
index 1d71149c1e253..80d77e1bc990e 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -605,7 +605,7 @@ static bool DumpRegister(Stream &s, StackFrame *frame, RegisterKind reg_kind,
if (reg_info) {
RegisterValue reg_value;
if (reg_ctx->ReadRegister(reg_info, reg_value)) {
- DumpRegisterValue(reg_value, &s, reg_info, false, false, format);
+ DumpRegisterValue(reg_value, s, *reg_info, false, false, format);
return true;
}
}
@@ -985,7 +985,7 @@ static bool DumpRegister(Stream &s, StackFrame *frame, const char *reg_name,
if (reg_info) {
RegisterValue reg_value;
if (reg_ctx->ReadRegister(reg_info, reg_value)) {
- DumpRegisterValue(reg_value, &s, reg_info, false, false, format);
+ DumpRegisterValue(reg_value, s, *reg_info, false, false, format);
return true;
}
}
diff --git a/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp b/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
index 47fc210b5d641..7ff5cd2c23b07 100644
--- a/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
+++ b/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
@@ -500,7 +500,7 @@ bool UnwindAssemblyInstEmulation::ReadRegister(EmulateInstruction *instruction,
strm.Printf("UnwindAssemblyInstEmulation::ReadRegister (name = \"%s\") => "
"synthetic_value = %i, value = ",
reg_info->name, synthetic);
- DumpRegisterValue(reg_value, &strm, reg_info, false, false, eFormatDefault);
+ DumpRegisterValue(reg_value, strm, *reg_info, false, false, eFormatDefault);
log->PutString(strm.GetString());
}
return true;
@@ -526,7 +526,7 @@ bool UnwindAssemblyInstEmulation::WriteRegister(
strm.Printf(
"UnwindAssemblyInstEmulation::WriteRegister (name = \"%s\", value = ",
reg_info->name);
- DumpRegisterValue(reg_value, &strm, reg_info, false, false, eFormatDefault);
+ DumpRegisterValue(reg_value, strm, *reg_info, false, false, eFormatDefault);
strm.PutCString(", context = ");
context.Dump(strm, instruction);
log->PutString(strm.GetString());
diff --git a/lldb/source/Target/ThreadPlanCallFunction.cpp b/lldb/source/Target/ThreadPlanCallFunction.cpp
index 7e9bb963bb5da..31027cd9e0115 100644
--- a/lldb/source/Target/ThreadPlanCallFunction.cpp
+++ b/lldb/source/Target/ThreadPlanCallFunction.cpp
@@ -163,7 +163,7 @@ void ThreadPlanCallFunction::ReportRegisterState(const char *message) {
reg_idx < num_registers; ++reg_idx) {
const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx);
if (reg_ctx->ReadRegister(reg_info, reg_value)) {
- DumpRegisterValue(reg_value, &strm, reg_info, true, false,
+ DumpRegisterValue(reg_value, strm, *reg_info, true, false,
eFormatDefault);
strm.EOL();
}
diff --git a/lldb/source/Target/ThreadPlanTracer.cpp b/lldb/source/Target/ThreadPlanTracer.cpp
index 82927ef648775..25e2e4013355c 100644
--- a/lldb/source/Target/ThreadPlanTracer.cpp
+++ b/lldb/source/Target/ThreadPlanTracer.cpp
@@ -223,7 +223,7 @@ void ThreadPlanAssemblyTracer::Log() {
reg_value != m_register_values[reg_num]) {
if (reg_value.GetType() != RegisterValue::eTypeInvalid) {
stream->PutCString("\n\t");
- DumpRegisterValue(reg_value, stream, reg_info, true, false,
+ DumpRegisterValue(reg_value, *stream, *reg_info, true, false,
eFormatDefault);
}
}
More information about the lldb-commits
mailing list