blob: 4dbea69525b369277b7ad720e01094fb83d45f41 [file] [log] [blame]
Johnny Chen7ea9aee2010-10-07 21:38:28 +00001"""
2Test SBprocess and SBThread APIs with printing of the stack traces.
3"""
4
5import os, time
6import re
7import unittest2
8import lldb
9from lldbtest import *
10
11class ThreadsStackTracesTestCase(TestBase):
12
13 mydir = "threads"
14
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)
31 self.assertTrue(target.IsValid(), VALID_TARGET)
32
Johnny Chenc043de12010-11-11 20:18:36 +000033 breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000034 self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
35
36 # Now launch the process, and do not stop at entry point.
37 rc = lldb.SBError()
Greg Clayton6f907e62011-01-23 17:46:22 +000038 self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, rc)
Johnny Chen7ea9aee2010-10-07 21:38:28 +000039
40 if not rc.Success() or not self.process.IsValid():
41 self.fail("SBTarget.LaunchProcess() failed")
42
43 if self.process.GetState() != lldb.eStateStopped:
Johnny Chen0c724ef2010-10-18 15:44:42 +000044 self.fail("Process should be in the 'stopped' state, "
Johnny Chen7ea9aee2010-10-07 21:38:28 +000045 "instead the actual state is: '%s'" %
Johnny Chen28ae2942010-10-07 22:15:58 +000046 lldbutil.StateTypeString(self.process.GetState()))
Johnny Chen7ea9aee2010-10-07 21:38:28 +000047
48 import lldbutil
49 lldbutil.PrintStackTraces(self.process)
50
51
52if __name__ == '__main__':
53 import atexit
54 lldb.SBDebugger.Initialize()
55 atexit.register(lambda: lldb.SBDebugger.Terminate())
56 unittest2.main()