Example #1
0
        public override IEnumerable <ClrRoot> EnumerateRoots(bool enumerateStatics)
        {
            /*// Stack objects.
             * foreach (var thread in NativeRuntime.Threads)
             *  foreach (var stackRef in NativeRuntime.EnumerateStackRoots(thread))
             *      yield return stackRef;*/

            // Static Variables.
            foreach (var root in NativeRuntime.EnumerateStaticRoots(enumerateStatics))
            {
                yield return(root);
            }

            // Handle Table.
            foreach (ClrRoot root in NativeRuntime.EnumerateHandleRoots())
            {
                yield return(root);
            }

            // Finalizer Queue.
            ClrAppDomain domain = NativeRuntime.AppDomains[0];

            foreach (ulong obj in NativeRuntime.EnumerateFinalizerQueueObjectAddresses())
            {
                ClrType type = GetObjectType(obj);
                if (type == null)
                {
                    continue;
                }

                yield return(new NativeFinalizerRoot(obj, type, domain, "finalizer root"));
            }
        }
Example #2
0
 public NativeThread(NativeRuntime runtime, ref NativeThreadData data, ulong address, bool finalizer)
 {
     data        = _data;
     IsFinalizer = finalizer;
     Address     = address;
     Runtime     = runtime;
 }
Example #3
0
        private bool FillGCDesc()
        {
            NativeRuntime runtime = _heap.NativeRuntime;

            int entries;

            if (!runtime.MemoryReader.TryReadDword(_eeType - (ulong)IntPtr.Size, out entries))
            {
                return(false);
            }

            // Get entries in map
            if (entries < 0)
            {
                entries = -entries;
            }

            int read;
            int slots = 1 + entries * 2;

            byte[] buffer = new byte[slots * IntPtr.Size];
            if (!runtime.ReadMemory(_eeType - (ulong)(slots * IntPtr.Size), buffer, buffer.Length, out read) || read != buffer.Length)
            {
                return(false);
            }

            // Construct the gc desc
            _gcDesc = new GCDesc(buffer);
            return(true);
        }
Example #4
0
 public NativeModule(NativeRuntime runtime, ModuleInfo module)
 {
     _runtime = runtime;
     _name = string.IsNullOrEmpty(module.FileName) ? "" : Path.GetFileNameWithoutExtension(module.FileName);
     _filename = module.FileName;
     _imageBase = module.ImageBase;
     _size = module.FileSize;
 }
Example #5
0
 public NativeModule(NativeRuntime runtime, ModuleInfo module)
 {
     _runtime   = runtime;
     _name      = string.IsNullOrEmpty(module.FileName) ? "" : Path.GetFileNameWithoutExtension(module.FileName);
     _filename  = module.FileName;
     _imageBase = module.ImageBase;
     _size      = module.FileSize;
 }
Example #6
0
        private void CreateFreeType()
        {
            ulong            free   = NativeRuntime.GetFreeType();
            IMethodTableData mtData = NativeRuntime.GetMethodTableData(free);

            _free          = new NativeType(this, _types.Count, _mrtModule, "Free", free, mtData);
            _indices[free] = _types.Count;
            _types.Add(_free);
        }
Example #7
0
        internal NativeHeap(NativeRuntime runtime, NativeModule[] modules, TextWriter log)
            : base(runtime)
        {
            Log           = log;
            NativeRuntime = runtime;
            _modules      = modules;
            _mrtModule    = FindMrtModule();

            CreateFreeType();
            InitSegments(runtime);
        }
Example #8
0
        internal NativeHeap(NativeRuntime runtime, NativeModule[] modules, TextWriter log)
            : base(runtime)
        {
            Log = log;
            NativeRuntime = runtime;
            _modules = modules;
            _mrtModule = FindMrtModule();

            CreateFreeType();
            InitSegments(runtime);
        }
Example #9
0
 public NativeStaticVar(NativeRuntime runtime, ulong addr, ulong obj, ClrType type, string name, bool pinned, bool interior)
 {
     Address    = addr;
     Object     = obj;
     _type      = type;
     _name      = name;
     _pinned    = pinned;
     _interior  = interior;
     _type      = runtime.Heap.GetObjectType(obj);
     _appDomain = runtime.GetRhAppDomain();
 }
