[Lldb-commits] [lldb] r228709 - Fix multiple problems of lldb-mi blocking on input monitoring and needing a return.

Hafiz Abid Qadeer hafiz_abid at mentor.com
Tue Feb 10 09:10:39 PST 2015


Author: abidh
Date: Tue Feb 10 11:10:39 2015
New Revision: 228709

URL: http://llvm.org/viewvc/llvm-project?rev=228709&view=rev
Log:
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

Modified:
    lldb/trunk/test/tools/lldb-mi/TestMiExit.py
    lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.cpp
    lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.h

Modified: lldb/trunk/test/tools/lldb-mi/TestMiExit.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/TestMiExit.py?rev=228709&r1=228708&r2=228709&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/TestMiExit.py (original)
+++ lldb/trunk/test/tools/lldb-mi/TestMiExit.py Tue Feb 10 11:10:39 2015
@@ -28,7 +28,6 @@ class MiExitTestCase(lldbmi_testcase.MiT
 
         # 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)

Modified: lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.cpp?rev=228709&r1=228708&r2=228709&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.cpp Tue Feb 10 11:10:39 2015
@@ -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::CMICmnStreamStdi
     : 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(CMIUtil
 void
 CMICmnStreamStdinLinux::InterruptReadLine(void)
 {
-    fclose(stdin);
+    m_waitForInput = false;
 }

Modified: lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.h?rev=228709&r1=228708&r2=228709&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.h Tue Feb 10 11:10:39 2015
@@ -69,4 +69,5 @@ class CMICmnStreamStdinLinux : public CM
     const MIuint m_constBufferSize;
     FILE *m_pStdin;
     MIchar *m_pCmdBuffer;
+    bool m_waitForInput;
 };





More information about the lldb-commits mailing list