[Lldb-commits] [lldb] [lldb][Windows] Check for EOF before the ctrl-c retry in GetLine (PR #212745)

Charles Zablit via lldb-commits lldb-commits at lists.llvm.org
Wed Jul 29 04:53:46 PDT 2026


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

>From 773ecbd8b0822c8a5a7246dfa4555b6df0d6f56e Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Wed, 29 Jul 2026 12:35:23 +0100
Subject: [PATCH 1/2] [lldb][Windows] Check for EOF before the ctrl-c retry in
 GetLine

---
 lldb/source/Core/IOHandler.cpp | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp
index 0bb8b58f24bff..a4477e4931b15 100644
--- a/lldb/source/Core/IOHandler.cpp
+++ b/lldb/source/Core/IOHandler.cpp
@@ -395,23 +395,24 @@ bool IOHandlerEditline::GetLine(std::string &line, bool &interrupted) {
     while (!got_line) {
       char *r = fgets(buffer, sizeof(buffer), in);
 #ifdef _WIN32
-      // ReadFile on Windows is supposed to set ERROR_OPERATION_ABORTED
-      // according to the docs on MSDN. However, this has evidently been a
-      // known bug since Windows 8. Therefore, we can't detect if a signal
-      // interrupted in the fgets. So pressing ctrl-c causes the repl to end
-      // and the process to exit. A temporary workaround is just to attempt to
-      // fgets twice until this bug is fixed.
-      if (r == nullptr)
-        r = fgets(buffer, sizeof(buffer), in);
-      // this is the equivalent of EINTR for Windows
-      if (r == nullptr && GetLastError() == ERROR_OPERATION_ABORTED)
-        continue;
-#endif
       if (r == nullptr) {
+        if (feof(in)) {
+          got_line = SplitLineEOF(m_line_buffer);
+          break;
+        }
         if (ferror(in) && errno == EINTR)
           continue;
-        if (feof(in))
-          got_line = SplitLineEOF(m_line_buffer);
+        // ReadFile on Windows is supposed to set ERROR_OPERATION_ABORTED
+        // according to the docs on MSDN. However, this has evidently been a
+        // known bug since Windows 8. Therefore, we can't detect if a signal
+        // interrupted in the fgets. So pressing ctrl-c causes the repl to end
+        // and the process to exit. A temporary workaround is just to attempt
+        // to fgets twice until this bug is fixed.
+        if (GetLastError() == ERROR_OPERATION_ABORTED) {
+          clearerr(in);
+          continue;
+        }
+#endif
         break;
       }
       m_line_buffer += buffer;

>From c34c4e916b6e76ae59ec4f17d6f6d678cde7e6e8 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Wed, 29 Jul 2026 12:53:32 +0100
Subject: [PATCH 2/2] fixup! [lldb][Windows] Check for EOF before the ctrl-c
 retry in GetLine

---
 lldb/source/Core/IOHandler.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp
index a4477e4931b15..7553df36dfa54 100644
--- a/lldb/source/Core/IOHandler.cpp
+++ b/lldb/source/Core/IOHandler.cpp
@@ -394,8 +394,8 @@ bool IOHandlerEditline::GetLine(std::string &line, bool &interrupted) {
   if (!got_line && in) {
     while (!got_line) {
       char *r = fgets(buffer, sizeof(buffer), in);
-#ifdef _WIN32
       if (r == nullptr) {
+#ifdef _WIN32
         if (feof(in)) {
           got_line = SplitLineEOF(m_line_buffer);
           break;



More information about the lldb-commits mailing list