1""" 2Test stop hook functionality 3""" 4 5 6 7import lldb 8import lldbsuite.test.lldbutil as lldbutil 9from lldbsuite.test.lldbtest import * 10 11 12class TestStopHooks(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 setUp(self): 22 TestBase.setUp(self) 23 self.build() 24 self.main_source_file = lldb.SBFileSpec("main.c") 25 full_path = os.path.join(self.getSourceDir(), "main.c") 26 self.main_start_line = line_number(full_path, "main()") 27 28 def test_stop_hooks_step_out(self): 29 """Test that stop hooks fire on step-out.""" 30 self.step_out_test() 31 32 def step_out_test(self): 33 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, 34 "Set a breakpoint here", self.main_source_file) 35 36 interp = self.dbg.GetCommandInterpreter() 37 result = lldb.SBCommandReturnObject() 38 interp.HandleCommand("target stop-hook add -o 'expr g_var++'", result) 39 self.assertTrue(result.Succeeded, "Set the target stop hook") 40 thread.StepOut() 41 var = target.FindFirstGlobalVariable("g_var") 42 self.assertTrue(var.IsValid()) 43 self.assertEqual(var.GetValueAsUnsigned(), 1, "Updated g_var") 44 45