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