Ejemplo n.º 1
0
        // Returns all objects being kept alive by the input object
        // Based off the code at https://github.com/Microsoft/clrmd/blob/master/Documentation/WalkingTheHeap.md
        public static List <ulong> GetReferencedObjects(ClrHeap heap, ulong obj)
        {
            List <ulong>  references = new List <ulong>();
            Stack <ulong> eval       = new Stack <ulong>();

            HashSet <ulong> considered = new HashSet <ulong>();

            eval.Push(obj);

            while (eval.Count > 0)
            {
                obj = eval.Pop();
                if (considered.Contains(obj))
                {
                    continue;
                }

                considered.Add(obj);

                // Grab the type. We will only get null here in the case of heap corruption.
                ClrType type = heap.GetObjectType(obj);
                if (type == null)
                {
                    continue;
                }

                references.Add(obj);

                // Now enumerate all objects that this object points to, add them to the
                // evaluation stack if we haven't seen them before.
                type.EnumerateRefsOfObjectCarefully(obj, delegate(ulong child, int offset)
                {
                    if (child != 0 && !considered.Contains(child))
                    {
                        eval.Push(child);
                    }
                });
            }

            return(references);
        }
Ejemplo n.º 2
0
        public override void EnumerateRefsOfObjectCarefully(ulong objRef, Action <ulong, int> action) // TODO GET HELP
        {
            ClrType realType = DesktopHeap.GetObjectType(objRef);

            realType.EnumerateRefsOfObjectCarefully(objRef, action);
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     Does the same as EnumerateRefsOfObject, but does additional bounds checking to ensure
 ///     we don't loop forever with inconsistent data.
 /// </summary>
 /// <param name="objRef">The object reference.</param>
 /// <param name="action">The action.</param>
 public void EnumerateRefsOfObjectCarefully(ulong objRef, Action <ulong, int> action)
 {
     ClrType.EnumerateRefsOfObjectCarefully(objRef, action);
 }
Ejemplo n.º 4
0
 private void CollectChildren(ClrType type, ulong address)
 {
     type.EnumerateRefsOfObjectCarefully(address, CollectChild);
 }
Ejemplo n.º 5
0
 public void EnumerateReferences(Action <ulong, int> action)
 {
     Type.EnumerateRefsOfObjectCarefully(Address, action);
 }