]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdBase.h
MFV r339226 (peter): Record merge of serf-1.3.9.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdBase.h
1 //===-- MICmdBase.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 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "MICmdArgSet.h"
17 #include "MICmdData.h"
18 #include "MICmdFactory.h"
19 #include "MICmdInvoker.h"
20 #include "MICmnBase.h"
21 #include "MICmnMIResultRecord.h"
22 #include "MICmnResources.h"
23 #include "MIUtilString.h"
24
25 // Declarations:
26 class CMICmnLLDBDebugSessionInfo;
27
28 //++
29 //============================================================================
30 // Details: MI command base class. MI commands derive from this base class.
31 //          The Command Factory creates command objects and passes them to the
32 //          Command Invoker. The Invoker takes ownership of any commands created
33 //          which means it is the only object to delete them when a command is
34 //          finished working. Commands do not delete themselves.
35 //          There are two types of command implicitly defined by the state of
36 //          the m_bWaitForEventFromSBDebugger flag. There is the event type
37 //          command which registers (command fn) callbacks with the SBListener
38 //          does some work then wakes up again when called back, does more work
39 //          perhaps, ends, then the Invoker calls the command's Acknowledge
40 //          function. The other type of command is one that just does some work,
41 //          ends, then the Invoker calls the command's Acknowledge function. No
42 //          events set up.
43 //          A command's Execute(), Acknowledge() and event callback functions
44 //          are
45 //          carried out in the main thread.
46 //          A command may use the argument derived object classes
47 //          (CMICmdArgValBase)
48 //          to factor handling and parsing of different types of arguments
49 //          presented to a command. A command will produce an error should it
50 //          be presented with arguments or options it does not understand.
51 //--
52 class CMICmdBase : public CMICmnBase,
53                    public CMICmdInvoker::ICmd,
54                    public CMICmdFactory::ICmd {
55   // Methods:
56 public:
57   CMICmdBase();
58
59   // Overridden:
60   // From CMICmdInvoker::ICmd
61   const SMICmdData &GetCmdData() const override;
62   const CMIUtilString &GetErrorDescription() const override;
63   void SetCmdData(const SMICmdData &vCmdData) override;
64   void CmdFinishedTellInvoker() const override;
65   const CMIUtilString &GetMIResultRecord() const override;
66   const CMIUtilString &GetMIResultRecordExtra() const override;
67   bool HasMIResultRecordExtra() const override;
68   bool ParseArgs() override;
69   // From CMICmdFactory::ICmd
70   const CMIUtilString &GetMiCmd() const override;
71   CMICmdFactory::CmdCreatorFnPtr GetCmdCreatorFn() const override;
72
73   virtual MIuint GetGUID();
74   void AddCommonArgs();
75
76   // Overrideable:
77   ~CMICmdBase() override;
78   virtual bool GetExitAppOnCommandFailure() const;
79
80   // Methods:
81 protected:
82   void SetError(const CMIUtilString &rErrMsg);
83   template <class T> T *GetOption(const CMIUtilString &vStrOptionName);
84   bool ParseValidateCmdOptions();
85
86   // Attributes:
87   CMICmdFactory::CmdCreatorFnPtr m_pSelfCreatorFn;
88   CMIUtilString m_strCurrentErrDescription; // Reason for Execute or Acknowledge
89                                             // function failure
90   SMICmdData m_cmdData; // Holds information/status of *this command. Used by
91                         // other MI code to report or determine state of a
92                         // command.
93   bool m_bWaitForEventFromSBDebugger; // True = yes event type command wait,
94                                       // false = command calls Acknowledge()
95                                       // straight after Execute()
96                                       // no waiting
97   CMIUtilString
98       m_strMiCmd; // The MI text identifying *this command i.e. 'break-insert'
99   CMICmnMIResultRecord m_miResultRecord; // This is completed in the
100                                          // Acknowledge() function and returned
101                                          // to the Command Invoker to proceed
102   // stdout output. Each command forms 1 response to its input.
103   CMIUtilString m_miResultRecordExtra; // This is completed in the Acknowledge()
104                                        // function and returned to the Command
105                                        // Invoker to proceed
106   // stdout output. Hack command produce more response text to help the client
107   // because of using LLDB
108   CMICmnLLDBDebugSessionInfo &m_rLLDBDebugSessionInfo; // Access to command
109                                                        // sharing information or
110                                                        // data across any and
111                                                        // all command based
112                                                        // derived classes.
113   bool m_bHasResultRecordExtra; // True = Yes command produced additional MI
114                                 // output to its 1 line response, false = no
115                                 // extra MI output
116                                 // formed.
117   CMICmdArgSet m_setCmdArgs;    // The list of arguments *this command needs to
118                              // parse from the options string to carry out work.
119   const CMIUtilString m_constStrArgThreadGroup;
120   const CMIUtilString m_constStrArgThread;
121   const CMIUtilString m_constStrArgFrame;
122   const CMIUtilString m_constStrArgConsume;
123
124   // These 3 members can be used by the derived classes to make any of
125   // "thread", "frame" or "thread-group" mandatory.
126   bool m_ThreadGrpArgMandatory;
127   bool m_ThreadArgMandatory;
128   bool m_FrameArgMandatory;
129 };
130
131 //++
132 //------------------------------------------------------------------------------------
133 // Details: Retrieve the command argument or option object pointer so that it
134 // can be
135 //          examined. If the option found and valid get the value (number,
136 //          string or list
137 //          - see CMICmdArgValBase class) from it to use with the command's
138 //          decision
139 //          making. If the argument is not found the command's error description
140 //          is set
141 //          describing the error condition.
142 // Type:    Template method.
143 // Args:    vStrOptionName  - (R)   The text name of the argument or option to
144 // search for in
145 //                                  the list of the command's possible arguments
146 //                                  or options.
147 // Return:  T * - CMICmdArgValBase derived object.
148 //              - nullptr = function has failed, unable to retrieve the
149 //              option/arg object.
150 // Throws:  None.
151 //--
152 template <class T>
153 T *CMICmdBase::GetOption(const CMIUtilString &vStrOptionName) {
154   CMICmdArgValBase *pPtrBase = nullptr;
155   if (!m_setCmdArgs.GetArg(vStrOptionName, pPtrBase)) {
156     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND),
157                                    m_cmdData.strMiCmd.c_str(),
158                                    vStrOptionName.c_str()));
159     return nullptr;
160   }
161
162   return static_cast<T *>(pPtrBase);
163 }
164
165 //++
166 //------------------------------------------------------------------------------------
167 // Details: Retrieve the command argument or option object pointer using
168 // template function
169 //          CMICmdBase::GetOption(). Should the argument (by name) not be found
170 //          the
171 //          command will exit with a failure (set in GetOption()).
172 // Type:    Preprocessor macro.
173 // Args:    a   - (R) The actual variable's name.
174 //          b   - (R) The type of variable (appended to CMICmdArgVal i.e.
175 //          CMICmdArgValString).
176 //          c   - (R) The text name of the argument or option to search for in
177 //          the list of
178 //                    the command's possible arguments or options.
179 // Return:  T * - CMICmdArgValBase derived object.
180 //              - nullptr = function has failed, unable to retrieve the
181 //              option/arg object.
182 // Throws:  None.
183 //--
184 #define CMICMDBASE_GETOPTION(a, b, c)                                          \
185   CMICmdArgVal##b *a = CMICmdBase::GetOption<CMICmdArgVal##b>(c);              \
186   if (a == nullptr)                                                            \
187     return MIstatus::failure;
188 // This comment is to stop compile warning for #define