1 //===-- MICmdBase.h ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
14 // Other libraries and framework 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"
26 class CMICmnLLDBDebugSessionInfo;
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
43 // A command's Execute(), Acknowledge() and event callback functions
45 // carried out in the main thread.
46 // A command may use the argument derived object classes
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.
52 class CMICmdBase : public CMICmnBase,
53 public CMICmdInvoker::ICmd,
54 public CMICmdFactory::ICmd {
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;
73 virtual MIuint GetGUID();
77 ~CMICmdBase() override;
78 virtual bool GetExitAppOnCommandFailure() const;
82 void SetError(const CMIUtilString &rErrMsg);
83 template <class T> T *GetOption(const CMIUtilString &vStrOptionName);
84 bool ParseValidateCmdOptions();
87 CMICmdFactory::CmdCreatorFnPtr m_pSelfCreatorFn;
88 CMIUtilString m_strCurrentErrDescription; // Reason for Execute or Acknowledge
90 SMICmdData m_cmdData; // Holds information/status of *this command. Used by
91 // other MI code to report or determine state of a
93 bool m_bWaitForEventFromSBDebugger; // True = yes event type command wait,
94 // false = command calls Acknowledge()
95 // straight after Execute()
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
113 bool m_bHasResultRecordExtra; // True = Yes command produced additional MI
114 // output to its 1 line response, false = no
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;
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;
132 //------------------------------------------------------------------------------------
133 // Details: Retrieve the command argument or option object pointer so that it
135 // examined. If the option found and valid get the value (number,
137 // - see CMICmdArgValBase class) from it to use with the command's
139 // making. If the argument is not found the command's error description
141 // describing the error condition.
142 // Type: Template method.
143 // Args: vStrOptionName - (R) The text name of the argument or option to
145 // the list of the command's possible arguments
147 // Return: T * - CMICmdArgValBase derived object.
148 // - nullptr = function has failed, unable to retrieve the
149 // option/arg object.
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()));
162 return static_cast<T *>(pPtrBase);
166 //------------------------------------------------------------------------------------
167 // Details: Retrieve the command argument or option object pointer using
169 // CMICmdBase::GetOption(). Should the argument (by name) not be found
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
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.
184 #define CMICMDBASE_GETOPTION(a, b, c) \
185 CMICmdArgVal##b *a = CMICmdBase::GetOption<CMICmdArgVal##b>(c); \
187 return MIstatus::failure;
188 // This comment is to stop compile warning for #define