public async Task<IEnumerable<object>> Execute(Models.OperationModel model, CancellationToken token, object customeParameter)
 {
     return await DebuggerSession.Instance.ExecuteOperation(() =>
     {
         _token = token;
         _heap = DebuggerSession.Instance.Runtime.GetHeap();
         _found = false;
         var stack = new Stack<ulong>();
         foreach (var root in _heap.EnumerateRoots())
         {
             stack.Clear();
             stack.Push(root.Object);
             if (token.IsCancellationRequested)
                 break;
             GetRefChainFromRootToObject(model.ObjectAddress, stack, new HashSet<ulong>());
             if (_found) break;
         }
         var enumerable = from address in stack
                          orderby address ascending
                          let type = _heap.GetObjectType(address)
                          select new { Address = address, Type = type.Name, MetadataToken = type.MetadataToken, };
         return enumerable.ToList();
     });
 }
Пример #2
0
        private static List<ClrRoot> FillRootDictionary(ClrHeap heap)
        {
            List<ClrRoot> roots = new List<ClrRoot>(heap.EnumerateRoots());
            foreach (var root in roots)
            {
                List<ClrRoot> list;
                if (!m_rootDict.TryGetValue(root.Object, out list))
                {
                    list = new List<ClrRoot>();
                    m_rootDict[root.Object] = list;
                }

                list.Add(root);
            }
            return roots;
        }
Пример #3
0
        private static ObjectSet GetLiveObjects(ClrHeap heap)
        {
            ObjectSet considered = new ObjectSet(heap);
            Stack<ulong> eval = new Stack<ulong>();

            foreach (var root in heap.EnumerateRoots())
                eval.Push(root.Object);

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

                considered.Add(obj);

                var type = heap.GetObjectType(obj);
                if (type == null)  // Only if heap corruption
                    continue;

                type.EnumerateRefsOfObject(obj, delegate(ulong child, int offset)
                {
                    if (child != 0 && !considered.Contains(child))
                        eval.Push(child);
                });
            }

            return considered;
        }