1""" 2Test that the SBWatchpoint::SetEnable API works. 3""" 4 5import lldb 6from lldbsuite.test.lldbtest import * 7from lldbsuite.test.decorators import * 8from lldbsuite.test import lldbplatform, lldbplatformutil 9 10 11class TestWatchpointSetEnable(TestBase): 12 mydir = TestBase.compute_mydir(__file__) 13 NO_DEBUG_INFO_TESTCASE = True 14 15 def test_disable_works (self): 16 """Set a watchpoint, disable it, and make sure it doesn't get hit.""" 17 self.build() 18 self.do_test(False) 19 20 def test_disable_enable_works (self): 21 """Set a watchpoint, disable it, and make sure it doesn't get hit.""" 22 self.build() 23 self.do_test(True) 24 25 def do_test(self, test_enable): 26 """Set a watchpoint, disable it and make sure it doesn't get hit.""" 27 28 main_file_spec = lldb.SBFileSpec("main.c") 29 30 self.target = self.createTestTarget() 31 32 bkpt_before = self.target.BreakpointCreateBySourceRegex("Set a breakpoint here", main_file_spec) 33 self.assertEqual(bkpt_before.GetNumLocations(), 1, "Failed setting the before breakpoint.") 34 35 bkpt_after = self.target.BreakpointCreateBySourceRegex("We should have stopped", main_file_spec) 36 self.assertEqual(bkpt_after.GetNumLocations(), 1, "Failed setting the after breakpoint.") 37 38 process = self.target.LaunchSimple( 39 None, None, self.get_process_working_directory()) 40 self.assertTrue(process, PROCESS_IS_VALID) 41 42 thread = lldbutil.get_one_thread_stopped_at_breakpoint(process, bkpt_before) 43 self.assertTrue(thread.IsValid(), "We didn't stop at the before breakpoint.") 44 45 ret_val = lldb.SBCommandReturnObject() 46 self.dbg.GetCommandInterpreter().HandleCommand("watchpoint set variable -w write global_var", ret_val) 47 self.assertTrue(ret_val.Succeeded(), "Watchpoint set variable did not return success.") 48 49 wp = self.target.FindWatchpointByID(1) 50 self.assertTrue(wp.IsValid(), "Didn't make a valid watchpoint.") 51 self.assertNotEqual(wp.GetWatchAddress(), lldb.LLDB_INVALID_ADDRESS, "Watch address is invalid") 52 53 wp.SetEnabled(False) 54 self.assertTrue(not wp.IsEnabled(), "The watchpoint thinks it is still enabled") 55 56 process.Continue() 57 58 stop_reason = thread.GetStopReason() 59 60 self.assertEqual(stop_reason, lldb.eStopReasonBreakpoint, "We didn't stop at our breakpoint.") 61 62 if test_enable: 63 wp.SetEnabled(True) 64 self.assertTrue(wp.IsEnabled(), "The watchpoint thinks it is still disabled.") 65 process.Continue() 66 stop_reason = thread.GetStopReason() 67 self.assertEqual(stop_reason, lldb.eStopReasonWatchpoint, "We didn't stop at our watchpoint") 68 69