[Lldb-commits] [lldb] r130436 - in /lldb/trunk: include/lldb/Core/ include/lldb/Interpreter/ source/Commands/ source/Core/ source/Interpreter/

Greg Clayton gclayton at apple.com
Thu Apr 28 13:55:26 PDT 2011


Author: gclayton
Date: Thu Apr 28 15:55:26 2011
New Revision: 130436

URL: http://llvm.org/viewvc/llvm-project?rev=130436&view=rev
Log:
Added the ability to specify dumping options (show types, show location,
depth control, pointer depth, and more) when dumping memory and viewing as
a type.


Modified:
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/include/lldb/Interpreter/Args.h
    lldb/trunk/include/lldb/Interpreter/NamedOptionValue.h
    lldb/trunk/include/lldb/Interpreter/OptionGroupFormat.h
    lldb/trunk/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h
    lldb/trunk/source/Commands/CommandObjectExpression.cpp
    lldb/trunk/source/Commands/CommandObjectFrame.cpp
    lldb/trunk/source/Commands/CommandObjectMemory.cpp
    lldb/trunk/source/Commands/CommandObjectRegister.cpp
    lldb/trunk/source/Core/DataExtractor.cpp
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/Interpreter/Args.cpp
    lldb/trunk/source/Interpreter/NamedOptionValue.cpp
    lldb/trunk/source/Interpreter/OptionGroupFormat.cpp
    lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Thu Apr 28 15:55:26 2011
@@ -426,6 +426,8 @@
     lldb::Format
     GetFormat () const
     {
+        if (m_parent && m_format == lldb::eFormatDefault)
+            return m_parent->GetFormat();
         return m_format;
     }
     
@@ -467,8 +469,8 @@
     //------------------------------------------------------------------
     // Classes that inherit from ValueObject can see and modify these
     //------------------------------------------------------------------
-    ValueObject  *m_parent;       // The parent value object, or NULL if this has no parent
-    EvaluationPoint      m_update_point; // Stores both the stop id and the full context at which this value was last 
+    ValueObject  *      m_parent;       // The parent value object, or NULL if this has no parent
+    EvaluationPoint     m_update_point; // Stores both the stop id and the full context at which this value was last 
                                         // updated.  When we are asked to update the value object, we check whether
                                         // the context & stop id are the same before updating.
     ConstString         m_name;         // The name of this object

Modified: lldb/trunk/include/lldb/Interpreter/Args.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/Args.h?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/Args.h (original)
+++ lldb/trunk/include/lldb/Interpreter/Args.h Thu Apr 28 15:55:26 2011
@@ -360,7 +360,9 @@
     StringToScriptLanguage (const char *s, lldb::ScriptLanguage fail_value, bool *success_ptr);
 
     static Error
-    StringToFormat (const char *s, lldb::Format &format);
+    StringToFormat (const char *s,
+                    lldb::Format &format,
+                    uint32_t *byte_size_ptr); // If non-NULL, then a byte size can precede the format character
 
     static const char *
     StringToVersion (const char *s, uint32_t &major, uint32_t &minor, uint32_t &update);

Modified: lldb/trunk/include/lldb/Interpreter/NamedOptionValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/NamedOptionValue.h?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/NamedOptionValue.h (original)
+++ lldb/trunk/include/lldb/Interpreter/NamedOptionValue.h Thu Apr 28 15:55:26 2011
@@ -123,6 +123,12 @@
         lldb::Format
         GetFormatValue (lldb::Format fail_value = lldb::eFormatDefault);
 
+        bool
+        OptionWasSet () const
+        {
+            return m_value_was_set;
+        }
+
     protected:
         bool m_value_was_set; // This can be used to see if a value has been set
                               // by a call to SetValueFromCString(). It is often
@@ -392,6 +398,11 @@
             return m_current_value;
         }
 
