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 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 13 | mydir = TestBase.compute_mydir(__file__) |
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 | |
Pavel Labath | ecc728b | 2015-06-25 15:25:30 +0000 | [diff] [blame] | 21 | @expectedFailureAll("llvm.org/pr23043", ["linux"], archs=["i386"]) # We are unable to produce a backtrace of the main thread when the thread is blocked in fgets |
Zachary Turner | 9c7b08e | 2015-09-11 20:01:24 +0000 | [diff] [blame^] | 22 | @expectedFailureWindows("llvm.org/pr24778") |
Johnny Chen | 5ccbccf | 2011-07-30 01:39:58 +0000 | [diff] [blame] | 23 | @python_api_test |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 24 | def test_stack_traces(self): |
| 25 | """Test SBprocess and SBThread APIs with printing of the stack traces.""" |
| 26 | self.buildDefault() |
| 27 | self.break_and_print_stacktraces() |
| 28 | |
| 29 | def break_and_print_stacktraces(self): |
| 30 | """Break at main.cpp:68 and do a threads dump""" |
Vince Harron | 091a95d | 2015-03-31 17:45:54 +0000 | [diff] [blame] | 31 | |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 32 | exe = os.path.join(os.getcwd(), "a.out") |
| 33 | |
| 34 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 112f569 | 2011-05-17 22:14:39 +0000 | [diff] [blame] | 35 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 36 | |
Johnny Chen | c043de1 | 2010-11-11 20:18:36 +0000 | [diff] [blame] | 37 | breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line) |
Johnny Chen | 112f569 | 2011-05-17 22:14:39 +0000 | [diff] [blame] | 38 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 39 | |
| 40 | # Now launch the process, and do not stop at entry point. |
Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 41 | process = target.LaunchSimple (["abc", "xyz"], None, self.get_process_working_directory()) |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 42 | |
Johnny Chen | 1d3e880 | 2011-07-11 23:38:23 +0000 | [diff] [blame] | 43 | if not process: |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 44 | self.fail("SBTarget.LaunchProcess() failed") |
| 45 | |
Johnny Chen | 109941b | 2011-01-25 17:17:45 +0000 | [diff] [blame] | 46 | import lldbutil |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 47 | if process.GetState() != lldb.eStateStopped: |
Johnny Chen | 0c724ef | 2010-10-18 15:44:42 +0000 | [diff] [blame] | 48 | self.fail("Process should be in the 'stopped' state, " |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 49 | "instead the actual state is: '%s'" % |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 50 | lldbutil.state_type_to_str(process.GetState())) |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 51 | |
Johnny Chen | 0d4f6dd | 2011-06-16 22:07:48 +0000 | [diff] [blame] | 52 | stacktraces = lldbutil.print_stacktraces(process, string_buffer=True) |
| 53 | self.expect(stacktraces, exe=False, |
| 54 | substrs = ['(int)argc=3']) |
Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 55 | |
| 56 | |
| 57 | if __name__ == '__main__': |
| 58 | import atexit |
| 59 | lldb.SBDebugger.Initialize() |
| 60 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 61 | unittest2.main() |