internal async Task Eval() { _engine.CurrentRadix(); // ensure the radix value is up-to-date int threadId = Client.GetDebuggedThread().Id; uint frameLevel = _ctx.Level; Results results = await _engine.DebuggedProcess.MICommandFactory.VarCreate(_strippedName, threadId, frameLevel, ResultClass.None); if (results.ResultClass == ResultClass.done) { _internalName = results.FindString("name"); TypeName = results.TryFindString("type"); CountChildren = results.FindUint("numchild"); Value = results.TryFindString("value"); if ((Value == String.Empty || _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("Weird msg from -var-evaluate-expression"); } } } } else if (results.ResultClass == ResultClass.error) { SetAsError(results.FindString("msg")); } else { Debug.Fail("Weird msg from -var-create"); } }
internal async Task Eval() { _engine.CurrentRadix(); // ensure the radix value is up-to-date string execCommandString = "-exec "; if (_strippedName.StartsWith(execCommandString)) { // special case for executing raw mi commands. string consoleCommand = _strippedName.Substring(execCommandString.Length); string consoleResults = null; try { consoleResults = await MIDebugCommandDispatcher.ExecuteCommand(consoleCommand); Value = String.Empty; this.TypeName = null; } 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(ResourceStrings.Failed_ExecCommandError, message)); } if (!String.IsNullOrEmpty(consoleResults)) { _debuggedProcess.WriteOutput(consoleResults); } } else { int threadId = Client.GetDebuggedThread().Id; uint frameLevel = _ctx.Level; Results results = await _engine.DebuggedProcess.MICommandFactory.VarCreate(_strippedName, threadId, frameLevel, ResultClass.None); if (results.ResultClass == ResultClass.done) { _internalName = results.FindString("name"); TypeName = results.TryFindString("type"); if (results.Contains("dynamic") && results.Contains("has_more")) { CountChildren = results.FindUint("has_more"); } else { CountChildren = results.FindUint("numchild"); } Value = results.TryFindString("value"); if ((Value == String.Empty || _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("Weird msg from -var-evaluate-expression"); } } } } else if (results.ResultClass == ResultClass.error) { SetAsError(results.FindString("msg")); } else { Debug.Fail("Weird msg from -var-create"); } } }
internal async Task Eval(enum_EVALFLAGS dwFlags = 0, DAPEvalFlags dwDAPFlags = 0) { this.VerifyNotDisposed(); await _engine.UpdateRadixAsync(_engine.CurrentRadix()); // ensure the radix value is up-to-date try { string consoleCommand; if (IsConsoleExecCmd(_strippedName, out 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 ((Value == String.Empty || _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(ResourceStrings.Failed_ExecCommandError, message)); } }
// Retrieves a list of the stack frames for this thread. // For the sample engine, enumerating the stack frames requires walking the callstack in the debuggee for this thread // and coverting that to an implementation of IEnumDebugFrameInfo2. // Real engines will most likely want to cache this information to avoid recomputing it each time it is asked for, // and or construct it on demand instead of walking the entire stack. int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS dwFieldSpec, uint nRadix, out IEnumDebugFrameInfo2 enumObject) { enumObject = null; try { uint radix = _engine.CurrentRadix(); if (radix != _engine.DebuggedProcess.MICommandFactory.Radix) { _engine.DebuggedProcess.WorkerThread.RunOperation(async() => { await _engine.UpdateRadixAsync(radix); }); } // get the thread's stack frames System.Collections.Generic.List <ThreadContext> stackFrames = null; _engine.DebuggedProcess.WorkerThread.RunOperation(async() => stackFrames = await _engine.DebuggedProcess.ThreadCache.StackFrames(_debuggedThread)); int numStackFrames = stackFrames != null ? stackFrames.Count : 0; FRAMEINFO[] frameInfoArray; if (numStackFrames == 0) { // failed to walk any frames. Return an empty stack. frameInfoArray = new FRAMEINFO[0]; } else { uint low = stackFrames[0].Level; uint high = stackFrames[stackFrames.Count - 1].Level; FilterUnknownFrames(stackFrames); numStackFrames = stackFrames.Count; frameInfoArray = new FRAMEINFO[numStackFrames]; List <ArgumentList> parameters = null; if ((dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_ARGS) != 0 && !_engine.DebuggedProcess.MICommandFactory.SupportsFrameFormatting) { _engine.DebuggedProcess.WorkerThread.RunOperation(async() => parameters = await _engine.DebuggedProcess.GetParameterInfoOnly(this, (dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_ARGS_VALUES) != 0, (dwFieldSpec & enum_FRAMEINFO_FLAGS.FIF_FUNCNAME_ARGS_TYPES) != 0, low, high)); } for (int i = 0; i < numStackFrames; i++) { var p = parameters != null?parameters.Find((ArgumentList t) => t.Item1 == stackFrames[i].Level) : null; AD7StackFrame frame = new AD7StackFrame(_engine, this, stackFrames[i]); frame.SetFrameInfo(dwFieldSpec, out frameInfoArray[i], p != null ? p.Item2 : null); } } enumObject = new AD7FrameInfoEnum(frameInfoArray); return(Constants.S_OK); } catch (MIException e) { return(e.HResult); } catch (Exception e) { return(EngineUtils.UnexpectedException(e)); } }
internal async Task Eval(enum_EVALFLAGS dwFlags = 0) { this.VerifyNotDisposed(); await _engine.UpdateRadixAsync(_engine.CurrentRadix()); // ensure the radix value is up-to-date try { string consoleCommand; if (IsConsoleExecCmd(_strippedName, out 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 { 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 ((Value == String.Empty || _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("Weird msg from -var-evaluate-expression"); } } } } else if (results.ResultClass == ResultClass.error) { SetAsError(results.FindString("msg")); } else { Debug.Fail("Weird msg from -var-create"); } } } 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(ResourceStrings.Failed_ExecCommandError, message)); } }