This interface provides information about a variable in the target application.
Inheritance: DebuggerMarshalByRefObject
		public VariableReference (EvaluationContext ctx, TargetVariable var, DC.ObjectValueFlags flags): base (ctx)
		{
			this.flags = flags;
			this.var = var;
			if (!var.CanWrite)
				flags |= DC.ObjectValueFlags.ReadOnly;
		}
		public static AbstractVariable Create(TargetVariable variable, StackFrame stackFrame)
		{
			TargetObject obj;
			
			try {
				obj = variable.GetObject(stackFrame);
			} catch {
				return new ErrorVariable(variable.Name, "Can not get object");
			}
			
			return Create(variable.Name, obj, stackFrame);
		}
Example #3
0
        public void FormatVariable(StackFrame frame, TargetVariable variable)
        {
            TargetObject obj = null;

            Append ("{0} = ", variable.Name);

            if (!variable.IsAlive (frame.TargetAddress)) {
                Append ("<optimized out>");
                return;
            }

            try {
                obj = variable.GetObject (frame);
                if (obj != null)
                    Format (frame.Thread, obj);
                else
                    Append ("<cannot display object>");
            } catch {
                Append ("<cannot display object>");
            }
        }
Example #4
0
 public VariableAccessExpression(TargetVariable var)
 {
     this.var = var;
     resolved = true;
 }
Example #5
0
        protected override Expression DoResolve(ScriptingContext context)
        {
            frame = context.CurrentFrame;
            Method method = frame.Method;
            if (method == null)
                throw new ScriptingException (
                    "Keyword `this' not allowed: no current method.");

            if (!method.HasThis)
                throw new ScriptingException (
                    "Keyword `this' not allowed: current method is " +
                    "either static or unmanaged.");

            var = method.GetThis (context.CurrentThread);
            resolved = true;
            return this;
        }
Example #6
0
 public override string PrintVariable(TargetVariable variable, StackFrame frame)
 {
     ObjectFormatter formatter = new ObjectFormatter (DisplayFormat.Default);
     formatter.FormatVariable (frame, variable);
     return formatter.ToString ();
 }
Example #7
0
 public abstract string PrintVariable(TargetVariable variable, StackFrame frame);
Example #8
0
            void do_read_variables(TargetMemoryAccess memory)
            {
                if (!is_loaded)
                    throw new TargetException (TargetError.MethodNotLoaded);
                if (has_variables)
                    return;

                MonoLanguageBackend mono = file.MonoLanguage;

                TargetAddress decl_klass = mono.MetadataHelper.MonoMethodGetClass (
                    memory, address.MonoMethod);
                TargetType decl = mono.ReadMonoClass (memory, decl_klass);
                if (decl.HasClassType)
                    decl_type = decl.ClassType;
                else
                    decl_type = (TargetClassType) decl;

                do_read_blocks ();

                locals = new List<TargetVariable> ();
                parameters = new List<TargetVariable> ();
                scopes = new Dictionary<int,ScopeInfo> ();

                var captured_vars = new Dictionary<string,CapturedVariable> ();

                if (address.HasThis)
                    this_var = new MonoVariable (
                        "this", decl_type, true, true, this,
                        address.ThisVariableInfo);

                var scope_list = new List<ScopeInfo> ();

                C.ScopeVariable[] scope_vars = method.GetScopeVariables ();
                int num_scope_vars = scope_vars != null ? scope_vars.Length : 0;
                for (int i = 0; i < num_scope_vars; i++) {
                    C.ScopeVariable sv = scope_vars [i];

                    VariableInfo var;
                    if (sv.Index < 0) {
                        var = address.ThisVariableInfo;
                        this_is_captured = true;
                        this_var = null;
                    } else
                        var = address.LocalVariableInfo [sv.Index];

                    try {
                        TargetClassType type = mono.ReadStructType (memory, var.MonoType);
                        MonoVariable scope_var = new MonoVariable (
                            "$__" + sv.Scope, type, true, type.IsByRef, this, var);

                        ScopeInfo info = new ScopeInfo (sv.Scope, scope_var, type);
                        scopes.Add (sv.Scope, info);
                        scope_list.Add (info);
                    } catch (Exception ex) {
                        Report.Error ("Cannot read scope variable: {0}\n{1}", var, ex);
                    }
                }

                foreach (ScopeInfo scope in scope_list) {
                    read_scope (scope);
                }

                foreach (ScopeInfo scope in scopes.Values) {
                    C.AnonymousScopeEntry entry = file.File.GetAnonymousScope (scope.ID);
                    foreach (C.CapturedVariable captured in entry.CapturedVariables) {
                        CapturedVariable cv = new CapturedVariable (
                            scope, this, captured.Name, captured.CapturedName);

                        switch (captured.Kind) {
                        case C.CapturedVariable.CapturedKind.Local:
                            locals.Add (cv);
                            break;
                        case C.CapturedVariable.CapturedKind.Parameter:
                            parameters.Add (cv);
                            break;
                        case C.CapturedVariable.CapturedKind.This:
                            if (!cv.Resolve (memory))
                                throw new InternalError ();
                            if (cv.Type.HasClassType)
                                decl_type = cv.Type.ClassType;
                            else
                                decl_type = (TargetClassType) cv.Type;
                            this_var = cv;
                            continue;
                        default:
                            throw new InternalError ();
                        }

                        captured_vars.Add (captured.Name, cv);
                    }
                }

                var param_info = mdef.Parameters;
                for (int i = 0; i < param_info.Count; i++) {
                    if (captured_vars.ContainsKey (param_info [i].Name))
                        continue;

                    VariableInfo var = address.ParamVariableInfo [i];
                    TargetType type = mono.ReadType (memory, var.MonoType);
                    if (type == null)
                        type = mono.VoidType;

                    parameters.Add (new MonoVariable (
                        param_info [i].Name, type, false, type.IsByRef,
                        this, var, 0, 0));
                }

                C.LocalVariableEntry[] symfile_locals = method.GetLocals ();
                for (int i = 0; i < symfile_locals.Length; i++) {
                    C.LocalVariableEntry local = symfile_locals [i];

                    if (captured_vars.ContainsKey (local.Name))
                        continue;

                    VariableInfo var = address.LocalVariableInfo [local.Index];
                    TargetType type = mono.ReadType (memory, var.MonoType);
                    if (type == null)
                        type = mono.VoidType;

                    if (local.BlockIndex > 0) {
                        int index = local.BlockIndex - 1;
                        MonoCodeBlock block = code_blocks [index];
                        locals.Add (new MonoVariable (
                            local.Name, type, true, type.IsByRef, this, var,
                            block.StartAddress, block.EndAddress));
                    } else {
                        locals.Add (new MonoVariable (
                            local.Name, type, true, type.IsByRef, this, var));
                    }
                }

                has_variables = true;
            }
