예제 #1
0
 public override ILValue CreateRuntimeTypeHandle(DmdType type) => new RuntimeTypeHandleILValue(this, type);
예제 #2
0
        public override string GetPropertyExpression(string baseExpression, string name, DmdType castType, bool addParens)
        {
            var sb = ObjectCache.AllocStringBuilder();

            AddCastBegin(sb, castType);
            AddParens(sb, baseExpression, addParens);
            AddCastEnd(sb, castType);
            sb.Append('.');
            sb.Append(name);
            return(ObjectCache.FreeAndToString(ref sb));
        }
        DmdType CreateCore(TypeMirror type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (recursionCounter++ > 100)
            {
                throw new InvalidOperationException();
            }

            List <DmdType> types;

            if (!typeCache.TryGetType(type, out var result))
            {
                bool canAddType = true;
                if (type.IsByRef)
                {
                    result = CreateCore(type.GetElementType())?.MakeByRefType();
                }
                else if (type.IsArray)
                {
                    if (type.GetArrayRank() == 1)
                    {
                        if (type.FullName.EndsWith("[*]", StringComparison.Ordinal))
                        {
                            result = CreateCore(type.GetElementType())?.MakeArrayType(1);
                        }
                        else
                        {
                            result = CreateCore(type.GetElementType())?.MakeArrayType();
                        }
                    }
                    else
                    {
                        result = CreateCore(type.GetElementType())?.MakeArrayType(type.GetArrayRank());
                    }
                }
                else if (type.IsPointer)
                {
                    result = CreateCore(type.GetElementType())?.MakePointerType();
                }
                else
                {
                    var module         = engine.TryGetModule(type.Module)?.GetReflectionModule() ?? throw new InvalidOperationException();
                    var reflectionType = module.ResolveType(type.MetadataToken, DmdResolveOptions.None);
                    if ((object)reflectionType != null && reflectionType.GetGenericArguments().Count != 0)
                    {
                        DmdType      parsedType = null;
                        TypeMirror[] genericArgs;
                        if (type.VirtualMachine.Version.AtLeast(2, 15))
                        {
                            genericArgs = type.GetGenericArguments();
                        }
                        else
                        {
                            parsedType = reflectionType.Assembly.GetType(type.FullName);
                            if ((object)parsedType != null && parsedType.MetadataToken != type.MetadataToken)
                            {
                                parsedType = null;
                            }
                            genericArgs = Array.Empty <TypeMirror>();
                            canAddType  = (object)parsedType != null;
                        }

                        if ((object)parsedType != null)
                        {
                            reflectionType = parsedType;
                        }
                        else
                        {
                            types = GetTypesList();
                            foreach (var t in genericArgs)
                            {
                                var newType = CreateCore(t);
                                if ((object)newType == null)
                                {
                                    reflectionType = null;
                                    break;
                                }
                                types.Add(newType);
                            }
                            if ((object)reflectionType != null)
                            {
                                Debug.Assert(types.Count == 0 || reflectionType.GetGenericArguments().Count == types.Count);
                                if (types.Count != 0)
                                {
                                    reflectionType = reflectionType.MakeGenericType(types.ToArray());
                                }
                            }
                            FreeTypesList(ref types);
                        }
                    }
                    result = reflectionType;
                }
                if (canAddType && (object)result != null)
                {
                    typeCache.Add(type, result);
                }
            }

            recursionCounter--;
            return(result);
        }
예제 #4
0
 public override ILValue LoadIndirect(DmdType type, LoadValueType loadValueType) => LoadIndirect();
예제 #5
0
 public SyntheticValue(DmdType type, DbgDotNetRawValue rawValue)
 {
     Type          = type ?? throw new ArgumentNullException(nameof(type));
     this.rawValue = rawValue;
 }
