예제 #1
0
        public static TargetStructObject ToStructObject(MdbEvaluationContext ctx, TargetObject obj)
        {
            TargetStructObject sobj = obj as TargetStructObject;

            if (sobj != null)
            {
                return(sobj);
            }

            TargetObjectObject oobj = obj as TargetObjectObject;

            if (oobj != null)
            {
                return(oobj.GetClassObject(ctx.Thread));
            }

            TargetArrayObject aobj = obj as TargetArrayObject;

            if ((aobj != null) && aobj.HasClassObject)
            {
                return(aobj.GetClassObject(ctx.Thread));
            }

            return(null);
        }
예제 #2
0
        public static TargetObject ImplicitConversion(MdbEvaluationContext ctx,
                                                      TargetObject obj, TargetType type)
        {
            if (obj.Type.Equals(type))
            {
                return(obj);
            }

            if (type is TargetObjectType || ObjectUtil.FixTypeName(type.Name) == "System.Object")
            {
                if (obj.Type.IsByRef)
                {
                    return(obj);
                }
                return(BoxValue(ctx, obj));
            }

            if (obj is TargetEnumObject && type is TargetFundamentalType)
            {
                TargetEnumObject e = (TargetEnumObject)obj;
                return(ImplicitConversion(ctx, e.GetValue(ctx.Thread), type));
            }

            if (type is TargetEnumType)
            {
                TargetEnumType e = (TargetEnumType)type;
                return(ImplicitConversion(ctx, obj, e.Value.Type));
            }

            if (obj is TargetArrayObject && type.Name == "System.Array")
            {
                return(obj);
            }

            if (obj is TargetArrayObject && type is TargetArrayType)
            {
                TargetArrayObject sa = (TargetArrayObject)obj;
                TargetArrayType   ta = (TargetArrayType)type;
                if (sa.Type.ElementType.Equals(ta.ElementType))
                {
                    return(obj);
                }
            }

            if ((obj is TargetFundamentalObject) && (type is TargetFundamentalType))
            {
                return(ImplicitFundamentalConversion(
                           ctx, (TargetFundamentalObject)obj,
                           (TargetFundamentalType)type));
            }

            if ((obj is TargetClassObject) && (type is TargetClassType))
            {
                return(ImplicitReferenceConversion(
                           ctx, (TargetClassObject)obj,
                           (TargetClassType)type));
            }

            return(null);
        }
예제 #3
0
        public ArrayVariable(string name, StackFrame stackFrame, TargetArrayObject obj)
        {
            this.name       = name;
            this.stackFrame = stackFrame;
            this.obj        = obj;

            universalSubset = new ArraySubsetVariable(stackFrame, obj, new int[0]);
        }
예제 #4
0
        protected void FormatArray(Thread target, TargetArrayObject aobj)
        {
            TargetArrayBounds bounds = aobj.GetArrayBounds(target);

            if (bounds.IsUnbound)
            {
                Append("[ ]");
            }
            else
            {
                FormatArray(target, aobj, bounds, 0, new int [0]);
            }
        }
예제 #5
0
        protected void FormatArray(Thread target, TargetArrayObject aobj,
                                   TargetArrayBounds bounds, int dimension,
                                   int[] indices)
        {
            Append("[ ");
            indent_level += 3;

            bool first = true;

            int[] new_indices = new int [dimension + 1];
            indices.CopyTo(new_indices, 0);

            int lower, upper;

            if (!bounds.IsMultiDimensional)
            {
                lower = 0;
                upper = bounds.Length - 1;
            }
            else
            {
                lower = bounds.LowerBounds [dimension];
                upper = bounds.UpperBounds [dimension];
            }

            for (int i = lower; i <= upper; i++)
            {
                if (!first)
                {
                    Append(", ");
                    CheckLineWrap();
                }
                first = false;

                new_indices [dimension] = i;
                if (dimension + 1 < bounds.Rank)
                {
                    FormatArray(target, aobj, bounds, dimension + 1, new_indices);
                }
                else
                {
                    TargetObject eobj = aobj.GetElement(target, new_indices);
                    FormatObjectRecursed(target, eobj, false);
                }
            }

            Append(first ? "]" : " ]");
            indent_level -= 3;
        }
