Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 1 | """ |
Johnny Chen | 0b8fd43 | 2011-04-19 22:44:20 +0000 | [diff] [blame] | 2 | Test SBprocess and SBThread APIs with printing of the stack traces using lldbutil. |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 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 | |
Johnny Chen | ad7372c | 2011-05-12 00:32:41 +0000 | [diff] [blame] | 13 | mydir = "python_api/lldbutil/process" |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 14 | |
Johnny Chen | c043de1 | 2010-11-11 20:18:36 +0000 | [diff] [blame] | 15 | def setUp(self): |
| 16 | # Call super's setUp(). |
| 17 | TestBase.setUp(self) |
| 18 | # Find the line number to break inside main(). |
| 19 | self.line = line_number('main.cpp', '// Set break point at this line.') |
| 20 | |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 21 | def test_stack_traces(self): |
| 22 | """Test SBprocess and SBThread APIs with printing of the stack traces.""" |
| 23 | self.buildDefault() |
| 24 | self.break_and_print_stacktraces() |
| 25 | |
| 26 | def break_and_print_stacktraces(self): |
| 27 | """Break at main.cpp:68 and do a threads dump""" |
| 28 | exe = os.path.join(os.getcwd(), "a.out") |
| 29 | |
| 30 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 112f569 | 2011-05-17 22:14:39 +0000 | [diff] [blame] | 31 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 32 | |
Johnny Chen | c043de1 | 2010-11-11 20:18:36 +0000 | [diff] [blame] | 33 | breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line) |
Johnny Chen | 112f569 | 2011-05-17 22:14:39 +0000 | [diff] [blame] | 34 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 35 | |
| 36 | # Now launch the process, and do not stop at entry point. |
| 37 | rc = lldb.SBError() |
Johnny Chen | d762ff1 | 2011-02-03 23:15:53 +0000 | [diff] [blame] | 38 | self.process = target.Launch (self.dbg.GetListener(), None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, rc) |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 39 | |
Johnny Chen | 112f569 | 2011-05-17 22:14:39 +0000 | [diff] [blame] | 40 | if not rc.Success() or not self.process: |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 41 | self.fail("SBTarget.LaunchProcess() failed") |
| 42 | |
Johnny Chen | 109941b | 2011-01-25 17:17:45 +0000 | [diff] [blame] | 43 | import lldbutil |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 44 | if self.process.GetState() != lldb.eStateStopped: |
Johnny Chen | 0c724ef | 2010-10-18 15:44:42 +0000 | [diff] [blame] | 45 | self.fail("Process should be in the 'stopped' state, " |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 46 | "instead the actual state is: '%s'" % |
Johnny Chen | de90f1d | 2011-04-27 17:43:07 +0000 | [diff] [blame] | 47 | lldbutil.state_type_to_str(self.process.GetState())) |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 48 | |
Johnny Chen | 0b8fd43 | 2011-04-19 22:44:20 +0000 | [diff] [blame] | 49 | if self.TraceOn(): |
Johnny Chen | d0fef81 | 2011-04-25 23:38:13 +0000 | [diff] [blame] | 50 | lldbutil.print_stacktraces(self.process) |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 51 | |
| 52 | |
| 53 | if __name__ == '__main__': |
| 54 | import atexit |
| 55 | lldb.SBDebugger.Initialize() |
| 56 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 57 | unittest2.main() |