+        operator uint64_t () const
+        {
+            return m_current_value;
+        }
+
         uint64_t
         GetCurrentValue() const
         {
@@ -628,22 +639,16 @@
     class OptionValueFormat : public OptionValue
     {
     public:
-        OptionValueFormat () :
-            m_current_value (lldb::eFormatInvalid),
-            m_default_value (lldb::eFormatDefault)
-        {
-        }
-        
-        OptionValueFormat (lldb::Format current_value) :
-            m_current_value (current_value),
-            m_default_value (lldb::eFormatDefault)
-        {
-        }
-        
-        OptionValueFormat (lldb::Format current_value, 
-                           lldb::Format default_value) :
+        OptionValueFormat (lldb::Format current_value = lldb::eFormatDefault, 
+                           lldb::Format default_value = lldb::eFormatDefault,
+                           uint32_t current_byte_size = 0,
+                           uint32_t default_byte_size = 0,
+                           bool byte_size_prefix_ok = false) :
             m_current_value (current_value),
-            m_default_value (default_value)
+            m_default_value (default_value),
+            m_current_byte_size (current_byte_size),
+            m_default_byte_size (default_byte_size),
+            m_byte_size_prefix_ok (byte_size_prefix_ok)
         {
         }
         
@@ -681,7 +686,7 @@
         //---------------------------------------------------------------------
         
         lldb::Format
-        GetCurrentValue()
+        GetCurrentValue() const
         {
             return m_current_value;
         }
@@ -704,9 +709,36 @@
             m_default_value = value;
         }
         
+        uint32_t 
+        GetCurrentByteSize () const
+        {
+            return m_current_byte_size;
+        }
+
+        uint32_t 
+        GetDefaultByteSize () const
+        {
+            return m_default_byte_size;
+        }
+        
+        void
+        SetCurrentByteSize (uint32_t byte_size)
+        {
+            m_current_byte_size = byte_size;
+        }
+        
+        void
+        SetDefaultByteSize (uint32_t byte_size)
+        {
+            m_default_byte_size = byte_size;
+        }
+
     protected:
         lldb::Format m_current_value;
         lldb::Format m_default_value;
+        uint32_t m_current_byte_size;
+        uint32_t m_default_byte_size;
+        bool m_byte_size_prefix_ok;
     };
     
     //---------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Interpreter/OptionGroupFormat.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionGroupFormat.h?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionGroupFormat.h (original)
+++ lldb/trunk/include/lldb/Interpreter/OptionGroupFormat.h Thu Apr 28 15:55:26 2011
@@ -27,7 +27,9 @@
 {
 public:
     
-    OptionGroupFormat (lldb::Format default_format);
+    OptionGroupFormat (lldb::Format default_format, 
+                       uint32_t default_byte_size,
+                       bool byte_size_prefix_ok);
     
     virtual
     ~OptionGroupFormat ();
@@ -48,11 +50,16 @@
     OptionParsingStarting (CommandInterpreter &interpreter);
     
     lldb::Format
-    GetFormat ()
+    GetFormat () const
     {
         return m_format.GetCurrentValue();
     }
 
+    uint32_t
+    GetByteSize() const
+    {
+        return m_format.GetCurrentByteSize();
+    }
     
 protected:
 

Modified: lldb/trunk/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h (original)
+++ lldb/trunk/include/lldb/Interpreter/OptionGroupValueObjectDisplay.h Thu Apr 28 15:55:26 2011
@@ -53,7 +53,6 @@
     bool use_objc;
     uint32_t max_depth;
     uint32_t ptr_depth;
-    lldb::Format format;
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Thu Apr 28 15:55:26 2011
@@ -70,7 +70,7 @@
         break;
 
     case 'f':
-        error = Args::StringToFormat(option_arg, format);
+        error = Args::StringToFormat(option_arg, format, NULL);
         break;
         
     case 'o':

Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Thu Apr 28 15:55:26 2011
@@ -334,7 +334,7 @@
             case 'L':   show_location= true;  break;
             case 'c':   show_decl    = true;  break;
             case 'D':   debug        = true;  break;
-            case 'f':   error = Args::StringToFormat(option_arg, format); break;
+            case 'f':   error = Args::StringToFormat(option_arg, format, NULL); break;
             case 'F':   flat_output  = true;  break;
             case 'A':
                 max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);

Modified: lldb/trunk/source/Commands/CommandObjectMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMemory.cpp?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMemory.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMemory.cpp Thu Apr 28 15:55:26 2011
@@ -24,13 +24,14 @@
 #include "lldb/Interpreter/Options.h"
 #include "lldb/Interpreter/OptionGroupFormat.h"
 #include "lldb/Interpreter/OptionGroupOutputFile.h"
+#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/StackFrame.h"
 
 using namespace lldb;
 using namespace lldb_private;
 
