//++ ------------------------------------------------------------------------------------ // Details: Initialize setup *this driver ready for use. // Type: Method. // Args: None. // Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. // Throws: None. //-- bool CMIDriver::Initialize( void ) { m_eCurrentDriverState = eDriverState_Initialising; m_clientUsageRefCnt++; ClrErrorDescription(); if( m_bInitialized ) return MIstatus::success; bool bOk = MIstatus::success; CMIUtilString errMsg; // Initialize all of the modules we depend on MI::ModuleInit< CMICmnLog > ( IDS_MI_INIT_ERR_LOG , bOk, errMsg ); MI::ModuleInit< CMICmnStreamStdout >( IDS_MI_INIT_ERR_STREAMSTDOUT , bOk, errMsg ); MI::ModuleInit< CMICmnStreamStderr >( IDS_MI_INIT_ERR_STREAMSTDERR , bOk, errMsg ); MI::ModuleInit< CMICmnResources > ( IDS_MI_INIT_ERR_RESOURCES , bOk, errMsg ); MI::ModuleInit< CMICmnThreadMgrStd >( IDS_MI_INIT_ERR_THREADMANAGER, bOk, errMsg ); MI::ModuleInit< CMICmnStreamStdin > ( IDS_MI_INIT_ERR_STREAMSTDIN , bOk, errMsg ); MI::ModuleInit< CMICmdMgr > ( IDS_MI_INIT_ERR_CMDMGR , bOk, errMsg ); bOk &= m_rLldbDebugger.SetDriver( *this ); MI::ModuleInit< CMICmnLLDBDebugger >( IDS_MI_INIT_ERR_LLDBDEBUGGER , bOk, errMsg ); #if MICONFIG_COMPILE_MIDRIVER_WITH_LLDBDRIVER CMIDriverMgr & rDrvMgr = CMIDriverMgr::Instance(); bOk = bOk && rDrvMgr.RegisterDriver( *g_driver, "LLDB driver" ); // Will be pass thru driver if( bOk ) { bOk = SetEnableFallThru( false ); // This is intentional at this time - yet to be fully implemented bOk = bOk && SetDriverToFallThruTo( *g_driver ); CMIUtilString strOtherDrvErrMsg; if( bOk && GetEnableFallThru() && !g_driver->MISetup( strOtherDrvErrMsg ) ) { bOk = false; errMsg = CMIUtilString::Format( MIRSRC( IDS_MI_INIT_ERR_FALLTHRUDRIVER ), strOtherDrvErrMsg.c_str() ); } } #endif // MICONFIG_COMPILE_MIDRIVER_WITH_LLDBDRIVER m_bExitApp = false; bOk = bOk && InitClientIDEToMIDriver(); // Init Eclipse IDE m_bInitialized = bOk; if( !bOk ) { const CMIUtilString msg = CMIUtilString::Format( MIRSRC( IDS_MI_INIT_ERR_DRIVER ), errMsg.c_str() ); SetErrorDescription( msg ); return MIstatus::failure; } m_eCurrentDriverState = eDriverState_RunningNotDebugging; return bOk; }
//++ ------------------------------------------------------------------------------------ // 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; }
//++ ------------------------------------------------------------------------------------ // 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; }