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.
59 const SMICmdData & CMICmdBase::GetCmdData( void ) const
64 //++ ------------------------------------------------------------------------------------
65 // Details: The invoker requires this function.
68 // Return: CMIUtilString & - *this command's current error description.
69 // Empty string indicates command status ok.
72 const CMIUtilString & CMICmdBase::GetErrorDescription( void ) const
74 return m_strCurrentErrDescription;
77 //++ ------------------------------------------------------------------------------------
78 // Details: The CMICmdFactory requires this function. Retrieve the command and argument
79 // options description string.
82 // Return: CMIUtilString & - Command decription.
85 const CMIUtilString & CMICmdBase::GetMiCmd( void ) const
90 //++ ------------------------------------------------------------------------------------
91 // Details: The invoker requires this function. A command must be given working data and
92 // provide data about its status or provide information to other objects.
95 // Return: MIstatus::success - Functional succeeded.
96 // MIstatus::failure - Functional failed.
99 bool CMICmdBase::SetCmdData( const SMICmdData & vCmdData )
101 m_cmdData = vCmdData;
103 return MIstatus::success;
106 //++ ------------------------------------------------------------------------------------
107 // Details: The command factory requires this function. The factory calls this function
108 // so it can obtain *this command's creation function.
111 // Return: CMICmdFactory::CmdCreatorFnPtr - Function pointer.
114 CMICmdFactory::CmdCreatorFnPtr CMICmdBase::GetCmdCreatorFn( void ) const
116 return m_pSelfCreatorFn;
119 //++ ------------------------------------------------------------------------------------
120 // Details: If a command is an event type (has callbacks registered with SBListener) it
121 // needs to inform the Invoker that it has finished its work so that the
122 // Invoker can tidy up and call the commands Acknowledge function (yes the
123 // command itself could call the Acknowledge itself but not doing that way).
129 void CMICmdBase::CmdFinishedTellInvoker( void ) const
131 CMICmdInvoker::Instance().CmdExecuteFinished( const_cast< CMICmdBase & >( *this ) );
134 //++ ------------------------------------------------------------------------------------
135 // Details: Returns the final version of the MI result record built up in the command's
136 // Acknowledge function. The one line text of MI result.
139 // Return: CMIUtilString & - MI text version of the MI result record.
142 const CMIUtilString & CMICmdBase::GetMIResultRecord( void ) const
144 return m_miResultRecord.GetString();
147 //++ ------------------------------------------------------------------------------------
148 // Details: Retrieve from the command additional MI result to its 1 line response.
149 // Because of using LLDB addtional 'fake'/hack output is sometimes required to
150 // help the driver client operate i.e. Eclipse.
153 // Return: CMIUtilString & - MI text version of the MI result record.
156 const CMIUtilString & CMICmdBase::GetMIResultRecordExtra( void ) const
158 return m_miResultRecordExtra;
161 //++ ------------------------------------------------------------------------------------
162 // Details: Hss *this command got additional MI result to its 1 line response.
163 // Because of using LLDB addtional 'fake'/hack output is sometimes required to
164 // help the driver client operate i.e. Eclipse.
167 // Return: bool - True = Yes have additional MI output, false = no nothing extra.
170 bool CMICmdBase::HasMIResultRecordExtra( void ) const
172 return m_bHasResultRecordExtra;
175 //++ ------------------------------------------------------------------------------------
176 // Details: Short cut function to enter error information into the command's metadata
177 // object and set the command's error status.
179 // Args: rErrMsg - (R) Error description.
183 void CMICmdBase::SetError( const CMIUtilString & rErrMsg )
185 m_cmdData.bCmdValid = false;
186 m_cmdData.strErrorDescription = rErrMsg;
187 m_cmdData.bCmdExecutedSuccessfully = false;
189 const CMICmnMIValueResult valueResult( "msg", CMICmnMIValueConst( rErrMsg ) );
190 const CMICmnMIResultRecord miResultRecord( m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, valueResult );
191 m_miResultRecord = miResultRecord;
192 m_cmdData.strMiCmdResultRecord = miResultRecord.GetString();
195 //++ ------------------------------------------------------------------------------------
196 // Details: Ask a command to provide its unique identifier.
198 // Args: A unique identifier for this command class.
202 MIuint CMICmdBase::GetGUID( void )
204 MIuint64 vptr = reinterpret_cast< MIuint64 >( this );
205 MIuint id = (vptr ) & 0xFFFFFFFF;
206 id ^= (vptr >> 32) & 0xFFFFFFFF;
211 //++ ------------------------------------------------------------------------------------
212 // Details: The invoker requires this function. The parses the command line options
213 // arguments to extract values for each of those arguments.
216 // Return: MIstatus::success - Functional succeeded.
217 // MIstatus::failure - Functional failed.
220 bool CMICmdBase::ParseArgs( void )
222 // Do nothing - override to implement
224 return MIstatus::success;
227 //++ ------------------------------------------------------------------------------------
228 // Details: Having previously given CMICmdArgSet m_setCmdArgs all the argument or option
229 // definitions for the command to handle proceed to parse and validate the
230 // command's options text for those arguments and extract the values for each if
234 // Return: MIstatus::success - Functional succeeded.
235 // MIstatus::failure - Functional failed.
238 bool CMICmdBase::ParseValidateCmdOptions( void )
240 CMICmdArgContext argCntxt( m_cmdData.strMiCmdOption );
241 if( m_setCmdArgs.Validate( m_cmdData.strMiCmd, argCntxt ) )
242 return MIstatus::success;
244 SetError( CMIUtilString::Format( MIRSRC( IDS_CMD_ERR_ARGS ), m_cmdData.strMiCmd.c_str(), m_setCmdArgs.GetErrorDescription().c_str() ) );
246 return MIstatus::failure;
249 //++ ------------------------------------------------------------------------------------
250 // Details: If the MI Driver is not operating via a client i.e. Eclipse but say operating
251 // on a executable passed in as a argument to the drive then what should the driver
252 // do on a command failing? Either continue operating or exit the application.
253 // Override this function where a command failure cannot allow the driver to
254 // continue operating.
255 // Type: Overrideable.
257 // Return: bool - True = Fatal if command fails, false = can continue if command fails.
260 bool CMICmdBase::GetExitAppOnCommandFailure( void ) const