1 //===-- MIDriverMgr.h -------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // Third party headers:
12 #include "lldb/API/SBDebugger.h"
16 #include "MICmnBase.h"
18 #include "MIUtilSingletonBase.h"
19 #include "MIUtilString.h"
22 //============================================================================
23 // Details: MI Driver Manager. Register lldb::SBBroadcaster derived Driver type
24 // objects with *this manager. The manager does not own driver objects
25 // registered with it and so will not delete when this manager is
26 // shutdown. The Driver flagged as "use this one" will be set as
28 // driver and will be the one that is used. Other drivers are not
29 // operated. A Driver can call another Driver should it not handle a
31 // It also initializes other resources as part it's setup such as the
32 // Logger and Resources objects (explicit indicate *this object
34 // those objects (modules/components) to support it's own
36 // The Driver manager is the first object instantiated as part of the
37 // MI code base. It is also the first thing to interpret the command
38 // line arguments passed to the executable. Bases on options it
39 // understands the manage will set up the appropriate driver or give
40 // help information. Other options are passed on to the driver chosen
42 // Each driver instance (the CMIDriver, LLDB::Driver) has its own
46 class CMIDriverMgr : public CMICmnBase, public MI::ISingleton<CMIDriverMgr> {
47 friend MI::ISingleton<CMIDriverMgr>;
52 // Description: Driver deriver objects need this interface to work with
57 virtual bool DoInitialize() = 0;
58 virtual bool DoShutdown() = 0;
59 virtual bool DoMainLoop() = 0;
60 virtual lldb::SBError DoParseArgs(const int argc, const char *argv[],
61 FILE *vpStdOut, bool &vwbExiting) = 0;
62 virtual CMIUtilString GetError() const = 0;
63 virtual const CMIUtilString &GetName() const = 0;
64 virtual lldb::SBDebugger &GetTheDebugger() = 0;
65 virtual bool GetDriverIsGDBMICompatibleDriver() const = 0;
66 virtual bool SetId(const CMIUtilString &vId) = 0;
67 virtual const CMIUtilString &GetId() const = 0;
68 virtual void DeliverSignal(int signal) = 0;
70 // Not part of the interface, ignore
71 /* dtor */ virtual ~IDriver() {}
77 bool Initialize() override;
78 bool Shutdown() override;
80 CMIUtilString GetAppVersion() const;
81 bool RegisterDriver(const IDriver &vrADriver,
82 const CMIUtilString &vrDriverID);
83 bool UnregisterDriver(const IDriver &vrADriver);
84 bool SetUseThisDriverToDoWork(
85 const IDriver &vrADriver); // Specify working main driver
86 IDriver *GetUseThisDriverToDoWork() const;
87 bool ParseArgs(const int argc, const char *argv[], bool &vwbExiting);
88 IDriver *GetDriver(const CMIUtilString &vrDriverId) const;
90 // MI Proxy fn to current specified working driver
91 bool DriverMainLoop();
92 bool DriverParseArgs(const int argc, const char *argv[], FILE *vpStdOut,
94 CMIUtilString DriverGetError() const;
95 CMIUtilString DriverGetName() const;
96 lldb::SBDebugger *DriverGetTheDebugger();
97 void DeliverSignal(int signal);
101 typedef std::map<CMIUtilString, IDriver *> MapDriverIdToDriver_t;
102 typedef std::pair<CMIUtilString, IDriver *> MapPairDriverIdToDriver_t;
106 /* ctor */ CMIDriverMgr();
107 /* ctor */ CMIDriverMgr(const CMIDriverMgr &);
108 void operator=(const CMIDriverMgr &);
110 bool HaveDriverAlready(const IDriver &vrMedium) const;
111 bool UnregisterDriverAll();
112 IDriver *GetFirstMIDriver() const;
113 IDriver *GetFirstNonMIDriver() const;
114 CMIUtilString GetHelpOnCmdLineArgOptions() const;
119 /* dtor */ ~CMIDriverMgr() override;
123 MapDriverIdToDriver_t m_mapDriverIdToDriver;
124 IDriver *m_pDriverCurrent; // This driver is used by this manager to do work.
125 // It is the main driver.
126 bool m_bInMi2Mode; // True = --interpreter entered on the cmd line, false =
127 // operate LLDB driver (non GDB)