diff options
| author | Hafiz Abid Qadeer <hafiz_abid@mentor.com> | 2015-02-10 17:10:39 +0000 |
|---|---|---|
| committer | Hafiz Abid Qadeer <hafiz_abid@mentor.com> | 2015-02-10 17:10:39 +0000 |
| commit | e73e82f2beb4d25c9007a0878ca131959ec1f1b2 (patch) | |
| tree | 8d5c3c1141ffd6fdcbf07392e53035106763f9a5 /lldb/tools/lldb-mi/MICmnStreamStdinLinux.cpp | |
| parent | 404d5b242de1d849bf048a40a702d2dd04abda10 (diff) | |
| download | bcm5719-llvm-e73e82f2beb4d25c9007a0878ca131959ec1f1b2.tar.gz bcm5719-llvm-e73e82f2beb4d25c9007a0878ca131959ec1f1b2.zip | |
Fix multiple problems of lldb-mi blocking on input monitoring and needing a return.
Summary:
One of the problem is reported here.
http://llvm.org/bugs/show_bug.cgi?id=22411
A fix was committed for this problem that works only for OSX. This revision
extends that fix to other system. The select system call has some limitation with
multi-threaded application which have been addresses here.
LLDB-mi exits if quit command is given but needs an extra retur if -gdb-exit is
given. That issue has also been addressed.
Reviewers: ki.stfu, emaste
Reviewed By: ki.stfu
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D7529
llvm-svn: 228709
Diffstat (limited to 'lldb/tools/lldb-mi/MICmnStreamStdinLinux.cpp')
| -rw-r--r-- | lldb/tools/lldb-mi/MICmnStreamStdinLinux.cpp | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/lldb/tools/lldb-mi/MICmnStreamStdinLinux.cpp b/lldb/tools/lldb-mi/MICmnStreamStdinLinux.cpp index 07e652d84c1..07b547350e4 100644 --- a/lldb/tools/lldb-mi/MICmnStreamStdinLinux.cpp +++ b/lldb/tools/lldb-mi/MICmnStreamStdinLinux.cpp @@ -20,10 +20,8 @@ //-- // Third Party Headers: -#if defined(__APPLE__) #include <sys/select.h> #include <unistd.h> // For STDIN_FILENO -#endif // defined( __APPLE__ ) #include <string.h> // For std::strerror() // In-house headers: @@ -43,6 +41,7 @@ CMICmnStreamStdinLinux::CMICmnStreamStdinLinux(void) : m_constBufferSize(1024) , m_pStdin(nullptr) , m_pCmdBuffer(nullptr) + , m_waitForInput(true) { } @@ -153,28 +152,32 @@ CMICmnStreamStdinLinux::Shutdown(void) bool CMICmnStreamStdinLinux::InputAvailable(bool &vwbAvail) { -#if defined(__APPLE__) - // The code below is needed on OSX where lldb-mi hangs when doing -exec-run. - // The hang seems to come from calling fgets and fileno from different thread. - // Although this problem was not observed on Linux. - // A solution based on 'ioctl' was initially committed but it seems to make - // lldb-mi takes much more processor time. The solution based on 'select' works - // well but it seems to slow the execution of lldb-mi tests a lot on Linux. - // As a result, this code is #defined to run only on OSX. + // Wait for the input using select API. Timeout is used so that we get an + // opportunity to check if m_waitForInput has been set to false by other thread. fd_set setOfStdin; - FD_ZERO(&setOfStdin); - FD_SET(STDIN_FILENO, &setOfStdin); + struct timeval tv; - // Wait while input would be available - if (::select(STDIN_FILENO + 1, &setOfStdin, nullptr, nullptr, nullptr) == -1) + while (m_waitForInput) { - vwbAvail = false; - return MIstatus::failure; + FD_ZERO(&setOfStdin); + FD_SET(STDIN_FILENO, &setOfStdin); + tv.tv_sec = 1; + tv.tv_usec = 0; + int ret = ::select(STDIN_FILENO + 1, &setOfStdin, nullptr, nullptr, &tv); + if (ret == 0) // Timeout. Loop back if m_waitForInput is true + continue; + else if (ret == -1) // Error condition. Return + { + vwbAvail = false; + return MIstatus::failure; + } + else // Have some valid input + { + vwbAvail = true; + return MIstatus::success; + } } - -#endif // defined( __APPLE__ ) - vwbAvail = true; - return MIstatus::success; + return MIstatus::failure; } //++ ------------------------------------------------------------------------------------ @@ -221,5 +224,5 @@ CMICmnStreamStdinLinux::ReadLine(CMIUtilString &vwErrMsg) void CMICmnStreamStdinLinux::InterruptReadLine(void) { - fclose(stdin); + m_waitForInput = false; } |

