Ejemplo n.º 1
0
        private string TypeHeader()
        {
            var specKind = TypeExtractor.GetSpecialKind(_kind);

            if (specKind != ClrElementKind.Unknown)
            {
                switch (specKind)
                {
                case ClrElementKind.Free:
                case ClrElementKind.Guid:
                case ClrElementKind.DateTime:
                case ClrElementKind.TimeSpan:
                case ClrElementKind.Decimal:
                    return(Constants.PrimitiveHeader);

                case ClrElementKind.Interface:
                    return(Constants.InterfaceHeader);

                case ClrElementKind.Enum:
                    return(Constants.PrimitiveHeader);

                case ClrElementKind.SystemVoid:
                    return(Constants.StructHeader);

                case ClrElementKind.SystemObject:
                case ClrElementKind.System__Canon:
                case ClrElementKind.Exception:
                case ClrElementKind.Abstract:
                    return(Constants.ClassHeader);
                }
                throw new MdrException("[ClrtDisplayableType.TypeHeader] Not all cases are handled for (specKind != ClrElementKind.Unknown).");
            }
            else
            {
                switch (TypeExtractor.GetStandardKind(_kind))
                {
                case ClrElementKind.String:
                    return(Constants.PrimitiveHeader);

                case ClrElementKind.SZArray:
                case ClrElementKind.Array:
                case ClrElementKind.Object:
                case ClrElementKind.Class:
                    return(Constants.ClassHeader);

                case ClrElementKind.Struct:
                    return(Constants.StructHeader);

                case ClrElementKind.Unknown:
                    return(Constants.PrimitiveHeader);

                default:
                    return(Constants.PrimitiveHeader);
                }
            }
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get type display panel.
        /// </summary>
        /// <param name="dispType">Type information.</param>
        /// <returns>Adorned panel.</returns>
        public static StackPanel GetClrtDisplayableTypeStackPanel(ClrtDisplayableType dispType)
        {
            var stackPanel = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };

            Image image = new Image();

            if (dispType.IsDummy)
            {
                image.Source = ((Image)Application.Current.FindResource("GroupPng")).Source;
                stackPanel.Children.Add(image);
                stackPanel.Children.Add(GetClrtDisplayableTypeTextBlock(dispType));
                return(stackPanel);
            }

            var kind     = dispType.Kind;
            var specKind = TypeExtractor.GetSpecialKind(kind);

            if (specKind != ClrElementKind.Unknown)
            {
                switch (specKind)
                {
                case ClrElementKind.Free:
                case ClrElementKind.Guid:
                case ClrElementKind.DateTime:
                case ClrElementKind.TimeSpan:
                case ClrElementKind.Decimal:
                    image.Source = ((Image)Application.Current.FindResource("PrimitivePng")).Source;
                    break;

                case ClrElementKind.Interface:
                    image.Source = ((Image)Application.Current.FindResource("InterfacePng")).Source;
                    break;

                case ClrElementKind.Enum:
                    image.Source = ((Image)Application.Current.FindResource("EnumPng")).Source;
                    break;

                case ClrElementKind.SystemObject:
                case ClrElementKind.System__Canon:
                case ClrElementKind.Exception:
                case ClrElementKind.Abstract:
                    image.Source = ((Image)Application.Current.FindResource("ClassPng")).Source;
                    break;

                case ClrElementKind.SystemNullable:
                    image.Source = ((Image)Application.Current.FindResource("StructPng")).Source;
                    break;
                }
            }
            else
            {
                switch (TypeExtractor.GetStandardKind(kind))
                {
                case ClrElementKind.String:
                    image.Source = ((Image)Application.Current.FindResource("PrimitivePng")).Source;
                    break;

                case ClrElementKind.SZArray:
                case ClrElementKind.Array:
                    image.Source = ((Image)Application.Current.FindResource("ArrayPng")).Source;
                    break;

                case ClrElementKind.Object:
                case ClrElementKind.Class:
                    image.Source = ((Image)Application.Current.FindResource("ClassPng")).Source;
                    break;

                case ClrElementKind.Struct:
                    image.Source = ((Image)Application.Current.FindResource("StructPng")).Source;
                    break;

                case ClrElementKind.Unknown:
                    image.Source = ((Image)Application.Current.FindResource("QuestionPng")).Source;
                    break;

                default:
                    image.Source = ((Image)Application.Current.FindResource("PrimitivePng")).Source;
                    break;
                }
            }

            stackPanel.Children.Add(image);
            stackPanel.Children.Add(GetClrtDisplayableTypeTextBlock(dispType));
            return(stackPanel);
        }
