Beispiel #1
0
 public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError)
 {
     ppExpr     = null;
     pbstrError = "";
     pichError  = 0;
     return(VSConstants.E_NOTIMPL);
 }
Beispiel #2
0
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode,
                                               enum_PARSEFLAGS dwFlags,
                                               uint nRadix,
                                               out IDebugExpression2 ppExpr,
                                               out string pbstrError,
                                               out uint pichError)
        {
            pbstrError = string.Empty;
            pichError  = 0;

            var evaluationResults = this._stackFrame.Locals.Union(this._stackFrame.Parameters);

            foreach (var currVariable in evaluationResults)
            {
                if (StringComparer.Ordinal.Equals(currVariable.Expression, pszCode))
                {
                    ppExpr = new UncalculatedAD7Expression(this, currVariable.Expression);
                    return(VSConstants.S_OK);
                }
            }

            string errorMsg;

            if (!this._stackFrame.TryParseText(pszCode, out errorMsg))
            {
                pbstrError = "Error: " + errorMsg;
                pichError  = (uint)pbstrError.Length;
            }

            ppExpr = new UncalculatedAD7Expression(this, pszCode);
            return(VSConstants.S_OK);
        }
Beispiel #3
0
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string code,
                                               enum_PARSEFLAGS dwFlags,
                                               uint nRadix,
                                               out IDebugExpression2 expression,
                                               out string error,
                                               out uint pichError)
        {
            var frame = this.frame();

            error     = null;
            pichError = 0;
            try
            {
                if (frame.ValidateExpression(code))
                {
                    var value = frame.GetExpressionValue(code, EvaluationOptions.DefaultOptions);
                    expression = new MonoExpression(engine, thread, code, value);
                    return(VSConstants.S_OK);
                }
                else
                {
                    expression = null;
                    return(VSConstants.S_FALSE);
                }
            }
            catch (Exception e)
            {
                expression = null;
                Debug.WriteLine("Unexpected exception during Attach: \r\n" + e);
                return(VSConstants.S_FALSE);
            }
        }
            // Token: 0x060001F8 RID: 504 RVA: 0x00006E30 File Offset: 0x00005030
            int IDebugExpressionContext2.ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError)
            {
                EvaluationOptions defaultOptions = StackFrame.DefaultOptions;

                defaultOptions.AllowMethodEvaluation   = false;
                defaultOptions.AllowTargetInvoke       = false;
                defaultOptions.AllowToStringCalls      = false;
                defaultOptions.EvaluationTimeout       = 1000;
                defaultOptions.MemberEvaluationTimeout = 1000;
                if (nRadix == 16U)
                {
                    defaultOptions.IntegerDisplayFormat = IntegerDisplayFormat.Hexadecimal;
                }
                else
                {
                    defaultOptions.IntegerDisplayFormat = IntegerDisplayFormat.Decimal;
                }
                ValidationResult validationResult = this.Frame.Frame.ValidateExpression(pszCode, defaultOptions);

                if (!validationResult.IsValid)
                {
                    pbstrError = validationResult.Message;
                    pichError  = 0U;
                    ppExpr     = null;
                    return(1);
                }
                pbstrError = null;
                pichError  = 0U;
                ppExpr     = new StackFrame.Expression(this.Frame, pszCode);
                return(0);
            }
Beispiel #5
0
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode,
                                               enum_PARSEFLAGS dwFlags,
                                               uint nRadix,
                                               out IDebugExpression2 ppExpr,
                                               out string pbstrError,
                                               out uint pichError)
        {
            pbstrError = null;
            pichError  = 0;
            ppExpr     = null;

            try
            {
                // we have no "parser" as such, so we accept anything that isn't blank and let the Evaluate method figure out the errors
                ppExpr = new AD7Expression(Engine, Engine.DebuggedProcess.Natvis.GetVariable(pszCode, this));
                return(Constants.S_OK);
            }
            catch (MIException e)
            {
                return(e.HResult);
            }
            catch (Exception e)
            {
                return(EngineUtils.UnexpectedException(e));
            }
        }
Beispiel #6
0
 int IDebugExpressionContext2.ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError)
 {
     pbstrError = "";
     pichError  = 0;
     ppExpr     = new AD7Expression(this, pszCode);
     return(VSConstants.S_OK);
 }
Beispiel #7
0
 public int Parse(string upstrExpression, enum_PARSEFLAGS dwFlags, uint nRadix, out string pbstrError, out uint pichError, out IDebugParsedExpression ppParsedExpression)
 {
     pbstrError         = "";
     pichError          = 0;
     ppParsedExpression = null;
     return(VSConstants.E_NOTIMPL);
 }
Beispiel #8
0
 public int Parse(string upstrExpression, enum_PARSEFLAGS dwFlags, uint nRadix, out string pbstrError, out uint pichError, out IDebugParsedExpression ppParsedExpression)
 {
     pbstrError = "";
     pichError = 0;
     ppParsedExpression = null;
     return VSConstants.E_NOTIMPL;
 }
