[Lldb-commits] [lldb] [lldb][windows] fix a race condition in IO reader thread (PR #194422)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Tue Apr 28 04:51:22 PDT 2026
================
@@ -740,9 +740,39 @@ ProcessWindows::OnDebugException(bool first_chance,
return ExceptionResult::SendToApplication;
}
+ // Drain any in-flight process output before announcing the stop. The I/O
+ // reader thread and this debug-event thread run concurrently. Without
+ // synchronization the eBroadcastBitStateChanged(Stopped) event can reach
+ // the Debugger event thread before the preceding eBroadcastBitSTDOUT
+ // events.
+ auto drain_stdout = [this] {
+ if (!m_stdio_communication.ReadThreadIsRunning())
+ return;
+ m_stdio_communication.SynchronizeWithReadThread();
+ if (!m_pty || m_pty->GetMode() != PseudoConsole::Mode::ConPTY)
+ return;
+
+ HANDLE pipe = m_pty->GetSTDOUTHandle();
+ for (int consec_empty = 0; consec_empty < 3;) {
+ DWORD avail = 0;
+ if (!::PeekNamedPipe(pipe, nullptr, 0, nullptr, &avail, nullptr))
----------------
charles-zablit wrote:
Not reading, only peeking the pipe, which is thread safe. I added a comment.
https://github.com/llvm/llvm-project/pull/194422
More information about the lldb-commits
mailing list