/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="field"></param> /// <param name="kind"></param> /// <param name="heap"></param> /// <param name="addr"></param> /// <returns></returns> public static string GetValueAsString(ClrType type, ClrElementKind typeKind, ClrInstanceField field, ClrElementKind fldKind, ClrHeap heap, ulong addr, bool intr) { Debug.Assert(!TypeExtractor.IsUnknownStruct(typeKind) && !TypeExtractor.IsUnknownStruct(fldKind)); if (TypeExtractor.IsAmbiguousKind(fldKind)) { if (TypeExtractor.IsString(typeKind)) { var faddr = ValueExtractor.ReadUlongAtAddress(addr, heap); return(ValueExtractor.GetStringAtAddress(faddr, heap)); } if (TypeExtractor.IsKnownStruct(fldKind)) { switch (TypeExtractor.GetSpecialKind(fldKind)) { case ClrElementKind.Decimal: return(ValueExtractor.DecimalValueAsString(addr, type, null)); case ClrElementKind.DateTime: return(ValueExtractor.DateTimeValueString(addr, type)); case ClrElementKind.TimeSpan: return(ValueExtractor.TimeSpanValueAsString(addr, type)); case ClrElementKind.Guid: return(ValueExtractor.GuidValue(addr, field)); default: return(Constants.DontKnowHowToGetValue); } } if (TypeExtractor.IsPrimitive(typeKind)) { return(ValueExtractor.PrimitiveValueAsString(addr, type, typeKind)); } if (TypeExtractor.IsObjectReference(typeKind)) { var obj = field.GetValue(addr, false, false); if (obj == null || !(obj is ulong)) { return(Constants.ZeroAddressStr); } return(Utils.RealAddressString((ulong)obj)); } return(Constants.DontKnowHowToGetValue); } if (TypeExtractor.IsString(fldKind)) { return(ValueExtractor.GetStringAtAddress(addr, intr, field)); } if (TypeExtractor.IsKnownStruct(fldKind)) { switch (TypeExtractor.GetSpecialKind(fldKind)) { case ClrElementKind.Decimal: return(ValueExtractor.DecimalStringPAF(addr, field, intr)); case ClrElementKind.DateTime: return(ValueExtractor.GetDateTimeValue(addr, field, intr)); case ClrElementKind.TimeSpan: return(ValueExtractor.TimeSpanValue(addr, field)); case ClrElementKind.Guid: return(ValueExtractor.GuidValue(addr, field)); default: return(Constants.DontKnowHowToGetValue); } } if (TypeExtractor.IsPrimitive(fldKind)) { return(ValueExtractor.PrimitiveValue(addr, field, intr)); } if (TypeExtractor.IsObjectReference(fldKind)) { var obj = field.GetValue(addr, intr, false); if (obj == null || !(obj is ulong)) { return(Constants.ZeroAddressStr); } return(Utils.RealAddressString((ulong)obj)); } return(Constants.DontKnowHowToGetValue); }
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)); } }