Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test SBprocess and SBThread APIs with printing of the stack traces. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import re |
| 7 | import unittest2 |
| 8 | import lldb |
| 9 | from lldbtest import * |
| 10 | |
| 11 | class ThreadsStackTracesTestCase(TestBase): |
| 12 | |
| 13 | mydir = "threads" |
| 14 | |
| 15 | def test_stack_traces(self): |
| 16 | """Test SBprocess and SBThread APIs with printing of the stack traces.""" |
| 17 | self.buildDefault() |
| 18 | self.break_and_print_stacktraces() |
| 19 | |
| 20 | def break_and_print_stacktraces(self): |
| 21 | """Break at main.cpp:68 and do a threads dump""" |
| 22 | exe = os.path.join(os.getcwd(), "a.out") |
| 23 | |
| 24 | target = self.dbg.CreateTarget(exe) |
| 25 | self.assertTrue(target.IsValid(), VALID_TARGET) |
| 26 | |
| 27 | breakpoint = target.BreakpointCreateByLocation("main.cpp", 68) |
| 28 | self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT) |
| 29 | |
| 30 | # Now launch the process, and do not stop at entry point. |
| 31 | rc = lldb.SBError() |
| 32 | self.process = target.Launch([''], [''], os.ctermid(), 0, False, rc) |
| 33 | |
| 34 | if not rc.Success() or not self.process.IsValid(): |
| 35 | self.fail("SBTarget.LaunchProcess() failed") |
| 36 | |
| 37 | if self.process.GetState() != lldb.eStateStopped: |
| 38 | self.fail("Process should be in the 'Stopped' state, " |
| 39 | "instead the actual state is: '%s'" % |
Johnny Chen | 28ae294 | 2010-10-07 22:15:58 +0000 | [diff] [blame^] | 40 | lldbutil.StateTypeString(self.process.GetState())) |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 41 | |
| 42 | import lldbutil |
| 43 | lldbutil.PrintStackTraces(self.process) |
| 44 | |
| 45 | |
| 46 | if __name__ == '__main__': |
| 47 | import atexit |
| 48 | lldb.SBDebugger.Initialize() |
| 49 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 50 | unittest2.main() |