in src/MIDebugEngine/Engine.Impl/Variables.cs [498:628]
internal async Task Eval(uint radix, enum_EVALFLAGS dwFlags = 0, DAPEvalFlags dwDAPFlags = 0)
{
this.VerifyNotDisposed();
if (radix != 0)
{
await _engine.UpdateRadixAsync(radix); // ensure the radix value is up-to-date
}
try
{
if (EngineUtils.IsConsoleExecCmd(_strippedName, out string _, out string consoleCommand))
{
// special case for executing raw mi commands.
string consoleResults = null;
consoleResults = await MIDebugCommandDispatcher.ExecuteCommand(consoleCommand, _debuggedProcess, ignoreFailures: true);
Value = String.Empty;
this.TypeName = null;
if (!String.IsNullOrEmpty(consoleResults))
{
_debuggedProcess.WriteOutput(consoleResults);
}
}
else
{
bool canRunClipboardContextCommands = this._debuggedProcess.MICommandFactory.Mode == MIMode.Gdb && dwDAPFlags.HasFlag(DAPEvalFlags.CLIPBOARD_CONTEXT);
int numElements = 200;
if (canRunClipboardContextCommands)
{
string showPrintElementsResult = await MIDebugCommandDispatcher.ExecuteCommand("show print elements", _debuggedProcess, ignoreFailures: true);
// Possible values for 'numElementsStr'
// "Limit on string chars or array elements to print is <number>."
// "Limit on string chars or array elements to print is unlimited."
string numElementsStr = Regex.Match(showPrintElementsResult, @"\d+").Value;
if (!string.IsNullOrEmpty(numElementsStr) && int.TryParse(numElementsStr, out numElements) && numElements != 0)
{
await MIDebugCommandDispatcher.ExecuteCommand("set print elements 0", _debuggedProcess, ignoreFailures: true);
}
}
int threadId = Client.GetDebuggedThread().Id;
uint frameLevel = _ctx.Level;
Results results = await _engine.DebuggedProcess.MICommandFactory.VarCreate(_strippedName, threadId, frameLevel, dwFlags, ResultClass.None);
if (results.ResultClass == ResultClass.done)
{
_internalName = results.FindString("name");
TypeName = results.TryFindString("type");
if (results.Contains("dynamic"))
{
IsPreformatted = true;
}
if (results.Contains("dynamic") && results.Contains("has_more"))
{
CountChildren = results.FindUint("has_more");
}
else
{
CountChildren = results.FindUint("numchild");
}
if (results.Contains("displayhint"))
{
DisplayHint = results.FindString("displayhint");
}
if (results.Contains("attributes"))
{
if (results.FindString("attributes") == "noneditable")
{
_isReadonly = true;
}
_attribsFetched = true;
}
Value = results.TryFindString("value");
if ((string.IsNullOrEmpty(Value) || _format != null) && !string.IsNullOrEmpty(_internalName))
{
if (_format != null)
{
await Format();
}
else
{
results = await _engine.DebuggedProcess.MICommandFactory.VarEvaluateExpression(_internalName, ResultClass.None);
if (results.ResultClass == ResultClass.done)
{
Value = results.FindString("value");
}
else if (results.ResultClass == ResultClass.error)
{
SetAsError(results.FindString("msg"));
}
else
{
Debug.Fail("Unexpected format of msg from -var-evaluate-expression");
}
}
}
}
else if (results.ResultClass == ResultClass.error)
{
SetAsError(results.FindString("msg"));
}
else
{
Debug.Fail("Unexpected format of msg from -var-create");
}
if (canRunClipboardContextCommands && numElements != 0)
{
await MIDebugCommandDispatcher.ExecuteCommand(string.Format(CultureInfo.InvariantCulture, "set print elements {0}", numElements), _debuggedProcess, ignoreFailures: true);
}
}
}
catch (Exception e)
{
if (e.InnerException != null)
e = e.InnerException;
UnexpectedMIResultException miException = e as UnexpectedMIResultException;
string message;
if (miException != null && miException.MIError != null)
message = miException.MIError;
else
message = e.Message;
SetAsError(string.Format(CultureInfo.CurrentCulture, ResourceStrings.Failed_ExecCommandError, message));
}
}