blob: cd13d688e19453d9d89f23bb8a4cc7bff1578652 [file] [log] [blame]
Johnny Chen7ea9aee2010-10-07 21:38:28 +00001"""
Johnny Chen0b8fd432011-04-19 22:44:20 +00002Test SBprocess and SBThread APIs with printing of the stack traces using lldbutil.
Johnny Chen7ea9aee2010-10-07 21:38:28 +00003"""
4
5import os, time
6import re
7import unittest2
8import lldb
9from lldbtest import *
10
11class ThreadsStackTracesTestCase(TestBase):
12
Greg Clayton4570d3e2013-12-10 23:19:29 +000013 mydir = TestBase.compute_mydir(__file__)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000014
Johnny Chenc043de12010-11-11 20:18:36 +000015 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 Labathecc728b2015-06-25 15:25:30 +000021 @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 Turner9c7b08e2015-09-11 20:01:24 +000022 @expectedFailureWindows("llvm.org/pr24778")
Johnny Chen5ccbccf2011-07-30 01:39:58 +000023 @python_api_test
Johnny Chen7ea9aee2010-10-07 21:38:28 +000024 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 Harron091a95d2015-03-31 17:45:54 +000031
Johnny Chen7ea9aee2010-10-07 21:38:28 +000032 exe = os.path.join(os.getcwd(), "a.out")
33
34 target = self.dbg.CreateTarget(exe)
Johnny Chen112f5692011-05-17 22:14:39 +000035 self.assertTrue(target, VALID_TARGET)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000036
Johnny Chenc043de12010-11-11 20:18:36 +000037 breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
Johnny Chen112f5692011-05-17 22:14:39 +000038 self.assertTrue(breakpoint, VALID_BREAKPOINT)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000039
40 # Now launch the process, and do not stop at entry point.
Greg Claytonc6947512013-12-13 19:18:59 +000041 process = target.LaunchSimple (["abc", "xyz"], None, self.get_process_working_directory())
Johnny Chen7ea9aee2010-10-07 21:38:28 +000042
Johnny Chen1d3e8802011-07-11 23:38:23 +000043 if not process:
Johnny Chen7ea9aee2010-10-07 21:38:28 +000044 self.fail("SBTarget.LaunchProcess() failed")
45
Johnny Chen109941b2011-01-25 17:17:45 +000046 import lldbutil
Johnny Chen5a0bee72011-06-15 22:14:12 +000047 if process.GetState() != lldb.eStateStopped:
Johnny Chen0c724ef2010-10-18 15:44:42 +000048 self.fail("Process should be in the 'stopped' state, "
Johnny Chen7ea9aee2010-10-07 21:38:28 +000049 "instead the actual state is: '%s'" %
Johnny Chen5a0bee72011-06-15 22:14:12 +000050 lldbutil.state_type_to_str(process.GetState()))
Johnny Chen7ea9aee2010-10-07 21:38:28 +000051
Johnny Chen0d4f6dd2011-06-16 22:07:48 +000052 stacktraces = lldbutil.print_stacktraces(process, string_buffer=True)
53 self.expect(stacktraces, exe=False,
54 substrs = ['(int)argc=3'])
Johnny Chen7ea9aee2010-10-07 21:38:28 +000055
56
57if __name__ == '__main__':
58 import atexit
59 lldb.SBDebugger.Initialize()
60 atexit.register(lambda: lldb.SBDebugger.Terminate())
61 unittest2.main()