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)); }
//public FilterValue(string filterStr, ClrElementKind kind, Op oper) //{ // _filterString = filterStr; // _kind = kind; // _op = oper; //} public FilterValue(string filterStr, ClrElementKind kind, Op oper, Regex regex) { _filterString = filterStr; _kind = kind; _op = oper; _regex = regex; }
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)); }
public void SetField(ClrType parent) { if (parent.Fields != null && _fldIndex >= 0 && _fldIndex < parent.Fields.Count) { _field = parent.Fields[_fldIndex]; _kind = TypeExtractor.GetElementKind(_field.Type); } }
public static ColumnType KindToColumnType(ClrElementKind kind) { var specKind = TypeExtractor.GetSpecialKind(kind); if (specKind != ClrElementKind.Unknown) { switch (specKind) { case ClrElementKind.Guid: case ClrElementKind.DateTime: case ClrElementKind.TimeSpan: case ClrElementKind.Decimal: case ClrElementKind.Enum: case ClrElementKind.Exception: return(ColumnType.String); case ClrElementKind.Free: case ClrElementKind.Abstract: case ClrElementKind.SystemVoid: case ClrElementKind.SystemObject: return(ColumnType.UInt64); default: throw new ArgumentException("[ReportFile.KindToColumnType(..)] Invalid kind: " + kind.ToString()); } } else { switch (kind) { case ClrElementKind.String: return(ColumnType.String); case ClrElementKind.SZArray: case ClrElementKind.Array: case ClrElementKind.Object: case ClrElementKind.Class: return(ColumnType.UInt64); case ClrElementKind.Int16: case ClrElementKind.Int32: return(ColumnType.Int32); case ClrElementKind.UInt16: case ClrElementKind.UInt32: return(ColumnType.UInt32); case ClrElementKind.Unknown: throw new ArgumentException("[ReportFile.KindToColumnType(..)] Invalid kind: " + kind.ToString()); default: return(ColumnType.String); } } }
public static StructFieldsInfo GetStructFields(ClrType type, ClrHeap heap, ulong addr) { Debug.Assert(type.IsValueClass); var flds = type.Fields; var cnt = flds.Count; StructFieldsInfo[] structFields = null; var types = new ClrType[cnt]; var typeKinds = new ClrElementKind[cnt]; var fields = new ClrInstanceField[cnt]; var fldKinds = new ClrElementKind[cnt]; for (int i = 0; i < cnt; ++i) { var fld = flds[i]; var ftype = fld.Type; fields[i] = fld; fldKinds[i] = TypeExtractor.GetElementKind(fld.Type); types[i] = fld.Type; typeKinds[i] = fldKinds[i]; if (TypeExtractor.IsAmbiguousKind(fldKinds[i])) { ClrType fType = null; ClrElementKind fKind = ClrElementKind.Unknown; ClrType rType = null; ClrElementKind rKind = ClrElementKind.Unknown; //object obj = fld.GetValue(addr, false, false); object obj = fld.GetValue(addr, true, false); // TODO JRD if (obj is ulong) { (fType, fKind, rType, rKind) = TypeExtractor.GetRealType(heap, (ulong)obj); } if (fType != null) { types[i] = fType; typeKinds[i] = fKind; ftype = fType; } } if (TypeExtractor.IsUnknownStruct(fldKinds[i]) || TypeExtractor.IsUnknownStruct(typeKinds[i])) { if (structFields == null) { structFields = new StructFieldsInfo[cnt]; } var faddr = fld.GetAddress(addr, false); structFields[i] = GetStructFields(types[i], heap, faddr); } } return(new StructFieldsInfo(type, types, typeKinds, fields, fldKinds, structFields)); }
public InstanceValue(int typeId, ulong addr, string typeName, string fldName, string value, int fldNdx = Constants.InvalidIndex) { _typeId = typeId; _kind = ClrElementKind.Unknown; _address = addr; _typeName = typeName; _fieldName = fldName; _value = new DisplayableString(value); _fields = Utils.EmptyArray <InstanceValue> .Value; _fieldNdx = fldNdx; _aryValues = null; _parent = null; }
public ClrtDisplayableType(ClrtDisplayableType parent, int typeId, int fieldIndex, string typeName, string fieldName, ClrElementKind kind, ulong[] addresses = null) { _id = GetId(); _parent = parent; _typeId = typeId; _fieldIndex = fieldIndex; _typeName = typeName; _fieldName = fieldName; _kind = kind; _fields = Utils.EmptyArray <ClrtDisplayableType> .Value; _valueFilter = null; _getValue = false; _alternatives = null; _addresses = addresses; }
public void ResetClrInfo() { _type = null; _kind = ClrElementKind.Unknown; _field = null; _fldIndex = Constants.InvalidIndex; _value = null; if (_children != null) { for (int i = 0, icnt = _children.Length; i < icnt; ++i) { _children[i].ResetClrInfo(); } } }
public ValueTuple <int[], ClrElementKind[], int[]> GetTypeFieldInfo(int typeId, out string error) { error = null; try { if (!IsLoaded && !Load(out error)) { return(null, null, null); } int typeIdNdx = Array.BinarySearch(_typeIds, typeId); if (typeIdNdx < 0) { error = Constants.InformationSymbolHeader + "Cannot find type id '" + typeId.ToString() + "' in TypeFldInfo data."; return(null, null, null); } int first = typeIdNdx; while (first > 0 && _typeIds[first - 1] == typeId) { --first; } int lastNdx = _typeIds.Length; int end = typeIdNdx + 1; while (end < lastNdx && _typeIds[end] == typeId) { ++end; } int cnt = end - first; int[] types = new int[cnt]; ClrElementKind[] kinds = new ClrElementKind[cnt]; int[] nameIds = new int[cnt]; int ndx = 0; for (int i = first; i < end; ++i) { types[ndx] = _fldTypeIds[i]; kinds[ndx] = _fldKinds[i]; nameIds[ndx] = _fldNameIds[i]; ++ndx; } return(types, kinds, nameIds); } catch (Exception ex) { error = Utils.GetExceptionErrorString(ex); return(null, null, null); } }
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); } }
private void InitFilterDescription() { _kind = _dispType.Kind; Debug.Assert(_kind != ClrElementKind.Unknown); var specKind = TypeExtractor.GetSpecialKind(_kind); if (TypeExtractor.IsString(_kind)) { TypeValueDescr.Visibility = Visibility.Hidden; TypeValueCase.IsChecked = _dispType.HasFilter && _dispType.Filter.IsIgnoreCase(); TypeValueRegex.IsChecked = _dispType.HasFilter && _dispType.Filter.IsRegex(); return; } TypeValueCase.Visibility = Visibility.Hidden; TypeValueRegex.Visibility = Visibility.Hidden; if (specKind != ClrElementKind.Unknown) { switch (specKind) { case ClrElementKind.Exception: TypeValueDescr.Inlines.Add(new Run("Enter address in hex format: ")); TypeValueDescr.Inlines.Add(new Run("0x000083599c5498") { FontWeight = FontWeights.Bold }); TypeValueDescr.Inlines.Add(new Run(", leading zeros are not necessary.")); break; case ClrElementKind.Enum: TypeValueDescr.Inlines.Add(new Run("Enum format is integral value of enumeration.")); break; case ClrElementKind.Free: TypeValueDescr.Inlines.Add(new Run("Free type should not be filtered!") { FontWeight = FontWeights.Bold, Foreground = Brushes.Red }); break; case ClrElementKind.Guid: TypeValueDescr.Inlines.Add(new Run("Guid format ex.: ")); TypeValueDescr.Inlines.Add(new Run("00000000-0000-0000-0000-000000000000") { FontWeight = FontWeights.Bold }); break; case ClrElementKind.DateTime: TypeValueDescr.Inlines.Add(new Run("DateTime format ex.: ")); TypeValueDescr.Inlines.Add(new Run("2009-06-15T13:45:30") { FontWeight = FontWeights.Bold }); TypeValueDescr.Inlines.Add(new Run(" -> 6/15/2009 1:45 PM")); break; case ClrElementKind.TimeSpan: TypeValueDescr.Inlines.Add(new Run("TimeSpan format ex.: ")); TypeValueDescr.Inlines.Add(new Run("1:3:16:50.5 ") { FontWeight = FontWeights.Bold }); break; case ClrElementKind.Decimal: TypeValueDescr.Inlines.Add(new Run("Decimal format ex.: ")); TypeValueDescr.Inlines.Add(new Run("3.14159265") { FontWeight = FontWeights.Bold }); break; case ClrElementKind.SystemVoid: TypeValueDescr.Inlines.Add(new Run("System.Void -- unexpected type!") { FontWeight = FontWeights.Bold, Foreground = Brushes.Red }); break; case ClrElementKind.SystemObject: case ClrElementKind.Interface: case ClrElementKind.Abstract: case ClrElementKind.System__Canon: TypeValueDescr.Inlines.Add(new Run("Enter address in hex format: ")); TypeValueDescr.Inlines.Add(new Run("0x000083599c5498") { FontWeight = FontWeights.Bold }); TypeValueDescr.Inlines.Add(new Run(", leading zeros are not necessary.")); break; default: TypeValueDescr.Inlines.Add(new Run("Unexpected type!") { FontWeight = FontWeights.Bold, Foreground = Brushes.Red }); break; } } else { var stdKind = TypeExtractor.GetStandardKind(_kind); switch (stdKind) { case ClrElementKind.Boolean: TypeValueDescr.Inlines.Add(new Run("Valid values for this type, are: ")); TypeValueDescr.Inlines.Add(new Run("true") { FontWeight = FontWeights.Bold }); TypeValueDescr.Inlines.Add(new Run(" or ")); TypeValueDescr.Inlines.Add(new Run("false") { FontWeight = FontWeights.Bold }); break; case ClrElementKind.Class: case ClrElementKind.Struct: case ClrElementKind.SZArray: case ClrElementKind.Array: break; case ClrElementKind.Object: TypeValueDescr.Inlines.Add(new Run("Enter address in hex format: ")); TypeValueDescr.Inlines.Add(new Run("0x000083599c5498") { FontWeight = FontWeights.Bold }); TypeValueDescr.Inlines.Add(new Run(", leading zeros are not necessary.")); break; case ClrElementKind.Char: case ClrElementKind.Int8: case ClrElementKind.UInt8: case ClrElementKind.Int16: case ClrElementKind.UInt16: case ClrElementKind.Int32: case ClrElementKind.UInt32: case ClrElementKind.Int64: case ClrElementKind.UInt64: case ClrElementKind.Float: case ClrElementKind.Double: case ClrElementKind.String: case ClrElementKind.Pointer: case ClrElementKind.NativeInt: case ClrElementKind.NativeUInt: case ClrElementKind.FunctionPointer: TypeValueDescr.Inlines.Add(new Run("Primitive type: " + stdKind.ToString() + ", enter in standard format.")); break; default: TypeValueDescr.Inlines.Add(new Run("Unexpected type!") { FontWeight = FontWeights.Bold, Foreground = Brushes.Red }); break; } } }
public static object GetValue(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.GetDecimalValue(addr, type)); case ClrElementKind.DateTime: return(ValueExtractor.DateTimeValue(addr, type)); case ClrElementKind.TimeSpan: return(ValueExtractor.TimeSpanValue(addr, type)); case ClrElementKind.Guid: return(ValueExtractor.GuidValue(addr, type)); default: return(Constants.DontKnowHowToGetValue); } } if (TypeExtractor.IsPrimitive(typeKind)) { return(ValueExtractor.PrimitiveValueAsString(addr, type, typeKind)); } if (TypeExtractor.IsObjectReference(typeKind)) { return(field.GetValue(addr, intr, false)); } 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.GetDecimalPAF(addr, field, intr)); case ClrElementKind.DateTime: return(ValueExtractor.GetDateTimePAF(addr, field, intr)); case ClrElementKind.TimeSpan: return(ValueExtractor.GetTimeSpan(addr, field, intr)); case ClrElementKind.Guid: return(ValueExtractor.GetGuid(addr, field, intr)); default: return(Constants.DontKnowHowToGetValue); } } if (TypeExtractor.IsPrimitive(fldKind)) { return(ValueExtractor.GetPrimitiveValueObject(addr, field, intr)); } if (TypeExtractor.IsObjectReference(fldKind)) { return(field.GetValue(addr, intr, false)); } return(Constants.DontKnowHowToGetValue); }
public FilterValue(object value, ClrElementKind kind, Op oper) { _value = value; _kind = kind; _op = oper; }
public void SetKind(ClrElementKind kind, int i) { Debug.Assert(i >= 0 && i < _kinds.Length); _kinds[i] = kind; }
public void SetField(ClrInstanceField fld) { _field = fld; _kind = TypeExtractor.GetElementKind(_field.Type); }
public void SetTypeAndKind(ClrType clrType, ClrElementKind kind) { _type = clrType; _kind = kind; }