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