Ejemplo n.º 4
0
        public bool Accept(object obj)
        {
            bool accept   = true;
            var  specKind = TypeExtractor.GetSpecialKind(_kind);

            if (specKind != ClrElementKind.Unknown)
            {
                switch (specKind)
                {
                case ClrElementKind.Exception:
                case ClrElementKind.Enum:
                case ClrElementKind.Free:
                    break;

                case ClrElementKind.Guid:
                    accept = AcceptGuid((Guid)obj, (Guid)_value, _op);
                    break;

                case ClrElementKind.DateTime:
                    accept = Accept <DateTime>((DateTime)obj, (DateTime)_value, _op);
                    break;

                case ClrElementKind.TimeSpan:
                    accept = Accept <TimeSpan>((TimeSpan)obj, (TimeSpan)_value, _op);
                    break;

                case ClrElementKind.Decimal:
                    accept = Accept <decimal>((decimal)obj, (decimal)_value, _op);
                    break;

                case ClrElementKind.SystemVoid:
                    break;

                case ClrElementKind.SystemObject:
                case ClrElementKind.Interface:
                case ClrElementKind.Abstract:
                case ClrElementKind.System__Canon:
                    accept = Accept <ulong>((ulong)obj, (ulong)_value, _op);
                    break;

                default:
                    break;
                }
            }
            else
            {
                var stdKind = TypeExtractor.GetStandardKind(_kind);
                switch (stdKind)
                {
                case ClrElementKind.Class:
                case ClrElementKind.Struct:
                    break;

                case ClrElementKind.SZArray:
                case ClrElementKind.Array:
                case ClrElementKind.Object:
                    accept = Accept <ulong>((ulong)obj, (ulong)_value, _op);
                    break;

                case ClrElementKind.Boolean:
                    accept = AcceptBoolean((bool)obj, (bool)_value);
                    break;

                case ClrElementKind.Char:     // ?
                    accept = Accept <char>((char)obj, (char)_value, _op);
                    break;

                case ClrElementKind.Int8:
                    accept = Accept <sbyte>((sbyte)obj, (sbyte)_value, _op);
                    break;

                case ClrElementKind.Int16:
                    accept = Accept <Int16>((Int16)obj, (Int16)_value, _op);
                    break;

                case ClrElementKind.Int32:
                    accept = Accept <Int32>((Int32)obj, (Int32)_value, _op);
                    break;

                case ClrElementKind.Int64:
                    accept = Accept <long>((long)obj, (long)_value, _op);
                    break;

                case ClrElementKind.UInt8:
                    accept = Accept <byte>((byte)obj, (byte)_value, _op);
                    break;

                case ClrElementKind.UInt16:
                    accept = Accept <Int16>((Int16)obj, (Int16)_value, _op);
                    break;

                case ClrElementKind.UInt32:
                    accept = Accept <UInt32>((UInt32)obj, (UInt32)_value, _op);
                    break;

                case ClrElementKind.UInt64:
                    accept = Accept <UInt64>((ulong)obj, (ulong)_value, _op);
                    break;

                case ClrElementKind.Float:
                case ClrElementKind.Double:
                    accept = Accept <double>((double)obj, (double)_value, _op);
                    break;

                case ClrElementKind.String:
                    accept = AcceptString((string)obj, _filterString, _op);
                    break;

                case ClrElementKind.Pointer:
                case ClrElementKind.NativeInt:
                case ClrElementKind.NativeUInt:
                case ClrElementKind.FunctionPointer:
                    accept = Accept <UInt64>((ulong)obj, (ulong)_value, _op);
                    break;

                default:
                    break;
                }
            }

            return(accept);
        }
Ejemplo n.º 5
0
        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;
                }
            }
        }
