1""" 2Make sure the frame variable -g, -a, and -l flags work. 3""" 4 5 6 7import lldb 8import lldbsuite.test.lldbutil as lldbutil 9from lldbsuite.test.lldbtest import * 10 11 12class TestFrameVar(TestBase): 13 14 mydir = TestBase.compute_mydir(__file__) 15 16 # If your test case doesn't stress debug info, the 17 # set this to true. That way it won't be run once for 18 # each debug info format. 19 NO_DEBUG_INFO_TESTCASE = True 20 21 def test_frame_var(self): 22 self.build() 23 self.do_test() 24 25 def do_test(self): 26 target = self.createTestTarget() 27 28 # Now create a breakpoint in main.c at the source matching 29 # "Set a breakpoint here" 30 breakpoint = target.BreakpointCreateBySourceRegex( 31 "Set a breakpoint here", lldb.SBFileSpec("main.c")) 32 self.assertTrue(breakpoint and 33 breakpoint.GetNumLocations() >= 1, 34 VALID_BREAKPOINT) 35 36 error = lldb.SBError() 37 # This is the launch info. If you want to launch with arguments or 38 # environment variables, add them using SetArguments or 39 # SetEnvironmentEntries 40 41 launch_info = target.GetLaunchInfo() 42 process = target.Launch(launch_info, error) 43 self.assertTrue(process, PROCESS_IS_VALID) 44 45 # Did we hit our breakpoint? 46 from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint 47 threads = get_threads_stopped_at_breakpoint(process, breakpoint) 48 self.assertEqual( 49 len(threads), 1, 50 "There should be a thread stopped at our breakpoint") 51 52 # The hit count for the breakpoint should be 1. 53 self.assertEquals(breakpoint.GetHitCount(), 1) 54 55 frame = threads[0].GetFrameAtIndex(0) 56 command_result = lldb.SBCommandReturnObject() 57 interp = self.dbg.GetCommandInterpreter() 58 59 # Just get args: 60 result = interp.HandleCommand("frame var -l", command_result) 61 self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") 62 output = command_result.GetOutput() 63 self.assertIn("argc", output, "Args didn't find argc") 64 self.assertIn("argv", output, "Args didn't find argv") 65 self.assertNotIn("test_var", output, "Args found a local") 66 self.assertNotIn("g_var", output, "Args found a global") 67 68 # Just get locals: 69 result = interp.HandleCommand("frame var -a", command_result) 70 self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") 71 output = command_result.GetOutput() 72 self.assertNotIn("argc", output, "Locals found argc") 73 self.assertNotIn("argv", output, "Locals found argv") 74 self.assertIn("test_var", output, "Locals didn't find test_var") 75 self.assertNotIn("g_var", output, "Locals found a global") 76 77 # Get the file statics: 78 result = interp.HandleCommand("frame var -l -a -g", command_result) 79 self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") 80 output = command_result.GetOutput() 81 self.assertNotIn("argc", output, "Globals found argc") 82 self.assertNotIn("argv", output, "Globals found argv") 83 self.assertNotIn("test_var", output, "Globals found test_var") 84 self.assertIn("g_var", output, "Globals didn't find g_var") 85 86 87 88