[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:38:33 PDT 2026
https://github.com/charles-zablit created https://github.com/llvm/llvm-project/pull/212745
On Windows `lldb --repl` can hang forever instead of exiting at EOF.
`IOHandlerEditline::GetLine` checks `GetLastError() == ERROR_OPERATION_ABORTED` and does a `continue` before checking `feof`.
However `fgets` is a CRT function and does not set the Win32 last error value, so the `GetLastError` read is not the expected error. When it happens to be `ERROR_OPERATION_ABORTED` (995) the loop never reaches the EOF check.
This reorders the checks so EOF wins unconditionally, and adds `clearerr` before the ctrl-c retry (a real interrupt leaves the error flag set, which would fail the next `fgets`). ctrl-c handling is otherwise unchanged.
rdar://183335061
>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] [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;
More information about the lldb-commits
mailing list