]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MIDriverMgr.h
Add ELF Tool Chain's brandelf(1) to contrib
[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 //++
11 // File:        MIDriverMgr.h
12 //
13 // Overview:    CMIImplCmn interface.
14 //
15 // Environment: Compilers:  Visual C++ 12.
16 //                          gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 //              Libraries:  See MIReadme.txt.
18 //
19 // Copyright:   None.
20 //--
21
22 #pragma once
23
24 // Third party headers:
25 #include <map>
26 #include <lldb/API/SBDebugger.h>
27
28 // In-house headers:
29 #include "MICmnBase.h"
30 #include "MIUtilString.h"
31 #include "MICmnLog.h"
32 #include "MIUtilSingletonBase.h"
33
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
41 //          command.
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
50 //          to do work.
51 //          Each driver instance (the CMIDriver, LLDB::Driver) has its own
52 //          LLDB::SBDebugger.
53 //          Singleton class.
54 // Gotchas: None.
55 // Authors: Illya Rudkin 28/02/2014.
56 // Changes: None.
57 //--
58 class CMIDriverMgr : public CMICmnBase, public MI::ISingleton<CMIDriverMgr>
59 {
60     friend MI::ISingleton<CMIDriverMgr>;
61
62     // Class:
63   public:
64     //++
65     // Description: Driver deriver objects need this interface to work with
66     //              *this manager.
67     //--
68     class IDriver
69     {
70       public:
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;
82
83         // Not part of the interface, ignore
84         /* dtor */ virtual ~IDriver(void) {}
85     };
86
87     // Methods:
88   public:
89     // MI system
90     bool Initialize(void);
91     bool Shutdown(void);
92     //
93     CMIUtilString GetAppVersion(void) const;
94     bool RegisterDriver(const IDriver &vrADriver, const CMIUtilString &vrDriverID);
95     bool UnregisterDriver(const IDriver &vrADriver);
96     bool
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;
101     //
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);
109
110     // Typedef:
111   private:
112     typedef std::map<CMIUtilString, IDriver *> MapDriverIdToDriver_t;
113     typedef std::pair<CMIUtilString, IDriver *> MapPairDriverIdToDriver_t;
114
115     // Methods:
116   private:
117     /* ctor */ CMIDriverMgr(void);
118     /* ctor */ CMIDriverMgr(const CMIDriverMgr &);
119     void operator=(const CMIDriverMgr &);
120     //
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;
126
127     // Overridden:
128   private:
129     // From CMICmnBase
130     /* dtor */ virtual ~CMIDriverMgr(void);
131
132     // Attributes:
133   private:
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)
137 };