-OptionDefinition
+static OptionDefinition
 g_option_table[] =
 {
     { LLDB_OPT_SET_1|
@@ -49,9 +50,9 @@
 public:
 
     OptionGroupReadMemory () :
-        m_byte_size (0,0),
-        m_count (0,0),
-        m_num_per_line (0,0),
+        m_byte_size (1,1),
+        m_count (8,8),
+        m_num_per_line (1,1),
         m_output_as_binary (false),
         m_view_as_type()
     {
@@ -128,26 +129,55 @@
         m_view_as_type.Clear();
     }
     
-    void
-    FinalizeSettings (lldb::Format format)
+    Error
+    FinalizeSettings (Target *target, const OptionGroupFormat& format_options)
     {
-        if (m_num_per_line.GetCurrentValue() == 0)
-            m_num_per_line.SetCurrentValue(1);
-
-        switch (format)
+        Error error;
+        bool byte_size_option_set = m_byte_size.OptionWasSet();
+        const bool num_per_line_option_set = m_num_per_line.OptionWasSet();
+        const bool count_option_set = m_count.OptionWasSet();
+        
+        uint32_t format_byte_size = format_options.GetByteSize();
+        if (byte_size_option_set)
+        {
+            if (format_byte_size > 0)
+            {
+                error.SetErrorString("can't specify the byte size in both the '--size <num>' option and the '--format [<byte-size>]<format-char>' options.");
+                return error;
+            }
+        }
+        else
+        {
+            if (format_byte_size != 0)
+            {
+                byte_size_option_set = true;
+                m_byte_size = format_byte_size;
+            }
+        }
+    
+        switch (format_options.GetFormat())
         {
             default:
                 break;
                 
             case eFormatBoolean:
-                if (m_byte_size.GetCurrentValue() == 0)
+                if (!byte_size_option_set)
                     m_byte_size = 1;
+                if (!num_per_line_option_set)
+                    m_num_per_line = 1;
+                if (!count_option_set)
+                    m_count = 8;
                 break;
                 
             case eFormatCString:
                 break;
                 
             case eFormatPointer:
+                m_byte_size = target->GetArchitecture().GetAddressByteSize();
+                if (!num_per_line_option_set)
+                    m_num_per_line = 4;
+                if (!count_option_set)
+                    m_count = 8;
                 break;
                 
             case eFormatBinary:
@@ -158,27 +188,69 @@
             case eFormatUnicode16:
             case eFormatUnicode32:
             case eFormatUnsigned:
-                if (m_byte_size.GetCurrentValue() == 0)
+                if (!byte_size_option_set)
                     m_byte_size = 4;
+                if (!num_per_line_option_set)
+                    m_num_per_line = 1;
+                if (!count_option_set)
+                    m_count = 8;
                 break;
                 
             case eFormatBytes:
             case eFormatBytesWithASCII:
-                if (m_byte_size.GetCurrentValue() == 0)
+                if (m_byte_size.OptionWasSet())
+                {
+                    if (m_byte_size > 1)
+                        error.SetErrorString ("use --count option to specify an end address to display a number of bytes");
+                }
+                else
                     m_byte_size = 1;
+                if (!num_per_line_option_set)
+                    m_num_per_line = 16;
+                if (!count_option_set)
+                    m_count = 32;
                 break;
             case eFormatChar:
             case eFormatCharPrintable:
-                if (m_byte_size.GetCurrentValue() == 0)
+                if (!byte_size_option_set)
                     m_byte_size = 1;
+                if (!num_per_line_option_set)
+                    m_num_per_line = 32;
+                if (!count_option_set)
+                    m_count = 64;
                 break;
             case eFormatComplex:
-                if (m_byte_size.GetCurrentValue() == 0)
+                if (!byte_size_option_set)
                     m_byte_size = 8;
+                if (!num_per_line_option_set)
+                    m_num_per_line = 1;
+                if (!count_option_set)
+                    m_count = 8;
                 break;
             case eFormatHex:
-                if (m_byte_size.GetCurrentValue() == 0)
+                if (!byte_size_option_set)
                     m_byte_size = 4;
+                if (!num_per_line_option_set)
+                {
+                    switch (m_byte_size)
+                    {
+                        case 1:
+                        case 2:
+                            m_num_per_line = 8;
+                            break;
+                        case 4:
+                            m_num_per_line = 4;
+                            break;
+                        case 8:
+                            m_num_per_line = 2;
+                            break;
+                        default:
+                            m_num_per_line = 1;
+                            break;
+                    }
+                }
+                if (!count_option_set)
+                    m_count = 8;
                 break;
                 
             case eFormatVectorOfChar:
@@ -193,8 +265,15 @@
             case eFormatVectorOfFloat32:
             case eFormatVectorOfFloat64:
             case eFormatVectorOfUInt128:
+                if (!byte_size_option_set)
+                    m_byte_size = 128;
+                if (!num_per_line_option_set)
+                    m_num_per_line = 1;
+                if (!count_option_set)
+                    m_count = 4;
                 break;
         }
+        return error;
     }
 
     OptionValueUInt64 m_byte_size;
@@ -213,172 +292,6 @@
 {
 public:
 
-//    class CommandOptions : public Options
-//    {
-//    public:
-//        CommandOptions (CommandInterpreter &interpreter) :
-//            Options(interpreter)
-//        {
-//            OptionParsingStarting();
-//        }
-//
-//        virtual
-//        ~CommandOptions ()
-//        {
-//        }
-//
-//        virtual Error
-//        SetOptionValue (uint32_t option_idx, const char *option_arg)
-//        {
-//            Error error;
-//            char short_option = (char) m_getopt_table[option_idx].val;
-//
-//            switch (short_option)
-//            {
-//            case 'f':
-//                error = Args::StringToFormat (option_arg, m_format);
-//
-//                switch (m_format)
-//                {
-//                default:
-//                    break;
-//
-//                case eFormatBoolean:
-//                    if (m_byte_size == 0)
-//                        m_byte_size = 1;
-//                    if (m_num_per_line == 0)
-//                        m_num_per_line = 1;
-//                    break;
-//
-//                case eFormatCString:
-//                    if (m_num_per_line == 0)
-//                        m_num_per_line = 1;
-//                    break;
-//
-//                case eFormatPointer:
-//                    break;
-//
-//                case eFormatBinary:
-//                case eFormatFloat:
-//                case eFormatOctal:
-//                case eFormatDecimal:
-//                case eFormatEnum:
-//                case eFormatUnicode16:
-//                case eFormatUnicode32:
-//                case eFormatUnsigned:
-//                    if (m_byte_size == 0)
-//                        m_byte_size = 4;
-//                    if (m_num_per_line == 0)
-//                        m_num_per_line = 1;
-//                    break;
-//
-//                case eFormatBytes:
-//                case eFormatBytesWithASCII:
-//                case eFormatChar:
-//                case eFormatCharPrintable:
-//                    if (m_byte_size == 0)
-//                        m_byte_size = 1;
-//                    break;
-//                case eFormatComplex:
-//                    if (m_byte_size == 0)
-//                        m_byte_size = 8;
-//                    break;
-//                case eFormatHex:
-//                    if (m_byte_size == 0)
-//                        m_byte_size = 4;
-//                    break;
-//
-//                case eFormatVectorOfChar:
-//                case eFormatVectorOfSInt8:
-//                case eFormatVectorOfUInt8:
-//                case eFormatVectorOfSInt16:
-//                case eFormatVectorOfUInt16:
-//                case eFormatVectorOfSInt32:
-//                case eFormatVectorOfUInt32:
-//                case eFormatVectorOfSInt64:
-//                case eFormatVectorOfUInt64:
-//                case eFormatVectorOfFloat32:
-//                case eFormatVectorOfFloat64:
-//                case eFormatVectorOfUInt128:
-//                    break;
-//                }
-//                break;
-//
-//            case 'l':
-//                m_num_per_line = Args::StringToUInt32 (option_arg, 0);
-//                if (m_num_per_line == 0)
-//                    error.SetErrorStringWithFormat("Invalid value for --num-per-line option '%s'. Must be positive integer value.\n", option_arg);
-//                break;
-//
-//            case 'c':
-//                m_count = Args::StringToUInt32 (option_arg, 0);
-//                if (m_count == 0)
-//                    error.SetErrorStringWithFormat("Invalid value for --count option '%s'. Must be positive integer value.\n", option_arg);
-//                break;
-//
-//            case 's':
-//                m_byte_size = Args::StringToUInt32 (option_arg, 0);
-//                if (m_byte_size == 0)
-//                    error.SetErrorStringWithFormat("Invalid value for --size option '%s'. Must be positive integer value.\n", option_arg);
-//                break;
-//
-//            case 'o':
-//                m_outfile_filespec.SetFile (option_arg, true);
-//                break;
-//
-//            case 'b':
-//                m_output_as_binary = true;
-//                break;
-//
-//            case 'a':
-//                m_append_to_outfile = true;
-//                break;
-//            
-//            case 't':
-//                m_view_as_type.assign (option_arg);
-//                break;
-//
-//            default:
-//                error.SetErrorStringWithFormat("Unrecognized short option '%c'.\n", short_option);
-//                break;
-//            }
-//            return error;
-//        }
-//
-//        void
-//        OptionParsingStarting ()
-//        {
-//            m_format = eFormatBytesWithASCII;
-//            m_byte_size = 0;
-//            m_count = 0;
-//            m_num_per_line = 0;
-//            m_outfile_filespec.Clear();
-//            m_view_as_type.clear();
-//            m_append_to_outfile = false;
-//            m_output_as_binary = false;
-//        }
-//
-//        const OptionDefinition*
-//        GetDefinitions ()
-//        {
-//            return g_option_table;
-//        }
-//
-//        // Options table: Required for subclasses of Options.
-//
-//        static OptionDefinition g_option_table[];
-//
-//        // Instance variables to hold the values for command options.
-//        lldb::Format m_format;
-//        uint32_t m_byte_size;
-//        uint32_t m_count;
-//        uint32_t m_num_per_line;
-//        FileSpec m_outfile_filespec;
-//        std::string m_view_as_type;
-//        bool m_append_to_outfile;
-//        bool m_output_as_binary;
-//    };
-
     CommandObjectMemoryRead (CommandInterpreter &interpreter) :
         CommandObject (interpreter,
                        "memory read",
@@ -386,9 +299,10 @@
                        NULL,
                        eFlagProcessMustBeLaunched),
         m_option_group (interpreter),
-        m_format_options (eFormatBytesWithASCII),
+        m_format_options (eFormatBytesWithASCII, 0, true),
         m_memory_options (),
-        m_outfile_options ()
+        m_outfile_options (),
+        m_varobj_options()
     {
         CommandArgumentEntry arg1;
         CommandArgumentEntry arg2;
@@ -416,8 +330,8 @@
         m_option_group.Append (&m_format_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1 | LLDB_OPT_SET_3);
         m_option_group.Append (&m_memory_options);
         m_option_group.Append (&m_outfile_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3);
+        m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_3);
         m_option_group.Finalize();
-
     }
 
     virtual
@@ -452,9 +366,10 @@
             return false;
         }
 
-        size_t item_byte_size = m_memory_options.m_byte_size.GetCurrentValue();
-        ClangASTType clang_ast_type;
-        
+        ClangASTType clang_ast_type;        
+        Error error;
+
+        Format format = m_format_options.GetFormat();
         const char *view_as_type_cstr = m_memory_options.m_view_as_type.GetCurrentValue();
         if (view_as_type_cstr && view_as_type_cstr[0])
         {
@@ -571,42 +486,36 @@
                 --pointer_count;
             }
 
-            item_byte_size = (clang_ast_type.GetClangTypeBitWidth () + 7) / 8;
+            m_memory_options.m_byte_size = (clang_ast_type.GetClangTypeBitWidth () + 7) / 8;
             
-            if (item_byte_size == 0)
+            if (m_memory_options.m_byte_size == 0)
             {
                 result.AppendErrorWithFormat ("unable to get the byte size of the type '%s'\n", 
                                               view_as_type_cstr);
                 result.SetStatus(eReturnStatusFailed);
                 return false;
             }
+            
+            if (!m_memory_options.m_count.OptionWasSet())
+                m_memory_options.m_count = 1;
         }
         else
         {
-            if (item_byte_size == 0)
-            {
-                if (m_format_options.GetFormat() == eFormatPointer)
-                    item_byte_size = exe_ctx.target->GetArchitecture().GetAddressByteSize();
-                else
-                    item_byte_size = 1;
-            }
+            error = m_memory_options.FinalizeSettings (exe_ctx.target, m_format_options);
         }
 
