summaryrefslogtreecommitdiff
path: root/lldb/source/Host/common/NativeProcessProtocol.cpp
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2025-07-18 13:26:00 -0700
committerPeter Collingbourne <peter@pcc.me.uk>2025-07-18 13:26:00 -0700
commit9bf3524731070cadc6175707314f3b6ca37190d5 (patch)
tree86dcab7604336b01ae938fe81062c29ff69efba8 /lldb/source/Host/common/NativeProcessProtocol.cpp
parent3a84c15cc13b6daf8e812592898ab6c7f19091a9 (diff)
parent4f43f0606c3d7e1ce6d069583b5e59f036e112ce (diff)
Created using spr 1.3.6-beta.1
Diffstat (limited to 'lldb/source/Host/common/NativeProcessProtocol.cpp')
-rw-r--r--lldb/source/Host/common/NativeProcessProtocol.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/lldb/source/Host/common/NativeProcessProtocol.cpp b/lldb/source/Host/common/NativeProcessProtocol.cpp
index 405acbb5662d..196f54b93538 100644
--- a/lldb/source/Host/common/NativeProcessProtocol.cpp
+++ b/lldb/source/Host/common/NativeProcessProtocol.cpp
@@ -366,12 +366,19 @@ Status NativeProcessProtocol::RemoveSoftwareBreakpoint(lldb::addr_t addr) {
if (--it->second.ref_count > 0)
return Status();
+ // Remove the entry from m_software_breakpoints rightaway, so that we don't
+ // leave behind an entry with ref_count == 0 in case one of the following
+ // conditions returns an error. The breakpoint is moved so that it can be
+ // accessed below.
+ SoftwareBreakpoint bkpt = std::move(it->second);
+ m_software_breakpoints.erase(it);
+
// This is the last reference. Let's remove the breakpoint.
Status error;
// Clear a software breakpoint instruction
- llvm::SmallVector<uint8_t, 4> curr_break_op(
- it->second.breakpoint_opcodes.size(), 0);
+ llvm::SmallVector<uint8_t, 4> curr_break_op(bkpt.breakpoint_opcodes.size(),
+ 0);
// Read the breakpoint opcode
size_t bytes_read = 0;
@@ -382,10 +389,10 @@ Status NativeProcessProtocol::RemoveSoftwareBreakpoint(lldb::addr_t addr) {
"addr=0x%" PRIx64 ": tried to read %zu bytes but only read %zu", addr,
curr_break_op.size(), bytes_read);
}
- const auto &saved = it->second.saved_opcodes;
+ const auto &saved = bkpt.saved_opcodes;
// Make sure the breakpoint opcode exists at this address
- if (llvm::ArrayRef(curr_break_op) != it->second.breakpoint_opcodes) {
- if (curr_break_op != it->second.saved_opcodes)
+ if (llvm::ArrayRef(curr_break_op) != bkpt.breakpoint_opcodes) {
+ if (curr_break_op != bkpt.saved_opcodes)
return Status::FromErrorString(
"Original breakpoint trap is no longer in memory.");
LLDB_LOG(log,
@@ -418,7 +425,6 @@ Status NativeProcessProtocol::RemoveSoftwareBreakpoint(lldb::addr_t addr) {
llvm::make_range(saved.begin(), saved.end()));
}
- m_software_breakpoints.erase(it);
return Status();
}