]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdBase.cpp
Merge OpenSSL 1.0.1k.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdBase.cpp
1 //===-- MICmdBase.cpp -------------------------------------------*- 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:                MICmdBase.cpp
12 //
13 // Overview:    CMICmdBase implementation.
14 //
15 // Environment: Compilers:      Visual C++ 12.
16 //                                                      gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 //                              Libraries:      See MIReadmetxt. 
18 //
19 // Copyright:   None.
20 //--
21
22 // In-house headers:
23 #include "MICmdBase.h"
24 #include "MICmnMIValueConst.h"
25 #include "MICmnLLDBDebugSessionInfo.h"
26
27 //++ ------------------------------------------------------------------------------------
28 // Details:     CMICmdBase constructor.
29 // Type:        Method.
30 // Args:        None.
31 // Return:      None.
32 // Throws:      None.
33 //--
34 CMICmdBase::CMICmdBase( void )
35 :       m_pSelfCreatorFn( nullptr )
36 ,       m_rLLDBDebugSessionInfo( CMICmnLLDBDebugSessionInfo::Instance() )
37 ,       m_bHasResultRecordExtra( false )
38 {
39 }
40
41 //++ ------------------------------------------------------------------------------------
42 // Details:     CMICmdBase destructor.
43 // Type:        Overrideable.
44 // Args:        None.
45 // Return:      None.
46 // Throws:      None.
47 //--
48 CMICmdBase::~CMICmdBase( void )
49 {
50 }
51
52 //++ ------------------------------------------------------------------------------------
53 // Details:     The invoker requires this function.
54 // Type:        Overridden.
55 // Args:        None.
56 // Return:      SMICmdData & -  *this command's present status/data/information.
57 // Throws:      None.
58 //--
59 const SMICmdData & CMICmdBase::GetCmdData( void ) const 
60 {
61         return m_cmdData; 
62 }
63         
64 //++ ------------------------------------------------------------------------------------
65 // Details:     The invoker requires this function.
66 // Type:        Overridden.
67 // Args:        None.
68 // Return:      CMIUtilString & -       *this command's current error description.
69 //                                                              Empty string indicates command status ok.
70 // Throws:      None.
71 //--
72 const CMIUtilString & CMICmdBase::GetErrorDescription( void ) const 
73 {
74         return m_strCurrentErrDescription; 
75 }
76
77 //++ ------------------------------------------------------------------------------------
78 // Details:     The CMICmdFactory requires this function. Retrieve the command and argument
79 //                      options description string.
80 // Type:        Overridden.
81 // Args:        None.
82 // Return:      CMIUtilString & -       Command decription.
83 // Throws:      None.
84 //--
85 const CMIUtilString & CMICmdBase::GetMiCmd( void ) const
86
87         return m_strMiCmd; 
88 }
89
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.
93 // Type:        Overridden.
94 // Args:        None.
95 // Return:      MIstatus::success - Functional succeeded.
96 //                      MIstatus::failure - Functional failed.
97 // Throws:      None.
98 //--
99 bool CMICmdBase::SetCmdData( const SMICmdData & vCmdData ) 
100 {
101         m_cmdData = vCmdData;
102
103         return MIstatus::success;
104 }
105
106 //++ ------------------------------------------------------------------------------------
107 // Details:     The command factory requires this function. The factory calls this function 
108 //                      so it can obtain *this command's creation function.
109 // Type:        Overridden.
110 // Args:        None.
111 // Return:      CMICmdFactory::CmdCreatorFnPtr - Function pointer.
112 // Throws:      None.
113 //--
114 CMICmdFactory::CmdCreatorFnPtr CMICmdBase::GetCmdCreatorFn( void ) const
115 {
116         return m_pSelfCreatorFn;
117 }
118
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).
124 // Type:        Overridden.
125 // Args:        None.
126 // Return:      None.
127 // Throws:      None.
128 //--
129 void CMICmdBase::CmdFinishedTellInvoker( void ) const
130 {
131         CMICmdInvoker::Instance().CmdExecuteFinished( const_cast< CMICmdBase & >( *this ) );
132 }
133
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.
137 // Type:        Overridden.
138 // Args:        None.
139 // Return:      CMIUtilString & - MI text version of the MI result record.
140 // Throws:      None.
141 //--
142 const CMIUtilString & CMICmdBase::GetMIResultRecord( void ) const
143 {
144         return m_miResultRecord.GetString();
145 }
146         
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.
151 // Type:        Overridden.
152 // Args:        None.
153 // Return:      CMIUtilString & - MI text version of the MI result record.
154 // Throws:      None.
155 //--
156 const CMIUtilString & CMICmdBase::GetMIResultRecordExtra( void ) const
157 {
158         return m_miResultRecordExtra;
159 }
160
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.
165 // Type:        Overridden.
166 // Args:        None.
167 // Return:      bool    - True = Yes have additional MI output, false = no nothing extra.
168 // Throws:      None.
169 //--
170 bool CMICmdBase::HasMIResultRecordExtra( void ) const
171 {
172         return m_bHasResultRecordExtra;
173 }
174
175 //++ ------------------------------------------------------------------------------------
176 // Details:     Short cut function to enter error information into the command's metadata
177 //                      object and set the command's error status.
178 // Type:        Method.
179 // Args:        rErrMsg - (R) Error description.
180 // Return:      None.
181 // Throws:      None.
182 //--
183 void CMICmdBase::SetError( const CMIUtilString & rErrMsg )
184 {
185         m_cmdData.bCmdValid = false;
186         m_cmdData.strErrorDescription = rErrMsg;
187         m_cmdData.bCmdExecutedSuccessfully = false;
188         
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();
193 }
194
195 //++ ------------------------------------------------------------------------------------
196 // Details:     Ask a command to provide its unique identifier.
197 // Type:        Method.
198 // Args:        A unique identifier for this command class.
199 // Return:      None.
200 // Throws:      None.
201 //--
202 MIuint CMICmdBase::GetGUID( void )
203 {
204         MIuint64 vptr = reinterpret_cast< MIuint64 >( this );
205         MIuint id  = (vptr      ) & 0xFFFFFFFF;
206                         id ^= (vptr >> 32) & 0xFFFFFFFF;
207
208         return id;
209 }
210
211 //++ ------------------------------------------------------------------------------------
212 // Details:     The invoker requires this function. The parses the command line options 
213 //                      arguments to extract values for each of those arguments.
214 // Type:        Overridden.
215 // Args:        None.
216 // Return:      MIstatus::success - Functional succeeded.
217 //                      MIstatus::failure - Functional failed.
218 // Throws:      None.
219 //--
220 bool CMICmdBase::ParseArgs( void ) 
221
222         // Do nothing - override to implement
223
224         return MIstatus::success; 
225 }
226         
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
231 //                      any.
232 // Type:        Method.
233 // Args:        None.
234 // Return:      MIstatus::success - Functional succeeded.
235 //                      MIstatus::failure - Functional failed.
236 // Throws:      None.
237 //--
238 bool CMICmdBase::ParseValidateCmdOptions( void )
239 {
240         CMICmdArgContext argCntxt( m_cmdData.strMiCmdOption );
241         if( m_setCmdArgs.Validate( m_cmdData.strMiCmd, argCntxt ) )
242                 return MIstatus::success;
243         
244         SetError( CMIUtilString::Format( MIRSRC( IDS_CMD_ERR_ARGS ), m_cmdData.strMiCmd.c_str(), m_setCmdArgs.GetErrorDescription().c_str() ) );
245
246         return MIstatus::failure;
247 }
248
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.
256 // Args:        None.
257 // Return:      bool - True = Fatal if command fails, false = can continue if command fails.
258 // Throws:      None.
259 //--
260 bool CMICmdBase::GetExitAppOnCommandFailure( void ) const
261 {
262         return false;
263 }