================
@@ -651,18 +652,31 @@ Status 
NativeProcessProtocol::RemoveBreakpoint(lldb::addr_t addr,
 
 Status NativeProcessProtocol::WriteMemory(lldb::addr_t addr, const void *buf,
                                           size_t size, size_t &bytes_written) {
-  const uint8_t *byte_buf = static_cast<const uint8_t *>(buf);
-  bytes_written = 0;
   Status error;
+  bytes_written = 0;
 
   if (!size)
     return error;
 
-  for (auto &[sbp_addr, sbp_data] : m_software_breakpoints) {
+  if (m_software_breakpoints.empty())
+    return DoWriteMemory(addr, buf, size, bytes_written);
+
+  // Find first breakpoint that starts > addr.
+  std::map<lldb::addr_t, SoftwareBreakpoint>::iterator bkpt =
+      m_software_breakpoints.upper_bound(addr);
+
+  // it points to the first breakpoint starting at > addr, but the one
+  // immediately before it may extend over addr, or begin exactly at addr.
+  if (bkpt != m_software_breakpoints.begin())
+    bkpt = std::prev(bkpt);
----------------
DavidSpickett wrote:

Yes, the difference is that sometimes with lower bound you get the break start 
== write addr result. In that case you know that previous is not going to 
overlap. With upper bound you always get break start > write addr, so the 
previous is always worth checking.

So I do think upper_bound is a tiny bit easier to think about, but debugserver 
uses lower bound and I think that'll make comparing the code later a lot easier.

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

Reply via email to