[Lldb-commits] [lldb] r134745 - in /lldb/trunk: include/lldb/Core/ValueObject.h include/lldb/Core/ValueObjectList.h include/lldb/Symbol/Variable.h include/lldb/Symbol/VariableList.h source/Commands/CommandObjectTarget.cpp source/Core/ValueObjectList.cpp source/Symbol/Variable.cpp source/Symbol/VariableList.cpp

Greg Clayton gclayton at apple.com
Fri Jul 8 14:46:14 PDT 2011


Author: gclayton
Date: Fri Jul  8 16:46:14 2011
New Revision: 134745

URL: http://llvm.org/viewvc/llvm-project?rev=134745&view=rev
Log:
Added the ability to see global variables with a variable expression path so
you can do things like:

(lldb) target variable g_global.a
(lldb) target variable *g_global.ptr
(lldb) target variable g_global.ptr[1]


Modified:
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/include/lldb/Core/ValueObjectList.h
    lldb/trunk/include/lldb/Symbol/Variable.h
    lldb/trunk/include/lldb/Symbol/VariableList.h
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/ValueObjectList.cpp
    lldb/trunk/source/Symbol/Variable.cpp
    lldb/trunk/source/Symbol/VariableList.cpp

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=134745&r1=134744&r2=134745&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Fri Jul  8 16:46:14 2011
@@ -121,9 +121,9 @@
         GetValueForExpressionPathOptions(bool dot = false,
                                          bool no_ivar = false,
                                          bool bitfield = true) :
-        m_check_dot_vs_arrow_syntax(dot),
-        m_no_fragile_ivar(no_ivar),
-        m_allow_bitfields_syntax(bitfield)
+            m_check_dot_vs_arrow_syntax(dot),
+            m_no_fragile_ivar(no_ivar),
+            m_allow_bitfields_syntax(bitfield)
         {
         }
         

Modified: lldb/trunk/include/lldb/Core/ValueObjectList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectList.h?rev=134745&r1=134744&r2=134745&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObjectList.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObjectList.h Fri Jul  8 16:46:14 2011
@@ -59,6 +59,9 @@
     lldb::ValueObjectSP
     GetValueObjectAtIndex (uint32_t idx);
 
+    lldb::ValueObjectSP
+    RemoveValueObjectAtIndex (uint32_t idx);
+    
     void
     SetValueObjectAtIndex (uint32_t idx, 
                            const lldb::ValueObjectSP &valobj_sp);

Modified: lldb/trunk/include/lldb/Symbol/Variable.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Variable.h?rev=134745&r1=134744&r2=134745&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Variable.h (original)
+++ lldb/trunk/include/lldb/Symbol/Variable.h Fri Jul  8 16:46:14 2011
@@ -140,6 +140,19 @@
     {
         m_loc_is_const_data = b;
     }
+    
+    typedef uint32_t (*GetVariableCallback) (void *baton, 
+                                             const char *name,
+                                             VariableList &var_list);
+
+
+    static Error
+    GetValuesForVariableExpressionPath (const char *variable_expr_path,
+                                        ExecutionContextScope *scope,
+                                        GetVariableCallback callback,
+                                        void *baton,
+                                        VariableList &variable_list,
+                                        ValueObjectList &valobj_list);
 
 protected:
     ConstString m_name;                 // The basename of the variable (no namespaces)

Modified: lldb/trunk/include/lldb/Symbol/VariableList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/VariableList.h?rev=134745&r1=134744&r2=134745&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/VariableList.h (original)
+++ lldb/trunk/include/lldb/Symbol/VariableList.h Fri Jul  8 16:46:14 2011
@@ -45,6 +45,9 @@
     GetVariableAtIndex(uint32_t idx);
 
     lldb::VariableSP
+    RemoveVariableAtIndex (uint32_t idx);
+    
+    lldb::VariableSP
     FindVariable (const ConstString& name);
 
     uint32_t

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=134745&r1=134744&r2=134745&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Fri Jul  8 16:46:14 2011
@@ -433,7 +433,82 @@
     ~CommandObjectTargetVariable ()
     {
     }
+
+    void
+    DumpValueObject (Stream &s, VariableSP &var_sp, ValueObjectSP &valobj_sp, const char *root_name)
+    {
+        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);
+        
+        ValueObject::DumpValueObject (s, 
+                                      valobj_sp.get(), 
+                                      root_name,
+                                      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);                                        
+
+    }
+    
+    
+    static uint32_t GetVariableCallback (void *baton, 
+                                         const char *name,
+                                         VariableList &variable_list)
+    {
+        Target *target = static_cast<Target *>(baton);
+        if (target)
+        {
+            return target->GetImages().FindGlobalVariables (ConstString(name),
+                                                            true, 
+                                                            UINT32_MAX, 
+                                                            variable_list);
+        }
+        return 0;
+    }
     
