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 //===----------------------------------------------------------------------===//
12 // Third party headers:
13 #include "lldb/API/SBDebugger.h"
17 #include "MICmnBase.h"
19 #include "MIUtilSingletonBase.h"
20 #include "MIUtilString.h"
23 //============================================================================
24 // Details: MI Driver Manager. Register lldb::SBBroadcaster derived Driver type
25 // objects with *this manager. The manager does not own driver objects
26 // registered with it and so will not delete when this manager is
27 // shutdown. The Driver flagged as "use this one" will be set as
29 // driver and will be the one that is used. Other drivers are not
30 // operated. A Driver can call another Driver should it not handle a
32 // It also initializes other resources as part it's setup such as the
33 // Logger and Resources objects (explicit indicate *this object
35 // those objects (modules/components) to support it's own
37 // The Driver manager is the first object instantiated as part of the
38 // MI code base. It is also the first thing to interpret the command
39 // line arguments passed to the executable. Bases on options it
40 // understands the manage will set up the appropriate driver or give
41 // help information. Other options are passed on to the driver chosen
43 // Each driver instance (the CMIDriver, LLDB::Driver) has its own
47 class CMIDriverMgr : public CMICmnBase, public MI::ISingleton<CMIDriverMgr> {
48 friend MI::ISingleton<CMIDriverMgr>;
53 // Description: Driver deriver objects need this interface to work with
58 virtual bool DoInitialize() = 0;
59 virtual bool DoShutdown() = 0;
60 virtual bool DoMainLoop() = 0;
61 virtual lldb::SBError DoParseArgs(const int argc, const char *argv[],
62 FILE *vpStdOut, bool &vwbExiting) = 0;
63 virtual CMIUtilString GetError() const = 0;
64 virtual const CMIUtilString &GetName() const = 0;
65 virtual lldb::SBDebugger &GetTheDebugger() = 0;
66 virtual bool GetDriverIsGDBMICompatibleDriver() const = 0;
67 virtual bool SetId(const CMIUtilString &vId) = 0;
68 virtual const CMIUtilString &GetId() const = 0;
69 virtual void DeliverSignal(int signal) = 0;
71 // Not part of the interface, ignore
72 /* dtor */ virtual ~IDriver() {}
78 bool Initialize() override;
79 bool Shutdown() override;
81 CMIUtilString GetAppVersion() const;
82 bool RegisterDriver(const IDriver &vrADriver,
83 const CMIUtilString &vrDriverID);
84 bool UnregisterDriver(const IDriver &vrADriver);
85 bool SetUseThisDriverToDoWork(
86 const IDriver &vrADriver); // Specify working main driver
87 IDriver *GetUseThisDriverToDoWork() const;
88 bool ParseArgs(const int argc, const char *argv[], bool &vwbExiting);
89 IDriver *GetDriver(const CMIUtilString &vrDriverId) const;
91 // MI Proxy fn to current specified working driver
92 bool DriverMainLoop();
93 bool DriverParseArgs(const int argc, const char *argv[], FILE *vpStdOut,
95 CMIUtilString DriverGetError() const;
96 CMIUtilString DriverGetName() const;
97 lldb::SBDebugger *DriverGetTheDebugger();
98 void DeliverSignal(int signal);
102 typedef std::map<CMIUtilString, IDriver *> MapDriverIdToDriver_t;
103 typedef std::pair<CMIUtilString, IDriver *> MapPairDriverIdToDriver_t;
107 /* ctor */ CMIDriverMgr();
108 /* ctor */ CMIDriverMgr(const CMIDriverMgr &);
109 void operator=(const CMIDriverMgr &);
111 bool HaveDriverAlready(const IDriver &vrMedium) const;
112 bool UnregisterDriverAll();
113 IDriver *GetFirstMIDriver() const;
114 IDriver *GetFirstNonMIDriver() const;
115 CMIUtilString GetHelpOnCmdLineArgOptions() const;
120 /* dtor */ ~CMIDriverMgr() override;
124 MapDriverIdToDriver_t m_mapDriverIdToDriver;
125 IDriver *m_pDriverCurrent; // This driver is used by this manager to do work.
126 // It is the main driver.
127 bool m_bInMi2Mode; // True = --interpreter entered on the cmd line, false =
128 // operate LLDB driver (non GDB)