1 """Test that adding, deleting and modifying watchpoints sends the appropriate events."""
3 from __future__ import print_function
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
9 from lldbsuite.test import lldbutil
12 class TestWatchpointEvents (TestBase):
14 mydir = TestBase.compute_mydir(__file__)
15 NO_DEBUG_INFO_TESTCASE = True
18 # Call super's setUp().
20 # Find the line numbers that we will step to in main:
21 self.main_source = "main.c"
23 @add_test_categories(['pyapi'])
24 def test_with_python_api(self):
25 """Test that adding, deleting and modifying watchpoints sends the appropriate events."""
28 exe = self.getBuildArtifact("a.out")
30 target = self.dbg.CreateTarget(exe)
31 self.assertTrue(target, VALID_TARGET)
33 self.main_source_spec = lldb.SBFileSpec(self.main_source)
35 break_in_main = target.BreakpointCreateBySourceRegex(
36 '// Put a breakpoint here.', self.main_source_spec)
37 self.assertTrue(break_in_main, VALID_BREAKPOINT)
39 # Now launch the process, and do not stop at entry point.
40 process = target.LaunchSimple(
41 None, None, self.get_process_working_directory())
43 self.assertTrue(process, PROCESS_IS_VALID)
45 # The stop reason of the thread should be breakpoint.
46 threads = lldbutil.get_threads_stopped_at_breakpoint(
47 process, break_in_main)
50 self.fail("Failed to stop at first breakpoint in main.")
53 frame = thread.GetFrameAtIndex(0)
54 local_var = frame.FindVariable("local_var")
55 self.assertTrue(local_var.IsValid())
57 self.listener = lldb.SBListener("com.lldb.testsuite_listener")
58 self.target_bcast = target.GetBroadcaster()
59 self.target_bcast.AddListener(
60 self.listener, lldb.SBTarget.eBroadcastBitWatchpointChanged)
61 self.listener.StartListeningForEvents(
62 self.target_bcast, lldb.SBTarget.eBroadcastBitWatchpointChanged)
64 error = lldb.SBError()
65 local_watch = local_var.Watch(True, False, True, error)
66 if not error.Success():
68 "Failed to make watchpoint for local_var: %s" %
71 self.GetWatchpointEvent(lldb.eWatchpointEventTypeAdded)
72 # Now change some of the features of this watchpoint and make sure we
74 local_watch.SetEnabled(False)
75 self.GetWatchpointEvent(lldb.eWatchpointEventTypeDisabled)
77 local_watch.SetEnabled(True)
78 self.GetWatchpointEvent(lldb.eWatchpointEventTypeEnabled)
80 local_watch.SetIgnoreCount(10)
81 self.GetWatchpointEvent(lldb.eWatchpointEventTypeIgnoreChanged)
84 local_watch.SetCondition(condition)
85 self.GetWatchpointEvent(lldb.eWatchpointEventTypeConditionChanged)
87 self.assertTrue(local_watch.GetCondition() == condition,
88 'make sure watchpoint condition is "' + condition + '"')
90 def GetWatchpointEvent(self, event_type):
91 # We added a watchpoint so we should get a watchpoint added event.
92 event = lldb.SBEvent()
93 success = self.listener.WaitForEvent(1, event)
94 self.assertTrue(success, "Successfully got watchpoint event")
96 lldb.SBWatchpoint.EventIsWatchpointEvent(event),
97 "Event is a watchpoint event.")
98 found_type = lldb.SBWatchpoint.GetWatchpointEventTypeFromEvent(event)
100 found_type == event_type,
101 "Event is not correct type, expected: %d, found: %d" %
104 # There shouldn't be another event waiting around:
105 found_event = self.listener.PeekAtNextEventForBroadcasterWithType(
106 self.target_bcast, lldb.SBTarget.eBroadcastBitBreakpointChanged, event)
108 print("Found an event I didn't expect: ", event)
110 self.assertTrue(not found_event, "Only one event per change.")