[Lldb-commits] [lldb] [WIP] LLDB: correct event when removing all watchpoints (PR #125312)
Ben Jackson via lldb-commits
lldb-commits at lists.llvm.org
Sat Feb 1 10:27:39 PST 2025
https://github.com/puremourning updated https://github.com/llvm/llvm-project/pull/125312
>From 6af277d30baaa1c8ff56bb4da13a6687dfa0c729 Mon Sep 17 00:00:00 2001
From: Ben Jackson <puremourning at gmail.com>
Date: Fri, 31 Jan 2025 22:38:04 +0000
Subject: [PATCH] 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.
---
lldb/source/Breakpoint/WatchpointList.cpp | 2 +-
.../watchpoint_events/TestWatchpointEvents.py | 52 +++++++++++++------
2 files changed, 36 insertions(+), 18 deletions(-)
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