1""" 2Testlldb Python SBFrame APIs IsInlined() and GetFunctionName(). 3""" 4 5import os, time 6import re 7import unittest2 8import lldb, lldbutil 9from lldbtest import * 10 11class InlinedFrameAPITestCase(TestBase): 12 13 mydir = os.path.join("python_api", "frame", "inlines") 14 15 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 16 @python_api_test 17 @dsym_test 18 def test_stop_at_outer_inline_with_dsym(self): 19 """Exercise SBFrame.IsInlined() and SBFrame.GetFunctionName().""" 20 self.buildDsym() 21 self.do_stop_at_outer_inline() 22 23 @python_api_test 24 @dwarf_test 25 def test_stop_at_outer_inline_with_dwarf(self): 26 """Exercise SBFrame.IsInlined() and SBFrame.GetFunctionName().""" 27 self.buildDwarf() 28 self.do_stop_at_outer_inline() 29 30 def setUp(self): 31 32 # Call super's setUp(). 33 TestBase.setUp(self) 34 # Find the line number to of function 'c'. 35 self.source = 'inlines.c' 36 self.first_stop = line_number(self.source, '// This should correspond to the first break stop.') 37 self.second_stop = line_number(self.source, '// This should correspond to the second break stop.') 38 39 def do_stop_at_outer_inline(self): 40 """Exercise SBFrame.IsInlined() and SBFrame.GetFunctionName().""" 41 exe = os.path.join(os.getcwd(), "a.out") 42 43 # Create a target by the debugger. 44 target = self.dbg.CreateTarget(exe) 45 self.assertTrue(target, VALID_TARGET) 46 47 # Now create a breakpoint on main.c by the name of 'inner_inline'. 48 breakpoint = target.BreakpointCreateByName('inner_inline', 'a.out') 49 #print "breakpoint:", breakpoint 50 self.assertTrue(breakpoint and 51 breakpoint.GetNumLocations() > 1, 52 VALID_BREAKPOINT) 53 54 # Now launch the process, and do not stop at the entry point. 55 process = target.LaunchSimple(None, None, os.getcwd()) 56 57 process = target.GetProcess() 58 self.assertTrue(process.GetState() == lldb.eStateStopped, 59 PROCESS_STOPPED) 60 61 import lldbutil 62 stack_traces1 = lldbutil.print_stacktraces(process, string_buffer=True) 63 if self.TraceOn(): 64 print "Full stack traces when first stopped on the breakpoint 'inner_inline':" 65 print stack_traces1 66 67 # The first breakpoint should correspond to an inlined call frame. 68 # If it's an inlined call frame, expect to find, in the stack trace, 69 # that there is a frame which corresponds to the following call site: 70 # 71 # outer_inline (argc); 72 # 73 frame0 = process.GetThreadAtIndex(0).GetFrameAtIndex(0) 74 if frame0.IsInlined(): 75 filename = frame0.GetLineEntry().GetFileSpec().GetFilename() 76 self.assertTrue(filename == self.source) 77 self.expect(stack_traces1, "First stop at %s:%d" % (self.source, self.first_stop), exe=False, 78 substrs = ['%s:%d' % (self.source, self.first_stop)]) 79 80 # Expect to break again for the second time. 81 process.Continue() 82 self.assertTrue(process.GetState() == lldb.eStateStopped, 83 PROCESS_STOPPED) 84 stack_traces2 = lldbutil.print_stacktraces(process, string_buffer=True) 85 if self.TraceOn(): 86 print "Full stack traces when stopped on the breakpoint 'inner_inline' for the second time:" 87 print stack_traces2 88 self.expect(stack_traces2, "Second stop at %s:%d" % (self.source, self.second_stop), exe=False, 89 substrs = ['%s:%d' % (self.source, self.second_stop)]) 90 91if __name__ == '__main__': 92 import atexit 93 lldb.SBDebugger.Initialize() 94 atexit.register(lambda: lldb.SBDebugger.Terminate()) 95 unittest2.main() 96