diff --git a/lldb/include/lldb/Core/DumpRegisterValue.h b/lldb/include/lldb/Core/DumpRegisterValue.h --- a/lldb/include/lldb/Core/DumpRegisterValue.h +++ b/lldb/include/lldb/Core/DumpRegisterValue.h @@ -24,8 +24,8 @@ // 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 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -84,42 +84,38 @@ 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 @@ 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 @@ 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 @@ 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 --- a/lldb/source/Core/DumpRegisterValue.cpp +++ b/lldb/source/Core/DumpRegisterValue.cpp @@ -59,8 +59,8 @@ 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 @@ 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 @@ 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 @@ 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 @@ std::pair 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 --- a/lldb/source/Core/EmulateInstruction.cpp +++ b/lldb/source/Core/EmulateInstruction.cpp @@ -363,7 +363,7 @@ 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 --- a/lldb/source/Core/FormatEntity.cpp +++ b/lldb/source/Core/FormatEntity.cpp @@ -605,7 +605,7 @@ 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 @@ 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 --- a/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp +++ b/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp @@ -500,7 +500,7 @@ 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 @@ 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 --- a/lldb/source/Target/ThreadPlanCallFunction.cpp +++ b/lldb/source/Target/ThreadPlanCallFunction.cpp @@ -163,7 +163,7 @@ 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 --- a/lldb/source/Target/ThreadPlanTracer.cpp +++ b/lldb/source/Target/ThreadPlanTracer.cpp @@ -223,7 +223,7 @@ 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); } }