+
+
     virtual bool
     Execute (Args& args, CommandReturnObject &result)
     {
@@ -444,9 +519,13 @@
             const size_t argc = args.GetArgumentCount();
             if (argc > 0)
             {
+                Stream &s = result.GetOutputStream();
+
                 for (size_t idx = 0; idx < argc; ++idx)
                 {
-                    VariableList global_var_list;
+                    VariableList variable_list;
+                    ValueObjectList valobj_list;
+
                     const char *arg = args.GetArgumentAtIndex(idx);
                     uint32_t matches = 0;
                     if (m_option_variable.use_regex)
@@ -461,14 +540,22 @@
                         matches = exe_ctx.target->GetImages().FindGlobalVariables (regex,
                                                                                    true, 
                                                                                    UINT32_MAX, 
-                                                                                   global_var_list);
+                                                                                   variable_list);
                     }
                     else
                     {
-                        matches = exe_ctx.target->GetImages().FindGlobalVariables (ConstString(arg),
-                                                                                   true, 
-                                                                                   UINT32_MAX, 
-                                                                                   global_var_list);
+                        Error error (Variable::GetValuesForVariableExpressionPath (arg,
+                                                                                   exe_ctx.target,
+                                                                                   GetVariableCallback,
+                                                                                   exe_ctx.target,
+                                                                                   variable_list,
+                                                                                   valobj_list));
+                        
+//                        matches = exe_ctx.target->GetImages().FindGlobalVariables (ConstString(arg),
+//                                                                                   true, 
+//                                                                                   UINT32_MAX, 
+//                                                                                   variable_list);
+                        matches = variable_list.GetSize();
                     }
                     
                     if (matches == 0)
@@ -479,68 +566,17 @@
                     }
                     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));
+                            VariableSP var_sp (variable_list.GetVariableAtIndex(global_idx));
                             if (var_sp)
                             {
-                                ValueObjectSP valobj_sp(ValueObjectVariable::Create (exe_ctx.target, var_sp));
+                                ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(global_idx));
+                                if (!valobj_sp)
+                                    valobj_sp = ValueObjectVariable::Create (exe_ctx.target, var_sp);
                                 
                                 if (valobj_sp)
-                                {
-                                    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);
-                                    
-                                    ValueObject::DumpValueObject (s, 
-                                                                  valobj_sp.get(), 
-                                                                  var_sp->GetName().GetCString(), 
-                                                                  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);                                        
-                                }
+                                    DumpValueObject (s, var_sp, valobj_sp, arg);
                             }
                         }
                     }

Modified: lldb/trunk/source/Core/ValueObjectList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectList.cpp?rev=134745&r1=134744&r2=134745&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectList.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectList.cpp Fri Jul  8 16:46:14 2011
@@ -82,6 +82,18 @@
     return valobj_sp;
 }
 
+lldb::ValueObjectSP
+ValueObjectList::RemoveValueObjectAtIndex (uint32_t idx)
+{
+    lldb::ValueObjectSP valobj_sp;
+    if (idx < m_value_objects.size())
+    {
+        valobj_sp = m_value_objects[idx];
+        m_value_objects.erase (m_value_objects.begin() + idx);
+    }
+    return valobj_sp;
+}
+
 void
 ValueObjectList::SetValueObjectAtIndex (uint32_t idx, const ValueObjectSP &valobj_sp)
 {

Modified: lldb/trunk/source/Symbol/Variable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Variable.cpp?rev=134745&r1=134744&r2=134745&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Variable.cpp (original)
+++ lldb/trunk/source/Symbol/Variable.cpp Fri Jul  8 16:46:14 2011
@@ -11,10 +11,13 @@
 
 #include "lldb/Core/Stream.h"
 #include "lldb/Core/RegularExpression.h"
+#include "lldb/Core/ValueObject.h"
+#include "lldb/Core/ValueObjectVariable.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Symbol/Function.h"
 #include "lldb/Symbol/SymbolContext.h"
 #include "lldb/Symbol/Type.h"
+#include "lldb/Symbol/VariableList.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/StackFrame.h"
@@ -229,3 +232,163 @@
     return false;
 }
 
