https://github.com/charles-zablit created 
https://github.com/llvm/llvm-project/pull/175812

This patch fixes an infinite wait in `IOHandlerProcessSTDIOWindows`.

`WaitForMultipleObjects` returns when a non text input is received. `ReadFile` 
however, does not, causing an infinite wait. This patch ensures that, if 
`hstdin` is a console handle, we don't try to call `ReadFile` on non text input 
(key up events for instance).

I was not able to write a test for this. I have tried writing a shell test with 
`echo` piping commands to `lldb`, and also a custom Python script which sends 
the commands to `lldb` over stdin, but none of them work.

Related issues:
- fixes https://github.com/llvm/llvm-project/issues/175652

>From ca113a51b42d08382e0a9b6dd0636eba9f0d6ab4 Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Tue, 13 Jan 2026 18:54:43 +0000
Subject: [PATCH] [lldb][windows] prevent IOHandlerProcessSTDIOWindows from
 consuming non text inputs

---
 .../Process/Windows/Common/ProcessWindows.cpp   | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index 127dd0f59e9ae..72043d16313cd 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -981,6 +981,9 @@ class IOHandlerProcessSTDIOWindows : public IOHandler {
     HANDLE hInterrupt = (HANDLE)_get_osfhandle(m_pipe.GetReadFileDescriptor());
     HANDLE waitHandles[2] = {hStdin, hInterrupt};
 
+    DWORD consoleMode;
+    bool isConsole = GetConsoleMode(hStdin, &consoleMode) != 0;
+
     while (true) {
       {
         std::lock_guard<std::mutex> guard(m_mutex);
@@ -993,6 +996,20 @@ class IOHandlerProcessSTDIOWindows : public IOHandler {
       case WAIT_FAILED:
         goto exit_loop;
       case WAIT_OBJECT_0: {
+        if (isConsole) {
+          INPUT_RECORD inputRecord;
+          DWORD numRead = 0;
+          if (!PeekConsoleInput(hStdin, &inputRecord, 1, &numRead) ||
+              numRead == 0)
+            goto exit_loop;
+          // We only care about text input. Ignore all non text input events 
and
+          // let other IOHandlers handle them.
+          if (inputRecord.EventType != KEY_EVENT ||
+              !inputRecord.Event.KeyEvent.bKeyDown ||
+              inputRecord.Event.KeyEvent.uChar.AsciiChar == 0)
+            break;
+        }
+
         char ch = 0;
         DWORD read = 0;
         if (!ReadFile(hStdin, &ch, 1, &read, nullptr) || read != 1)

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to