| 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 | |
| Zachary Turner | 35d017f | 2015-10-23 17:04:29 +0000 | [diff] [blame] | 5 | from __future__ import print_function |
| 6 | |
| Zachary Turner | 0a0490b | 2015-10-27 20:12:05 +0000 | [diff] [blame^] | 7 | import use_lldb_suite |
| Zachary Turner | 77db4a8 | 2015-10-22 20:06:20 +0000 | [diff] [blame] | 8 | |
| Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 9 | import os, time |
| 10 | import re |
| Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 11 | import lldb |
| 12 | from lldbtest import * |
| 13 | |
| 14 | class ThreadsStackTracesTestCase(TestBase): |
| 15 | |
| Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 16 | mydir = TestBase.compute_mydir(__file__) |
| Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 17 | |
| Johnny Chen | c043de1 | 2010-11-11 20:18:36 +0000 | [diff] [blame] | 18 | def setUp(self): |
| 19 | # Call super's setUp(). |
| 20 | TestBase.setUp(self) |
| 21 | # Find the line number to break inside main(). |
| 22 | self.line = line_number('main.cpp', '// Set break point at this line.') |
| 23 | |
| Pavel Labath | ecc728b | 2015-06-25 15:25:30 +0000 | [diff] [blame] | 24 | @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] | 25 | @expectedFailureWindows("llvm.org/pr24778") |
| Pavel Labath | dc8b2d3 | 2015-10-26 09:28:32 +0000 | [diff] [blame] | 26 | @add_test_categories(['pyapi']) |
| Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 27 | def test_stack_traces(self): |
| 28 | """Test SBprocess and SBThread APIs with printing of the stack traces.""" |
| Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 29 | self.build() |
| Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 30 | exe = os.path.join(os.getcwd(), "a.out") |
| 31 | |
| 32 | target = self.dbg.CreateTarget(exe) |
| Johnny Chen | 112f569 | 2011-05-17 22:14:39 +0000 | [diff] [blame] | 33 | self.assertTrue(target, VALID_TARGET) |
| Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 34 | |
| Johnny Chen | c043de1 | 2010-11-11 20:18:36 +0000 | [diff] [blame] | 35 | breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line) |
| Johnny Chen | 112f569 | 2011-05-17 22:14:39 +0000 | [diff] [blame] | 36 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
| Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 37 | |
| 38 | # Now launch the process, and do not stop at entry point. |
| Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 39 | process = target.LaunchSimple (["abc", "xyz"], None, self.get_process_working_directory()) |
| Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 40 | |
| Johnny Chen | 1d3e880 | 2011-07-11 23:38:23 +0000 | [diff] [blame] | 41 | if not process: |
| Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 42 | self.fail("SBTarget.LaunchProcess() failed") |
| 43 | |
| Johnny Chen | 109941b | 2011-01-25 17:17:45 +0000 | [diff] [blame] | 44 | import lldbutil |
| Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 45 | if process.GetState() != lldb.eStateStopped: |
| Johnny Chen | 0c724ef | 2010-10-18 15:44:42 +0000 | [diff] [blame] | 46 | self.fail("Process should be in the 'stopped' state, " |
| Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 47 | "instead the actual state is: '%s'" % |
| Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 48 | lldbutil.state_type_to_str(process.GetState())) |
| Johnny Chen | 7ea9aee | 2010-10-07 21:38:28 +0000 | [diff] [blame] | 49 | |
| Johnny Chen | 0d4f6dd | 2011-06-16 22:07:48 +0000 | [diff] [blame] | 50 | stacktraces = lldbutil.print_stacktraces(process, string_buffer=True) |
| 51 | self.expect(stacktraces, exe=False, |
| 52 | substrs = ['(int)argc=3']) |