[Lldb-commits] [lldb] c26bb4f - [lldb] correct event when removing all watchpoints (#125312)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Feb 3 14:39:46 PST 2025
Author: Ben Jackson
Date: 2025-02-03T14:39:43-08:00
New Revision: c26bb4f095120ff4741b6530b6b3c0ac5a7dacad
URL: https://github.com/llvm/llvm-project/commit/c26bb4f095120ff4741b6530b6b3c0ac5a7dacad
DIFF: https://github.com/llvm/llvm-project/commit/c26bb4f095120ff4741b6530b6b3c0ac5a7dacad.diff
LOG: [lldb] correct event when removing all watchpoints (#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.
Added:
Modified:
lldb/source/Breakpoint/WatchpointList.cpp
lldb/test/API/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py
Removed:
################################################################################
diff --git a/lldb/source/Breakpoint/WatchpointList.cpp b/lldb/source/Breakpoint/WatchpointList.cpp
index f7564483e6f1fcd..57369b76c03aff0 100644
--- a/lldb/source/Breakpoint/WatchpointList.cpp
+++ b/lldb/source/Breakpoint/WatchpointList.cpp
@@ -236,7 +236,7 @@ void WatchpointList::RemoveAll(bool notify) {
wp_collection::iterator pos, end = m_watchpoints.end();
for (pos = m_watchpoints.begin(); pos != end; ++pos) {
if ((*pos)->GetTarget().EventTypeHasListeners(
- Target::eBroadcastBitBreakpointChanged)) {
+ Target::eBroadcastBitWatchpointChanged)) {
auto data_sp = std::make_shared<Watchpoint::WatchpointEventData>(
eWatchpointEventTypeRemoved, *pos);
(*pos)->GetTarget().BroadcastEvent(
diff --git a/lldb/test/API/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py b/lldb/test/API/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py
index 726a9d93c29d460..6e05cf06204a7d5 100644
--- a/lldb/test/API/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py
+++ b/lldb/test/API/commands/watchpoints/watchpoint_events/TestWatchpointEvents.py
@@ -82,27 +82,45 @@ def test_with_python_api(self):
'make sure watchpoint condition is "' + condition + '"',
)
- def GetWatchpointEvent(self, event_type):
- # We added a watchpoint so we should get a watchpoint added event.
- event = lldb.SBEvent()
- success = self.listener.WaitForEvent(1, event)
- self.assertTrue(success, "Successfully got watchpoint event")
- self.assertTrue(
- lldb.SBWatchpoint.EventIsWatchpointEvent(event),
- "Event is a watchpoint event.",
+ target.DeleteWatchpoint(local_watch.GetID())
+ self.GetWatchpointEvent(
+ lldb.eWatchpointEventTypeDisabled, lldb.eWatchpointEventTypeRemoved
)
- found_type = lldb.SBWatchpoint.GetWatchpointEventTypeFromEvent(event)
- self.assertEqual(
- found_type,
- event_type,
- "Event is not correct type, expected: %d, found: %d"
- % (event_type, found_type),
+
+ # Re-create it so that we can check DeleteAllWatchpoints
+ local_watch = local_var.Watch(True, False, True, error)
+ if not error.Success():
+ self.fail(
+ "Failed to make watchpoint for local_var: %s" % (error.GetCString())
+ )
+ self.GetWatchpointEvent(lldb.eWatchpointEventTypeAdded)
+ target.DeleteAllWatchpoints()
+ self.GetWatchpointEvent(
+ lldb.eWatchpointEventTypeDisabled, lldb.eWatchpointEventTypeRemoved
)
+
+ def GetWatchpointEvent(self, *event_types):
+ # We added a watchpoint so we should get a watchpoint added event.
+ event = lldb.SBEvent()
+ for event_type in event_types:
+ success = self.listener.WaitForEvent(1, event)
+ self.assertTrue(success, "Successfully got watchpoint event")
+ self.assertTrue(
+ lldb.SBWatchpoint.EventIsWatchpointEvent(event),
+ "Event is a watchpoint event.",
+ )
+ found_type = lldb.SBWatchpoint.GetWatchpointEventTypeFromEvent(event)
+ self.assertEqual(
+ found_type,
+ event_type,
+ "Event is not correct type, expected: %d, found: %d"
+ % (event_type, found_type),
+ )
# There shouldn't be another event waiting around:
found_event = self.listener.PeekAtNextEventForBroadcasterWithType(
- self.target_bcast, lldb.SBTarget.eBroadcastBitBreakpointChanged, event
+ self.target_bcast, lldb.SBTarget.eBroadcastBitWatchpointChanged, event
)
if found_event:
- print("Found an event I didn't expect: ", event)
+ print("Found an event I didn't expect: ", event.GetType())
- self.assertTrue(not found_event, "Only one event per change.")
+ self.assertTrue(not found_event, f"Only expected {len(event_types)} events.")
More information about the lldb-commits
mailing list