<div dir="ltr">Hi Abid,<div><br></div><div>Sorry for remarks, but there is a one problem with "ioctl" patch: it turns off canonical mode so we can't modify commands on input line correctly :(.</div><div><br></div><div>Also I added error checks and moved "setbuf(stdin, NULL)" into Initialize function to avoid ugly in-place initialization using static variable (but, if be honest I don't know why we need to disable bufferization before "ioctl" call).</div><div><br></div><div>I prepared new patch. Review it please.</div><div><br></div><div>Thanks,</div><div>Ilia</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 3, 2014 at 3:52 PM, Ilia K <span dir="ltr"><<a href="mailto:ki.stfu@gmail.com" target="_blank">ki.stfu@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Thank you</p><div class="HOEnZb"><div class="h5">
<div class="gmail_quote">On 3 Dec 2014 15:50, "Abid, Hafiz" <<a href="mailto:Hafiz_Abid@mentor.com" target="_blank">Hafiz_Abid@mentor.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-GB" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Thanks for catching this. I have removed the extra changes in r223227.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Thanks,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Abid<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Ilia K [mailto:<a href="mailto:ki.stfu@gmail.com" target="_blank">ki.stfu@gmail.com</a>]
<br>
<b>Sent:</b> 03 December 2014 12:40<br>
<b>To:</b> Abid, Hafiz<br>
<b>Cc:</b> <a href="mailto:lldb-commits@cs.uiuc.edu" target="_blank">lldb-commits@cs.uiuc.edu</a><br>
<b>Subject:</b> RE: [Lldb-commits] [lldb] r223222 - Fix a hang on OSX while executing -exec-run.<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<p>Yes. "select" patch requires extra handling on exit.<u></u><u></u></p>
<p>Thanks, <br>
Ilia<u></u><u></u></p>
<div>
<p class="MsoNormal">On 3 Dec 2014 15:37, "Abid, Hafiz" <<a href="mailto:Hafiz_Abid@mentor.com" target="_blank">Hafiz_Abid@mentor.com</a>> wrote:<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">You mean that just the change in ‘InputAvailable’ was needed? Rest of the changes were required with
‘select’.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Regards,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Abid</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><u></u><u></u></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Ilia
K [mailto:<a href="mailto:ki.stfu@gmail.com" target="_blank">ki.stfu@gmail.com</a>]
<br>
<b>Sent:</b> 03 December 2014 10:59<br>
<b>To:</b> Abid, Hafiz<br>
<b>Cc:</b> <a href="mailto:lldb-commits@cs.uiuc.edu" target="_blank">lldb-commits@cs.uiuc.edu</a><br>
<b>Subject:</b> Re: [Lldb-commits] [lldb] r223222 - Fix a hang on OSX while executing -exec-run.</span><u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">Hello Abid,<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">Thanks for commit :)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">But "ioctl" patch requires less changes than "select" version of this patch. Could you commit another patch to revert all unnecessary changes?<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Ilia<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Wed, Dec 3, 2014 at 1:23 PM, Hafiz Abid Qadeer <<a href="mailto:hafiz_abid@mentor.com" target="_blank">hafiz_abid@mentor.com</a>> wrote:<u></u><u></u></p>
<p class="MsoNormal">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" target="_blank">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" target="_blank">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><u></u><u></u></p>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote></div>
</div></div></blockquote></div><br></div>