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