1""" 2Test utility functions for the frame object. 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 FrameUtilsTestCase(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 break inside main(). 22 self.line = line_number('main.c', 23 "// Find the line number here.") 24 25 def test_frame_utils(self): 26 """Test utility functions for the frame object.""" 27 self.build() 28 exe = self.getBuildArtifact("a.out") 29 30 target = self.dbg.CreateTarget(exe) 31 self.assertTrue(target, VALID_TARGET) 32 33 breakpoint = target.BreakpointCreateByLocation("main.c", self.line) 34 self.assertTrue(breakpoint, VALID_BREAKPOINT) 35 36 # Now launch the process, and do not stop at entry point. 37 process = target.LaunchSimple( 38 None, None, self.get_process_working_directory()) 39 40 if not process: 41 self.fail("SBTarget.LaunchProcess() failed") 42 self.assertEqual(process.GetState(), lldb.eStateStopped, 43 PROCESS_STOPPED) 44 45 import lldbsuite.test.lldbutil as lldbutil 46 thread = lldbutil.get_stopped_thread( 47 process, lldb.eStopReasonBreakpoint) 48 self.assertTrue(thread) 49 frame0 = thread.GetFrameAtIndex(0) 50 self.assertTrue(frame0) 51 frame1 = thread.GetFrameAtIndex(1) 52 self.assertTrue(frame1) 53 parent = lldbutil.get_parent_frame(frame0) 54 self.assertTrue(parent and parent.GetFrameID() == frame1.GetFrameID()) 55 frame0_args = lldbutil.get_args_as_string(frame0) 56 parent_args = lldbutil.get_args_as_string(parent) 57 self.assertTrue( 58 frame0_args and parent_args and "(int)val=1" in frame0_args) 59 if self.TraceOn(): 60 lldbutil.print_stacktrace(thread) 61 print("Current frame: %s" % frame0_args) 62 print("Parent frame: %s" % parent_args) 63