コード例 #1
0
        public static StructFieldsEx GetStructFields(StructFields sf, ClrType type)
        {
            Debug.Assert(type.IsValueClass);
            var flds = type.Fields;
            var cnt  = flds.Count;

            StructFieldsEx[] structFields = null;
            var types  = new ClrType[cnt];
            var fields = new ClrInstanceField[cnt];

            for (int i = 0; i < cnt; ++i)
            {
                var fld  = flds[i];
                var kind = TypeExtractor.GetElementKind(fld.Type);
                if (TypeExtractor.IsUnknownStruct(kind))
                {
                    fields[i] = fld;
                    types[i]  = fld.Type;
                    if (structFields == null)
                    {
                        structFields = new StructFieldsEx[cnt];
                    }
                    Debug.Assert(sf.Structs[i] != null);
                    structFields[i] = GetStructFields(sf.Structs[i], fld.Type);
                }
                else
                {
                    fields[i] = fld;
                    types[i]  = fld.Type;
                }
            }
            return(new StructFieldsEx(sf, types, fields, structFields));
        }
コード例 #2
0
 public StructFieldsEx(StructFields structFields, ClrType[] types, ClrInstanceField[] fields, StructFieldsEx[] ex)
 {
     _structFields = structFields;
     _types        = types;
     _fields       = fields;
     _ex           = ex;
 }
コード例 #3
0
        public static StructFields GetStructDescription(StructFieldsInfo sfi)
        {
            if (sfi == null)
            {
                return(null);
            }
            int cnt = sfi._fields.Length;

            StructFields[] structFields = null;
            var            names        = new string[cnt];
            var            typeNames    = new string[cnt];
            var            kinds        = new ClrElementKind[cnt];

            for (int i = 0, icnt = sfi._fields.Length; i < icnt; ++i)
            {
                if (sfi._structFlds != null && sfi._structFlds[i] != null)
                {
                    if (structFields == null)
                    {
                        structFields = new StructFields[cnt];
                    }
                    structFields[i] = GetStructDescription(sfi._structFlds[i]);
                    continue;
                }
                var fld     = sfi._fields[i];
                var fldKind = sfi._fldKinds[i];
                var typ     = sfi._types[i];
                var typKind = sfi._typeKinds[i];
                names[i]     = fld.Name;
                typeNames[i] = typ.Name;
                kinds[i]     = typKind;
            }

            return(new StructFields(sfi._type.Name, kinds, names, typeNames, structFields));
        }
コード例 #4
0
        public static StructFields GetStructFields(ClrType type)
        {
            Debug.Assert(type.IsValueClass);
            var flds      = type.Fields.ToArray(); // enumeration seems off when this is not done
            var cnt       = flds.Length;
            var kinds     = new ClrElementKind[cnt];
            var names     = new string[cnt];
            var typeNames = new string[cnt];

            StructFields[] structFields = null;

            for (int i = 0; i < cnt; ++i)
            {
                var fld = flds[i];
                kinds[i]     = TypeExtractor.GetElementKind(fld.Type);
                names[i]     = fld.Name;
                typeNames[i] = fld.Type == null ? Constants.UnknownName : fld.Type.Name;
                if (TypeExtractor.IsUnknownStruct(kinds[i]))
                {
                    if (structFields == null)
                    {
                        structFields = new StructFields[cnt];
                    }
                    structFields[i] = GetStructFields(fld.Type);
                }
            }
            return(new StructFields(type.Name, kinds, names, typeNames, structFields));
        }
コード例 #5
0
 public static void Description(StructFields sf, StringBuilder sb, string indent)
 {
     for (int i = 0, icnt = sf._names.Length; i < icnt; ++i)
     {
         sb.AppendLine();
         sb.Append(indent).Append(sf._names[i]).Append(" : ").Append(sf._typeNames[i]);
         if (sf.Structs != null && sf.Structs[i] != null && !sf.Structs[i].IsEmpty())
         {
             sb.AppendLine();
             Description(sf.Structs[i], sb, indent + "   ");
         }
     }
 }
