Index: tools/lldb-mi/MIDriver.h =================================================================== --- tools/lldb-mi/MIDriver.h +++ tools/lldb-mi/MIDriver.h @@ -180,3 +180,5 @@ bool m_bDriverDebuggingArgExecutable; // True = The MI Driver (MI mode) is debugging executable passed as argument, false = running via // a client i.e Eclipse }; + +bool ReadLine(CMIUtilString &cmd); Index: tools/lldb-mi/MIDriver.cpp =================================================================== --- tools/lldb-mi/MIDriver.cpp +++ tools/lldb-mi/MIDriver.cpp @@ -551,16 +551,6 @@ // Grab the thread manager CMICmnThreadMgrStd &rThreadMgr = CMICmnThreadMgrStd::Instance(); - // Start the stdin thread - bOk &= m_rStdin.SetVisitor(*this); - if (bOk && !rThreadMgr.ThreadStart(m_rStdin)) - { - const CMIUtilString errMsg = CMIUtilString::Format(MIRSRC(IDS_THREADMGR_ERR_THREAD_FAIL_CREATE), - CMICmnThreadMgrStd::Instance().GetErrorDescription().c_str()); - SetErrorDescriptionn(errMsg); - return MIstatus::failure; - } - // Start the event polling thread if (bOk && !rThreadMgr.ThreadStart(m_rLldbDebugger)) { @@ -589,6 +579,36 @@ } //++ ------------------------------------------------------------------------------------ +// Details: Wait on new line of data from stdin stream (completed by '\n' or '\r'). +// Type: Method. +// Args: cmd - (W) Cmd buffer to fill. +// Return: bool - false of error and true otherwise. +// Throws: None. +//-- +bool +ReadLine(CMIUtilString &cmd) +{ + const int SIZE = 2048; + char buf[SIZE]; + // Read user input + const MIchar *pText = ::fgets(&buf[0], SIZE, stdin); + if (pText == nullptr) + return false; + + // Strip off new line characters + for (MIchar *pI = buf; *pI != '\0'; pI++) + { + if ((*pI == '\n') || (*pI == '\r')) + { + *pI = '\0'; + break; + } + } + cmd = CMIUtilString(buf); + return true; +} + +//++ ------------------------------------------------------------------------------------ // Details: Call this function puts *this driver to work. // This function is used by the application's main thread. // Type: Overridden. @@ -627,11 +647,26 @@ // While the app is active while (!m_bExitApp) { - // Poll stdin queue and dispatch - if (!ReadStdinLineQueue()) + CMIUtilString lineText; + if (::ReadLine (lineText) && (!lineText.empty ()) ) { - // Something went wrong - break; + if (lineText == "quit") + { + // We want to be exiting when receiving a quit command + m_bExitApp = true; + break; + } + + bool bOk = false; + { + // Lock Mutex before processing commands so that we don't disturb an event + // being processed + CMIUtilThreadLock lock(CMICmnLLDBDebugSessionInfo::Instance().GetSessionMutex()); + bOk = InterpretCommand(lineText); + } + // Draw prompt if desired + if (bOk && m_rStdin.GetEnablePrompt()) + m_rStdOut.WriteMIResponse(m_rStdin.GetPrompt()); } }