<div dir="ltr">Hello Abid,<br><div><br></div><div><div>Thanks for commit :)</div><div>But "ioctl" patch requires less changes than "select" version of this patch. Could you commit another patch to revert all unnecessary changes?</div></div><div><br></div><div>Thanks,</div><div>Ilia</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 3, 2014 at 1:23 PM, Hafiz Abid Qadeer <span dir="ltr"><<a href="mailto:hafiz_abid@mentor.com" target="_blank">hafiz_abid@mentor.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: abidh<br>
Date: Wed Dec  3 04:23:06 2014<br>
New Revision: 223222<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=223222&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=223222&view=rev</a><br>
Log:<br>
Fix a hang on OSX while executing -exec-run.<br>
Now we wait for input to become available before blocking in fgets.<br>
More details on problem can be found in<br>
<a href="http://lists.cs.uiuc.edu/pipermail/lldb-commits/Week-of-Mon-20141201/014290.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/lldb-commits/Week-of-Mon-20141201/014290.html</a><br>
<br>
Patch from <a href="mailto:dawn@burble.org">dawn@burble.org</a>.<br>
<br>
<br>
Modified:<br>
    lldb/trunk/tools/lldb-mi/MICmnStreamStdin.cpp<br>
    lldb/trunk/tools/lldb-mi/MICmnStreamStdin.h<br>
    lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.cpp<br>
    lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.h<br>
    lldb/trunk/tools/lldb-mi/MIDriver.cpp<br>
<br>
Modified: lldb/trunk/tools/lldb-mi/MICmnStreamStdin.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdin.cpp?rev=223222&r1=223221&r2=223222&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdin.cpp?rev=223222&r1=223221&r2=223222&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/tools/lldb-mi/MICmnStreamStdin.cpp (original)<br>
+++ lldb/trunk/tools/lldb-mi/MICmnStreamStdin.cpp Wed Dec  3 04:23:06 2014<br>
@@ -434,3 +434,16 @@ CMICmnStreamStdin::SetOSStdinHandler(IOS<br>
<br>
     return MIstatus::success;<br>
 }<br>
+<br>
+//++ ------------------------------------------------------------------------------------<br>
+// Details: Do some actions before exiting.<br>
+// Type:    Method.<br>
+// Args:    None.<br>
+// Return:  None.<br>
+// Throws:  None.<br>
+//--<br>
+void<br>
+CMICmnStreamStdin::OnExitHandler(void)<br>
+{<br>
+    m_pStdinReadHandler->InterruptReadLine();<br>
+}<br>
<br>
Modified: lldb/trunk/tools/lldb-mi/MICmnStreamStdin.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdin.h?rev=223222&r1=223221&r2=223222&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdin.h?rev=223222&r1=223221&r2=223222&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/tools/lldb-mi/MICmnStreamStdin.h (original)<br>
+++ lldb/trunk/tools/lldb-mi/MICmnStreamStdin.h Wed Dec  3 04:23:06 2014<br>
@@ -66,6 +66,7 @@ class CMICmnStreamStdin : public CMICmnB<br>
       public:<br>
         virtual bool InputAvailable(bool &vwbAvail) = 0;<br>
         virtual const MIchar *ReadLine(CMIUtilString &vwErrMsg) = 0;<br>
+        virtual void InterruptReadLine(void){};<br>
<br>
         /* dtor */ virtual ~IOSStdinHandler(void){};<br>
     };<br>
@@ -82,6 +83,7 @@ class CMICmnStreamStdin : public CMICmnB<br>
     void SetCtrlCHit(void);<br>
     bool SetVisitor(IStreamStdin &vrVisitor);<br>
     bool SetOSStdinHandler(IOSStdinHandler &vrHandler);<br>
+    void OnExitHandler(void);<br>
<br>
     // Overridden:<br>
   public:<br>
<br>
Modified: lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.cpp?rev=223222&r1=223221&r2=223222&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.cpp?rev=223222&r1=223221&r2=223222&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.cpp (original)<br>
+++ lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.cpp Wed Dec  3 04:23:06 2014<br>
@@ -22,7 +22,9 @@<br>
 // Third Party Headers:<br>
 #if !defined(_MSC_VER)<br>
 #include <sys/select.h><br>
+#include <unistd.h><br>
 #include <termios.h><br>
+#include <sys/ioctl.h><br>
 #endif              // !defined( _MSC_VER )<br>
 #include <string.h> // For std::strerror()<br>