コード例 #6
0
        public static ValueTuple <StructFields, StructFieldsEx> GetStructInfo(ClrType structType, ClrHeap heap, ulong addr, out string error)
        {
            Debug.Assert(structType.IsValueClass);
            error = null;
            try
            {
                ClrType type = null;
                object  val  = structType.Fields[0].GetValue(addr, true, false);

                if (val is ulong)
                {
                    type = heap.GetObjectType((ulong)val);
                }

                if (type == null)
                {
                    error = "StructValues.GetStructInfo" + Constants.HeavyGreekCrossPadded
                            + "Expected structure at address: " + Utils.RealAddressString(addr) + Constants.HeavyGreekCrossPadded
                            + "ClrHeap.GetObjectType return null. Field name: " + structType.Fields[0].Name + Constants.HeavyGreekCrossPadded;
                    return(null, null);
                }
                ClrElementKind kind = TypeExtractor.GetElementKind(type);
                if (TypeExtractor.IsUnknownStruct(kind))
                {
                    error = "StructValues.GetStructInfo" + Constants.HeavyGreekCrossPadded
                            + "Expected structure at address: " + Utils.RealAddressString(addr) + Constants.HeavyGreekCrossPadded
                            + "Found: " + type.Name + Constants.HeavyGreekCrossPadded;
                    return(null, null);
                }


                StructFields   sf  = StructFields.GetStructFields(type);
                StructFieldsEx sfx = StructFieldsEx.GetStructFields(sf, type, heap, addr);
                return(sf, sfx);
            }
            catch (Exception ex)
            {
                error = Utils.GetExceptionErrorString(ex);
                return(null, null);
            }
        }
コード例 #7
0
        public static StructFieldsEx GetStructFields(StructFields sf, ClrType type, ClrHeap heap, ulong addr)
        {
            Debug.Assert(type.IsValueClass);
            var flds = type.Fields;
            var cnt  = flds.Count;

            StructFieldsEx[] structFields = null;
            var types  = new ClrType[cnt];
            var fields = new ClrInstanceField[cnt];

            for (int i = 0; i < cnt; ++i)
            {
                var     fld   = flds[i];
                var     kind  = TypeExtractor.GetElementKind(fld.Type);
                ClrType fType = null;
                if (TypeExtractor.IsAmbiguousKind(kind))
                {
                    object obj = fld.GetValue(addr, false, false);
                    if (obj is ulong)
                    {
                        fType = heap.GetObjectType((ulong)obj);
                    }
                }

                fields[i] = fld;
                types[i]  = fType ?? fld.Type;

                if (TypeExtractor.IsUnknownStruct(kind))
                {
                    if (structFields == null)
                    {
                        structFields = new StructFieldsEx[cnt];
                    }
                    Debug.Assert(sf.Structs[i] != null);
                    structFields[i] = GetStructFields(sf.Structs[i], fld.Type);
                }
            }
            return(new StructFieldsEx(sf, types, fields, structFields));
        }
