1 //===-- MIDriverMgr.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 //===----------------------------------------------------------------------===//
11 // File: MIDriverMgr.h
13 // Overview: CMIImplCmn interface.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadme.txt.
24 // Third party headers:
26 #include <lldb/API/SBDebugger.h>
29 #include "MICmnBase.h"
30 #include "MIUtilString.h"
32 #include "MIUtilSingletonBase.h"
34 //++ ============================================================================
35 // Details: MI Driver Manager. Register lldb::SBBroadcaster derived Driver type
36 // objects with *this manager. The manager does not own driver objects
37 // registered with it and so will not delete when this manager is
38 // shutdown. The Driver flagged as "use this one" will be set as current
39 // driver and will be the one that is used. Other drivers are not
40 // operated. A Driver can call another Driver should it not handle a
42 // It also initializes other resources as part it's setup such as the
43 // Logger and Resources objects (explicit indicate *this object requires
44 // those objects (modules/components) to support it's own functionality).
45 // The Driver manager is the first object instantiated as part of the
46 // MI code base. It is also the first thing to interpret the command
47 // line arguments passed to the executeable. Bases on options it
48 // understands the manage will set up the appropriate driver or give
49 // help information. Other options are passed on to the driver chosen
51 // Each driver instance (the CMIDriver, LLDB::Driver) has its own
55 // Authors: Illya Rudkin 28/02/2014.
58 class CMIDriverMgr : public CMICmnBase, public MI::ISingleton<CMIDriverMgr>
60 friend MI::ISingleton<CMIDriverMgr>;
65 // Description: Driver deriver objects need this interface to work with
71 virtual bool DoInitialize(void) = 0;
72 virtual bool DoShutdown(void) = 0;
73 virtual bool DoMainLoop(void) = 0;
74 virtual void DoResizeWindow(const uint32_t vWindowSizeWsCol) = 0;
75 virtual lldb::SBError DoParseArgs(const int argc, const char *argv[], FILE *vpStdOut, bool &vwbExiting) = 0;
76 virtual CMIUtilString GetError(void) const = 0;
77 virtual const CMIUtilString &GetName(void) const = 0;
78 virtual lldb::SBDebugger &GetTheDebugger(void) = 0;
79 virtual bool GetDriverIsGDBMICompatibleDriver(void) const = 0;
80 virtual bool SetId(const CMIUtilString &vId) = 0;
81 virtual const CMIUtilString &GetId(void) const = 0;
83 // Not part of the interface, ignore
84 /* dtor */ virtual ~IDriver(void) {}
90 bool Initialize(void);
93 CMIUtilString GetAppVersion(void) const;
94 bool RegisterDriver(const IDriver &vrADriver, const CMIUtilString &vrDriverID);
95 bool UnregisterDriver(const IDriver &vrADriver);
97 SetUseThisDriverToDoWork(const IDriver &vrADriver); // Specify working main driver
98 IDriver *GetUseThisDriverToDoWork(void) const;
99 bool ParseArgs(const int argc, const char *argv[], bool &vwbExiting);
100 IDriver *GetDriver(const CMIUtilString &vrDriverId) const;
102 // MI Proxy fn to current specified working driver
103 bool DriverMainLoop(void);
104 void DriverResizeWindow(const uint32_t vWindowSizeWsCol);
105 bool DriverParseArgs(const int argc, const char *argv[], FILE *vpStdOut, bool &vwbExiting);
106 CMIUtilString DriverGetError(void) const;
107 CMIUtilString DriverGetName(void) const;
108 lldb::SBDebugger *DriverGetTheDebugger(void);
112 typedef std::map<CMIUtilString, IDriver *> MapDriverIdToDriver_t;
113 typedef std::pair<CMIUtilString, IDriver *> MapPairDriverIdToDriver_t;
117 /* ctor */ CMIDriverMgr(void);
118 /* ctor */ CMIDriverMgr(const CMIDriverMgr &);
119 void operator=(const CMIDriverMgr &);
121 bool HaveDriverAlready(const IDriver &vrMedium) const;
122 bool UnregisterDriverAll(void);
123 IDriver *GetFirstMIDriver(void) const;
124 IDriver *GetFirstNonMIDriver(void) const;
125 CMIUtilString GetHelpOnCmdLineArgOptions(void) const;
130 /* dtor */ virtual ~CMIDriverMgr(void);
134 MapDriverIdToDriver_t m_mapDriverIdToDriver;
135 IDriver *m_pDriverCurrent; // This driver is used by this manager to do work. It is the main driver.
136 bool m_bInMi2Mode; // True = --interpreter entered on the cmd line, false = operate LLDB driver (non GDB)