-        size_t item_count = m_memory_options.m_count.GetCurrentValue();
-
-        size_t num_per_line = m_memory_options.m_num_per_line.GetCurrentValue();
-        if (num_per_line == 0)
+        // Look for invalid combinations of settings
+        if (error.Fail())
         {
-            if (clang_ast_type.GetOpaqueQualType())
-                num_per_line = 1;
-            else
-            {
-                num_per_line = (16/item_byte_size);
-                if (num_per_line == 0)
-                    num_per_line = 1;
-            }
+            result.AppendErrorWithFormat("%s", error.AsCString());
+            result.SetStatus(eReturnStatusFailed);
+            return false;
         }
 
+        size_t item_count = m_memory_options.m_count.GetCurrentValue();
+        const size_t item_byte_size = m_memory_options.m_byte_size;
+        const size_t num_per_line = m_memory_options.m_num_per_line.GetCurrentValue();
+
         size_t total_byte_size = item_count * item_byte_size;
         if (total_byte_size == 0)
             total_byte_size = 32;
@@ -625,19 +534,19 @@
             lldb::addr_t end_addr = Args::StringToUInt64(command.GetArgumentAtIndex(1), LLDB_INVALID_ADDRESS, 0);
             if (end_addr == LLDB_INVALID_ADDRESS)
             {
-                result.AppendErrorWithFormat("Invalid end address string '%s'.\n", command.GetArgumentAtIndex(1));
+                result.AppendErrorWithFormat("invalid end address string '%s'.\n", command.GetArgumentAtIndex(1));
                 result.SetStatus(eReturnStatusFailed);
                 return false;
             }
             else if (end_addr <= addr)
             {
-                result.AppendErrorWithFormat("End address (0x%llx) must be greater that the start address (0x%llx).\n", end_addr, addr);
+                result.AppendErrorWithFormat("end address (0x%llx) must be greater that the start address (0x%llx).\n", end_addr, addr);
                 result.SetStatus(eReturnStatusFailed);
                 return false;
             }
