Ejemplo n.º 1
0
        protected override ITargetObject DoEvaluateVariable(EvaluationContext context)
        {
            FrameHandle frame = context.CurrentFrame;

            TargetLocation location = EvaluateAddress (context);
            return frame.Language.CreatePointer (frame.Frame, location.Address);
        }
Ejemplo n.º 2
0
 public override TargetLocation EvaluateAddress(EvaluationContext context)
 {
     ITargetObject obj = expr.EvaluateVariable (context);
     if (!obj.Location.HasAddress)
         throw new EvaluationException (
             "Cannot take address of expression `{0}'", expr.Name);
     return obj.Location;
 }
Ejemplo n.º 3
0
        protected override ITargetType DoEvaluateType(EvaluationContext context)
        {
            FrameHandle frame = context.CurrentFrame;

            ITargetPointerType ptype = expr.EvaluateType (context)
                as ITargetPointerType;
            if (ptype != null)
                return ptype;

            return frame.Language.PointerType;
        }
Ejemplo n.º 4
0
        protected override ITargetObject DoEvaluateVariable(EvaluationContext context)
        {
            bool cond = false;

              try {
            cond = (bool) this.test.Evaluate (context);
              }
              catch (Exception e) {
            throw new EvaluationException (
               "Cannot convert {0} to a boolean for conditional: {1}",
               this.test, e);
              }

              return cond ? true_expr.EvaluateVariable (context) : false_expr.EvaluateVariable (context);
        }
Ejemplo n.º 5
0
        public static ITargetMethodInfo OverloadResolve(EvaluationContext context,
								 ILanguage language,
								 ITargetStructType stype,
								 Expression[] types,
								 ArrayList candidates)
        {
            // We do a very simple overload resolution here
            ITargetType[] argtypes = new ITargetType [types.Length];
            for (int i = 0; i < types.Length; i++)
                argtypes [i] = types [i].EvaluateType (context);

            // Ok, no we need to find an exact match.
            ITargetMethodInfo match = null;
            foreach (ITargetMethodInfo method in candidates) {
                bool ok = true;
                for (int i = 0; i < types.Length; i++) {
                    if (method.Type.ParameterTypes [i].TypeHandle != argtypes [i].TypeHandle) {
                        ok = false;
                        break;
                    }
                }

                if (!ok)
                    continue;

                // We need to find exactly one match
                if (match != null)
                    return null;

                match = method;
            }

            return match;
        }
Ejemplo n.º 6
0
 protected override Expression DoResolve(EvaluationContext context)
 {
     return ResolveMemberAccess (context, false);
 }
Ejemplo n.º 7
0
        public Expression ResolveMemberAccess(EvaluationContext context, bool allow_instance)
        {
            StackFrame frame = context.CurrentFrame.Frame;

            Expression expr;
            Expression ltype = left.TryResolveType (context);
            if (ltype != null) {
                ITargetStructType stype = ltype.EvaluateType (context)
                    as ITargetStructType;
                if (stype == null)
                    throw new EvaluationException (
                        "`{0}' is not a struct or class", ltype.Name);

                expr = StructAccessExpression.FindMember (
                    stype, frame, null, allow_instance, name);
                if (expr == null)
                    throw new EvaluationException (
                        "Type `{0}' has no member `{1}'",
                        stype.Name, name);

                return expr;
            }

            Expression lexpr = left.TryResolve (context);
            if (lexpr == null)
                throw new EvaluationException (
                    "No such variable or type: `{0}'", left.Name);

            ITargetStructObject sobj = lexpr.EvaluateVariable (context)
                as ITargetStructObject;
            if (sobj == null)
                throw new EvaluationException (
                    "`{0}' is not a struct or class", left.Name);

            expr = StructAccessExpression.FindMember (
                sobj.Type, frame, sobj, true, name);
            if (expr == null)
                throw new EvaluationException (
                    "Type `{0}' has no member `{1}'",
                    sobj.Type.Name, name);

            return expr;
        }
Ejemplo n.º 8
0
 protected override ITargetObject DoEvaluateVariable(EvaluationContext context)
 {
     return Invoke (context, false);
 }
Ejemplo n.º 9
0
 protected virtual Expression DoResolveType(EvaluationContext context)
 {
     return null;
 }
Ejemplo n.º 10
0
        public ITargetObject EvaluateVariable(EvaluationContext context)
        {
            if (!resolved)
                throw new InvalidOperationException (
                    String.Format (
                        "Some clown tried to evaluate the " +
                        "unresolved expression `{0}' ({1})", Name,
                        GetType ()));

            try {
                ITargetObject retval = DoEvaluateVariable (context);
                if (retval == null)
                    throw new EvaluationException (
                        "Expression `{0}' is not a variable", Name);

                return retval;
            } catch (LocationInvalidException ex) {
                throw new EvaluationException (
                    "Location of variable `{0}' is invalid: {1}",
                    Name, ex.Message);
            }
        }