Beispiel #9
0
        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr,
                             out string pbstrError, out uint pichError)
        {
            pbstrError = "";
            pichError  = 0;
            ppExpr     = null;
            string lookup = pszCode;

            Debug.WriteLine($"ParseText(pszCode={pszCode}, dwFlags={dwFlags}, nRadix={nRadix})");
            try
            {
                //##############
                // Step01: local
                //##############

                var local = ThreadContext.Method.GetLocals().Where(x => x.Name == pszCode).FirstOrDefault();
                if (local != null)
                {
                    //Debug.WriteLine($"=> ParseText.LocalVariable: pszCode={pszCode}, Name={local?.Name}, Type={local?.Type?.FullName}");
                    ppExpr = new AD7Expression(new MonoProperty(ThreadContext, local));
                    return(VSConstants.S_OK);
                }

                //##############################
                // Step02: fields and properties
                //##############################

                var declaringType = ThreadContext.Method?.DeclaringType;
                if (declaringType != null)
                {
                    var field = declaringType.GetFields().Where(x => x.Name == pszCode).FirstOrDefault();

                    if (field != null)
                    {
                        //Debug.WriteLine($"=> ParseText.Field: pszCode={pszCode}, Name={field?.Name}, Type={field?.FieldType?.FullName}");
                        ppExpr = new AD7Expression(new MonoProperty(ThreadContext, field));
                        return(VSConstants.S_OK);
                    }

                    var property = declaringType.GetProperties().Where(x => x.Name == pszCode).FirstOrDefault();

                    if (property != null)
                    {
                        //Debug.WriteLine($"=> ParseText.Property: pszCode={pszCode}, Name={property?.Name}, Type={property?.PropertyType?.FullName}");
                        ppExpr = new AD7Expression(new MonoProperty(ThreadContext, property));
                        return(VSConstants.S_OK);
                    }
                }
            }
            catch (Exception ex)
            {
                pbstrError = "Error: " + ex.Message;
                pichError  = (uint)pbstrError.Length;
                return(VSConstants.S_FALSE);
            }

            pbstrError = "Unsupported Expression";
            pichError  = (uint)pbstrError.Length;
            return(VSConstants.S_FALSE);
        }
Beispiel #10
0
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode,
                                               enum_PARSEFLAGS dwFlags,
                                               uint nRadix,
                                               out IDebugExpression2 ppExpr,
                                               out string pbstrError,
                                               out uint pichError)
        {
            pbstrError = null;
            pichError  = 0;
            ppExpr     = null;

            try
            {
                ppExpr = new AD7Expression(Engine, new VariableInformation(pszCode, ThreadContext, Engine, Thread));
                return(VSConstants.S_OK);
            }
            catch (MIException e)
            {
                return(e.HResult);
            }
            catch (Exception e)
            {
                return(EngineUtils.UnexpectedException(e));
            }
        }
Beispiel #11
0
        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr,
                             out string pbstrError, out uint pichError)
        {
            pbstrError = "";
            pichError  = 0;
            ppExpr     = null;
            ILProperty prop;

            if (propertyMapping.TryGetValue(pszCode, out prop))
            {
                ppExpr = new AD7Expression(prop);
                return(Constants.S_OK);
            }

            /*string lookup = pszCode;
             *
             *
             * LocalVariable result = ThreadContext.GetVisibleVariableByName(lookup);
             * if (result != null)
             * {
             *  ppExpr = new AD7Expression(new MonoProperty(ThreadContext, result));
             *  return VSConstants.S_OK;
             * }
             */
            pbstrError = "Unsupported Expression";
            pichError  = (uint)pbstrError.Length;
            return(Constants.S_FALSE);
        }
        /// <summary>
        /// Parses an expression in text form for later evaluation.
        /// </summary>
        /// <param name="pszCode">The expression to be parsed.</param>
        /// <param name="dwFlags">A combination of flags from the PARSEFLAGS enumeration that controls parsing.</param>
        /// <param name="nRadix">The radix to be used in parsing any numerical information in pszCode.</param>
        /// <param name="ppExpr">Returns the IDebugExpression2 object that represents the parsed expression, which is ready for binding and evaluation.</param>
        /// <param name="pbstrError">Returns the error message if the expression contains an error.</param>
        /// <param name="pichError">Returns the character index of the error in pszCode if the expression contains an error.</param>
        /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns>
        /// <remarks>
        /// When this method is called, a debug engine (DE) should parse the expression and validate it for correctness.
        /// The pbstrError and pichError parameters may be filled in if the expression is invalid.
        /// 
        /// Note that the expression is not evaluated, only parsed. A later call to the IDebugExpression2.EvaluateSync
        /// or IDebugExpression2.EvaluateAsync methods evaluates the parsed expression.
        /// </remarks>
        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError)
        {
            if (pszCode == null)
                throw new ArgumentNullException("pszCode");
            if (pszCode.Length == 0)
                throw new ArgumentException();
            // dwFlags=0 in the Immediate window
            if (dwFlags != enum_PARSEFLAGS.PARSE_EXPRESSION && dwFlags != 0)
                throw new NotImplementedException();

            try
            {
                var expressionInput = new ANTLRStringStream(pszCode);
                var expressionUnicodeInput = new JavaUnicodeStream(expressionInput);
                var expressionLexer = new Java2Lexer(expressionUnicodeInput);
                var expressionTokens = new CommonTokenStream(expressionLexer);
                var expressionParser = new Java2Parser(expressionTokens);
                IAstRuleReturnScope<CommonTree> result = expressionParser.standaloneExpression();

                ppExpr = new JavaDebugExpression(this, result.Tree, pszCode);
                pbstrError = null;
                pichError = 0;
                return VSConstants.S_OK;
            }
            catch (RecognitionException e)
            {
                ppExpr = null;
                pbstrError = e.Message;
                pichError = (uint)Math.Max(0, e.Index);
                return VSConstants.E_FAIL;
            }
        }
 public int ParseText(string text, enum_PARSEFLAGS flags, uint radix,
                      out IDebugExpression2 expr, out string strError, out uint error)
 {
     strError = "";
     error    = 0;
     expr     = createExpressionDelegate.Invoke(lldbFrame, text, debugEngineHandler,
                                                debugProgram, thread);
     return(VSConstants.S_OK);
 }