Ejemplo n.º 6
0
        public bool CanGetFields(out string msg)
        {
            msg = null;
            if (IsDummy)
            {
                msg = "Cannot get fields, this is alternatives grouping node.";
                return(false);
            }
            var specKind = TypeExtractor.GetSpecialKind(_kind);

            if (specKind != ClrElementKind.Unknown)
            {
                switch (specKind)
                {
                case ClrElementKind.Free:
                case ClrElementKind.Guid:
                case ClrElementKind.DateTime:
                case ClrElementKind.TimeSpan:
                case ClrElementKind.Decimal:
                    msg = "Cannot get fields, this type is considered primitive.";
                    return(false);

                case ClrElementKind.Interface:
                    msg = "Cannot get fields of an interface.";
                    return(false);

                case ClrElementKind.Enum:
                    msg = "Cannot get fields, this type is primitive.";
                    return(false);

                case ClrElementKind.Exception:
                    return(true);

                case ClrElementKind.System__Canon:
                    msg = "Cannot get fields, this is System__Canon type.";
                    return(false);

                case ClrElementKind.SystemObject:
                    msg = "Cannot get fields, this is System.Object.";
                    return(false);

                case ClrElementKind.SystemVoid:
                    msg = "Cannot get fields, this is System.Void.";
                    return(false);

                case ClrElementKind.Abstract:
                    msg = "Cannot get fields, this is abstract class.";
                    return(false);
                }
                throw new MdrException("[ClrtDisplayableType.TypeHeader] Not all cases are handled for (specKind != ClrElementKind.Unknown).");
            }
            else
            {
                switch (TypeExtractor.GetStandardKind(_kind))
                {
                case ClrElementKind.String:
                    msg = "Cannot get fields, this type is considered primitive.";
                    return(false);

                case ClrElementKind.SZArray:
                case ClrElementKind.Array:
                    msg = "Cannot get fields, this is array type.";
                    return(false);

                case ClrElementKind.Object:
                case ClrElementKind.Class:
                    return(true);

                case ClrElementKind.Struct:
                    return(true);

                case ClrElementKind.Unknown:
                    msg = "Cannot get fields, the type is unknown.";
                    return(false);

                default:
                    msg = "Cannot get fields, this type is primitive.";
                    return(false);
                }
            }
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 9
0
        GetClassValues(ClrHeap heap, ulong addr)
        {
            try
            {
                addr = Utils.RealAddress(addr);
                (ClrType type, ClrElementKind kind, ClrType rtType, ClrElementKind rtKind) = 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, 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                objects        = fldCnt == 0 ? Utils.EmptyArray <object> .Value : new object[fldCnt];
                StructValues[]     structVals     = null;
                StructFieldsInfo[] structFldInfos = 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
                    var fldKind = TypeExtractor.GetElementKind(fldType);
                    if (fldKind == ClrElementKind.Unknown)
                    {
                        objects[i] = null;
                        continue; // nothing to do here, from MDR lib: There is
                                  // a bug in several versions of our debugging layer which causes this.
                    }
                    if (fldType == null || TypeExtractor.IsAmbiguousKind(fldKind))
                    {
                        var fldValObj = fld.GetValue(addr, type.IsValueClass, false);
                        if (fldValObj != null && fldValObj is ulong)
                        {
                            var t = heap.GetObjectType((ulong)fldValObj);
                            if (t != null)
                            {
                                fldType = t;
                                fldKind = TypeExtractor.GetElementKind(t);
                            }
                        }
                    }
                    fldTypes[i] = fldType;
                    fldKinds[i] = fldKind;
                    if (fldKind == ClrElementKind.Unknown)
                    {
                        continue;                                    // nothing to do here, from MDR lib: There is
                    }
                    // a bug in several versions of our debugging layer which causes this.
                    if (TypeExtractor.IsString(fldKind))
                    {
                        objects[i] = fld.GetValue(addr, false, true);
                    }
                    else if (TypeExtractor.IsObjectReference(fldKind))
                    {
                        object obj = fld.GetValue(addr, false, false);
                        if (obj != null && (ulong)obj != Constants.InvalidAddress)
                        {
                            var t = heap.GetObjectType((ulong)obj);
                            if (t != null)
                            {
                                var k = TypeExtractor.GetElementKind(t);
                                fldTypes[i] = t;
                                fldKinds[i] = k;
                            }
                        }

                        objects[i] = obj;
                    }
                    else if (TypeExtractor.IsEnum(fldKind))
                    {
                        objects[i] = ValueExtractor.GetEnumValueObject(addr, fld, false);
                    }
                    else if (fldType.IsPrimitive)
                    {
                        objects[i] = ValueExtractor.GetPrimitiveValueObject(addr, fld, false);
                    }
                    else if (TypeExtractor.IsKnownStruct(fldKind))
                    {
                        switch (TypeExtractor.GetSpecialKind(fldKind))
                        {
                        case ClrElementKind.DateTime:
                            objects[i] = ValueExtractor.GetDateTimePAF(addr, fld, false);
                            break;

                        case ClrElementKind.Guid:
                            objects[i] = ValueExtractor.GetGuid(addr, fld, false);
                            break;

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

                        case ClrElementKind.TimeSpan:
                            objects[i] = ValueExtractor.TimeSpanValue(addr, fldType);
                            break;
                        }
                    }
                    else if (TypeExtractor.IsUnknownStruct(fldKind))
                    {
                        //StructFields sf = StructFields.GetStructFields(fldType);
                        //StructFieldsEx sfx = StructFieldsEx.GetStructFields(sf, fldType);
                        if (structFldInfos == null)
                        {
                            structFldInfos = new StructFieldsInfo[fldCnt];
                        }
                        ulong            saddr = fld.GetAddress(addr, true);
                        StructFieldsInfo sfi   = StructFieldsInfo.GetStructFields(fldType, heap, saddr);
                        structFldInfos[i] = sfi;
                        if (sfi != null)
                        {
                            if (structVals == null)
                            {
                                structVals = new StructValues[fldCnt];
                            }
                            structVals[i] = StructFieldsInfo.GetStructValues(sfi, heap, saddr);
                        }
                    }
                }

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