blob: 09945f5cbe54afa3b8ac2d2c9ff558877c5ad6a3 [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."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000026 self.build()
Johnny Chen7ea9aee2010-10-07 21:38:28 +000027 exe = os.path.join(os.getcwd(), "a.out")
28
29 target = self.dbg.CreateTarget(exe)
Johnny Chen112f5692011-05-17 22:14:39 +000030 self.assertTrue(target, VALID_TARGET)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000031
Johnny Chenc043de12010-11-11 20:18:36 +000032 breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
Johnny Chen112f5692011-05-17 22:14:39 +000033 self.assertTrue(breakpoint, VALID_BREAKPOINT)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000034
35 # Now launch the process, and do not stop at entry point.
Greg Claytonc6947512013-12-13 19:18:59 +000036 process = target.LaunchSimple (["abc", "xyz"], None, self.get_process_working_directory())
Johnny Chen7ea9aee2010-10-07 21:38:28 +000037
Johnny Chen1d3e8802011-07-11 23:38:23 +000038 if not process:
Johnny Chen7ea9aee2010-10-07 21:38:28 +000039 self.fail("SBTarget.LaunchProcess() failed")
40
Johnny Chen109941b2011-01-25 17:17:45 +000041 import lldbutil
Johnny Chen5a0bee72011-06-15 22:14:12 +000042 if process.GetState() != lldb.eStateStopped:
Johnny Chen0c724ef2010-10-18 15:44:42 +000043 self.fail("Process should be in the 'stopped' state, "
Johnny Chen7ea9aee2010-10-07 21:38:28 +000044 "instead the actual state is: '%s'" %
Johnny Chen5a0bee72011-06-15 22:14:12 +000045 lldbutil.state_type_to_str(process.GetState()))
Johnny Chen7ea9aee2010-10-07 21:38:28 +000046
Johnny Chen0d4f6dd2011-06-16 22:07:48 +000047 stacktraces = lldbutil.print_stacktraces(process, string_buffer=True)
48 self.expect(stacktraces, exe=False,
49 substrs = ['(int)argc=3'])
Johnny Chen7ea9aee2010-10-07 21:38:28 +000050
51
52if __name__ == '__main__':
53 import atexit
54 lldb.SBDebugger.Initialize()
55 atexit.register(lambda: lldb.SBDebugger.Terminate())
56 unittest2.main()