Beispiel #14
0
        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr,
                             out string pbstrError, out uint pichError)
        {
            pbstrError = "";
            pichError  = 0;
            ppExpr     = null;

            Parser         parser = new Parser(pszCode);
            EvalExpression exp    = null;

            try
            {
                exp = parser.Parse();
            }
            catch (Exception ex)
            {
                pbstrError = ex.Message;
                pichError  = (uint)pbstrError.Length;
                return(Constants.S_FALSE);
            }
            ppExpr = new AD7Expression(this, exp, pszCode);
            return(Constants.S_OK);

            /*string[] names = pszCode.Split('.');
             * ILProperty root = null;
             * if(!propertyMapping.TryGetValue(names[0], out root))
             * {
             *  if (!propertyMapping.TryGetValue("this", out root))
             *  {
             *      pbstrError = "Unsupported Expression";
             *      pichError = (uint)pbstrError.Length;
             *      return Constants.S_FALSE;
             *  }
             * }
             *
             * if (names.Length < 2)
             * {
             *  ppExpr = new AD7Expression(root);
             *  return Constants.S_OK;
             * }
             * else
             * {
             *  ppExpr = new AD7Expression(Engine, Thread, root, names);
             *  return Constants.S_OK;
             * }*/
            /*string lookup = pszCode;
             *
             *
             * LocalVariable result = ThreadContext.GetVisibleVariableByName(lookup);
             * if (result != null)
             * {
             *  ppExpr = new AD7Expression(new MonoProperty(ThreadContext, result));
             *  return VSConstants.S_OK;
             * }
             */
        }
Beispiel #15
0
        /// <summary>
        /// This method allows us to hover variables and view their values when stopped in the debugger.
        /// </summary>
        /// <param name="pszCode"></param>
        /// <param name="dwFlags"></param>
        /// <param name="nRadix"></param>
        /// <param name="ppExpr"></param>
        /// <param name="pbstrError"></param>
        /// <param name="pichError"></param>
        /// <returns></returns>
        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError,
                             out uint pichError)
        {
            var variable = _debugger.GetVariable(pszCode);

            pbstrError = null;
            pichError  = 0;

            ppExpr = new ScriptExpression(_debugger, pszCode, variable);
            return(VSConstants.S_OK);
        }
Beispiel #16
0
        /// <summary>
        /// Parses an expression in text form for later evaluation.
        /// </summary>
        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError)
        {
            DLog.Debug(DContext.VSDebuggerComCall, "DebugStackFrame.ParseText");
            ppExpr     = null;
            pbstrError = null;
            pichError  = 0;

            // special registers group?
            if (pszCode.StartsWith("$reg", StringComparison.InvariantCultureIgnoreCase))
            {
                ppExpr = new DebugExpression(new DebugRegisterGroupProperty(this, false));
                return(VSConstants.S_OK);
            }

            // Try to match a local variable
            try
            {
                var locals        = GetValues();
                var localVariable = locals == null ? null : locals.FirstOrDefault(x => x.Name == pszCode);
                if (localVariable != null)
                {
                    ppExpr = new DebugExpression(new DebugStackFrameValueProperty(localVariable, null, this));
                    return(VSConstants.S_OK);
                }
            }
            catch
            {
            }

            // try to match any of the registers.
            var match = castRegisterExpression.Match(pszCode);

            if (match.Success)
            {
                var castExpr     = match.Groups[1].Value.Trim();
                var registerType = match.Groups[2].Value;
                int index        = int.Parse(match.Groups[3].Value);

                ppExpr = new DebugRegisterExpression(this, pszCode, registerType, index, castExpr);
                return(VSConstants.S_OK);
            }

            // try to match opcode help (in disassembly)
            var opHelp = Opcodes.Lookup(pszCode);

            if (opHelp != null)
            {
                ppExpr = new DebugExpression(new DebugConstProperty(pszCode, opHelp.Syntax + "\r\n\r\n" + opHelp.Arguments + "\r\n\r\n" + opHelp.Description, "(opcode)", null));
                return(VSConstants.S_OK);
            }

            return(VSConstants.E_FAIL);
        }
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode,
            enum_PARSEFLAGS dwFlags,
            uint nRadix,
            out IDebugExpression2 ppExpr,
            out string pbstrError,
            out uint pichError)
        {
            pbstrError = "";
            pichError = 0;
            ppExpr = null;

            try
            {
                if (m_parameters != null)
                {
                    foreach (VariableInformation currVariable in m_parameters)
                    {
                        if (String.CompareOrdinal(currVariable.m_name, pszCode) == 0)
                        {
                            ppExpr = new AD7Expression(currVariable);
                            return Constants.S_OK;
                        }
                    }
                }

                if (m_locals != null)
                {
                    foreach (VariableInformation currVariable in m_locals)
                    {
                        if (String.CompareOrdinal(currVariable.m_name, pszCode) == 0)
                        {
                            ppExpr = new AD7Expression(currVariable);
                            return Constants.S_OK;
                        }
                    }
                }

                pbstrError = "Invalid Expression";
                pichError = (uint)pbstrError.Length;
                return Constants.S_FALSE;
            }
            catch (ComponentException e)
            {
                return e.HResult;
            }
            catch (Exception e)
            {
                return EngineUtils.UnexpectedException(e);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError)
        {
            //
            // Parses an expression in text form for later evaluation.
            //

            LoggingUtils.PrintFunction();

            ppExpr = new DebuggeeExpression(m_debugEngine, this, pszCode, nRadix);

            pbstrError = string.Empty;

            pichError = (uint)pbstrError.Length;

            return(Constants.S_OK);
        }
Beispiel #19
0
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode,
                                               enum_PARSEFLAGS dwFlags,
                                               uint nRadix,
                                               out IDebugExpression2 ppExpr,
                                               out string pbstrError,
                                               out uint pichError)
        {
            pbstrError = "";
            pichError  = 0;
            ppExpr     = null;

            if (_parameters != null)
            {
                foreach (var currVariable in _parameters)
                {
                    if (String.CompareOrdinal(currVariable.Expression, pszCode) == 0)
                    {
                        ppExpr = new UncalculatedAD7Expression(this, currVariable.Expression, true);
                        return(VSConstants.S_OK);
                    }
                }
            }

            if (_locals != null)
            {
                foreach (var currVariable in _locals)
                {
                    if (String.CompareOrdinal(currVariable.Expression, pszCode) == 0)
                    {
                        ppExpr = new UncalculatedAD7Expression(this, currVariable.Expression, true);
                        return(VSConstants.S_OK);
                    }
                }
            }

            string errorMsg;

            if (!_stackFrame.TryParseText(pszCode, out errorMsg))
            {
                pbstrError = "Error: " + errorMsg;
                pichError  = (uint)pbstrError.Length;
            }

            ppExpr = new UncalculatedAD7Expression(this, pszCode);
            return(VSConstants.S_OK);
        }