<br>
@@ -153,30 +155,29 @@ CMICmnStreamStdinLinux::Shutdown(void)<br>
 bool<br>
 CMICmnStreamStdinLinux::InputAvailable(bool &vwbAvail)<br>
 {<br>
-    /* AD: Not used ATM but could come in handy just in case we need to do<br>
-           this, poll for input<br>
-<br>
-            static const int STDIN = 0;<br>
-        static bool bInitialized = false;<br>
-<br>
-        if( !bInitialized )<br>
-            {<br>
-            // Use termios to turn off line buffering<br>
-            ::termios term;<br>
-            ::tcgetattr( STDIN, &term );<br>
-            ::term.c_lflag &= ~ICANON;<br>
-            ::tcsetattr( STDIN, TCSANOW, &term );<br>
-            ::setbuf( stdin, NULL );<br>
-            bInitialized = true;<br>
-        }<br>
-<br>
-        int nBytesWaiting;<br>
-        ::ioctl( STDIN, FIONREAD, &nBytesWaiting );<br>
-        vwbAvail = (nBytesWaiting > 0);<br>
-<br>
-            return MIstatus::success;<br>
-    */<br>
-<br>
+#if !defined(_WIN32)<br>
+    // The code below is needed on OSX where lldb-mi hangs when doing -exec-run.<br>
+    // The hang seems to come from calling fgets and fileno from different thread.<br>
+    // Although this problem was not observed on Linux.<br>
+    // A solution based on 'select' was also proposed but it seems to slow things down<br>
+    // a lot.<br>
+    static bool bInitialized = false;<br>
+<br>
+    if (!bInitialized)<br>
+    {<br>
+        // Use termios to turn off line buffering<br>
+        ::termios term;<br>
+        ::tcgetattr(STDIN_FILENO, &term);<br>
+        term.c_lflag &= ~ICANON;<br>
+        ::tcsetattr(STDIN_FILENO, TCSANOW, &term);<br>
+        ::setbuf(stdin, NULL);<br>
+        bInitialized = true;<br>
+    }<br>
+<br>
+    int nBytesWaiting;<br>
+    ::ioctl(STDIN_FILENO, FIONREAD, &nBytesWaiting);<br>
+    vwbAvail = (nBytesWaiting > 0);<br>
+#endif<br>
     return MIstatus::success;<br>
 }<br>
<br>
@@ -213,3 +214,16 @@ CMICmnStreamStdinLinux::ReadLine(CMIUtil<br>
<br>
     return pText;<br>
 }<br>
+<br>
+//++ ------------------------------------------------------------------------------------<br>
+// Details: Interrupt current and prevent new ReadLine operations.<br>
+// Type:    Method.<br>
+// Args:    None.<br>
+// Return:  None.<br>
+// Throws:  None.<br>
+//--<br>
+void<br>
+CMICmnStreamStdinLinux::InterruptReadLine(void)<br>
+{<br>
+    fclose(stdin);<br>
+}<br>
<br>
Modified: lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.h?rev=223222&r1=223221&r2=223222&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.h?rev=223222&r1=223221&r2=223222&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.h (original)<br>
+++ lldb/trunk/tools/lldb-mi/MICmnStreamStdinLinux.h Wed Dec  3 04:23:06 2014<br>
@@ -51,6 +51,7 @@ class CMICmnStreamStdinLinux : public CM<br>
     // From CMICmnStreamStdin::IOSpecificReadStreamStdin<br>
     virtual bool InputAvailable(bool &vwbAvail);<br>
     virtual const MIchar *ReadLine(CMIUtilString &vwErrMsg);<br>
+    virtual void InterruptReadLine(void);<br>
<br>
     // Methods:<br>
   private:<br>
<br>
Modified: lldb/trunk/tools/lldb-mi/MIDriver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIDriver.cpp?rev=223222&r1=223221&r2=223222&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIDriver.cpp?rev=223222&r1=223221&r2=223222&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/tools/lldb-mi/MIDriver.cpp (original)<br>
+++ lldb/trunk/tools/lldb-mi/MIDriver.cpp Wed Dec  3 04:23:06 2014<br>
@@ -1075,6 +1075,7 @@ CMIDriver::SetExitApplicationFlag(const<br>
     {<br>
         CMIUtilThreadLock lock(m_threadMutex);<br>
         m_bExitApp = true;<br>
+        m_rStdin.OnExitHandler();<br>
         return;<br>
     }<br>
<br>
@@ -1089,6 +1090,7 @@ CMIDriver::SetExitApplicationFlag(const<br>
     }<br>
<br>
     m_bExitApp = true;<br>
+    m_rStdin.OnExitHandler();<br>
 }<br>
<br>
 //++ ------------------------------------------------------------------------------------<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@cs.uiuc.edu">lldb-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</a><br>
</blockquote></div><br></div>