예제 #6
0
        public DmdEventDefMD(DmdEcma335MetadataReader reader, uint rid, DmdType declaringType, DmdType reflectedType) : base(rid, declaringType, reflectedType)
        {
            this.reader = reader ?? throw new ArgumentNullException(nameof(reader));
            bool b = reader.TablesStream.TryReadEventRow(rid, out var row);

            Debug.Assert(b);
            Name       = reader.StringsStream.ReadNoNull(row.Name);
            Attributes = (DmdEventAttributes)row.EventFlags;
            if (!CodedToken.TypeDefOrRef.Decode(row.EventType, out uint token))
            {
                token = uint.MaxValue;
            }
            EventHandlerType = reader.ResolveType((int)token, DeclaringType.GetGenericArguments(), null, DmdResolveOptions.None) ?? reader.Module.AppDomain.System_Void;
        }
예제 #7
0
 public ArgumentAddress(DebuggerRuntimeImpl runtime, DmdType argumentType, int index)
     : base(runtime, argumentType)
 {
     this.argumentType = argumentType;
     this.index        = index;
 }
예제 #8
0
 public bool TryFormat(DmdType type, in DbgDotNetRawValue rawValue)
예제 #9
0
 protected DmdConstructorDef(uint rid, DmdType declaringType, DmdType reflectedType)
 {
     this.rid      = rid;
     DeclaringType = declaringType ?? throw new ArgumentNullException(nameof(declaringType));
     ReflectedType = reflectedType ?? throw new ArgumentNullException(nameof(reflectedType));
 }
예제 #10
0
 public override DmdPropertyInfo[] ReadDeclaredProperties(DmdType declaringType, DmdType reflectedType) =>
 COMThread(() => ReadDeclaredProperties_COMThread(declaringType, reflectedType));
예제 #11
0
 public override DmdEventInfo[] ReadDeclaredEvents(DmdType declaringType, DmdType reflectedType) =>
 COMThread(() => ReadDeclaredEvents_COMThread(declaringType, reflectedType));
예제 #12
0
 public override DmdMethodBase[] ReadDeclaredMethods(DmdType declaringType, DmdType reflectedType) =>
 COMThread(() => ReadDeclaredMethods_COMThread(declaringType, reflectedType));
예제 #13
0
 public override DmdFieldInfo[] ReadDeclaredFields(DmdType declaringType, DmdType reflectedType) =>
 COMThread(() => ReadDeclaredFields_COMThread(declaringType, reflectedType));
예제 #14
0
 public DmdConstructorDefCOMD(DmdComMetadataReader reader, DmdMethodAttributes attributes, DmdMethodImplAttributes implementationFlags, uint rid, string name, DmdType declaringType, DmdType reflectedType) : base(rid, declaringType, reflectedType)
 {
     this.reader = reader ?? throw new ArgumentNullException(nameof(reader));
     reader.Dispatcher.VerifyAccess();
     MethodImplementationFlags = implementationFlags;
     Attributes      = attributes;
     Name            = name ?? throw new ArgumentNullException(nameof(name));
     methodSignature = reader.ReadMethodSignature_COMThread(MDAPI.GetMethodSignatureBlob(reader.MetaDataImport, 0x06000000 + rid), DeclaringType.GetGenericArguments(), GetGenericArguments(), isProperty: false);
 }
예제 #15
0
 public DmdCreatedParameterInfo(DmdMemberInfo member, DmdParameterInfo originalParameter, DmdType parameterType)
 {
     Member = member ?? throw new ArgumentNullException(nameof(member));
     this.originalParameter = originalParameter ?? throw new ArgumentNullException(nameof(originalParameter));
     ParameterType          = parameterType ?? throw new ArgumentNullException(nameof(parameterType));
 }
예제 #16
0
 static DmdFieldInfo TryGetBuilderField(DmdType type) =>
 TryGetBuilderFieldByname(type) ?? TryGetBuilderFieldByType(type);
예제 #17
0
        public DmdEventDefCOMD(DmdComMetadataReader reader, uint rid, DmdType declaringType, DmdType reflectedType) : base(rid, declaringType, reflectedType)
        {
            this.reader = reader ?? throw new ArgumentNullException(nameof(reader));
            reader.Dispatcher.VerifyAccess();
            uint token = 0x14000000 + rid;

            Name       = MDAPI.GetEventName(reader.MetaDataImport, token) ?? string.Empty;
            Attributes = MDAPI.GetEventAttributes(reader.MetaDataImport, token);
            var eventTypeToken = MDAPI.GetEventTypeToken(reader.MetaDataImport, token);

            EventHandlerType = reader.ResolveType((int)eventTypeToken, DeclaringType.GetGenericArguments(), null, DmdResolveOptions.None) ?? reader.Module.AppDomain.System_Void;
        }