Example #10
0
        internal NativeHeap(NativeRuntime runtime, NativeModule[] modules)
            : base(runtime)
        {
            NativeRuntime = runtime;
            _modules      = modules;

            _mrtModule = FindMrtModule();

            CreateFreeType();
            InitSegments(runtime);
        }
Example #11
0
        public override int ReadMemory(ulong address, byte[] buffer, int offset, int count)
        {
            if (offset != 0)
            {
                throw new NotImplementedException("Non-zero offsets not supported (yet)");
            }
            int bytesRead;

            if (!NativeRuntime.ReadMemory(address, buffer, count, out bytesRead))
            {
                return(0);
            }
            return(bytesRead);
        }
Example #12
0
        internal NativeHeap(NativeRuntime runtime, NativeModule[] modules)
            : base(runtime)
        {
            NativeRuntime = runtime;
            _modules = modules;

            _symProvider = runtime.DataTarget.SymbolProvider;
            if (_symProvider == null)
                throw new InvalidOperationException("You must set DataTarget.SymbolProvider to enumerate the heap on a .Net Native runtime.");

            _mrtModule = FindMrtModule();

            CreateFreeType();
            InitSegments(runtime);

        }
Example #13
0
        internal NativeHeap(NativeRuntime runtime, NativeModule[] modules)
            : base(runtime)
        {
            NativeRuntime = runtime;
            _modules      = modules;

            _symProvider = runtime.DataTarget.SymbolProvider;
            if (_symProvider == null)
            {
                throw new InvalidOperationException("You must set DataTarget.SymbolProvider to enumerate the heap on a .Net Native runtime.");
            }

            _mrtModule = FindMrtModule();

            CreateFreeType();
            InitSegments(runtime);
        }
Example #14
0
 public NativeHandleRootWalker(NativeRuntime runtime, bool dependentHandleSupport)
 {
     _heap = runtime.GetHeap();
     _domain = runtime.GetRhAppDomain();
     _dependentSupport = dependentHandleSupport;
 }
Example #15
0
 public NativeStaticVar(NativeRuntime runtime, Address addr, Address obj, ClrType type, string name, bool pinned, bool interior)
 {
     Address = addr;
     Object = obj;
     _type = type;
     _name = name;
     _pinned = pinned;
     _interior = interior;
     _type = runtime.GetHeap().GetObjectType(obj);
     _appDomain = runtime.GetRhAppDomain();
 }
Example #16
0
        private ClrType ConstructObjectType(ulong eeType)
        {
            IMethodTableData mtData = NativeRuntime.GetMethodTableData(eeType);

            if (mtData == null)
            {
                return(null);
            }

            ulong componentType = mtData.ElementTypeHandle;
            bool  isArray       = componentType != 0;

            // EEClass is the canonical method table.  I stuffed the pointer there instead of creating a new property.
            ulong canonType = isArray ? componentType : mtData.EEClass;

            if (!isArray && canonType != 0)
            {
                int index;
                if (!isArray && _indices.TryGetValue(canonType, out index))
                {
                    _indices[eeType] = index;  // Link the original eeType to its canonical GCHeapType.
                    return(_types[index]);
                }

                ulong tmp = eeType;
                eeType    = canonType;
                canonType = tmp;
            }


            NativeModule module = FindContainingModule(eeType);

            if (module == null && canonType != 0)
            {
                module = FindContainingModule(canonType);
            }

            string name = null;

            if (module != null)
            {
                Debug.Assert(module.ImageBase < eeType);

                PdbInfo         pdb = module.Pdb;
                ISymbolResolver resolver;
                if (pdb != null)
                {
                    if (!_resolvers.TryGetValue(module, out resolver))
                    {
                        _resolvers[module] = resolver = _symProvider.GetSymbolResolver(pdb.FileName, pdb.Guid, pdb.Revision);
                    }

                    name = resolver == null ? null : resolver.GetSymbolNameByRVA((uint)(eeType - module.ImageBase));
                }
            }

            if (name == null)
            {
                string moduleName = module != null?Path.GetFileNameWithoutExtension(module.FileName) : "UNKNWON";

                name = string.Format("{0}_{1:x}", moduleName, eeType);
            }

            int len = name.Length;

            if (name.EndsWith("::`vftable'"))
            {
                len -= 11;
            }

            int i = name.IndexOf('!') + 1;

            name = name.Substring(i, len - i);

            if (isArray)
            {
                name += "[]";
            }


            if (module == null)
            {
                module = _mrtModule;
            }

            NativeType type = new NativeType(this, _types.Count, module, name, eeType, mtData);

            _indices[eeType] = _types.Count;
            if (!isArray)
            {
                _indices[canonType] = _types.Count;
            }
            _types.Add(type);

            return(type);
        }
