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());
        }
Example #2
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());
        }