]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MIDriverMgr.h
MFV r348537: 8601 memory leak in get_special_prop()
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MIDriverMgr.h
1 //===-- MIDriverMgr.h -------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #pragma once
11
12 // Third party headers:
13 #include "lldb/API/SBDebugger.h"
14 #include <map>
15
16 // In-house headers:
17 #include "MICmnBase.h"
18 #include "MICmnLog.h"
19 #include "MIUtilSingletonBase.h"
20 #include "MIUtilString.h"
21
22 //++
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
28 //          current
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
31 //          command.
32 //          It also initializes other resources as part it's setup such as the
33 //          Logger and Resources objects (explicit indicate *this object
34 //          requires
35 //          those objects (modules/components) to support it's own
36 //          functionality).
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
42 //          to do work.
43 //          Each driver instance (the CMIDriver, LLDB::Driver) has its own
44 //          LLDB::SBDebugger.
45 //          Singleton class.
46 //--
47 class CMIDriverMgr : public CMICmnBase, public MI::ISingleton<CMIDriverMgr> {
48   friend MI::ISingleton<CMIDriverMgr>;
49
50   // Class:
51 public:
52   //++
53   // Description: Driver deriver objects need this interface to work with
54   //              *this manager.
55   //--
56   class IDriver {
57   public:
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;
70
71     // Not part of the interface, ignore
72     /* dtor */ virtual ~IDriver() {}
73   };
74
75   // Methods:
76 public:
77   // MI system
78   bool Initialize() override;
79   bool Shutdown() override;
80   //
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;
90   //
91   // MI Proxy fn to current specified working driver
92   bool DriverMainLoop();
93   bool DriverParseArgs(const int argc, const char *argv[], FILE *vpStdOut,
94                        bool &vwbExiting);
95   CMIUtilString DriverGetError() const;
96   CMIUtilString DriverGetName() const;
97   lldb::SBDebugger *DriverGetTheDebugger();
98   void DeliverSignal(int signal);
99
100   // Typedef:
101 private:
102   typedef std::map<CMIUtilString, IDriver *> MapDriverIdToDriver_t;
103   typedef std::pair<CMIUtilString, IDriver *> MapPairDriverIdToDriver_t;
104
105   // Methods:
106 private:
107   /* ctor */ CMIDriverMgr();
108   /* ctor */ CMIDriverMgr(const CMIDriverMgr &);
109   void operator=(const CMIDriverMgr &);
110   //
111   bool HaveDriverAlready(const IDriver &vrMedium) const;
112   bool UnregisterDriverAll();
113   IDriver *GetFirstMIDriver() const;
114   IDriver *GetFirstNonMIDriver() const;
115   CMIUtilString GetHelpOnCmdLineArgOptions() const;
116
117   // Overridden:
118 private:
119   // From CMICmnBase
120   /* dtor */ ~CMIDriverMgr() override;
121
122   // Attributes:
123 private:
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)
129 };