1""" 2Test SBprocess and SBThread APIs with printing of the stack traces using lldbutil. 3""" 4 5import os, time 6import re 7import unittest2 8import lldb 9from lldbtest import * 10 11class ThreadsStackTracesTestCase(TestBase): 12 13 mydir = "python_api/lldbutil/process" 14 15 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 21 @expectedFailureFreeBSD("llvm.org/pr16696") # live debugging lacks threaded inferior support 22 @expectedFailureLinux # llvm.org/pr14323 23 @python_api_test 24 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""" 31 exe = os.path.join(os.getcwd(), "a.out") 32 33 target = self.dbg.CreateTarget(exe) 34 self.assertTrue(target, VALID_TARGET) 35 36 breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line) 37 self.assertTrue(breakpoint, VALID_BREAKPOINT) 38 39 # Now launch the process, and do not stop at entry point. 40 process = target.LaunchSimple(["abc", "xyz"], None, os.getcwd()) 41 42 if not process: 43 self.fail("SBTarget.LaunchProcess() failed") 44 45 import lldbutil 46 if process.GetState() != lldb.eStateStopped: 47 self.fail("Process should be in the 'stopped' state, " 48 "instead the actual state is: '%s'" % 49 lldbutil.state_type_to_str(process.GetState())) 50 51 stacktraces = lldbutil.print_stacktraces(process, string_buffer=True) 52 self.expect(stacktraces, exe=False, 53 substrs = ['(int)argc=3']) 54 55 56if __name__ == '__main__': 57 import atexit 58 lldb.SBDebugger.Initialize() 59 atexit.register(lambda: lldb.SBDebugger.Terminate()) 60 unittest2.main() 61