[Lldb-commits] [lldb] r134594 - in /lldb/trunk: include/lldb/Interpreter/OptionGroupVariable.h lldb.xcodeproj/project.pbxproj source/Commands/CommandObjectFrame.cpp source/Commands/CommandObjectTarget.cpp source/Interpreter/OptionGroupVariable.cpp test/lang/cpp/class_static/TestStaticVariables.py

Greg Clayton gclayton at apple.com
Wed Jul 6 21:38:25 PDT 2011


Author: gclayton
Date: Wed Jul  6 23:38:25 2011
New Revision: 134594

URL: http://llvm.org/viewvc/llvm-project?rev=134594&view=rev
Log:
Centralize the variable display prefs into a new option
group class: OptionGroupVariable. It gets initialized with
a boolean that indicates if the frame specific options are
included so that this can be used in both the "frame variable"
and "target variable" commands.

Removed the global functionality from the "frame variable" 
command. Users should switch to using the "target variable"
command.


Added:
    lldb/trunk/include/lldb/Interpreter/OptionGroupVariable.h
    lldb/trunk/source/Interpreter/OptionGroupVariable.cpp
Modified:
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/Commands/CommandObjectFrame.cpp
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/test/lang/cpp/class_static/TestStaticVariables.py

Added: lldb/trunk/include/lldb/Interpreter/OptionGroupVariable.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionGroupVariable.h?rev=134594&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionGroupVariable.h (added)
+++ lldb/trunk/include/lldb/Interpreter/OptionGroupVariable.h Wed Jul  6 23:38:25 2011
@@ -0,0 +1,63 @@
+//===-- OptionGroupVariable.h -----------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_OptionGroupVariable_h_
+#define liblldb_OptionGroupVariable_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Interpreter/Options.h"
+
+namespace lldb_private {
+
+//-------------------------------------------------------------------------
+// OptionGroupVariable
+//-------------------------------------------------------------------------
+
+    class OptionGroupVariable : public OptionGroup
+    {
+    public:
+        
+        OptionGroupVariable (bool show_frame_options);
+
+        virtual
+        ~OptionGroupVariable ();
+        
+        virtual uint32_t
+        GetNumDefinitions ();
+        
+        virtual const OptionDefinition*
+        GetDefinitions ();
+        
+        virtual Error
+        SetOptionValue (CommandInterpreter &interpreter,
+                        uint32_t option_idx, 
+                        const char *option_arg);
+        
+        virtual void
+        OptionParsingStarting (CommandInterpreter &interpreter);
+        
+        bool include_frame_options:1,
+             show_args:1,       // Frame option only (include_frame_options == true)
+             show_locals:1,     // Frame option only (include_frame_options == true)
+             show_globals:1,    // Frame option only (include_frame_options == true)
+             use_regex:1,
+             show_scope:1,
+             show_decl:1;
+        lldb::Format format;
+
+    private:
+        DISALLOW_COPY_AND_ASSIGN(OptionGroupVariable);
+    };
+    
+} // namespace lldb_private
+
+#endif  // liblldb_OptionGroupVariable_h_

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=134594&r1=134593&r2=134594&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Wed Jul  6 23:38:25 2011
@@ -380,6 +380,7 @@
 		26DE20631161904200A093E2 /* SBLineEntry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26DE20621161904200A093E2 /* SBLineEntry.cpp */; };
 		26DE20651161904E00A093E2 /* SBSymbol.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26DE20641161904E00A093E2 /* SBSymbol.cpp */; };
 		26ECA04313665FED008D1F18 /* ARM_DWARF_Registers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26ECA04213665FED008D1F18 /* ARM_DWARF_Registers.cpp */; };
