Add a test case which uses the SBProcess and SBThread APIs to iterate through
the threads and print their stack traces when stopped on a breakpoint.
Add a PrintStackTraces(process) utility function into the lldbutil.py module.
llvm-svn: 115983
diff --git a/lldb/test/threads/TestPrintStackTraces.py b/lldb/test/threads/TestPrintStackTraces.py
new file mode 100644
index 0000000..ce27ed1
--- /dev/null
+++ b/lldb/test/threads/TestPrintStackTraces.py
@@ -0,0 +1,50 @@
+"""
+Test SBprocess and SBThread APIs with printing of the stack traces.
+"""
+
+import os, time
+import re
+import unittest2
+import lldb
+from lldbtest import *
+
+class ThreadsStackTracesTestCase(TestBase):
+
+ mydir = "threads"
+
+ def test_stack_traces(self):
+ """Test SBprocess and SBThread APIs with printing of the stack traces."""
+ self.buildDefault()
+ self.break_and_print_stacktraces()
+
+ def break_and_print_stacktraces(self):
+ """Break at main.cpp:68 and do a threads dump"""
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target.IsValid(), VALID_TARGET)
+
+ breakpoint = target.BreakpointCreateByLocation("main.cpp", 68)
+ self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
+
+ # Now launch the process, and do not stop at entry point.
+ rc = lldb.SBError()
+ self.process = target.Launch([''], [''], os.ctermid(), 0, False, rc)
+
+ if not rc.Success() or not self.process.IsValid():
+ self.fail("SBTarget.LaunchProcess() failed")
+
+ if self.process.GetState() != lldb.eStateStopped:
+ self.fail("Process should be in the 'Stopped' state, "
+ "instead the actual state is: '%s'" %
+ StateTypeString(self.process.GetState()))
+
+ import lldbutil
+ lldbutil.PrintStackTraces(self.process)
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()