90 lines · python
1"""2Test that the SBWatchpoint::SetEnable API works.3"""4 5import lldb6from lldbsuite.test.lldbtest import *7from lldbsuite.test.decorators import *8from lldbsuite.test import lldbplatform, lldbplatformutil9 10 11class TestWatchpointSetEnable(TestBase):12 NO_DEBUG_INFO_TESTCASE = True13 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(32 "Set a breakpoint here", main_file_spec33 )34 self.assertEqual(35 bkpt_before.GetNumLocations(), 1, "Failed setting the before breakpoint."36 )37 38 bkpt_after = self.target.BreakpointCreateBySourceRegex(39 "We should have stopped", main_file_spec40 )41 self.assertEqual(42 bkpt_after.GetNumLocations(), 1, "Failed setting the after breakpoint."43 )44 45 process = self.target.LaunchSimple(46 None, None, self.get_process_working_directory()47 )48 self.assertTrue(process, PROCESS_IS_VALID)49 50 thread = lldbutil.get_one_thread_stopped_at_breakpoint(process, bkpt_before)51 self.assertTrue(thread.IsValid(), "We didn't stop at the before breakpoint.")52 53 ret_val = lldb.SBCommandReturnObject()54 self.dbg.GetCommandInterpreter().HandleCommand(55 "watchpoint set variable -w write global_var", ret_val56 )57 self.assertTrue(58 ret_val.Succeeded(), "Watchpoint set variable did not return success."59 )60 61 wp = self.target.FindWatchpointByID(1)62 self.assertTrue(wp.IsValid(), "Didn't make a valid watchpoint.")63 self.assertNotEqual(64 wp.GetWatchAddress(), lldb.LLDB_INVALID_ADDRESS, "Watch address is invalid"65 )66 67 wp.SetEnabled(False)68 self.assertTrue(not wp.IsEnabled(), "The watchpoint thinks it is still enabled")69 70 process.Continue()71 72 stop_reason = thread.GetStopReason()73 74 self.assertStopReason(75 stop_reason, lldb.eStopReasonBreakpoint, "We didn't stop at our breakpoint."76 )77 78 if test_enable:79 wp.SetEnabled(True)80 self.assertTrue(81 wp.IsEnabled(), "The watchpoint thinks it is still disabled."82 )83 process.Continue()84 stop_reason = thread.GetStopReason()85 self.assertStopReason(86 stop_reason,87 lldb.eStopReasonWatchpoint,88 "We didn't stop at our watchpoint",89 )90