diff options
Diffstat (limited to 'lldb')
-rw-r--r-- | lldb/test/tools/lldb-mi/TestMiExit.py | 1 | ||||
-rw-r--r-- | lldb/tools/lldb-mi/MICmnStreamStdinLinux.cpp | 45 | ||||
-rw-r--r-- | lldb/tools/lldb-mi/MICmnStreamStdinLinux.h | 1 |
3 files changed, 25 insertions, 22 deletions
diff --git a/lldb/test/tools/lldb-mi/TestMiExit.py b/lldb/test/tools/lldb-mi/TestMiExit.py index 223840dc46e..a8e6c8a235c 100644 --- a/lldb/test/tools/lldb-mi/TestMiExit.py +++ b/lldb/test/tools/lldb-mi/TestMiExit.py @@ -28,7 +28,6 @@ class MiExitTestCase(lldbmi_testcase.MiTestCaseBase): # Test -gdb-exit: try to exit and check that program is finished self.runCmd("-gdb-exit") - self.runCmd("") #FIXME hangs here on Linux; extra return is needed self.expect("\^exit") import pexpect self.expect(pexpect.EOF) 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; } diff --git a/lldb/tools/lldb-mi/MICmnStreamStdinLinux.h b/lldb/tools/lldb-mi/MICmnStreamStdinLinux.h index edac94034f5..78ca2db6f87 100644 --- a/lldb/tools/lldb-mi/MICmnStreamStdinLinux.h +++ b/lldb/tools/lldb-mi/MICmnStreamStdinLinux.h @@ -69,4 +69,5 @@ class CMICmnStreamStdinLinux : public CMICmnBase, public CMICmnStreamStdin::IOSS const MIuint m_constBufferSize; FILE *m_pStdin; MIchar *m_pCmdBuffer; + bool m_waitForInput; }; |