[Lldb-commits] [lldb] [lldb] correct event when removing all watchpoints (PR #125312)
puremourning wrote: > @puremourning Let me know if you need someone to press the Merge button for > you. Yes please. I don't have commit rights. https://github.com/llvm/llvm-project/pull/125312 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] WatchAddress ignores modify option (PR #124847)
puremourning wrote: Yep. Good to go. https://github.com/llvm/llvm-project/pull/124847 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] LLDB: correct event when removing all watchpoints (PR #125312)
puremourning wrote: Yes, on it. Sorry I should have marked this PR [wip]. https://github.com/llvm/llvm-project/pull/125312 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [WIP] LLDB: correct event when removing all watchpoints (PR #125312)
https://github.com/puremourning edited https://github.com/llvm/llvm-project/pull/125312 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [WIP] LLDB: correct event when removing all watchpoints (PR #125312)
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 Date: Fri, 31 Jan 2025 22:38:04 + 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( 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.") _
[Lldb-commits] [lldb] LLDB: correct event when removing all watchpoints (PR #125312)
https://github.com/puremourning edited https://github.com/llvm/llvm-project/pull/125312 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [WIP] LLDB: correct event when removing all watchpoints (PR #125312)
puremourning wrote: Done. The test fails (expectedly) at the line following "DeleteAllWatchpoints" prior to this patch, and passes after. https://github.com/llvm/llvm-project/pull/125312 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [WIP] LLDB: correct event when removing all watchpoints (PR #125312)
https://github.com/puremourning edited https://github.com/llvm/llvm-project/pull/125312 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] WatchAddress ignores modify option (PR #124847)
https://github.com/puremourning edited https://github.com/llvm/llvm-project/pull/124847 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] correct event when removing all watchpoints (PR #125312)
https://github.com/puremourning edited https://github.com/llvm/llvm-project/pull/125312 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
puremourning wrote: Hmm seems the behaviour on intel differs to arm. will need to think about it. https://github.com/llvm/llvm-project/pull/124847 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
puremourning wrote: > This looks good to me, thanks for fixing this. This method used to take two > bools, `read`, and `write`, I redefined the second to `modified` when I > changed the default watchpoints to be modify-style. The method previously had > a block doing > > ``` > -uint32_t watch_type = 0; > -if (read) > - watch_type |= LLDB_WATCH_TYPE_READ; > -if (write) > - watch_type |= LLDB_WATCH_TYPE_WRITE; > ``` > > and in rewriting this to set an SBWatchpointOptions object, I didn't update > it correctly to allow someone to request a read-only watchpoint. The test > cases look good, thanks for taking the time to write those. I'd address the > nit Jonas pointed out. Thanks, yeah I figured. Nit squashed. https://github.com/llvm/llvm-project/pull/124847 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
puremourning wrote: OK so the test is failing on CI, that's bad news. will check ``` FAIL: LLDB (/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-j6q2n-1/llvm-project/github-pull-requests/build/bin/clang-x86_64) :: test_read_watchpoint_watch_address (TestWatchpointRead.SetReadOnlyWatchpointTestCase) FAIL: LLDB (/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-j6q2n-1/llvm-project/github-pull-requests/build/bin/clang-x86_64) :: test_read_watchpoint_watch_create_by_address (TestWatchpointRead.SetReadOnlyWatchpointTestCase) == FAIL: test_read_watchpoint_watch_address (TestWatchpointRead.SetReadOnlyWatchpointTestCase) -- Traceback (most recent call last): File "/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-j6q2n-1/llvm-project/github-pull-requests/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py", line 69, in test_read_watchpoint_watch_address self.assertTrue( AssertionError: False is not true : The local variable has been incremented Config=x86_64-/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-j6q2n-1/llvm-project/github-pull-requests/build/bin/clang == FAIL: test_read_watchpoint_watch_create_by_address (TestWatchpointRead.SetReadOnlyWatchpointTestCase) -- Traceback (most recent call last): File "/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-j6q2n-1/llvm-project/github-pull-requests/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py", line 123, in test_read_watchpoint_watch_create_by_address self.assertTrue( AssertionError: False is not true : The local variable has been incremented Config=x86_64-/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-j6q2n-1/llvm-project/github-pull-requests/build/bin/clang -- Ran 2 tests in 0.908s ``` https://github.com/llvm/llvm-project/pull/124847 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
https://github.com/puremourning updated https://github.com/llvm/llvm-project/pull/124847 >From 169a8d84d4af08218227058db4968bed9fc701eb Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Tue, 28 Jan 2025 21:47:24 + Subject: [PATCH] LLDB: WatchAddress ignores modify option The WatchAddress API includes a flag to indicate if watchpoint should be for read, modify or both. This API uses 2 booleans, but the 'modify' flag was ignored and WatchAddress unconditionally watched write (actually modify). We now only watch for modify when the modify flag is true. --- lldb/source/API/SBTarget.cpp | 3 +- .../watchpoint/TestWatchpointRead.py | 125 ++ .../watchlocation/TestTargetWatchAddress.py | 71 +- 3 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 lldb/test/API/python_api/watchpoint/TestWatchpointRead.py diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 2a33161bc21edc..dd9caa724ea362 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -1342,7 +1342,8 @@ lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size, SBWatchpointOptions options; options.SetWatchpointTypeRead(read); - options.SetWatchpointTypeWrite(eWatchpointWriteTypeOnModify); + if (modify) +options.SetWatchpointTypeWrite(eWatchpointWriteTypeOnModify); return WatchpointCreateByAddress(addr, size, options, error); } diff --git a/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py b/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py new file mode 100644 index 00..c0d06e41faea47 --- /dev/null +++ b/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py @@ -0,0 +1,125 @@ +""" +Use lldb Python SBTarget API to set read watchpoints +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SetReadOnlyWatchpointTestCase(TestBase): +NO_DEBUG_INFO_TESTCASE = True + +def setUp(self): +# Call super's setUp(). +TestBase.setUp(self) +# Our simple source filename. +self.source = "main.c" +# Find the line number to break inside main(). +self.line = line_number(self.source, "// Set break point at this line.") +self.build() + +def test_read_watchpoint_watch_address(self): +exe = self.getBuildArtifact("a.out") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# Now create a breakpoint on main.c. +breakpoint = target.BreakpointCreateByLocation(self.source, self.line) +self.assertTrue( +breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT +) + +# Now launch the process, and do not stop at the entry point. +process = target.LaunchSimple(None, None, self.get_process_working_directory()) + +# We should be stopped due to the breakpoint. Get frame #0. +process = target.GetProcess() +self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) +thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) +frame0 = thread.GetFrameAtIndex(0) + +value = frame0.FindValue("global", lldb.eValueTypeVariableGlobal) +local = frame0.FindValue("local", lldb.eValueTypeVariableLocal) +error = lldb.SBError() + +watchpoint = target.WatchAddress(value.GetLoadAddress(), 1, True, False, error) +self.assertTrue( +value and local and watchpoint, +"Successfully found the values and set a watchpoint", +) +self.DebugSBValue(value) +self.DebugSBValue(local) + +# Hide stdout if not running with '-t' option. +if not self.TraceOn(): +self.HideStdout() + +print(watchpoint) + +# Continue. Expect the program to stop due to the variable being +# read, but *not* written to. +process.Continue() + +if self.TraceOn(): +lldbutil.print_stacktraces(process) + +self.assertTrue( +local.GetValueAsSigned() > 0, "The local variable has been incremented" +) + +def test_read_watchpoint_watch_create_by_address(self): +exe = self.getBuildArtifact("a.out") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# Now create a breakpoint on main.c. +breakpoint = target.BreakpointCreateByLocation(self.source, self.line) +self.assertTrue( +breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT +) + +# Now launch the process, and do not stop at the entry point. +process = target.LaunchSimple(None, None, self.get_process_working_directory()) + +# We should be stopped due to the breakpoint. Get frame #0. +process = target.GetProcess() +
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
puremourning wrote: I think the issue is that... we just don't support read-only watchpoints on intel because the [hardware doesn't support it](https://en.wikipedia.org/wiki/X86_debug_register#cite_note-brkpt_type-19). I guess I'll mark this test as "skip on x86" https://github.com/llvm/llvm-project/pull/124847 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
https://github.com/puremourning updated https://github.com/llvm/llvm-project/pull/124847 >From 6b3ba3f6dcf11d8b18ff72bc736b24ac75231626 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Tue, 28 Jan 2025 21:47:24 + Subject: [PATCH] LLDB: WatchAddress ignores modify option The WatchAddress API includes a flag to indicate if watchpoint should be for read, modify or both. This API uses 2 booleans, but the 'modify' flag was ignored and WatchAddress unconditionally watched write (actually modify). We now only watch for modify when the modify flag is true. --- lldb/source/API/SBTarget.cpp | 3 +- .../watchpoint/TestWatchpointRead.py | 129 ++ .../watchlocation/TestTargetWatchAddress.py | 71 +- 3 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 lldb/test/API/python_api/watchpoint/TestWatchpointRead.py diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 2a33161bc21edc7..dd9caa724ea3628 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -1342,7 +1342,8 @@ lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size, SBWatchpointOptions options; options.SetWatchpointTypeRead(read); - options.SetWatchpointTypeWrite(eWatchpointWriteTypeOnModify); + if (modify) +options.SetWatchpointTypeWrite(eWatchpointWriteTypeOnModify); return WatchpointCreateByAddress(addr, size, options, error); } diff --git a/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py b/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py new file mode 100644 index 000..f482ebe5b1ecee6 --- /dev/null +++ b/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py @@ -0,0 +1,129 @@ +""" +Use lldb Python SBTarget API to set read watchpoints +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SetReadOnlyWatchpointTestCase(TestBase): +NO_DEBUG_INFO_TESTCASE = True + +def setUp(self): +# Call super's setUp(). +TestBase.setUp(self) +# Our simple source filename. +self.source = "main.c" +# Find the line number to break inside main(). +self.line = line_number(self.source, "// Set break point at this line.") +self.build() + +# Intel hardware does not support read-only watchpoints +@expectedFailureAll(archs=["i386", "x86_64"]) +def test_read_watchpoint_watch_address(self): +exe = self.getBuildArtifact("a.out") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# Now create a breakpoint on main.c. +breakpoint = target.BreakpointCreateByLocation(self.source, self.line) +self.assertTrue( +breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT +) + +# Now launch the process, and do not stop at the entry point. +process = target.LaunchSimple(None, None, self.get_process_working_directory()) + +# We should be stopped due to the breakpoint. Get frame #0. +process = target.GetProcess() +self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) +thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) +frame0 = thread.GetFrameAtIndex(0) + +value = frame0.FindValue("global", lldb.eValueTypeVariableGlobal) +local = frame0.FindValue("local", lldb.eValueTypeVariableLocal) +error = lldb.SBError() + +watchpoint = target.WatchAddress(value.GetLoadAddress(), 1, True, False, error) +self.assertTrue( +value and local and watchpoint, +"Successfully found the values and set a watchpoint", +) +self.DebugSBValue(value) +self.DebugSBValue(local) + +# Hide stdout if not running with '-t' option. +if not self.TraceOn(): +self.HideStdout() + +print(watchpoint) + +# Continue. Expect the program to stop due to the variable being +# read, but *not* written to. +process.Continue() + +if self.TraceOn(): +lldbutil.print_stacktraces(process) + +self.assertTrue( +local.GetValueAsSigned() > 0, "The local variable has been incremented" +) + +# Intel hardware does not support read-only watchpoints +@expectedFailureAll(archs=["i386", "x86_64"]) +def test_read_watchpoint_watch_create_by_address(self): +exe = self.getBuildArtifact("a.out") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# Now create a breakpoint on main.c. +breakpoint = target.BreakpointCreateByLocation(self.source, self.line) +self.assertTrue( +breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT +) + +# Now launch the process, and do not stop at
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
puremourning wrote: Looking again, of course you're right and the behaviour of RemoveAll and Remove is inconsistent today, so I don't see a problem with fixing it. https://github.com/llvm/llvm-project/pull/124847 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] LLDB: correct event when removing all watchpoints (PR #125312)
https://github.com/puremourning edited https://github.com/llvm/llvm-project/pull/125312 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] LLDB: correct event when removing all watchpoints (PR #125312)
https://github.com/puremourning created https://github.com/llvm/llvm-project/pull/125312 Previously we incorrectly emitted a "breakpoint changed" event when removing all watchpoints (e.g. via SBTarget::DeleteAllWatchpoints()). Correct it to emit the "watchpoint changed" event, as that's what "Remove" does and what it checks for being registered. --- No test for now. It looks possible to add one though. >From c6c6e9bb4069193f1e3387492278ccad89df2ebd Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Fri, 31 Jan 2025 22:38:04 + Subject: [PATCH] LLDB: correct event when removing all watchpoints Previously we incorrectly emitted a "breakpoint changed" event when removing all watchpoints (e.g. via SBTarget::DeleteAllWatchpoints()). Correct it to emit the "watchpoint changed" event, as that's what "Remove" does and what it checks for being registered. --- lldb/source/Breakpoint/WatchpointList.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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( eWatchpointEventTypeRemoved, *pos); (*pos)->GetTarget().BroadcastEvent( ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
puremourning wrote: https://github.com/llvm/llvm-project/pull/125312 https://github.com/llvm/llvm-project/pull/124847 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] LLDB: correct event when removing all watchpoints (PR #125312)
https://github.com/puremourning updated https://github.com/llvm/llvm-project/pull/125312 >From 0bf7cf47b3373f3bd23802fcd41f6b831fff6adf Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Fri, 31 Jan 2025 22:38:04 + 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Breakpoint/WatchpointList.cpp b/lldb/source/Breakpoint/WatchpointList.cpp index f7564483e6f1fc..57369b76c03aff 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( eWatchpointEventTypeRemoved, *pos); (*pos)->GetTarget().BroadcastEvent( ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
puremourning wrote: > Seeing as you are working on watchpoints here, I found that `void > WatchpointList::RemoveAll(bool notify)` is sending the wrong event of > `Target::eBroadcastBitBreakpointChanged` instead of sending > `Target::eBroadcastBitWatchpointChanged`. Might be a good fix to get in to > ensure watchpoints are solid. Seems simple enough to change it. Though I worry about bug-compatibility, in case someone has code expecting the "wrong" event. Let me change it quickly and see what breaks in the tests If you're confident it is the "right" thing to do I can push another PR. https://github.com/llvm/llvm-project/pull/124847 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
https://github.com/puremourning created https://github.com/llvm/llvm-project/pull/124847 The WatchAddress API includes a flag to indicate if watchpoint should be for read, modify or both. This API uses 2 booleans, but the 'modify' flag was ignored and WatchAddress unconditionally watched write (actually modify). We now only watch for modify when the modify flag is true. --- The included test fails prior to this patch and succeeds after. That is previously specifying `False` for `modify` would still stop on _write_, but after the patch correctly only stops on _read_ >From a3ee813d5deb4179a916906c4b1b1dd10c4b586e Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Tue, 28 Jan 2025 21:47:24 + Subject: [PATCH] LLDB: WatchAddress ignores modify option The WatchAddress API includes a flag to indicate if watchpoint should be for read, modify or both. This API uses 2 booleans, but the 'modify' flag was ignored and WatchAddress unconditionally watched write (actually modify). We now only watch for modify when the modify flag is true. --- lldb/source/API/SBTarget.cpp | 4 +- .../watchpoint/TestWatchpointRead.py | 130 ++ .../watchlocation/TestTargetWatchAddress.py | 71 +- 3 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 lldb/test/API/python_api/watchpoint/TestWatchpointRead.py diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 2a33161bc21edc..9192f0be1c85b9 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -1342,7 +1342,9 @@ lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size, SBWatchpointOptions options; options.SetWatchpointTypeRead(read); - options.SetWatchpointTypeWrite(eWatchpointWriteTypeOnModify); + if (modify) { +options.SetWatchpointTypeWrite(eWatchpointWriteTypeOnModify); + } return WatchpointCreateByAddress(addr, size, options, error); } diff --git a/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py b/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py new file mode 100644 index 00..67b04464748108 --- /dev/null +++ b/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py @@ -0,0 +1,130 @@ +""" +Use lldb Python SBTarget API to set read watchpoints +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SetWatchpointAPITestCase(TestBase): +NO_DEBUG_INFO_TESTCASE = True + +def setUp(self): +# Call super's setUp(). +TestBase.setUp(self) +# Our simple source filename. +self.source = "main.c" +# Find the line number to break inside main(). +self.line = line_number(self.source, "// Set break point at this line.") +self.build() + + +def test_read_watchpoint_watch_address(self): +exe = self.getBuildArtifact("a.out") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# Now create a breakpoint on main.c. +breakpoint = target.BreakpointCreateByLocation(self.source, self.line) +self.assertTrue( +breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT +) + +# Now launch the process, and do not stop at the entry point. +process = target.LaunchSimple(None, None, self.get_process_working_directory()) + +# We should be stopped due to the breakpoint. Get frame #0. +process = target.GetProcess() +self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) +thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) +frame0 = thread.GetFrameAtIndex(0) + + +value = frame0.FindValue("global", lldb.eValueTypeVariableGlobal) +local = frame0.FindValue("local", lldb.eValueTypeVariableLocal) +error = lldb.SBError() + +watchpoint = target.WatchAddress( +value.GetLoadAddress(), 1, True, False, error +) +self.assertTrue( +value and local and watchpoint, "Successfully found the values and set a watchpoint" +) +self.DebugSBValue(value) +self.DebugSBValue(local) + +# Hide stdout if not running with '-t' option. +if not self.TraceOn(): +self.HideStdout() + +print(watchpoint) + +# Continue. Expect the program to stop due to the variable being +# read, but *not* written to. +process.Continue() + +if self.TraceOn(): +lldbutil.print_stacktraces(process) + +self.assertTrue( +local.GetValueAsSigned() > 0, +"The local variable has been incremented" +) + +def test_read_watchpoint_watch_create_by_address(self): +exe = self.getBuildArtifact("a.out") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
https://github.com/puremourning updated https://github.com/llvm/llvm-project/pull/124847 >From afae250c45e769006a5ae7d078e2e0ae39a4d8c0 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Tue, 28 Jan 2025 21:47:24 + Subject: [PATCH] LLDB: WatchAddress ignores modify option The WatchAddress API includes a flag to indicate if watchpoint should be for read, modify or both. This API uses 2 booleans, but the 'modify' flag was ignored and WatchAddress unconditionally watched write (actually modify). We now only watch for modify when the modify flag is true. --- lldb/source/API/SBTarget.cpp | 4 +- .../watchpoint/TestWatchpointRead.py | 130 ++ .../watchlocation/TestTargetWatchAddress.py | 71 +- 3 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 lldb/test/API/python_api/watchpoint/TestWatchpointRead.py diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 2a33161bc21edc..9192f0be1c85b9 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -1342,7 +1342,9 @@ lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size, SBWatchpointOptions options; options.SetWatchpointTypeRead(read); - options.SetWatchpointTypeWrite(eWatchpointWriteTypeOnModify); + if (modify) { +options.SetWatchpointTypeWrite(eWatchpointWriteTypeOnModify); + } return WatchpointCreateByAddress(addr, size, options, error); } diff --git a/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py b/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py new file mode 100644 index 00..21ba4760071276 --- /dev/null +++ b/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py @@ -0,0 +1,130 @@ +""" +Use lldb Python SBTarget API to set read watchpoints +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SetReadOnlyWatchpointTestCase(TestBase): +NO_DEBUG_INFO_TESTCASE = True + +def setUp(self): +# Call super's setUp(). +TestBase.setUp(self) +# Our simple source filename. +self.source = "main.c" +# Find the line number to break inside main(). +self.line = line_number(self.source, "// Set break point at this line.") +self.build() + + +def test_read_watchpoint_watch_address(self): +exe = self.getBuildArtifact("a.out") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# Now create a breakpoint on main.c. +breakpoint = target.BreakpointCreateByLocation(self.source, self.line) +self.assertTrue( +breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT +) + +# Now launch the process, and do not stop at the entry point. +process = target.LaunchSimple(None, None, self.get_process_working_directory()) + +# We should be stopped due to the breakpoint. Get frame #0. +process = target.GetProcess() +self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) +thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) +frame0 = thread.GetFrameAtIndex(0) + + +value = frame0.FindValue("global", lldb.eValueTypeVariableGlobal) +local = frame0.FindValue("local", lldb.eValueTypeVariableLocal) +error = lldb.SBError() + +watchpoint = target.WatchAddress( +value.GetLoadAddress(), 1, True, False, error +) +self.assertTrue( +value and local and watchpoint, "Successfully found the values and set a watchpoint" +) +self.DebugSBValue(value) +self.DebugSBValue(local) + +# Hide stdout if not running with '-t' option. +if not self.TraceOn(): +self.HideStdout() + +print(watchpoint) + +# Continue. Expect the program to stop due to the variable being +# read, but *not* written to. +process.Continue() + +if self.TraceOn(): +lldbutil.print_stacktraces(process) + +self.assertTrue( +local.GetValueAsSigned() > 0, +"The local variable has been incremented" +) + +def test_read_watchpoint_watch_create_by_address(self): +exe = self.getBuildArtifact("a.out") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# Now create a breakpoint on main.c. +breakpoint = target.BreakpointCreateByLocation(self.source, self.line) +self.assertTrue( +breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT +) + +# Now launch the process, and do not stop at the entry point. +process = target.LaunchSimple(None, None, self.get_process_working_directory()) + +# We should be stopped due to the breakpoint. Get frame #0. +proces
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
https://github.com/puremourning updated https://github.com/llvm/llvm-project/pull/124847 >From 3baafc236fb722a27799bd3abccb74e01656afab Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Tue, 28 Jan 2025 21:47:24 + Subject: [PATCH] LLDB: WatchAddress ignores modify option The WatchAddress API includes a flag to indicate if watchpoint should be for read, modify or both. This API uses 2 booleans, but the 'modify' flag was ignored and WatchAddress unconditionally watched write (actually modify). We now only watch for modify when the modify flag is true. --- lldb/source/API/SBTarget.cpp | 4 +- .../watchpoint/TestWatchpointRead.py | 130 ++ .../watchlocation/TestTargetWatchAddress.py | 71 +- 3 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 lldb/test/API/python_api/watchpoint/TestWatchpointRead.py diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 2a33161bc21edc..9192f0be1c85b9 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -1342,7 +1342,9 @@ lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size, SBWatchpointOptions options; options.SetWatchpointTypeRead(read); - options.SetWatchpointTypeWrite(eWatchpointWriteTypeOnModify); + if (modify) { +options.SetWatchpointTypeWrite(eWatchpointWriteTypeOnModify); + } return WatchpointCreateByAddress(addr, size, options, error); } diff --git a/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py b/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py new file mode 100644 index 00..21ba4760071276 --- /dev/null +++ b/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py @@ -0,0 +1,130 @@ +""" +Use lldb Python SBTarget API to set read watchpoints +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SetReadOnlyWatchpointTestCase(TestBase): +NO_DEBUG_INFO_TESTCASE = True + +def setUp(self): +# Call super's setUp(). +TestBase.setUp(self) +# Our simple source filename. +self.source = "main.c" +# Find the line number to break inside main(). +self.line = line_number(self.source, "// Set break point at this line.") +self.build() + + +def test_read_watchpoint_watch_address(self): +exe = self.getBuildArtifact("a.out") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# Now create a breakpoint on main.c. +breakpoint = target.BreakpointCreateByLocation(self.source, self.line) +self.assertTrue( +breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT +) + +# Now launch the process, and do not stop at the entry point. +process = target.LaunchSimple(None, None, self.get_process_working_directory()) + +# We should be stopped due to the breakpoint. Get frame #0. +process = target.GetProcess() +self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) +thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) +frame0 = thread.GetFrameAtIndex(0) + + +value = frame0.FindValue("global", lldb.eValueTypeVariableGlobal) +local = frame0.FindValue("local", lldb.eValueTypeVariableLocal) +error = lldb.SBError() + +watchpoint = target.WatchAddress( +value.GetLoadAddress(), 1, True, False, error +) +self.assertTrue( +value and local and watchpoint, "Successfully found the values and set a watchpoint" +) +self.DebugSBValue(value) +self.DebugSBValue(local) + +# Hide stdout if not running with '-t' option. +if not self.TraceOn(): +self.HideStdout() + +print(watchpoint) + +# Continue. Expect the program to stop due to the variable being +# read, but *not* written to. +process.Continue() + +if self.TraceOn(): +lldbutil.print_stacktraces(process) + +self.assertTrue( +local.GetValueAsSigned() > 0, +"The local variable has been incremented" +) + +def test_read_watchpoint_watch_create_by_address(self): +exe = self.getBuildArtifact("a.out") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# Now create a breakpoint on main.c. +breakpoint = target.BreakpointCreateByLocation(self.source, self.line) +self.assertTrue( +breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT +) + +# Now launch the process, and do not stop at the entry point. +process = target.LaunchSimple(None, None, self.get_process_working_directory()) + +# We should be stopped due to the breakpoint. Get frame #0. +proces
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
https://github.com/puremourning updated https://github.com/llvm/llvm-project/pull/124847 >From 1edd2a7cae5acbe11ae58f486f5bca7c182184f5 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Tue, 28 Jan 2025 21:47:24 + Subject: [PATCH] LLDB: WatchAddress ignores modify option The WatchAddress API includes a flag to indicate if watchpoint should be for read, modify or both. This API uses 2 booleans, but the 'modify' flag was ignored and WatchAddress unconditionally watched write (actually modify). We now only watch for modify when the modify flag is true. --- lldb/source/API/SBTarget.cpp | 4 +- .../watchpoint/TestWatchpointRead.py | 125 ++ .../watchlocation/TestTargetWatchAddress.py | 71 +- 3 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 lldb/test/API/python_api/watchpoint/TestWatchpointRead.py diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 2a33161bc21edc..9192f0be1c85b9 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -1342,7 +1342,9 @@ lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size, SBWatchpointOptions options; options.SetWatchpointTypeRead(read); - options.SetWatchpointTypeWrite(eWatchpointWriteTypeOnModify); + if (modify) { +options.SetWatchpointTypeWrite(eWatchpointWriteTypeOnModify); + } return WatchpointCreateByAddress(addr, size, options, error); } diff --git a/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py b/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py new file mode 100644 index 00..c0d06e41faea47 --- /dev/null +++ b/lldb/test/API/python_api/watchpoint/TestWatchpointRead.py @@ -0,0 +1,125 @@ +""" +Use lldb Python SBTarget API to set read watchpoints +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class SetReadOnlyWatchpointTestCase(TestBase): +NO_DEBUG_INFO_TESTCASE = True + +def setUp(self): +# Call super's setUp(). +TestBase.setUp(self) +# Our simple source filename. +self.source = "main.c" +# Find the line number to break inside main(). +self.line = line_number(self.source, "// Set break point at this line.") +self.build() + +def test_read_watchpoint_watch_address(self): +exe = self.getBuildArtifact("a.out") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# Now create a breakpoint on main.c. +breakpoint = target.BreakpointCreateByLocation(self.source, self.line) +self.assertTrue( +breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT +) + +# Now launch the process, and do not stop at the entry point. +process = target.LaunchSimple(None, None, self.get_process_working_directory()) + +# We should be stopped due to the breakpoint. Get frame #0. +process = target.GetProcess() +self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) +thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) +frame0 = thread.GetFrameAtIndex(0) + +value = frame0.FindValue("global", lldb.eValueTypeVariableGlobal) +local = frame0.FindValue("local", lldb.eValueTypeVariableLocal) +error = lldb.SBError() + +watchpoint = target.WatchAddress(value.GetLoadAddress(), 1, True, False, error) +self.assertTrue( +value and local and watchpoint, +"Successfully found the values and set a watchpoint", +) +self.DebugSBValue(value) +self.DebugSBValue(local) + +# Hide stdout if not running with '-t' option. +if not self.TraceOn(): +self.HideStdout() + +print(watchpoint) + +# Continue. Expect the program to stop due to the variable being +# read, but *not* written to. +process.Continue() + +if self.TraceOn(): +lldbutil.print_stacktraces(process) + +self.assertTrue( +local.GetValueAsSigned() > 0, "The local variable has been incremented" +) + +def test_read_watchpoint_watch_create_by_address(self): +exe = self.getBuildArtifact("a.out") + +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# Now create a breakpoint on main.c. +breakpoint = target.BreakpointCreateByLocation(self.source, self.line) +self.assertTrue( +breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT +) + +# Now launch the process, and do not stop at the entry point. +process = target.LaunchSimple(None, None, self.get_process_working_directory()) + +# We should be stopped due to the breakpoint. Get frame #0. +process = target.GetProcess() +
[Lldb-commits] [lldb] LLDB: WatchAddress ignores modify option (PR #124847)
@@ -1342,7 +1342,9 @@ lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size, SBWatchpointOptions options; options.SetWatchpointTypeRead(read); puremourning wrote: It doesn't need to: It passes read bool directly to the Set... method so it's set based on the value of 'read' https://github.com/llvm/llvm-project/pull/124847 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits