[Lldb-commits] [lldb] r337832 - Move dumping code out of RegisterValue class

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 24 08:48:13 PDT 2018


Author: labath
Date: Tue Jul 24 08:48:13 2018
New Revision: 337832

URL: http://llvm.org/viewvc/llvm-project?rev=337832&view=rev
Log:
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

Added:
    lldb/trunk/include/lldb/Core/DumpRegisterValue.h
    lldb/trunk/source/Core/DumpRegisterValue.cpp
Modified:
    lldb/trunk/include/lldb/Core/RegisterValue.h
    lldb/trunk/source/Commands/CommandObjectRegister.cpp
    lldb/trunk/source/Core/CMakeLists.txt
    lldb/trunk/source/Core/EmulateInstruction.cpp
    lldb/trunk/source/Core/FormatEntity.cpp
    lldb/trunk/source/Core/RegisterValue.cpp
    lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
    lldb/trunk/source/Target/ThreadPlanCallFunction.cpp
    lldb/trunk/source/Target/ThreadPlanTracer.cpp

Added: lldb/trunk/include/lldb/Core/DumpRegisterValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/DumpRegisterValue.h?rev=337832&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Core/DumpRegisterValue.h (added)
+++ lldb/trunk/include/lldb/Core/DumpRegisterValue.h Tue Jul 24 08:48:13 2018
@@ -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 &reg_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

Modified: lldb/trunk/include/lldb/Core/RegisterValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/RegisterValue.h?rev=337832&r1=337831&r2=337832&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/RegisterValue.h (original)
+++ lldb/trunk/include/lldb/Core/RegisterValue.h Tue Jul 24 08:48:13 2018
@@ -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 {

Modified: lldb/trunk/source/Commands/CommandObjectRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectRegister.cpp?rev=337832&r1=337831&r2=337832&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectRegister.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectRegister.cpp Tue Jul 24 08:48:13 2018
@@ -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();

Modified: lldb/trunk/source/Core/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/CMakeLists.txt?rev=337832&r1=337831&r2=337832&view=diff
==============================================================================
--- lldb/trunk/source/Core/CMakeLists.txt (original)
+++ lldb/trunk/source/Core/CMakeLists.txt Tue Jul 24 08:48:13 2018
@@ -18,6 +18,7 @@ add_lldb_library(lldbCore
   Debugger.cpp
   Disassembler.cpp
   DumpDataExtractor.cpp
+  DumpRegisterValue.cpp
   DynamicLoader.cpp
   EmulateInstruction.cpp
   Event.cpp

Added: lldb/trunk/source/Core/DumpRegisterValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DumpRegisterValue.cpp?rev=337832&view=auto
==============================================================================
--- lldb/trunk/source/Core/DumpRegisterValue.cpp (added)
+++ lldb/trunk/source/Core/DumpRegisterValue.cpp Tue Jul 24 08:48:13 2018
@@ -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 &reg_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;
+}

Modified: lldb/trunk/source/Core/EmulateInstruction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/EmulateInstruction.cpp?rev=337832&r1=337831&r2=337832&view=diff
==============================================================================
--- lldb/trunk/source/Core/EmulateInstruction.cpp (original)
+++ lldb/trunk/source/Core/EmulateInstruction.cpp Tue Jul 24 08:48:13 2018
@@ -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::WriteRegisterDe
                                               const RegisterValue &reg_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();

Modified: lldb/trunk/source/Core/FormatEntity.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatEntity.cpp?rev=337832&r1=337831&r2=337832&view=diff
==============================================================================
--- lldb/trunk/source/Core/FormatEntity.cpp (original)
+++ lldb/trunk/source/Core/FormatEntity.cpp Tue Jul 24 08:48:13 2018
@@ -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, Stac
         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, Stac
       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;
         }
       }

Modified: lldb/trunk/source/Core/RegisterValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/RegisterValue.cpp?rev=337832&r1=337831&r2=337832&view=diff
==============================================================================
--- lldb/trunk/source/Core/RegisterValue.cpp (original)
+++ lldb/trunk/source/Core/RegisterValue.cpp Tue Jul 24 08:48:13 2018
@@ -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;
 }

Modified: lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp?rev=337832&r1=337831&r2=337832&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp (original)
+++ lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp Tue Jul 24 08:48:13 2018
@@ -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::ReadRe
     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::WriteR
     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());

Modified: lldb/trunk/source/Target/ThreadPlanCallFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanCallFunction.cpp?rev=337832&r1=337831&r2=337832&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadPlanCallFunction.cpp (original)
+++ lldb/trunk/source/Target/ThreadPlanCallFunction.cpp Tue Jul 24 08:48:13 2018
@@ -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::ReportRegis
          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();
       }
     }

Modified: lldb/trunk/source/Target/ThreadPlanTracer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanTracer.cpp?rev=337832&r1=337831&r2=337832&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadPlanTracer.cpp (original)
+++ lldb/trunk/source/Target/ThreadPlanTracer.cpp Tue Jul 24 08:48:13 2018
@@ -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;




More information about the lldb-commits mailing list