Ejemplo n.º 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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Attempts to retrieve the MethodTable and component MethodTable from the given object.
 ///     Note that this some ClrTypes cannot be uniquely determined by MethodTable alone.  In
 ///     Desktop CLR (prior to v4.6), arrays of reference types all use the same MethodTable but
 ///     also carry a second MethodTable (called the component MethodTable) to determine the
 ///     array element types. 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 MethodTable of.</param>
 /// <param name="methodTable">The MethodTable for the given object.</param>
 /// <param name="componentMethodTable">The component MethodTable of the given object.</param>
 /// <returns>True if methodTable was filled, false if we failed to read memory.</returns>
 /// <inheritdoc />
 public bool TryGetMethodTable(ulong obj, out ulong methodTable, out ulong componentMethodTable) =>
 Heap.TryGetMethodTable(obj, out methodTable, out componentMethodTable);