1 //===-- MICmdBase.cpp -------------------------------------------*- 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 //===----------------------------------------------------------------------===//
11 // File: MICmdBase.cpp
13 // Overview: CMICmdBase implementation.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
23 #include "MICmdBase.h"
24 #include "MICmnMIValueConst.h"
25 #include "MICmnLLDBDebugSessionInfo.h"
27 //++ ------------------------------------------------------------------------------------
28 // Details: CMICmdBase constructor.
34 CMICmdBase::CMICmdBase(void)
35 : m_pSelfCreatorFn(nullptr)
36 , m_rLLDBDebugSessionInfo(CMICmnLLDBDebugSessionInfo::Instance())
37 , m_bHasResultRecordExtra(false)
41 //++ ------------------------------------------------------------------------------------
42 // Details: CMICmdBase destructor.
43 // Type: Overrideable.
48 CMICmdBase::~CMICmdBase(void)
52 //++ ------------------------------------------------------------------------------------
53 // Details: The invoker requires this function.
56 // Return: SMICmdData & - *this command's present status/data/information.
60 CMICmdBase::GetCmdData(void) const
65 //++ ------------------------------------------------------------------------------------
66 // Details: The invoker requires this function.
69 // Return: CMIUtilString & - *this command's current error description.
70 // Empty string indicates command status ok.
74 CMICmdBase::GetErrorDescription(void) const
76 return m_strCurrentErrDescription;
79 //++ ------------------------------------------------------------------------------------
80 // Details: The CMICmdFactory requires this function. Retrieve the command and argument
81 // options description string.
84 // Return: CMIUtilString & - Command decription.
88 CMICmdBase::GetMiCmd(void) const
93 //++ ------------------------------------------------------------------------------------
94 // Details: The invoker requires this function. A command must be given working data and
95 // provide data about its status or provide information to other objects.
98 // Return: MIstatus::success - Functional succeeded.
99 // MIstatus::failure - Functional failed.
103 CMICmdBase::SetCmdData(const SMICmdData &vCmdData)
105 m_cmdData = vCmdData;
107 return MIstatus::success;
110 //++ ------------------------------------------------------------------------------------
111 // Details: The command factory requires this function. The factory calls this function
112 // so it can obtain *this command's creation function.
115 // Return: CMICmdFactory::CmdCreatorFnPtr - Function pointer.
118 CMICmdFactory::CmdCreatorFnPtr
119 CMICmdBase::GetCmdCreatorFn(void) const
121 return m_pSelfCreatorFn;
124 //++ ------------------------------------------------------------------------------------
125 // Details: If a command is an event type (has callbacks registered with SBListener) it
126 // needs to inform the Invoker that it has finished its work so that the
127 // Invoker can tidy up and call the commands Acknowledge function (yes the
128 // command itself could call the Acknowledge itself but not doing that way).
135 CMICmdBase::CmdFinishedTellInvoker(void) const
137 CMICmdInvoker::Instance().CmdExecuteFinished(const_cast<CMICmdBase &>(*this));
140 //++ ------------------------------------------------------------------------------------
141 // Details: Returns the final version of the MI result record built up in the command's
142 // Acknowledge function. The one line text of MI result.
145 // Return: CMIUtilString & - MI text version of the MI result record.
148 const CMIUtilString &
149 CMICmdBase::GetMIResultRecord(void) const
151 return m_miResultRecord.GetString();
154 //++ ------------------------------------------------------------------------------------
155 // Details: Retrieve from the command additional MI result to its 1 line response.
156 // Because of using LLDB addtional 'fake'/hack output is sometimes required to
157 // help the driver client operate i.e. Eclipse.
160 // Return: CMIUtilString & - MI text version of the MI result record.
163 const CMIUtilString &
164 CMICmdBase::GetMIResultRecordExtra(void) const
166 return m_miResultRecordExtra;
169 //++ ------------------------------------------------------------------------------------
170 // Details: Hss *this command got additional MI result to its 1 line response.
171 // Because of using LLDB addtional 'fake'/hack output is sometimes required to
172 // help the driver client operate i.e. Eclipse.
175 // Return: bool - True = Yes have additional MI output, false = no nothing extra.
179 CMICmdBase::HasMIResultRecordExtra(void) const
181 return m_bHasResultRecordExtra;
184 //++ ------------------------------------------------------------------------------------
185 // Details: Short cut function to enter error information into the command's metadata
186 // object and set the command's error status.
188 // Args: rErrMsg - (R) Error description.
193 CMICmdBase::SetError(const CMIUtilString &rErrMsg)
195 m_cmdData.bCmdValid = false;
196 m_cmdData.strErrorDescription = rErrMsg;
197 m_cmdData.bCmdExecutedSuccessfully = false;
199 const CMICmnMIValueResult valueResult("msg", CMICmnMIValueConst(rErrMsg));
200 const CMICmnMIResultRecord miResultRecord(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, valueResult);
201 m_miResultRecord = miResultRecord;
202 m_cmdData.strMiCmdResultRecord = miResultRecord.GetString();
205 //++ ------------------------------------------------------------------------------------
206 // Details: Ask a command to provide its unique identifier.
208 // Args: A unique identifier for this command class.
213 CMICmdBase::GetGUID(void)
215 MIuint64 vptr = reinterpret_cast<MIuint64>(this);
216 MIuint id = (vptr)&0xFFFFFFFF;
217 id ^= (vptr >> 32) & 0xFFFFFFFF;
222 //++ ------------------------------------------------------------------------------------
223 // Details: The invoker requires this function. The parses the command line options
224 // arguments to extract values for each of those arguments.
227 // Return: MIstatus::success - Functional succeeded.
228 // MIstatus::failure - Functional failed.
232 CMICmdBase::ParseArgs(void)
234 // Do nothing - override to implement
236 return MIstatus::success;
239 //++ ------------------------------------------------------------------------------------
240 // Details: Having previously given CMICmdArgSet m_setCmdArgs all the argument or option
241 // definitions for the command to handle proceed to parse and validate the
242 // command's options text for those arguments and extract the values for each if
246 // Return: MIstatus::success - Functional succeeded.
247 // MIstatus::failure - Functional failed.
251 CMICmdBase::ParseValidateCmdOptions(void)
253 CMICmdArgContext argCntxt(m_cmdData.strMiCmdOption);
254 if (m_setCmdArgs.Validate(m_cmdData.strMiCmd, argCntxt))
255 return MIstatus::success;
257 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_ARGS), m_cmdData.strMiCmd.c_str(), m_setCmdArgs.GetErrorDescription().c_str()));
259 return MIstatus::failure;
262 //++ ------------------------------------------------------------------------------------
263 // Details: If the MI Driver is not operating via a client i.e. Eclipse but say operating
264 // on a executable passed in as a argument to the drive then what should the driver
265 // do on a command failing? Either continue operating or exit the application.
266 // Override this function where a command failure cannot allow the driver to
267 // continue operating.
268 // Type: Overrideable.
270 // Return: bool - True = Fatal if command fails, false = can continue if command fails.
274 CMICmdBase::GetExitAppOnCommandFailure(void) const