[Lldb-commits] [lldb] r141222 - /lldb/trunk/source/Commands/CommandObjectTarget.cpp

Greg Clayton gclayton at apple.com
Wed Oct 5 15:17:32 PDT 2011


Author: gclayton
Date: Wed Oct  5 17:17:32 2011
New Revision: 141222

URL: http://llvm.org/viewvc/llvm-project?rev=141222&view=rev
Log:
"target variable" will now display the current frame's compile unit globals
and statics when no arguments are given. 


Modified:
    lldb/trunk/source/Commands/CommandObjectTarget.cpp

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=141222&r1=141221&r2=141222&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Wed Oct  5 17:17:32 2011
@@ -623,9 +623,9 @@
         if (target)
         {
             const size_t argc = args.GetArgumentCount();
+            Stream &s = result.GetOutputStream();
             if (argc > 0)
             {
-                Stream &s = result.GetOutputStream();
 
                 for (size_t idx = 0; idx < argc; ++idx)
                 {
@@ -692,8 +692,56 @@
             }
             else
             {
-                result.AppendError ("'target variable' takes one or more global variable names as arguments\n");
-                result.SetStatus (eReturnStatusFailed);
+                bool success = false;
+                StackFrame *frame = exe_ctx.GetFramePtr();
+                CompileUnit *comp_unit = NULL;
+                if (frame)
+                {
+                    comp_unit = frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit;
+                    if (comp_unit)
+                    {
+                        const bool can_create = true;
+                        VariableListSP comp_unit_varlist_sp (comp_unit->GetVariableList(can_create));
+                        if (comp_unit_varlist_sp)
+                        {
+                            size_t count = comp_unit_varlist_sp->GetSize();
+                            if (count > 0)
+                            {
+                                s.Printf ("Global in %s/%s:\n", 
+                                          comp_unit->GetDirectory().GetCString(),
+                                          comp_unit->GetFilename().GetCString());
+
+                                success = true;
+                                for (uint32_t i=0; i<count; ++i)
+                                {
+                                    VariableSP var_sp (comp_unit_varlist_sp->GetVariableAtIndex(i));
+                                    if (var_sp)
+                                    {
+                                        ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_ctx.GetBestExecutionContextScope(), var_sp));
+                                        
+                                        if (valobj_sp)
+                                            DumpValueObject (s, var_sp, valobj_sp, var_sp->GetName().GetCString());
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+                if (!success)
+                {
+                    if (frame)
+                    {
+                        if (comp_unit)
+                            result.AppendErrorWithFormat ("no global variables in current compile unit: %s/%s\n", 
+                                                          comp_unit->GetDirectory().GetCString(), 
+                                                          comp_unit->GetFilename().GetCString());
+                        else
+                            result.AppendError ("no debug information for frame %u\n", frame->GetFrameIndex());
+                    }                        
+                    else
+                        result.AppendError ("'target variable' takes one or more global variable names as arguments\n");
+                    result.SetStatus (eReturnStatusFailed);
+                }
             }
         }
         else





More information about the lldb-commits mailing list