Beispiel #20
0
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr,
                                               out string pbstrError,
                                               out uint pichError)
        {
            //System.Windows.Forms.AD7Util.MessageBox("pszCode: " + pszCode);
            pbstrError = "";
            pichError  = 0;
            ppExpr     = null;

            try
            {
                if (mParams != null)
                {
                    foreach (DebugLocalInfo currVariable in mParams)
                    {
                        if (String.CompareOrdinal(currVariable.Name, pszCode) == 0)
                        {
                            ppExpr = new AD7Expression(currVariable, mProcess, this);
                            return(VSConstants.S_OK);
                        }
                    }
                }

                if (mLocals != null)
                {
                    foreach (DebugLocalInfo currVariable in mLocals)
                    {
                        if (String.CompareOrdinal(currVariable.Name, pszCode) == 0)
                        {
                            ppExpr = new AD7Expression(currVariable, mProcess, this);
                            return(VSConstants.S_OK);
                        }
                    }
                }

                pbstrError = "Invalid Expression";
                pichError  = (uint)pbstrError.Length;
                return(VSConstants.S_FALSE);
            }
            catch (Exception e)
            {
                return(EngineUtils.UnexpectedException(e));
            }
        }
Beispiel #21
0
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode,
                                               enum_PARSEFLAGS dwFlags,
                                               uint nRadix,
                                               out IDebugExpression2 ppExpr,
                                               out string pbstrError,
                                               out uint pichError)
        {
            pbstrError = "";
            pichError  = 0;
            ppExpr     = null;

            if (_parameters != null)
            {
                foreach (PythonEvaluationResult currVariable in _parameters)
                {
                    if (String.CompareOrdinal(currVariable.Expression, pszCode) == 0)
                    {
                        ppExpr = new UncalculatedAD7Expression(this, currVariable.Expression, true);
                        return(VSConstants.S_OK);
                    }
                }
            }

            if (_locals != null)
            {
                foreach (PythonEvaluationResult currVariable in _locals)
                {
                    if (String.CompareOrdinal(currVariable.Expression, pszCode) == 0)
                    {
                        ppExpr = new UncalculatedAD7Expression(this, currVariable.Expression, true);
                        return(VSConstants.S_OK);
                    }
                }
            }

            if (!_stackFrame.TryParseText(pszCode, out global::System.String errorMsg))
            {
                pbstrError = Strings.DebugStackFrameParseTextError.FormatUI(errorMsg);
                pichError  = (uint)pbstrError.Length;
            }

            ppExpr = new UncalculatedAD7Expression(this, pszCode);
            return(VSConstants.S_OK);
        }
Beispiel #22
0
        /// <summary>
        /// Parses an expression in text form for later evaluation.
        /// </summary>
        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError)
        {
            DLog.Debug(DContext.VSDebuggerComCall, "DebugStackFrame.ParseText");
            ppExpr     = null;
            pbstrError = null;
            pichError  = 0;

            // Try to match a local variable
            var locals        = GetValues();
            var localVariable = locals.FirstOrDefault(x => x.Name == pszCode);

            if (localVariable != null)
            {
                ppExpr = new DebugExpression(new DebugValueProperty(localVariable, null));
                return(VSConstants.S_OK);
            }

            return(VSConstants.E_FAIL);
        }
        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr,
            out string pbstrError, out uint pichError)
        {
            pbstrError = "";
            pichError = 0;
            ppExpr = null;
            string lookup = pszCode;


            LocalVariable result = ThreadContext.GetVisibleVariableByName(lookup);
            if (result != null)
            {
                ppExpr = new AD7Expression(new MonoProperty(ThreadContext, result));
                return VSConstants.S_OK;
            }

            pbstrError = "Unsupported Expression";
            pichError = (uint)pbstrError.Length;
            return VSConstants.S_FALSE;
        }
