Example #1
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);
        }
Example #2
0
        public ClrObject?AsObject()
        {
            if (_object.HasValue)
            {
                return(_object.Value);
            }

            // It's possible that ObjectPointer points the beginning of an object, though that's rare.  Check that first.
            ClrType?type = _segment.Heap.GetObjectType(ObjectPointer);

            if (!(type is null))
            {
                _object = new ClrObject(ObjectPointer, type);
                return(_object.Value);
            }

            // ObjectPointer is pointing in the middle of an object, get the previous object for the address.
            ulong obj = _segment.GetPreviousObjectAddress(ObjectPointer);

            if (obj == 0)
            {
                return(null);
            }

            type = _segment.Heap.GetObjectType(obj);
            if (type is null)
            {
                // This is heap corruption, or an inconsistent dump.  We should have found a real object here.
                return(null);
            }

            ClrObject result = new ClrObject(obj, type);

            _object = result;
            return(result);
        }