lldb-server does not account for writes over software breakpoint sites that it manages
Discovered while reasearching https://github.com/llvm/llvm-project/issues/197564.
Some background information first:
- Inside LLDB we classify breakpoints as hardware, software, or external.
- External means the debug server will deal with it. It could in reality be software, hardware, simulator specific trap setting, whatever, we don't need to care.
- We assume that if the debug server replaces an instruction to place the breakpoint, it will put that original instruction back into memory reads so it appears unchanged (which is not always the case, as discovered in https://github.com/llvm/llvm-project/issues/197564).
- We assume, or have never thought to check, that the same happens for memory writes. That the saved instruction would be updated if a memory write overwrote it.
- Nothing in the GDB remote protocol docs says whose responsibility it is to handle either situation.
This issue is about the writing part.
This session demonstrates the problem.
$ ./bin/lldb /tmp/test.o
(lldb) target create "/tmp/test.o"
Current executable set to '/tmp/test.o' (aarch64).
(lldb) log enable gdb-remote packets
I'm disabling the cache to prevent any chance of lldb trying to fix this itself.
(lldb) settings set target.process.disable-memory-cache true
This breakpoint will become a software break on main once we run.
(lldb) b main
Breakpoint 1: where = test.o`main at test.c:1:21, address = 0x0000000000000714
(lldb) breakpoint list
Current breakpoints:
1: name = 'main', locations = 1
1.1: where = test.o`main at test.c:1:21, address = test.o[0x0000000000000714], unresolved, hit count = 0
Note the second part of the MultiBreakpoint packet, that's the main breakpoint.
(lldb) run
<...>
lldb < 87> send packet: $jMultiBreakpoint:{"breakpoint_requests":["Z0,fffff7fc4c20,4","Z0,aaaaaaaa0714,4"]}]#fe
lldb < 28> read packet: ${"results":["OK","OK"]}]#85
<...>
Process 27261 stopped
* thread #1, name = 'test.o', stop reason = breakpoint 1.1
frame #0: 0x0000aaaaaaaa0714 test.o`main at test.c:1:21
-> 1 int main() { return 0; }
(lldb) breakpoint list
Current breakpoints:
1: name = 'main', locations = 1, resolved = 1, hit count = 1
1.1: where = test.o`main at test.c:1:21, address = 0x0000aaaaaaaa0714, resolved, hit count = 1
When we read the instructions back we will not see the breakpoint instruction, lldb-server correctly substitutes in the original instruction.
(I use the raw address here because expression evaluation creates a bunch of irrelevant packets)
(lldb) register read pc
pc = 0x0000aaaaaaaa0714 test.o`main at test.c:1:21
(lldb) memory read 0x0000aaaaaaaa0714
lldb < 20> send packet: $xaaaaaaaa0714,20#da
lldb < 36> read packet: $00008052c0035fd61f2003d5fd7bbfa9fd030091fd7bc1a8c0035fd601000200#2e
0xaaaaaaaa0714: 00 00 80 52 c0 03 5f d6 1f 20 03 d5 fd 7b bf a9 ...R.._.. ...{..
0xaaaaaaaa0724: fd 03 00 91 fd 7b c1 a8 c0 03 5f d6 01 00 02 00 .....{...._.....
Now we overwrite the breakpoint site. We know that this is not cached in lldb because we can see the M packet being sent out.
(lldb) memory write 0xaaaaaaaa0714 0xca 0xfe 0xf0 0x0d
lldb < 34> send packet: $qMemoryRegionInfo:aaaaaaaa0714#e8
lldb < 83> read packet: $start:aaaaaaaa0000;size:1000;permissions:rx;flags:;name:2f746d702f746573742e6f;#89
lldb < 28> send packet: $Maaaaaaaa0714,4:cafef00d#74
lldb < 6> read packet: $OK#9a
If lldb-server had caught this and updated the saved instruction for the breakpoint site, we should see the new value now, but we do not.
(lldb) memory read 0x0000aaaaaaaa0714
lldb < 20> send packet: $xaaaaaaaa0714,20#da
lldb < 36> read packet: $00008052c0035fd61f2003d5fd7bbfa9fd030091fd7bc1a8c0035fd601000200#2e
0xaaaaaaaa0714: 00 00 80 52 c0 03 5f d6 1f 20 03 d5 fd 7b bf a9 ...R.._.. ...{..
0xaaaaaaaa0724: fd 03 00 91 fd 7b c1 a8 c0 03 5f d6 01 00 02 00 .....{...._.....
When we single step we normally disable the breakpoint, single step, then re-enable it. In this case the disable fails:
(lldb) ni
lldb < 67> send packet: $jMultiBreakpoint:{"breakpoint_requests":["z0,aaaaaaaa0714,4"]}]#a1
lldb < 24> read packet: ${"results":["E09"]}]#8f
<...>
Process 27261 stopped
* thread #1, name = 'test.o', stop reason = signal SIGILL: illegal opcode
frame #0: 0x0000aaaaaaaa0714 test.o`main at test.c:1:21
-> 1 int main() { return 0; }
Though we now see the new value in memory somehow:
(lldb) memory read 0x0000aaaaaaaa0714
lldb < 20> send packet: $xaaaaaaaa0714,20#da
lldb < 36> read packet: $cafef00dc0035fd61f2003d5fd7bbfa9fd030091fd7bc1a8c0035fd601000200#21
0xaaaaaaaa0714: ca fe f0 0d c0 03 5f d6 1f 20 03 d5 fd 7b bf a9 ......_.. ...{..
0xaaaaaaaa0724: fd 03 00 91 fd 7b c1 a8 c0 03 5f d6 01 00 02 00 .....{...._.....
Which was pretty confusing at first, but what's happening is this:
- lldb-server saves the original opcode A and substitutes it into any reads of the site.
- A software breakpoint instruction B is written into memory.
- lldb writes over that location, lldb-server writes the new value C over B, and continues to show A in any memory reads.
- When asked to remove the breakpoint, lldb-server checks that the location contains B, it does not, so it fails to remove it because it doesn't want to make the situation worse.
We can see this in lldb-server logging:
$ ~/build-llvm-aarch64/bin/lldb-server gdbserver 127.0.0.1:1234 --log-channels "lldb break" -- /tmp/test.o
Launched '/tmp/test.o' as process 27096...
lldb-server-local_build
Connection established.
1781013220.950878143 NativeProcessProtocol.cpp:SetSoftwareBreakpoint addr = 0xaaaaaaaa0714, size_hint = 4
1781013220.950940847 NativeProcessProtocol.cpp:EnableSoftwareBreakpoint Overwriting bytes at 0xaaaaaaaa0714: 0x0, 0x0, 0x80, 0x52
1781013220.950979948 NativeProcessProtocol.cpp:EnableSoftwareBreakpoint addr = 0xaaaaaaaa0714: SUCCESS
<...>
1781013264.103750229 NativeProcessProtocol.cpp:RemoveSoftwareBreakpoint addr = 0xaaaaaaaa0714
1781013264.103790522 GDBRemoteCommunicationServerLLGS.cpp:ExecuteRemoveBreakpoint pid 27096 failed to remove breakpoint: Original breakpoint trap is no longer in memory.
lldb will do substitutions client side for writes in Process::WriteMemory, but only for eSoftware breakpoints. eExternal we expect the server to do it. The server calls GDBRemoteCommunicationServerLLGS::ExecuteRemoveBreakpoint, which ends up in NativeProcessProtocol::RemoveSoftwareBreakpoint which does:
// Make sure the breakpoint opcode exists at this address
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,
"Saved opcodes ({0:@[x]}) have already been restored at {1:x}.",
llvm::make_range(saved.begin(), saved.end()), addr);
Overwriting instructions is an uncommon thing to do but it's not unheard of. Usually you're NOP-ing out something or jumping over some code manually. I could see someone setting a breakpoint on code they want to NOP out.
Also it would be nice to say we account for both reads and writes when dealing with external software breakpoints, not just reads.
@llvm/issue-subscribers-lldb
Author: David Spickett (DavidSpickett)
Some background information first:
- Inside LLDB we classify breakpoints as hardware, software, or external.
- External means the debug server will deal with it. It could in reality be software, hardware, simulator specific trap setting, whatever, we don't need to care.
- We assume that if the debug server replaces an instruction to place the breakpoint, it will put that original instruction back into memory reads so it appears unchanged (which is not always the case, as discovered in https://github.com/llvm/llvm-project/issues/197564).
- We assume, or have never thought to check, that the same happens for memory writes. That the saved instruction would be updated if a memory write overwrote it.
- Nothing in the GDB remote protocol docs says whose responsibility it is to handle either situation.
This issue is about the writing part.
This session demonstrates the problem.
$ ./bin/lldb /tmp/test.o
(lldb) target create "/tmp/test.o"
Current executable set to '/tmp/test.o' (aarch64).
(lldb) log enable gdb-remote packets
I'm disabling the cache to prevent any chance of lldb trying to fix this itself.
(lldb) settings set target.process.disable-memory-cache true
This breakpoint will become a software break on main once we run.
(lldb) b main
Breakpoint 1: where = test.o`main at test.c:1:21, address = 0x0000000000000714
(lldb) breakpoint list
Current breakpoints:
1: name = 'main', locations = 1
1.1: where = test.o`main at test.c:1:21, address = test.o[0x0000000000000714], unresolved, hit count = 0
Note the second part of the MultiBreakpoint packet, that's the main breakpoint.
(lldb) run
<...>
lldb < 87> send packet: $jMultiBreakpoint:{"breakpoint_requests":["Z0,fffff7fc4c20,4","Z0,aaaaaaaa0714,4"]}]#fe
lldb < 28> read packet: ${"results":["OK","OK"]}]#<!-- -->85
<...>
Process 27261 stopped
* thread #<!-- -->1, name = 'test.o', stop reason = breakpoint 1.1
frame #<!-- -->0: 0x0000aaaaaaaa0714 test.o`main at test.c:1:21
-> 1 int main() { return 0; }
(lldb) breakpoint list
Current breakpoints:
1: name = 'main', locations = 1, resolved = 1, hit count = 1
1.1: where = test.o`main at test.c:1:21, address = 0x0000aaaaaaaa0714, resolved, hit count = 1
When we read the instructions back we will not see the breakpoint instruction, lldb-server correctly substitutes in the original instruction.
(I use the raw address here because expression evaluation creates a bunch of irrelevant packets)
(lldb) register read pc
pc = 0x0000aaaaaaaa0714 test.o`main at test.c:1:21
(lldb) memory read 0x0000aaaaaaaa0714
lldb < 20> send packet: $xaaaaaaaa0714,20#da
lldb < 36> read packet: $00008052c0035fd61f2003d5fd7bbfa9fd030091fd7bc1a8c0035fd601000200#<!-- -->2e
0xaaaaaaaa0714: 00 00 80 52 c0 03 5f d6 1f 20 03 d5 fd 7b bf a9 ...R.._.. ...{..
0xaaaaaaaa0724: fd 03 00 91 fd 7b c1 a8 c0 03 5f d6 01 00 02 00 .....{...._.....
Now we overwrite the breakpoint site. We know that this is not cached in lldb because we can see the M packet being sent out.
(lldb) memory write 0xaaaaaaaa0714 0xca 0xfe 0xf0 0x0d
lldb < 34> send packet: $qMemoryRegionInfo:aaaaaaaa0714#e8
lldb < 83> read packet: $start:aaaaaaaa0000;size:1000;permissions:rx;flags:;name:2f746d702f746573742e6f;#<!-- -->89
lldb < 28> send packet: $Maaaaaaaa0714,4:cafef00d#<!-- -->74
lldb < 6> read packet: $OK#<!-- -->9a
If lldb-server had caught this and updated the saved instruction for the breakpoint site, we should see the new value now, but we do not.
(lldb) memory read 0x0000aaaaaaaa0714
lldb < 20> send packet: $xaaaaaaaa0714,20#da
lldb < 36> read packet: $00008052c0035fd61f2003d5fd7bbfa9fd030091fd7bc1a8c0035fd601000200#<!-- -->2e
0xaaaaaaaa0714: 00 00 80 52 c0 03 5f d6 1f 20 03 d5 fd 7b bf a9 ...R.._.. ...{..
0xaaaaaaaa0724: fd 03 00 91 fd 7b c1 a8 c0 03 5f d6 01 00 02 00 .....{...._.....
When we single step we normally disable the breakpoint, single step, then re-enable it. In this case the disable fails:
(lldb) ni
lldb < 67> send packet: $jMultiBreakpoint:{"breakpoint_requests":["z0,aaaaaaaa0714,4"]}]#a1
lldb < 24> read packet: ${"results":["E09"]}]#<!-- -->8f
<...>
Process 27261 stopped
* thread #<!-- -->1, name = 'test.o', stop reason = signal SIGILL: illegal opcode
frame #<!-- -->0: 0x0000aaaaaaaa0714 test.o`main at test.c:1:21
-> 1 int main() { return 0; }
Though we now see the new value in memory somehow:
(lldb) memory read 0x0000aaaaaaaa0714
lldb < 20> send packet: $xaaaaaaaa0714,20#da
lldb < 36> read packet: $cafef00dc0035fd61f2003d5fd7bbfa9fd030091fd7bc1a8c0035fd601000200#<!-- -->21
0xaaaaaaaa0714: ca fe f0 0d c0 03 5f d6 1f 20 03 d5 fd 7b bf a9 ......_.. ...{..
0xaaaaaaaa0724: fd 03 00 91 fd 7b c1 a8 c0 03 5f d6 01 00 02 00 .....{...._.....
Which was pretty confusing at first, but what's happening is this:
- lldb-server saves the original opcode A and substitutes it into any reads of the site.
- A software breakpoint instruction B is written into memory.
- lldb writes over that location, lldb-server writes the new value C over B, and continues to show A in any memory reads.
- When asked to remove the breakpoint, lldb-server checks that the location contains B, it does not, so it fails to remove it because it doesn't want to make the situation worse.
We can see this in lldb-server logging:
$ ~/build-llvm-aarch64/bin/lldb-server gdbserver 127.0.0.1:1234 --log-channels "lldb break" -- /tmp/test.o
Launched '/tmp/test.o' as process 27096...
lldb-server-local_build
Connection established.
1781013220.950878143 NativeProcessProtocol.cpp:SetSoftwareBreakpoint addr = 0xaaaaaaaa0714, size_hint = 4
1781013220.950940847 NativeProcessProtocol.cpp:EnableSoftwareBreakpoint Overwriting bytes at 0xaaaaaaaa0714: 0x0, 0x0, 0x80, 0x52
1781013220.950979948 NativeProcessProtocol.cpp:EnableSoftwareBreakpoint addr = 0xaaaaaaaa0714: SUCCESS
<...>
1781013264.103750229 NativeProcessProtocol.cpp:RemoveSoftwareBreakpoint addr = 0xaaaaaaaa0714
1781013264.103790522 GDBRemoteCommunicationServerLLGS.cpp:ExecuteRemoveBreakpoint pid 27096 failed to remove breakpoint: Original breakpoint trap is no longer in memory.
lldb will do substitutions client side for writes in Process::WriteMemory, but only for eSoftware breakpoints. eExternal we expect the server to do it. The server calls GDBRemoteCommunicationServerLLGS::ExecuteRemoveBreakpoint, which ends up in NativeProcessProtocol::RemoveSoftwareBreakpoint which does:
// Make sure the breakpoint opcode exists at this address
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,
"Saved opcodes ({0:@[x]}) have already been restored at {1:x}.",
llvm::make_range(saved.begin(), saved.end()), addr);
Overwriting instructions is an uncommon thing to do but it's not unheard of. Usually you're NOP-ing out something or jumping over some code manually. I could see someone setting a breakpoint on code they want to NOP out.
Also it would be nice to say we account for both reads and writes when dealing with external software breakpoints, not just reads.
debugserver handles reads and writes:
RNBRemote::HandlePacket_M calls DNBProcessMemoryWrite calls MachProcess::WriteMemory:
//----------------------------------------------------------------------
// WriteMemory from the MachProcess level will always write memory around
// any software breakpoints. Any software breakpoints will have their
// opcodes modified if they are enabled. Any memory that doesn't overlap
// with software breakpoints will be written to. If you wish to write to
// inferior memory without this interference, then write to the MachTask
// (m_task.WriteMemory()) as that version will always modify inferior
// memory.
//----------------------------------------------------------------------
nub_size_t MachProcess::WriteMemory(nub_addr_t addr, nub_size_t size,
<...>
// Now write any bytes that would cover up any software breakpoints
// directly into the breakpoint opcode buffer
::memcpy(bp->SavedOpcodeBytes() + opcode_offset, ubuf + bytes_written,
intersect_size);
bytes_written += intersect_size;
Reads are also handled:
//----------------------------------------------------------------------
// ReadMemory from the MachProcess level will always remove any software
// breakpoints from the memory buffer before returning. If you wish to
// read memory and see those traps, read from the MachTask
// (m_task.ReadMemory()) as that version will give you what is actually
// in inferior memory.
//----------------------------------------------------------------------
nub_size_t MachProcess::ReadMemory(nub_addr_t addr, nub_size_t size,
<...>
// Then place any opcodes that fall into this range back into the buffer
// before we return this to callers.
if (bytes_read > 0)
m_breakpoints.RemoveTrapsFromBuffer(addr, bytes_read, buf);
We know for sure that GDB patches reads client side always. From what I can tell, it does the same for writes.
Checked gdbserver and QEMU's debug stub.
lldb -> gdbserver:
(lldb) b main
Breakpoint 1: where = test.o`main at test.c:1:21, address = 0x0000aaaaaaaa0714
(lldb) c
lldb < 21> send packet: $Z0,aaaaaaaa0714,4#ea
lldb < 6> read packet: $OK#9a
<...>
(lldb) settings set target.process.disable-memory-cache true
(lldb) memory read main
lldb < 14> send packet: $_M1000,rwx#fa
lldb < 4> read packet: $#00
lldb < 20> send packet: $maaaaaaaa0714,20#cf
lldb < 67> read packet: $0* 8052c0035fd61f2003d5fd7bbfa9fd030091fd7bc1a8c0035fd601000200#63
0xaaaaaaaa0714: 00 00 80 52 c0 03 5f d6 1f 20 03 d5 fd 7b bf a9 ...R.._.. ...{..
0xaaaaaaaa0724: fd 03 00 91 fd 7b c1 a8 c0 03 5f d6 01 00 02 00 .....{...._.....
(lldb) memory write 0xaaaaaaaa0714 0xca 0xfe 0xf0 0x0d
lldb < 28> send packet: $Maaaaaaaa0714,4:cafef00d#74
lldb < 6> read packet: $OK#9a
(lldb) memory read main
lldb < 20> send packet: $maaaaaaaa0714,20#cf
lldb < 68> read packet: $cafef00dc0035fd61f2003d5fd7bbfa9fd030091fd7bc1a8c0035fd601000200#d3
0xaaaaaaaa0714: ca fe f0 0d c0 03 5f d6 1f 20 03 d5 fd 7b bf a9 ......_.. ...{..
0xaaaaaaaa0724: fd 03 00 91 fd 7b c1 a8 c0 03 5f d6 01 00 02 00 .....{...._.....
gdbserver is giving us the original instruction on reads, and for writes is updating the saved instruction.
lldb -> QEMU:
(lldb) b main
Breakpoint 1: where = test.o`main at test.c:1:21, address = 0x0000005500000714
(lldb) c
lldb < 19> send packet: $Z0,5500000714,4#0c
lldb < 1> read packet: +
lldb < 6> read packet: $OK#9a
<...>
Process 1 stopped
* thread #1, stop reason = breakpoint 1.1
frame #0: 0x0000005500000714 test.o`main at test.c:1:21
-> 1 int main() { return 0; }
(lldb) memory read main
<...>
lldb < 18> send packet: $m5500000714,20#f1
lldb < 1> read packet: +
<...>
0x5500000714: 00 00 80 52 c0 03 5f d6 1f 20 03 d5 fd 7b bf a9 ...R.._.. ...{..
0x5500000724: fd 03 00 91 fd 7b c1 a8 c0 03 5f d6 01 00 02 00 .....{...._.....
(lldb) memory write 0x5500000714 0xca 0xfe 0xf0 0x0d
lldb < 26> send packet: $M5500000714,4:cafef00d#96
lldb < 1> read packet: +
lldb < 7> read packet: $E14#aa
lldb < 1> send packet: +
error: Memory write to 0x5500000714 failed: memory write failed for 0x5500000714
QEMU returns the original instruction on reads, and I can't write to see what the result of that is. I think this is a QEMU limitation, since it's emulating this code, it likely doesn't want us to modify it behind its back.
Also I suspect that software breakpoints in QEMU are not done by changing code, but instead by the simulation generating the exception itself at a given PC value.
FWIW the write doesn't work with gdb either, so it's not about how lldb sends it:
(gdb) set {char}0x5500000714 = 0x12
[remote] Sending packet: $M5500000714,1:12#3d
[remote] Received Ack
[remote] Packet received: E14
Cannot access memory at address 0x5500000714
And it fails for any code memory, not just for the breakpoint site. Writing to data memory, for example the stack, works fine.
OpenOCD I don't have a way to test it but we know from https://github.com/llvm/llvm-project/issues/197564 that it does not return the original instruction for reads.
It's breakpoint structure includes the original instruction of course, because it must be able to put it back. However all references to it are in the functions that set or remove the breakpoint. No references to it from memory read or write functions.
So for all the servers we know about, when it comes to external breakpoints which the server places on the client's behalf:
| Debug Server | Reports original instruction for reads | Updates original instruction on writes | Notes |
|---|---|---|---|
| debugserver | Yes | Yes | |
| lldb-server | Yes | No | |
| gdbserver | Yes | Yes | |
| OpenOCD | No | No | Writes checked by code inspection only. |
| pyOCD | Yes (see filter_memory) |
No (filter_memory not used by write methods) |
Checked by code inspection only. |
| Black Magic Debug | N/A (all <target>_breakwatch_set( reject TARGET_BREAK_SOFT) |
N/A | Checked by code inspection only. |
| stlink | N/A | N/A | Checked by code inspection only. Z handler in serve rejects software breakpoints (type 0). |
| QEMU debug stub | N/A | N/A (does not allow writes) | Likely using internal breakpoints rather than modifying code memory. |
| valgrind | N/A | N/A | Checked by code inspection only. Software and hardware break both implemented without modifying memory (see gs_addresses). |
| Renode | N/A | N/A | Checked by code inspection only. Software and hardware break are both simulation hooks. See InsertBreakpoint in https://github.com/renode/renode-infrastructure. |
Then the clients:
| Debug Client | Reports original instuction for reads | Updates orginal instructon on writes | Trusts the debug server? |
|---|---|---|---|
| gdb | Yes | Yes | No |
| lldb | No | No | Yes |
The API claims to preserve memory https://lldb.llvm.org/python_api/lldb.SBProcess.html#lldb.SBProcess.WriteMemory.
Writes memory to the current process’s address space and maintains any traps that might be present due to software breakpoints.
I can reproduce this behavior in a Linux/aarch64 Docker environment using Alpine's packaged LLDB:
lldb version 20.1.8
lldb-server version 20.1.8
Minimal repro I used:
cat > /tmp/test.c <<'SRC'
int main() { return 0; }
SRC
cc -g /tmp/test.c -o /tmp/test.o
cat > /tmp/lldb.cmds <<'LLDB'
target create /tmp/test.o
settings set target.process.disable-memory-cache true
log enable gdb-remote packets
breakpoint set -n main
run
memory read --format x --size 1 --count 4 main
memory write main 0xca 0xfe 0xf0 0x0d
memory read --format x --size 1 --count 4 main
nexti
LLDB
lldb -b -s /tmp/lldb.cmds
Observed sequence:
memory read main
0xaaaaaaaa07a0: 0x00 0x00 0x80 0x52
memory write main 0xca 0xfe 0xf0 0x0d
packet: $Maaaaaaaa07a0,4:cafef00d
response: OK
memory read main
packet: $xaaaaaaaa07a0,4
response: 00008052
output: 0x00 0x00 0x80 0x52
nexti
packet: $z0,aaaaaaaa07a0,4
response: E09
stop reason: signal SIGILL: illegal opcode
This matches the stale saved-opcode state described here: the memory write succeeds, but subsequent reads still appear to be patched from the old saved_opcodes, and breakpoint removal/step then fails.
I'll start looking into a fix unless someone is already working on this.
I'll start looking into a fix unless someone is already working on this.
Feel free.
At some point we may end up making lldb match gdb and not trust the server at all, but I would rather lldb-server was honest and consistent before we change anything in lldb.
Overwriting instructions is an uncommon thing to do but it's not unheard of. Usually you're NOP-ing out something or jumping over some code manually. I could see someone setting a breakpoint on code they want to NOP out.
Less uncommon than I thought: https://github.com/llvm/llvm-project/issues/216000
So this does need a fix for 23.
I will work on a fix for this.
settings set target.process.dont-delay-breakpoints true - something like "this" should be enough for me, but maybe you have a better fix in mind :)
settings set target.process.dont-delay-breakpoints true - something like "this" should be enough for me, but maybe you have a better fix in mind :)
Idk why I didn't check for one earlier, but there is a setting:
The following settings variables may relate to 'use-delayed-breakpoints':
target.process.use-delayed-breakpoints -- Specify whether updating breakpoints may be delayed until the process is about to resume.
If you set that to false you should have the 22.x behaviour.
I have a fix for this in the works - https://github.com/llvm/llvm-project/pull/217348.
In case the fix ends up too risky to cherry pick we have a couple of other options:
- Document in the 23 release notes that this new breakpoint handling exists, and can be reverted using the setting if needed. Or -
- Turn the setting off by default on the release branch. Or -
- Say this was a problem waiting to happen anyway, more ways to hit the same bug isn't a "regression".
Because you can argue that the regression here is not that lldb-server doesn't handle the write properly. It has never handled it properly.
The regression is that with the new lazy breakpoint behaviour, there is 1 more way to hit the same pre-existing bug. So if you relied on that use case working, it now doesn't, but you can turn the setting off to fix it. It's a question of how you'd figure out how to do that.
@felipepiovezan what do you think of those ideas? For the second one, would turning it off on 23 also turn it off in your downstreams, or are they not based on the release branch?
@felipepiovezan what do you think of those ideas? For the second one, would turning it off on 23 also turn it off in your downstreams, or are they not based on the release branch?
If the fix is too complex (will look into the draft PR in a moment), I don't mind if we decide to change the default behaviour for the 23 release. We have an automerger from llvm's 23 release into a branch in the swift fork, but I can switch the default there back to on and take any fixes deemed too risky for the llvm release.
The fix seems reasonably simple and self contained to me. For targets not using software breakpoints, it is very clearly a no-op