1""" 2Testlldb Python SBFrame APIs IsInlined() and GetFunctionName(). 3""" 4 5from __future__ import print_function 6 7 8import lldb 9from lldbsuite.test.decorators import * 10from lldbsuite.test.lldbtest import * 11from lldbsuite.test import lldbutil 12 13 14class InlinedFrameAPITestCase(TestBase): 15 16 mydir = TestBase.compute_mydir(__file__) 17 18 def setUp(self): 19 # Call super's setUp(). 20 TestBase.setUp(self) 21 # Find the line number to of function 'c'. 22 self.source = 'inlines.c' 23 self.first_stop = line_number( 24 self.source, '// This should correspond to the first break stop.') 25 self.second_stop = line_number( 26 self.source, '// This should correspond to the second break stop.') 27 28 @add_test_categories(['pyapi']) 29 def test_stop_at_outer_inline(self): 30 """Exercise SBFrame.IsInlined() and SBFrame.GetFunctionName().""" 31 self.build() 32 exe = self.getBuildArtifact("a.out") 33 34 # Create a target by the debugger. 35 target = self.dbg.CreateTarget(exe) 36 self.assertTrue(target, VALID_TARGET) 37 38 # Now create a breakpoint on main.c by the name of 'inner_inline'. 39 breakpoint = target.BreakpointCreateByName('inner_inline', 'a.out') 40 self.trace("breakpoint:", breakpoint) 41 self.assertTrue(breakpoint and 42 breakpoint.GetNumLocations() > 1, 43 VALID_BREAKPOINT) 44 45 # Now launch the process, and do not stop at the entry point. 46 process = target.LaunchSimple( 47 None, None, self.get_process_working_directory()) 48 49 process = target.GetProcess() 50 self.assertTrue(process.GetState() == lldb.eStateStopped, 51 PROCESS_STOPPED) 52 53 import lldbsuite.test.lldbutil as lldbutil 54 stack_traces1 = lldbutil.print_stacktraces(process, string_buffer=True) 55 if self.TraceOn(): 56 print( 57 "Full stack traces when first stopped on the breakpoint 'inner_inline':") 58 print(stack_traces1) 59 60 # The first breakpoint should correspond to an inlined call frame. 61 # If it's an inlined call frame, expect to find, in the stack trace, 62 # that there is a frame which corresponds to the following call site: 63 # 64 # outer_inline (argc); 65 # 66 thread = lldbutil.get_stopped_thread( 67 process, lldb.eStopReasonBreakpoint) 68 self.assertIsNotNone(thread) 69 70 frame0 = thread.GetFrameAtIndex(0) 71 if frame0.IsInlined(): 72 filename = frame0.GetLineEntry().GetFileSpec().GetFilename() 73 self.assertTrue(filename == self.source) 74 self.expect( 75 stack_traces1, "First stop at %s:%d" % 76 (self.source, self.first_stop), exe=False, substrs=[ 77 '%s:%d' % 78 (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( 85 process, string_buffer=True) 86 if self.TraceOn(): 87 print( 88 "Full stack traces when stopped on the breakpoint 'inner_inline' for the second time:") 89 print(stack_traces2) 90 self.expect( 91 stack_traces2, "Second stop at %s:%d" % 92 (self.source, self.second_stop), exe=False, substrs=[ 93 '%s:%d' % 94 (self.source, self.second_stop)]) 95