Fix native Windows adapter broken after detach#1050
Conversation
DebugActiveProcessStop must be called from the same thread that called DebugActiveProcess. Previously it was called from the main thread in Detach(), causing ERROR_ACCESS_DENIED and crashing the target process. Move DebugActiveProcessStop (and breakpoint cleanup) into DebugLoop() on the debug thread, handling both the stopped-at-breakpoint and target-running cases. Fixes #1041 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Detach() can now report success even when the actual detach fails, which leaves the adapter state inconsistent and drops all tracked breakpoints. The old code returned false immediately on DebugActiveProcessStop failure in public/debugger/core/adapters/windowsnativeadapter.cpp:252, but this PR moves that call into DebugLoop() and only logs a warning before breaking out of the loop (around public/debugger/core/adapters/windowsnativeadapter.cpp:564 and the new post-loop cleanup block after public/debugger/core/adapters/windowsnativeadapter.cpp:589). Detach() still joins the thread and proceeds as if detach succeeded, so any non-thread-affinity failure in DebugActiveProcessStop becomes a silent false success. Worse, the cleanup clears m_breakpoints before attempting the detach, so on failure the process can remain attached while the adapter has already discarded its breakpoint state. I did not find a second issue from the patch alone. The main fix direction looks right, but I would not merge it without preserving detach failure propagation back to Detach(). |
- Extract RemoveAllBreakpoints() helper to deduplicate software and hardware breakpoint cleanup on detach - Add missing hardware breakpoint removal (clearing debug registers on all threads) before detaching - If DebugActiveProcessStop fails, force-kill the target since its breakpoints have already been stripped and it would be in a corrupted state Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
I see your concern here but there is really not much we can do if the I made two changes to the PR:
What do you think of it? |
|
I've tried to understand this code but its complex state management and its pretty tricky. Relying on Codex but I've tried to understand the concerns and I think this addresses them well. A slight rearchitecture of how the "detach on debug thread" would solve the concerns but it needs to be less one shot fire and forget and more of a handshake. Current problems:
Here's a suggestion on how to fix:
In other words, move both:
behind a success check on the debug thread. Pseudo-flow: And in DebugLoop(): |
Summary
DebugActiveProcessStopmust be called from the same thread that calledDebugActiveProcess. Previously it was called from the main thread inDetach(), causingERROR_ACCESS_DENIEDand crashing the target process.DebugActiveProcessStop(and breakpoint cleanup) intoDebugLoop()on the debug thread, handling both the stopped-at-breakpoint and target-running cases.Fixes #1041
Test plan
🤖 Generated with Claude Code