blob: 43bf1eb6c71ab8bd71f746b6cb1a04090be8df04 [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 Chend762ff12011-02-03 23:15:53 +000038 self.process = target.Launch (self.dbg.GetListener(), None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, rc)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000039
Johnny Chen112f5692011-05-17 22:14:39 +000040 if not rc.Success() or not self.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 Chen7ea9aee2010-10-07 21:38:28 +000044 if self.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 Chende90f1d2011-04-27 17:43:07 +000047 lldbutil.state_type_to_str(self.process.GetState()))
Johnny Chen7ea9aee2010-10-07 21:38:28 +000048
Johnny Chen0b8fd432011-04-19 22:44:20 +000049 if self.TraceOn():
Johnny Chend0fef812011-04-25 23:38:13 +000050 lldbutil.print_stacktraces(self.process)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000051
52
53if __name__ == '__main__':
54 import atexit
55 lldb.SBDebugger.Initialize()
56 atexit.register(lambda: lldb.SBDebugger.Terminate())
57 unittest2.main()