blob: 0e652198c7dd47fb3d8d66ff45ac1c645f9de465 [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
Johnny Chenad7372c2011-05-12 00:32:41 +000013 mydir = "python_api/lldbutil/process"
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
Johnny Chen7ea9aee2010-10-07 21:38:28 +000021 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 Chen112f5692011-05-17 22:14:39 +000031 self.assertTrue(target, VALID_TARGET)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000032
Johnny Chenc043de12010-11-11 20:18:36 +000033 breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
Johnny Chen112f5692011-05-17 22:14:39 +000034 self.assertTrue(breakpoint, VALID_BREAKPOINT)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000035
36 # Now launch the process, and do not stop at entry point.
37 rc = lldb.SBError()
Johnny Chen0d4f6dd2011-06-16 22:07:48 +000038 process = target.Launch (self.dbg.GetListener(), ["abc", "xyz"], None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, rc)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000039
Johnny Chen5a0bee72011-06-15 22:14:12 +000040 if not rc.Success() or not process:
Johnny Chen7ea9aee2010-10-07 21:38:28 +000041 self.fail("SBTarget.LaunchProcess() failed")
42
Johnny Chen109941b2011-01-25 17:17:45 +000043 import lldbutil
Johnny Chen5a0bee72011-06-15 22:14:12 +000044 if process.GetState() != lldb.eStateStopped:
Johnny Chen0c724ef2010-10-18 15:44:42 +000045 self.fail("Process should be in the 'stopped' state, "
Johnny Chen7ea9aee2010-10-07 21:38:28 +000046 "instead the actual state is: '%s'" %
Johnny Chen5a0bee72011-06-15 22:14:12 +000047 lldbutil.state_type_to_str(process.GetState()))
Johnny Chen7ea9aee2010-10-07 21:38:28 +000048
Johnny Chen0d4f6dd2011-06-16 22:07:48 +000049 stacktraces = lldbutil.print_stacktraces(process, string_buffer=True)
50 self.expect(stacktraces, exe=False,
51 substrs = ['(int)argc=3'])
Johnny Chen7ea9aee2010-10-07 21:38:28 +000052
53
54if __name__ == '__main__':
55 import atexit
56 lldb.SBDebugger.Initialize()
57 atexit.register(lambda: lldb.SBDebugger.Terminate())
58 unittest2.main()