예제 #6
0
        public ArraySubsetVariable(StackFrame stackFrame, TargetArrayObject obj, int[] indicesPefix, int startIndex, int endIndex)
        {
            this.stackFrame   = stackFrame;
            this.obj          = obj;
            this.indicesPefix = indicesPefix;
            this.startIndex   = startIndex;
            this.endIndex     = endIndex;

            dimension  = indicesPefix.Length;
            lowerBound = obj.GetLowerBound(stackFrame.Thread, dimension);
            upperBound = obj.GetUpperBound(stackFrame.Thread, dimension) - 1;

            // Uncoment to test that the whole int range can be handled
            //lowerBound = int.MinValue;
            //upperBound = int.MaxValue;
        }
예제 #7
0
 public ArraySubsetVariable(StackFrame stackFrame, TargetArrayObject obj, int[] indicesPefix)
     : this(stackFrame, obj, indicesPefix, 0, 0)
 {
     this.startIndex = lowerBound;
     this.endIndex   = upperBound;
 }
예제 #8
0
        protected override string Execute(ScriptingContext context,
                                          Expression expression, DisplayFormat format)
        {
            try {
                if (expression is TypeExpression)
                {
                    throw new ScriptingException(
                              "`{0}' is a type, not a variable.", expression.Name);
                }
                object retval = expression.Evaluate(context);

                EmonicInterpreter.printData output = new EmonicInterpreter.printData();
                output.type     = "";
                output.varValue = "";
                output.varNames = "";

                if (retval != null)
                {
                    output.type = ((TargetObject)retval).TypeName;
                    if (output.type == null)
                    {
                        output.type = "";
                    }

                    switch (((TargetObject)retval).Kind)
                    {
                    case TargetObjectKind.Fundamental:
                        // we send the value of the fundamental type
                        TargetFundamentalObject tfo = retval as TargetFundamentalObject;
                        if (tfo == null)
                        {
                            // element is "null"
                            output.varValue = "<null>";
                            break;
                        }
                        output.varValue = tfo.GetObject(context.CurrentThread).ToString();
                        if (output.varValue == null)
                        {
                            output.varValue = "";
                        }
                        break;

                    case TargetObjectKind.Array:
                        // we send back the number of array elements
                        TargetArrayObject tao = retval as TargetArrayObject;
                        if (tao == null)
                        {
                            // element is "null"
                            output.varValue = "<null>";
                            break;
                        }
                        int lower = tao.GetLowerBound(context.CurrentThread, 0);
                        int upper = tao.GetUpperBound(context.CurrentThread, 0);
                        output.varNames = (upper - lower).ToString();
                        break;

                    // same for struct and class
                    case TargetObjectKind.Struct:
                    case TargetObjectKind.Class:
                        // we send back the member's names
                        // NOTE! we also show static and constant fields
                        TargetObject obj = retval as TargetObject;
                        if (obj.HasAddress && obj.GetAddress(context.CurrentThread).IsNull)
                        {
                            output.varValue = "<null>";
                            break;
                        }
                        Mono.Debugger.Thread thread = context.CurrentThread;
                        TargetClass          tc     = ((TargetClassObject)retval).Type.GetClass(thread);
                        if (tc == null)
                        {
                            break;
                        }
                        TargetFieldInfo[] tfi = tc.GetFields(thread);
                        if (tfi == null)
                        {
                            break;
                        }
                        output.varNames = "";
                        for (int i = 0; i < tfi.Length; i++)
                        {
                            if (tfi[i].IsStatic)                             // do not show static fields, they're not accessible via the instance!
                            {
                                continue;
                            }
                            output.varNames += tfi[i].Name;
                            output.varNames += " ";
                        }
                        output.varNames = output.varNames.Trim();
                        break;

                    case TargetObjectKind.Object:
                    case TargetObjectKind.Pointer:
                    case TargetObjectKind.Unknown:
                    case TargetObjectKind.Function:
                    case TargetObjectKind.Alias:
                    case TargetObjectKind.Enum:
                        context.Print("ERROR: Print Command will return no values because of an implementation error");
                        break;
                    }
                }
                string text = context.FormatObject(retval, format);
                context.Print(text);

                EmonicInterpreter.printOutput = output;
                EmonicInterpreter.printSem.Release();

                return(text);
            } catch {
                EmonicInterpreter.printData output = new EmonicInterpreter.printData();
                output.type     = "";
                output.varValue = "";
                output.varNames = "";
                EmonicInterpreter.printOutput = output;
                EmonicInterpreter.printSem.Release();
                throw;
            }
        }
예제 #9
0
 public ArrayAdaptor(MdbEvaluationContext ctx, TargetArrayObject array)
 {
     this.ctx   = ctx;
     this.array = array;
 }