Example #9
0
            TargetVariable[] resolve_variables(ArrayList variables)
            {
                if (variables == null)
                    return new TargetVariable [0];

                ArrayList list = new ArrayList ();
                foreach (DieMethodVariable variable in variables) {
                    TargetVariable resolved = variable.Variable;
                    if (resolved != null)
                        list.Add (resolved);
                }

                TargetVariable[] retval = new TargetVariable [list.Count];
                list.CopyTo (retval, 0);
                return retval;
            }
Example #10
0
            void DoResolve()
            {
                if (abstract_origin != 0) {
                    DieSubprogram aorigin = comp_unit.GetSubprogram (abstract_origin);
                    if (aorigin == null)
                        throw new InternalError ();

                    DoResolveSpecification (aorigin);
                }

                if (specification != 0) {
                    DieSubprogram ssubprog = comp_unit.GetSubprogram (specification);
                    if (ssubprog == null)
                        throw new InternalError ();

                    DoResolveSpecification (ssubprog);
                }

                locals = resolve_variables (local_dies);
                parameters = resolve_variables (param_dies);

                if (param_dies != null) {
                    DieMethodVariable first_var = (DieMethodVariable) param_dies [0];
                    if ((first_var.IsArtificial != null) && (first_var.Name == "this"))
                        this_var = first_var.Variable;
                }

                debug ("{0} resolve: {1} {2} {3} {4}", Offset, param_dies != null, local_dies != null,
                       name != null, this_var != null);

                if ((param_dies != null) && (name != null)) {
                    StringBuilder sb = new StringBuilder ();
                    if (this_var != null) {
                        sb.Append (this_var.Type.Name);
                        sb.Append ("::");
                    }
                    sb.Append (name);
                    sb.Append ("(");
                    bool first = true;
                    for (int i = 0; i < param_dies.Count; i++) {
                        DieMethodVariable the_param = (DieMethodVariable) param_dies [i];
                        if (!first)
                            sb.Append (", ");
                        if (the_param.Type == null)
                            continue;
                        sb.Append (the_param.Type.Name);
                        if (the_param.Name != null) {
                            sb.Append (" ");
                            sb.Append (the_param.Name);
                        }
                        first = false;
                    }
                    sb.Append (")");
                    full_name = sb.ToString ();
                }
            }