Ejemplo n.º 11
0
        public ITargetType EvaluateType(EvaluationContext context)
        {
            if (!resolved)
                throw new InvalidOperationException (
                    String.Format (
                        "Some clown tried to evaluate the " +
                        "unresolved expression `{0}'", Name));

            try {
                ITargetType type = DoEvaluateType (context);
                if (type == null)
                    throw new EvaluationException (
                        "Cannot get type of expression `{0}'", Name);

                return type;
            } catch (LocationInvalidException ex) {
                throw new EvaluationException (
                    "Location of variable `{0}' is invalid: {1}",
                    Name, ex.Message);
            }
        }
Ejemplo n.º 12
0
        public SourceLocation EvaluateLocation(EvaluationContext context, LocationType type,
							Expression [] types)
        {
            if (!resolved)
                throw new InvalidOperationException (
                    String.Format (
                        "Some clown tried to evaluate the " +
                        "unresolved expression `{0}'", Name));

            try {
                SourceLocation location = DoEvaluateLocation (context, type, types);
                if (location == null)
                    throw new EvaluationException (
                        "Expression `{0}' is not a method", Name);

                return location;
            } catch (LocationInvalidException ex) {
                throw new EvaluationException (
                    "Location of variable `{0}' is invalid: {1}",
                    Name, ex.Message);
            }
        }
Ejemplo n.º 13
0
        public object Evaluate(EvaluationContext context)
        {
            if (!resolved)
                throw new InvalidOperationException (
                    String.Format (
                        "Some clown tried to evaluate the " +
                        "unresolved expression `{0}'", Name));

            object result = DoEvaluate (context);
            if (result == null)
                throw new EvaluationException (
                    "Cannot evaluate expression `{0}'", Name);

            return result;
        }
Ejemplo n.º 14
0
        public void Assign(EvaluationContext context, ITargetObject obj)
        {
            if (!resolved)
                throw new InvalidOperationException (
                    String.Format (
                        "Some clown tried to evaluate the " +
                        "unresolved expression `{0}'", Name));

            bool ok = DoAssign (context, obj);
            if (!ok)
                throw new EvaluationException (
                    "Expression `{0}' is not an lvalue", Name);
        }
Ejemplo n.º 15
0
        protected override Expression DoResolve(EvaluationContext context)
        {
            test = test.Resolve (context);
            true_expr = true_expr.Resolve (context);
            false_expr = false_expr.Resolve (context);

            resolved = true;
            return this;
        }
Ejemplo n.º 16
0
 protected virtual ITargetObject DoEvaluateVariable(EvaluationContext context)
 {
     return null;
 }
Ejemplo n.º 17
0
 protected abstract Expression DoResolve(EvaluationContext context);
Ejemplo n.º 18
0
        public Expression ResolveType(EvaluationContext context)
        {
            Expression expr = DoResolveType (context);
            if (expr == null)
                throw new EvaluationException (
                    "Expression `{0}' is not a type.", Name);

            return expr;
        }
Ejemplo n.º 19
0
        public ITargetObject Invoke(EvaluationContext context, bool debug)
        {
            Expression[] args = new Expression [arguments.Length];
            for (int i = 0; i < arguments.Length; i++) {
                args [i] = arguments [i].Resolve (context);
                if (args [i] == null)
                    return null;
            }

            ITargetFunctionObject func = mg.EvaluateMethod (
                context, context.CurrentFrame.Frame, args);

            ITargetObject[] objs = new ITargetObject [args.Length];
            for (int i = 0; i < args.Length; i++)
                objs [i] = args [i].EvaluateVariable (context);

            try {
                ITargetObject retval = func.Invoke (objs, debug);
                if (!debug && !func.Type.HasReturnValue)
                    throw new EvaluationException ("Method `{0}' doesn't return a value.", Name);

                return retval;
            } catch (Mono.Debugger.TargetInvocationException ex) {
                throw new EvaluationException ("Invocation of `{0}' raised an exception: {1}", Name, ex.Message);
            }
        }
Ejemplo n.º 20
0
 public Expression TryResolveType(EvaluationContext context)
 {
     try {
         return DoResolveType (context);
     } catch (EvaluationException) {
         return null;
     } catch (Mono.Debugger.TargetException) {
         return null;
     }
 }
Ejemplo n.º 21
0
        protected override SourceLocation DoEvaluateLocation(EvaluationContext context,
								      LocationType type, Expression[] types)
        {
            Expression[] argtypes = new Expression [arguments.Length];
            for (int i = 0; i < arguments.Length; i++) {
                argtypes [i] = arguments [i].ResolveType (context);
                if (argtypes [i] == null)
                    return null;
            }

            return method_expr.EvaluateLocation (context, type, argtypes);
        }
Ejemplo n.º 22
0
 protected virtual bool DoAssign(EvaluationContext context, ITargetObject obj)
 {
     return false;
 }
