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
diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt
index 64c5661..927a0dc 100644
--- a/lldb/source/Core/CMakeLists.txt
+++ b/lldb/source/Core/CMakeLists.txt
@@ -18,6 +18,7 @@
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 0000000..99334ca
--- /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 2ee2c79..4690221 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 @@
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 de9263f..2257b7e 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 @@
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 @@
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 07dd96d..4f90860 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;
}