//++ ------------------------------------------------------------------------------------
// Details: Call this function puts *this driver to work.
//          This function is used by the application's main thread.
// Type:    Overridden.
// Args:    None.
// Return:  MIstatus::success - Functional succeeded.
//          MIstatus::failure - Functional failed.
// Throws:  None.
//--
bool
CMIDriver::DoMainLoop(void)
{
    if (!InitClientIDEToMIDriver()) // Init Eclipse IDE
    {
        SetErrorDescriptionn(MIRSRC(IDS_MI_INIT_ERR_CLIENT_USING_DRIVER));
        return MIstatus::failure;
    }

    if (!StartWorkerThreads())
        return MIstatus::failure;

    bool bOk = MIstatus::success;

    if (HaveExecutableFileNamePathOnCmdLine())
    {
        if (!LocalDebugSessionStartupExecuteCommands())
        {
            SetErrorDescription(MIRSRC(IDS_MI_INIT_ERR_LOCAL_DEBUG_SESSION));
            bOk = MIstatus::failure;
        }
    }

    // App is not quitting currently
    m_bExitApp = false;

    // Handle source file
    if (m_bHaveCommandFileNamePathOnCmdLine)
    {
        const bool bAsyncMode = false;
        ExecuteCommandFile(bAsyncMode);
    }

    // While the app is active
    while (bOk && !m_bExitApp)
    {
        CMIUtilString errorText;
        const char *pCmd = m_rStdin.ReadLine (errorText);
        if (pCmd != nullptr)
        {
            CMIUtilString lineText(pCmd);
            if (!lineText.empty ())
            {
                // Check that the handler thread is alive (otherwise we stuck here)
                assert(CMICmnLLDBDebugger::Instance().ThreadIsActive());

                {
                    // 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
                bOk = bOk && CMICmnStreamStdout::WritePrompt();

                // Wait while the handler thread handles incoming events
                CMICmnLLDBDebugger::Instance().WaitForHandleEvent();
            }
        }
    }

    // Signal that the application is shutting down
    DoAppQuit();

    // Close and wait for the workers to stop
    StopWorkerThreads();

    // Ensure that a new line is sent as the last act of the dying driver
    m_rStdOut.WriteMIResponse("\n", false);

    return MIstatus::success;
}
Exemple #2
0
//++ ------------------------------------------------------------------------------------
// Details: Call this function puts *this driver to work.
//          This function is used by the application's main thread.
// Type:    Overridden.
// Args:    None.
// Return:  MIstatus::success - Functional succeeded.
//          MIstatus::failure - Functional failed.
// Throws:  None.
//--
bool
CMIDriver::DoMainLoop(void)
{
    if (!InitClientIDEToMIDriver()) // Init Eclipse IDE
    {
        SetErrorDescriptionn(MIRSRC(IDS_MI_INIT_ERR_CLIENT_USING_DRIVER));
        return MIstatus::failure;
    }

    if (!StartWorkerThreads())
        return MIstatus::failure;

    bool bOk = MIstatus::success;

    if (HaveExecutableFileNamePathOnCmdLine())
    {
        if (!LocalDebugSessionStartupExecuteCommands())
        {
            SetErrorDescription(MIRSRC(IDS_MI_INIT_ERR_LOCAL_DEBUG_SESSION));
            bOk = MIstatus::failure;
        }
    }

    // App is not quitting currently
    m_bExitApp = false;

    // While the app is active
    while (bOk && !m_bExitApp)
    {
        CMIUtilString errorText;
        const MIchar *pCmd = m_rStdin.ReadLine (errorText);
        if (pCmd != nullptr)
        {
            CMIUtilString lineText(pCmd);
            if (!lineText.empty ())
            {
                if (lineText == "quit")
                {
                    // We want to be exiting when receiving a quit command
                    m_bExitApp = true;
                    break;
                }

                {
                    // 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())
                    bOk = m_rStdOut.WriteMIResponse(m_rStdin.GetPrompt());
            }
        }
    }

    // Signal that the application is shutting down
    DoAppQuit();

    // Close and wait for the workers to stop
    StopWorkerThreads();

    // Ensure that a new line is sent as the last act of the dying driver
    m_rStdOut.WriteMIResponse("\n", false);

    return MIstatus::success;
}