Exemple #1
0
        public void GetObjectMethodTableTest()
        {
            using (DataTarget dt = TestTargets.AppDomains.LoadFullDump())
            {
                ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime();
                ClrHeap    heap    = runtime.Heap;

                int i = 0;
                foreach (ulong obj in heap.EnumerateObjectAddresses())
                {
                    i++;
                    ClrType type = heap.GetObjectType(obj);

                    if (type.IsArray)
                    {
                        ulong mt, cmt;
                        bool  result = heap.TryGetMethodTable(obj, out mt, out cmt);

                        Assert.True(result);
                        Assert.NotEqual(0ul, mt);
                        Assert.Equal(type.MethodTable, mt);

                        Assert.Same(type, heap.GetTypeByMethodTable(mt, cmt));
                    }
                    else
                    {
                        ulong mt = heap.GetMethodTable(obj);

                        Assert.NotEqual(0ul, mt);
                        Assert.Contains(mt, type.EnumerateMethodTables());

                        Assert.Same(type, heap.GetTypeByMethodTable(mt));
                        Assert.Same(type, heap.GetTypeByMethodTable(mt, 0));

                        ulong mt2, cmt;
                        bool  res = heap.TryGetMethodTable(obj, out mt2, out cmt);

                        Assert.True(res);
                        Assert.Equal(mt, mt2);
                        Assert.Equal(0ul, cmt);
                    }
                }
            }
        }
Exemple #2
0
        public void EETypeTest()
        {
            using DataTarget dt = TestTargets.AppDomains.LoadFullDump();
            ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime();
            ClrHeap    heap    = runtime.Heap;

            HashSet <ulong> methodTables = (from obj in heap.EnumerateObjectAddresses()
                                            let type = heap.GetObjectType(obj)
                                                       where !type.IsFree
                                                       select heap.GetMethodTable(obj)).Unique();

            Assert.DoesNotContain(0ul, methodTables);

            foreach (ulong mt in methodTables)
            {
                ClrType type    = heap.GetTypeByMethodTable(mt);
                ulong   eeclass = heap.GetEEClassByMethodTable(mt);
                Assert.NotEqual(0ul, eeclass);

                Assert.NotEqual(0ul, heap.GetMethodTableByEEClass(eeclass));
            }
        }
Exemple #3
0
 /// <summary>
 ///     Attempts to retrieve the MethodTable from the given object.
 ///     Note that this some ClrTypes cannot be uniquely determined by MethodTable alone.  In
 ///     Desktop CLR, arrays of reference types all use the same MethodTable.  To uniquely
 ///     determine an array of referneces you must also have its component type.
 ///     Note this function has undefined behavior if you do not pass a valid object reference
 ///     to it.
 /// </summary>
 /// <param name="obj">The object to get the MethodTablee of.</param>
 /// <returns>The MethodTable of the object, or 0 if the address could not be read from.</returns>
 /// <inheritdoc />
 public ulong GetMethodTable(ulong obj) => Heap.GetMethodTable(obj);