]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MICmdCmdVar.cpp
Merge bmake-20170510
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MICmdCmdVar.cpp
1 //===-- MICmdCmdVar.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 // Overview:    CMICmdCmdVarCreate                  implementation.
11 //              CMICmdCmdVarUpdate                  implementation.
12 //              CMICmdCmdVarDelete                  implementation.
13 //              CMICmdCmdVarAssign                  implementation.
14 //              CMICmdCmdVarSetFormat               implementation.
15 //              CMICmdCmdVarListChildren            implementation.
16 //              CMICmdCmdVarEvaluateExpression      implementation.
17 //              CMICmdCmdVarInfoPathExpression      implementation.
18 //              CMICmdCmdVarShowAttributes          implementation.
19
20 // Third Party Headers:
21 #include "lldb/API/SBStream.h"
22 #include "lldb/API/SBThread.h"
23 #include "lldb/API/SBType.h"
24
25 // In-house headers:
26 #include "MICmdArgValListOfN.h"
27 #include "MICmdArgValNumber.h"
28 #include "MICmdArgValOptionLong.h"
29 #include "MICmdArgValOptionShort.h"
30 #include "MICmdArgValPrintValues.h"
31 #include "MICmdArgValString.h"
32 #include "MICmdArgValThreadGrp.h"
33 #include "MICmdCmdVar.h"
34 #include "MICmnLLDBDebugSessionInfo.h"
35 #include "MICmnLLDBDebugger.h"
36 #include "MICmnLLDBProxySBValue.h"
37 #include "MICmnLLDBUtilSBValue.h"
38 #include "MICmnMIResultRecord.h"
39 #include "MICmnMIValueConst.h"
40
41 //++
42 //------------------------------------------------------------------------------------
43 // Details: CMICmdCmdVarCreate constructor.
44 // Type:    Method.
45 // Args:    None.
46 // Return:  None.
47 // Throws:  None.
48 //--
49 CMICmdCmdVarCreate::CMICmdCmdVarCreate()
50     : m_nChildren(0), m_nThreadId(0), m_strType("??"), m_bValid(false),
51       m_strValue("??"), m_constStrArgName("name"),
52       m_constStrArgFrameAddr("frame-addr"),
53       m_constStrArgExpression("expression") {
54   // Command factory matches this name with that received from the stdin stream
55   m_strMiCmd = "var-create";
56
57   // Required by the CMICmdFactory when registering *this command
58   m_pSelfCreatorFn = &CMICmdCmdVarCreate::CreateSelf;
59 }
60
61 //++
62 //------------------------------------------------------------------------------------
63 // Details: CMICmdCmdVarCreate destructor.
64 // Type:    Overrideable.
65 // Args:    None.
66 // Return:  None.
67 // Throws:  None.
68 //--
69 CMICmdCmdVarCreate::~CMICmdCmdVarCreate() {}
70
71 //++
72 //------------------------------------------------------------------------------------
73 // Details: The invoker requires this function. The parses the command line
74 // options
75 //          arguments to extract values for each of those arguments.
76 // Type:    Overridden.
77 // Args:    None.
78 // Return:  MIstatus::success - Functional succeeded.
79 //          MIstatus::failure - Functional failed.
80 // Throws:  None.
81 //--
82 bool CMICmdCmdVarCreate::ParseArgs() {
83   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, false, true));
84   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgFrameAddr, false, true));
85   m_setCmdArgs.Add(
86       new CMICmdArgValString(m_constStrArgExpression, true, true, true, true));
87   return ParseValidateCmdOptions();
88 }
89
90 //++
91 //------------------------------------------------------------------------------------
92 // Details: The invoker requires this function. The command does work in this
93 // function.
94 //          The command is likely to communicate with the LLDB SBDebugger in
95 //          here.
96 // Type:    Overridden.
97 // Args:    None.
98 // Return:  MIstatus::success - Functional succeeded.
99 //          MIstatus::failure - Functional failed.
100 // Throws:  None.
101 //--
102 bool CMICmdCmdVarCreate::Execute() {
103   CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
104   CMICMDBASE_GETOPTION(pArgFrame, OptionLong, m_constStrArgFrame);
105   CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
106   CMICMDBASE_GETOPTION(pArgFrameAddr, String, m_constStrArgFrameAddr);
107   CMICMDBASE_GETOPTION(pArgExpression, String, m_constStrArgExpression);
108
109   // Retrieve the --thread option's thread ID (only 1)
110   MIuint64 nThreadId = UINT64_MAX;
111   if (pArgThread->GetFound() &&
112       !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId)) {
113     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND),
114                                    m_cmdData.strMiCmd.c_str(),
115                                    m_constStrArgThread.c_str()));
116     return MIstatus::failure;
117   }
118
119   // Retrieve the --frame option's number
120   MIuint64 nFrame = UINT64_MAX;
121   if (pArgThread->GetFound() &&
122       !pArgFrame->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nFrame)) {
123     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND),
124                                    m_cmdData.strMiCmd.c_str(),
125                                    m_constStrArgFrame.c_str()));
126     return MIstatus::failure;
127   }
128
129   const CMICmdArgValOptionLong::VecArgObjPtr_t &rVecFrameId(
130       pArgFrame->GetExpectedOptions());
131   CMICmdArgValOptionLong::VecArgObjPtr_t::const_iterator it2 =
132       rVecFrameId.begin();
133   if (it2 != rVecFrameId.end()) {
134     const CMICmdArgValNumber *pOption = static_cast<CMICmdArgValNumber *>(*it2);
135     nFrame = pOption->GetValue();
136   }
137
138   m_strVarName = "<unnamedvariable>";
139   if (pArgName->GetFound()) {
140     const CMIUtilString &rArg = pArgName->GetValue();
141     const bool bAutoName = (rArg == "-");
142     if (bAutoName) {
143       m_strVarName = CMIUtilString::Format(
144           "var%u", CMICmnLLDBDebugSessionInfoVarObj::VarObjIdGet());
145       CMICmnLLDBDebugSessionInfoVarObj::VarObjIdInc();
146     } else
147       m_strVarName = rArg;
148   }
149
150   bool bCurrentFrame = false;
151   if (pArgFrameAddr->GetFound()) {
152     const CMIUtilString &rStrFrameAddr(pArgFrameAddr->GetValue());
153     bCurrentFrame = CMIUtilString::Compare(rStrFrameAddr, "*");
154     if (!bCurrentFrame && (nFrame == UINT64_MAX)) {
155       // FIXME: *addr isn't implemented. Exit with error if --thread isn't
156       // specified.
157       SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND),
158                                      m_cmdData.strMiCmd.c_str(),
159                                      m_constStrArgFrame.c_str()));
160       return MIstatus::failure;
161     }
162   }
163
164   const CMIUtilString &rStrExpression(pArgExpression->GetValue());
165   m_strExpression = rStrExpression;
166
167   CMICmnLLDBDebugSessionInfo &rSessionInfo(
168       CMICmnLLDBDebugSessionInfo::Instance());
169   lldb::SBProcess sbProcess = rSessionInfo.GetProcess();
170   lldb::SBThread thread = (nThreadId != UINT64_MAX)
171                               ? sbProcess.GetThreadByIndexID(nThreadId)
172                               : sbProcess.GetSelectedThread();
173   m_nThreadId = thread.GetIndexID();
174   lldb::SBFrame frame = bCurrentFrame ? thread.GetSelectedFrame()
175                                       : thread.GetFrameAtIndex(nFrame);
176   lldb::SBValue value;
177
178   if (rStrExpression[0] == '$') {
179     const CMIUtilString rStrRegister(rStrExpression.substr(1));
180     value = frame.FindRegister(rStrRegister.c_str());
181   } else {
182     const bool bArgs = true;
183     const bool bLocals = true;
184     const bool bStatics = true;
185     const bool bInScopeOnly = false;
186     const lldb::SBValueList valueList =
187         frame.GetVariables(bArgs, bLocals, bStatics, bInScopeOnly);
188     value = valueList.GetFirstValueByName(rStrExpression.c_str());
189   }
190
191   if (!value.IsValid())
192     value = frame.EvaluateExpression(rStrExpression.c_str());
193
194   if (value.IsValid() && value.GetError().Success()) {
195     CompleteSBValue(value);
196     m_bValid = true;
197     m_nChildren = value.GetNumChildren();
198     m_strType = CMICmnLLDBUtilSBValue(value).GetTypeNameDisplay();
199
200     // This gets added to CMICmnLLDBDebugSessionInfoVarObj static container of
201     // varObjs
202     CMICmnLLDBDebugSessionInfoVarObj varObj(rStrExpression, m_strVarName,
203                                             value);
204     m_strValue = varObj.GetValueFormatted();
205   } else {
206     m_strValue = value.GetError().GetCString();
207   }
208
209   return MIstatus::success;
210 }
211
212 //++
213 //------------------------------------------------------------------------------------
214 // Details: The invoker requires this function. The command prepares a MI Record
215 // Result
216 //          for the work carried out in the Execute().
217 // Type:    Overridden.
218 // Args:    None.
219 // Return:  MIstatus::success - Functional succeeded.
220 //          MIstatus::failure - Functional failed.
221 // Throws:  None.
222 //--
223 bool CMICmdCmdVarCreate::Acknowledge() {
224   if (m_bValid) {
225     // MI print
226     // "%s^done,name=\"%s\",numchild=\"%d\",value=\"%s\",type=\"%s\",thread-id=\"%llu\",has_more=\"%u\""
227     const CMICmnMIValueConst miValueConst(m_strVarName);
228     CMICmnMIValueResult miValueResultAll("name", miValueConst);
229     const CMIUtilString strNumChild(CMIUtilString::Format("%d", m_nChildren));
230     const CMICmnMIValueConst miValueConst2(strNumChild);
231     miValueResultAll.Add("numchild", miValueConst2);
232     const CMICmnMIValueConst miValueConst3(m_strValue);
233     miValueResultAll.Add("value", miValueConst3);
234     const CMICmnMIValueConst miValueConst4(m_strType);
235     miValueResultAll.Add("type", miValueConst4);
236     const CMIUtilString strThreadId(CMIUtilString::Format("%llu", m_nThreadId));
237     const CMICmnMIValueConst miValueConst5(strThreadId);
238     miValueResultAll.Add("thread-id", miValueConst5);
239     const CMICmnMIValueConst miValueConst6("0");
240     miValueResultAll.Add("has_more", miValueConst6);
241
242     const CMICmnMIResultRecord miRecordResult(
243         m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done,
244         miValueResultAll);
245     m_miResultRecord = miRecordResult;
246
247     return MIstatus::success;
248   }
249
250   CMIUtilString strErrMsg(m_strValue);
251   if (m_strValue.empty())
252     strErrMsg = CMIUtilString::Format(
253         MIRSRC(IDS_CMD_ERR_VARIABLE_CREATION_FAILED), m_strExpression.c_str());
254   const CMICmnMIValueConst miValueConst(
255       strErrMsg.Escape(true /* vbEscapeQuotes */));
256   CMICmnMIValueResult miValueResult("msg", miValueConst);
257   const CMICmnMIResultRecord miRecordResult(
258       m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
259       miValueResult);
260   m_miResultRecord = miRecordResult;
261
262   return MIstatus::success;
263 }
264
265 //++
266 //------------------------------------------------------------------------------------
267 // Details: Required by the CMICmdFactory when registering *this command. The
268 // factory
269 //          calls this function to create an instance of *this command.
270 // Type:    Static method.
271 // Args:    None.
272 // Return:  CMICmdBase * - Pointer to a new command.
273 // Throws:  None.
274 //--
275 CMICmdBase *CMICmdCmdVarCreate::CreateSelf() {
276   return new CMICmdCmdVarCreate();
277 }
278
279 //++
280 //------------------------------------------------------------------------------------
281 // Details: Complete SBValue object and its children to get
282 // SBValue::GetValueDidChange
283 //          work.
284 // Type:    Method.
285 // Args:    vrwValue    - (R)   Value to update.
286 // Return:  MIstatus::success - Functional succeeded.
287 //          MIstatus::failure - Functional failed.
288 // Throws:  None.
289 //--
290 void CMICmdCmdVarCreate::CompleteSBValue(lldb::SBValue &vrwValue) {
291   // Force a value to update
292   vrwValue.GetValueDidChange();
293
294   // And update its children
295   lldb::SBType valueType = vrwValue.GetType();
296   if (!valueType.IsPointerType() && !valueType.IsReferenceType()) {
297     const MIuint nChildren = vrwValue.GetNumChildren();
298     for (MIuint i = 0; i < nChildren; ++i) {
299       lldb::SBValue member = vrwValue.GetChildAtIndex(i);
300       if (member.IsValid())
301         CompleteSBValue(member);
302     }
303   }
304 }
305
306 //---------------------------------------------------------------------------------------
307 //---------------------------------------------------------------------------------------
308 //---------------------------------------------------------------------------------------
309
310 //++
311 //------------------------------------------------------------------------------------
312 // Details: CMICmdCmdVarUpdate constructor.
313 // Type:    Method.
314 // Args:    None.
315 // Return:  None.
316 // Throws:  None.
317 //--
318 CMICmdCmdVarUpdate::CMICmdCmdVarUpdate()
319     : m_constStrArgPrintValues("print-values"), m_constStrArgName("name"),
320       m_bValueChanged(false), m_miValueList(true) {
321   // Command factory matches this name with that received from the stdin stream
322   m_strMiCmd = "var-update";
323
324   // Required by the CMICmdFactory when registering *this command
325   m_pSelfCreatorFn = &CMICmdCmdVarUpdate::CreateSelf;
326 }
327
328 //++
329 //------------------------------------------------------------------------------------
330 // Details: CMICmdCmdVarUpdate destructor.
331 // Type:    Overrideable.
332 // Args:    None.
333 // Return:  None.
334 // Throws:  None.
335 //--
336 CMICmdCmdVarUpdate::~CMICmdCmdVarUpdate() {}
337
338 //++
339 //------------------------------------------------------------------------------------
340 // Details: The invoker requires this function. The parses the command line
341 // options
342 //          arguments to extract values for each of those arguments.
343 // Type:    Overridden.
344 // Args:    None.
345 // Return:  MIstatus::success - Functional succeeded.
346 //          MIstatus::failure - Functional failed.
347 // Throws:  None.
348 //--
349 bool CMICmdCmdVarUpdate::ParseArgs() {
350   m_setCmdArgs.Add(
351       new CMICmdArgValPrintValues(m_constStrArgPrintValues, false, true));
352   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
353   return ParseValidateCmdOptions();
354 }
355
356 //++
357 //------------------------------------------------------------------------------------
358 // Details: The invoker requires this function. The command does work in this
359 // function.
360 //          The command is likely to communicate with the LLDB SBDebugger in
361 //          here.
362 // Type:    Overridden.
363 // Args:    None.
364 // Return:  MIstatus::success - Functional succeeded.
365 //          MIstatus::failure - Functional failed.
366 // Throws:  None.
367 //--
368 bool CMICmdCmdVarUpdate::Execute() {
369   CMICMDBASE_GETOPTION(pArgPrintValues, PrintValues, m_constStrArgPrintValues);
370   CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
371
372   CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e eVarInfoFormat =
373       CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_NoValues;
374   if (pArgPrintValues->GetFound())
375     eVarInfoFormat =
376         static_cast<CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e>(
377             pArgPrintValues->GetValue());
378
379   const CMIUtilString &rVarObjName(pArgName->GetValue());
380   CMICmnLLDBDebugSessionInfoVarObj varObj;
381   if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj)) {
382     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST),
383                                    m_cmdData.strMiCmd.c_str(),
384                                    rVarObjName.c_str()));
385     return MIstatus::failure;
386   }
387
388   lldb::SBValue &rValue = varObj.GetValue();
389   if (!ExamineSBValueForChange(rValue, m_bValueChanged))
390     return MIstatus::failure;
391
392   if (m_bValueChanged) {
393     varObj.UpdateValue();
394     const bool bPrintValue(
395         (eVarInfoFormat ==
396          CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_AllValues) ||
397         (eVarInfoFormat ==
398              CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_SimpleValues &&
399          rValue.GetNumChildren() == 0));
400     const CMIUtilString strValue(bPrintValue ? varObj.GetValueFormatted() : "");
401     const CMIUtilString strInScope(rValue.IsInScope() ? "true" : "false");
402     MIFormResponse(rVarObjName, bPrintValue ? strValue.c_str() : nullptr,
403                    strInScope);
404   }
405
406   return MIstatus::success;
407 }
408
409 //++
410 //------------------------------------------------------------------------------------
411 // Details: The invoker requires this function. The command prepares a MI Record
412 // Result
413 //          for the work carried out in the Execute().
414 // Type:    Overridden.
415 // Args:    None.
416 // Return:  MIstatus::success - Functional succeeded.
417 //          MIstatus::failure - Functional failed.
418 // Throws:  None.
419 //--
420 bool CMICmdCmdVarUpdate::Acknowledge() {
421   if (m_bValueChanged) {
422     // MI print
423     // "%s^done,changelist=[{name=\"%s\",value=\"%s\",in_scope=\"%s\",type_changed=\"false\",has_more=\"0\"}]"
424     CMICmnMIValueResult miValueResult("changelist", m_miValueList);
425     const CMICmnMIResultRecord miRecordResult(
426         m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done,
427         miValueResult);
428     m_miResultRecord = miRecordResult;
429   } else {
430     // MI print "%s^done,changelist=[]"
431     const CMICmnMIValueList miValueList(true);
432     CMICmnMIValueResult miValueResult6("changelist", miValueList);
433     const CMICmnMIResultRecord miRecordResult(
434         m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done,
435         miValueResult6);
436     m_miResultRecord = miRecordResult;
437   }
438
439   return MIstatus::success;
440 }
441
442 //++
443 //------------------------------------------------------------------------------------
444 // Details: Required by the CMICmdFactory when registering *this command. The
445 // factory
446 //          calls this function to create an instance of *this command.
447 // Type:    Static method.
448 // Args:    None.
449 // Return:  CMICmdBase * - Pointer to a new command.
450 // Throws:  None.
451 //--
452 CMICmdBase *CMICmdCmdVarUpdate::CreateSelf() {
453   return new CMICmdCmdVarUpdate();
454 }
455
456 //++
457 //------------------------------------------------------------------------------------
458 // Details: Form the MI response for multiple variables.
459 // Type:    Method.
460 // Args:    vrStrVarName    - (R)   Session var object's name.
461 //          vpValue         - (R)   Text version of the value held in the
462 //          variable.
463 //          vrStrScope      - (R)   In scope "yes" or "no".
464 // Return:  None.
465 // Throws:  None.
466 //--
467 void CMICmdCmdVarUpdate::MIFormResponse(const CMIUtilString &vrStrVarName,
468                                         const char *const vpValue,
469                                         const CMIUtilString &vrStrScope) {
470   // MI print
471   // "[{name=\"%s\",value=\"%s\",in_scope=\"%s\",type_changed=\"false\",has_more=\"0\"}]"
472   const CMICmnMIValueConst miValueConst(vrStrVarName);
473   const CMICmnMIValueResult miValueResult("name", miValueConst);
474   CMICmnMIValueTuple miValueTuple(miValueResult);
475   if (vpValue != nullptr) {
476     const CMICmnMIValueConst miValueConst2(vpValue);
477     const CMICmnMIValueResult miValueResult2("value", miValueConst2);
478     miValueTuple.Add(miValueResult2);
479   }
480   const CMICmnMIValueConst miValueConst3(vrStrScope);
481   const CMICmnMIValueResult miValueResult3("in_scope", miValueConst3);
482   miValueTuple.Add(miValueResult3);
483   const CMICmnMIValueConst miValueConst4("false");
484   const CMICmnMIValueResult miValueResult4("type_changed", miValueConst4);
485   miValueTuple.Add(miValueResult4);
486   const CMICmnMIValueConst miValueConst5("0");
487   const CMICmnMIValueResult miValueResult5("has_more", miValueConst5);
488   miValueTuple.Add(miValueResult5);
489   m_miValueList.Add(miValueTuple);
490 }
491
492 //++
493 //------------------------------------------------------------------------------------
494 // Details: Determine if the var object was changed.
495 // Type:    Method.
496 // Args:    vrVarObj    - (R)   Session var object to examine.
497 //          vrwbChanged - (W)   True = The var object was changed,
498 //                              False = It was not changed.
499 // Return:  MIstatus::success - Functional succeeded.
500 //          MIstatus::failure - Functional failed.
501 // Throws:  None.
502 //--
503 bool CMICmdCmdVarUpdate::ExamineSBValueForChange(lldb::SBValue &vrwValue,
504                                                  bool &vrwbChanged) {
505   if (vrwValue.GetValueDidChange()) {
506     vrwbChanged = true;
507     return MIstatus::success;
508   }
509
510   lldb::SBType valueType = vrwValue.GetType();
511   if (!valueType.IsPointerType() && !valueType.IsReferenceType()) {
512     const MIuint nChildren = vrwValue.GetNumChildren();
513     for (MIuint i = 0; i < nChildren; ++i) {
514       lldb::SBValue member = vrwValue.GetChildAtIndex(i);
515       if (!member.IsValid())
516         continue;
517
518       if (member.GetValueDidChange()) {
519         vrwbChanged = true;
520         return MIstatus::success;
521       } else if (ExamineSBValueForChange(member, vrwbChanged) && vrwbChanged)
522         // Handle composite types (i.e. struct or arrays)
523         return MIstatus::success;
524     }
525   }
526
527   vrwbChanged = false;
528   return MIstatus::success;
529 }
530
531 //---------------------------------------------------------------------------------------
532 //---------------------------------------------------------------------------------------
533 //---------------------------------------------------------------------------------------
534
535 //++
536 //------------------------------------------------------------------------------------
537 // Details: CMICmdCmdVarDelete constructor.
538 // Type:    Method.
539 // Args:    None.
540 // Return:  None.
541 // Throws:  None.
542 //--
543 CMICmdCmdVarDelete::CMICmdCmdVarDelete() : m_constStrArgName("name") {
544   // Command factory matches this name with that received from the stdin stream
545   m_strMiCmd = "var-delete";
546
547   // Required by the CMICmdFactory when registering *this command
548   m_pSelfCreatorFn = &CMICmdCmdVarDelete::CreateSelf;
549 }
550
551 //++
552 //------------------------------------------------------------------------------------
553 // Details: The invoker requires this function. The parses the command line
554 // options
555 //          arguments to extract values for each of those arguments.
556 // Type:    Overridden.
557 // Args:    None.
558 // Return:  MIstatus::success - Functional succeeded.
559 //          MIstatus::failure - Functional failed.
560 // Throws:  None.
561 //--
562 bool CMICmdCmdVarDelete::ParseArgs() {
563   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
564   return ParseValidateCmdOptions();
565 }
566
567 //++
568 //------------------------------------------------------------------------------------
569 // Details: CMICmdCmdVarDelete destructor.
570 // Type:    Overrideable.
571 // Args:    None.
572 // Return:  None.
573 // Throws:  None.
574 //--
575 CMICmdCmdVarDelete::~CMICmdCmdVarDelete() {}
576
577 //++
578 //------------------------------------------------------------------------------------
579 // Details: The invoker requires this function. The command does work in this
580 // function.
581 //          The command is likely to communicate with the LLDB SBDebugger in
582 //          here.
583 // Type:    Overridden.
584 // Args:    None.
585 // Return:  MIstatus::success - Functional succeeded.
586 //          MIstatus::failure - Functional failed.
587 // Throws:  None.
588 //--
589 bool CMICmdCmdVarDelete::Execute() {
590   CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
591
592   const CMIUtilString &rVarObjName(pArgName->GetValue());
593   CMICmnLLDBDebugSessionInfoVarObj::VarObjDelete(rVarObjName);
594
595   return MIstatus::success;
596 }
597
598 //++
599 //------------------------------------------------------------------------------------
600 // Details: The invoker requires this function. The command prepares a MI Record
601 // Result
602 //          for the work carried out in the Execute().
603 // Type:    Overridden.
604 // Args:    None.
605 // Return:  MIstatus::success - Functional succeeded.
606 //          MIstatus::failure - Functional failed.
607 // Throws:  None.
608 //--
609 bool CMICmdCmdVarDelete::Acknowledge() {
610   const CMICmnMIResultRecord miRecordResult(
611       m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done);
612   m_miResultRecord = miRecordResult;
613
614   return MIstatus::success;
615 }
616
617 //++
618 //------------------------------------------------------------------------------------
619 // Details: Required by the CMICmdFactory when registering *this command. The
620 // factory
621 //          calls this function to create an instance of *this command.
622 // Type:    Static method.
623 // Args:    None.
624 // Return:  CMICmdBase * - Pointer to a new command.
625 // Throws:  None.
626 //--
627 CMICmdBase *CMICmdCmdVarDelete::CreateSelf() {
628   return new CMICmdCmdVarDelete();
629 }
630
631 //---------------------------------------------------------------------------------------
632 //---------------------------------------------------------------------------------------
633 //---------------------------------------------------------------------------------------
634
635 //++
636 //------------------------------------------------------------------------------------
637 // Details: CMICmdCmdVarAssign constructor.
638 // Type:    Method.
639 // Args:    None.
640 // Return:  None.
641 // Throws:  None.
642 //--
643 CMICmdCmdVarAssign::CMICmdCmdVarAssign()
644     : m_bOk(true), m_constStrArgName("name"),
645       m_constStrArgExpression("expression") {
646   // Command factory matches this name with that received from the stdin stream
647   m_strMiCmd = "var-assign";
648
649   // Required by the CMICmdFactory when registering *this command
650   m_pSelfCreatorFn = &CMICmdCmdVarAssign::CreateSelf;
651 }
652
653 //++
654 //------------------------------------------------------------------------------------
655 // Details: CMICmdCmdVarAssign destructor.
656 // Type:    Overrideable.
657 // Args:    None.
658 // Return:  None.
659 // Throws:  None.
660 //--
661 CMICmdCmdVarAssign::~CMICmdCmdVarAssign() {}
662
663 //++
664 //------------------------------------------------------------------------------------
665 // Details: The invoker requires this function. The parses the command line
666 // options
667 //          arguments to extract values for each of those arguments.
668 // Type:    Overridden.
669 // Args:    None.
670 // Return:  MIstatus::success - Functional succeeded.
671 //          MIstatus::failure - Functional failed.
672 // Throws:  None.
673 //--
674 bool CMICmdCmdVarAssign::ParseArgs() {
675   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
676   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgExpression, true, true));
677   return ParseValidateCmdOptions();
678 }
679
680 //++
681 //------------------------------------------------------------------------------------
682 // Details: The invoker requires this function. The command does work in this
683 // function.
684 //          The command is likely to communicate with the LLDB SBDebugger in
685 //          here.
686 // Type:    Overridden.
687 // Args:    None.
688 // Return:  MIstatus::success - Functional succeeded.
689 //          MIstatus::failure - Functional failed.
690 // Throws:  None.
691 //--
692 bool CMICmdCmdVarAssign::Execute() {
693   CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
694   CMICMDBASE_GETOPTION(pArgExpression, String, m_constStrArgExpression);
695
696   const CMIUtilString &rVarObjName(pArgName->GetValue());
697   const CMIUtilString &rExpression(pArgExpression->GetValue());
698
699   CMICmnLLDBDebugSessionInfoVarObj varObj;
700   if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj)) {
701     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST),
702                                    m_cmdData.strMiCmd.c_str(),
703                                    rVarObjName.c_str()));
704     return MIstatus::failure;
705   }
706   m_varObjName = rVarObjName;
707
708   CMIUtilString strExpression(rExpression.Trim());
709   strExpression = strExpression.Trim('"');
710   lldb::SBValue &rValue(const_cast<lldb::SBValue &>(varObj.GetValue()));
711   m_bOk = rValue.SetValueFromCString(strExpression.c_str());
712   if (m_bOk)
713     varObj.UpdateValue();
714
715   return MIstatus::success;
716 }
717
718 //++
719 //------------------------------------------------------------------------------------
720 // Details: The invoker requires this function. The command prepares a MI Record
721 // Result
722 //          for the work carried out in the Execute().
723 // Type:    Overridden.
724 // Args:    None.
725 // Return:  MIstatus::success - Functional succeeded.
726 //          MIstatus::failure - Functional failed.
727 // Throws:  None.
728 //--
729 bool CMICmdCmdVarAssign::Acknowledge() {
730   if (m_bOk) {
731     // MI print "%s^done,value=\"%s\""
732     CMICmnLLDBDebugSessionInfoVarObj varObj;
733     CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(m_varObjName, varObj);
734     const CMICmnMIValueConst miValueConst(varObj.GetValueFormatted());
735     const CMICmnMIValueResult miValueResult("value", miValueConst);
736     const CMICmnMIResultRecord miRecordResult(
737         m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done,
738         miValueResult);
739     m_miResultRecord = miRecordResult;
740
741     return MIstatus::success;
742   }
743
744   const CMICmnMIValueConst miValueConst("expression could not be evaluated");
745   const CMICmnMIValueResult miValueResult("msg", miValueConst);
746   const CMICmnMIResultRecord miRecordResult(
747       m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
748       miValueResult);
749   m_miResultRecord = miRecordResult;
750
751   return MIstatus::success;
752 }
753
754 //++
755 //------------------------------------------------------------------------------------
756 // Details: Required by the CMICmdFactory when registering *this command. The
757 // factory
758 //          calls this function to create an instance of *this command.
759 // Type:    Static method.
760 // Args:    None.
761 // Return:  CMICmdBase * - Pointer to a new command.
762 // Throws:  None.
763 //--
764 CMICmdBase *CMICmdCmdVarAssign::CreateSelf() {
765   return new CMICmdCmdVarAssign();
766 }
767
768 //---------------------------------------------------------------------------------------
769 //---------------------------------------------------------------------------------------
770 //---------------------------------------------------------------------------------------
771
772 //++
773 //------------------------------------------------------------------------------------
774 // Details: CMICmdCmdVarSetFormat constructor.
775 // Type:    Method.
776 // Args:    None.
777 // Return:  None.
778 // Throws:  None.
779 //--
780 CMICmdCmdVarSetFormat::CMICmdCmdVarSetFormat()
781     : m_constStrArgName("name"), m_constStrArgFormatSpec("format-spec") {
782   // Command factory matches this name with that received from the stdin stream
783   m_strMiCmd = "var-set-format";
784
785   // Required by the CMICmdFactory when registering *this command
786   m_pSelfCreatorFn = &CMICmdCmdVarSetFormat::CreateSelf;
787 }
788
789 //++
790 //------------------------------------------------------------------------------------
791 // Details: CMICmdCmdVarSetFormat destructor.
792 // Type:    Overrideable.
793 // Args:    None.
794 // Return:  None.
795 // Throws:  None.
796 //--
797 CMICmdCmdVarSetFormat::~CMICmdCmdVarSetFormat() {}
798
799 //++
800 //------------------------------------------------------------------------------------
801 // Details: The invoker requires this function. The parses the command line
802 // options
803 //          arguments to extract values for each of those arguments.
804 // Type:    Overridden.
805 // Args:    None.
806 // Return:  MIstatus::success - Functional succeeded.
807 //          MIstatus::failure - Functional failed.
808 // Throws:  None.
809 //--
810 bool CMICmdCmdVarSetFormat::ParseArgs() {
811   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
812   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgFormatSpec, true, true));
813   return ParseValidateCmdOptions();
814 }
815
816 //++
817 //------------------------------------------------------------------------------------
818 // Details: The invoker requires this function. The command does work in this
819 // function.
820 //          The command is likely to communicate with the LLDB SBDebugger in
821 //          here.
822 // Type:    Overridden.
823 // Args:    None.
824 // Return:  MIstatus::success - Functional succeeded.
825 //          MIstatus::failure - Functional failed.
826 // Throws:  None.
827 //--
828 bool CMICmdCmdVarSetFormat::Execute() {
829   CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
830   CMICMDBASE_GETOPTION(pArgFormatSpec, String, m_constStrArgFormatSpec);
831
832   const CMIUtilString &rVarObjName(pArgName->GetValue());
833   const CMIUtilString &rExpression(pArgFormatSpec->GetValue());
834
835   CMICmnLLDBDebugSessionInfoVarObj varObj;
836   if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj)) {
837     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST),
838                                    m_cmdData.strMiCmd.c_str(),
839                                    rVarObjName.c_str()));
840     return MIstatus::failure;
841   }
842   if (!varObj.SetVarFormat(
843           CMICmnLLDBDebugSessionInfoVarObj::GetVarFormatForString(
844               rExpression))) {
845     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_ENUM_INVALID),
846                                    m_cmdData.strMiCmd.c_str(),
847                                    rVarObjName.c_str(), rExpression.c_str()));
848     return MIstatus::failure;
849   }
850   varObj.UpdateValue();
851
852   m_varObjName = rVarObjName;
853
854   return MIstatus::success;
855 }
856
857 //++
858 //------------------------------------------------------------------------------------
859 // Details: The invoker requires this function. The command prepares a MI Record
860 // Result
861 //          for the work carried out in the Execute().
862 // Type:    Overridden.
863 // Args:    None.
864 // Return:  MIstatus::success - Functional succeeded.
865 //          MIstatus::failure - Functional failed.
866 // Throws:  None.
867 //--
868 bool CMICmdCmdVarSetFormat::Acknowledge() {
869   // MI print
870   // "%s^done,changelist=[{name=\"%s\",value=\"%s\",in_scope=\"%s\",type_changed=\"false\",has_more=\"0\"}]"
871   CMICmnLLDBDebugSessionInfoVarObj varObj;
872   CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(m_varObjName, varObj);
873   const CMICmnMIValueConst miValueConst(m_varObjName);
874   const CMICmnMIValueResult miValueResult("name", miValueConst);
875   CMICmnMIValueTuple miValueTuple(miValueResult);
876   const CMICmnMIValueConst miValueConst2(varObj.GetValueFormatted());
877   const CMICmnMIValueResult miValueResult2("value", miValueConst2);
878   miValueTuple.Add(miValueResult2);
879   lldb::SBValue &rValue = const_cast<lldb::SBValue &>(varObj.GetValue());
880   const CMICmnMIValueConst miValueConst3(rValue.IsInScope() ? "true" : "false");
881   const CMICmnMIValueResult miValueResult3("in_scope", miValueConst3);
882   miValueTuple.Add(miValueResult3);
883   const CMICmnMIValueConst miValueConst4("false");
884   const CMICmnMIValueResult miValueResult4("type_changed", miValueConst4);
885   miValueTuple.Add(miValueResult4);
886   const CMICmnMIValueConst miValueConst5("0");
887   const CMICmnMIValueResult miValueResult5("type_changed", miValueConst5);
888   miValueTuple.Add(miValueResult5);
889   const CMICmnMIValueList miValueList(miValueTuple);
890   const CMICmnMIValueResult miValueResult6("changelist", miValueList);
891
892   const CMICmnMIResultRecord miRecordResult(
893       m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done,
894       miValueResult6);
895   m_miResultRecord = miRecordResult;
896
897   return MIstatus::success;
898 }
899
900 //++
901 //------------------------------------------------------------------------------------
902 // Details: Required by the CMICmdFactory when registering *this command. The
903 // factory
904 //          calls this function to create an instance of *this command.
905 // Type:    Static method.
906 // Args:    None.
907 // Return:  CMICmdBase * - Pointer to a new command.
908 // Throws:  None.
909 //--
910 CMICmdBase *CMICmdCmdVarSetFormat::CreateSelf() {
911   return new CMICmdCmdVarSetFormat();
912 }
913
914 //---------------------------------------------------------------------------------------
915 //---------------------------------------------------------------------------------------
916 //---------------------------------------------------------------------------------------
917
918 //++
919 //------------------------------------------------------------------------------------
920 // Details: CMICmdCmdVarListChildren constructor.
921 // Type:    Method.
922 // Args:    None.
923 // Return:  None.
924 // Throws:  None.
925 //--
926 CMICmdCmdVarListChildren::CMICmdCmdVarListChildren()
927     : m_constStrArgPrintValues("print-values"), m_constStrArgName("name"),
928       m_constStrArgFrom("from"), m_constStrArgTo("to"), m_bValueValid(false),
929       m_nChildren(0), m_miValueList(true), m_bHasMore(false) {
930   // Command factory matches this name with that received from the stdin stream
931   m_strMiCmd = "var-list-children";
932
933   // Required by the CMICmdFactory when registering *this command
934   m_pSelfCreatorFn = &CMICmdCmdVarListChildren::CreateSelf;
935 }
936
937 //++
938 //------------------------------------------------------------------------------------
939 // Details: CMICmdCmdVarListChildren destructor.
940 // Type:    Overrideable.
941 // Args:    None.
942 // Return:  None.
943 // Throws:  None.
944 //--
945 CMICmdCmdVarListChildren::~CMICmdCmdVarListChildren() {}
946
947 //++
948 //------------------------------------------------------------------------------------
949 // Details: The invoker requires this function. The parses the command line
950 // options
951 //          arguments to extract values for each of those arguments.
952 // Type:    Overridden.
953 // Args:    None.
954 // Return:  MIstatus::success - Functional succeeded.
955 //          MIstatus::failure - Functional failed.
956 // Throws:  None.
957 //--
958 bool CMICmdCmdVarListChildren::ParseArgs() {
959   m_setCmdArgs.Add(
960       new CMICmdArgValPrintValues(m_constStrArgPrintValues, false, true));
961   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true, true));
962   m_setCmdArgs.Add(new CMICmdArgValNumber(m_constStrArgFrom, false, true));
963   m_setCmdArgs.Add(new CMICmdArgValNumber(m_constStrArgTo, false, true));
964   return ParseValidateCmdOptions();
965 }
966
967 //++
968 //------------------------------------------------------------------------------------
969 // Details: The invoker requires this function. The command does work in this
970 // function.
971 //          The command is likely to communicate with the LLDB SBDebugger in
972 //          here.
973 // Type:    Overridden.
974 // Args:    None.
975 // Return:  MIstatus::success - Functional succeeded.
976 //          MIstatus::failure - Functional failed.
977 // Throws:  None.
978 //--
979 bool CMICmdCmdVarListChildren::Execute() {
980   CMICMDBASE_GETOPTION(pArgPrintValues, PrintValues, m_constStrArgPrintValues);
981   CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
982   CMICMDBASE_GETOPTION(pArgFrom, Number, m_constStrArgFrom);
983   CMICMDBASE_GETOPTION(pArgTo, Number, m_constStrArgTo);
984
985   CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e eVarInfoFormat =
986       CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_NoValues;
987   if (pArgPrintValues->GetFound())
988     eVarInfoFormat =
989         static_cast<CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e>(
990             pArgPrintValues->GetValue());
991
992   const CMIUtilString &rVarObjName(pArgName->GetValue());
993   CMICmnLLDBDebugSessionInfoVarObj varObj;
994   if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj)) {
995     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST),
996                                    m_cmdData.strMiCmd.c_str(),
997                                    rVarObjName.c_str()));
998     return MIstatus::failure;
999   }
1000
1001   MIuint nFrom = 0;
1002   MIuint nTo = UINT32_MAX;
1003   if (pArgFrom->GetFound() && pArgTo->GetFound()) {
1004     nFrom = pArgFrom->GetValue();
1005     nTo = pArgTo->GetValue();
1006   } else if (pArgFrom->GetFound() || pArgTo->GetFound()) {
1007     // Only from or to was specified but both are required
1008     SetError(
1009         CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_CHILD_RANGE_INVALID),
1010                               m_cmdData.strMiCmd.c_str()));
1011     return MIstatus::failure;
1012   }
1013
1014   lldb::SBValue &rValue = const_cast<lldb::SBValue &>(varObj.GetValue());
1015   m_bValueValid = rValue.IsValid();
1016   if (!m_bValueValid)
1017     return MIstatus::success;
1018
1019   const MIuint nChildren = rValue.GetNumChildren();
1020   m_bHasMore = nTo < nChildren;
1021   nTo = std::min(nTo, nChildren);
1022   m_nChildren = nFrom < nTo ? nTo - nFrom : 0;
1023   for (MIuint i = nFrom; i < nTo; i++) {
1024     lldb::SBValue member = rValue.GetChildAtIndex(i);
1025     const CMICmnLLDBUtilSBValue utilValue(member);
1026     const CMIUtilString strExp = utilValue.GetName();
1027     const CMIUtilString name(
1028         strExp.empty() ? CMIUtilString::Format("%s.$%u", rVarObjName.c_str(), i)
1029                        : CMIUtilString::Format("%s.%s", rVarObjName.c_str(),
1030                                                strExp.c_str()));
1031     const MIuint nChildren = member.GetNumChildren();
1032     const CMIUtilString strThreadId(
1033         CMIUtilString::Format("%u", member.GetThread().GetIndexID()));
1034
1035     // Varobj gets added to CMICmnLLDBDebugSessionInfoVarObj static container of
1036     // varObjs
1037     CMICmnLLDBDebugSessionInfoVarObj var(strExp, name, member, rVarObjName);
1038
1039     // MI print
1040     // "child={name=\"%s\",exp=\"%s\",numchild=\"%d\",value=\"%s\",type=\"%s\",thread-id=\"%u\",has_more=\"%u\"}"
1041     const CMICmnMIValueConst miValueConst(name);
1042     const CMICmnMIValueResult miValueResult("name", miValueConst);
1043     CMICmnMIValueTuple miValueTuple(miValueResult);
1044     const CMICmnMIValueConst miValueConst2(strExp);
1045     const CMICmnMIValueResult miValueResult2("exp", miValueConst2);
1046     miValueTuple.Add(miValueResult2);
1047     const CMIUtilString strNumChild(CMIUtilString::Format("%u", nChildren));
1048     const CMICmnMIValueConst miValueConst3(strNumChild);
1049     const CMICmnMIValueResult miValueResult3("numchild", miValueConst3);
1050     miValueTuple.Add(miValueResult3);
1051     const CMICmnMIValueConst miValueConst5(utilValue.GetTypeNameDisplay());
1052     const CMICmnMIValueResult miValueResult5("type", miValueConst5);
1053     miValueTuple.Add(miValueResult5);
1054     const CMICmnMIValueConst miValueConst6(strThreadId);
1055     const CMICmnMIValueResult miValueResult6("thread-id", miValueConst6);
1056     miValueTuple.Add(miValueResult6);
1057     // nChildren == 0 is used to check for simple values
1058     if (eVarInfoFormat ==
1059             CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_AllValues ||
1060         (eVarInfoFormat ==
1061              CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_SimpleValues &&
1062          nChildren == 0)) {
1063       const CMIUtilString strValue(
1064           CMICmnLLDBDebugSessionInfoVarObj::GetValueStringFormatted(
1065               member, CMICmnLLDBDebugSessionInfoVarObj::eVarFormat_Natural));
1066       const CMICmnMIValueConst miValueConst7(strValue);
1067       const CMICmnMIValueResult miValueResult7("value", miValueConst7);
1068       miValueTuple.Add(miValueResult7);
1069     }
1070     const CMICmnMIValueConst miValueConst8("0");
1071     const CMICmnMIValueResult miValueResult8("has_more", miValueConst8);
1072     miValueTuple.Add(miValueResult8);
1073     const CMICmnMIValueResult miValueResult9("child", miValueTuple);
1074     m_miValueList.Add(miValueResult9);
1075   }
1076
1077   return MIstatus::success;
1078 }
1079
1080 //++
1081 //------------------------------------------------------------------------------------
1082 // Details: The invoker requires this function. The command prepares a MI Record
1083 // Result
1084 //          for the work carried out in the Execute().
1085 // Type:    Overridden.
1086 // Args:    None.
1087 // Return:  MIstatus::success - Functional succeeded.
1088 //          MIstatus::failure - Functional failed.
1089 // Throws:  None.
1090 //--
1091 bool CMICmdCmdVarListChildren::Acknowledge() {
1092   if (m_bValueValid) {
1093     // MI print "%s^done,numchild=\"%u\",children=[%s],has_more=\"%d\""
1094     const CMIUtilString strNumChild(CMIUtilString::Format("%u", m_nChildren));
1095     const CMICmnMIValueConst miValueConst(strNumChild);
1096     CMICmnMIValueResult miValueResult("numchild", miValueConst);
1097     if (m_nChildren != 0)
1098       miValueResult.Add("children", m_miValueList);
1099     const CMIUtilString strHasMore(m_bHasMore ? "1" : "0");
1100     const CMICmnMIValueConst miValueConst2(strHasMore);
1101     miValueResult.Add("has_more", miValueConst2);
1102
1103     const CMICmnMIResultRecord miRecordResult(
1104         m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done,
1105         miValueResult);
1106     m_miResultRecord = miRecordResult;
1107
1108     return MIstatus::success;
1109   }
1110
1111   // MI print "%s^error,msg=\"variable invalid\""
1112   const CMICmnMIValueConst miValueConst("variable invalid");
1113   const CMICmnMIValueResult miValueResult("msg", miValueConst);
1114   const CMICmnMIResultRecord miRecordResult(
1115       m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
1116       miValueResult);
1117   m_miResultRecord = miRecordResult;
1118
1119   return MIstatus::success;
1120 }
1121
1122 //++
1123 //------------------------------------------------------------------------------------
1124 // Details: Required by the CMICmdFactory when registering *this command. The
1125 // factory
1126 //          calls this function to create an instance of *this command.
1127 // Type:    Static method.
1128 // Args:    None.
1129 // Return:  CMICmdBase * - Pointer to a new command.
1130 // Throws:  None.
1131 //--
1132 CMICmdBase *CMICmdCmdVarListChildren::CreateSelf() {
1133   return new CMICmdCmdVarListChildren();
1134 }
1135
1136 //---------------------------------------------------------------------------------------
1137 //---------------------------------------------------------------------------------------
1138 //---------------------------------------------------------------------------------------
1139
1140 //++
1141 //------------------------------------------------------------------------------------
1142 // Details: CMICmdCmdVarEvaluateExpression constructor.
1143 // Type:    Method.
1144 // Args:    None.
1145 // Return:  None.
1146 // Throws:  None.
1147 //--
1148 CMICmdCmdVarEvaluateExpression::CMICmdCmdVarEvaluateExpression()
1149     : m_bValueValid(true), m_constStrArgFormatSpec("-f"),
1150       m_constStrArgName("name") {
1151   // Command factory matches this name with that received from the stdin stream
1152   m_strMiCmd = "var-evaluate-expression";
1153
1154   // Required by the CMICmdFactory when registering *this command
1155   m_pSelfCreatorFn = &CMICmdCmdVarEvaluateExpression::CreateSelf;
1156 }
1157
1158 //++
1159 //------------------------------------------------------------------------------------
1160 // Details: CMICmdCmdVarEvaluateExpression destructor.
1161 // Type:    Overrideable.
1162 // Args:    None.
1163 // Return:  None.
1164 // Throws:  None.
1165 //--
1166 CMICmdCmdVarEvaluateExpression::~CMICmdCmdVarEvaluateExpression() {}
1167
1168 //++
1169 //------------------------------------------------------------------------------------
1170 // Details: The invoker requires this function. The parses the command line
1171 // options
1172 //          arguments to extract values for each of those arguments.
1173 // Type:    Overridden.
1174 // Args:    None.
1175 // Return:  MIstatus::success - Functional succeeded.
1176 //          MIstatus::failure - Functional failed.
1177 // Throws:  None.
1178 //--
1179 bool CMICmdCmdVarEvaluateExpression::ParseArgs() {
1180   m_setCmdArgs.Add(
1181       new CMICmdArgValOptionShort(m_constStrArgFormatSpec, false, false,
1182                                   CMICmdArgValListBase::eArgValType_String, 1));
1183   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
1184   return ParseValidateCmdOptions();
1185 }
1186
1187 //++
1188 //------------------------------------------------------------------------------------
1189 // Details: The invoker requires this function. The command does work in this
1190 // function.
1191 //          The command is likely to communicate with the LLDB SBDebugger in
1192 //          here.
1193 // Type:    Overridden.
1194 // Args:    None.
1195 // Return:  MIstatus::success - Functional succeeded.
1196 //          MIstatus::failure - Functional failed.
1197 // Throws:  None.
1198 //--
1199 bool CMICmdCmdVarEvaluateExpression::Execute() {
1200   CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
1201
1202   const CMIUtilString &rVarObjName(pArgName->GetValue());
1203   CMICmnLLDBDebugSessionInfoVarObj varObj;
1204   if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj)) {
1205     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST),
1206                                    m_cmdData.strMiCmd.c_str(),
1207                                    rVarObjName.c_str()));
1208     return MIstatus::failure;
1209   }
1210
1211   lldb::SBValue &rValue = const_cast<lldb::SBValue &>(varObj.GetValue());
1212   m_bValueValid = rValue.IsValid();
1213   if (!m_bValueValid)
1214     return MIstatus::success;
1215
1216   m_varObjName = rVarObjName;
1217   varObj.UpdateValue();
1218
1219   return MIstatus::success;
1220 }
1221
1222 //++
1223 //------------------------------------------------------------------------------------
1224 // Details: The invoker requires this function. The command prepares a MI Record
1225 // Result
1226 //          for the work carried out in the Execute().
1227 // Type:    Overridden.
1228 // Args:    None.
1229 // Return:  MIstatus::success - Functional succeeded.
1230 //          MIstatus::failure - Functional failed.
1231 // Throws:  None.
1232 //--
1233 bool CMICmdCmdVarEvaluateExpression::Acknowledge() {
1234   if (m_bValueValid) {
1235     CMICmnLLDBDebugSessionInfoVarObj varObj;
1236     CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(m_varObjName, varObj);
1237     const CMICmnMIValueConst miValueConst(varObj.GetValueFormatted());
1238     const CMICmnMIValueResult miValueResult("value", miValueConst);
1239     const CMICmnMIResultRecord miRecordResult(
1240         m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done,
1241         miValueResult);
1242     m_miResultRecord = miRecordResult;
1243     return MIstatus::success;
1244   }
1245
1246   const CMICmnMIValueConst miValueConst("variable invalid");
1247   const CMICmnMIValueResult miValueResult("msg", miValueConst);
1248   const CMICmnMIResultRecord miRecordResult(
1249       m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
1250       miValueResult);
1251   m_miResultRecord = miRecordResult;
1252   return MIstatus::success;
1253 }
1254
1255 //++
1256 //------------------------------------------------------------------------------------
1257 // Details: Required by the CMICmdFactory when registering *this command. The
1258 // factory
1259 //          calls this function to create an instance of *this command.
1260 // Type:    Static method.
1261 // Args:    None.
1262 // Return:  CMICmdBase * - Pointer to a new command.
1263 // Throws:  None.
1264 //--
1265 CMICmdBase *CMICmdCmdVarEvaluateExpression::CreateSelf() {
1266   return new CMICmdCmdVarEvaluateExpression();
1267 }
1268
1269 //---------------------------------------------------------------------------------------
1270 //---------------------------------------------------------------------------------------
1271 //---------------------------------------------------------------------------------------
1272
1273 //++
1274 //------------------------------------------------------------------------------------
1275 // Details: CMICmdCmdVarInfoPathExpression constructor.
1276 // Type:    Method.
1277 // Args:    None.
1278 // Return:  None.
1279 // Throws:  None.
1280 //--
1281 CMICmdCmdVarInfoPathExpression::CMICmdCmdVarInfoPathExpression()
1282     : m_bValueValid(true), m_constStrArgName("name") {
1283   // Command factory matches this name with that received from the stdin stream
1284   m_strMiCmd = "var-info-path-expression";
1285
1286   // Required by the CMICmdFactory when registering *this command
1287   m_pSelfCreatorFn = &CMICmdCmdVarInfoPathExpression::CreateSelf;
1288 }
1289
1290 //++
1291 //------------------------------------------------------------------------------------
1292 // Details: CMICmdCmdVarInfoPathExpression destructor.
1293 // Type:    Overrideable.
1294 // Args:    None.
1295 // Return:  None.
1296 // Throws:  None.
1297 //--
1298 CMICmdCmdVarInfoPathExpression::~CMICmdCmdVarInfoPathExpression() {}
1299
1300 //++
1301 //------------------------------------------------------------------------------------
1302 // Details: The invoker requires this function. The parses the command line
1303 // options
1304 //          arguments to extract values for each of those arguments.
1305 // Type:    Overridden.
1306 // Args:    None.
1307 // Return:  MIstatus::success - Functional succeeded.
1308 //          MIstatus::failure - Functional failed.
1309 // Throws:  None.
1310 //--
1311 bool CMICmdCmdVarInfoPathExpression::ParseArgs() {
1312   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
1313   return ParseValidateCmdOptions();
1314 }
1315
1316 //++
1317 //------------------------------------------------------------------------------------
1318 // Details: The invoker requires this function. The command does work in this
1319 // function.
1320 //          The command is likely to communicate with the LLDB SBDebugger in
1321 //          here.
1322 // Type:    Overridden.
1323 // Args:    None.
1324 // Return:  MIstatus::success - Functional succeeded.
1325 //          MIstatus::failure - Functional failed.
1326 // Throws:  None.
1327 //--
1328 bool CMICmdCmdVarInfoPathExpression::Execute() {
1329   CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
1330
1331   const CMIUtilString &rVarObjName(pArgName->GetValue());
1332   CMICmnLLDBDebugSessionInfoVarObj varObj;
1333   if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj)) {
1334     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST),
1335                                    m_cmdData.strMiCmd.c_str(),
1336                                    rVarObjName.c_str()));
1337     return MIstatus::failure;
1338   }
1339
1340   lldb::SBValue &rValue = const_cast<lldb::SBValue &>(varObj.GetValue());
1341   m_bValueValid = rValue.IsValid();
1342   if (!m_bValueValid)
1343     return MIstatus::success;
1344
1345   lldb::SBStream stream;
1346   if (!rValue.GetExpressionPath(stream, true)) {
1347     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_EXPRESSIONPATH),
1348                                    m_cmdData.strMiCmd.c_str(),
1349                                    rVarObjName.c_str()));
1350     return MIstatus::failure;
1351   }
1352
1353   const char *pPathExpression = stream.GetData();
1354   if (pPathExpression == nullptr) {
1355     // Build expression from what we do know
1356     m_strPathExpression = varObj.GetNameReal();
1357     return MIstatus::success;
1358   }
1359
1360   // Has LLDB returned a var signature of it's own
1361   if (pPathExpression[0] != '$') {
1362     m_strPathExpression = pPathExpression;
1363     return MIstatus::success;
1364   }
1365
1366   // Build expression from what we do know
1367   const CMIUtilString &rVarParentName(varObj.GetVarParentName());
1368   if (rVarParentName.empty()) {
1369     m_strPathExpression = varObj.GetNameReal();
1370   } else {
1371     CMICmnLLDBDebugSessionInfoVarObj varObjParent;
1372     if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarParentName,
1373                                                      varObjParent)) {
1374       SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST),
1375                                      m_cmdData.strMiCmd.c_str(),
1376                                      rVarParentName.c_str()));
1377       return MIstatus::failure;
1378     }
1379     m_strPathExpression =
1380         CMIUtilString::Format("%s.%s", varObjParent.GetNameReal().c_str(),
1381                               varObj.GetNameReal().c_str());
1382   }
1383
1384   return MIstatus::success;
1385 }
1386
1387 //++
1388 //------------------------------------------------------------------------------------
1389 // Details: The invoker requires this function. The command prepares a MI Record
1390 // Result
1391 //          for the work carried out in the Execute().
1392 // Type:    Overridden.
1393 // Args:    None.
1394 // Return:  MIstatus::success - Functional succeeded.
1395 //          MIstatus::failure - Functional failed.
1396 // Throws:  None.
1397 //--
1398 bool CMICmdCmdVarInfoPathExpression::Acknowledge() {
1399   if (m_bValueValid) {
1400     const CMICmnMIValueConst miValueConst(m_strPathExpression);
1401     const CMICmnMIValueResult miValueResult("path_expr", miValueConst);
1402     const CMICmnMIResultRecord miRecordResult(
1403         m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done,
1404         miValueResult);
1405     m_miResultRecord = miRecordResult;
1406     return MIstatus::success;
1407   }
1408
1409   const CMICmnMIValueConst miValueConst("variable invalid");
1410   const CMICmnMIValueResult miValueResult("msg", miValueConst);
1411   const CMICmnMIResultRecord miRecordResult(
1412       m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
1413       miValueResult);
1414   m_miResultRecord = miRecordResult;
1415
1416   return MIstatus::success;
1417 }
1418
1419 //++
1420 //------------------------------------------------------------------------------------
1421 // Details: Required by the CMICmdFactory when registering *this command. The
1422 // factory
1423 //          calls this function to create an instance of *this command.
1424 // Type:    Static method.
1425 // Args:    None.
1426 // Return:  CMICmdBase * - Pointer to a new command.
1427 // Throws:  None.
1428 //--
1429 CMICmdBase *CMICmdCmdVarInfoPathExpression::CreateSelf() {
1430   return new CMICmdCmdVarInfoPathExpression();
1431 }
1432
1433 //---------------------------------------------------------------------------------------
1434 //---------------------------------------------------------------------------------------
1435 //---------------------------------------------------------------------------------------
1436
1437 //++
1438 //------------------------------------------------------------------------------------
1439 // Details: CMICmdCmdVarShowAttributes constructor.
1440 // Type:    Method.
1441 // Args:    None.
1442 // Return:  None.
1443 // Throws:  None.
1444 //--
1445 CMICmdCmdVarShowAttributes::CMICmdCmdVarShowAttributes()
1446     : m_constStrArgName("name") {
1447   // Command factory matches this name with that received from the stdin stream
1448   m_strMiCmd = "var-show-attributes";
1449
1450   // Required by the CMICmdFactory when registering *this command
1451   m_pSelfCreatorFn = &CMICmdCmdVarShowAttributes::CreateSelf;
1452 }
1453
1454 //++
1455 //------------------------------------------------------------------------------------
1456 // Details: CMICmdCmdVarShowAttributes destructor.
1457 // Type:    Overrideable.
1458 // Args:    None.
1459 // Return:  None.
1460 // Throws:  None.
1461 //--
1462 CMICmdCmdVarShowAttributes::~CMICmdCmdVarShowAttributes() {}
1463
1464 //++
1465 //------------------------------------------------------------------------------------
1466 // Details: The invoker requires this function. The parses the command line
1467 // options
1468 //          arguments to extract values for each of those arguments.
1469 // Type:    Overridden.
1470 // Args:    None.
1471 // Return:  MIstatus::success - Functional succeeded.
1472 //          MIstatus::failure - Functional failed.
1473 // Throws:  None.
1474 //--
1475 bool CMICmdCmdVarShowAttributes::ParseArgs() {
1476   m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
1477   return ParseValidateCmdOptions();
1478 }
1479
1480 //++
1481 //------------------------------------------------------------------------------------
1482 // Details: The invoker requires this function. The command does work in this
1483 // function.
1484 //          The command is likely to communicate with the LLDB SBDebugger in
1485 //          here.
1486 // Type:    Overridden.
1487 // Args:    None.
1488 // Return:  MIstatus::success - Functional succeeded.
1489 //          MIstatus::failure - Functional failed.
1490 // Throws:  None.
1491 //--
1492 bool CMICmdCmdVarShowAttributes::Execute() {
1493   CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
1494
1495   const CMIUtilString &rVarObjName(pArgName->GetValue());
1496   CMICmnLLDBDebugSessionInfoVarObj varObj;
1497   if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj)) {
1498     SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST),
1499                                    m_cmdData.strMiCmd.c_str(),
1500                                    rVarObjName.c_str()));
1501     return MIstatus::failure;
1502   }
1503
1504   return MIstatus::success;
1505 }
1506
1507 //++
1508 //------------------------------------------------------------------------------------
1509 // Details: The invoker requires this function. The command prepares a MI Record
1510 // Result
1511 //          for the work carried out in the Execute().
1512 // Type:    Overridden.
1513 // Args:    None.
1514 // Return:  MIstatus::success - Functional succeeded.
1515 //          MIstatus::failure - Functional failed.
1516 // Throws:  None.
1517 //--
1518 bool CMICmdCmdVarShowAttributes::Acknowledge() {
1519   // MI output: "%s^done,status=\"editable\"]"
1520   const CMICmnMIValueConst miValueConst("editable");
1521   const CMICmnMIValueResult miValueResult("status", miValueConst);
1522   const CMICmnMIResultRecord miRecordResult(
1523       m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done,
1524       miValueResult);
1525   m_miResultRecord = miRecordResult;
1526
1527   return MIstatus::success;
1528 }
1529
1530 //++
1531 //------------------------------------------------------------------------------------
1532 // Details: Required by the CMICmdFactory when registering *this command. The
1533 // factory
1534 //          calls this function to create an instance of *this command.
1535 // Type:    Static method.
1536 // Args:    None.
1537 // Return:  CMICmdBase * - Pointer to a new command.
1538 // Throws:  None.
1539 //--
1540 CMICmdBase *CMICmdCmdVarShowAttributes::CreateSelf() {
1541   return new CMICmdCmdVarShowAttributes();
1542 }