[Lldb-commits] [lldb] r115653 - /lldb/trunk/test/class_types/TestClassTypesDisassembly.py

Johnny Chen johnny.chen at apple.com
Tue Oct 5 12:34:07 PDT 2010


Author: johnny
Date: Tue Oct  5 14:34:06 2010
New Revision: 115653

URL: http://llvm.org/viewvc/llvm-project?rev=115653&view=rev
Log:
Add a test class to call lldb 'disassemble -n function' command on each call frame when stopped on C's ctor.
This is not a long running test so it shall always be exercised.

Added:
    lldb/trunk/test/class_types/TestClassTypesDisassembly.py

Added: lldb/trunk/test/class_types/TestClassTypesDisassembly.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_types/TestClassTypesDisassembly.py?rev=115653&view=auto
==============================================================================
--- lldb/trunk/test/class_types/TestClassTypesDisassembly.py (added)
+++ lldb/trunk/test/class_types/TestClassTypesDisassembly.py Tue Oct  5 14:34:06 2010
@@ -0,0 +1,96 @@
+"""
+Test the lldb disassemble command on each call frame when stopped on C's ctor.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+
+class IterateFrameAndDisassembleTestCase(TestBase):
+
+    mydir = "class_types"
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_with_dsym_and_run_command(self):
+        """Disassemble each call frame when stopped on C's constructor."""
+        self.buildDsym()
+        self.disassemble_call_stack()
+
+    def test_with_dwarf_and_run_command(self):
+        """Disassemble each call frame when stopped on C's constructor."""
+        self.buildDwarf()
+        self.disassemble_call_stack()
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_with_dsym_and_python_api(self):
+        """Disassemble each call frame when stopped on C's constructor."""
+        self.buildDsym()
+        self.disassemble_call_stack_api()
+
+    def test_with_dwarf_and_python_api(self):
+        """Disassemble each call frame when stopped on C's constructor."""
+        self.buildDwarf()
+        self.disassemble_call_stack_api()
+
+    def breakOnCtor(self):
+        """Setup/run the program so it stops on C's constructor."""
+        exe = os.path.join(os.getcwd(), "a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        # Break on the ctor function of class C.
+        self.expect("breakpoint set -f main.cpp -l 93", BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 1: file ='main.cpp', line = 93, locations = 1")
+
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # The stop reason of the thread should be breakpoint.
+        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+            substrs = ['state is Stopped',
+                       'stop reason = breakpoint'])
+
+        # We should be stopped on the ctor function of class C.
+        self.expect("thread backtrace", BACKTRACE_DISPLAYED_CORRECTLY,
+            substrs = ['C::C'])
+
+    def disassemble_call_stack(self):
+        """Disassemble each call frame when stopped on C's constructor."""
+        self.breakOnCtor()
+
+        raw_output = self.res.GetOutput()
+        frameRE = re.compile(r"""
+                              ^\s\sframe        # heading for the frame info,
+                              .*                # wildcard, and
+                              0x[0-9a-f]{16}    # the frame pc, and
+                              \sa.out`(.+)      # module`function, and
+                              \s\+\s            # the rest ' + ....'
+                              """, re.VERBOSE)
+        for line in raw_output.split(os.linesep):
+            match = frameRE.search(line)
+            if match:
+                function = match.group(1)
+                #print "line:", line
+                #print "function:", function
+                self.runCmd("disassemble -n '%s'" % function)
+
+    def disassemble_call_stack_api(self):
+        """Disassemble each call frame when stopped on C's constructor."""
+        self.breakOnCtor()
+
+        # Now use the Python API to get at each function on the call stack and
+        # disassemble it.
+        target = self.dbg.GetSelectedTarget()
+        process = target.GetProcess()
+        thread = process.GetThreadAtIndex(0)
+        depth = thread.GetNumFrames()
+        for i in range(depth - 1):
+            frame = thread.GetFrameAtIndex(i)
+            function = frame.GetFunction()
+            self.runCmd("disassemble -n '%s'" % function.GetName())
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()





More information about the lldb-commits mailing list