| Issue |
244255
|
| Summary |
[lldb][Windows] GetStopReply() fails with "state was not stopped: invalid" when lldb-server sends an async $O (OutputDebugString) packet on connect
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
spookyGh0st
|
The issue was found by a human, this report was found and generated by Gemini, and only rudimentary checked by hand.
### Summary
When connecting to `lldb-server.exe` on Windows (`gdb-remote` / `lldb-dap`), if the debuggee or Windows loader emits an `OutputDebugString` message during startup, `lldb-server.exe` sends an async `$O<hex>` packet. When LLDB subsequently queries the stop reason via `$?#3f` in `GDBRemoteCommunicationClient::GetStopReply()`, it reads that `$O` packet as the response to `?`, causing `ProcessGDBRemote::DoConnectRemote()` to fail with:
```text
error: Process <pid> was reported after connecting to 'connect://<host>:<port>', but state was not stopped: invalid
```
### Environment
- **Client OS:** Windows (x86_64)
- **Server OS:** Windows (x86_64) (`x86_64-pc-windows-msvc`, Windows NT 6.2.0 reported in `qHostInfo`)
- **Debugger / Server:** `lldb-dap` + `lldb-server.exe g` (LLVM 23.1.6`)
### Steps to Reproduce
1. On a remote Windows host, start `lldb-server.exe` in gdbserver mode launching an executable that triggers a Windows `OutputDebugString` during initial process/DLL load (for me, it was the binary being located on a network drive, resultin in `kernelbase.dll` logging `BasepIsRemovableMedia: Host device is removable, Shim cache deactivated`):
```powershell
lldb-server.exe g 0.0.0.0:5925 -- C:\path\to\app.exe
```
2. From the client, attach via `lldb-dap` (using `attachCommands: ["gdb-remote <host>:5925"]`) or `lldb`:
```text
(lldb) target create path/to/app.exe
(lldb) gdb-remote <host>:5925
```
### Actual Behavior
Connecting fails immediately after `$?#3f` because `lldb-server.exe` sends an `$O` packet containing the `OutputDebugString` message instead of (or ahead of) the stop reply packet:
<details>
<summary>gdb-remote packet log</summary>
```text
< 1> send packet: +
history[1] tid=0x1fe4 < 1> send packet: +
< 19> send packet: $QStartNoAckMode#b0
< 1> read packet: +
< 6> read packet: $OK#9a
< 1> send packet: +
< 104> send packet: $qSupported:xmlRegisters=i386,arm,mips,arc;multiprocess+;fork-events+;vfork-events+;swbreak+;hwbreak+#cd
< 181> read packet: $PacketSize=131072;QStartNoAckMode+;qEcho+;native-signals+;QThreadSuffixSupported+;QListThreadsInStopReply+;qXfer:features:read+;QNonStop+;jMultiBreakpoint+;qXfer:libraries:read+#2c
< 26> send packet: $QThreadSuffixSupported#e4
< 6> read packet: $OK#9a
< 27> send packet: $QListThreadsInStopReply#21
< 6> read packet: $OK#9a
< 13> send packet: $qHostInfo#9b
< 259> read packet: $triple:7838365f36342d70632d77696e646f77732d6d737663;ptrsize:8;watchpoint_exceptions_received:after;endian:little;os_version:6.2.0;os_build:57696e646f7773204e5420362e322e30;os_kernel:57696e646f7773204e5420362e322e30;hostname:<redacted-hex>;#xx
< 10> send packet: $vCont?#49
< 19> read packet: $vCont;c;C;s;S;t#11
< 27> send packet: $qVAttachOrWaitSupported#38
< 6> read packet: $OK#9a
< 23> send packet: $QEnableErrorStrings#8c
< 6> read packet: $OK#9a
< 16> send packet: $qProcessInfo#dc
< 192> read packet: $pid:2c9c;parent-pid:2d6c;real-uid:ffffffff;real-gid:ffffffff;effective-uid:ffffffff;effective-gid:ffffffff;triple:7838365f36342d70632d77696e646f7773;ostype:windows;endian:little;ptrsize:8;#b2
< 5> send packet: $?#3f
< 149> read packet: $O4261736570497352656d6f7661626c654d656469613a20486f7374206465766963652069732072656d6f7661626c652c205368696d2063616368652064656163746976617465640a#2b
error: Process 11420 was reported after connecting to 'connect://<remote-host>:5925', but state was not stopped: invalid
```
</details>
Decoding the `$O` payload:
```text
BasepIsRemovableMedia: Host device is removable, Shim cache deactivated
```
### Expected Behavior
LLDB should consume/forward any async `$O` output packets and continue waiting for the actual stop-reply (`T`/`S`/`W`/`X`) packet when querying `?` on connect, rather than failing with `state was not stopped: invalid`.
### Root Cause Analysis
1. In LLVM 23, `lldb-server.exe` on Windows began forwarding `OutputDebugString[A|W]` events as async `$O` packets.
2. `GDBRemoteCommunicationClient::GetStopReply()` (`lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp`) currently uses:
```cpp
bool GDBRemoteCommunicationClient::GetStopReply(
StringExtractorGDBRemote &response) {
if (SendPacketAndWaitForResponse("?", response) == PacketResult::Success)
return response.IsNormalResponse();
return false;
}
```
3. Unlike `SendPacketAndReceiveResponseWithOutputSupport(...)` (which was also needed for the LLGS test client in PR #225521 to tolerate async `$O` packets on Windows), `SendPacketAndWaitForResponse` does not filter or dispatch `$O` packets.
4. `ProcessGDBRemote::DoConnectRemote()` then passes the `$O...` packet to `SetThreadStopInfo(response)`, which falls into the `default:` case and returns `eStateInvalid`, aborting the connection.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs