summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Lanza <nathan@lanza.io>2019-07-16 23:01:59 +0000
committerNathan Lanza <nathan@lanza.io>2019-07-16 23:01:59 +0000
commit0500f70e90fb0948dc60d5c57bf873bb94a50f28 (patch)
treed2cbebc6cf7867f1713ebdfea9f12ad1e6ef11bf
parentea2cba09114c93a53d4b0001a15b8734a96f7166 (diff)
add a workaround in GetLine to account for ReadFile not reporintg error
Summary: 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. A possible alternative would be to set a flag in the `sigint_handler` and simply check that flag in the true part of the if statement. However, signal handlers on Windows are asynchronous and this would require sleeping on the repl loop thread while still not necessarily guarnateeing that you caught the sigint. Reviewers: jfb Differential Revision: https://reviews.llvm.org/D64660 git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@366281 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--source/Core/IOHandler.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/source/Core/IOHandler.cpp b/source/Core/IOHandler.cpp
index 3a7a75e8a..b30308490 100644
--- a/source/Core/IOHandler.cpp
+++ b/source/Core/IOHandler.cpp
@@ -374,7 +374,18 @@ bool IOHandlerEditline::GetLine(std::string &line, bool &interrupted) {
bool got_line = false;
m_editing = true;
while (!done) {
+#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 (fgets(buffer, sizeof(buffer), in) == nullptr &&
+ fgets(buffer, sizeof(buffer), in) == nullptr) {
+#else
if (fgets(buffer, sizeof(buffer), in) == nullptr) {
+#endif
const int saved_errno = errno;
if (feof(in))
done = true;