]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/lldb-mi/MICmdBase.cpp
Import LLDB as of upstream SVN r225923 (git 2b588ecd)
[FreeBSD/FreeBSD.git] / 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 &
60 CMICmdBase::GetCmdData(void) const
61 {
62     return m_cmdData;
63 }
64
65 //++ ------------------------------------------------------------------------------------
66 // Details: The invoker requires this function.
67 // Type:    Overridden.
68 // Args:    None.
69 // Return:  CMIUtilString & -   *this command's current error description.
70 //                              Empty string indicates command status ok.
71 // Throws:  None.
72 //--
73 const CMIUtilString &
74 CMICmdBase::GetErrorDescription(void) const
75 {
76     return m_strCurrentErrDescription;
77 }
78
79 //++ ------------------------------------------------------------------------------------
80 // Details: The CMICmdFactory requires this function. Retrieve the command and argument
81 //          options description string.
82 // Type:    Overridden.
83 // Args:    None.
84 // Return:  CMIUtilString & -   Command decription.
85 // Throws:  None.
86 //--
87 const CMIUtilString &
88 CMICmdBase::GetMiCmd(void) const
89 {
90     return m_strMiCmd;
91 }
92
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.
96 // Type:    Overridden.
97 // Args:    None.
98 // Return:  MIstatus::success - Functional succeeded.
99 //          MIstatus::failure - Functional failed.
100 // Throws:  None.
101 //--
102 bool
103 CMICmdBase::SetCmdData(const SMICmdData &vCmdData)
104 {
105     m_cmdData = vCmdData;
106
107     return MIstatus::success;
108 }
109
110 //++ ------------------------------------------------------------------------------------
111 // Details: The command factory requires this function. The factory calls this function
112 //          so it can obtain *this command's creation function.
113 // Type:    Overridden.
114 // Args:    None.
115 // Return:  CMICmdFactory::CmdCreatorFnPtr - Function pointer.
116 // Throws:  None.
117 //--
118 CMICmdFactory::CmdCreatorFnPtr
119 CMICmdBase::GetCmdCreatorFn(void) const
120 {
121     return m_pSelfCreatorFn;
122 }
123
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).
129 // Type:    Overridden.
130 // Args:    None.
131 // Return:  None.
132 // Throws:  None.
133 //--
134 void
135 CMICmdBase::CmdFinishedTellInvoker(void) const
136 {
137     CMICmdInvoker::Instance().CmdExecuteFinished(const_cast<CMICmdBase &>(*this));
138 }
139
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.
143 // Type:    Overridden.
144 // Args:    None.
145 // Return:  CMIUtilString & - MI text version of the MI result record.
146 // Throws:  None.
147 //--
148 const CMIUtilString &
149 CMICmdBase::GetMIResultRecord(void) const
150 {
151     return m_miResultRecord.GetString();
152 }
153
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.
158 // Type:    Overridden.
159 // Args:    None.
160 // Return:  CMIUtilString & - MI text version of the MI result record.
161 // Throws:  None.
162 //--
163 const CMIUtilString &
164 CMICmdBase::GetMIResultRecordExtra(void) const
165 {
166     return m_miResultRecordExtra;
167 }
168
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.
173 // Type:    Overridden.
174 // Args:    None.
175 // Return:  bool    - True = Yes have additional MI output, false = no nothing extra.
176 // Throws:  None.
177 //--
178 bool
179 CMICmdBase::HasMIResultRecordExtra(void) const
180 {
181     return m_bHasResultRecordExtra;
182 }
183
184 //++ ------------------------------------------------------------------------------------
185 // Details: Short cut function to enter error information into the command's metadata
186 //          object and set the command's error status.
187 // Type:    Method.
188 // Args:    rErrMsg - (R) Error description.
189 // Return:  None.
190 // Throws:  None.
191 //--
192 void
193 CMICmdBase::SetError(const CMIUtilString &rErrMsg)
194 {
195     m_cmdData.bCmdValid = false;
196     m_cmdData.strErrorDescription = rErrMsg;
197     m_cmdData.bCmdExecutedSuccessfully = false;
198
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();
203 }
204
205 //++ ------------------------------------------------------------------------------------
206 // Details: Ask a command to provide its unique identifier.
207 // Type:    Method.
208 // Args:    A unique identifier for this command class.
209 // Return:  None.
210 // Throws:  None.
211 //--
212 MIuint
213 CMICmdBase::GetGUID(void)
214 {
215     MIuint64 vptr = reinterpret_cast<MIuint64>(this);
216     MIuint id = (vptr)&0xFFFFFFFF;
217     id ^= (vptr >> 32) & 0xFFFFFFFF;
218
219     return id;
220 }
221
222 //++ ------------------------------------------------------------------------------------
223 // Details: The invoker requires this function. The parses the command line options
224 //          arguments to extract values for each of those arguments.
225 // Type:    Overridden.
226 // Args:    None.
227 // Return:  MIstatus::success - Functional succeeded.
228 //          MIstatus::failure - Functional failed.
229 // Throws:  None.
230 //--
231 bool
232 CMICmdBase::ParseArgs(void)
233 {
234     // Do nothing - override to implement
235
236     return MIstatus::success;
237 }
238
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
243 //          any.
244 // Type:    Method.
245 // Args:    None.
246 // Return:  MIstatus::success - Functional succeeded.
247 //          MIstatus::failure - Functional failed.
248 // Throws:  None.
249 //--
250 bool
251 CMICmdBase::ParseValidateCmdOptions(void)
252 {
253     CMICmdArgContext argCntxt(m_cmdData.strMiCmdOption);
254     if (m_setCmdArgs.Validate(m_cmdData.strMiCmd, argCntxt))
255         return MIstatus::success;
256
257     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_ARGS), m_cmdData.strMiCmd.c_str(), m_setCmdArgs.GetErrorDescription().c_str()));
258
259     return MIstatus::failure;
260 }
261
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.
269 // Args:    None.
270 // Return:  bool - True = Fatal if command fails, false = can continue if command fails.
271 // Throws:  None.
272 //--
273 bool
274 CMICmdBase::GetExitAppOnCommandFailure(void) const
275 {
276     return false;
277 }