Index: tools/lldb-mi/MIDriver.h =================================================================== --- tools/lldb-mi/MIDriver.h +++ tools/lldb-mi/MIDriver.h @@ -142,7 +142,6 @@ void operator=(const CMIDriver &); lldb::SBError ParseArgs(const int argc, const char *argv[], FILE *vpStdOut, bool &vwbExiting); - bool ReadStdinLineQueue(void); bool DoAppQuit(void); bool InterpretCommand(const CMIUtilString &vTextLine); bool InterpretCommandThisDriver(const CMIUtilString &vTextLine, bool &vwbCmdYesValid); @@ -180,3 +179,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)) { @@ -627,11 +617,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()); } } @@ -648,72 +653,6 @@ } //++ ------------------------------------------------------------------------------------ -// Details: *this driver sits and waits for input to the stdin line queue shared by *this -// driver and the stdin monitor thread, it queues, *this reads, interprets and -// reacts. -// This function is used by the application's main thread. -// Type: Method. -// Args: None. -// Return: MIstatus::success - Functional succeeded. -// MIstatus::failure - Functional failed. -// Throws: None. -//-- -bool -CMIDriver::ReadStdinLineQueue(void) -{ - // True when queue contains input - bool bHaveInput = false; - - // Stores the current input line - CMIUtilString lineText; - { - // Lock while we access the queue - CMIUtilThreadLock lock(m_threadMutex); - if (!m_queueStdinLine.empty()) - { - lineText = m_queueStdinLine.front(); - m_queueStdinLine.pop(); - bHaveInput = !lineText.empty(); - } - } - - // Process while we have input - if (bHaveInput) - { - if (lineText == "quit") - { - // We want to be exiting when receiving a quit command - m_bExitApp = true; - return MIstatus::success; - } - - // Process the command - bool bOk = false; - { - // Lock Mutex before processing commands so that we don't disturb an event - // that is 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()); - - // Input has been processed - bHaveInput = false; - } - else - { - // Give resources back to the OS - const std::chrono::milliseconds time(1); - std::this_thread::sleep_for(time); - } - - return MIstatus::success; -} - -//++ ------------------------------------------------------------------------------------ // Details: Set things in motion, set state etc that brings *this driver (and the // application) to a tidy shutdown. // This function is used by the application's main thread. @@ -1335,3 +1274,33 @@ { return m_bDriverDebuggingArgExecutable; } + +//++ ------------------------------------------------------------------------------------ +// 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; +}