예제 #18
0
 protected TypeILValueImpl(DebuggerRuntimeImpl runtime, DmdType type)
 {
     this.runtime        = runtime;
     __objValue_DONT_USE = null;
     Type = type ?? throw new ArgumentNullException(nameof(type));
 }
예제 #19
0
 public LocalAddress(DebuggerRuntimeImpl runtime, DmdType localType, int index)
     : base(runtime, localType)
 {
     this.localType = localType;
     this.index     = index;
 }
예제 #20
0
 public TypeILValueImpl(DebuggerRuntimeImpl runtime, DbgDotNetValue objValue, DmdType type = null)
 {
     this.runtime        = runtime;
     __objValue_DONT_USE = objValue ?? throw new ArgumentNullException(nameof(objValue));
     Type = type ?? objValue.Type;
 }
예제 #21
0
 protected AddressILValue(DebuggerRuntimeImpl runtime, DmdType locationType)
 {
     this.runtime = runtime;
     Type         = locationType.MakeByRefType();
 }
예제 #22
0
 public override void FormatType(DbgEvaluationContext context, ITextColorWriter output, DmdType type, DbgDotNetValue value, DbgValueFormatterTypeOptions options, CultureInfo cultureInfo) =>
 new CSharpTypeFormatter(output, options.ToTypeFormatterOptions(), cultureInfo).Format(type, value);
예제 #23
0
 public override bool StoreIndirect(DmdType type, LoadValueType loadValueType, ILValue value)
 {
     WriteValue(runtime.GetDebuggerValue(value, Type.GetElementType()));
     return(true);
 }
예제 #24
0
        public DbgDotNetValueResult Execute(DbgEvaluationContext context, DbgStackFrame frame, DbgDotNetILInterpreterState state, string typeName, string methodName, DbgEvaluationOptions options, out DmdType expectedType, CancellationToken cancellationToken)
        {
            var frameMethod            = frame.Runtime.GetDotNetRuntime().GetFrameMethod(context, frame, cancellationToken) ?? throw new InvalidOperationException();
            var genericTypeArguments   = frameMethod.ReflectedType.GetGenericArguments();
            var genericMethodArguments = frameMethod.GetGenericArguments();

            return(Execute(context, frame, genericTypeArguments, genericMethodArguments, null, null, state, typeName, methodName, options, out expectedType, cancellationToken));
        }
예제 #25
0
        public static DbgDotNetValue?TryCreateSyntheticValue(DmdType type, object?constant)
        {
            switch (DmdType.GetTypeCode(type))
            {
            case TypeCode.Boolean:
                if (constant is bool)
                {
                    return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.Boolean, constant)));
                }
                break;

            case TypeCode.Char:
                if (constant is char)
                {
                    return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.CharUtf16, constant)));
                }
                break;

            case TypeCode.SByte:
                if (constant is sbyte)
                {
                    return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.Int8, constant)));
                }
                break;

            case TypeCode.Byte:
                if (constant is byte)
                {
                    return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.UInt8, constant)));
                }
                break;

            case TypeCode.Int16:
                if (constant is short)
                {
                    return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.Int16, constant)));
                }
                break;

            case TypeCode.UInt16:
                if (constant is ushort)
                {
                    return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.UInt16, constant)));
                }
                break;

            case TypeCode.Int32:
                if (constant is int)
                {
                    return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.Int32, constant)));
                }
                break;

            case TypeCode.UInt32:
                if (constant is uint)
                {
                    return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.UInt32, constant)));
                }
                break;

            case TypeCode.Int64:
                if (constant is long)
                {
                    return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.Int64, constant)));
                }
                break;

            case TypeCode.UInt64:
                if (constant is ulong)
                {
                    return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.UInt64, constant)));
                }
                break;

            case TypeCode.Single:
                if (constant is float)
                {
                    return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.Float32, constant)));
                }
                break;

            case TypeCode.Double:
                if (constant is double)
                {
                    return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.Float64, constant)));
                }
                break;

            case TypeCode.String:
                if (constant is string || constant is null)
                {
                    return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.StringUtf16, constant)));
                }
                break;

            default:
                if (type == type.AppDomain.System_IntPtr || type == type.AppDomain.System_UIntPtr)
                {
                    if (type.AppDomain.Runtime.PointerSize == 4)
                    {
                        if (constant is int)
                        {
                            return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.Ptr32, (uint)(int)constant)));
                        }
                        else if (constant is uint)
                        {
                            return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.Ptr32, constant)));
                        }
                    }
                    else
                    {
                        if (constant is long)
                        {
                            return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.Ptr64, (ulong)(long)constant)));
                        }
                        else if (constant is ulong)
                        {
                            return(new SyntheticValue(type, new DbgDotNetRawValue(DbgSimpleValueType.Ptr64, constant)));
                        }
                    }
                }
                else if (constant is null && !type.IsValueType)
                {
                    return(new SyntheticNullValue(type));
                }
                break;
            }
            return(null);
        }
