示例#1
0
        private async void VRDebugExecAsync(string command)
        {
            var commandWindow = (IVsCommandWindow)GetService(typeof(SVsCommandWindow));

            string results = null;

            try
            {
                results = await MIDebugCommandDispatcher.ExecuteCommand(command);
            }
            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;
                }

                commandWindow.Print(string.Format("Error: {0}\r\n", message));
                return;
            }

            if (results.Length > 0)
            {
                // Make sure that we are printing whole lines
                if (!results.EndsWith("\n") && !results.EndsWith("\r\n"))
                {
                    results = results + "\n";
                }

                commandWindow.Print(results);
            }
        }
示例#2
0
        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");
                }
            }
        }
        private async void MIDebugExecAsync(string command)
        {
            var  commandWindow = (IVsCommandWindow)GetService(typeof(SVsCommandWindow));
            bool atBreak       = false;
            var  debugger      = GetService(typeof(SVsShellDebugger)) as IVsDebugger;

            if (debugger != null)
            {
                DBGMODE[] mode = new DBGMODE[1];
                if (debugger.GetMode(mode) == MIDebugEngine.Constants.S_OK)
                {
                    atBreak = mode[0] == DBGMODE.DBGMODE_Break;
                }
            }

            string results = null;

            try
            {
                if (atBreak)
                {
                    commandWindow.ExecuteCommand(String.Format(CultureInfo.InvariantCulture, "Debug.EvaluateStatement -exec {0}", command));
                }
                else
                {
                    results = await MIDebugCommandDispatcher.ExecuteCommand(command);
                }
            }
            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;
                }

                commandWindow.Print(string.Format("Error: {0}\r\n", message));
                return;
            }

            if (results != null && results.Length > 0)
            {
                // Make sure that we are printing whole lines
                if (!results.EndsWith("\n") && !results.EndsWith("\r\n"))
                {
                    results = results + "\n";
                }

                commandWindow.Print(results);
            }
        }
示例#4
0
        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));
            }
        }
示例#5
0
        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));
            }
        }