Exemplo n.º 1
0
        protected virtual ArrayMappingModel ReadTheOnlyArrayInsideType(ClrObject obj, ModelMapperFactory factory)
        {
            ClrAssert.ClrObjectNotNull(obj);
            var type = obj.Type;

            Assert.Required(type, "NoType");

            var collectionFld = (from fld in type.Fields
                                 let fldType = fld.Type
                                               where fldType != null
                                               where fldType.IsArray
                                               select fld).FirstOrDefault();

            Assert.Required(collectionFld, "no array type found");

            var address = (ulong)collectionFld.GetValue(obj.Address);

            var arrayObj = new ClrObject(address, type.Heap);

            if ((arrayObj.Address == default(ulong)) || (arrayObj.Type == null))
            {
                return(null);
            }
            return(ReadArray(arrayObj, factory));
        }
        /// <summary>
        /// Gets the <see cref="ClrThread"/> by managed ThreadID specified in <paramref name="threadObj"/>.
        /// </summary>
        /// <param name="threadObj">The thread object.</param>
        /// <returns></returns>
        public static ClrThread GetByAddress([ClrObjAndTypeNotEmpty] ClrObject threadObj)
        {
            ClrAssert.ObjectNotNullTypeNotEmpty(threadObj);
            var tp = threadObj.Type;
            var id = threadObj.GetInt32Fld("m_ManagedThreadId");

            return(tp.Heap.Runtime.Threads.FirstOrDefault(t => t.ManagedThreadId == id));
        }
        public override void Compute()
        {
            ClrAssert.ObjectNotNullTypeNotEmpty(this.Obj);

            this.Value = Obj.GetStringFld(fieldName: "_stringValue") ?? string.Empty;

            ClrObject multi = Obj.GetRefFld("_multiValue");

            if (multi.IsNullObj)
            {
                return;
            }

            ClrObject arrayList = multi.GetRefFld("_entriesArray");

            if (arrayList.IsNullObj)
            {
                return;
            }

            List <ClrObject> buckets = ClrCollectionHelper.EnumerateArrayList(arrayList);

            foreach (ClrObject bucket in buckets)
            {
                bucket.ReEvaluateType();
                ClrObject val = bucket.GetRefFld("Value");
                val.ReEvaluateType();
                if (val.IsNullObj)
                {
                    continue;
                }

                List <ClrObject> nestedValues = ClrCollectionHelper.EnumerateArrayList(val);
                foreach (ClrObject nestedValue in nestedValues)
                {
                    nestedValue.ReEvaluateType();
                    if (nestedValue.IsNullObj || (nestedValue.Type == null))
                    {
                        continue;
                    }

                    object tmpvalue = nestedValue.Type.GetValue(nestedValue.Address);
                    if (tmpvalue is string)
                    {
                        this.Value += tmpvalue;
                    }
                }
            }

            // var buckets = ClrCollectionHelper.EnumerateArrayOfRefTypes(arrayList);
            // buckets.
        }
Exemplo n.º 4
0
        public virtual ArrayMappingModel ReadArray([CanBeNullObject] ClrObject obj)
        {
            if (obj.IsNullObj)
            {
                return(new ArrayMappingModel());
            }

            ClrAssert.ObjectNotNullTypeNotEmpty(obj);

            if (!obj.Type.IsArray)
            {
                throw new ArrayTypeMismatchException("Type {0} not of array type".FormatWith(obj.Type.Name));
            }

            return(this.BuildModel(obj) as ArrayMappingModel);
        }
