コード例 #1
0
        internal virtual IEnumerable <ClrRoot> EnumerateStackReferences(ClrThread thread, bool includeDead)
        {
            Address stackBase  = thread.StackBase;
            Address stackLimit = thread.StackLimit;

            if (stackLimit <= stackBase)
            {
                Address tmp = stackLimit;
                stackLimit = stackBase;
                stackBase  = tmp;
            }

            ClrAppDomain domain = GetAppDomainByAddress(thread.AppDomain);
            ClrHeap      heap   = GetHeap();
            var          mask   = ((ulong)(PointerSize - 1));
            var          cache  = MemoryReader;

            cache.EnsureRangeInCache(stackBase);
            for (Address stackPtr = stackBase; stackPtr < stackLimit; stackPtr += (uint)PointerSize)
            {
                Address objRef;
                if (cache.ReadPtr(stackPtr, out objRef))
                {
                    // If the value isn't pointer aligned, it cannot be a managed pointer.
                    if (heap.IsInHeap(objRef))
                    {
                        ulong mt;
                        if (heap.ReadPointer(objRef, out mt))
                        {
                            ClrType type = null;

                            if (mt > 1024)
                            {
                                type = heap.GetObjectType(objRef);
                            }

                            if (type != null && !type.IsFree)
                            {
                                yield return(new LocalVarRoot(stackPtr, objRef, type, domain, thread, false, true, false, null));
                            }
                        }
                    }
                }
            }
        }