[Lldb-commits] [lldb] r119758 - /lldb/trunk/test/class_static/TestStaticVariables.py

Johnny Chen johnny.chen at apple.com
Thu Nov 18 15:33:44 PST 2010


Author: johnny
Date: Thu Nov 18 17:33:43 2010
New Revision: 119758

URL: http://llvm.org/viewvc/llvm-project?rev=119758&view=rev
Log:
Add Python API tests for file and class static variables, too.

Modified:
    lldb/trunk/test/class_static/TestStaticVariables.py

Modified: lldb/trunk/test/class_static/TestStaticVariables.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_static/TestStaticVariables.py?rev=119758&r1=119757&r2=119758&view=diff
==============================================================================
--- lldb/trunk/test/class_static/TestStaticVariables.py (original)
+++ lldb/trunk/test/class_static/TestStaticVariables.py Thu Nov 18 17:33:43 2010
@@ -18,10 +18,21 @@
         self.static_variable_commands()
 
     def test_with_dwarf_and_run_command(self):
-        """Test that anonymous and named namespace variables display correctly."""
+        """Test that file and class static variables display correctly."""
         self.buildDwarf()
         self.static_variable_commands()
 
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_with_dsym_and_python_api(self):
+        """Test Python APIs on file and class static variables."""
+        self.buildDsym()
+        self.static_variable_python()
+
+    def test_with_dwarf_and_python_api(self):
+        """Test Python APIs on file and class static variables."""
+        self.buildDwarf()
+        self.static_variable_python()
+
     def setUp(self):
         # Call super's setUp().
         TestBase.setUp(self)
@@ -29,7 +40,7 @@
         self.line = line_number('main.cpp', '// Set break point at this line.')
 
     def static_variable_commands(self):
-        """Test that anonymous and named namespace variables display correctly."""
+        """Test that that file and class static variables display correctly."""
         self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
 
         self.expect("breakpoint set -f main.cpp -l %d" % self.line,
@@ -56,6 +67,58 @@
             self.expect("frame variable A::g_points[1].x", VARIABLES_DISPLAYED_CORRECTLY,
                 startstr = "(int) A::g_points[1].x = 11")
 
+    def static_variable_python(self):
+        """Test Python APIs on file and class static variables."""
+        exe = os.path.join(os.getcwd(), "a.out")
+
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target.IsValid(), VALID_TARGET)
+
+        breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
+        self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
+
+        # Now launch the process, and do not stop at entry point.
+        self.process = target.LaunchProcess([''], [''], os.ctermid(), 0, False)
+
+        self.process = target.GetProcess()
+        self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID)
+
+        # The stop reason of the thread should be breakpoint.
+        thread = self.process.GetThreadAtIndex(0)
+        if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
+            from lldbutil import StopReasonString
+            self.fail(STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS %
+                      StopReasonString(thread.GetStopReason()))
+
+        # Get the SBValue of 'A::g_points' and 'g_points'.
+        frame = thread.GetFrameAtIndex(0)
+
+        # arguments =>     False
+        # locals =>        False
+        # statics =>       True
+        # in_scope_only => False
+        valList = frame.GetVariables(False, False, True, False)
+
+        from lldbutil import lldb_iter
+        for val in lldb_iter(valList, 'GetSize', 'GetValueAtIndex'):
+            self.DebugSBValue(frame, val)
+            self.assertTrue(val.GetValueType() == lldb.eValueTypeVariableGlobal)
+            name = val.GetName()
+            self.assertTrue(name in ['g_points', 'A::g_points'])
+            if name == 'g_points':
+                self.assertTrue(val.GetNumChildren() == 2)
+            elif name == 'A::g_points' and self.getCompiler() in ['clang', 'llvm-gcc']:
+                self.assertTrue(val.GetNumChildren() == 2)
+                child1 = val.GetChildAtIndex(1)
+                self.DebugSBValue(frame, child1)
+                child1_x = child1.GetChildAtIndex(0)
+                self.DebugSBValue(frame, child1_x)
+                self.assertTrue(child1_x.GetTypeName() == 'int' and
+                                child1_x.GetValue(frame) == '11')
+
+        #variable = frame.LookupVarInScope("A::g_points", "global")
+        #print "variable:", repr(variable)
+
 
 if __name__ == '__main__':
     import atexit





More information about the lldb-commits mailing list