1 //===-- MIDriver.h ----------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #pragma once 11 12 // Third party headers 13 #include <queue> 14 15 // In-house headers: 16 #include "MICmdData.h" 17 #include "MICmnBase.h" 18 #include "MICmnConfig.h" 19 #include "MICmnStreamStdin.h" 20 #include "MIDriverBase.h" 21 #include "MIDriverMgr.h" 22 #include "MIUtilSingletonBase.h" 23 24 // Declarations: 25 class CMICmnLLDBDebugger; 26 class CMICmnStreamStdout; 27 28 //++ 29 //============================================================================ 30 // Details: MI driver implementation class. A singleton class derived from 31 // LLDB SBBroadcaster class. Register the instance of *this class with 32 // the CMIDriverMgr. The CMIDriverMgr sets the driver(s) of to start 33 // work depending on the one selected to work. A driver can if not able 34 // to handle an instruction or 'command' can pass that command onto 35 // another driver object registered with the Driver Manager. 36 //-- 37 class CMIDriver : public CMICmnBase, 38 public CMIDriverMgr::IDriver, 39 public CMIDriverBase, 40 public MI::ISingleton<CMIDriver> { 41 friend class MI::ISingleton<CMIDriver>; 42 43 // Enumerations: 44 public: 45 //++ ---------------------------------------------------------------------- 46 // Details: The MI Driver has a running state which is used to help determine 47 // which specific action(s) it should take or not allow. 48 // The driver when operational and not shutting down alternates 49 // between eDriverState_RunningNotDebugging and 50 // eDriverState_RunningDebugging. eDriverState_RunningNotDebugging 51 // is normally set when a breakpoint is hit or halted. 52 // eDriverState_RunningDebugging is normally set when "exec-continue" 53 // or "exec-run" is issued. 54 //-- 55 enum DriverState_e { 56 eDriverState_NotRunning = 0, // The MI Driver is not operating 57 eDriverState_Initialising, // The MI Driver is setting itself up 58 eDriverState_RunningNotDebugging, // The MI Driver is operational acting on 59 // any MI commands sent to it 60 eDriverState_RunningDebugging, // The MI Driver is currently overseeing an 61 // inferior program that is running 62 eDriverState_ShuttingDown, // The MI Driver is tearing down resources and 63 // about exit 64 eDriverState_count // Always last 65 }; 66 67 // Methods: 68 public: 69 // MI system 70 bool Initialize() override; 71 bool Shutdown() override; 72 73 // MI state 74 bool GetExitApplicationFlag() const; 75 DriverState_e GetCurrentDriverState() const; 76 bool SetDriverStateRunningNotDebugging(); 77 bool SetDriverStateRunningDebugging(); 78 void SetDriverDebuggingArgExecutable(); 79 bool IsDriverDebuggingArgExecutable() const; 80 81 // MI information about itself 82 const CMIUtilString &GetAppNameShort() const; 83 const CMIUtilString &GetAppNameLong() const; 84 const CMIUtilString &GetVersionDescription() const; 85 86 // MI do work 87 bool WriteMessageToLog(const CMIUtilString &vMessage); 88 bool SetEnableFallThru(const bool vbYes); 89 bool GetEnableFallThru() const; 90 bool HaveExecutableFileNamePathOnCmdLine() const; 91 const CMIUtilString &GetExecutableFileNamePathOnCmdLine() const; 92 93 // Overridden: 94 public: 95 // From CMIDriverMgr::IDriver 96 bool DoInitialize() override; 97 bool DoShutdown() override; 98 bool DoMainLoop() override; 99 lldb::SBError DoParseArgs(const int argc, const char *argv[], FILE *vpStdOut, 100 bool &vwbExiting) override; 101 CMIUtilString GetError() const override; 102 const CMIUtilString &GetName() const override; 103 lldb::SBDebugger &GetTheDebugger() override; 104 bool GetDriverIsGDBMICompatibleDriver() const override; 105 bool SetId(const CMIUtilString &vId) override; 106 const CMIUtilString &GetId() const override; 107 // From CMIDriverBase 108 void SetExitApplicationFlag(const bool vbForceExit) override; 109 bool DoFallThruToAnotherDriver(const CMIUtilString &vCmd, 110 CMIUtilString &vwErrMsg) override; 111 bool SetDriverToFallThruTo(const CMIDriverBase &vrOtherDriver) override; 112 FILE *GetStdin() const override; 113 FILE *GetStdout() const override; 114 FILE *GetStderr() const override; 115 const CMIUtilString &GetDriverName() const override; 116 const CMIUtilString &GetDriverId() const override; 117 void DeliverSignal(int signal) override; 118 119 // Typedefs: 120 private: 121 typedef std::queue<CMIUtilString> QueueStdinLine_t; 122 123 // Methods: 124 private: 125 /* ctor */ CMIDriver(); 126 /* ctor */ CMIDriver(const CMIDriver &); 127 void operator=(const CMIDriver &); 128 129 lldb::SBError ParseArgs(const int argc, const char *argv[], FILE *vpStdOut, 130 bool &vwbExiting); 131 bool DoAppQuit(); 132 bool InterpretCommand(const CMIUtilString &vTextLine); 133 bool InterpretCommandThisDriver(const CMIUtilString &vTextLine, 134 bool &vwbCmdYesValid); 135 CMIUtilString 136 WrapCLICommandIntoMICommand(const CMIUtilString &vTextLine) const; 137 bool InterpretCommandFallThruDriver(const CMIUtilString &vTextLine, 138 bool &vwbCmdYesValid); 139 bool ExecuteCommand(const SMICmdData &vCmdData); 140 bool StartWorkerThreads(); 141 bool StopWorkerThreads(); 142 bool InitClientIDEToMIDriver() const; 143 bool InitClientIDEEclipse() const; 144 bool LocalDebugSessionStartupExecuteCommands(); 145 bool ExecuteCommandFile(const bool vbAsyncMode); 146 147 // Overridden: 148 private: 149 // From CMICmnBase 150 /* dtor */ ~CMIDriver() override; 151 152 // Attributes: 153 private: 154 static const CMIUtilString ms_constAppNameShort; 155 static const CMIUtilString ms_constAppNameLong; 156 static const CMIUtilString ms_constMIVersion; 157 // 158 bool m_bFallThruToOtherDriverEnabled; // True = yes fall through, false = do 159 // not pass on command 160 CMIUtilThreadMutex m_threadMutex; 161 bool m_bDriverIsExiting; // True = yes, driver told to quit, false = continue 162 // working 163 void *m_handleMainThread; // *this driver is run by the main thread 164 CMICmnStreamStdin &m_rStdin; 165 CMICmnLLDBDebugger &m_rLldbDebugger; 166 CMICmnStreamStdout &m_rStdOut; 167 DriverState_e m_eCurrentDriverState; 168 bool m_bHaveExecutableFileNamePathOnCmdLine; // True = yes, executable given 169 // as one of the parameters to 170 // the MI Driver, false = not 171 // found 172 CMIUtilString m_strCmdLineArgExecuteableFileNamePath; 173 bool m_bDriverDebuggingArgExecutable; // True = the MI Driver (MI mode) is 174 // debugging executable passed as 175 // argument, 176 // false = running via a client (e.g. Eclipse) 177 bool m_bHaveCommandFileNamePathOnCmdLine; // True = file with initial commands 178 // given as one of the parameters to 179 // the MI Driver, false = not found 180 CMIUtilString m_strCmdLineArgCommandFileNamePath; 181 }; 182