1""" 2Test utility functions for the frame object. 3""" 4 5import lldb 6from lldbsuite.test.decorators import * 7from lldbsuite.test.lldbtest import * 8from lldbsuite.test import lldbutil 9 10 11class FrameUtilsTestCase(TestBase): 12 def setUp(self): 13 # Call super's setUp(). 14 TestBase.setUp(self) 15 # Find the line number to break inside main(). 16 self.line = line_number("main.c", "// Find the line number here.") 17 18 def test_frame_utils(self): 19 """Test utility functions for the frame object.""" 20 self.build() 21 exe = self.getBuildArtifact("a.out") 22 23 target = self.dbg.CreateTarget(exe) 24 self.assertTrue(target, VALID_TARGET) 25 26 breakpoint = target.BreakpointCreateByLocation("main.c", self.line) 27 self.assertTrue(breakpoint, VALID_BREAKPOINT) 28 29 # Now launch the process, and do not stop at entry point. 30 process = target.LaunchSimple(None, None, self.get_process_working_directory()) 31 32 if not process: 33 self.fail("SBTarget.LaunchProcess() failed") 34 self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) 35 36 import lldbsuite.test.lldbutil as lldbutil 37 38 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) 39 self.assertTrue(thread) 40 frame0 = thread.GetFrameAtIndex(0) 41 self.assertTrue(frame0) 42 frame1 = thread.GetFrameAtIndex(1) 43 self.assertTrue(frame1) 44 parent = lldbutil.get_parent_frame(frame0) 45 self.assertTrue(parent and parent.GetFrameID() == frame1.GetFrameID()) 46 frame0_args = lldbutil.get_args_as_string(frame0) 47 parent_args = lldbutil.get_args_as_string(parent) 48 self.assertTrue(frame0_args and parent_args and "(int)val=1" in frame0_args) 49 if self.TraceOn(): 50 lldbutil.print_stacktrace(thread) 51 print("Current frame: %s" % frame0_args) 52 print("Parent frame: %s" % parent_args) 53