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 exe = self.getBuildArtifact("a.out") 27 28 # Create a target by the debugger. 29 target = self.dbg.CreateTarget(exe) 30 self.assertTrue(target, VALID_TARGET) 31 32 # Now create a breakpoint in main.c at the source matching 33 # "Set a breakpoint here" 34 breakpoint = target.BreakpointCreateBySourceRegex( 35 "Set a breakpoint here", lldb.SBFileSpec("main.c")) 36 self.assertTrue(breakpoint and 37 breakpoint.GetNumLocations() >= 1, 38 VALID_BREAKPOINT) 39 40 error = lldb.SBError() 41 # This is the launch info. If you want to launch with arguments or 42 # environment variables, add them using SetArguments or 43 # SetEnvironmentEntries 44 45 launch_info = target.GetLaunchInfo() 46 process = target.Launch(launch_info, error) 47 self.assertTrue(process, PROCESS_IS_VALID) 48 49 # Did we hit our breakpoint? 50 from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint 51 threads = get_threads_stopped_at_breakpoint(process, breakpoint) 52 self.assertEqual( 53 len(threads), 1, 54 "There should be a thread stopped at our breakpoint") 55 56 # The hit count for the breakpoint should be 1. 57 self.assertEquals(breakpoint.GetHitCount(), 1) 58 59 frame = threads[0].GetFrameAtIndex(0) 60 command_result = lldb.SBCommandReturnObject() 61 interp = self.dbg.GetCommandInterpreter() 62 63 # Just get args: 64 result = interp.HandleCommand("frame var -l", command_result) 65 self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") 66 output = command_result.GetOutput() 67 self.assertIn("argc", output, "Args didn't find argc") 68 self.assertIn("argv", output, "Args didn't find argv") 69 self.assertNotIn("test_var", output, "Args found a local") 70 self.assertNotIn("g_var", output, "Args found a global") 71 72 # Just get locals: 73 result = interp.HandleCommand("frame var -a", command_result) 74 self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") 75 output = command_result.GetOutput() 76 self.assertNotIn("argc", output, "Locals found argc") 77 self.assertNotIn("argv", output, "Locals found argv") 78 self.assertIn("test_var", output, "Locals didn't find test_var") 79 self.assertNotIn("g_var", output, "Locals found a global") 80 81 # Get the file statics: 82 result = interp.HandleCommand("frame var -l -a -g", command_result) 83 self.assertEqual(result, lldb.eReturnStatusSuccessFinishResult, "frame var -a didn't succeed") 84 output = command_result.GetOutput() 85 self.assertNotIn("argc", output, "Globals found argc") 86 self.assertNotIn("argv", output, "Globals found argv") 87 self.assertNotIn("test_var", output, "Globals found test_var") 88 self.assertIn("g_var", output, "Globals didn't find g_var") 89 90 91 92