[Lldb-commits] [lldb] [lldb][debugserver] Fix bugs in FindBreakpointsThatOverlapRange (PR #217837)
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Fri Aug 21 02:06:28 PDT 2026
================
@@ -125,34 +125,38 @@ DNBBreakpointList::FindNearestWatchpoint(nub_addr_t addr) const {
size_t DNBBreakpointList::FindBreakpointsThatOverlapRange(
nub_addr_t addr, nub_addr_t size, std::vector<DNBBreakpoint *> &bps) {
bps.clear();
+
+ if (m_breakpoints.empty())
+ return bps.size();
+
iterator end = m_breakpoints.end();
// Find the first breakpoint with an address >= to "addr"
iterator pos = m_breakpoints.lower_bound(addr);
- if (pos != end) {
- if (pos != m_breakpoints.begin()) {
- // Watch out for a breakpoint at an address less than "addr" that might
- // still overlap
- iterator prev_pos = pos;
- --prev_pos;
- if (prev_pos->second.IntersectsRange(addr, size, NULL, NULL, NULL))
- bps.push_back(&pos->second);
- }
- while (pos != end) {
- // When we hit a breakpoint whose start address is greater than "addr +
- // size" we are done.
- // Do the math in a way that doesn't risk unsigned overflow with bad
- // input.
- if ((pos->second.Address() - addr) >= size)
- break;
+ if (pos != m_breakpoints.begin()) {
+ // Watch out for a breakpoint at an address less than "addr" that might
+ // still overlap
+ iterator prev_pos = pos;
+ --prev_pos;
+ if (prev_pos->second.IntersectsRange(addr, size, NULL, NULL, NULL))
+ bps.push_back(&prev_pos->second);
+ }
----------------
DavidSpickett wrote:
If lower_bound returns a breakpoint that starts exactly where the write starts, you are right. Breakpoints do not overlap, so the previous breakpoint does not overlap the write.
It's the > case where you need to check previous.If lower bound finds a breakpoint starting beyond the write start, the previous breakpoint may extend beyond address.
In other words, if the found breakpoint starts maybe 4 bytes beyond the write address, then a breakpoint 2 bytes before the write address would overlap the write (assuming 4 byte break instructions).
https://github.com/llvm/llvm-project/pull/217837
More information about the lldb-commits
mailing list