コード例 #1
0
        public override IEnumerable <ClrException> EnumerateSerializedExceptions()
        {
            if (_sosNativeSerializedExceptionSupport == null)
            {
                return(new ClrException[0]);
            }

            var exceptionById = new Dictionary <ulong, NativeException>();
            ISerializedExceptionEnumerator serializedExceptionEnumerator = _sosNativeSerializedExceptionSupport.GetSerializedExceptions();

            while (serializedExceptionEnumerator.HasNext())
            {
                ISerializedException serializedException = serializedExceptionEnumerator.Next();

                //build the stack frames
                IList <ClrStackFrame>           stackFrames = new List <ClrStackFrame>();
                ISerializedStackFrameEnumerator serializedStackFrameEnumerator = serializedException.StackFrames;
                while (serializedStackFrameEnumerator.HasNext())
                {
                    ISerializedStackFrame serializedStackFrame = serializedStackFrameEnumerator.Next();

                    NativeModule nativeModule = ((NativeHeap)this.GetHeap()).GetModuleFromAddress(serializedStackFrame.IP);
                    string       symbolName   = null;
                    stackFrames.Add(new NativeHeap.NativeStackFrame(serializedStackFrame.IP, symbolName, nativeModule));
                }

                //create a new exception and populate the fields

                exceptionById.Add(serializedException.ExceptionId, new NativeException(
                                      this.GetHeap().GetTypeByMethodTable(serializedException.ExceptionEEType),
                                      serializedException.ExceptionCCWPtr,
                                      serializedException.HResult,
                                      serializedException.ThreadId,
                                      serializedException.ExceptionId,
                                      serializedException.InnerExceptionId,
                                      serializedException.NestingLevel,
                                      stackFrames));
            }

            var usedAsInnerException = new HashSet <ulong>();

            foreach (var nativeException in exceptionById.Values)
            {
                if (nativeException.InnerExceptionId > 0)
                {
                    NativeException innerException;
                    if (exceptionById.TryGetValue(nativeException.InnerExceptionId, out innerException))
                    {
                        nativeException.setInnerException(innerException);
                        usedAsInnerException.Add(innerException.ExceptionId);
                    }
                }
            }

            return(exceptionById.Keys.Except(usedAsInnerException).Select(id => exceptionById[id]).Cast <ClrException>().ToList());
        }
コード例 #2
0
        internal NativeHeap(NativeRuntime runtime, NativeModule[] modules)
            : base(runtime)
        {
            NativeRuntime = runtime;
            _modules      = modules;

            _mrtModule = FindMrtModule();

            CreateFreeType();
            InitSegments(runtime);
        }
コード例 #3
0
ファイル: heap.cs プロジェクト: popotans/netext
        internal NativeHeap(NativeRuntime runtime, NativeModule[] modules, TextWriter log)
            : base(runtime)
        {
            Log           = log;
            NativeRuntime = runtime;
            _modules      = modules;
            _mrtModule    = FindMrtModule();

            CreateFreeType();
            InitSegments(runtime);
        }
コード例 #4
0
ファイル: heap.cs プロジェクト: kailer89/clrmd
        internal NativeHeap(NativeRuntime runtime, NativeModule[] modules, TextWriter log)
            : base(runtime)
        {
            Log = log;
            NativeRuntime = runtime;
            _modules = modules;
            _mrtModule = FindMrtModule();

            CreateFreeType();
            InitSegments(runtime);
        }
コード例 #5
0
ファイル: types.cs プロジェクト: tomasr/clrmd
        public NativeType(NativeHeap heap, int index, NativeModule module, string name, ulong eeType, Microsoft.Diagnostics.Runtime.Desktop.IMethodTableData mtData)
        {
            _heap = heap;
            _module = module;
            _name = name;
            _eeType = eeType;
            _index = index;

            _baseSize = mtData.BaseSize;
            _componentSize = mtData.ComponentSize;
            _containsPointers = mtData.ContainsPointers;
        }
コード例 #6
0
ファイル: types.cs プロジェクト: popotans/netext
        public NativeType(NativeHeap heap, int index, NativeModule module, string name, ulong eeType, Microsoft.Diagnostics.Runtime.Desktop.IMethodTableData mtData)
        {
            _heap   = heap;
            _module = module;
            _name   = name;
            _eeType = eeType;
            _index  = index;

            _baseSize         = mtData.BaseSize;
            _componentSize    = mtData.ComponentSize;
            _containsPointers = mtData.ContainsPointers;
        }
コード例 #7
0
        private NativeModule[] ConvertModuleList(List <ModuleInfo> modules)
        {
            NativeModule[] result = new NativeModule[modules.Count];

            int i = 0;

            foreach (var module in modules)
            {
                result[i++] = new NativeModule(this, module);
            }

            return(result);
        }
コード例 #8
0
        public NativeType(NativeHeap heap, NativeModule module, string name, ulong eeType, Desktop.IMethodTableData mtData)
        {
            _heap   = heap;
            _module = module;
            _name   = name;
            _eeType = eeType;

            if (mtData != null)
            {
                _baseSize         = mtData.BaseSize;
                _componentSize    = mtData.ComponentSize;
                _containsPointers = mtData.ContainsPointers;
            }
        }