コード例 #8
0
        GetClassValueStrings(ClrHeap heap, ulong addr)
        {
            try
            {
                addr = Utils.RealAddress(addr);

                (ClrType type, ClrElementKind kind, ClrType rtype, ClrElementKind rkind) = TypeExtractor.GetRealType(heap, addr);
                if (type == null)
                {
                    return("Object Value Error" + Constants.HeavyGreekCrossPadded + "Cannot find an instance." + Constants.HeavyGreekCrossPadded + "Heap cannot get object type at address: " + Utils.RealAddressString(addr), null, ClrElementKind.Unknown, (null, null, null, null));
                }

                var fldCnt   = type.Fields.Count;
                var fldTypes = fldCnt == 0 ? Utils.EmptyArray <ClrType> .Value : new ClrType[fldCnt];
                var fldKinds = fldCnt == 0 ? Utils.EmptyArray <ClrElementKind> .Value : new ClrElementKind[fldCnt];
                var strings  = fldCnt == 0 ? Utils.EmptyArray <string> .Value : new string[fldCnt];
                StructValueStrings[] structVals = null;
                for (int i = 0; i < fldCnt; ++i)
                {
                    var fld     = type.Fields[i];
                    var fldType = fld.Type; // returns ClrElementKind.Unknown if fld.Type is null
                    fldTypes[i] = fldType;
                    var fldKind = TypeExtractor.GetElementKind(fldType);
                    fldKinds[i] = fldKind;
                    if (fldKind == ClrElementKind.Unknown)
                    {
                        strings[i] = Constants.UnknownValue;
                        continue; // nothing to do here, from MDR lib: There is
                                  // a bug in several versions of our debugging layer which causes this.
                    }
                    if (TypeExtractor.IsAmbiguousKind(fldKind))
                    {
                        (ClrType aType, ClrElementKind aKind) = TypeExtractor.GetReferenceFieldRealTypeAndKind(heap, addr, fld);
                        if (aType != null)
                        {
                            fldType     = aType;
                            fldTypes[i] = fldType;
                            fldKind     = aKind;
                            fldKinds[i] = fldKind;
                        }
                    }
                    if (TypeExtractor.IsString(fldKind))
                    {
                        var o = fld.GetValue(addr, false, true);
                        strings[i] = o == null ? Constants.NullValue : o.ToString();
                    }
                    else if (TypeExtractor.IsObjectReference(fldKind))
                    {
                        var obj = fld.GetValue(addr, false, false);
                        strings[i] = obj == null ? Constants.InvalidAddressStr : Utils.RealAddressString((ulong)obj);
                    }
                    else if (TypeExtractor.IsEnum(fldKind))
                    {
                        strings[i] = ValueExtractor.GetEnumString(addr, fld, false);
                    }
                    else if (fldType.IsPrimitive)
                    {
                        strings[i] = ValueExtractor.PrimitiveValue(addr, fld, false);
                    }
                    else if (TypeExtractor.IsKnownStruct(fldKind))
                    {
                        switch (TypeExtractor.GetSpecialKind(fldKind))
                        {
                        case ClrElementKind.DateTime:
                            strings[i] = ValueExtractor.GetDateTimeString(addr, fld, false);
                            break;

                        case ClrElementKind.Guid:
                            strings[i] = ValueExtractor.GuidValueAsString(addr, fldType, false);
                            break;

                        case ClrElementKind.Decimal:
                            strings[i] = ValueExtractor.DecimalStringPAF(addr, fld, false);
                            break;

                        case ClrElementKind.TimeSpan:
                            strings[i] = ValueExtractor.TimeSpanValueAsString(addr, fldType);
                            break;
                        }
                    }
                    else if (TypeExtractor.IsUnknownStruct(fldKind))
                    {
                        StructFields   sf  = StructFields.GetStructFields(fldType);
                        StructFieldsEx sfx = StructFieldsEx.GetStructFields(sf, fldType);
                        sfx.ResetTypes();
                        if (structVals == null)
                        {
                            structVals = new StructValueStrings[fldCnt];
                        }
                        ulong structAddr = fld.GetAddress(addr, false);
                        structVals[i] = StructFieldsEx.GetStructValueStrings(sfx, heap, structAddr);
                    }
                }
                //if (!Utils.SameStrings(fld.Type.Name,fldType.Name))
                //    {
                //        ulong fldAddr = fld.GetAddress(addr, type.IsValueClass);
                //        if (TypeExtractor.IsString(fldKind))
                //        {
                //            var obj = ValueExtractor.GetStringValue(fldType, fldAddr);
                //            strings[i] = obj == null ? Constants.NullValue : (string)obj;
                //        }
                //        else if (TypeExtractor.IsObjectReference(fldKind))
                //        {
                //            var obj = fld.GetValue(addr, false, false);
                //            strings[i] = obj == null ? Constants.InvalidAddressStr : Utils.RealAddressString((ulong)obj);
                //        }
                //        else if (TypeExtractor.IsEnum(fldKind))
                //        {
                //            long intVal;
                //            strings[i] = ValueExtractor.GetEnumValueString(fldAddr, fldType, out intVal);
                //        }
                //        else if (fldType.IsPrimitive)
                //        {
                //            var obj = fld.Type.GetValue(fldAddr);
                //            strings[i] = ValueExtractor.PrimitiveValue(obj, fldKind);
                //        }
                //        else if (TypeExtractor.IsKnownStruct(fldKind))
                //        {
                //            switch (TypeExtractor.GetSpecialKind(fldKind))
                //            {
                //                case ClrElementKind.DateTime:
                //                    strings[i] = ValueExtractor.DateTimeValueString(fldAddr, fldType, null);
                //                    break;
                //                case ClrElementKind.Guid:
                //                    strings[i] = ValueExtractor.GuidValueAsString(fldAddr, fldType);
                //                    break;
                //                case ClrElementKind.Decimal:
                //                    strings[i] = ValueExtractor.DecimalValueAsString(fldAddr, fldType,null);
                //                    break;
                //                case ClrElementKind.TimeSpan:
                //                    strings[i] = ValueExtractor.TimeSpanValueAsString(fldAddr, fldType);
                //                    break;
                //            }
                //        }
                //        else if (TypeExtractor.IsUnknownStruct(fldKind))
                //        {
                //            StructFields sf = StructFields.GetStructFields(fldType);
                //            StructFieldsEx sfx = StructFieldsEx.GetStructFields(sf, fldType);
                //            sfx.ResetTypes();
                //            if (structVals == null) structVals = new StructValueStrings[fldCnt];
                //            ulong structAddr = fld.GetAddress(addr, false);
                //            structVals[i] = StructFieldsEx.GetStructValueStrings(sfx, heap, structAddr);
                //        }

                //        continue;


                return(null, type, kind, (fldTypes, fldKinds, strings, structVals));
            }
            catch (Exception ex)
            {
                return(Utils.GetExceptionErrorString(ex), null, ClrElementKind.Unknown, (null, null, null, null));
            }
        }