-            else if (item_count != 0)
+            else if (m_memory_options.m_count.OptionWasSet())
             {
-                result.AppendErrorWithFormat("Specify either the end address (0x%llx) or the count (--count %u), not both.\n", end_addr, item_count);
+                result.AppendErrorWithFormat("specify either the end address (0x%llx) or the count (--count %u), not both.\n", end_addr, item_count);
                 result.SetStatus(eReturnStatusFailed);
                 return false;
             }
@@ -645,19 +554,8 @@
             total_byte_size = end_addr - addr;
             item_count = total_byte_size / item_byte_size;
         }
-        else
-        {
-            if (item_count == 0)
-            {
-                if (clang_ast_type.GetOpaqueQualType())
-                    item_count = 1;
-                else
-                    item_count = 32;
-            }
-        }
         
         DataBufferSP data_sp;
-        Error error;
         size_t bytes_read = 0;
         if (!clang_ast_type.GetOpaqueQualType())
         {
@@ -742,28 +640,24 @@
                                                                     clang_ast_type));
                 if (valobj_sp)
                 {
-                    uint32_t ptr_depth = 0;
-                    uint32_t curr_depth = 0;
-                    uint32_t max_depth = UINT32_MAX;
-                    bool show_types = false;
-                    bool show_location = false;
-                    bool use_objc = false;
+                    if (format != eFormatDefault)
+                        valobj_sp->SetFormat (format);
+
                     bool use_dynamic = false;
-                    bool scope_already_checked = false;
-                    bool flat_output = false;
+                    bool scope_already_checked = true;
                     
                     ValueObject::DumpValueObject (*output_stream,
                                                   valobj_sp.get(),
                                                   NULL,
-                                                  ptr_depth,
-                                                  curr_depth,
-                                                  max_depth,
-                                                  show_types,
-                                                  show_location,
-                                                  use_objc,
+                                                  m_varobj_options.ptr_depth,
+                                                  0,
+                                                  m_varobj_options.max_depth,
+                                                  m_varobj_options.show_types,
+                                                  m_varobj_options.show_location,
+                                                  m_varobj_options.use_objc,
                                                   use_dynamic,
                                                   scope_already_checked,
-                                                  flat_output);
+                                                  m_varobj_options.flat_output);
                 }
                 else
                 {
@@ -803,6 +697,7 @@
     OptionGroupFormat m_format_options;
     OptionGroupReadMemory m_memory_options;
     OptionGroupOutputFile m_outfile_options;
+    OptionGroupValueObjectDisplay m_varobj_options;
 
 };
 
