[Lldb-commits] [lldb] r119811 - in /lldb/trunk: source/API/SBFrame.cpp test/class_static/TestStaticVariables.py test/class_static/main.cpp

Johnny Chen johnny.chen at apple.com
Fri Nov 19 10:07:14 PST 2010


Author: johnny
Date: Fri Nov 19 12:07:14 2010
New Revision: 119811

URL: http://llvm.org/viewvc/llvm-project?rev=119811&view=rev
Log:
Fill in more test sequences for Python API SBFrame.LookupVarInScope(name, scope).

Change SBFrame::LookupVarInScope() to also work with "global" scope in addition
to "local" and "parameter" scope.

Modified:
    lldb/trunk/source/API/SBFrame.cpp
    lldb/trunk/test/class_static/TestStaticVariables.py
    lldb/trunk/test/class_static/main.cpp

Modified: lldb/trunk/source/API/SBFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=119811&r1=119810&r2=119811&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFrame.cpp (original)
+++ lldb/trunk/source/API/SBFrame.cpp Fri Nov 19 12:07:14 2010
@@ -350,26 +350,25 @@
 
         if (var_scope != eValueTypeInvalid)
         {
-            lldb_private::VariableList variable_list;
-            SBSymbolContext sc = GetSymbolContext (eSymbolContextEverything);
-
-            SBBlock block = sc.GetBlock();
-            if (block.IsValid())
-                block.AppendVariables (true, true, &variable_list);
-
-            const uint32_t num_variables = variable_list.GetSize();
-
-            bool found = false;
-            for (uint32_t i = 0; i < num_variables && !found; ++i)
+            lldb_private::VariableList *variable_list = m_opaque_sp->GetVariableList(true);
+            if (variable_list)
             {
-                var_sp = variable_list.GetVariableAtIndex(i);
-                if (var_sp
-                    && (var_sp.get()->GetName() == lldb_private::ConstString(var_name))
-                    && var_sp.get()->GetScope() == var_scope)
-                    found = true;
+                const uint32_t num_variables = variable_list->GetSize();
+                bool found = false;
+                for (uint32_t i = 0; i < num_variables && !found; ++i)
+                {
+                    var_sp = variable_list->GetVariableAtIndex(i);
+                    if (var_sp
+                        && (var_sp.get()->GetName() == lldb_private::ConstString(var_name))
+                        && var_sp.get()->GetScope() == var_scope)
+                    {
+                        found = true;
+                        break;
+                    }
+                }
+                if (!found)
+                    var_sp.reset();
             }
-            if (!found)
-                var_sp.reset();
         }
     }
     

Modified: lldb/trunk/test/class_static/TestStaticVariables.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_static/TestStaticVariables.py?rev=119811&r1=119810&r2=119811&view=diff
==============================================================================
--- lldb/trunk/test/class_static/TestStaticVariables.py (original)
+++ lldb/trunk/test/class_static/TestStaticVariables.py Fri Nov 19 12:07:14 2010
@@ -116,8 +116,23 @@
                 self.assertTrue(child1_x.GetTypeName() == 'int' and
                                 child1_x.GetValue(frame) == '11')
 
-        #variable = frame.LookupVarInScope("A::g_points", "global")
-        #print "variable:", repr(variable)
+        # SBFrame.LookupVarInScope() should also work.
+        val = frame.LookupVarInScope("A::g_points", "global")
+        self.DebugSBValue(frame, val)
+        self.assertTrue(val.GetName() == 'A::g_points')
+
+        # Also exercise the "parameter" and "local" scopes while we are at it.
+        val = frame.LookupVarInScope("argc", "parameter")
+        self.DebugSBValue(frame, val)
+        self.assertTrue(val.GetName() == 'argc')
+
+        val = frame.LookupVarInScope("argv", "parameter")
+        self.DebugSBValue(frame, val)
+        self.assertTrue(val.GetName() == 'argv')
+
+        val = frame.LookupVarInScope("hello_world", "local")
+        self.DebugSBValue(frame, val)
+        self.assertTrue(val.GetName() == 'hello_world')
 
 
 if __name__ == '__main__':

Modified: lldb/trunk/test/class_static/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_static/main.cpp?rev=119811&r1=119810&r2=119811&view=diff
==============================================================================
--- lldb/trunk/test/class_static/main.cpp (original)
+++ lldb/trunk/test/class_static/main.cpp Fri Nov 19 12:07:14 2010
@@ -45,7 +45,9 @@
 int
 main (int argc, char const *argv[])
 {
+    const char *hello_world = "Hello, world!";
     printf ("A::g_points[1].x = %i\n", A::g_points[1].x); // Set break point at this line.
     printf ("::g_points[1].x = %i\n", g_points[1].x);
+    printf ("%s\n", hello_world);
     return 0;
 }





More information about the lldb-commits mailing list