Author: David Spickett
Date: 2026-08-24T09:25:58+01:00
New Revision: 938e6446b0392a2bdebdab17fd1bf74afea4ea64

URL: 
https://github.com/llvm/llvm-project/commit/938e6446b0392a2bdebdab17fd1bf74afea4ea64
DIFF: 
https://github.com/llvm/llvm-project/commit/938e6446b0392a2bdebdab17fd1bf74afea4ea64.diff

LOG: [lldb][debugserver] Handle breakpoint prior to addr in 
RemoveTrapsFromBuffer (#217851)

Fixes #217840

lower_bound finds the first breakpoint that starts >= addr. There might
be a breakpoint before that which starts before addr but extends past
addr. Therefore it might need to be patched out of the buffer.

This fix is intentionally minimal as I don't have a Mac to test it in.

A proper fix would reuse FindBreakpointsThatOverlapRange, which also has
this bug but is getting fixed. The problem with that is that
RemoveTrapsFromBuffer is const, and FindBreakpointsThatOverlapRange
returns non const pointers to the breakpoints.

Not super complex to fix but more than I want to do at a distance.

Added: 
    

Modified: 
    lldb/tools/debugserver/source/DNBBreakpoint.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/tools/debugserver/source/DNBBreakpoint.cpp 
b/lldb/tools/debugserver/source/DNBBreakpoint.cpp
index 74f0fb17129f3..531a049bfd803 100644
--- a/lldb/tools/debugserver/source/DNBBreakpoint.cpp
+++ b/lldb/tools/debugserver/source/DNBBreakpoint.cpp
@@ -171,9 +171,18 @@ void DNBBreakpointList::DisableAll() {
 
 void DNBBreakpointList::RemoveTrapsFromBuffer(nub_addr_t addr, nub_size_t size,
                                               void *p) const {
+  if (m_breakpoints.empty())
+    return;
+
   uint8_t *buf = (uint8_t *)p;
   const_iterator end = m_breakpoints.end();
   const_iterator pos = m_breakpoints.lower_bound(addr);
+
+  // lower_bound finds a breakpoint starting >= addr. The breakpoint prior to
+  // that may start before addr but extend beyond it, so it must be checked 
too.
+  if (pos != m_breakpoints.begin())
+    --pos;
+
   while (pos != end && (pos->first < (addr + size))) {
     nub_addr_t intersect_addr;
     nub_size_t intersect_size;


        
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to