@@ -855,7 +750,7 @@
             switch (short_option)
             {
             case 'f':
-                error = Args::StringToFormat (option_arg, m_format);
+                error = Args::StringToFormat (option_arg, m_format, &m_byte_size);
                 break;
 
             case 's':

Modified: lldb/trunk/source/Commands/CommandObjectRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectRegister.cpp?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectRegister.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectRegister.cpp Thu Apr 28 15:55:26 2011
@@ -265,7 +265,7 @@
             switch (short_option)
             {
                 case 'f':
-                    error = Args::StringToFormat (option_arg, format);
+                    error = Args::StringToFormat (option_arg, format, NULL);
                     break;
 
                 case 's':

Modified: lldb/trunk/source/Core/DataExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataExtractor.cpp?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataExtractor.cpp (original)
+++ lldb/trunk/source/Core/DataExtractor.cpp Thu Apr 28 15:55:26 2011
@@ -1446,24 +1446,20 @@
             {
                 assert (item_bit_size == 0 && item_bit_offset == 0);
                 s->PutCString("0x");
-                int32_t start_idx, end_idx, delta;
-                if (m_byte_order == eByteOrderBig)
-                {
-                    start_idx = offset;
-                    end_idx = offset + item_byte_size;
-                    delta = 1;
-                }
-                else
-                {
-                    start_idx = offset + item_byte_size - 1;
-                    end_idx = -1;
-                    delta = -1;
-                }
                 const uint8_t *bytes = (const uint8_t* )GetData(&offset, item_byte_size);
                 if (bytes)
                 {
-                    for (int32_t idx = start_idx; idx != end_idx; idx += delta)
-                        s->Printf("%2.2x", bytes[idx]);
+                    uint32_t idx;
+                    if (m_byte_order == eByteOrderBig)
+                    {
+                        for (idx = 0; idx < item_byte_size; ++idx)
+                            s->Printf("%2.2x", bytes[idx]);
+                    }
+                    else
+                    {
+                        for (idx = 0; idx < item_byte_size; ++idx)
+                            s->Printf("%2.2x", bytes[item_byte_size - 1 - idx]);
+                    }
                 }
             }
             break;

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Thu Apr 28 15:55:26 2011
@@ -674,13 +674,14 @@
                         if (clang_type)
                         {
                             StreamString sstr;
-                            if (m_format == eFormatDefault)
-                                m_format = ClangASTType::GetFormat(clang_type);
+                            Format format = GetFormat();
+                            if (format == eFormatDefault)
+                                format = ClangASTType::GetFormat(clang_type);
 
                             if (ClangASTType::DumpTypeValue (GetClangAST(),            // The clang AST
                                                              clang_type,               // The clang type to display
                                                              &sstr,
-                                                             m_format,                 // Format to display this type with
+                                                             format,                   // Format to display this type with
                                                              m_data,                   // Data to extract from
                                                              0,                        // Byte offset into "m_data"
                                                              GetByteSize(),            // Byte size of item in "m_data"

Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Thu Apr 28 15:55:26 2011
@@ -876,7 +876,8 @@
 Args::StringToFormat
 (
     const char *s,
-    lldb::Format &format
+    lldb::Format &format,
+    uint32_t *byte_size_ptr
 )
 {
     format = eFormatInvalid;
@@ -884,29 +885,51 @@
 
     if (s && s[0])
     {
-        switch (s[0])
+        if (byte_size_ptr)
         {
-        case 'y': format = eFormatBytes;            break;
-        case 'Y': format = eFormatBytesWithASCII;   break;
-        case 'b': format = eFormatBinary;           break;
-        case 'B': format = eFormatBoolean;          break;
-        case 'c': format = eFormatChar;             break;
-        case 'C': format = eFormatCharPrintable;    break;
-        case 'o': format = eFormatOctal;            break;
-        case 'O': format = eFormatOSType;           break;
-        case 'i':
-        case 'd': format = eFormatDecimal;          break;
-        case 'I': format = eFormatComplexInteger;   break;
-        case 'u': format = eFormatUnsigned;         break;
-        case 'x': format = eFormatHex;              break;
-        case 'X': format = eFormatComplex;          break;
-        case 'f':
-        case 'e':
-        case 'g': format = eFormatFloat;            break;
-        case 'p': format = eFormatPointer;          break;
-        case 's': format = eFormatCString;          break;
-        default:
-            error.SetErrorStringWithFormat("Invalid format character '%c'. Valid values are:\n"
+            if (isdigit (s[0]))
+            {
+                char *format_char = NULL;
+                unsigned long byte_size = ::strtoul (s, &format_char, 0);
+                if (byte_size != ULONG_MAX)
+                    *byte_size_ptr = byte_size;
+                s = format_char;
+            }
+            else
+                *byte_size_ptr = 0;
+        }
+
+        bool success = s[1] == '\0';
+        if (success)
+        {
+            switch (s[0])
+            {
+            case 'y': format = eFormatBytes;            break;
+            case 'Y': format = eFormatBytesWithASCII;   break;
+            case 'b': format = eFormatBinary;           break;
+            case 'B': format = eFormatBoolean;          break;
+            case 'c': format = eFormatChar;             break;
+            case 'C': format = eFormatCharPrintable;    break;
+            case 'o': format = eFormatOctal;            break;
+            case 'O': format = eFormatOSType;           break;
+            case 'i':
+            case 'd': format = eFormatDecimal;          break;
+            case 'I': format = eFormatComplexInteger;   break;
+            case 'u': format = eFormatUnsigned;         break;
+            case 'x': format = eFormatHex;              break;
+            case 'X': format = eFormatComplex;          break;
+            case 'f':
+            case 'e':
+            case 'g': format = eFormatFloat;            break;
+            case 'p': format = eFormatPointer;          break;
+            case 's': format = eFormatCString;          break;
+            default:
+                success = false;
+                break;
+            }
+        }
+        if (!success)
+            error.SetErrorStringWithFormat ("Invalid format specification '%s'. Valid values are:\n"
                                             "  b - binary\n"
                                             "  B - boolean\n"
                                             "  c - char\n"
@@ -925,9 +948,10 @@
                                             "  x - hex\n"
                                             "  X - complex float\n"
                                             "  y - bytes\n"
-                                            "  Y - bytes with ASCII\n", s[0]);
-            break;
-        }
+                                            "  Y - bytes with ASCII\n%s",
+                                            s, 
+                                            byte_size_ptr ? "An optional byte size can precede the format character.\n" : "");
+
 
         if (error.Fail())
             return error;

Modified: lldb/trunk/source/Interpreter/NamedOptionValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/NamedOptionValue.cpp?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/NamedOptionValue.cpp (original)
+++ lldb/trunk/source/Interpreter/NamedOptionValue.cpp Thu Apr 28 15:55:26 2011
@@ -318,11 +318,14 @@
 OptionValueFormat::SetValueFromCString (const char *value_cstr)
 {
     Format new_format;
-    Error error (Args::StringToFormat(value_cstr, new_format));
+    uint32_t new_byte_size = UINT32_MAX;
+    Error error (Args::StringToFormat(value_cstr, new_format, m_byte_size_prefix_ok ? &new_byte_size : NULL));
     if (error.Success())
     {
         m_value_was_set = true;
         m_current_value = new_format;
+        if (new_byte_size != UINT32_MAX)
+            m_current_byte_size = new_byte_size;
     }
     return error;
 }

Modified: lldb/trunk/source/Interpreter/OptionGroupFormat.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupFormat.cpp?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupFormat.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupFormat.cpp Thu Apr 28 15:55:26 2011
@@ -17,8 +17,14 @@
 using namespace lldb;
 using namespace lldb_private;
 
-OptionGroupFormat::OptionGroupFormat(lldb::Format default_format) :
-    m_format (default_format, default_format)
+OptionGroupFormat::OptionGroupFormat(lldb::Format default_format,
+                                     uint32_t default_byte_size,
+                                     bool byte_size_prefix_ok) :
+    m_format (default_format, 
+              default_format,
+              default_byte_size,
+              default_byte_size,
+              byte_size_prefix_ok)
 {
 }
 
@@ -47,8 +53,8 @@
 
 Error
 OptionGroupFormat::SetOptionValue (CommandInterpreter &interpreter,
-                                         uint32_t option_idx,
-                                         const char *option_arg)
+                                   uint32_t option_idx,
+                                   const char *option_arg)
 {
     Error error;
     char short_option = (char) g_option_table[option_idx].short_option;

Modified: lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp?rev=130436&r1=130435&r2=130436&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupValueObjectDisplay.cpp Thu Apr 28 15:55:26 2011
@@ -25,17 +25,16 @@
 {
 }
 
-OptionDefinition
+static OptionDefinition
 g_option_table[] =
 {
-    { LLDB_OPT_SET_1, false, "depth",           'd', required_argument, NULL, 0, eArgTypeCount,     "Set the max recurse depth when dumping aggregate types (default is infinity)."},
-    { LLDB_OPT_SET_1, false, "format",          'f', required_argument, NULL, 0, eArgTypeExprFormat,"Specify the format that the variable output should use."},
+    { LLDB_OPT_SET_1, false, "depth",           'D', required_argument, NULL, 0, eArgTypeCount,     "Set the max recurse depth when dumping aggregate types (default is infinity)."},
     { LLDB_OPT_SET_1, false, "flat",            'F', no_argument,       NULL, 0, eArgTypeNone,      "Display results in a flat format that uses expression paths for each variable or member."},
     { LLDB_OPT_SET_1, false, "location",        'L', no_argument,       NULL, 0, eArgTypeNone,      "Show variable location information."},
-    { LLDB_OPT_SET_1, false, "objc",            'o', no_argument,       NULL, 0, eArgTypeNone,      "Print as an Objective-C object."},
-    { LLDB_OPT_SET_1, false, "ptr-depth",       'p', required_argument, NULL, 0, eArgTypeCount,     "The number of pointers to be traversed when dumping values (default is zero)."},
-    { LLDB_OPT_SET_1, false, "show-types",      't', no_argument,       NULL, 0, eArgTypeNone,      "Show variable types when dumping values."},
-    { LLDB_OPT_SET_1, false, "no-summary",      'y', no_argument,       NULL, 0, eArgTypeNone,      "Omit summary information."},
+    { LLDB_OPT_SET_1, false, "objc",            'O', no_argument,       NULL, 0, eArgTypeNone,      "Print as an Objective-C object."},
+    { LLDB_OPT_SET_1, false, "ptr-depth",       'P', required_argument, NULL, 0, eArgTypeCount,     "The number of pointers to be traversed when dumping values (default is zero)."},
+    { LLDB_OPT_SET_1, false, "show-types",      'T', no_argument,       NULL, 0, eArgTypeNone,      "Show variable types when dumping values."},
+    { LLDB_OPT_SET_1, false, "no-summary",      'Y', no_argument,       NULL, 0, eArgTypeNone,      "Omit summary information."},
     { 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
 };
 
@@ -65,19 +64,18 @@
 
     switch (short_option)
     {
-        case 't':   show_types   = true;  break;
-        case 'y':   show_summary = false; break;
+        case 'T':   show_types   = true;  break;
+        case 'Y':   show_summary = false; break;
         case 'L':   show_location= true;  break;
         case 'F':   flat_output  = true;  break;
-        case 'f':   error = Args::StringToFormat(option_arg, format); break;
-        case 'o':   use_objc = true;      break;
-        case 'd':
+        case 'O':   use_objc = true;      break;
+        case 'D':
             max_depth = Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success);
             if (!success)
                 error.SetErrorStringWithFormat("Invalid max depth '%s'.\n", option_arg);
             break;
             
-        case 'p':
+        case 'P':
             ptr_depth = Args::StringToUInt32 (option_arg, 0, 0, &success);
             if (!success)
                 error.SetErrorStringWithFormat("Invalid pointer depth '%s'.\n", option_arg);
@@ -101,6 +99,5 @@
     use_objc      = false;
     max_depth     = UINT32_MAX;
     ptr_depth     = 0;
-    format        = eFormatDefault;
 }
 





More information about the lldb-commits mailing list