+		26ED3D6D13C563810017D45E /* OptionGroupVariable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26ED3D6C13C563810017D45E /* OptionGroupVariable.cpp */; };
 		26F5C27710F3D9E4009D5894 /* Driver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F5C27310F3D9E4009D5894 /* Driver.cpp */; };
 		26F5C27810F3D9E4009D5894 /* IOChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F5C27510F3D9E4009D5894 /* IOChannel.cpp */; };
 		26F5C32510F3DF23009D5894 /* libpython.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C32410F3DF23009D5894 /* libpython.dylib */; };
@@ -1048,6 +1049,8 @@
 		26E6902E129C6BD500DDECD9 /* ClangExternalASTSourceCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangExternalASTSourceCallbacks.h; path = include/lldb/Symbol/ClangExternalASTSourceCallbacks.h; sourceTree = "<group>"; };
 		26E69030129C6BEF00DDECD9 /* ClangExternalASTSourceCallbacks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangExternalASTSourceCallbacks.cpp; path = source/Symbol/ClangExternalASTSourceCallbacks.cpp; sourceTree = "<group>"; };
 		26ECA04213665FED008D1F18 /* ARM_DWARF_Registers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ARM_DWARF_Registers.cpp; path = source/Utility/ARM_DWARF_Registers.cpp; sourceTree = "<group>"; };
+		26ED3D6C13C563810017D45E /* OptionGroupVariable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OptionGroupVariable.cpp; path = source/Interpreter/OptionGroupVariable.cpp; sourceTree = "<group>"; };
+		26ED3D6F13C5638A0017D45E /* OptionGroupVariable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = OptionGroupVariable.h; path = include/lldb/Interpreter/OptionGroupVariable.h; sourceTree = "<group>"; };
 		26F5C26A10F3D9A4009D5894 /* lldb */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = lldb; sourceTree = BUILT_PRODUCTS_DIR; };
 		26F5C27210F3D9E4009D5894 /* lldb-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "lldb-Info.plist"; path = "tools/driver/lldb-Info.plist"; sourceTree = "<group>"; };
 		26F5C27310F3D9E4009D5894 /* Driver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Driver.cpp; path = tools/driver/Driver.cpp; sourceTree = "<group>"; };
@@ -2263,6 +2266,8 @@
 				260E07C5136FA69E00CF21D3 /* OptionGroupUUID.cpp */,
 				267C0128136880C7006E963E /* OptionGroupValueObjectDisplay.h */,
 				267C012A136880DF006E963E /* OptionGroupValueObjectDisplay.cpp */,
+				26ED3D6F13C5638A0017D45E /* OptionGroupVariable.h */,
+				26ED3D6C13C563810017D45E /* OptionGroupVariable.cpp */,
 				26BC7DE510F1B7F900F91463 /* ScriptInterpreter.h */,
 				9A82010B10FFB49800182560 /* ScriptInterpreter.cpp */,
 				9A2771FB1135A35C00E6ADB6 /* ScriptInterpreterNone.h */,
@@ -3245,6 +3250,7 @@
 				9415F61813B2C0EF00A52B36 /* FormatManager.cpp in Sources */,
 				49D8FB3913B5598F00411094 /* ClangASTImporter.cpp in Sources */,
 				9467E65213C3D97600B3B6F3 /* TypeHierarchyNavigator.cpp in Sources */,
