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