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 def test_stop_at_outer_inline(self): 29 """Exercise SBFrame.IsInlined() and SBFrame.GetFunctionName().""" 30 self.build() 31 exe = self.getBuildArtifact("a.out") 32 33 # Create a target by the debugger. 34 target = self.dbg.CreateTarget(exe) 35 self.assertTrue(target, VALID_TARGET) 36 37 # Now create a breakpoint on main.c by the name of 'inner_inline'. 38 breakpoint = target.BreakpointCreateByName('inner_inline', 'a.out') 39 self.trace("breakpoint:", breakpoint) 40 self.assertTrue(breakpoint and 41 breakpoint.GetNumLocations() > 1, 42 VALID_BREAKPOINT) 43 44 # Now launch the process, and do not stop at the entry point. 45 process = target.LaunchSimple( 46 None, None, self.get_process_working_directory()) 47 48 process = target.GetProcess() 49 self.assertEqual(process.GetState(), lldb.eStateStopped, 50 PROCESS_STOPPED) 51 52 import lldbsuite.test.lldbutil as lldbutil 53 stack_traces1 = lldbutil.print_stacktraces(process, string_buffer=True) 54 if self.TraceOn(): 55 print( 56 "Full stack traces when first stopped on the breakpoint 'inner_inline':") 57 print(stack_traces1) 58 59 # The first breakpoint should correspond to an inlined call frame. 60 # If it's an inlined call frame, expect to find, in the stack trace, 61 # that there is a frame which corresponds to the following call site: 62 # 63 # outer_inline (argc); 64 # 65 thread = lldbutil.get_stopped_thread( 66 process, lldb.eStopReasonBreakpoint) 67 self.assertIsNotNone(thread) 68 69 frame0 = thread.GetFrameAtIndex(0) 70 if frame0.IsInlined(): 71 filename = frame0.GetLineEntry().GetFileSpec().GetFilename() 72 self.assertEqual(filename, self.source) 73 self.expect( 74 stack_traces1, "First stop at %s:%d" % 75 (self.source, self.first_stop), exe=False, substrs=[ 76 '%s:%d' % 77 (self.source, self.first_stop)]) 78 79 # Expect to break again for the second time. 80 process.Continue() 81 self.assertEqual(process.GetState(), lldb.eStateStopped, 82 PROCESS_STOPPED) 83 stack_traces2 = lldbutil.print_stacktraces( 84 process, string_buffer=True) 85 if self.TraceOn(): 86 print( 87 "Full stack traces when stopped on the breakpoint 'inner_inline' for the second time:") 88 print(stack_traces2) 89 self.expect( 90 stack_traces2, "Second stop at %s:%d" % 91 (self.source, self.second_stop), exe=False, substrs=[ 92 '%s:%d' % 93 (self.source, self.second_stop)]) 94