+				26ED3D6D13C563810017D45E /* OptionGroupVariable.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=134594&r1=134593&r2=134594&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Wed Jul  6 23:38:25 2011
@@ -26,6 +26,7 @@
 #include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Interpreter/Options.h"
 #include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
+#include "lldb/Interpreter/OptionGroupVariable.h"
 #include "lldb/Symbol/ClangASTType.h"
 #include "lldb/Symbol/ClangASTContext.h"
 #include "lldb/Symbol/ObjectFile.h"
@@ -378,7 +379,7 @@
                        NULL,
                        eFlagProcessMustBeLaunched | eFlagProcessMustBePaused),
         m_option_group (interpreter),
-        m_frame_var_options(),
+        m_option_variable(true), // Include the frame specific options by passing "true"
         m_varobj_options()
     {
         CommandArgumentEntry arg;
@@ -394,7 +395,7 @@
         // Push the data for the first argument into the m_arguments vector.
         m_arguments.push_back (arg);
         
-        m_option_group.Append (&m_frame_var_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+        m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
         m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
         m_option_group.Finalize();
     }
@@ -438,73 +439,8 @@
 
             const char *name_cstr = NULL;
             size_t idx;
-            if (!m_frame_var_options.globals.empty())
-            {
-                uint32_t fail_count = 0;
-                if (exe_ctx.target)
-                {
-                    const size_t num_globals = m_frame_var_options.globals.size();
-                    for (idx = 0; idx < num_globals; ++idx)
-                    {
-                        VariableList global_var_list;
-                        const uint32_t num_matching_globals 
-                                = exe_ctx.target->GetImages().FindGlobalVariables (m_frame_var_options.globals[idx], 
-                                                                                   true, 
-                                                                                   UINT32_MAX, 
-                                                                                   global_var_list);
 
-                        if (num_matching_globals == 0)
-                        {
-                            ++fail_count;
-                            result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", 
-                                                            m_frame_var_options.globals[idx].AsCString());
-                        }
-                        else
-                        {
-                            for (uint32_t global_idx=0; global_idx<num_matching_globals; ++global_idx)
-                            {
-                                var_sp = global_var_list.GetVariableAtIndex(global_idx);
-                                if (var_sp)
-                                {
-                                    valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp, 
-                                                                                               m_varobj_options.use_dynamic);
-                                    if (!valobj_sp)
-                                        valobj_sp = exe_ctx.frame->TrackGlobalVariable (var_sp, 
-                                                                                        m_varobj_options.use_dynamic);
-
-                                    if (valobj_sp)
-                                    {
-                                        if (m_frame_var_options.format != eFormatDefault)
-                                            valobj_sp->SetFormat (m_frame_var_options.format);
-
-                                        if (m_frame_var_options.show_decl && var_sp->GetDeclaration ().GetFile())
-                                        {
-                                            var_sp->GetDeclaration ().DumpStopContext (&s, false);
-                                            s.PutCString (": ");
-                                        }
-                                        
-                                        ValueObject::DumpValueObject (result.GetOutputStream(), 
-                                                                      valobj_sp.get(), 
-                                                                      name_cstr, 
-                                                                      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,
-                                                                      m_varobj_options.use_dynamic,
-                                                                      false,
-                                                                      m_varobj_options.flat_output);                                        
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-                if (fail_count)
-                    result.SetStatus (eReturnStatusFailed);
-            }
-            else if (variable_list)
+            if (variable_list)
             {
                 if (command.GetArgumentCount() > 0)
                 {
@@ -516,7 +452,7 @@
                     {
                         uint32_t ptr_depth = m_varobj_options.ptr_depth;
                         
-                        if (m_frame_var_options.use_regex)
+                        if (m_option_variable.use_regex)
                         {
                             const uint32_t regex_start_index = regex_var_list.GetSize();
                             RegularExpression regex (name_cstr);
@@ -538,10 +474,10 @@
                                             valobj_sp = exe_ctx.frame->GetValueObjectForFrameVariable (var_sp, m_varobj_options.use_dynamic);
                                             if (valobj_sp)
                                             {                                        
-                                                if (m_frame_var_options.format != eFormatDefault)
-                                                    valobj_sp->SetFormat (m_frame_var_options.format);
+                                                if (m_option_variable.format != eFormatDefault)
+                                                    valobj_sp->SetFormat (m_option_variable.format);
                                                 
-                                                if (m_frame_var_options.show_decl && var_sp->GetDeclaration ().GetFile())
+                                                if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
                                                 {
                                                     var_sp->GetDeclaration ().DumpStopContext (&s, false);
                                                     s.PutCString (": ");
@@ -589,9 +525,9 @@
                                                                                           error);
                             if (valobj_sp)
                             {
-                                if (m_frame_var_options.format != eFormatDefault)
-                                    valobj_sp->SetFormat (m_frame_var_options.format);
-                                if (m_frame_var_options.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
+                                if (m_option_variable.format != eFormatDefault)
+                                    valobj_sp->SetFormat (m_option_variable.format);
+                                if (m_option_variable.show_decl && var_sp && var_sp->GetDeclaration ().GetFile())
                                 {
                                     var_sp->GetDeclaration ().DumpStopContext (&s, false);
                                     s.PutCString (": ");
@@ -635,26 +571,26 @@
                             switch (var_sp->GetScope())
                             {
                             case eValueTypeVariableGlobal:
-                                dump_variable = m_frame_var_options.show_globals;
-                                if (dump_variable && m_frame_var_options.show_scope)
+                                dump_variable = m_option_variable.show_globals;
+                                if (dump_variable && m_option_variable.show_scope)
                                     s.PutCString("GLOBAL: ");
                                 break;
 
                             case eValueTypeVariableStatic:
-                                dump_variable = m_frame_var_options.show_globals;
-                                if (dump_variable && m_frame_var_options.show_scope)
+                                dump_variable = m_option_variable.show_globals;
+                                if (dump_variable && m_option_variable.show_scope)
                                     s.PutCString("STATIC: ");
                                 break;
                                 
                             case eValueTypeVariableArgument:
-                                dump_variable = m_frame_var_options.show_args;
-                                if (dump_variable && m_frame_var_options.show_scope)
+                                dump_variable = m_option_variable.show_args;
+                                if (dump_variable && m_option_variable.show_scope)
                                     s.PutCString("   ARG: ");
                                 break;
                                 
                             case eValueTypeVariableLocal:
-                                dump_variable = m_frame_var_options.show_locals;
-                                if (dump_variable && m_frame_var_options.show_scope)
+                                dump_variable = m_option_variable.show_locals;
+                                if (dump_variable && m_option_variable.show_scope)
                                     s.PutCString(" LOCAL: ");
                                 break;
 
@@ -672,14 +608,14 @@
                                                                                            m_varobj_options.use_dynamic);
                                 if (valobj_sp)
                                 {
-                                    if (m_frame_var_options.format != eFormatDefault)
-                                        valobj_sp->SetFormat (m_frame_var_options.format);
+                                    if (m_option_variable.format != eFormatDefault)
+                                        valobj_sp->SetFormat (m_option_variable.format);
                                     
                                     // When dumping all variables, don't print any variables
                                     // that are not in scope to avoid extra unneeded output
                                     if (valobj_sp->IsInScope ())
                                     {
-                                        if (m_frame_var_options.show_decl && var_sp->GetDeclaration ().GetFile())
+                                        if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
                                         {
                                             var_sp->GetDeclaration ().DumpStopContext (&s, false);
                                             s.PutCString (": ");
@@ -710,30 +646,10 @@
 protected:
 
     OptionGroupOptions m_option_group;
-    OptionGroupFrameVariable m_frame_var_options;
+    OptionGroupVariable m_option_variable;
     OptionGroupValueObjectDisplay m_varobj_options;
 };
 
-OptionDefinition
-CommandObjectFrameVariable::OptionGroupFrameVariable::g_option_table[] =
-{
-{ LLDB_OPT_SET_1, false, "no-args",         'a', no_argument,       NULL, 0, eArgTypeNone,    "Omit function arguments."},
-{ LLDB_OPT_SET_1, false, "show-declaration",'c', no_argument,       NULL, 0, eArgTypeNone,    "Show variable declaration information (source file and line where the variable was declared)."},
-{ 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, "show-globals",    'g', no_argument,       NULL, 0, eArgTypeNone,    "Show the current frame source file global and static variables."},
-{ LLDB_OPT_SET_1, false, "find-global",     'G', required_argument, NULL, 0, eArgTypeVarName, "Find a global variable by name (which might not be in the current stack frame source file)."},
-{ LLDB_OPT_SET_1, false, "no-locals",       'l', no_argument,       NULL, 0, eArgTypeNone,    "Omit local variables."},
-{ LLDB_OPT_SET_1, false, "regex",           'r', no_argument,       NULL, 0, eArgTypeRegularExpression,    "The <variable-name> argument for name lookups are regular expressions."},
-{ LLDB_OPT_SET_1, false, "scope",           's', no_argument,       NULL, 0, eArgTypeNone,    "Show variable scope (argument, local, global, static)."},
-{ 0, false, NULL, 0, 0, NULL, NULL, eArgTypeNone, NULL }
-};
-
-uint32_t
-CommandObjectFrameVariable::OptionGroupFrameVariable::GetNumDefinitions ()
-{
-    return sizeof(CommandObjectFrameVariable::OptionGroupFrameVariable::g_option_table)/sizeof(OptionDefinition);
-}
-        
 
 #pragma mark CommandObjectMultiwordFrame
 

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=134594&r1=134593&r2=134594&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Wed Jul  6 23:38:25 2011
@@ -27,7 +27,7 @@
 #include "lldb/Interpreter/Options.h"
 #include "lldb/Interpreter/OptionGroupArchitecture.h"
 #include "lldb/Interpreter/OptionGroupFile.h"
-#include "lldb/Interpreter/OptionGroupFormat.h"
+#include "lldb/Interpreter/OptionGroupVariable.h"
 #include "lldb/Interpreter/OptionGroupPlatform.h"
 #include "lldb/Interpreter/OptionGroupUInt64.h"
 #include "lldb/Interpreter/OptionGroupUUID.h"
@@ -417,13 +417,13 @@
                        NULL,
                        0),
         m_option_group (interpreter),
-        m_format_options (eFormatDefault, 0, false),
+        m_option_variable (false), // Don't include frame options
         m_option_compile_units    (LLDB_OPT_SET_1, false, "file", 'f', 0, eArgTypePath, "A basename or fullpath to a file that contains global variables. This option can be specified multiple times."),
         m_option_shared_libraries (LLDB_OPT_SET_1, false, "shlib",'s', 0, eArgTypePath, "A basename or fullpath to a shared library to use in the search for global variables. This option can be specified multiple times."),
         m_varobj_options()
     {
         m_option_group.Append (&m_varobj_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
-        m_option_group.Append (&m_format_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+        m_option_group.Append (&m_option_variable, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
         m_option_group.Append (&m_option_compile_units, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);   
         m_option_group.Append (&m_option_shared_libraries, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);   
         m_option_group.Finalize();
@@ -447,19 +447,39 @@
                 for (size_t idx = 0; idx < argc; ++idx)
                 {
                     VariableList global_var_list;
-                    const char *global_var_name = args.GetArgumentAtIndex(idx);
-                    const uint32_t matches = exe_ctx.target->GetImages().FindGlobalVariables (global_var_name,
-                                                                                              true, 
-                                                                                              UINT32_MAX, 
-                                                                                              global_var_list);
+                    const char *arg = args.GetArgumentAtIndex(idx);
+                    uint32_t matches = 0;
+                    if (m_option_variable.use_regex)
+                    {
+                        RegularExpression regex(arg);
+                        if (!regex.IsValid ())
+                        {
+                            result.GetErrorStream().Printf ("error: invalid regular expression: '%s'\n", arg);
+                            result.SetStatus (eReturnStatusFailed);
+                            return false;
+                        }
+                        matches = exe_ctx.target->GetImages().FindGlobalVariables (regex,
+                                                                                   true, 
+                                                                                   UINT32_MAX, 
+                                                                                   global_var_list);
+                    }
+                    else
+                    {
+                        matches = exe_ctx.target->GetImages().FindGlobalVariables (arg,
+                                                                                   true, 
+                                                                                   UINT32_MAX, 
+                                                                                   global_var_list);
+                    }
                     
                     if (matches == 0)
                     {
-                        result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", 
-                                                        global_var_name);
+                        result.GetErrorStream().Printf ("error: can't find global variable '%s'\n", arg);
+                        result.SetStatus (eReturnStatusFailed);
+                        return false;
                     }
                     else
                     {
+                        Stream &s = result.GetOutputStream();
                         for (uint32_t global_idx=0; global_idx<matches; ++global_idx)
                         {
                             VariableSP var_sp (global_var_list.GetVariableAtIndex(global_idx));
@@ -469,19 +489,48 @@
                                 
                                 if (valobj_sp)
                                 {
-                                    const Format format = m_format_options.GetFormat ();
+                                    if (m_option_variable.format != eFormatDefault)
+                                        valobj_sp->SetFormat (m_option_variable.format);
+
+                                    switch (var_sp->GetScope())
+                                    {
+                                        case eValueTypeVariableGlobal:
+                                            if (m_option_variable.show_scope)
+                                                s.PutCString("GLOBAL: ");
+                                            break;
+                                            
+                                        case eValueTypeVariableStatic:
+                                            if (m_option_variable.show_scope)
+                                                s.PutCString("STATIC: ");
+                                            break;
+                                            
+                                        case eValueTypeVariableArgument:
+                                            if (m_option_variable.show_scope)
+                                                s.PutCString("   ARG: ");
+                                            break;
+                                            
+                                        case eValueTypeVariableLocal:
+                                            if (m_option_variable.show_scope)
+                                                s.PutCString(" LOCAL: ");
+                                            break;
+                                            
+                                        default:
+                                            break;
+                                    }
+
+                                    if (m_option_variable.show_decl && var_sp->GetDeclaration ().GetFile())
+                                    {
+                                        var_sp->GetDeclaration ().DumpStopContext (&s, false);
+                                        s.PutCString (": ");
+                                    }
+
+                                    const Format format = m_option_variable.format;
                                     if (format != eFormatDefault)
                                         valobj_sp->SetFormat (format);
                                     
-//                                    if (m_format_options.show_decl && var_sp->GetDeclaration ().GetFile())
-//                                    {
-//                                        var_sp->GetDeclaration ().DumpStopContext (&s, false);
-//                                        s.PutCString (": ");
-//                                    }
-                                    
-                                    ValueObject::DumpValueObject (result.GetOutputStream(), 
+                                    ValueObject::DumpValueObject (s, 
                                                                   valobj_sp.get(), 
-                                                                  global_var_name, 
+                                                                  var_sp->GetName().GetCString(), 
                                                                   m_varobj_options.ptr_depth, 
                                                                   0, 
                                                                   m_varobj_options.max_depth, 
@@ -520,7 +569,7 @@
     
 protected:
     OptionGroupOptions m_option_group;
-    OptionGroupFormat m_format_options;
+    OptionGroupVariable m_option_variable;
     OptionGroupFileList m_option_compile_units;
     OptionGroupFileList m_option_shared_libraries;
     OptionGroupValueObjectDisplay m_varobj_options;

Added: lldb/trunk/source/Interpreter/OptionGroupVariable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupVariable.cpp?rev=134594&view=auto
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupVariable.cpp (added)
+++ lldb/trunk/source/Interpreter/OptionGroupVariable.cpp Wed Jul  6 23:38:25 2011
@@ -0,0 +1,109 @@
+//===-- OptionGroupVariable.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/Interpreter/OptionGroupVariable.h"
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Target/Target.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+static OptionDefinition
+g_option_table[] =
+{
+    { LLDB_OPT_SET_1, false, "no-args",         'a', no_argument,       NULL, 0, eArgTypeNone,    "Omit function arguments."},
+    { LLDB_OPT_SET_1, false, "no-locals",       'l', no_argument,       NULL, 0, eArgTypeNone,    "Omit local variables."},
+    { LLDB_OPT_SET_1, false, "show-globals",    'g', no_argument,       NULL, 0, eArgTypeNone,    "Show the current frame source file global and static variables."},
+    { LLDB_OPT_SET_1, false, "show-declaration",'c', no_argument,       NULL, 0, eArgTypeNone,    "Show variable declaration information (source file and line where the variable was declared)."},
+    { 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, "regex",           'r', no_argument,       NULL, 0, eArgTypeRegularExpression,    "The <variable-name> argument for name lookups are regular expressions."},
+    { LLDB_OPT_SET_1, false, "scope",           's', no_argument,       NULL, 0, eArgTypeNone,    "Show variable scope (argument, local, global, static)."}
+};
+
+
+OptionGroupVariable::OptionGroupVariable (bool show_frame_options) :
+    OptionGroup(),
+    include_frame_options (show_frame_options)
+{
+}
+
+OptionGroupVariable::~OptionGroupVariable ()
+{
+}
+
+Error
+OptionGroupVariable::SetOptionValue (CommandInterpreter &interpreter,
+                                     uint32_t option_idx, 
+                                     const char *option_arg)
+{
+    Error error;
+    if (!include_frame_options)
+        option_idx += 3;
+    char short_option = (char) g_option_table[option_idx].short_option;
+    switch (short_option)
+    {
+        case 'r':   use_regex    = true;  break;
+        case 'a':   show_args    = false; break;
+        case 'l':   show_locals  = false; break;
+        case 'g':   show_globals = true;  break;
+        case 'c':   show_decl    = true;  break;
+        case 'f':   error = Args::StringToFormat(option_arg, format, NULL); break;
+        case 's':
+            show_scope = true;
+            break;
+            
+        default:
+            error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
+            break;
+    }
+    
+    return error;
+}
+
+void
+OptionGroupVariable::OptionParsingStarting (CommandInterpreter &interpreter)
+{
+    show_args     = true;   // Frame option only
+    show_locals   = true;   // Frame option only
+    show_globals  = false;  // Frame option only
+    show_decl     = false;
+    format        = lldb::eFormatDefault;
+    use_regex     = false;
+    show_scope    = false;
+}
+
+
+const OptionDefinition*
+OptionGroupVariable::GetDefinitions ()
+{
+    // Show the "--no-args", "--no-locals" and "--show-globals" 
+    // options if we are showing frame specific options
+    if (include_frame_options)
+        return g_option_table;
+
+    // Skip the "--no-args", "--no-locals" and "--show-globals" 
+    // options if we are not showing frame specific options (globals only)
+    return &g_option_table[3];
+}
+
+uint32_t
+OptionGroupVariable::GetNumDefinitions ()
+{
+    if (include_frame_options)
+        return 7;
+    else
+        return 4;
+}
+
+

Modified: lldb/trunk/test/lang/cpp/class_static/TestStaticVariables.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/class_static/TestStaticVariables.py?rev=134594&r1=134593&r2=134594&view=diff
==============================================================================
--- lldb/trunk/test/lang/cpp/class_static/TestStaticVariables.py (original)
+++ lldb/trunk/test/lang/cpp/class_static/TestStaticVariables.py Wed Jul  6 23:38:25 2011
@@ -60,9 +60,11 @@
         # On Mac OS X, gcc 4.2 emits the wrong debug info for A::g_points.
         slist = ['(PointType [2]) g_points', 'A::g_points']
 
+# global variables are no longer displayed with the "frame variable" command. 
+# add tests for the "target variable" command soon
         # 'frame variable -G' finds and displays global variable(s) by name.
-        self.expect('frame variable -G g_points', VARIABLES_DISPLAYED_CORRECTLY,
-            substrs = slist)
+        # self.expect('frame variable -G g_points', VARIABLES_DISPLAYED_CORRECTLY,
+        #     substrs = slist)
 
         # A::g_points is an array of two elements.
         if sys.platform.startswith("darwin") and self.getCompiler() in ['clang', 'llvm-gcc']:





More information about the lldb-commits mailing list