1 //===-- MIDriver.h ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // Third party 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"
25 class CMICmnLLDBDebugger;
26 class CMICmnStreamStdout;
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.
37 class CMIDriver : public CMICmnBase,
38 public CMIDriverMgr::IDriver,
40 public MI::ISingleton<CMIDriver> {
41 friend class MI::ISingleton<CMIDriver>;
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.
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
64 eDriverState_count // Always last
70 bool Initialize() override;
71 bool Shutdown() override;
74 bool GetExitApplicationFlag() const;
75 DriverState_e GetCurrentDriverState() const;
76 bool SetDriverStateRunningNotDebugging();
77 bool SetDriverStateRunningDebugging();
78 void SetDriverDebuggingArgExecutable();
79 bool IsDriverDebuggingArgExecutable() const;
81 // MI information about itself
82 const CMIUtilString &GetAppNameShort() const;
83 const CMIUtilString &GetAppNameLong() const;
84 const CMIUtilString &GetVersionDescription() const;
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;
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;
121 typedef std::queue<CMIUtilString> QueueStdinLine_t;
125 /* ctor */ CMIDriver();
126 /* ctor */ CMIDriver(const CMIDriver &);
127 void operator=(const CMIDriver &);
129 lldb::SBError ParseArgs(const int argc, const char *argv[], FILE *vpStdOut,
132 bool InterpretCommand(const CMIUtilString &vTextLine);
133 bool InterpretCommandThisDriver(const CMIUtilString &vTextLine,
134 bool &vwbCmdYesValid);
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);
150 /* dtor */ ~CMIDriver() override;
154 static const CMIUtilString ms_constAppNameShort;
155 static const CMIUtilString ms_constAppNameLong;
156 static const CMIUtilString ms_constMIVersion;
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
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
172 CMIUtilString m_strCmdLineArgExecuteableFileNamePath;
173 bool m_bDriverDebuggingArgExecutable; // True = the MI Driver (MI mode) is
174 // debugging executable passed as
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;