summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
authorHafiz Abid Qadeer <hafiz_abid@mentor.com>2014-12-15 19:09:40 +0000
committerHafiz Abid Qadeer <hafiz_abid@mentor.com>2014-12-15 19:09:40 +0000
commitfcbc3cdf3c2cc9593d1ff2ba4823608e51dff74c (patch)
tree40e647d3fe67d027b4dd56176cc0d4f059e12885 /lldb
parentbe7ea19b585dc1b0d4c4358df3ca498ceb65b969 (diff)
downloadbcm5719-llvm-fcbc3cdf3c2cc9593d1ff2ba4823608e51dff74c.tar.gz
bcm5719-llvm-fcbc3cdf3c2cc9593d1ff2ba4823608e51dff74c.zip
Replace ioctl with select to reduce processor usage by lldb-mi on OSX.
This saga started with a hang on OSX. 2 solutions were proposed. 1) 'select' based solution works ok on OSX but slows down test completion time on Linux many times. 2) 'ioctl' base solution also works but it causes heavy processor usage on OSX as reported by Ilia K. But as the original hang did not occur on Linux so this commit re-introduces the 'select' in conditional code so that it only runs for OSX. There is no need for this 'fix' to run on Linux. Initial patch by Ilia K <ki.stfu@gmail.com>. A few changes were made by me. llvm-svn: 224258
Diffstat (limited to 'lldb')
-rw-r--r--lldb/tools/lldb-mi/MICmnStreamStdin.cpp12
-rw-r--r--lldb/tools/lldb-mi/MICmnStreamStdin.h2
-rw-r--r--lldb/tools/lldb-mi/MICmnStreamStdinLinux.cpp43
-rw-r--r--lldb/tools/lldb-mi/MICmnStreamStdinLinux.h1
-rw-r--r--lldb/tools/lldb-mi/MIDriver.cpp2
5 files changed, 47 insertions, 13 deletions
diff --git a/lldb/tools/lldb-mi/MICmnStreamStdin.cpp b/lldb/tools/lldb-mi/MICmnStreamStdin.cpp
index 8dccf16fca2..2d54921d323 100644
--- a/lldb/tools/lldb-mi/MICmnStreamStdin.cpp
+++ b/lldb/tools/lldb-mi/MICmnStreamStdin.cpp
@@ -435,3 +435,15 @@ CMICmnStreamStdin::SetOSStdinHandler(IOSStdinHandler &vrHandler)
return MIstatus::success;
}
+//++ ------------------------------------------------------------------------------------
+// Details: Do some actions before exiting.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+void
+CMICmnStreamStdin::OnExitHandler(void)
+{
+ m_pStdinReadHandler->InterruptReadLine();
+}
diff --git a/lldb/tools/lldb-mi/MICmnStreamStdin.h b/lldb/tools/lldb-mi/MICmnStreamStdin.h
index 7b31a644103..a6779d53166 100644
--- a/lldb/tools/lldb-mi/MICmnStreamStdin.h
+++ b/lldb/tools/lldb-mi/MICmnStreamStdin.h
@@ -66,6 +66,7 @@ class CMICmnStreamStdin : public CMICmnBase, public CMIUtilThreadActiveObjBase,
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 @@ class CMICmnStreamStdin : public CMICmnBase, public CMIUtilThreadActiveObjBase,
void SetCtrlCHit(void);
bool SetVisitor(IStreamStdin &vrVisitor);
bool SetOSStdinHandler(IOSStdinHandler &vrHandler);
+ void OnExitHandler(void);
// Overridden:
public:
diff --git a/lldb/tools/lldb-mi/MICmnStreamStdinLinux.cpp b/lldb/tools/lldb-mi/MICmnStreamStdinLinux.cpp
index ef9030b2182..07e652d84c1 100644
--- a/lldb/tools/lldb-mi/MICmnStreamStdinLinux.cpp
+++ b/lldb/tools/lldb-mi/MICmnStreamStdinLinux.cpp
@@ -20,12 +20,10 @@
//--
// Third Party Headers:
-#if !defined(_MSC_VER)
+#if defined(__APPLE__)
#include <sys/select.h>
-#include <unistd.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-#endif // !defined( _MSC_VER )
+#include <unistd.h> // For STDIN_FILENO
+#endif // defined( __APPLE__ )
#include <string.h> // For std::strerror()
// In-house headers:
@@ -155,20 +153,27 @@ CMICmnStreamStdinLinux::Shutdown(void)
bool
CMICmnStreamStdinLinux::InputAvailable(bool &vwbAvail)
{
-#if !defined(_WIN32)
+#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 'select' was also proposed but it seems to slow things down
- // a lot.
- int nBytesWaiting;
- if (::ioctl(STDIN_FILENO, FIONREAD, &nBytesWaiting) == -1)
+ // 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.
+ fd_set setOfStdin;
+ FD_ZERO(&setOfStdin);
+ FD_SET(STDIN_FILENO, &setOfStdin);
+
+ // Wait while input would be available
+ if (::select(STDIN_FILENO + 1, &setOfStdin, nullptr, nullptr, nullptr) == -1)
{
vwbAvail = false;
- return MIstatus::failure;;
+ return MIstatus::failure;
}
- vwbAvail = (nBytesWaiting > 0);
-#endif // !defined( _WIN32 )
+
+#endif // defined( __APPLE__ )
+ vwbAvail = true;
return MIstatus::success;
}
@@ -206,3 +211,15 @@ CMICmnStreamStdinLinux::ReadLine(CMIUtilString &vwErrMsg)
return pText;
}
+//++ ------------------------------------------------------------------------------------
+// Details: Interrupt current and prevent new ReadLine operations.
+// Type: Method.
+// Args: None.
+// Return: None.
+// Throws: None.
+//--
+void
+CMICmnStreamStdinLinux::InterruptReadLine(void)
+{
+ fclose(stdin);
+}
diff --git a/lldb/tools/lldb-mi/MICmnStreamStdinLinux.h b/lldb/tools/lldb-mi/MICmnStreamStdinLinux.h
index 34717225eba..edac94034f5 100644
--- a/lldb/tools/lldb-mi/MICmnStreamStdinLinux.h
+++ b/lldb/tools/lldb-mi/MICmnStreamStdinLinux.h
@@ -51,6 +51,7 @@ class CMICmnStreamStdinLinux : public CMICmnBase, public CMICmnStreamStdin::IOSS
// From CMICmnStreamStdin::IOSpecificReadStreamStdin
virtual bool InputAvailable(bool &vwbAvail);
virtual const MIchar *ReadLine(CMIUtilString &vwErrMsg);
+ virtual void InterruptReadLine(void);
// Methods:
private:
diff --git a/lldb/tools/lldb-mi/MIDriver.cpp b/lldb/tools/lldb-mi/MIDriver.cpp
index a16c62f773a..accde1c7cde 100644
--- a/lldb/tools/lldb-mi/MIDriver.cpp
+++ b/lldb/tools/lldb-mi/MIDriver.cpp
@@ -1075,6 +1075,7 @@ CMIDriver::SetExitApplicationFlag(const bool vbForceExit)
{
CMIUtilThreadLock lock(m_threadMutex);
m_bExitApp = true;
+ m_rStdin.OnExitHandler();
return;
}
@@ -1089,6 +1090,7 @@ CMIDriver::SetExitApplicationFlag(const bool vbForceExit)
}
m_bExitApp = true;
+ m_rStdin.OnExitHandler();
}
//++ ------------------------------------------------------------------------------------
OpenPOWER on IntegriCloud