Esempio n. 1
0
        public static AbstractVariable Create(string name, TargetObject obj, StackFrame stackFrame)
        {
            if (obj == null)
            {
                return(new ErrorVariable(name, "Object is null"));
            }

            try {
                switch (obj.Kind)
                {
                case TargetObjectKind.Array:
                    return(new ArrayVariable(name, stackFrame, (TargetArrayObject)obj));

                case TargetObjectKind.Pointer:
                    TargetPointerObject pobj = (TargetPointerObject)obj;
                    if (!pobj.Type.IsTypesafe)
                    {
                        return(new ErrorVariable(name, "Pointer is not typesafe"));
                    }
                    try {
                        TargetObject deref = pobj.GetDereferencedObject(stackFrame.Thread);
                        return(VariableFactory.Create(name, deref, stackFrame));
                    } catch {
                        return(new ErrorVariable(name, "Can not dereference object"));
                    }

                case TargetObjectKind.Object:
                    try {
                        TargetObject deref = ((TargetObjectObject)obj).GetDereferencedObject(stackFrame.Thread);
                        return(VariableFactory.Create(name, deref, stackFrame));
                    } catch {
                        return(new ErrorVariable(name, "Can not dereference object"));
                    }

                case TargetObjectKind.Struct:
                case TargetObjectKind.Class:
                    return(new ClassVariable(name, stackFrame, (TargetClassObject)obj));

                case TargetObjectKind.Fundamental:
                    return(new FundamentalVariable(name, stackFrame, (TargetFundamentalObject)obj));

                case TargetObjectKind.Enum:
                    return(new EnumVariable(name, stackFrame, (TargetEnumObject)obj));

                default:
                    return(new ErrorVariable(name, "Unknown kind of object"));
                }
            } catch (Exception e) {
                return(new ErrorVariable(name, e.Message));
            }
        }
Esempio n. 2
0
        protected void FormatObject(Thread target, TargetObject obj)
        {
            switch (obj.Kind)
            {
            case TargetObjectKind.Array:
                FormatArray(target, (TargetArrayObject)obj);
                break;

            case TargetObjectKind.Pointer:
                TargetPointerObject pobj = (TargetPointerObject)obj;
                if (!pobj.Type.IsTypesafe)
                {
                    FormatObjectRecursed(target, pobj, true);
                    break;
                }

                try {
                    TargetObject deref = pobj.GetDereferencedObject(target);
                    Append("&({0}) ", deref.TypeName);
                    FormatObjectRecursed(target, deref, true);
                } catch (Exception ex) {
                    FormatObjectRecursed(target, pobj, true);
                }
                break;

            case TargetObjectKind.Object:
                TargetObjectObject oobj = (TargetObjectObject)obj;
                try {
                    TargetObject deref = oobj.GetDereferencedObject(target);
                    Append("&({0}) ", deref.TypeName);
                    FormatObjectRecursed(target, deref, false);
                } catch {
                    FormatObjectRecursed(target, oobj, true);
                }
                break;

            case TargetObjectKind.Class:
            case TargetObjectKind.Struct:
                FormatStructObject(target, (TargetClassObject)obj);
                break;

            case TargetObjectKind.Fundamental: {
                object value = ((TargetFundamentalObject)obj).GetObject(target);
                Format(target, value);
                break;
            }

            case TargetObjectKind.Enum:
                FormatEnum(target, (TargetEnumObject)obj);
                break;

            case TargetObjectKind.GenericInstance:
                FormatStructObject(target, (TargetClassObject)obj);
                break;

            case TargetObjectKind.Nullable:
                FormatNullable(target, (TargetNullableObject)obj);
                break;

            default:
                PrintObject(target, obj);
                break;
            }
        }