2 Test that the SBWatchpoint::SetEnable API works.
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test import lldbplatform, lldbplatformutil
11 class TestWatchpointSetEnable(TestBase):
12 mydir = TestBase.compute_mydir(__file__)
13 NO_DEBUG_INFO_TESTCASE = True
15 def test_disable_works (self):
16 """Set a watchpoint, disable it, and make sure it doesn't get hit."""
20 def test_disable_enable_works (self):
21 """Set a watchpoint, disable it, and make sure it doesn't get hit."""
25 def do_test(self, test_enable):
26 """Set a watchpoint, disable it and make sure it doesn't get hit."""
28 exe = self.getBuildArtifact("a.out")
29 main_file_spec = lldb.SBFileSpec("main.c")
31 # Create a target by the debugger.
32 self.target = self.dbg.CreateTarget(exe)
33 self.assertTrue(self.target, VALID_TARGET)
35 bkpt_before = self.target.BreakpointCreateBySourceRegex("Set a breakpoint here", main_file_spec)
36 self.assertEqual(bkpt_before.GetNumLocations(), 1, "Failed setting the before breakpoint.")
38 bkpt_after = self.target.BreakpointCreateBySourceRegex("We should have stopped", main_file_spec)
39 self.assertEqual(bkpt_after.GetNumLocations(), 1, "Failed setting the after breakpoint.")
41 process = self.target.LaunchSimple(
42 None, None, self.get_process_working_directory())
43 self.assertTrue(process, PROCESS_IS_VALID)
45 thread = lldbutil.get_one_thread_stopped_at_breakpoint(process, bkpt_before)
46 self.assertTrue(thread.IsValid(), "We didn't stop at the before breakpoint.")
48 ret_val = lldb.SBCommandReturnObject()
49 self.dbg.GetCommandInterpreter().HandleCommand("watchpoint set variable -w write global_var", ret_val)
50 self.assertTrue(ret_val.Succeeded(), "Watchpoint set variable did not return success.")
52 wp = self.target.FindWatchpointByID(1)
53 self.assertTrue(wp.IsValid(), "Didn't make a valid watchpoint.")
54 self.assertTrue(wp.GetWatchAddress() != lldb.LLDB_INVALID_ADDRESS, "Watch address is invalid")
57 self.assertTrue(not wp.IsEnabled(), "The watchpoint thinks it is still enabled")
61 stop_reason = thread.GetStopReason()
63 self.assertEqual(stop_reason, lldb.eStopReasonBreakpoint, "We didn't stop at our breakpoint.")
67 self.assertTrue(wp.IsEnabled(), "The watchpoint thinks it is still disabled.")
69 stop_reason = thread.GetStopReason()
70 self.assertEqual(stop_reason, lldb.eStopReasonWatchpoint, "We didn't stop at our watchpoint")