1 //===-- MICmdCmdVar.cpp -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
20 // Third Party Headers:
21 #include "lldb/API/SBStream.h"
22 #include "lldb/API/SBType.h"
23 #include "lldb/API/SBThread.h"
26 #include "MICmdCmdVar.h"
27 #include "MICmnMIResultRecord.h"
28 #include "MICmnMIValueConst.h"
29 #include "MICmnLLDBDebugger.h"
30 #include "MICmnLLDBDebugSessionInfo.h"
31 #include "MICmdArgValNumber.h"
32 #include "MICmdArgValString.h"
33 #include "MICmdArgValThreadGrp.h"
34 #include "MICmdArgValOptionLong.h"
35 #include "MICmdArgValOptionShort.h"
36 #include "MICmdArgValPrintValues.h"
37 #include "MICmdArgValListOfN.h"
38 #include "MICmnLLDBProxySBValue.h"
39 #include "MICmnLLDBUtilSBValue.h"
41 //++ ------------------------------------------------------------------------------------
42 // Details: CMICmdCmdVarCreate constructor.
48 CMICmdCmdVarCreate::CMICmdCmdVarCreate()
54 , m_constStrArgName("name")
55 , m_constStrArgFrameAddr("frame-addr")
56 , m_constStrArgExpression("expression")
58 // Command factory matches this name with that received from the stdin stream
59 m_strMiCmd = "var-create";
61 // Required by the CMICmdFactory when registering *this command
62 m_pSelfCreatorFn = &CMICmdCmdVarCreate::CreateSelf;
65 //++ ------------------------------------------------------------------------------------
66 // Details: CMICmdCmdVarCreate destructor.
67 // Type: Overrideable.
72 CMICmdCmdVarCreate::~CMICmdCmdVarCreate()
76 //++ ------------------------------------------------------------------------------------
77 // Details: The invoker requires this function. The parses the command line options
78 // arguments to extract values for each of those arguments.
81 // Return: MIstatus::success - Functional succeeded.
82 // MIstatus::failure - Functional failed.
86 CMICmdCmdVarCreate::ParseArgs()
88 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, false, true));
89 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgFrameAddr, false, true));
90 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgExpression, true, true, true, true));
91 return ParseValidateCmdOptions();
94 //++ ------------------------------------------------------------------------------------
95 // Details: The invoker requires this function. The command does work in this function.
96 // The command is likely to communicate with the LLDB SBDebugger in here.
99 // Return: MIstatus::success - Functional succeeded.
100 // MIstatus::failure - Functional failed.
104 CMICmdCmdVarCreate::Execute()
106 CMICMDBASE_GETOPTION(pArgThread, OptionLong, m_constStrArgThread);
107 CMICMDBASE_GETOPTION(pArgFrame, OptionLong, m_constStrArgFrame);
108 CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
109 CMICMDBASE_GETOPTION(pArgFrameAddr, String, m_constStrArgFrameAddr);
110 CMICMDBASE_GETOPTION(pArgExpression, String, m_constStrArgExpression);
112 // Retrieve the --thread option's thread ID (only 1)
113 MIuint64 nThreadId = UINT64_MAX;
114 if (pArgThread->GetFound() && !pArgThread->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nThreadId))
116 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgThread.c_str()));
117 return MIstatus::failure;
120 // Retrieve the --frame option's number
121 MIuint64 nFrame = UINT64_MAX;
122 if (pArgThread->GetFound() && !pArgFrame->GetExpectedOption<CMICmdArgValNumber, MIuint64>(nFrame))
124 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgFrame.c_str()));
125 return MIstatus::failure;
128 const CMICmdArgValOptionLong::VecArgObjPtr_t &rVecFrameId(pArgFrame->GetExpectedOptions());
129 CMICmdArgValOptionLong::VecArgObjPtr_t::const_iterator it2 = rVecFrameId.begin();
130 if (it2 != rVecFrameId.end())
132 const CMICmdArgValNumber *pOption = static_cast<CMICmdArgValNumber *>(*it2);
133 nFrame = pOption->GetValue();
136 m_strVarName = "<unnamedvariable>";
137 if (pArgName->GetFound())
139 const CMIUtilString &rArg = pArgName->GetValue();
140 const bool bAutoName = (rArg == "-");
143 m_strVarName = CMIUtilString::Format("var%u", CMICmnLLDBDebugSessionInfoVarObj::VarObjIdGet());
144 CMICmnLLDBDebugSessionInfoVarObj::VarObjIdInc();
150 bool bCurrentFrame = false;
151 if (pArgFrameAddr->GetFound())
153 const CMIUtilString &rStrFrameAddr(pArgFrameAddr->GetValue());
154 bCurrentFrame = CMIUtilString::Compare(rStrFrameAddr, "*");
155 if (!bCurrentFrame && (nFrame == UINT64_MAX))
157 //FIXME: *addr isn't implemented. Exit with error if --thread isn't specified.
158 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_OPTION_NOT_FOUND), m_cmdData.strMiCmd.c_str(), m_constStrArgFrame.c_str()));
159 return MIstatus::failure;
163 const CMIUtilString &rStrExpression(pArgExpression->GetValue());
164 m_strExpression = rStrExpression;
166 CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
167 lldb::SBProcess sbProcess = rSessionInfo.GetProcess();
168 lldb::SBThread thread = (nThreadId != UINT64_MAX) ? sbProcess.GetThreadByIndexID(nThreadId) : sbProcess.GetSelectedThread();
169 m_nThreadId = thread.GetIndexID();
170 lldb::SBFrame frame = bCurrentFrame ? thread.GetSelectedFrame() : thread.GetFrameAtIndex(nFrame);
173 if (rStrExpression[0] == '$')
175 const CMIUtilString rStrRegister(rStrExpression.substr(1));
176 value = frame.FindRegister(rStrRegister.c_str());
180 const bool bArgs = true;
181 const bool bLocals = true;
182 const bool bStatics = true;
183 const bool bInScopeOnly = false;
184 const lldb::SBValueList valueList = frame.GetVariables(bArgs, bLocals, bStatics, bInScopeOnly);
185 value = valueList.GetFirstValueByName(rStrExpression.c_str());
188 if (!value.IsValid())
189 value = frame.EvaluateExpression(rStrExpression.c_str());
191 if (value.IsValid() && value.GetError().Success())
193 CompleteSBValue(value);
195 m_nChildren = value.GetNumChildren();
196 m_strType = CMICmnLLDBUtilSBValue(value).GetTypeNameDisplay();
198 // This gets added to CMICmnLLDBDebugSessionInfoVarObj static container of varObjs
199 CMICmnLLDBDebugSessionInfoVarObj varObj(rStrExpression, m_strVarName, value);
200 m_strValue = varObj.GetValueFormatted();
204 m_strValue = value.GetError().GetCString();
207 return MIstatus::success;
210 //++ ------------------------------------------------------------------------------------
211 // Details: The invoker requires this function. The command prepares a MI Record Result
212 // for the work carried out in the Execute().
215 // Return: MIstatus::success - Functional succeeded.
216 // MIstatus::failure - Functional failed.
220 CMICmdCmdVarCreate::Acknowledge()
224 // MI print "%s^done,name=\"%s\",numchild=\"%d\",value=\"%s\",type=\"%s\",thread-id=\"%llu\",has_more=\"%u\""
225 const CMICmnMIValueConst miValueConst(m_strVarName);
226 CMICmnMIValueResult miValueResultAll("name", miValueConst);
227 const CMIUtilString strNumChild(CMIUtilString::Format("%d", m_nChildren));
228 const CMICmnMIValueConst miValueConst2(strNumChild);
229 miValueResultAll.Add("numchild", miValueConst2);
230 const CMICmnMIValueConst miValueConst3(m_strValue);
231 miValueResultAll.Add("value", miValueConst3);
232 const CMICmnMIValueConst miValueConst4(m_strType);
233 miValueResultAll.Add("type", miValueConst4);
234 const CMIUtilString strThreadId(CMIUtilString::Format("%llu", m_nThreadId));
235 const CMICmnMIValueConst miValueConst5(strThreadId);
236 miValueResultAll.Add("thread-id", miValueConst5);
237 const CMICmnMIValueConst miValueConst6("0");
238 miValueResultAll.Add("has_more", miValueConst6);
240 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResultAll);
241 m_miResultRecord = miRecordResult;
243 return MIstatus::success;
246 CMIUtilString strErrMsg(m_strValue);
247 if (m_strValue.empty())
248 strErrMsg = CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_CREATION_FAILED), m_strExpression.c_str());
249 const CMICmnMIValueConst miValueConst(strErrMsg.Escape(true /* vbEscapeQuotes */));
250 CMICmnMIValueResult miValueResult("msg", miValueConst);
251 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
252 m_miResultRecord = miRecordResult;
254 return MIstatus::success;
257 //++ ------------------------------------------------------------------------------------
258 // Details: Required by the CMICmdFactory when registering *this command. The factory
259 // calls this function to create an instance of *this command.
260 // Type: Static method.
262 // Return: CMICmdBase * - Pointer to a new command.
266 CMICmdCmdVarCreate::CreateSelf()
268 return new CMICmdCmdVarCreate();
271 //++ ------------------------------------------------------------------------------------
272 // Details: Complete SBValue object and its children to get SBValue::GetValueDidChange
275 // Args: vrwValue - (R) Value to update.
276 // Return: MIstatus::success - Functional succeeded.
277 // MIstatus::failure - Functional failed.
281 CMICmdCmdVarCreate::CompleteSBValue(lldb::SBValue &vrwValue)
283 // Force a value to update
284 vrwValue.GetValueDidChange();
286 // And update its children
287 lldb::SBType valueType = vrwValue.GetType();
288 if (!valueType.IsPointerType() && !valueType.IsReferenceType())
290 const MIuint nChildren = vrwValue.GetNumChildren();
291 for (MIuint i = 0; i < nChildren; ++i)
293 lldb::SBValue member = vrwValue.GetChildAtIndex(i);
294 if (member.IsValid())
295 CompleteSBValue(member);
300 //---------------------------------------------------------------------------------------
301 //---------------------------------------------------------------------------------------
302 //---------------------------------------------------------------------------------------
304 //++ ------------------------------------------------------------------------------------
305 // Details: CMICmdCmdVarUpdate constructor.
311 CMICmdCmdVarUpdate::CMICmdCmdVarUpdate()
312 : m_constStrArgPrintValues("print-values")
313 , m_constStrArgName("name")
314 , m_bValueChanged(false)
315 , m_miValueList(true)
317 // Command factory matches this name with that received from the stdin stream
318 m_strMiCmd = "var-update";
320 // Required by the CMICmdFactory when registering *this command
321 m_pSelfCreatorFn = &CMICmdCmdVarUpdate::CreateSelf;
324 //++ ------------------------------------------------------------------------------------
325 // Details: CMICmdCmdVarUpdate destructor.
326 // Type: Overrideable.
331 CMICmdCmdVarUpdate::~CMICmdCmdVarUpdate()
335 //++ ------------------------------------------------------------------------------------
336 // Details: The invoker requires this function. The parses the command line options
337 // arguments to extract values for each of those arguments.
340 // Return: MIstatus::success - Functional succeeded.
341 // MIstatus::failure - Functional failed.
345 CMICmdCmdVarUpdate::ParseArgs()
347 m_setCmdArgs.Add(new CMICmdArgValPrintValues(m_constStrArgPrintValues, false, true));
348 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
349 return ParseValidateCmdOptions();
352 //++ ------------------------------------------------------------------------------------
353 // Details: The invoker requires this function. The command does work in this function.
354 // The command is likely to communicate with the LLDB SBDebugger in here.
357 // Return: MIstatus::success - Functional succeeded.
358 // MIstatus::failure - Functional failed.
362 CMICmdCmdVarUpdate::Execute()
364 CMICMDBASE_GETOPTION(pArgPrintValues, PrintValues, m_constStrArgPrintValues);
365 CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
367 CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e eVarInfoFormat = CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_NoValues;
368 if (pArgPrintValues->GetFound())
369 eVarInfoFormat = static_cast<CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e>(pArgPrintValues->GetValue());
371 const CMIUtilString &rVarObjName(pArgName->GetValue());
372 CMICmnLLDBDebugSessionInfoVarObj varObj;
373 if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj))
375 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST), m_cmdData.strMiCmd.c_str(), rVarObjName.c_str()));
376 return MIstatus::failure;
379 lldb::SBValue &rValue = varObj.GetValue();
380 if (!ExamineSBValueForChange(rValue, m_bValueChanged))
381 return MIstatus::failure;
385 varObj.UpdateValue();
386 const bool bPrintValue((eVarInfoFormat == CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_AllValues) ||
387 (eVarInfoFormat == CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_SimpleValues && rValue.GetNumChildren() == 0));
388 const CMIUtilString strValue(bPrintValue ? varObj.GetValueFormatted() : "");
389 const CMIUtilString strInScope(rValue.IsInScope() ? "true" : "false");
390 MIFormResponse(rVarObjName, bPrintValue ? strValue.c_str() : nullptr, strInScope);
393 return MIstatus::success;
396 //++ ------------------------------------------------------------------------------------
397 // Details: The invoker requires this function. The command prepares a MI Record Result
398 // for the work carried out in the Execute().
401 // Return: MIstatus::success - Functional succeeded.
402 // MIstatus::failure - Functional failed.
406 CMICmdCmdVarUpdate::Acknowledge()
410 // MI print "%s^done,changelist=[{name=\"%s\",value=\"%s\",in_scope=\"%s\",type_changed=\"false\",has_more=\"0\"}]"
411 CMICmnMIValueResult miValueResult("changelist", m_miValueList);
412 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult);
413 m_miResultRecord = miRecordResult;
417 // MI print "%s^done,changelist=[]"
418 const CMICmnMIValueList miValueList(true);
419 CMICmnMIValueResult miValueResult6("changelist", miValueList);
420 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult6);
421 m_miResultRecord = miRecordResult;
424 return MIstatus::success;
427 //++ ------------------------------------------------------------------------------------
428 // Details: Required by the CMICmdFactory when registering *this command. The factory
429 // calls this function to create an instance of *this command.
430 // Type: Static method.
432 // Return: CMICmdBase * - Pointer to a new command.
436 CMICmdCmdVarUpdate::CreateSelf()
438 return new CMICmdCmdVarUpdate();
441 //++ ------------------------------------------------------------------------------------
442 // Details: Form the MI response for multiple variables.
444 // Args: vrStrVarName - (R) Session var object's name.
445 // vpValue - (R) Text version of the value held in the variable.
446 // vrStrScope - (R) In scope "yes" or "no".
451 CMICmdCmdVarUpdate::MIFormResponse(const CMIUtilString &vrStrVarName, const char *const vpValue, const CMIUtilString &vrStrScope)
453 // MI print "[{name=\"%s\",value=\"%s\",in_scope=\"%s\",type_changed=\"false\",has_more=\"0\"}]"
454 const CMICmnMIValueConst miValueConst(vrStrVarName);
455 const CMICmnMIValueResult miValueResult("name", miValueConst);
456 CMICmnMIValueTuple miValueTuple(miValueResult);
457 if (vpValue != nullptr)
459 const CMICmnMIValueConst miValueConst2(vpValue);
460 const CMICmnMIValueResult miValueResult2("value", miValueConst2);
461 miValueTuple.Add(miValueResult2);
463 const CMICmnMIValueConst miValueConst3(vrStrScope);
464 const CMICmnMIValueResult miValueResult3("in_scope", miValueConst3);
465 miValueTuple.Add(miValueResult3);
466 const CMICmnMIValueConst miValueConst4("false");
467 const CMICmnMIValueResult miValueResult4("type_changed", miValueConst4);
468 miValueTuple.Add(miValueResult4);
469 const CMICmnMIValueConst miValueConst5("0");
470 const CMICmnMIValueResult miValueResult5("has_more", miValueConst5);
471 miValueTuple.Add(miValueResult5);
472 m_miValueList.Add(miValueTuple);
475 //++ ------------------------------------------------------------------------------------
476 // Details: Determine if the var object was changed.
478 // Args: vrVarObj - (R) Session var object to examine.
479 // vrwbChanged - (W) True = The var object was changed,
480 // False = It was not changed.
481 // Return: MIstatus::success - Functional succeeded.
482 // MIstatus::failure - Functional failed.
486 CMICmdCmdVarUpdate::ExamineSBValueForChange(lldb::SBValue &vrwValue, bool &vrwbChanged)
488 if (vrwValue.GetValueDidChange())
491 return MIstatus::success;
494 lldb::SBType valueType = vrwValue.GetType();
495 if (!valueType.IsPointerType() && !valueType.IsReferenceType())
497 const MIuint nChildren = vrwValue.GetNumChildren();
498 for (MIuint i = 0; i < nChildren; ++i)
500 lldb::SBValue member = vrwValue.GetChildAtIndex(i);
501 if (!member.IsValid())
504 if (member.GetValueDidChange())
507 return MIstatus::success;
509 else if (ExamineSBValueForChange(member, vrwbChanged) && vrwbChanged)
510 // Handle composite types (i.e. struct or arrays)
511 return MIstatus::success;
516 return MIstatus::success;
519 //---------------------------------------------------------------------------------------
520 //---------------------------------------------------------------------------------------
521 //---------------------------------------------------------------------------------------
523 //++ ------------------------------------------------------------------------------------
524 // Details: CMICmdCmdVarDelete constructor.
530 CMICmdCmdVarDelete::CMICmdCmdVarDelete()
531 : m_constStrArgName("name")
533 // Command factory matches this name with that received from the stdin stream
534 m_strMiCmd = "var-delete";
536 // Required by the CMICmdFactory when registering *this command
537 m_pSelfCreatorFn = &CMICmdCmdVarDelete::CreateSelf;
540 //++ ------------------------------------------------------------------------------------
541 // Details: The invoker requires this function. The parses the command line options
542 // arguments to extract values for each of those arguments.
545 // Return: MIstatus::success - Functional succeeded.
546 // MIstatus::failure - Functional failed.
550 CMICmdCmdVarDelete::ParseArgs()
552 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
553 return ParseValidateCmdOptions();
556 //++ ------------------------------------------------------------------------------------
557 // Details: CMICmdCmdVarDelete destructor.
558 // Type: Overrideable.
563 CMICmdCmdVarDelete::~CMICmdCmdVarDelete()
567 //++ ------------------------------------------------------------------------------------
568 // Details: The invoker requires this function. The command does work in this function.
569 // The command is likely to communicate with the LLDB SBDebugger in here.
572 // Return: MIstatus::success - Functional succeeded.
573 // MIstatus::failure - Functional failed.
577 CMICmdCmdVarDelete::Execute()
579 CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
581 const CMIUtilString &rVarObjName(pArgName->GetValue());
582 CMICmnLLDBDebugSessionInfoVarObj::VarObjDelete(rVarObjName);
584 return MIstatus::success;
587 //++ ------------------------------------------------------------------------------------
588 // Details: The invoker requires this function. The command prepares a MI Record Result
589 // for the work carried out in the Execute().
592 // Return: MIstatus::success - Functional succeeded.
593 // MIstatus::failure - Functional failed.
597 CMICmdCmdVarDelete::Acknowledge()
599 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done);
600 m_miResultRecord = miRecordResult;
602 return MIstatus::success;
605 //++ ------------------------------------------------------------------------------------
606 // Details: Required by the CMICmdFactory when registering *this command. The factory
607 // calls this function to create an instance of *this command.
608 // Type: Static method.
610 // Return: CMICmdBase * - Pointer to a new command.
614 CMICmdCmdVarDelete::CreateSelf()
616 return new CMICmdCmdVarDelete();
619 //---------------------------------------------------------------------------------------
620 //---------------------------------------------------------------------------------------
621 //---------------------------------------------------------------------------------------
623 //++ ------------------------------------------------------------------------------------
624 // Details: CMICmdCmdVarAssign constructor.
630 CMICmdCmdVarAssign::CMICmdCmdVarAssign()
632 , m_constStrArgName("name")
633 , m_constStrArgExpression("expression")
635 // Command factory matches this name with that received from the stdin stream
636 m_strMiCmd = "var-assign";
638 // Required by the CMICmdFactory when registering *this command
639 m_pSelfCreatorFn = &CMICmdCmdVarAssign::CreateSelf;
642 //++ ------------------------------------------------------------------------------------
643 // Details: CMICmdCmdVarAssign destructor.
644 // Type: Overrideable.
649 CMICmdCmdVarAssign::~CMICmdCmdVarAssign()
653 //++ ------------------------------------------------------------------------------------
654 // Details: The invoker requires this function. The parses the command line options
655 // arguments to extract values for each of those arguments.
658 // Return: MIstatus::success - Functional succeeded.
659 // MIstatus::failure - Functional failed.
663 CMICmdCmdVarAssign::ParseArgs()
665 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
666 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgExpression, true, true));
667 return ParseValidateCmdOptions();
670 //++ ------------------------------------------------------------------------------------
671 // Details: The invoker requires this function. The command does work in this function.
672 // The command is likely to communicate with the LLDB SBDebugger in here.
675 // Return: MIstatus::success - Functional succeeded.
676 // MIstatus::failure - Functional failed.
680 CMICmdCmdVarAssign::Execute()
682 CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
683 CMICMDBASE_GETOPTION(pArgExpression, String, m_constStrArgExpression);
685 const CMIUtilString &rVarObjName(pArgName->GetValue());
686 const CMIUtilString &rExpression(pArgExpression->GetValue());
688 CMICmnLLDBDebugSessionInfoVarObj varObj;
689 if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj))
691 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST), m_cmdData.strMiCmd.c_str(), rVarObjName.c_str()));
692 return MIstatus::failure;
694 m_varObjName = rVarObjName;
696 CMIUtilString strExpression(rExpression.Trim());
697 strExpression = strExpression.Trim('"');
698 lldb::SBValue &rValue(const_cast<lldb::SBValue &>(varObj.GetValue()));
699 m_bOk = rValue.SetValueFromCString(strExpression.c_str());
701 varObj.UpdateValue();
703 return MIstatus::success;
706 //++ ------------------------------------------------------------------------------------
707 // Details: The invoker requires this function. The command prepares a MI Record Result
708 // for the work carried out in the Execute().
711 // Return: MIstatus::success - Functional succeeded.
712 // MIstatus::failure - Functional failed.
716 CMICmdCmdVarAssign::Acknowledge()
720 // MI print "%s^done,value=\"%s\""
721 CMICmnLLDBDebugSessionInfoVarObj varObj;
722 CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(m_varObjName, varObj);
723 const CMICmnMIValueConst miValueConst(varObj.GetValueFormatted());
724 const CMICmnMIValueResult miValueResult("value", miValueConst);
725 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult);
726 m_miResultRecord = miRecordResult;
728 return MIstatus::success;
731 const CMICmnMIValueConst miValueConst("expression could not be evaluated");
732 const CMICmnMIValueResult miValueResult("msg", miValueConst);
733 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
734 m_miResultRecord = miRecordResult;
736 return MIstatus::success;
739 //++ ------------------------------------------------------------------------------------
740 // Details: Required by the CMICmdFactory when registering *this command. The factory
741 // calls this function to create an instance of *this command.
742 // Type: Static method.
744 // Return: CMICmdBase * - Pointer to a new command.
748 CMICmdCmdVarAssign::CreateSelf()
750 return new CMICmdCmdVarAssign();
753 //---------------------------------------------------------------------------------------
754 //---------------------------------------------------------------------------------------
755 //---------------------------------------------------------------------------------------
757 //++ ------------------------------------------------------------------------------------
758 // Details: CMICmdCmdVarSetFormat constructor.
764 CMICmdCmdVarSetFormat::CMICmdCmdVarSetFormat()
765 : m_constStrArgName("name")
766 , m_constStrArgFormatSpec("format-spec")
768 // Command factory matches this name with that received from the stdin stream
769 m_strMiCmd = "var-set-format";
771 // Required by the CMICmdFactory when registering *this command
772 m_pSelfCreatorFn = &CMICmdCmdVarSetFormat::CreateSelf;
775 //++ ------------------------------------------------------------------------------------
776 // Details: CMICmdCmdVarSetFormat destructor.
777 // Type: Overrideable.
782 CMICmdCmdVarSetFormat::~CMICmdCmdVarSetFormat()
786 //++ ------------------------------------------------------------------------------------
787 // Details: The invoker requires this function. The parses the command line options
788 // arguments to extract values for each of those arguments.
791 // Return: MIstatus::success - Functional succeeded.
792 // MIstatus::failure - Functional failed.
796 CMICmdCmdVarSetFormat::ParseArgs()
798 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
799 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgFormatSpec, true, true));
800 return ParseValidateCmdOptions();
803 //++ ------------------------------------------------------------------------------------
804 // Details: The invoker requires this function. The command does work in this function.
805 // The command is likely to communicate with the LLDB SBDebugger in here.
808 // Return: MIstatus::success - Functional succeeded.
809 // MIstatus::failure - Functional failed.
813 CMICmdCmdVarSetFormat::Execute()
815 CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
816 CMICMDBASE_GETOPTION(pArgFormatSpec, String, m_constStrArgFormatSpec);
818 const CMIUtilString &rVarObjName(pArgName->GetValue());
819 const CMIUtilString &rExpression(pArgFormatSpec->GetValue());
821 CMICmnLLDBDebugSessionInfoVarObj varObj;
822 if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj))
824 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST), m_cmdData.strMiCmd.c_str(), rVarObjName.c_str()));
825 return MIstatus::failure;
827 if (!varObj.SetVarFormat(CMICmnLLDBDebugSessionInfoVarObj::GetVarFormatForString(rExpression)))
829 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_ENUM_INVALID), m_cmdData.strMiCmd.c_str(), rVarObjName.c_str(),
830 rExpression.c_str()));
831 return MIstatus::failure;
833 varObj.UpdateValue();
835 m_varObjName = rVarObjName;
837 return MIstatus::success;
840 //++ ------------------------------------------------------------------------------------
841 // Details: The invoker requires this function. The command prepares a MI Record Result
842 // for the work carried out in the Execute().
845 // Return: MIstatus::success - Functional succeeded.
846 // MIstatus::failure - Functional failed.
850 CMICmdCmdVarSetFormat::Acknowledge()
852 // MI print "%s^done,changelist=[{name=\"%s\",value=\"%s\",in_scope=\"%s\",type_changed=\"false\",has_more=\"0\"}]"
853 CMICmnLLDBDebugSessionInfoVarObj varObj;
854 CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(m_varObjName, varObj);
855 const CMICmnMIValueConst miValueConst(m_varObjName);
856 const CMICmnMIValueResult miValueResult("name", miValueConst);
857 CMICmnMIValueTuple miValueTuple(miValueResult);
858 const CMICmnMIValueConst miValueConst2(varObj.GetValueFormatted());
859 const CMICmnMIValueResult miValueResult2("value", miValueConst2);
860 miValueTuple.Add(miValueResult2);
861 lldb::SBValue &rValue = const_cast<lldb::SBValue &>(varObj.GetValue());
862 const CMICmnMIValueConst miValueConst3(rValue.IsInScope() ? "true" : "false");
863 const CMICmnMIValueResult miValueResult3("in_scope", miValueConst3);
864 miValueTuple.Add(miValueResult3);
865 const CMICmnMIValueConst miValueConst4("false");
866 const CMICmnMIValueResult miValueResult4("type_changed", miValueConst4);
867 miValueTuple.Add(miValueResult4);
868 const CMICmnMIValueConst miValueConst5("0");
869 const CMICmnMIValueResult miValueResult5("type_changed", miValueConst5);
870 miValueTuple.Add(miValueResult5);
871 const CMICmnMIValueList miValueList(miValueTuple);
872 const CMICmnMIValueResult miValueResult6("changelist", miValueList);
874 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult6);
875 m_miResultRecord = miRecordResult;
877 return MIstatus::success;
880 //++ ------------------------------------------------------------------------------------
881 // Details: Required by the CMICmdFactory when registering *this command. The factory
882 // calls this function to create an instance of *this command.
883 // Type: Static method.
885 // Return: CMICmdBase * - Pointer to a new command.
889 CMICmdCmdVarSetFormat::CreateSelf()
891 return new CMICmdCmdVarSetFormat();
894 //---------------------------------------------------------------------------------------
895 //---------------------------------------------------------------------------------------
896 //---------------------------------------------------------------------------------------
898 //++ ------------------------------------------------------------------------------------
899 // Details: CMICmdCmdVarListChildren constructor.
905 CMICmdCmdVarListChildren::CMICmdCmdVarListChildren()
906 : m_constStrArgPrintValues("print-values")
907 , m_constStrArgName("name")
908 , m_constStrArgFrom("from")
909 , m_constStrArgTo("to")
910 , m_bValueValid(false)
912 , m_miValueList(true)
915 // Command factory matches this name with that received from the stdin stream
916 m_strMiCmd = "var-list-children";
918 // Required by the CMICmdFactory when registering *this command
919 m_pSelfCreatorFn = &CMICmdCmdVarListChildren::CreateSelf;
922 //++ ------------------------------------------------------------------------------------
923 // Details: CMICmdCmdVarListChildren destructor.
924 // Type: Overrideable.
929 CMICmdCmdVarListChildren::~CMICmdCmdVarListChildren()
933 //++ ------------------------------------------------------------------------------------
934 // Details: The invoker requires this function. The parses the command line options
935 // arguments to extract values for each of those arguments.
938 // Return: MIstatus::success - Functional succeeded.
939 // MIstatus::failure - Functional failed.
943 CMICmdCmdVarListChildren::ParseArgs()
945 m_setCmdArgs.Add(new CMICmdArgValPrintValues(m_constStrArgPrintValues, false, true));
946 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true, true));
947 m_setCmdArgs.Add(new CMICmdArgValNumber(m_constStrArgFrom, false, true));
948 m_setCmdArgs.Add(new CMICmdArgValNumber(m_constStrArgTo, false, true));
949 return ParseValidateCmdOptions();
952 //++ ------------------------------------------------------------------------------------
953 // Details: The invoker requires this function. The command does work in this function.
954 // The command is likely to communicate with the LLDB SBDebugger in here.
957 // Return: MIstatus::success - Functional succeeded.
958 // MIstatus::failure - Functional failed.
962 CMICmdCmdVarListChildren::Execute()
964 CMICMDBASE_GETOPTION(pArgPrintValues, PrintValues, m_constStrArgPrintValues);
965 CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
966 CMICMDBASE_GETOPTION(pArgFrom, Number, m_constStrArgFrom);
967 CMICMDBASE_GETOPTION(pArgTo, Number, m_constStrArgTo);
969 CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e eVarInfoFormat = CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_NoValues;
970 if (pArgPrintValues->GetFound())
971 eVarInfoFormat = static_cast<CMICmnLLDBDebugSessionInfo::VariableInfoFormat_e>(pArgPrintValues->GetValue());
973 const CMIUtilString &rVarObjName(pArgName->GetValue());
974 CMICmnLLDBDebugSessionInfoVarObj varObj;
975 if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj))
977 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST), m_cmdData.strMiCmd.c_str(), rVarObjName.c_str()));
978 return MIstatus::failure;
982 MIuint nTo = UINT32_MAX;
983 if (pArgFrom->GetFound() && pArgTo->GetFound())
985 nFrom = pArgFrom->GetValue();
986 nTo = pArgTo->GetValue();
988 else if (pArgFrom->GetFound() || pArgTo->GetFound())
990 // Only from or to was specified but both are required
991 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_CHILD_RANGE_INVALID), m_cmdData.strMiCmd.c_str()));
992 return MIstatus::failure;
995 lldb::SBValue &rValue = const_cast<lldb::SBValue &>(varObj.GetValue());
996 m_bValueValid = rValue.IsValid();
998 return MIstatus::success;
1000 const MIuint nChildren = rValue.GetNumChildren();
1001 m_bHasMore = nTo < nChildren;
1002 nTo = std::min(nTo, nChildren);
1003 m_nChildren = nFrom < nTo ? nTo - nFrom : 0;
1004 for (MIuint i = nFrom; i < nTo; i++)
1006 lldb::SBValue member = rValue.GetChildAtIndex(i);
1007 const CMICmnLLDBUtilSBValue utilValue(member);
1008 const CMIUtilString strExp = utilValue.GetName();
1009 const CMIUtilString name(strExp.empty() ?
1010 CMIUtilString::Format("%s.$%u", rVarObjName.c_str(), i) :
1011 CMIUtilString::Format("%s.%s", rVarObjName.c_str(), strExp.c_str()));
1012 const MIuint nChildren = member.GetNumChildren();
1013 const CMIUtilString strThreadId(CMIUtilString::Format("%u", member.GetThread().GetIndexID()));
1015 // Varobj gets added to CMICmnLLDBDebugSessionInfoVarObj static container of varObjs
1016 CMICmnLLDBDebugSessionInfoVarObj var(strExp, name, member, rVarObjName);
1018 // MI print "child={name=\"%s\",exp=\"%s\",numchild=\"%d\",value=\"%s\",type=\"%s\",thread-id=\"%u\",has_more=\"%u\"}"
1019 const CMICmnMIValueConst miValueConst(name);
1020 const CMICmnMIValueResult miValueResult("name", miValueConst);
1021 CMICmnMIValueTuple miValueTuple(miValueResult);
1022 const CMICmnMIValueConst miValueConst2(strExp);
1023 const CMICmnMIValueResult miValueResult2("exp", miValueConst2);
1024 miValueTuple.Add(miValueResult2);
1025 const CMIUtilString strNumChild(CMIUtilString::Format("%u", nChildren));
1026 const CMICmnMIValueConst miValueConst3(strNumChild);
1027 const CMICmnMIValueResult miValueResult3("numchild", miValueConst3);
1028 miValueTuple.Add(miValueResult3);
1029 const CMICmnMIValueConst miValueConst5(utilValue.GetTypeNameDisplay());
1030 const CMICmnMIValueResult miValueResult5("type", miValueConst5);
1031 miValueTuple.Add(miValueResult5);
1032 const CMICmnMIValueConst miValueConst6(strThreadId);
1033 const CMICmnMIValueResult miValueResult6("thread-id", miValueConst6);
1034 miValueTuple.Add(miValueResult6);
1035 // nChildren == 0 is used to check for simple values
1036 if (eVarInfoFormat == CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_AllValues ||
1037 (eVarInfoFormat == CMICmnLLDBDebugSessionInfo::eVariableInfoFormat_SimpleValues && nChildren == 0))
1039 const CMIUtilString strValue(
1040 CMICmnLLDBDebugSessionInfoVarObj::GetValueStringFormatted(member, CMICmnLLDBDebugSessionInfoVarObj::eVarFormat_Natural));
1041 const CMICmnMIValueConst miValueConst7(strValue);
1042 const CMICmnMIValueResult miValueResult7("value", miValueConst7);
1043 miValueTuple.Add(miValueResult7);
1045 const CMICmnMIValueConst miValueConst8("0");
1046 const CMICmnMIValueResult miValueResult8("has_more", miValueConst8);
1047 miValueTuple.Add(miValueResult8);
1048 const CMICmnMIValueResult miValueResult9("child", miValueTuple);
1049 m_miValueList.Add(miValueResult9);
1052 return MIstatus::success;
1055 //++ ------------------------------------------------------------------------------------
1056 // Details: The invoker requires this function. The command prepares a MI Record Result
1057 // for the work carried out in the Execute().
1058 // Type: Overridden.
1060 // Return: MIstatus::success - Functional succeeded.
1061 // MIstatus::failure - Functional failed.
1065 CMICmdCmdVarListChildren::Acknowledge()
1069 // MI print "%s^done,numchild=\"%u\",children=[%s],has_more=\"%d\""
1070 const CMIUtilString strNumChild(CMIUtilString::Format("%u", m_nChildren));
1071 const CMICmnMIValueConst miValueConst(strNumChild);
1072 CMICmnMIValueResult miValueResult("numchild", miValueConst);
1073 if (m_nChildren != 0)
1074 miValueResult.Add("children", m_miValueList);
1075 const CMIUtilString strHasMore(m_bHasMore ? "1" : "0");
1076 const CMICmnMIValueConst miValueConst2(strHasMore);
1077 miValueResult.Add("has_more", miValueConst2);
1079 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult);
1080 m_miResultRecord = miRecordResult;
1082 return MIstatus::success;
1085 // MI print "%s^error,msg=\"variable invalid\""
1086 const CMICmnMIValueConst miValueConst("variable invalid");
1087 const CMICmnMIValueResult miValueResult("msg", miValueConst);
1088 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
1089 m_miResultRecord = miRecordResult;
1091 return MIstatus::success;
1094 //++ ------------------------------------------------------------------------------------
1095 // Details: Required by the CMICmdFactory when registering *this command. The factory
1096 // calls this function to create an instance of *this command.
1097 // Type: Static method.
1099 // Return: CMICmdBase * - Pointer to a new command.
1103 CMICmdCmdVarListChildren::CreateSelf()
1105 return new CMICmdCmdVarListChildren();
1108 //---------------------------------------------------------------------------------------
1109 //---------------------------------------------------------------------------------------
1110 //---------------------------------------------------------------------------------------
1112 //++ ------------------------------------------------------------------------------------
1113 // Details: CMICmdCmdVarEvaluateExpression constructor.
1119 CMICmdCmdVarEvaluateExpression::CMICmdCmdVarEvaluateExpression()
1120 : m_bValueValid(true)
1121 , m_constStrArgFormatSpec("-f")
1122 , m_constStrArgName("name")
1124 // Command factory matches this name with that received from the stdin stream
1125 m_strMiCmd = "var-evaluate-expression";
1127 // Required by the CMICmdFactory when registering *this command
1128 m_pSelfCreatorFn = &CMICmdCmdVarEvaluateExpression::CreateSelf;
1131 //++ ------------------------------------------------------------------------------------
1132 // Details: CMICmdCmdVarEvaluateExpression destructor.
1133 // Type: Overrideable.
1138 CMICmdCmdVarEvaluateExpression::~CMICmdCmdVarEvaluateExpression()
1142 //++ ------------------------------------------------------------------------------------
1143 // Details: The invoker requires this function. The parses the command line options
1144 // arguments to extract values for each of those arguments.
1145 // Type: Overridden.
1147 // Return: MIstatus::success - Functional succeeded.
1148 // MIstatus::failure - Functional failed.
1152 CMICmdCmdVarEvaluateExpression::ParseArgs()
1155 new CMICmdArgValOptionShort(m_constStrArgFormatSpec, false, false, CMICmdArgValListBase::eArgValType_String, 1));
1156 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
1157 return ParseValidateCmdOptions();
1160 //++ ------------------------------------------------------------------------------------
1161 // Details: The invoker requires this function. The command does work in this function.
1162 // The command is likely to communicate with the LLDB SBDebugger in here.
1163 // Type: Overridden.
1165 // Return: MIstatus::success - Functional succeeded.
1166 // MIstatus::failure - Functional failed.
1170 CMICmdCmdVarEvaluateExpression::Execute()
1172 CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
1174 const CMIUtilString &rVarObjName(pArgName->GetValue());
1175 CMICmnLLDBDebugSessionInfoVarObj varObj;
1176 if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj))
1178 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST), m_cmdData.strMiCmd.c_str(), rVarObjName.c_str()));
1179 return MIstatus::failure;
1182 lldb::SBValue &rValue = const_cast<lldb::SBValue &>(varObj.GetValue());
1183 m_bValueValid = rValue.IsValid();
1185 return MIstatus::success;
1187 m_varObjName = rVarObjName;
1188 varObj.UpdateValue();
1190 return MIstatus::success;
1193 //++ ------------------------------------------------------------------------------------
1194 // Details: The invoker requires this function. The command prepares a MI Record Result
1195 // for the work carried out in the Execute().
1196 // Type: Overridden.
1198 // Return: MIstatus::success - Functional succeeded.
1199 // MIstatus::failure - Functional failed.
1203 CMICmdCmdVarEvaluateExpression::Acknowledge()
1207 CMICmnLLDBDebugSessionInfoVarObj varObj;
1208 CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(m_varObjName, varObj);
1209 const CMICmnMIValueConst miValueConst(varObj.GetValueFormatted());
1210 const CMICmnMIValueResult miValueResult("value", miValueConst);
1211 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult);
1212 m_miResultRecord = miRecordResult;
1213 return MIstatus::success;
1216 const CMICmnMIValueConst miValueConst("variable invalid");
1217 const CMICmnMIValueResult miValueResult("msg", miValueConst);
1218 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
1219 m_miResultRecord = miRecordResult;
1220 return MIstatus::success;
1223 //++ ------------------------------------------------------------------------------------
1224 // Details: Required by the CMICmdFactory when registering *this command. The factory
1225 // calls this function to create an instance of *this command.
1226 // Type: Static method.
1228 // Return: CMICmdBase * - Pointer to a new command.
1232 CMICmdCmdVarEvaluateExpression::CreateSelf()
1234 return new CMICmdCmdVarEvaluateExpression();
1237 //---------------------------------------------------------------------------------------
1238 //---------------------------------------------------------------------------------------
1239 //---------------------------------------------------------------------------------------
1241 //++ ------------------------------------------------------------------------------------
1242 // Details: CMICmdCmdVarInfoPathExpression constructor.
1248 CMICmdCmdVarInfoPathExpression::CMICmdCmdVarInfoPathExpression()
1249 : m_bValueValid(true)
1250 , m_constStrArgName("name")
1252 // Command factory matches this name with that received from the stdin stream
1253 m_strMiCmd = "var-info-path-expression";
1255 // Required by the CMICmdFactory when registering *this command
1256 m_pSelfCreatorFn = &CMICmdCmdVarInfoPathExpression::CreateSelf;
1259 //++ ------------------------------------------------------------------------------------
1260 // Details: CMICmdCmdVarInfoPathExpression destructor.
1261 // Type: Overrideable.
1266 CMICmdCmdVarInfoPathExpression::~CMICmdCmdVarInfoPathExpression()
1270 //++ ------------------------------------------------------------------------------------
1271 // Details: The invoker requires this function. The parses the command line options
1272 // arguments to extract values for each of those arguments.
1273 // Type: Overridden.
1275 // Return: MIstatus::success - Functional succeeded.
1276 // MIstatus::failure - Functional failed.
1280 CMICmdCmdVarInfoPathExpression::ParseArgs()
1282 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
1283 return ParseValidateCmdOptions();
1286 //++ ------------------------------------------------------------------------------------
1287 // Details: The invoker requires this function. The command does work in this function.
1288 // The command is likely to communicate with the LLDB SBDebugger in here.
1289 // Type: Overridden.
1291 // Return: MIstatus::success - Functional succeeded.
1292 // MIstatus::failure - Functional failed.
1296 CMICmdCmdVarInfoPathExpression::Execute()
1298 CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
1300 const CMIUtilString &rVarObjName(pArgName->GetValue());
1301 CMICmnLLDBDebugSessionInfoVarObj varObj;
1302 if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj))
1304 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST), m_cmdData.strMiCmd.c_str(), rVarObjName.c_str()));
1305 return MIstatus::failure;
1308 lldb::SBValue &rValue = const_cast<lldb::SBValue &>(varObj.GetValue());
1309 m_bValueValid = rValue.IsValid();
1311 return MIstatus::success;
1313 lldb::SBStream stream;
1314 if (!rValue.GetExpressionPath(stream, true))
1316 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_EXPRESSIONPATH), m_cmdData.strMiCmd.c_str(), rVarObjName.c_str()));
1317 return MIstatus::failure;
1320 const char *pPathExpression = stream.GetData();
1321 if (pPathExpression == nullptr)
1323 // Build expression from what we do know
1324 m_strPathExpression = varObj.GetNameReal();
1325 return MIstatus::success;
1328 // Has LLDB returned a var signature of it's own
1329 if (pPathExpression[0] != '$')
1331 m_strPathExpression = pPathExpression;
1332 return MIstatus::success;
1335 // Build expression from what we do know
1336 const CMIUtilString &rVarParentName(varObj.GetVarParentName());
1337 if (rVarParentName.empty())
1339 m_strPathExpression = varObj.GetNameReal();
1343 CMICmnLLDBDebugSessionInfoVarObj varObjParent;
1344 if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarParentName, varObjParent))
1346 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST), m_cmdData.strMiCmd.c_str(), rVarParentName.c_str()));
1347 return MIstatus::failure;
1349 m_strPathExpression = CMIUtilString::Format("%s.%s", varObjParent.GetNameReal().c_str(), varObj.GetNameReal().c_str());
1352 return MIstatus::success;
1355 //++ ------------------------------------------------------------------------------------
1356 // Details: The invoker requires this function. The command prepares a MI Record Result
1357 // for the work carried out in the Execute().
1358 // Type: Overridden.
1360 // Return: MIstatus::success - Functional succeeded.
1361 // MIstatus::failure - Functional failed.
1365 CMICmdCmdVarInfoPathExpression::Acknowledge()
1369 const CMICmnMIValueConst miValueConst(m_strPathExpression);
1370 const CMICmnMIValueResult miValueResult("path_expr", miValueConst);
1371 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult);
1372 m_miResultRecord = miRecordResult;
1373 return MIstatus::success;
1376 const CMICmnMIValueConst miValueConst("variable invalid");
1377 const CMICmnMIValueResult miValueResult("msg", miValueConst);
1378 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, miValueResult);
1379 m_miResultRecord = miRecordResult;
1381 return MIstatus::success;
1384 //++ ------------------------------------------------------------------------------------
1385 // Details: Required by the CMICmdFactory when registering *this command. The factory
1386 // calls this function to create an instance of *this command.
1387 // Type: Static method.
1389 // Return: CMICmdBase * - Pointer to a new command.
1393 CMICmdCmdVarInfoPathExpression::CreateSelf()
1395 return new CMICmdCmdVarInfoPathExpression();
1398 //---------------------------------------------------------------------------------------
1399 //---------------------------------------------------------------------------------------
1400 //---------------------------------------------------------------------------------------
1402 //++ ------------------------------------------------------------------------------------
1403 // Details: CMICmdCmdVarShowAttributes constructor.
1409 CMICmdCmdVarShowAttributes::CMICmdCmdVarShowAttributes()
1410 : m_constStrArgName("name")
1412 // Command factory matches this name with that received from the stdin stream
1413 m_strMiCmd = "var-show-attributes";
1415 // Required by the CMICmdFactory when registering *this command
1416 m_pSelfCreatorFn = &CMICmdCmdVarShowAttributes::CreateSelf;
1419 //++ ------------------------------------------------------------------------------------
1420 // Details: CMICmdCmdVarShowAttributes destructor.
1421 // Type: Overrideable.
1426 CMICmdCmdVarShowAttributes::~CMICmdCmdVarShowAttributes()
1430 //++ ------------------------------------------------------------------------------------
1431 // Details: The invoker requires this function. The parses the command line options
1432 // arguments to extract values for each of those arguments.
1433 // Type: Overridden.
1435 // Return: MIstatus::success - Functional succeeded.
1436 // MIstatus::failure - Functional failed.
1440 CMICmdCmdVarShowAttributes::ParseArgs()
1442 m_setCmdArgs.Add(new CMICmdArgValString(m_constStrArgName, true, true));
1443 return ParseValidateCmdOptions();
1446 //++ ------------------------------------------------------------------------------------
1447 // Details: The invoker requires this function. The command does work in this function.
1448 // The command is likely to communicate with the LLDB SBDebugger in here.
1449 // Type: Overridden.
1451 // Return: MIstatus::success - Functional succeeded.
1452 // MIstatus::failure - Functional failed.
1456 CMICmdCmdVarShowAttributes::Execute()
1458 CMICMDBASE_GETOPTION(pArgName, String, m_constStrArgName);
1460 const CMIUtilString &rVarObjName(pArgName->GetValue());
1461 CMICmnLLDBDebugSessionInfoVarObj varObj;
1462 if (!CMICmnLLDBDebugSessionInfoVarObj::VarObjGet(rVarObjName, varObj))
1464 SetError(CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_VARIABLE_DOESNOTEXIST), m_cmdData.strMiCmd.c_str(), rVarObjName.c_str()));
1465 return MIstatus::failure;
1468 return MIstatus::success;
1471 //++ ------------------------------------------------------------------------------------
1472 // Details: The invoker requires this function. The command prepares a MI Record Result
1473 // for the work carried out in the Execute().
1474 // Type: Overridden.
1476 // Return: MIstatus::success - Functional succeeded.
1477 // MIstatus::failure - Functional failed.
1481 CMICmdCmdVarShowAttributes::Acknowledge()
1483 // MI output: "%s^done,status=\"editable\"]"
1484 const CMICmnMIValueConst miValueConst("editable");
1485 const CMICmnMIValueResult miValueResult("status", miValueConst);
1486 const CMICmnMIResultRecord miRecordResult(m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Done, miValueResult);
1487 m_miResultRecord = miRecordResult;
1489 return MIstatus::success;
1492 //++ ------------------------------------------------------------------------------------
1493 // Details: Required by the CMICmdFactory when registering *this command. The factory
1494 // calls this function to create an instance of *this command.
1495 // Type: Static method.
1497 // Return: CMICmdBase * - Pointer to a new command.
1501 CMICmdCmdVarShowAttributes::CreateSelf()
1503 return new CMICmdCmdVarShowAttributes();