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()); }
internal NativeHeap(NativeRuntime runtime, NativeModule[] modules) : base(runtime) { NativeRuntime = runtime; _modules = modules; _mrtModule = FindMrtModule(); CreateFreeType(); InitSegments(runtime); }
internal NativeHeap(NativeRuntime runtime, NativeModule[] modules, TextWriter log) : base(runtime) { Log = log; NativeRuntime = runtime; _modules = modules; _mrtModule = FindMrtModule(); CreateFreeType(); InitSegments(runtime); }
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; }
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); }
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; } }
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; } }
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); }
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); }
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); }
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()); }
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; }
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); }