diff options
author | Pavel Labath <labath@google.com> | 2018-07-24 15:48:13 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2018-07-24 15:48:13 +0000 |
commit | e03334cf6a65f8671b49ea82f4132ca9526ec521 (patch) | |
tree | fe2f21f0ffaff3f047c03d503293c55b88fe2227 | |
parent | 8dbcc58917a6c39be05fe8de29ce84ae4adcb50e (diff) | |
download | bcm5719-llvm-e03334cf6a65f8671b49ea82f4132ca9526ec521.tar.gz bcm5719-llvm-e03334cf6a65f8671b49ea82f4132ca9526ec521.zip |
Move dumping code out of RegisterValue class
Summary:
The dump function was the only part of this class which depended on
high-level functionality. This was due to the DumpDataExtractor
function, which uses info from a running target to control dump format
(although, RegisterValue doesn't really use the high-level part of
DumpDataExtractor).
This patch follows the same approach done for the DataExtractor class,
and extracts the dumping code into a separate function/file. This file
can stay in the higher level code, while the RegisterValue class and
anything that does not depend in dumping can stay go to lower layers.
The XCode project will need to be updated after this patch.
Reviewers: zturner, jingham, clayborg
Subscribers: lldb-commits, mgorny
Differential Revision: https://reviews.llvm.org/D48351
llvm-svn: 337832
-rw-r--r-- | lldb/include/lldb/Core/DumpRegisterValue.h | 31 | ||||
-rw-r--r-- | lldb/include/lldb/Core/RegisterValue.h | 6 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectRegister.cpp | 5 | ||||
-rw-r--r-- | lldb/source/Core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lldb/source/Core/DumpRegisterValue.cpp | 79 | ||||
-rw-r--r-- | lldb/source/Core/EmulateInstruction.cpp | 3 | ||||
-rw-r--r-- | lldb/source/Core/FormatEntity.cpp | 5 | ||||
-rw-r--r-- | lldb/source/Core/RegisterValue.cpp | 62 | ||||
-rw-r--r-- | lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp | 5 | ||||
-rw-r--r-- | lldb/source/Target/ThreadPlanCallFunction.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Target/ThreadPlanTracer.cpp | 4 |
11 files changed, 128 insertions, 77 deletions
diff --git a/lldb/include/lldb/Core/DumpRegisterValue.h b/lldb/include/lldb/Core/DumpRegisterValue.h new file mode 100644 index 00000000000..bc4860fbc0e --- /dev/null +++ b/lldb/include/lldb/Core/DumpRegisterValue.h @@ -0,0 +1,31 @@ +//===-- DumpRegisterValue.h -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_CORE_DUMPREGISTERVALUE_H +#define LLDB_CORE_DUMPREGISTERVALUE_H + +#include "lldb/lldb-enumerations.h" +#include <cstdint> + +namespace lldb_private { + +class RegisterValue; +struct RegisterInfo; +class Stream; + +// The default value of 0 for reg_name_right_align_at means no alignment at +// all. +bool DumpRegisterValue(const RegisterValue ®_val, Stream *s, + const RegisterInfo *reg_info, bool prefix_with_name, + bool prefix_with_alt_name, lldb::Format format, + uint32_t reg_name_right_align_at = 0); + +} // namespace lldb_private + +#endif // LLDB_CORE_DUMPREGISTERVALUE_H diff --git a/lldb/include/lldb/Core/RegisterValue.h b/lldb/include/lldb/Core/RegisterValue.h index 1262ed1c595..b369c3dff9a 100644 --- a/lldb/include/lldb/Core/RegisterValue.h +++ b/lldb/include/lldb/Core/RegisterValue.h @@ -248,12 +248,6 @@ public: Status SetValueFromData(const RegisterInfo *reg_info, DataExtractor &data, lldb::offset_t offset, bool partial_data_ok); - // The default value of 0 for reg_name_right_align_at means no alignment at - // all. - bool Dump(Stream *s, const RegisterInfo *reg_info, bool prefix_with_name, - bool prefix_with_alt_name, lldb::Format format, - uint32_t reg_name_right_align_at = 0) const; - const void *GetBytes() const; lldb::ByteOrder GetByteOrder() const { diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 193729eff11..4dadc5d68d2 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -9,6 +9,7 @@ #include "CommandObjectRegister.h" #include "lldb/Core/Debugger.h" +#include "lldb/Core/DumpRegisterValue.h" #include "lldb/Core/RegisterValue.h" #include "lldb/Core/Scalar.h" #include "lldb/Host/OptionParser.h" @@ -92,8 +93,8 @@ public: bool prefix_with_altname = (bool)m_command_options.alternate_name; bool prefix_with_name = !prefix_with_altname; - reg_value.Dump(&strm, reg_info, prefix_with_name, prefix_with_altname, - m_format_options.GetFormat(), 8); + DumpRegisterValue(reg_value, &strm, reg_info, prefix_with_name, + prefix_with_altname, m_format_options.GetFormat(), 8); if ((reg_info->encoding == eEncodingUint) || (reg_info->encoding == eEncodingSint)) { Process *process = exe_ctx.GetProcessPtr(); diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt index 64c56611ced..927a0dcc2ec 100644 --- a/lldb/source/Core/CMakeLists.txt +++ b/lldb/source/Core/CMakeLists.txt @@ -18,6 +18,7 @@ add_lldb_library(lldbCore Debugger.cpp Disassembler.cpp DumpDataExtractor.cpp + DumpRegisterValue.cpp DynamicLoader.cpp EmulateInstruction.cpp Event.cpp diff --git a/lldb/source/Core/DumpRegisterValue.cpp b/lldb/source/Core/DumpRegisterValue.cpp new file mode 100644 index 00000000000..99334ca78a6 --- /dev/null +++ b/lldb/source/Core/DumpRegisterValue.cpp @@ -0,0 +1,79 @@ +//===-- DumpRegisterValue.cpp -----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Core/DumpRegisterValue.h" +#include "lldb/Core/DumpDataExtractor.h" +#include "lldb/Core/RegisterValue.h" +#include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/StreamString.h" +#include "lldb/lldb-private-types.h" + +using namespace lldb; + +bool lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream *s, + const RegisterInfo *reg_info, + bool prefix_with_name, + bool prefix_with_alt_name, Format format, + uint32_t reg_name_right_align_at) { + DataExtractor data; + if (reg_val.GetData(data)) { + bool name_printed = false; + // For simplicity, alignment of the register name printing applies only in + // the most common case where: + // + // prefix_with_name^prefix_with_alt_name is true + // + StreamString format_string; + if (reg_name_right_align_at && (prefix_with_name ^ prefix_with_alt_name)) + format_string.Printf("%%%us", reg_name_right_align_at); + else + format_string.Printf("%%s"); + std::string fmt = format_string.GetString(); + if (prefix_with_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); + 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); + 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); + name_printed = true; + } + } + if (name_printed) + s->PutCString(" = "); + + if (format == eFormatDefault) + format = reg_info->format; + + DumpDataExtractor(data, s, + 0, // Offset in "data" + format, // Format to use when dumping + reg_info->byte_size, // item_byte_size + 1, // item_count + UINT32_MAX, // num_per_line + LLDB_INVALID_ADDRESS, // base_addr + 0, // item_bit_size + 0); // item_bit_offset + return true; + } + return false; +} diff --git a/lldb/source/Core/EmulateInstruction.cpp b/lldb/source/Core/EmulateInstruction.cpp index 2ee2c79de27..469022119c9 100644 --- a/lldb/source/Core/EmulateInstruction.cpp +++ b/lldb/source/Core/EmulateInstruction.cpp @@ -10,6 +10,7 @@ #include "lldb/Core/EmulateInstruction.h" #include "lldb/Core/Address.h" +#include "lldb/Core/DumpRegisterValue.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/RegisterValue.h" #include "lldb/Core/StreamFile.h" @@ -361,7 +362,7 @@ bool EmulateInstruction::WriteRegisterDefault(EmulateInstruction *instruction, const RegisterValue ®_value) { StreamFile strm(stdout, false); strm.Printf(" Write to Register (name = %s, value = ", reg_info->name); - reg_value.Dump(&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 de9263f58fa..2257b7e273e 100644 --- a/lldb/source/Core/FormatEntity.cpp +++ b/lldb/source/Core/FormatEntity.cpp @@ -12,6 +12,7 @@ #include "lldb/Core/Address.h" #include "lldb/Core/AddressRange.h" // for AddressRange #include "lldb/Core/Debugger.h" +#include "lldb/Core/DumpRegisterValue.h" #include "lldb/Core/Module.h" #include "lldb/Core/RegisterValue.h" // for RegisterValue #include "lldb/Core/ValueObject.h" @@ -621,7 +622,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)) { - reg_value.Dump(&s, reg_info, false, false, format); + DumpRegisterValue(reg_value, &s, reg_info, false, false, format); return true; } } @@ -1018,7 +1019,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)) { - reg_value.Dump(&s, reg_info, false, false, format); + DumpRegisterValue(reg_value, &s, reg_info, false, false, format); return true; } } diff --git a/lldb/source/Core/RegisterValue.cpp b/lldb/source/Core/RegisterValue.cpp index 07dd96d3a77..4f908609dde 100644 --- a/lldb/source/Core/RegisterValue.cpp +++ b/lldb/source/Core/RegisterValue.cpp @@ -9,7 +9,6 @@ #include "lldb/Core/RegisterValue.h" -#include "lldb/Core/DumpDataExtractor.h" #include "lldb/Core/Scalar.h" #include "lldb/Utility/Args.h" #include "lldb/Utility/DataExtractor.h" @@ -34,67 +33,6 @@ using namespace lldb; using namespace lldb_private; -bool RegisterValue::Dump(Stream *s, const RegisterInfo *reg_info, - bool prefix_with_name, bool prefix_with_alt_name, - Format format, - uint32_t reg_name_right_align_at) const { - DataExtractor data; - if (GetData(data)) { - bool name_printed = false; - // For simplicity, alignment of the register name printing applies only in - // the most common case where: - // - // prefix_with_name^prefix_with_alt_name is true - // - StreamString format_string; - if (reg_name_right_align_at && (prefix_with_name ^ prefix_with_alt_name)) - format_string.Printf("%%%us", reg_name_right_align_at); - else - format_string.Printf("%%s"); - std::string fmt = format_string.GetString(); - if (prefix_with_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); - 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); - 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); - name_printed = true; - } - } - if (name_printed) - s->PutCString(" = "); - - if (format == eFormatDefault) - format = reg_info->format; - - DumpDataExtractor(data, s, - 0, // Offset in "data" - format, // Format to use when dumping - reg_info->byte_size, // item_byte_size - 1, // item_count - UINT32_MAX, // num_per_line - LLDB_INVALID_ADDRESS, // base_addr - 0, // item_bit_size - 0); // item_bit_offset - return true; - } - return false; -} - bool RegisterValue::GetData(DataExtractor &data) const { return data.SetData(GetBytes(), GetByteSize(), GetByteOrder()) > 0; } diff --git a/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp b/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp index 0878c0e7f34..54e182b30b6 100644 --- a/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp +++ b/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp @@ -12,6 +12,7 @@ #include "lldb/Core/Address.h" #include "lldb/Core/Disassembler.h" #include "lldb/Core/DumpDataExtractor.h" +#include "lldb/Core/DumpRegisterValue.h" #include "lldb/Core/FormatEntity.h" #include "lldb/Core/PluginManager.h" #include "lldb/Target/ExecutionContext.h" @@ -486,7 +487,7 @@ bool UnwindAssemblyInstEmulation::ReadRegister(EmulateInstruction *instruction, strm.Printf("UnwindAssemblyInstEmulation::ReadRegister (name = \"%s\") => " "synthetic_value = %i, value = ", reg_info->name, synthetic); - reg_value.Dump(&strm, reg_info, false, false, eFormatDefault); + DumpRegisterValue(reg_value, &strm, reg_info, false, false, eFormatDefault); log->PutString(strm.GetString()); } return true; @@ -512,7 +513,7 @@ bool UnwindAssemblyInstEmulation::WriteRegister( strm.Printf( "UnwindAssemblyInstEmulation::WriteRegister (name = \"%s\", value = ", reg_info->name); - reg_value.Dump(&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 a00087fee27..18beda42fb6 100644 --- a/lldb/source/Target/ThreadPlanCallFunction.cpp +++ b/lldb/source/Target/ThreadPlanCallFunction.cpp @@ -15,6 +15,7 @@ #include "lldb/Breakpoint/Breakpoint.h" #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/Address.h" +#include "lldb/Core/DumpRegisterValue.h" #include "lldb/Core/Module.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/ABI.h" @@ -186,7 +187,8 @@ 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)) { - reg_value.Dump(&strm, reg_info, true, false, eFormatDefault); + 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 5057ca0a711..acbbd4d8bcc 100644 --- a/lldb/source/Target/ThreadPlanTracer.cpp +++ b/lldb/source/Target/ThreadPlanTracer.cpp @@ -13,6 +13,7 @@ #include "lldb/Core/Debugger.h" #include "lldb/Core/Disassembler.h" +#include "lldb/Core/DumpRegisterValue.h" #include "lldb/Core/Module.h" #include "lldb/Core/State.h" #include "lldb/Core/StreamFile.h" @@ -217,7 +218,8 @@ void ThreadPlanAssemblyTracer::Log() { reg_value != m_register_values[reg_num]) { if (reg_value.GetType() != RegisterValue::eTypeInvalid) { stream->PutCString("\n\t"); - reg_value.Dump(stream, reg_info, true, false, eFormatDefault); + DumpRegisterValue(reg_value, stream, reg_info, true, false, + eFormatDefault); } } m_register_values[reg_num] = reg_value; |