Ejemplo n.º 23
0
        protected override Expression DoResolve(EvaluationContext context)
        {
            method_expr = method_expr.Resolve (context);
            if (method_expr == null)
                return null;

            mg = method_expr as MethodGroupExpression;
            if (mg == null)
                throw new EvaluationException (
                    "Expression `{0}' is not a method.", method_expr.Name);

            resolved = true;
            return this;
        }
Ejemplo n.º 24
0
 protected virtual object DoEvaluate(EvaluationContext context)
 {
     return DoEvaluateVariable (context);
 }
Ejemplo n.º 25
0
        protected override Expression DoResolve(EvaluationContext context)
        {
            expr = expr.Resolve (context);
            if (expr == null)
                return null;

            resolved = true;
            return this;
        }
Ejemplo n.º 26
0
        protected virtual SourceLocation DoEvaluateLocation(EvaluationContext context,
								     LocationType type, Expression[] types)
        {
            return null;
        }
Ejemplo n.º 27
0
        protected override Expression DoResolveType(EvaluationContext context)
        {
            StackFrame frame = context.CurrentFrame.Frame;

            ITargetType the_type;

            Expression ltype = left.TryResolveType (context);
            if (ltype == null)
                the_type = frame.Language.LookupType (frame, Name);
            else {
                string nested = ltype.Name + "+" + name;
                the_type = frame.Language.LookupType (frame, nested);
            }

            if (the_type == null)
                return null;

            return new TypeExpression (the_type);
        }
Ejemplo n.º 28
0
 protected virtual ITargetType DoEvaluateType(EvaluationContext context)
 {
     return EvaluateVariable (context).TypeInfo.Type;
 }
        public string EvaluateDebuggerDisplay(ITargetObject obj, string display)
        {
            StringBuilder sb = new StringBuilder ("");
            DebuggingService dbgr = (DebuggingService)Runtime.DebuggingService;
            EvaluationContext ctx = new EvaluationContext (obj);

            ctx.CurrentProcess = new ProcessHandle (dbgr.MainThread);

            /* break up the string into runs of {...} and
             * normal text.  treat the {...} as C#
             * expressions, and evaluate them */
            int start_idx = 0;

            while (true) {
                int left_idx;
                int right_idx;
                left_idx = display.IndexOf ('{', start_idx);

                if (left_idx == -1) {
                    /* we're done. */
                    sb.Append (display.Substring (start_idx));
                    break;
                }
                if (left_idx != start_idx) {
                    sb.Append (display.Substring (start_idx, left_idx - start_idx));
                }
                right_idx = display.IndexOf ('}', left_idx + 1);
                if (right_idx == -1) {
                    // '{...\0'.  ignore the '{', append the rest, and break out */
                    sb.Append (display.Substring (left_idx + 1));
                    break;
                }

                if (right_idx - left_idx > 1) {
                    /* there's enough space for an
                     * expression.  parse it and see
                     * what we get. */
                    RefParse.Parser parser;
                    AST.Expression ast_expr;
                    Expression dbgr_expr;
                    DebuggerASTVisitor visitor;
                    string snippet;
                    object retval;

                    /* parse the snippet to build up MD's AST */
                    parser = new RefParse.Parser();

                    snippet = display.Substring (left_idx + 1, right_idx - left_idx - 1);
                    ast_expr = parser.ParseExpression (new RefParse.Lexer (new RefParse.StringReader (snippet)));

                    /* use our visitor to convert from MD's AST to types that
                     * facilitate evaluation by the debugger */
                    visitor = new DebuggerASTVisitor ();
                    dbgr_expr = (Expression)ast_expr.AcceptVisitor (visitor, null);

                    /* finally, resolve and evaluate the expression */
                    dbgr_expr = dbgr_expr.Resolve (ctx);
                    retval = dbgr_expr.Evaluate (ctx);

            #region "c&p'ed from debugger/frontend/Style.cs"
                    if (retval is long) {
                        sb.Append (String.Format ("0x{0:x}", (long) retval));
                    }
                    else if (retval is string) {
                        sb.Append ('"' + (string) retval + '"');
                    }
                    else if (retval is ITargetObject) {
                        ITargetObject tobj = (ITargetObject) retval;
                        sb.Append (tobj.Print ());
                    }
                    else {
                        sb.Append (retval.ToString ());
                    }
            #endregion
                }

                start_idx = right_idx + 1;
            }

            return sb.ToString ();
        }
Ejemplo n.º 30
0
        static ITargetClassObject TryParentCast(EvaluationContext context,
							 ITargetClassObject source,
							 ITargetClassType source_type,
							 ITargetClassType target_type)
        {
            if (source_type == target_type)
                return source;

            if (!source_type.HasParent)
                return null;

            source = TryParentCast (
                context, source, source_type.ParentType, target_type);
            if (source == null)
                return null;

            return source.Parent;
        }