[Lldb-commits] [lldb] r158039 - in /lldb/trunk: include/lldb/Core/RegisterValue.h source/Commands/CommandObjectRegister.cpp source/Core/RegisterValue.cpp

Johnny Chen johnny.chen at apple.com
Tue Jun 5 16:25:11 PDT 2012


Author: johnny
Date: Tue Jun  5 18:25:10 2012
New Revision: 158039

URL: http://llvm.org/viewvc/llvm-project?rev=158039&view=rev
Log:
rdar://problem/11598332

The output of 'register read' should be prettier.
Modify RegisterValue::Dump() to take an additional parameter:

    uint32_t reg_name_right_align_at

which defaults to 0 (i.e., no alignment at all).  Update the 'register read' command impl to pass 8
as the alignment to RegisterValue::Dump() method.  If more sophisticated scheme is desired, we will
need to introduce an additional command option to 'register read' later on.

Modified:
    lldb/trunk/include/lldb/Core/RegisterValue.h
    lldb/trunk/source/Commands/CommandObjectRegister.cpp
    lldb/trunk/source/Core/RegisterValue.cpp

Modified: lldb/trunk/include/lldb/Core/RegisterValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/RegisterValue.h?rev=158039&r1=158038&r2=158039&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/RegisterValue.h (original)
+++ lldb/trunk/include/lldb/Core/RegisterValue.h Tue Jun  5 18:25:10 2012
@@ -348,12 +348,14 @@
                           uint32_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) const;
+              lldb::Format format,
+              uint32_t reg_name_right_align_at = 0) const;
 
         void *
         GetBytes ();

Modified: lldb/trunk/source/Commands/CommandObjectRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectRegister.cpp?rev=158039&r1=158038&r2=158039&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectRegister.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectRegister.cpp Tue Jun  5 18:25:10 2012
@@ -95,7 +95,7 @@
 
                 bool prefix_with_altname = 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());
+                reg_value.Dump(&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/RegisterValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/RegisterValue.cpp?rev=158039&r1=158038&r2=158039&view=diff
==============================================================================
--- lldb/trunk/source/Core/RegisterValue.cpp (original)
+++ lldb/trunk/source/Core/RegisterValue.cpp Tue Jun  5 18:25:10 2012
@@ -17,6 +17,7 @@
 #include "lldb/Core/Error.h"
 #include "lldb/Core/Scalar.h"
 #include "lldb/Core/Stream.h"
+#include "lldb/Core/StreamString.h"
 #include "lldb/Interpreter/Args.h"
 
 using namespace lldb;
@@ -28,22 +29,34 @@
                      const RegisterInfo *reg_info, 
                      bool prefix_with_name, 
                      bool prefix_with_alt_name, 
-                     Format format) const
+                     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");
+        const char *fmt = format_string.GetData();
         if (prefix_with_name)
         {
             if (reg_info->name)
             {
-                s->Printf ("%s", reg_info->name);
+                s->Printf (fmt, reg_info->name);
                 name_printed = true;
             }
             else if (reg_info->alt_name)
             {
-                s->Printf ("%s", reg_info->alt_name);
+                s->Printf (fmt, reg_info->alt_name);
                 prefix_with_alt_name = false;
                 name_printed = true;
             }
@@ -54,13 +67,13 @@
                 s->PutChar ('/');
             if (reg_info->alt_name)
             {
-                s->Printf ("%s", reg_info->alt_name);
+                s->Printf (fmt, 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 ("%s", reg_info->name);
+                s->Printf (fmt, reg_info->name);
                 name_printed = true;
             }
         }





More information about the lldb-commits mailing list