Beispiel #24
0
        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr,
                             out string pbstrError, out uint pichError)
        {
            pbstrError = "";
            pichError  = 0;
            ppExpr     = null;
            string[]   names = pszCode.Split('.');
            ILProperty root  = null;

            if (!propertyMapping.TryGetValue(names[0], out root))
            {
                if (!propertyMapping.TryGetValue("this", out root))
                {
                    pbstrError = "Unsupported Expression";
                    pichError  = (uint)pbstrError.Length;
                    return(Constants.S_FALSE);
                }
            }

            if (names.Length < 2)
            {
                ppExpr = new AD7Expression(root);
                return(Constants.S_OK);
            }
            else
            {
                ppExpr = new AD7Expression(Engine, root, names);
                return(Constants.S_OK);
            }

            /*string lookup = pszCode;
             *
             *
             * LocalVariable result = ThreadContext.GetVisibleVariableByName(lookup);
             * if (result != null)
             * {
             *  ppExpr = new AD7Expression(new MonoProperty(ThreadContext, result));
             *  return VSConstants.S_OK;
             * }
             */
        }
Beispiel #25
0
        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr,
                             out string pbstrError, out uint pichError)
        {
            pbstrError = "";
            pichError  = 0;
            ppExpr     = null;
            string lookup = pszCode;


            LocalVariable result = frame.GetVisibleVariableByName(lookup);

            if (result != null)
            {
                ppExpr = new TrivialMonoExpression(new MonoProperty(frame, result));
                return(VSConstants.S_OK);
            }

            pbstrError = "Unsupported Expression";
            pichError  = (uint)pbstrError.Length;
            return(VSConstants.S_FALSE);
        }
 int IDebugExpressionContext2.ParseText(
   string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, 
   out IDebugExpression2 ppExpr, 
   out string pbstrError, out uint pichError)
 {
   pbstrError = null;
   ppExpr = null;
   pichError = 0;
   try
   {
     AD7DebugExpression expr = new AD7DebugExpression(_stackFrame, pszCode);
     bool success = DebuggerManager.Instance.Debugger.TryParseExpression(pszCode, out pbstrError);
     if (success)
       ppExpr = (IDebugExpression2)expr;
   }
   catch (Exception e)
   {
     pbstrError = e.Message;
     return VSConstants.E_FAIL;
   }
   return VSConstants.S_OK;
 }
Beispiel #27
0
        /// <summary>
        /// Parses an expression in text form for later evaluation.
        /// </summary>
        /// <param name="pszCode">The expression to be parsed.</param>
        /// <param name="dwFlags">A combination of flags from the PARSEFLAGS enumeration that controls parsing.</param>
        /// <param name="nRadix">The radix to be used in parsing any numerical information in pszCode.</param>
        /// <param name="ppExpr">Returns the IDebugExpression2 object that represents the parsed expression, which is ready for binding and evaluation.</param>
        /// <param name="pbstrError">Returns the error message if the expression contains an error.</param>
        /// <param name="pichError">Returns the character index of the error in pszCode if the expression contains an error.</param>
        /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns>
        /// <remarks>
        /// When this method is called, a debug engine (DE) should parse the expression and validate it for correctness.
        /// The pbstrError and pichError parameters may be filled in if the expression is invalid.
        ///
        /// Note that the expression is not evaluated, only parsed. A later call to the IDebugExpression2.EvaluateSync
        /// or IDebugExpression2.EvaluateAsync methods evaluates the parsed expression.
        /// </remarks>
        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError)
        {
            if (pszCode == null)
            {
                throw new ArgumentNullException("pszCode");
            }
            if (pszCode.Length == 0)
            {
                throw new ArgumentException();
            }
            // dwFlags=0 in the Immediate window
            if (dwFlags != enum_PARSEFLAGS.PARSE_EXPRESSION && dwFlags != 0)
            {
                throw new NotImplementedException();
            }

            try
            {
                var expressionInput        = new ANTLRStringStream(pszCode);
                var expressionUnicodeInput = new JavaUnicodeStream(expressionInput);
                var expressionLexer        = new Java2Lexer(expressionUnicodeInput);
                var expressionTokens       = new CommonTokenStream(expressionLexer);
                var expressionParser       = new Java2Parser(expressionTokens);
                IAstRuleReturnScope <CommonTree> result = expressionParser.standaloneExpression();

                ppExpr     = new JavaDebugExpression(this, result.Tree, pszCode);
                pbstrError = null;
                pichError  = 0;
                return(VSConstants.S_OK);
            }
            catch (RecognitionException e)
            {
                ppExpr     = null;
                pbstrError = e.Message;
                pichError  = (uint)Math.Max(0, e.Index);
                return(VSConstants.E_FAIL);
            }
        }
