コード例 #1
0
        private static void AnalyseDuplications(ClrObject obj, ClrHeap heap)
        {
            if (obj.IsNull)
            {
                return;
            }
            if (obj.Type != heap.StringType)
            {
                return;
            }
            var asString = obj.AsString();

            if (string.IsNullOrEmpty(asString))
            {
                return;
            }
            if (!DuplicatedInstances.ContainsKey(asString))
            {
                DuplicatedInstances.Add(asString, 1);
                InstanceSize.Add(asString, obj.Size);
            }
            else
            {
                var duplicatedInstance = DuplicatedInstances[asString];
                DuplicatedInstances[asString] = duplicatedInstance + 1;
            }
        }
コード例 #2
0
        public void StringEmptyTest()
        {
            using DataTarget dt      = TestTargets.Types.LoadFullDump();
            using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime();

            ClrType strType   = runtime.Heap.StringType;
            var     statics   = strType.StaticFields;
            ulong   valueSlot = Assert.Single(statics).GetAddress(runtime.AppDomains[0]);

            Assert.NotEqual(0ul, valueSlot);

            ulong address = dt.DataReader.ReadPointer(valueSlot);

            Assert.NotEqual(0ul, address);
            ClrObject obj = runtime.Heap.GetObject(address);

            Assert.True(obj.Type.IsString);

            string strValue = obj.AsString();

            Assert.Equal("", strValue);

            ClrSegment seg = runtime.Heap.GetSegmentByAddress(valueSlot);

            Assert.NotNull(seg);

            ulong prev = seg.GetPreviousObjectAddress(valueSlot);

            Assert.NotEqual(0ul, prev);

            ClrObject staticsArray = runtime.Heap.GetObject(prev);

            Assert.True(staticsArray.IsValid);
            Assert.True(staticsArray.IsArray);
        }
コード例 #3
0
 public static string GetStringValue(this ClrObject clrObject, int maxLength = int.MaxValue)
 {
     return(clrObject.Type.IsString ? clrObject.AsString(maxLength) : null);
 }