コード例 #9
0
ファイル: NativeTypes.cs プロジェクト: venux/netext
        public NativeType(NativeHeap heap, int index, NativeModule module, string name, ulong eeType, Desktop.IMethodTableData mtData)
        {
            _heap   = heap;
            _module = module;
            _name   = name;
            _eeType = eeType;
            _index  = index;
            _gcDesc = new Lazy <GCDesc>(FillGCDesc);

            if (mtData != null)
            {
                _baseSize         = mtData.BaseSize;
                _componentSize    = mtData.ComponentSize;
                _containsPointers = mtData.ContainsPointers;
            }
        }
コード例 #10
0
ファイル: NativeHeap.cs プロジェクト: JeffCyr/clrmd
        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);

        }
コード例 #11
0
ファイル: NativeHeap.cs プロジェクト: venux/netext
        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);
        }
コード例 #12
0
ファイル: NativeHeap.cs プロジェクト: venux/netext
        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);
        }
コード例 #13
0
        public override IEnumerable <ClrException> EnumerateSerializedExceptions()
        {
            if (_sosNativeSerializedExceptionSupport == null)
            {
                return(new ClrException[0]);
            }

            var exceptionById = new Dictionary <ulong, NativeException>();
            ISerializedExceptionEnumerator serializedExceptionEnumerator = _sosNativeSerializedExceptionSupport.GetSerializedExceptions();

            while (serializedExceptionEnumerator.HasNext())
            {
                ISerializedException serializedException = serializedExceptionEnumerator.Next();

                //build the stack frames
                IList <ClrStackFrame>           stackFrames = new List <ClrStackFrame>();
                ISerializedStackFrameEnumerator serializedStackFrameEnumerator = serializedException.StackFrames;
                while (serializedStackFrameEnumerator.HasNext())
                {
                    ISerializedStackFrame serializedStackFrame = serializedStackFrameEnumerator.Next();

                    NativeModule nativeModule = ((NativeHeap)this.GetHeap()).GetModuleFromAddress(serializedStackFrame.IP);
                    string       symbolName   = null;
                    if (nativeModule != null)
                    {
                        if (nativeModule.Pdb != null)
                        {
                            try
                            {
                                ISymbolResolver resolver = this.DataTarget.SymbolProvider.GetSymbolResolver(nativeModule.Pdb.FileName, nativeModule.Pdb.Guid, nativeModule.Pdb.Revision);

                                if (resolver != null)
                                {
                                    symbolName = resolver.GetSymbolNameByRVA((uint)(serializedStackFrame.IP - nativeModule.ImageBase));
                                }
                                else
                                {
                                    Trace.WriteLine($"Unable to find symbol resolver for PDB [Filename:{nativeModule.Pdb.FileName}, GUID:{nativeModule.Pdb.Guid}, Revision:{nativeModule.Pdb.Revision}]");
                                }
                            }
                            catch (Exception e)
                            {
                                Trace.WriteLine($"Error in finding the symbol resolver for PDB [Filename:{nativeModule.Pdb.FileName}, GUID:{nativeModule.Pdb.Guid}, Revision:{nativeModule.Pdb.Revision}]: {e.Message}");
                                Trace.WriteLine("Check previous traces for additional information");
                            }
                        }
                        else
                        {
                            Trace.WriteLine(String.Format("PDB not found for IP {0}, Module={1}", serializedStackFrame.IP, nativeModule.Name));
                        }
                    }
                    else
                    {
                        Trace.WriteLine(String.Format("Unable to resolve module for IP {0}", serializedStackFrame.IP));
                    }

                    stackFrames.Add(new NativeHeap.NativeStackFrame(serializedStackFrame.IP, symbolName, nativeModule));
                }

                //create a new exception and populate the fields

                exceptionById.Add(serializedException.ExceptionId, new NativeException(
                                      this.GetHeap().GetTypeByMethodTable(serializedException.ExceptionEEType),
                                      serializedException.ExceptionCCWPtr,
                                      serializedException.HResult,
                                      serializedException.ThreadId,
                                      serializedException.ExceptionId,
                                      serializedException.InnerExceptionId,
                                      serializedException.NestingLevel,
                                      stackFrames));
            }

            var usedAsInnerException = new HashSet <ulong>();

            foreach (var nativeException in exceptionById.Values)
            {
                if (nativeException.InnerExceptionId > 0)
                {
                    NativeException innerException;
                    if (exceptionById.TryGetValue(nativeException.InnerExceptionId, out innerException))
                    {
                        nativeException.setInnerException(innerException);
                        usedAsInnerException.Add(innerException.ExceptionId);
                    }
                }
            }

            return(exceptionById.Keys.Except(usedAsInnerException).Select(id => exceptionById[id]).Cast <ClrException>().ToList());
        }
コード例 #14
0
ファイル: runtime.cs プロジェクト: mwatts/clrmd
        private NativeModule[] ConvertModuleList(List<ModuleInfo> modules)
        {
            NativeModule[] result = new NativeModule[modules.Count];

            int i = 0;
            foreach (var module in modules)
                result[i++] = new NativeModule(this, module);

            return result;
        }
コード例 #15
0
ファイル: heap.cs プロジェクト: popotans/netext
        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);
        }