private static List <EnhancedStackFrame> GetFrames(StackTrace stackTrace) { var frames = new List <EnhancedStackFrame>(); var stackFrames = stackTrace.GetFrames(); if (stackFrames == null) { return(frames); } for (var i = 0; i < stackFrames.Length; i++) { var frame = stackFrames[i]; var method = frame.GetMethod(); // Always show last stackFrame if (!ShowInStackTrace(method) && i < stackFrames.Length - 1) { continue; } var fileName = frame.GetFileName(); var row = frame.GetFileLineNumber(); var column = frame.GetFileColumnNumber(); var stackFrame = new EnhancedStackFrame(frame, GetMethodDisplayString(method), fileName, row, column); frames.Add(stackFrame); } return(frames); }
private static List <EnhancedStackFrame> GetFrames(StackTrace stackTrace) { var frames = new List <EnhancedStackFrame>(); var stackFrames = stackTrace.GetFrames(); if (stackFrames == null) { return(frames); } var portablePdbReader = new Lazy <IPortablePdbReader>(() => { return((IPortablePdbReader)portablePdbReaderDomain.Value.CreateInstanceAndUnwrap( "Ben.Demystifier.VS.PortablePdbReader", "System.Diagnostics.Internal.PortablePdbReader")); }); try { for (var i = 0; i < stackFrames.Length; i++) { var frame = stackFrames[i]; var method = frame.GetMethod(); // Always show last stackFrame if (!ShowInStackTrace(method) && i < stackFrames.Length - 1) { continue; } var fileName = frame.GetFileName(); var row = frame.GetFileLineNumber(); var column = frame.GetFileColumnNumber(); var ilOffset = frame.GetILOffset(); if (string.IsNullOrEmpty(fileName) && ilOffset >= 0) { // .NET Framework and older versions of mono don't support portable PDBs // so we read it manually to get file name and line information portablePdbReader.Value.PopulateStackFrame(method.Module.Assembly.IsDynamic, method.Module.Assembly.Location, method.MetadataToken, frame.GetILOffset(), out fileName, out row, out column); } var stackFrame = new EnhancedStackFrame(frame, GetMethodDisplayString(method), fileName, row, column); frames.Add(stackFrame); } return(frames); } finally { if (portablePdbReader.IsValueCreated) { portablePdbReader.Value.Dispose(); } } }
private static List <EnhancedStackFrame> GetFrames(StackTrace stackTrace) { var frames = new List <EnhancedStackFrame>(); var stackFrames = stackTrace.GetFrames(); if (stackFrames == null) { return(frames); } // Portable reader is not supported in BuildXL because it requires some dependencies that can't be used today. // using (var portablePdbReader = new PortablePdbReader()) { for (var i = 0; i < stackFrames.Length; i++) { var frame = stackFrames[i]; var method = frame.GetMethod(); // Always show last stackFrame if (!ShowInStackTrace(method) && i < stackFrames.Length - 1) { continue; } var fileName = frame.GetFileName(); var row = frame.GetFileLineNumber(); var column = frame.GetFileColumnNumber(); var ilOffset = frame.GetILOffset(); // This feature is not supported in BuildXL because it requires some dependencies that can't be used today. //if (string.IsNullOrEmpty(fileName) && ilOffset >= 0) //{ // // .NET Framework and older versions of mono don't support portable PDBs // // so we read it manually to get file name and line information // // portablePdbReader.PopulateStackFrame(frame, method, frame.GetILOffset(), out fileName, out row, out column); // return frames; //} var stackFrame = new EnhancedStackFrame(frame, GetMethodDisplayString(method), fileName, row, column); frames.Add(stackFrame); } return(frames); } }
private static List <EnhancedStackFrame> GetFrames(StackTrace stackTrace) { var frames = new List <EnhancedStackFrame>(); var stackFrames = stackTrace.GetFrames(); if (stackFrames == null) { return(frames); } using (var portablePdbReader = new PortablePdbReader()) { for (var i = 0; i < stackFrames.Length; i++) { var frame = stackFrames[i]; var method = frame.GetMethod(); // Always show last stackFrame if (method != null && !ShowInStackTrace(method) && i < stackFrames.Length - 1) { continue; } var fileName = frame.GetFileName(); var row = frame.GetFileLineNumber(); var column = frame.GetFileColumnNumber(); var ilOffset = frame.GetILOffset(); if (method != null && string.IsNullOrEmpty(fileName) && ilOffset >= 0) { // .NET Framework and older versions of mono don't support portable PDBs // so we read it manually to get file name and line information portablePdbReader.PopulateStackFrame(frame, method, frame.GetILOffset(), out fileName, out row, out column); } var stackFrame = new EnhancedStackFrame(frame, GetMethodDisplayString(method), fileName, row, column); frames.Add(stackFrame); } return(frames); } }
public static List <EnhancedStackFrame> GetFrames(StackTrace stackTrace) { var frames = new List <EnhancedStackFrame>(); var stackFrames = stackTrace.GetFrames(); if (stackFrames == null) { return(frames); } EnhancedStackFrame?lastFrame = null; PortablePdbReader? portablePdbReader = null; try { for (var i = 0; i < stackFrames.Length; i++) { var frame = stackFrames[i]; if (frame is null) { continue; } var method = frame.GetMethod(); // Always show last stackFrame if (method != null && !ShowInStackTrace(method) && i < stackFrames.Length - 1) { continue; } var fileName = frame.GetFileName(); var row = frame.GetFileLineNumber(); var column = frame.GetFileColumnNumber(); var ilOffset = frame.GetILOffset(); if (method != null && string.IsNullOrEmpty(fileName) && ilOffset >= 0) { // .NET Framework and older versions of mono don't support portable PDBs // so we read it manually to get file name and line information (portablePdbReader ??= new PortablePdbReader()).PopulateStackFrame(frame, method, frame.GetILOffset(), out fileName, out row, out column); } if (method is null) { // Method can't be null continue; } var resolvedMethod = GetMethodDisplayString(method); if (lastFrame?.IsEquivalent(resolvedMethod, fileName, row, column) ?? false) { lastFrame.IsRecursive = true; } else { var stackFrame = new EnhancedStackFrame(frame, resolvedMethod, fileName, row, column); frames.Add(stackFrame); lastFrame = stackFrame; } } } finally { portablePdbReader?.Dispose(); } return(frames); }