[Lldb-commits] [lldb] r127432 - in /lldb/trunk/test/python_api/thread: TestThreadAPI.py main2.cpp

Johnny Chen johnny.chen at apple.com
Thu Mar 10 14:32:48 PST 2011


Author: johnny
Date: Thu Mar 10 16:32:47 2011
New Revision: 127432

URL: http://llvm.org/viewvc/llvm-project?rev=127432&view=rev
Log:
Add test cases to TestThreadAPI.py to exercise SBThread.StepOver() by stopping at a breakpoint,
doing three step-over's, then verifying that the correct source line number is reached.

Modified:
    lldb/trunk/test/python_api/thread/TestThreadAPI.py
    lldb/trunk/test/python_api/thread/main2.cpp

Modified: lldb/trunk/test/python_api/thread/TestThreadAPI.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/thread/TestThreadAPI.py?rev=127432&r1=127431&r2=127432&view=diff
==============================================================================
--- lldb/trunk/test/python_api/thread/TestThreadAPI.py (original)
+++ lldb/trunk/test/python_api/thread/TestThreadAPI.py Thu Mar 10 16:32:47 2011
@@ -44,13 +44,33 @@
         self.setTearDownCleanup(dictionary=d)
         self.step_out_of_malloc_into_function_b()
 
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @python_api_test
+    def test_step_over_3_times_with_dsym(self):
+        """Test Python SBThread.StepOver() API."""
+        # We build a different executable than the default buildDsym() does.
+        d = {'CXX_SOURCES': 'main2.cpp'}
+        self.buildDsym(dictionary=d)
+        self.setTearDownCleanup(dictionary=d)
+        self.step_over_3_times()
+
+    @python_api_test
+    def test_step_over_3_times_with_dwarf(self):
+        """Test Python SBThread.StepOver() API."""
+        # We build a different executable than the default buildDwarf() does.
+        d = {'CXX_SOURCES': 'main2.cpp'}
+        self.buildDwarf(dictionary=d)
+        self.setTearDownCleanup(dictionary=d)
+        self.step_over_3_times()
+
     def setUp(self):
         # Call super's setUp().
         TestBase.setUp(self)
         # Find the line number to break inside main().
         self.line = line_number("main.cpp", "// Set break point at this line and check variable 'my_char'.")
-        # Find the line number within main2.cpp for step_out_of_malloc_into_function_b().
+        # Find the line numbers within main2.cpp for step_over_3_times() and step_out_of_malloc_into_function_b().
         self.line2 = line_number("main2.cpp", "// thread step-out of malloc into function b.")
+        self.line3 = line_number("main2.cpp", "// we should reach here after 3 step-over's.")
 
     def get_stop_description(self):
         """Test Python SBProcess.ReadMemory() API."""
@@ -114,6 +134,45 @@
         self.assertTrue(thread.GetFrameAtIndex(0).GetLineEntry().GetLine() == self.line2,
                         "step out of malloc into function b is successful")
 
+    def step_over_3_times(self):
+        """Test Python SBThread.StepOver() API."""
+        exe = os.path.join(os.getcwd(), "a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target.IsValid(), VALID_TARGET)
+
+        breakpoint = target.BreakpointCreateByLocation('main2.cpp', self.line2)
+        self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
+        self.runCmd("breakpoint list")
+
+        # Launch the process, and do not stop at the entry point.
+        error = lldb.SBError()
+        self.process = target.Launch (self.dbg.GetListener(), None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error)
+
+        self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID)
+
+        # Frame #0 should be on self.line2.
+        self.assertTrue(self.process.GetState() == lldb.eStateStopped)
+        thread = get_stopped_thread(self.process, lldb.eStopReasonBreakpoint)
+        self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint condition")
+        self.runCmd("thread backtrace")
+        frame0 = thread.GetFrameAtIndex(0)
+        lineEntry = frame0.GetLineEntry()
+        self.assertTrue(lineEntry.GetLine() == self.line2)
+
+        thread.StepOver()
+        thread.StepOver()
+        thread.StepOver()
+        self.runCmd("thread backtrace")
+
+        # Verify that we are stopped at the correct source line number in main2.cpp.
+        frame0 = thread.GetFrameAtIndex(0)
+        lineEntry = frame0.GetLineEntry()
+        self.assertTrue(thread.GetStopReason() == lldb.eStopReasonPlanComplete)
+        self.assertTrue(lineEntry.GetLine() == self.line3)
+
+
 if __name__ == '__main__':
     import atexit
     lldb.SBDebugger.Initialize()

Modified: lldb/trunk/test/python_api/thread/main2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/thread/main2.cpp?rev=127432&r1=127431&r2=127432&view=diff
==============================================================================
--- lldb/trunk/test/python_api/thread/main2.cpp (original)
+++ lldb/trunk/test/python_api/thread/main2.cpp Thu Mar 10 16:32:47 2011
@@ -31,7 +31,7 @@
         return -1;
     else
         printf("ptr=%p\n", ptr);
-    return rc;
+    return rc;                // we should reach here after 3 step-over's.
 }
 
 int c(int val)





More information about the lldb-commits mailing list