Example #17
0
 internal NativeHeap(NativeRuntime runtime)
 {
     Runtime = runtime;
 }
Example #18
0
 public NativeThread(NativeRuntime runtime, IThreadData thread, ulong address, bool finalizer) : base(thread, address, finalizer)
 {
     _runtime = runtime;
 }
Example #19
0
 public NativeStaticRootWalker(NativeRuntime runtime, bool resolveStatics)
 {
     Roots    = new List <ClrRoot>(128);
     _runtime = resolveStatics ? runtime : null;
     _heap    = _runtime.Heap;
 }
Example #20
0
 public NativeStaticRootWalker(NativeRuntime runtime, bool resolveStatics)
 {
     Roots = new List<ClrRoot>(128);
     _runtime = resolveStatics ? runtime : null;
     _heap = _runtime.GetHeap();
 }
Example #21
0
        private ClrType ConstructObjectType(ulong eeType)
        {
            IMethodTableData mtData = NativeRuntime.GetMethodTableData(eeType);

            if (mtData == null)
            {
                return(null);
            }

            ulong componentType = mtData.ElementTypeHandle;
            bool  isArray       = componentType != 0;

            // EEClass is the canonical method table.  I stuffed the pointer there instead of creating a new property.
            ulong canonType = isArray ? componentType : mtData.EEClass;

            if (!isArray && canonType != 0)
            {
                int index;
                if (!isArray && _indices.TryGetValue(canonType, out index))
                {
                    _indices[eeType] = index;  // Link the original eeType to its canonical GCHeapType.
                    return(_types[index]);
                }

                ulong tmp = eeType;
                eeType    = canonType;
                canonType = tmp;
            }

            string name = NativeRuntime.ResolveSymbol(eeType);

            if (string.IsNullOrEmpty(name))
            {
                name = NativeRuntime.ResolveSymbol(canonType);
                if (name == null)
                {
                    name = string.Format("unknown type {0:x}", eeType);
                }
            }


            int len = name.Length;

            if (name.EndsWith("::`vftable'"))
            {
                len -= 11;
            }

            int i = name.IndexOf('!') + 1;

            name = name.Substring(i, len - i);

            if (isArray)
            {
                name += "[]";
            }

            NativeModule module = FindContainingModule(eeType);

            if (module == null && canonType != 0)
            {
                module = FindContainingModule(canonType);
            }

            if (module == null)
            {
                module = _mrtModule;
            }

            NativeType type = new NativeType(this, _types.Count, module, name, eeType, mtData);

            _indices[eeType] = _types.Count;
            if (!isArray)
            {
                _indices[canonType] = _types.Count;
            }
            _types.Add(type);

            return(type);
        }
Example #22
0
 public NativeHandleRootWalker(NativeRuntime runtime, bool dependentHandleSupport)
 {
     _heap             = runtime.Heap;
     _domain           = runtime.GetRhAppDomain();
     _dependentSupport = dependentHandleSupport;
 }
Example #23
0
 public NativeThread(NativeRuntime runtime, IThreadData thread, ulong address, bool finalizer) : base(thread, address, finalizer)
 {
     _runtime = runtime;
 }