+Error
+Variable::GetValuesForVariableExpressionPath (const char *variable_expr_path,
+                                              ExecutionContextScope *scope,
+                                              GetVariableCallback callback,
+                                              void *baton,
+                                              VariableList &variable_list,
+                                              ValueObjectList &valobj_list)
+{
+    Error error;
+    if (variable_expr_path && callback)
+    {
+        switch (variable_expr_path[0])
+        {
+        case '*':
+            {
+                error = Variable::GetValuesForVariableExpressionPath (variable_expr_path + 1,
+                                                                      scope,
+                                                                      callback,
+                                                                      baton,
+                                                                      variable_list,
+                                                                      valobj_list);
+                if (error.Success())
+                {
+                    for (uint32_t i=0; i<valobj_list.GetSize(); )
+                    {
+                        Error tmp_error;
+                        ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(i)->Dereference(tmp_error));
+                        if (tmp_error.Fail())
+                        {
+                            variable_list.RemoveVariableAtIndex (i);
+                            valobj_list.RemoveValueObjectAtIndex (i);
+                        }
+                        else
+                        {
+                            valobj_list.SetValueObjectAtIndex (i, valobj_sp);
+                            ++i;
+                        }
+                    }
+                }
+                else
+                {
+                    error.SetErrorString ("unknown error");
+                }
+                return error;
+            }
+            break;
+        
+        case '&':
+            {
+                error = Variable::GetValuesForVariableExpressionPath (variable_expr_path + 1,
+                                                                      scope,
+                                                                      callback,
+                                                                      baton,
+                                                                      variable_list,
+                                                                      valobj_list);
+                if (error.Success())
+                {
+                    for (uint32_t i=0; i<valobj_list.GetSize(); )
+                    {
+                        Error tmp_error;
+                        ValueObjectSP valobj_sp (valobj_list.GetValueObjectAtIndex(i)->AddressOf(tmp_error));
+                        if (tmp_error.Fail())
+                        {
+                            variable_list.RemoveVariableAtIndex (i);
+                            valobj_list.RemoveValueObjectAtIndex (i);
+                        }
+                        else
+                        {
+                            valobj_list.SetValueObjectAtIndex (i, valobj_sp);
+                            ++i;
+                        }
+                    }
+                }
+                else
+                {
+                    error.SetErrorString ("unknown error");
+                }
+                return error;
+            }
+            break;
+            
+        default:
+            {
+                RegularExpression regex ("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)");
+                if (regex.Execute(variable_expr_path, 1))
+                {
+                    std::string variable_name;
+                    if (regex.GetMatchAtIndex(variable_expr_path, 1, variable_name))
+                    {
+                        variable_list.Clear();
+                        if (callback (baton, variable_name.c_str(), variable_list))
+                        {
+                            uint32_t i=0;
+                            while (i < variable_list.GetSize())
+                            {
+                                VariableSP var_sp (variable_list.GetVariableAtIndex (i));
+                                ValueObjectSP valobj_sp;
+                                if (var_sp)
+                                {
+                                    ValueObjectSP variable_valobj_sp(ValueObjectVariable::Create (scope, var_sp));
+                                    if (variable_valobj_sp)
+                                    {
+                                        variable_expr_path += variable_name.size();
+                                        if (*variable_expr_path)
+                                        {
+                                            const char* first_unparsed = NULL;
+                                            ValueObject::ExpressionPathScanEndReason reason_to_stop;
+                                            ValueObject::ExpressionPathEndResultType final_value_type;
+                                            ValueObject::GetValueForExpressionPathOptions options;
+                                            ValueObject::ExpressionPathAftermath final_task_on_target;
+
+                                            valobj_sp = variable_valobj_sp->GetValueForExpressionPath (variable_expr_path,
+                                                                                                       &first_unparsed,
+                                                                                                       &reason_to_stop,
+                                                                                                       &final_value_type,
+                                                                                                       options,
+                                                                                                       &final_task_on_target);
+                                            if (!valobj_sp)
+                                            {
+                                                error.SetErrorStringWithFormat ("invalid expression path '%s' for variable '%s'",
+                                                                                variable_expr_path,
+                                                                                var_sp->GetName().GetCString());
+                                            }
+                                        }
+                                        else
+                                        {
+                                            // Just the name of a variable with no extras
+                                            valobj_sp = variable_valobj_sp;
+                                        }
+                                    }
+                                }
+
+                                if (!var_sp || !valobj_sp)
+                                {
+                                    variable_list.RemoveVariableAtIndex (i);
+                                }
+                                else
+                                {
+                                    valobj_list.Append(valobj_sp);
+                                    ++i;
+                                }
+                            }
+                            
+                            if (variable_list.GetSize() > 0)
+                            {
+                                error.Clear();
+                                return error;
+                            }
+                        }
+                    }
+                }
+                error.SetErrorStringWithFormat ("unable to extracta variable name from '%s'", variable_expr_path);
+            }
+            break;
+        }
+    }
+    error.SetErrorString ("unknown error");
+    return error;
+}
+

Modified: lldb/trunk/source/Symbol/VariableList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/VariableList.cpp?rev=134745&r1=134744&r2=134745&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/VariableList.cpp (original)
+++ lldb/trunk/source/Symbol/VariableList.cpp Fri Jul  8 16:46:14 2011
@@ -72,6 +72,18 @@
     return var_sp;
 }
 
+VariableSP
+VariableList::RemoveVariableAtIndex(uint32_t idx)
+{
+    VariableSP var_sp;
+    if (idx < m_variables.size())
+    {
+        var_sp = m_variables[idx];
+        m_variables.erase (m_variables.begin() + idx);
+    }
+    return var_sp;
+}
+
 uint32_t
 VariableList::FindVariableIndex (const VariableSP &var_sp)
 {





More information about the lldb-commits mailing list