Skip to content

Commit c26bb4f

Browse files
authored
[lldb] correct event when removing all watchpoints (llvm#125312)
LLDB: correct event when removing all watchpoints Previously we incorrectly checked for a "breakpoint changed" event listener removing all watchpoints (e.g. via SBTarget::DeleteAllWatchpoints()), although we would emit a "watchpoint changed" event if there were a listener for 'breakpoint changed'. This meant that we might not emit a "watchpoint changed" event if there was a listener for this event. Correct it to check for the "watchpoint changed" event. --- Updated regression tests which were also incorrectly peeking for the wrong event type. The 'remove' action actually triggers 2 events which the test didn't allow, so I updated it to allow specifically what was requested. The test fails (expectedly) at the line following "DeleteAllWatchpoints" prior to this patch, and passes after.
1 parent f8fa931 commit c26bb4f

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

lldb/source/Breakpoint/WatchpointList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void WatchpointList::RemoveAll(bool notify) {
236236
wp_collection::iterator pos, end = m_watchpoints.end();
237237
for (pos = m_watchpoints.begin(); pos != end; ++pos) {
238238
if ((*pos)->GetTarget().EventTypeHasListeners(
239-
Target::eBroadcastBitBreakpointChanged)) {
239+
Target::eBroadcastBitWatchpointChanged)) {
240240
auto data_sp = std::make_shared<Watchpoint::WatchpointEventData>(
241241
eWatchpointEventTypeRemoved, *pos);
242242
(*pos)->GetTarget().BroadcastEvent(

lldb/test/API/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,45 @@ def test_with_python_api(self):
8282
'make sure watchpoint condition is "' + condition + '"',
8383
)
8484

85-
def GetWatchpointEvent(self, event_type):
86-
# We added a watchpoint so we should get a watchpoint added event.
87-
event = lldb.SBEvent()
88-
success = self.listener.WaitForEvent(1, event)
89-
self.assertTrue(success, "Successfully got watchpoint event")
90-
self.assertTrue(
91-
lldb.SBWatchpoint.EventIsWatchpointEvent(event),
92-
"Event is a watchpoint event.",
85+
target.DeleteWatchpoint(local_watch.GetID())
86+
self.GetWatchpointEvent(
87+
lldb.eWatchpointEventTypeDisabled, lldb.eWatchpointEventTypeRemoved
9388
)
94-
found_type = lldb.SBWatchpoint.GetWatchpointEventTypeFromEvent(event)
95-
self.assertEqual(
96-
found_type,
97-
event_type,
98-
"Event is not correct type, expected: %d, found: %d"
99-
% (event_type, found_type),
89+
90+
# Re-create it so that we can check DeleteAllWatchpoints
91+
local_watch = local_var.Watch(True, False, True, error)
92+
if not error.Success():
93+
self.fail(
94+
"Failed to make watchpoint for local_var: %s" % (error.GetCString())
95+
)
96+
self.GetWatchpointEvent(lldb.eWatchpointEventTypeAdded)
97+
target.DeleteAllWatchpoints()
98+
self.GetWatchpointEvent(
99+
lldb.eWatchpointEventTypeDisabled, lldb.eWatchpointEventTypeRemoved
100100
)
101+
102+
def GetWatchpointEvent(self, *event_types):
103+
# We added a watchpoint so we should get a watchpoint added event.
104+
event = lldb.SBEvent()
105+
for event_type in event_types:
106+
success = self.listener.WaitForEvent(1, event)
107+
self.assertTrue(success, "Successfully got watchpoint event")
108+
self.assertTrue(
109+
lldb.SBWatchpoint.EventIsWatchpointEvent(event),
110+
"Event is a watchpoint event.",
111+
)
112+
found_type = lldb.SBWatchpoint.GetWatchpointEventTypeFromEvent(event)
113+
self.assertEqual(
114+
found_type,
115+
event_type,
116+
"Event is not correct type, expected: %d, found: %d"
117+
% (event_type, found_type),
118+
)
101119
# There shouldn't be another event waiting around:
102120
found_event = self.listener.PeekAtNextEventForBroadcasterWithType(
103-
self.target_bcast, lldb.SBTarget.eBroadcastBitBreakpointChanged, event
121+
self.target_bcast, lldb.SBTarget.eBroadcastBitWatchpointChanged, event
104122
)
105123
if found_event:
106-
print("Found an event I didn't expect: ", event)
124+
print("Found an event I didn't expect: ", event.GetType())
107125

108-
self.assertTrue(not found_event, "Only one event per change.")
126+
self.assertTrue(not found_event, f"Only expected {len(event_types)} events.")

0 commit comments

Comments
 (0)