Exemplo n.º 1
0
        public override IEnumerable<ClrHandle> EnumerateHandles()
        {
            object tmp;
            if (_sos.GetHandleEnum(out tmp) < 0)
                return null;

            ISOSHandleEnum handleEnum = tmp as ISOSHandleEnum;
            if (handleEnum == null)
                return null;

            HandleData[] handles = new HandleData[1];
            List<ClrHandle> res = new List<ClrHandle>();

            uint fetched = 0;
            do
            {
                if (handleEnum.Next(1, handles, out fetched) != 0)
                    break;

                ClrHandle handle = new ClrHandle(this, GetHeap(), handles[0]);
                res.Add(handle);

                handle = handle.GetInteriorHandle();
                if (handle != null)
                    res.Add(handle);
            } while (fetched == 1);

            return res;
        }
Exemplo n.º 2
0
        private IEnumerable<ClrHandle> EnumerateHandleWorker()
        {
            // handles was fully populated already
            if (_handles != null && _handleEnum == null)
                yield break;

            // Create _handleEnum if it's not already created.
            object tmp;
            if (_handleEnum == null)
            {
                if (_sos.GetHandleEnum(out tmp) < 0)
                    yield break;

                _handleEnum = tmp as ISOSHandleEnum;
                if (_handleEnum == null)
                    yield break;

                _handles = new List<ClrHandle>();
            }
            
            // We already partially enumerated handles before, start with them.
            foreach (var handle in _handles)
                yield return handle;
            
            HandleData[] handles = new HandleData[8];
            uint fetched = 0;
            do
            {
                if (_handleEnum.Next((uint)handles.Length, handles, out fetched) < 0 || fetched <= 0)
                    break;

                int curr = _handles.Count;
                for (int i = 0; i < fetched; i++)
                {
                    ClrHandle handle = new ClrHandle(this, GetHeap(), handles[i]);
                    _handles.Add(handle);

                    handle = handle.GetInteriorHandle();
                    if (handle != null)
                    {
                        _handles.Add(handle);
                        yield return handle;
                    }
                }

                for (int i = curr; i < _handles.Count; i++)
                    yield return _handles[i];

            } while (fetched > 0);

            _handleEnum = null;
        }
Exemplo n.º 3
0
        internal ClrHandle(Microsoft.Diagnostics.Runtime.Desktop.V45Runtime clr, ClrHeap heap, Microsoft.Diagnostics.Runtime.Desktop.HandleData handleData)
        {
            Address obj;

            Address = handleData.Handle;
            clr.ReadPointer(Address, out obj);

            Object = obj;
            Type   = heap.GetObjectType(obj);

            uint refCount = 0;

            if (handleData.Type == (int)HandleType.RefCount)
            {
                if (handleData.IsPegged != 0)
                {
                    refCount = handleData.JupiterRefCount;
                }

                if (refCount < handleData.RefCount)
                {
                    refCount = handleData.RefCount;
                }

                if (Type != null)
                {
                    if (Type.IsCCW(obj))
                    {
                        CcwData data = Type.GetCCWData(obj);
                        if (data != null && refCount < data.RefCount)
                        {
                            refCount = (uint)data.RefCount;
                        }
                    }
                    else if (Type.IsRCW(obj))
                    {
                        RcwData data = Type.GetRCWData(obj);
                        if (data != null && refCount < data.RefCount)
                        {
                            refCount = (uint)data.RefCount;
                        }
                    }
                }

                RefCount = refCount;
            }


            HandleType = (HandleType)handleData.Type;
            AppDomain  = clr.GetAppDomainByAddress(handleData.AppDomain);

            if (HandleType == HandleType.Dependent)
            {
                DependentTarget = handleData.Secondary;
                DependentType   = heap.GetObjectType(handleData.Secondary);
            }
        }