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 "MICmnConfig.h"
17 #include "MICmnBase.h"
18 #include "MIDriverBase.h"
19 #include "MIDriverMgr.h"
20 #include "MICmnStreamStdin.h"
21 #include "MICmdData.h"
22 #include "MIUtilSingletonBase.h"
25 class CMICmnLLDBDebugger;
26 class CMICmnStreamStdout;
28 //++ ============================================================================
29 // Details: MI driver implementation class. A singleton class derived from
30 // LLDB SBBroadcaster class. Register the instance of *this class with
31 // the CMIDriverMgr. The CMIDriverMgr sets the driver(s) of to start
32 // work depending on the one selected to work. A driver can if not able
33 // to handle an instruction or 'command' can pass that command onto
34 // another driver object registered with the Driver Manager.
36 // Authors: Illya Rudkin 29/01/2014.
39 class CMIDriver : public CMICmnBase,
40 public CMIDriverMgr::IDriver,
42 public MI::ISingleton<CMIDriver>
44 friend class MI::ISingleton<CMIDriver>;
48 //++ ----------------------------------------------------------------------
49 // Details: The MI Driver has a running state which is used to help determine
50 // which specific action(s) it should take or not allow.
51 // The driver when operational and not shutting down alternates
52 // between eDriverState_RunningNotDebugging and
53 // eDriverState_RunningDebugging. eDriverState_RunningNotDebugging
54 // is normally set when a breakpoint is hit or halted.
55 // eDriverState_RunningDebugging is normally set when "exec-continue"
56 // or "exec-run" is issued.
60 eDriverState_NotRunning = 0, // The MI Driver is not operating
61 eDriverState_Initialising, // The MI Driver is setting itself up
62 eDriverState_RunningNotDebugging, // The MI Driver is operational acting on any MI commands sent to it
63 eDriverState_RunningDebugging, // The MI Driver is currently overseeing an inferior program that is running
64 eDriverState_ShuttingDown, // The MI Driver is tearing down resources and about exit
65 eDriverState_count // Always last
71 bool Initialize(void) override;
72 bool Shutdown(void) override;
75 bool GetExitApplicationFlag(void) const;
76 DriverState_e GetCurrentDriverState(void) const;
77 bool SetDriverStateRunningNotDebugging(void);
78 bool SetDriverStateRunningDebugging(void);
79 void SetDriverDebuggingArgExecutable(void);
80 bool IsDriverDebuggingArgExecutable(void) const;
82 // MI information about itself
83 const CMIUtilString &GetAppNameShort(void) const;
84 const CMIUtilString &GetAppNameLong(void) const;
85 const CMIUtilString &GetVersionDescription(void) const;
88 bool WriteMessageToLog(const CMIUtilString &vMessage);
89 bool SetEnableFallThru(const bool vbYes);
90 bool GetEnableFallThru(void) const;
91 bool HaveExecutableFileNamePathOnCmdLine(void) const;
92 const CMIUtilString &GetExecutableFileNamePathOnCmdLine(void) const;
96 // From CMIDriverMgr::IDriver
97 bool DoInitialize(void) override;
98 bool DoShutdown(void) override;
99 bool DoMainLoop(void) override;
100 lldb::SBError DoParseArgs(const int argc, const char *argv[], FILE *vpStdOut, bool &vwbExiting) override;
101 CMIUtilString GetError(void) const override;
102 const CMIUtilString &GetName(void) const override;
103 lldb::SBDebugger &GetTheDebugger(void) override;
104 bool GetDriverIsGDBMICompatibleDriver(void) const override;
105 bool SetId(const CMIUtilString &vId) override;
106 const CMIUtilString &GetId(void) const override;
107 // From CMIDriverBase
108 void SetExitApplicationFlag(const bool vbForceExit) override;
109 bool DoFallThruToAnotherDriver(const CMIUtilString &vCmd, CMIUtilString &vwErrMsg) override;
110 bool SetDriverToFallThruTo(const CMIDriverBase &vrOtherDriver) override;
111 FILE *GetStdin(void) const override;
112 FILE *GetStdout(void) const override;
113 FILE *GetStderr(void) const override;
114 const CMIUtilString &GetDriverName(void) const override;
115 const CMIUtilString &GetDriverId(void) const override;
116 void DeliverSignal(int signal) override;
120 typedef std::queue<CMIUtilString> QueueStdinLine_t;
124 /* ctor */ CMIDriver(void);
125 /* ctor */ CMIDriver(const CMIDriver &);
126 void operator=(const CMIDriver &);
128 lldb::SBError ParseArgs(const int argc, const char *argv[], FILE *vpStdOut, bool &vwbExiting);
129 bool DoAppQuit(void);
130 bool InterpretCommand(const CMIUtilString &vTextLine);
131 bool InterpretCommandThisDriver(const CMIUtilString &vTextLine, bool &vwbCmdYesValid);
132 CMIUtilString WrapCLICommandIntoMICommand(const CMIUtilString &vTextLine) const;
133 bool InterpretCommandFallThruDriver(const CMIUtilString &vTextLine, bool &vwbCmdYesValid);
134 bool ExecuteCommand(const SMICmdData &vCmdData);
135 bool StartWorkerThreads(void);
136 bool StopWorkerThreads(void);
137 bool InitClientIDEToMIDriver(void) const;
138 bool InitClientIDEEclipse(void) const;
139 bool LocalDebugSessionStartupExecuteCommands(void);
140 bool ExecuteCommandFile(const bool vbAsyncMode);
145 /* dtor */ ~CMIDriver(void) override;
149 static const CMIUtilString ms_constAppNameShort;
150 static const CMIUtilString ms_constAppNameLong;
151 static const CMIUtilString ms_constMIVersion;
153 bool m_bFallThruToOtherDriverEnabled; // True = yes fall through, false = do not pass on command
154 CMIUtilThreadMutex m_threadMutex;
155 bool m_bDriverIsExiting; // True = yes, driver told to quit, false = continue working
156 void *m_handleMainThread; // *this driver is run by the main thread
157 CMICmnStreamStdin &m_rStdin;
158 CMICmnLLDBDebugger &m_rLldbDebugger;
159 CMICmnStreamStdout &m_rStdOut;
160 DriverState_e m_eCurrentDriverState;
161 bool m_bHaveExecutableFileNamePathOnCmdLine; // True = yes, executable given as one of the parameters to the MI Driver, false = not found
162 CMIUtilString m_strCmdLineArgExecuteableFileNamePath;
163 bool m_bDriverDebuggingArgExecutable; // True = the MI Driver (MI mode) is debugging executable passed as argument,
164 // false = running via a client (e.g. Eclipse)
165 bool m_bHaveCommandFileNamePathOnCmdLine; // True = file with initial commands given as one of the parameters to the MI Driver, false = not found
166 CMIUtilString m_strCmdLineArgCommandFileNamePath;