llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Charles Zablit (charles-zablit)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/175812.diff


1 Files Affected:

- (modified) lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
(+17) 


``````````diff
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)

``````````

</details>


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

Reply via email to