Exemplo n.º 5
0
        /// <summary>
        ///   Reads date from <see cref="ClrObject" /> which points on <see cref="DateTime" />.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns></returns>
        public static DateTime FromObjToDate(ClrObject obj)
        {
            ClrAssert.ObjectNotNullTypeNotEmpty(obj);
            DateTime result;

            if (obj.Type.Name != typeof(DateTime).FullName)
            {
                result = DateTime.MinValue;
            }
            else
            {
                ClrInstanceField dateDataField = obj.Type.GetFieldByName("dateData");
                var rawDateTimeData            = (ulong)dateDataField.GetValue(obj.Address, true);
                result = TicksToDt(rawDateTimeData);
            }

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        ///   Parent class ( <see cref="BaseModelMapperFactory.BuildModel" /> API) ensures that method would not go into recursion
        ///   during processing circular references.
        /// </summary>
        /// <param name="obj">The object ensured to have type and not empty pointer.</param>
        /// <returns>
        ///   The <see cref="IClrObjMappingModel" />.
        /// </returns>
        protected override sealed IClrObjMappingModel DoBuildModelFreeOfRecursion([ClrObjAndTypeNotEmpty] ClrObject obj)
        {
            ClrAssert.ObjectNotNullTypeNotEmpty(obj);
            try
            {
                if (this.InEnabledCache(obj.Address))
                {
                    return(this.mappingModelsCache[obj.Address] as IClrObjMappingModel);
                }

                IClrObjMappingModel model = DoBuildModelWrapped(obj);

                if (!this.mappingModelsCache.ContainsKey(obj.Address) &&
                    (this.CacheOn) &&
                    (!(model is RecursionDetectedModel)))
                {
                    this.mappingModelsCache[obj.Address] = model;
                }

                return(model);
            }
            catch (Exception ex)
            {
                if (this.InEnabledCache(obj.Address))
                {
                    return(this.mappingModelsCache[obj.Address] as IClrObjMappingModel);
                }

                // If mapping field is specified as end type ( not IClrObjMappingModel), than set field reflection would fail.
                var res = new ErrorDuringProcessing
                {
                    Obj = obj,
                    Ex  = ex
                };
                if (this.CacheOn)
                {
                    this.mappingModelsCache[obj.Address] = res;
                }

                return(res);
            }
        }
        /// <summary>
        ///   Builds the model. Free of recursion. Caching layer is provided by base class as well as high-level exception handling
        /// </summary>
        /// <param name="obj">Obj is guaranteed to have type and have non-null pointer.</param>
        /// <returns>
        ///   The <see cref="IClrObjMappingModel" />.
        /// </returns>
        protected override IClrObjMappingModel DoBuildModelWrapped([NotNull] ClrObject obj)
        {
            ClrAssert.ObjectNotNullTypeNotEmpty(obj);

            IClrObjMappingModel model = this.GetModelByObjectType(obj);

            if (model is NoConverterForType)
            {
                IClrObjMappingModel specialCollection;

                // Try to read special collections like hashtables, arrays, generic lists, weak references,
                return(this.CollectionEnumerator.TryProcessSpecialCollection(obj, out specialCollection) ? specialCollection : model);
            }

#if TRACE
            Trace.TraceInformation("{0} model was picked for {1} obj {2}", model.GetType().Name, obj.Type.Name, obj.Address.ToString("x8"));
#endif

            this.MapModelFields(ref model, obj);
            model.Compute();
            return(model);
        }
        public DateTime ExtractData(ClrObject ClrObj)
        {
            ClrAssert.ObjectNotNullTypeNotEmpty(ClrObj);

            return(ExtractData(ClrObj.Type.Heap.Runtime));
        }
 protected bool FieldWithSameNameExists(ClrObject clrObject, [NotNull] FieldInfo fieldInfo)
 {
     ClrAssert.TypeNotEmpty(clrObject);
     return(clrObject.Type.Fields.Any(t => t.Name.Equals(fieldInfo.Name, StringComparison.Ordinal)));
 }
        public static DateTime GetDumpTime([ClrObjAndTypeNotEmpty] ClrObject clrObj)
        {
            ClrAssert.ObjectNotNullTypeNotEmpty(clrObj);

            return(_DumpTimeProvider.ExtractData(clrObj));
        }