https://github.com/charles-zablit updated 
https://github.com/llvm/llvm-project/pull/194950

>From 30f9d0f33c94dd5038a926ce05eb83eef778c19b Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Wed, 29 Apr 2026 21:18:38 +0100
Subject: [PATCH 1/2] [lldb][windows] fix command source hitting EOF

---
 lldb/source/Host/common/File.cpp                      |  9 +++++++++
 .../ScriptInterpreter/Python/io-command-source.test   | 11 +++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 
lldb/test/Shell/ScriptInterpreter/Python/io-command-source.test

diff --git a/lldb/source/Host/common/File.cpp b/lldb/source/Host/common/File.cpp
index 8346cc67ca445..546e09615b14c 100644
--- a/lldb/source/Host/common/File.cpp
+++ b/lldb/source/Host/common/File.cpp
@@ -356,6 +356,15 @@ FILE *NativeFile::GetStream() {
         if (m_stream) {
           m_own_stream = true;
           m_own_descriptor = false;
+#ifdef _WIN32
+          // On Windows, the first fgets() fills the C-runtime's internal
+          // buffer with one large OS read, leaving the underlying fd at EOF.
+          // Code that later opens the same fd then immediately hits EOF.
+          // Disabling buffering here, before any I/O touches the stream, keeps
+          // the fd in sync with what has been logically consumed.
+          if ((m_options & OpenOptionsModeMask) == eOpenOptionReadOnly)
+            setvbuf(m_stream, nullptr, _IONBF, 0);
+#endif
         }
       }
     }
diff --git a/lldb/test/Shell/ScriptInterpreter/Python/io-command-source.test 
b/lldb/test/Shell/ScriptInterpreter/Python/io-command-source.test
new file mode 100644
index 0000000000000..3ba97988d53fb
--- /dev/null
+++ b/lldb/test/Shell/ScriptInterpreter/Python/io-command-source.test
@@ -0,0 +1,11 @@
+# RUN: %lldb -o 'command source %s' 2>/dev/null | FileCheck %s
+
+# Verify that "script --language python --" inside "command source" correctly
+# reads subsequent lines as Python input rather than immediately seeing EOF.
+
+# CHECK: 255
+
+script --language python --
+variable = 250 + 5
+print(variable)
+quit()

>From a74ae6dfa7f2070379fc2624afb8e200ca32c600 Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Wed, 6 May 2026 18:37:58 +0100
Subject: [PATCH 2/2] remove test and enable existing test

---
 .../test/API/python_api/file_handle/TestFileHandle.py |  1 -
 .../ScriptInterpreter/Python/io-command-source.test   | 11 -----------
 2 files changed, 12 deletions(-)
 delete mode 100644 
lldb/test/Shell/ScriptInterpreter/Python/io-command-source.test

diff --git a/lldb/test/API/python_api/file_handle/TestFileHandle.py 
b/lldb/test/API/python_api/file_handle/TestFileHandle.py
index eba758f5a5d28..1fa2d379ad95c 100644
--- a/lldb/test/API/python_api/file_handle/TestFileHandle.py
+++ b/lldb/test/API/python_api/file_handle/TestFileHandle.py
@@ -679,7 +679,6 @@ def test_stdout_file(self):
             lines = [x for x in f.read().strip().split() if x != "7"]
             self.assertEqual(lines, ["foobar"])
 
-    @skipIf(hostoslist=["windows"])
     def test_stdout_file_interactive(self):
         """Ensure when we read stdin from a file, outputs from python goes to 
the right I/O stream."""
         with open(self.in_filename, "w") as f:
diff --git a/lldb/test/Shell/ScriptInterpreter/Python/io-command-source.test 
b/lldb/test/Shell/ScriptInterpreter/Python/io-command-source.test
deleted file mode 100644
index 3ba97988d53fb..0000000000000
--- a/lldb/test/Shell/ScriptInterpreter/Python/io-command-source.test
+++ /dev/null
@@ -1,11 +0,0 @@
-# RUN: %lldb -o 'command source %s' 2>/dev/null | FileCheck %s
-
-# Verify that "script --language python --" inside "command source" correctly
-# reads subsequent lines as Python input rather than immediately seeing EOF.
-
-# CHECK: 255
-
-script --language python --
-variable = 250 + 5
-print(variable)
-quit()

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

Reply via email to