Beispiel #28
0
 int IDebugExpressionContext2.ParseText(
     string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix,
     out IDebugExpression2 ppExpr,
     out string pbstrError, out uint pichError)
 {
     pbstrError = null;
     ppExpr     = null;
     pichError  = 0;
     try
     {
         AD7DebugExpression expr = new AD7DebugExpression(_stackFrame, pszCode);
         bool success            = DebuggerManager.Instance.Debugger.TryParseExpression(pszCode, out pbstrError);
         if (success)
         {
             ppExpr = (IDebugExpression2)expr;
         }
     }
     catch (Exception e)
     {
         pbstrError = e.Message;
         return(VSConstants.E_FAIL);
     }
     return(VSConstants.S_OK);
 }
Beispiel #29
0
        // Parses a text-based expression for evaluation.
        int IDebugExpressionContext2.ParseText(string pszCode,
                                               enum_PARSEFLAGS dwFlags,
                                               uint nRadix,
                                               out IDebugExpression2 ppExpr,
                                               out string pbstrError,
                                               out uint pichError)
        {
            pbstrError = "";
            pichError  = 0;
            ppExpr     = null;

            try
            {
                // Check if the expression belongs to the parameters
                foreach (var currVariable in _parameters)
                {
                    if (String.CompareOrdinal(currVariable.Name, pszCode) == 0)
                    {
                        ppExpr = new XamarinExpression(_engine, _thread, currVariable);
                        return(VisualStudioExtensionConstants.S_OK);
                    }
                }

                // Check if the expression belongs to the locals
                foreach (var currVariable in _locals)
                {
                    if (String.CompareOrdinal(currVariable.Name, pszCode) == 0)
                    {
                        ppExpr = new XamarinExpression(_engine, _thread, currVariable);
                        return(VisualStudioExtensionConstants.S_OK);
                    }
                }

                if (_thisObject != null)
                {
                    // Are we looking for "this"?
                    if (String.CompareOrdinal("this", pszCode) == 0)
                    {
                        ppExpr = new XamarinExpression(_engine, _thread, _thisObject);
                        return(VisualStudioExtensionConstants.S_OK);
                    }

                    // Lastly, check if it's a member of this
                    var parsedExpression = ParseThisInternals(_thisObject, pszCode);
                    if (parsedExpression != null)
                    {
                        ppExpr = parsedExpression;
                        return(VisualStudioExtensionConstants.S_OK);
                    }
                }

                pbstrError = "Invalid Expression";
                pichError  = (uint)pbstrError.Length;
                return(VisualStudioExtensionConstants.S_FALSE);
            }
            catch (ComponentException e)
            {
                return(e.HResult);
            }
            catch (Exception e)
            {
                NLogService.Logger.Error(e);
                return(VisualStudioExtensionConstants.S_FALSE);
            }
        }
Beispiel #30
0
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode,
            enum_PARSEFLAGS dwFlags,
            uint nRadix,
            out IDebugExpression2 ppExpr,
            out string pbstrError,
            out uint pichError)
        {
            //            pbstrError = "";
            //            pichError = 0;
            //            ppExpr = null;

            //            return VSConstants.E_NOTIMPL;

            pbstrError = "";
            pichError = 0;
            ppExpr = null;

            // Parse here, if needed: verify if it is a valid expression, and store the parsed results into VariableInfo, or create another object.
            // if not: send a GDB command to evaluate the expression pszCode. It should return the result or an error message.
            // This object is indirectly sent to IDebugExpression2.EvaluateAsync
            // if pszCode is a variable, it must be found in Locals.

            //            VariableInfo vi = new VariableInfo(pszCode,"","");
            ppExpr = new AD7Expression(pszCode, this, m_engine.eDispatcher);
            return VSConstants.S_OK;
        }
Beispiel #31
0
 int IDebugExpressionContext2.ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError) {
     pbstrError = "";
     pichError = 0;
     ppExpr = new AD7Expression(this, pszCode);
     return VSConstants.S_OK;
 }
Beispiel #32
0
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode,
                                               enum_PARSEFLAGS dwFlags,
                                               uint nRadix,
                                               out IDebugExpression2 ppExpr,
                                               out string pbstrError,
                                               out uint pichError)
        {
            pbstrError = "";
            pichError = 0;

            if (_parameters != null)
            {
                foreach (NodeEvaluationResult currVariable in _parameters)
                {
                    if (String.CompareOrdinal(currVariable.Name, pszCode) == 0)
                    {
                        ppExpr = new AD7Expression(this, currVariable.Name);
                        return VSConstants.S_OK;
                    }
                }
            }

            if (_locals != null)
            {
                foreach (NodeEvaluationResult currVariable in _locals)
                {
                    if (String.CompareOrdinal(currVariable.Name, pszCode) == 0)
                    {
                        ppExpr = new AD7Expression(this, currVariable.Name);
                        return VSConstants.S_OK;
                    }
                }
            }

            string errorMsg;
            if (!_stackFrame.TryParseText(pszCode, out errorMsg))
            {
                pbstrError = "Error: " + errorMsg;
                pichError = (uint) pbstrError.Length;
            }

            ppExpr = new AD7Expression(this, pszCode);
            return VSConstants.S_OK;
        }