예제 #26
0
 public abstract DbgDotNetValueResult Execute(DbgEvaluationContext context, DbgStackFrame frame, IList <DmdType> genericTypeArguments, IList <DmdType> genericMethodArguments, VariablesProvider argumentsProvider, VariablesProvider localsProvider, DbgDotNetILInterpreterState state, string typeName, string methodName, DbgEvaluationOptions options, out DmdType expectedType, CancellationToken cancellationToken);
예제 #27
0
 public TypeVariableValue(DmdType type) => this.type = type ?? throw new ArgumentNullException(nameof(type));
        public bool TryFormat(DmdType type, DbgDotNetRawValue rawValue)
        {
            if (!rawValue.HasRawValue)
            {
                return(false);
            }

            if (rawValue.RawValue is null)
            {
                OutputWrite(Keyword_null, DbgTextColor.Keyword);
                return(true);
            }

            if (type.IsEnum && NumberUtils.TryConvertIntegerToUInt64ZeroExtend(rawValue.RawValue, out var enumValue))
            {
                FormatEnum(enumValue, type);
                return(true);
            }

            switch (rawValue.ValueType)
            {
            case DbgSimpleValueType.Other:
                if (rawValue.RawValue is DmdType)
                {
                    // It's a type variable
                    FormatType((DmdType)rawValue.RawValue);
                    return(true);
                }
                return(false);

            case DbgSimpleValueType.DateTime:
                return(false);

            case DbgSimpleValueType.Boolean:
                FormatBoolean((bool)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.Char1:
                FormatChar((char)(byte)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.CharUtf16:
                FormatChar((char)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.Int8:
                FormatSByte((sbyte)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.Int16:
                FormatInt16((short)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.Int32:
                FormatInt32((int)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.Int64:
                FormatInt64((long)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.UInt8:
                FormatByte((byte)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.UInt16:
                FormatUInt16((ushort)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.UInt32:
                FormatUInt32((uint)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.UInt64:
                FormatUInt64((ulong)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.Float32:
                FormatSingle((float)rawValue.RawValue, type.AppDomain);
                return(true);

            case DbgSimpleValueType.Float64:
                FormatDouble((double)rawValue.RawValue, type.AppDomain);
                return(true);

            case DbgSimpleValueType.Decimal:
                FormatDecimal((decimal)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.Ptr32:
                FormatPointer32((uint)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.Ptr64:
                FormatPointer64((ulong)rawValue.RawValue);
                return(true);

            case DbgSimpleValueType.StringUtf16:
                FormatString((string)rawValue.RawValue);
                return(true);

            default:
                throw new InvalidOperationException();
            }
        }
예제 #29
0
 public SyntheticNullValue(DmdType type) =>
예제 #30
0
 public override bool StoreLocal(int index, DmdType type, ILValue value) => StoreLocal2(index, type, GetDebuggerValue(value, type));