[Lldb-commits] [PATCH] fix lldb-mi hang on OSX
dawn at burble.org
dawn at burble.org
Tue Nov 25 16:13:06 PST 2014
Hi guys,
Please help me resolve this blocking issue with lldb-mi on OSX. The patch sent
in the original e-mail (and included below) solves the problem by enabling the
ioctl code in CMICmnStreamStdinLinux::InputAvailable. Attached is an alternate
patch which uses select, but requires additional code to handle -gdb-exit.
Without either of these patches, lldb-mi hangs on OSX after -exec-run, and
-gdb-exit doesn't terminate.
Please apply one of these, or tell me how you would prefer to resolve this?
Thanks,
-Dawn
On Fri, Nov 21, 2014 at 06:57:39PM -0800, dawn at burble.org wrote:
> This patch fixes the initial hang when starting up lldb-mi in interpreter mode
> on OSX. Without this, an additional "return" is required in order for lldb-mi
> to proceed after "-exec-run" and "-gdb-exit" is also not handled properly.
>
> The patch enables code which was commented out. Was there a reason for this?
> If the code is not desired, would it be OK to enable it for OSX only? Or would
> you prefer a command-line option for this? This code is definately needed on
> OSX to get past the hang. If OK as is, please commit?
>
> Thanks,
> -Dawn
>
> Index: tools/lldb-mi/MICmnStreamStdinLinux.cpp
> ===================================================================
> --- tools/lldb-mi/MICmnStreamStdinLinux.cpp (revision 222598)
> +++ tools/lldb-mi/MICmnStreamStdinLinux.cpp (working copy)
> @@ -22,6 +22,7 @@
> // Third Party Headers:
> #if !defined(_MSC_VER)
> #include <sys/select.h>
> +#include <sys/ioctl.h>
> #include <termios.h>
> #endif // !defined( _MSC_VER )
> #include <string.h> // For std::strerror()
> @@ -153,30 +154,27 @@
> bool
> CMICmnStreamStdinLinux::InputAvailable(bool &vwbAvail)
> {
> - /* AD: Not used ATM but could come in handy just in case we need to do
> - this, poll for input
> +#if !defined(_MSC_VER)
> + // poll for input
> + static const int STDIN = 0;
> + static bool bInitialized = false;
>
> - static const int STDIN = 0;
> - static bool bInitialized = false;
> + if (!bInitialized)
> + {
> + // Use termios to turn off line buffering
> + ::termios term;
> + ::tcgetattr(STDIN, &term);
> + term.c_lflag &= ~ICANON;
> + ::tcsetattr(STDIN, TCSANOW, &term);
> + ::setbuf(stdin, NULL);
> + bInitialized = true;
> + }
>
> - if( !bInitialized )
> - {
> - // Use termios to turn off line buffering
> - ::termios term;
> - ::tcgetattr( STDIN, &term );
> - ::term.c_lflag &= ~ICANON;
> - ::tcsetattr( STDIN, TCSANOW, &term );
> - ::setbuf( stdin, NULL );
> - bInitialized = true;
> - }
> + int nBytesWaiting;
> + ::ioctl(STDIN, FIONREAD, &nBytesWaiting);
> + vwbAvail = (nBytesWaiting > 0);
> +#endif // !defined(_MSC_VER)
>
> - int nBytesWaiting;
> - ::ioctl( STDIN, FIONREAD, &nBytesWaiting );
> - vwbAvail = (nBytesWaiting > 0);
> -
> - return MIstatus::success;
> - */
> -
> return MIstatus::success;
> }
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
-------------- next part --------------
Index: tools/lldb-mi/MICmnStreamStdin.cpp
===================================================================
--- tools/lldb-mi/MICmnStreamStdin.cpp (revision 222776)
+++ tools/lldb-mi/MICmnStreamStdin.cpp (working copy)
@@ -434,3 +434,16 @@
return MIstatus::success;
}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Do some actions before exiting.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+void
+CMICmnStreamStdin::OnExitHandler(void)
+{
+ m_pStdinReadHandler->InterruptReadLine();
+}
Index: tools/lldb-mi/MICmnStreamStdin.h
===================================================================
--- tools/lldb-mi/MICmnStreamStdin.h (revision 222776)
+++ tools/lldb-mi/MICmnStreamStdin.h (working copy)
@@ -66,6 +66,7 @@
public:
virtual bool InputAvailable(bool &vwbAvail) = 0;
virtual const MIchar *ReadLine(CMIUtilString &vwErrMsg) = 0;
+ virtual void InterruptReadLine(void){};
/* dtor */ virtual ~IOSStdinHandler(void){};
};
@@ -82,6 +83,7 @@
void SetCtrlCHit(void);
bool SetVisitor(IStreamStdin &vrVisitor);
bool SetOSStdinHandler(IOSStdinHandler &vrHandler);
+ void OnExitHandler(void);
// Overridden:
public:
Index: tools/lldb-mi/MICmnStreamStdinLinux.cpp
===================================================================
--- tools/lldb-mi/MICmnStreamStdinLinux.cpp (revision 222776)
+++ tools/lldb-mi/MICmnStreamStdinLinux.cpp (working copy)
@@ -22,6 +22,7 @@
// Third Party Headers:
#if !defined(_MSC_VER)
#include <sys/select.h>
+#include <unistd.h>
#include <termios.h>
#endif // !defined( _MSC_VER )
#include <string.h> // For std::strerror()
@@ -153,30 +154,42 @@
bool
CMICmnStreamStdinLinux::InputAvailable(bool &vwbAvail)
{
- /* AD: Not used ATM but could come in handy just in case we need to do
- this, poll for input
+#if !defined(_MSC_VER)
+ fd_set setOfStdin;
+ FD_ZERO(&setOfStdin);
+ FD_SET(STDIN_FILENO, &setOfStdin);
- static const int STDIN = 0;
- static bool bInitialized = false;
+ // Wait until input is available
+ int nfds = select(STDIN_FILENO + 1, &setOfStdin, nullptr, nullptr, nullptr);
+ if (-1 == nfds)
+ {
+ vwbAvail = false;
+ return MIstatus::failure;
+ }
+ vwbAvail = (1 == nfds);
+#if 0 // Alternate fix using ioctl
+ // AD: Not used ATM but could come in handy just in case we need to do
+ // this, poll for input (note: must include <sys/ioctl.h>)
+ static const int STDIN = 0;
+ static bool bInitialized = false;
- if( !bInitialized )
- {
- // Use termios to turn off line buffering
- ::termios term;
- ::tcgetattr( STDIN, &term );
- ::term.c_lflag &= ~ICANON;
- ::tcsetattr( STDIN, TCSANOW, &term );
- ::setbuf( stdin, NULL );
- bInitialized = true;
- }
+ if (!bInitialized)
+ {
+ // Use termios to turn off line buffering
+ ::termios term;
+ ::tcgetattr(STDIN, &term);
+ term.c_lflag &= ~ICANON;
+ ::tcsetattr(STDIN, TCSANOW, &term);
+ ::setbuf(stdin, NULL);
+ bInitialized = true;
+ }
- int nBytesWaiting;
- ::ioctl( STDIN, FIONREAD, &nBytesWaiting );
- vwbAvail = (nBytesWaiting > 0);
+ int nBytesWaiting;
+ ::ioctl(STDIN, FIONREAD, &nBytesWaiting);
+ vwbAvail = (nBytesWaiting > 0);
+#endif // 0
+#endif // !defined(_MSC_VER)
- return MIstatus::success;
- */
-
return MIstatus::success;
}
@@ -213,3 +226,16 @@
return pText;
}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Interrupt current and prevent new ReadLine operations.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+void
+CMICmnStreamStdinLinux::InterruptReadLine(void)
+{
+ fclose(stdin);
+}
Index: tools/lldb-mi/MICmnStreamStdinLinux.h
===================================================================
--- tools/lldb-mi/MICmnStreamStdinLinux.h (revision 222776)
+++ tools/lldb-mi/MICmnStreamStdinLinux.h (working copy)
@@ -51,6 +51,7 @@
// From CMICmnStreamStdin::IOSpecificReadStreamStdin
virtual bool InputAvailable(bool &vwbAvail);
virtual const MIchar *ReadLine(CMIUtilString &vwErrMsg);
+ virtual void InterruptReadLine(void);
// Methods:
private:
Index: tools/lldb-mi/MIDriver.cpp
===================================================================
--- tools/lldb-mi/MIDriver.cpp (revision 222776)
+++ tools/lldb-mi/MIDriver.cpp (working copy)
@@ -1075,6 +1075,7 @@
{
CMIUtilThreadLock lock(m_threadMutex);
m_bExitApp = true;
+ m_rStdin.OnExitHandler();
return;
}
@@ -1089,6 +1090,7 @@
}
m_bExitApp = true;
+ m_rStdin.OnExitHandler();
}
//++ ------------------------------------------------------------------------------------
More information about the lldb-commits
mailing list