Beispiel #33
0
    // Parses a text-based expression for evaluation.
    // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
    int IDebugExpressionContext2.ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr,
                                            out string pbstrError,
                                            out uint pichError) {
      //System.Windows.Forms.MessageBox.Show("pszCode: " + pszCode);
      pbstrError = "";
      pichError = 0;
      ppExpr = null;

      try {
        if (mParams != null) {
          foreach (DebugLocalInfo currVariable in mParams) {
            if (String.CompareOrdinal(currVariable.Name, pszCode) == 0) {
              ppExpr = new AD7Expression(currVariable, mProcess, this);
              return VSConstants.S_OK;
            }
          }
        }

        if (mLocals != null) {
          foreach (DebugLocalInfo currVariable in mLocals) {
            if (String.CompareOrdinal(currVariable.Name, pszCode) == 0) {
              ppExpr = new AD7Expression(currVariable, mProcess, this);
              return VSConstants.S_OK;
            }
          }
        }

        pbstrError = "Invalid Expression";
        pichError = (uint)pbstrError.Length;
        return VSConstants.S_FALSE;
      } catch (Exception e) {
        return EngineUtils.UnexpectedException(e);
      }
    }
Beispiel #34
0
        /// <summary>
        /// Parses an expression in text form for later evaluation.
        /// </summary>
        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError)
        {
            DLog.Debug(DContext.VSDebuggerComCall, "DebugStackFrame.ParseText");
            ppExpr = null;
            pbstrError = null;
            pichError = 0;

            // special registers group?
            if (pszCode.StartsWith("$reg", StringComparison.InvariantCultureIgnoreCase))
            {
                ppExpr = new DebugExpression(new DebugRegisterGroupProperty(this, false));
                return VSConstants.S_OK;
            }

            // Try to match a local variable
            try
            {
                var locals = GetValues();
                var localVariable = locals == null ? null : locals.FirstOrDefault(x => x.Name == pszCode);
                if (localVariable != null)
                {
                    ppExpr = new DebugExpression(new DebugStackFrameValueProperty(localVariable, null, this));
                    return VSConstants.S_OK;
                }
            }
            catch
            {
            }

            // try to match any of the registers.
            var match = castRegisterExpression.Match(pszCode);
            if (match.Success)
            {
                var castExpr = match.Groups[1].Value.Trim();
                var registerType = match.Groups[2].Value;
                int index = int.Parse(match.Groups[3].Value);

                ppExpr = new DebugRegisterExpression(this, pszCode, registerType, index, castExpr);
                return VSConstants.S_OK;
            }

            // try to match opcode help (in disassembly)
            var opHelp = Opcodes.Lookup(pszCode);
            if (opHelp != null)
            {
                ppExpr = new DebugExpression(new DebugConstProperty(pszCode, opHelp.Syntax + "\r\n\r\n" + opHelp.Arguments + "\r\n\r\n" + opHelp.Description, "(opcode)", null));
                return VSConstants.S_OK;
            }

            return VSConstants.E_FAIL;
        }
Beispiel #35
0
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode,
                                                enum_PARSEFLAGS dwFlags, 
                                                uint nRadix, 
                                                out IDebugExpression2 ppExpr, 
                                                out string pbstrError, 
                                                out uint pichError)
        {
            pbstrError = "";
            pichError = 0;
            ppExpr = null;

            if(IsDebuggingNPL())
            {
                VariableInformation varInfo = VariableInformation.Create(m_engine.DebuggedProcess, pszCode);
                if (varInfo!=null)
                {
                    ppExpr = new AD7Expression(varInfo);
                    return Constants.S_OK;
                }
                else
                {
                    return Constants.S_FALSE;
                }
            }

            try
            {
                if (m_parameters != null)
                {
                    foreach (VariableInformation currVariable in m_parameters)
                    {
                        if (String.CompareOrdinal(currVariable.m_name, pszCode) == 0)
                        {
                            ppExpr = new AD7Expression(currVariable);
                            return Constants.S_OK;
                        }
                    }
                }

                if (m_locals != null)
                {
                    foreach (VariableInformation currVariable in m_locals)
                    {
                        if (String.CompareOrdinal(currVariable.m_name, pszCode) == 0)
                        {
                            ppExpr = new AD7Expression(currVariable);
                            return Constants.S_OK;
                        }
                    }
                }

                pbstrError = "Invalid Expression";
                pichError = (uint)pbstrError.Length;
                return Constants.S_FALSE;
            }
            catch (ComponentException e)
            {
                return e.HResult;
            }
            catch (Exception e)
            {
                return EngineUtils.UnexpectedException(e);
            }
        }
