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