[Lldb-commits] [lldb] [lldb][windows] prevent IOHandlerProcessSTDIOWindows from consuming non text inputs (PR #175812)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Mon Jan 19 05:58:01 PST 2026
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/175812
>From ca113a51b42d08382e0a9b6dd0636eba9f0d6ab4 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Tue, 13 Jan 2026 18:54:43 +0000
Subject: [PATCH 1/3] [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)
>From 0fa56fa8a08ea20f031baddce32d85f4bef20a41 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Mon, 19 Jan 2026 13:50:09 +0000
Subject: [PATCH 2/3] consume non text input
---
.../Process/Windows/Common/ProcessWindows.cpp | 28 +++++++++++--------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index 72043d16313cd..ed02f243a5445 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -997,17 +997,23 @@ class IOHandlerProcessSTDIOWindows : public IOHandler {
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;
+ while (true) {
+ INPUT_RECORD inputRecord;
+ DWORD numRead = 0;
+ if (!PeekConsoleInput(hStdin, &inputRecord, 1, &numRead) ||
+ numRead == 0)
+ goto exit_loop;
+
+ // We only care about text input. Consume all non text input events before letting ReadFile handle text input.
+ if (inputRecord.EventType == KEY_EVENT &&
+ inputRecord.Event.KeyEvent.bKeyDown &&
+ inputRecord.Event.KeyEvent.uChar.AsciiChar != 0)
+ break;
+
+ if (!ReadConsoleInput(hStdin, &inputRecord, 1, &numRead) ||
+ numRead == 0)
+ goto exit_loop;
+ }
}
char ch = 0;
>From 275e21f2179b313337d56f0ada62f6fb70dd767d Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Mon, 19 Jan 2026 13:57:50 +0000
Subject: [PATCH 3/3] fix formatting
---
lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index ed02f243a5445..0717f4f50a02a 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -1004,7 +1004,8 @@ class IOHandlerProcessSTDIOWindows : public IOHandler {
numRead == 0)
goto exit_loop;
- // We only care about text input. Consume all non text input events before letting ReadFile handle text input.
+ // We only care about text input. Consume all non text input events
+ // before letting ReadFile handle text input.
if (inputRecord.EventType == KEY_EVENT &&
inputRecord.Event.KeyEvent.bKeyDown &&
inputRecord.Event.KeyEvent.uChar.AsciiChar != 0)
More information about the lldb-commits
mailing list