Beispiel #36
0
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError)
        {
            pbstrError = "";
            pichError = 0;
            ppExpr = null;

            try {
                var localOrArg = m_parameters.Concat(m_locals).FirstOrDefault(v => String.CompareOrdinal(v.m_name, pszCode) == 0);
                if (localOrArg != null) {
                    ppExpr = new AD7Property(localOrArg);
                    return Constants.S_OK;
                }
                var result = m_engine.DebuggedProcess.Evaluate(m_threadContext, pszCode, out pbstrError);
                if (result != null) {
                    ppExpr = new AD7Property(result);
                    return Constants.S_OK;
                }
                pichError = (uint)pbstrError.Length;
                return Constants.S_FALSE;
            } catch (Exception e) {
                return EngineUtils.UnexpectedException(e);
            }
        }
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode,
                                               enum_PARSEFLAGS dwFlags,
                                               uint nRadix,
                                               out IDebugExpression2 ppExpr,
                                               out string pbstrError,
                                               out uint pichError)
        {
            pbstrError = "";
            pichError  = 0;
            ppExpr     = null;
            if (pszCode.Length == 0)
            {
                pbstrError = "Invalid Expression";
                pichError  = (uint)pbstrError.Length;
                return(EngineConstants.S_FALSE);
            }

            try
            {
                bool iswatch = true;
                //HACK WARNING
                //I put a $ in front of the expression so I know that is not a watch in
                //is done by SquirrelAuthoringScope::GetDataTipText (alberto)
                if (pszCode[0] == '$')
                {
                    Debug.WriteLine("!Evaluating " + pszCode);
                    iswatch = false;
                    pszCode = pszCode.Substring(1);
                    if (pszCode.Length == 0)
                    {
                        pbstrError = "Invalid Expression";
                        pichError  = (uint)pbstrError.Length;
                        return(EngineConstants.S_FALSE);
                    }
                }
                if (sqframe.Locals != null)
                {
                    Debug.WriteLine("Evaluating " + pszCode);
                    string[]            targets = pszCode.Split(new char[] { '.' });
                    SquirrelDebugObject val;
                    if (EvaluateSquirrelObject(sqframe.Locals, targets, 0, out val))
                    {
                        ppExpr = new AD7Expression(new SquirrelDebugObject(pszCode, val.Value));

                        return(EngineConstants.S_OK);
                    }

                    if (targets[0] != "this")
                    {
                        List <string> trgswiththis = new List <string>();
                        trgswiththis.Add("this");
                        trgswiththis.AddRange(targets);
                        if (EvaluateSquirrelObject(sqframe.Locals, trgswiththis.ToArray(), 0, out val))
                        {
                            ppExpr = new AD7Expression(new SquirrelDebugObject(pszCode, val.Value));
                            Debug.WriteLine("Succeeded with 'this'" + pszCode);
                            return(EngineConstants.S_OK);
                        }
                    }
                }

                //if(sqframe.Watches.ContainsKey(pszCode))
                if (iswatch)
                {
                    ctx.AddWatch(pszCode);
                    SquirrelDebugObject val;
                    if (sqframe.Watches.TryGetValue(pszCode, out val))
                    {
                        ppExpr = new AD7Expression(val);
                        return(EngineConstants.S_OK);
                    }
                }


                pbstrError = "Invalid Expression";
                pichError  = (uint)pbstrError.Length;
                return(EngineConstants.S_FALSE);
            }
            catch (ComponentException e)
            {
                return(e.HRESULT);
            }
            catch (Exception e)
            {
                return(EngineUtils.UnexpectedException(e));
            }
        }
Beispiel #38
0
        /// <summary>
        /// Parses an expression in text form for later evaluation.
        /// </summary>
        public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError)
        {
            DLog.Debug(DContext.VSDebuggerComCall, "DebugStackFrame.ParseText");
            ppExpr = null;
            pbstrError = null;
            pichError = 0;

            // Try to match a local variable
            var locals = GetValues();
            var localVariable = locals.FirstOrDefault(x => x.Name == pszCode);
            if (localVariable != null)
            {
                ppExpr = new DebugExpression(new DebugValueProperty(localVariable, null));
                return VSConstants.S_OK;
            }

            return VSConstants.E_FAIL;
        }
Beispiel #39
0
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode,
            enum_PARSEFLAGS dwFlags,
            uint nRadix,
            out IDebugExpression2 ppExpr,
            out string pbstrError,
            out uint pichError) {
            pbstrError = String.Empty;
            pichError = 0;

            IEnumerable<NodeEvaluationResult> evaluationResults = _stackFrame.Locals.Union(_stackFrame.Parameters);
            foreach (NodeEvaluationResult currVariable in evaluationResults) {
                if (String.CompareOrdinal(currVariable.Expression, pszCode) == 0) {
                    ppExpr = new UncalculatedAD7Expression(this, currVariable.Expression);
                    return VSConstants.S_OK;
                }
            }

            string errorMsg;
            if (!_stackFrame.TryParseText(pszCode, out errorMsg)) {
                pbstrError = "Error: " + errorMsg;
                pichError = (uint)pbstrError.Length;
            }

            ppExpr = new UncalculatedAD7Expression(this, pszCode);
            return VSConstants.S_OK;
        }
Beispiel #40
0
        // Parses a text-based expression for evaluation.
        // The engine sample only supports locals and parameters so the only task here is to check the names in those collections.
        int IDebugExpressionContext2.ParseText(string pszCode,
                                                enum_PARSEFLAGS dwFlags,
                                                uint nRadix,
                                                out IDebugExpression2 ppExpr,
                                                out string pbstrError,
                                                out uint pichError)
        {
            pbstrError = null;
            pichError = 0;
            ppExpr = null;

            try
            {
                // we have no "parser" as such, so we accept anything that isn't blank and let the Evaluate method figure out the errors
                ppExpr = new AD7Expression(Engine.DebuggedProcess.Natvis.GetVariable(pszCode, this));
                return Constants.S_OK;
            }
            catch (MIException e)
            {
                return e.HResult;
            }
            catch (Exception e)
            {
                return EngineUtils.UnexpectedException(e);
            }
        }
Beispiel #41
0
 public int ParseText(string pszCode, enum_PARSEFLAGS dwFlags, uint nRadix, out IDebugExpression2 ppExpr, out string pbstrError, out uint pichError)
 {
     ppExpr = null;
     pbstrError = "";
     pichError = 0;
     return VSConstants.E_NOTIMPL;
 }