diff options
-rw-r--r-- | mcs/class/corlib/System.Diagnostics/StackTrace.cs | 94 | ||||
-rw-r--r-- | mcs/tools/mono-symbolicate/StackFrameData.cs | 39 | ||||
-rw-r--r-- | mcs/tools/mono-symbolicate/StackTraceMetadata.cs | 36 | ||||
-rw-r--r-- | mcs/tools/mono-symbolicate/SymbolManager.cs | 10 | ||||
-rw-r--r-- | mcs/tools/mono-symbolicate/mono-symbolicate.exe.sources | 1 | ||||
-rw-r--r-- | mcs/tools/mono-symbolicate/symbolicate.cs | 95 |
6 files changed, 55 insertions, 220 deletions
diff --git a/mcs/class/corlib/System.Diagnostics/StackTrace.cs b/mcs/class/corlib/System.Diagnostics/StackTrace.cs index ba77979609f..ccf9f835734 100644 --- a/mcs/class/corlib/System.Diagnostics/StackTrace.cs +++ b/mcs/class/corlib/System.Diagnostics/StackTrace.cs @@ -182,6 +182,20 @@ namespace System.Diagnostics { return frames; } + static bool isAotidSet; + static string aotid; + static string GetAotId () + { + if (!isAotidSet) { + aotid = Assembly.GetAotId (); + if (aotid != null) + aotid = new Guid (aotid).ToString ("N"); + isAotidSet = true; + } + + return aotid; + } + bool AddFrames (StringBuilder sb) { bool printOffset; @@ -219,8 +233,18 @@ namespace System.Diagnostics { sb.AppendFormat (" [0x{0:x5}]", frame.GetILOffset ()); } - sb.AppendFormat (debugInfo, frame.GetSecureFileName (), - frame.GetFileLineNumber ()); + var filename = frame.GetSecureFileName (); + if (filename[0] == '<') { + var mvid = frame.GetMethod ().Module.ModuleVersionId.ToString ("N"); + var aotid = GetAotId (); + if (frame.GetILOffset () != -1 || aotid == null) { + filename = string.Format ("<{0}>", mvid); + } else { + filename = string.Format ("<{0}#{1}>", mvid, aotid); + } + } + + sb.AppendFormat (debugInfo, filename, frame.GetFileLineNumber ()); } } @@ -291,8 +315,6 @@ namespace System.Diagnostics { if (!t.AddFrames (sb)) continue; - t.AddMetadata (sb); - sb.Append (Environment.NewLine); sb.Append ("--- End of stack trace from previous location where exception was thrown ---"); sb.Append (Environment.NewLine); @@ -300,78 +322,14 @@ namespace System.Diagnostics { } AddFrames (sb); - AddMetadata (sb); return sb.ToString (); } - void AddMetadata (StringBuilder sb) - { - if (metadataHandlers == null) - InitMetadataHandlers (); - - foreach (var handler in metadataHandlers) { - var lines = handler.Value (this); - using (var reader = new StringReader (lines)) { - string line; - while ((line = reader.ReadLine()) != null) { - sb.AppendLine (); - sb.AppendFormat ("[{0}] {1}", handler.Key, line); - } - } - } - } - internal String ToString (TraceFormat traceFormat) { // TODO: return ToString (); } - - static void InitMetadataHandlers () - { - metadataHandlers = new Dictionary<string, Func<StackTrace, string>> (StringComparer.Ordinal); - - var aotid = Assembly.GetAotId (); - if (aotid != null) - AddMetadataHandler ("AOTID", st => { return new Guid (aotid).ToString ("N"); }); - - AddMetadataHandler ("MVID", st => { - var mvidLines = new Dictionary<Guid, List<int>> (); - var frames = st.GetFrames (); - for (var lineNumber = 0; lineNumber < frames.Length; lineNumber++) { - var method = frames[lineNumber].GetMethod (); - if (method == null) - continue; - var mvid = method.Module.ModuleVersionId; - - List<int> lines = null; - if (!mvidLines.TryGetValue (mvid, out lines)) { - lines = new List<int> (); - mvidLines.Add (mvid, lines); - } - - lines.Add (lineNumber); - } - - var mvids = new List<Guid> (mvidLines.Keys); - mvids.Sort (); - - var sb = new StringBuilder (); - foreach (var mvid in mvids) - sb.AppendLine (string.Format ("{0} {1}", mvid.ToString ("N"), string.Join (",", mvidLines[mvid]))); - - return sb.ToString (); - }); - } - - // This method signature should not change, apps can use it with reflection to add custom metadata handlers. - private static void AddMetadataHandler (string id, Func<StackTrace, string> handler) - { - if (metadataHandlers == null) - InitMetadataHandlers (); - - metadataHandlers.Add (id, handler); - } } } diff --git a/mcs/tools/mono-symbolicate/StackFrameData.cs b/mcs/tools/mono-symbolicate/StackFrameData.cs index ed5134709cd..0177fcd6106 100644 --- a/mcs/tools/mono-symbolicate/StackFrameData.cs +++ b/mcs/tools/mono-symbolicate/StackFrameData.cs @@ -6,7 +6,7 @@ namespace Mono { class StackFrameData { - static Regex regex = new Regex (@"\w*at (?<Method>.+) *(\[0x(?<IL>.+)\]|<0x.+ \+ 0x(?<NativeOffset>.+)>( (?<MethodIndex>\d+)|)) in <filename unknown>:0"); + static Regex regex = new Regex (@"\w*at (?<Method>.+) *(\[0x(?<IL>.+)\]|<0x.+ \+ 0x(?<NativeOffset>.+)>( (?<MethodIndex>\d+)|)) in <(?<MVID>[^>#]+)(#(?<AOTID>[^>]+)|)>:0"); public readonly string TypeFullName; public readonly string MethodSignature; @@ -14,13 +14,13 @@ namespace Mono public readonly bool IsILOffset; public readonly uint MethodIndex; public readonly string Line; - - public readonly bool IsValid; + public readonly string Mvid; + public readonly string Aotid; public string File { get; private set; } public int LineNumber { get; private set; } - private StackFrameData (string line, string typeFullName, string methodSig, int offset, bool isILOffset, uint methodIndex) + private StackFrameData (string line, string typeFullName, string methodSig, int offset, bool isILOffset, uint methodIndex, string mvid, string aotid) { LineNumber = -1; @@ -30,15 +30,8 @@ namespace Mono Offset = offset; IsILOffset = isILOffset; MethodIndex = methodIndex; - - IsValid = true; - } - - private StackFrameData (string line) - { - LineNumber = -1; - - Line = line; + Mvid = mvid; + Aotid = aotid; } public static bool TryParse (string line, out StackFrameData stackFrame) @@ -46,13 +39,8 @@ namespace Mono stackFrame = null; var match = regex.Match (line); - if (!match.Success) { - if (line.Trim ().StartsWith ("at ", StringComparison.InvariantCulture)) { - stackFrame = new StackFrameData (line); - return true; - } + if (!match.Success) return false; - } string typeFullName, methodSignature; var methodStr = match.Groups ["Method"].Value.Trim (); @@ -67,7 +55,10 @@ namespace Mono if (!string.IsNullOrEmpty (match.Groups ["MethodIndex"].Value)) methodIndex = uint.Parse (match.Groups ["MethodIndex"].Value, CultureInfo.InvariantCulture); - stackFrame = new StackFrameData (line, typeFullName, methodSignature, offset, isILOffset, methodIndex); + var mvid = match.Groups ["MVID"].Value; + var aotid = match.Groups ["AOTID"].Value; + + stackFrame = new StackFrameData (line, typeFullName, methodSignature, offset, isILOffset, methodIndex, mvid, aotid); return true; } @@ -106,11 +97,9 @@ namespace Mono LineNumber = lineNumber; } - public override string ToString () { - if (Line.Contains ("<filename unknown>:0") && LineNumber != -1) - return Line.Replace ("<filename unknown>:0", string.Format ("{0}:{1}", File, LineNumber)); - - return Line; + public override string ToString () + { + return string.Format ("{0} in {1}:{2} ", Line.Substring (0, Line.IndexOf(" in <", StringComparison.Ordinal)), File, LineNumber); } } } diff --git a/mcs/tools/mono-symbolicate/StackTraceMetadata.cs b/mcs/tools/mono-symbolicate/StackTraceMetadata.cs deleted file mode 100644 index 4aa47532320..00000000000 --- a/mcs/tools/mono-symbolicate/StackTraceMetadata.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Text.RegularExpressions; - -namespace Mono -{ - class StackTraceMetadata - { - static Regex regex = new Regex (@"\[(?<Id>.+)\] (?<Value>.+)"); - - public readonly string Id; - public readonly string Value; - public readonly string Line; - - private StackTraceMetadata (string line, string id, string val) - { - Line = line; - Id = id; - Value = val; - } - - public static bool TryParse (string line, out StackTraceMetadata metadata) - { - metadata = null; - - var match = regex.Match (line); - if (!match.Success) - return false; - - string id = match.Groups ["Id"].Value; - string val = match.Groups ["Value"].Value; - - metadata = new StackTraceMetadata (line, id, val); - - return true; - } - } -} diff --git a/mcs/tools/mono-symbolicate/SymbolManager.cs b/mcs/tools/mono-symbolicate/SymbolManager.cs index 42990e5325e..734aa3a1660 100644 --- a/mcs/tools/mono-symbolicate/SymbolManager.cs +++ b/mcs/tools/mono-symbolicate/SymbolManager.cs @@ -19,18 +19,18 @@ namespace Mono this.logger = logger; } - internal bool TryResolveLocation (StackFrameData sfData, string mvid, string aotid) + internal bool TryResolveLocation (StackFrameData sfData) { - if (mvid == null) + if (sfData.Mvid == null) return false; - var assemblyLocProvider = GetOrCreateAssemblyLocationProvider (mvid); + var assemblyLocProvider = GetOrCreateAssemblyLocationProvider (sfData.Mvid); if (assemblyLocProvider == null) return false; SeqPointInfo seqPointInfo = null; - if (!sfData.IsILOffset && aotid != null) - seqPointInfo = GetOrCreateSeqPointInfo (aotid); + if (!sfData.IsILOffset && sfData.Aotid != null) + seqPointInfo = GetOrCreateSeqPointInfo (sfData.Aotid); return assemblyLocProvider.TryResolveLocation (sfData, seqPointInfo); } diff --git a/mcs/tools/mono-symbolicate/mono-symbolicate.exe.sources b/mcs/tools/mono-symbolicate/mono-symbolicate.exe.sources index daa4ebfb64b..6cb8042e9c5 100644 --- a/mcs/tools/mono-symbolicate/mono-symbolicate.exe.sources +++ b/mcs/tools/mono-symbolicate/mono-symbolicate.exe.sources @@ -2,7 +2,6 @@ symbolicate.cs LocationProvider.cs SeqPointInfo.cs StackFrameData.cs -StackTraceMetadata.cs SymbolManager.cs Logger.cs ../../class/Mono.Options/Mono.Options/Options.cs diff --git a/mcs/tools/mono-symbolicate/symbolicate.cs b/mcs/tools/mono-symbolicate/symbolicate.cs index 78b6945f149..2c04a27eef0 100644 --- a/mcs/tools/mono-symbolicate/symbolicate.cs +++ b/mcs/tools/mono-symbolicate/symbolicate.cs @@ -80,8 +80,16 @@ namespace Mono var symbolManager = new SymbolManager (msymDir, logger); using (StreamReader r = new StreamReader (inputFile)) { - var sb = Process (r, symbolManager); - Console.Write (sb.ToString ()); + for (var line = r.ReadLine (); line != null; line = r.ReadLine ()) { + StackFrameData sfData; + if (StackFrameData.TryParse (line, out sfData) && + symbolManager.TryResolveLocation (sfData)) { + Console.WriteLine (sfData.ToString ()); + continue; + } + + Console.WriteLine (line); + } } } @@ -94,88 +102,5 @@ namespace Mono symbolManager.StoreSymbols (lookupDirs); } - - public static StringBuilder Process (StreamReader reader, SymbolManager symbolManager) - { - List<StackFrameData> stackFrames = new List<StackFrameData>(); - List<StackTraceMetadata> metadata = new List<StackTraceMetadata>(); - StringBuilder sb = new StringBuilder (); - bool linesEnded = false; - - for (var line = reader.ReadLine (); line != null; line = reader.ReadLine ()) { - StackFrameData sfData; - if (!linesEnded && StackFrameData.TryParse (line, out sfData)) { - stackFrames.Add (sfData); - continue; - } - - if (stackFrames.Count > 0) { - linesEnded = true; - - StackTraceMetadata stMetadata; - if (StackTraceMetadata.TryParse (line, out stMetadata)) { - metadata.Add (stMetadata); - continue; - } - - DumpStackTrace (symbolManager, sb, stackFrames, metadata); - - // Clear lists for next stack trace - stackFrames.Clear (); - metadata.Clear (); - } - - linesEnded = false; - - // Append last line - sb.AppendLine (line); - } - - if (stackFrames.Count > 0) - DumpStackTrace (symbolManager, sb, stackFrames, metadata); - - return sb; - } - - private static void DumpStackTrace (SymbolManager symbolManager, StringBuilder sb, List<StackFrameData> stackFrames, List<StackTraceMetadata> metadata) - { - string aotid = null; - var aotidMetadata = metadata.FirstOrDefault ( m => m.Id == "AOTID" ); - if (aotidMetadata != null) - aotid = aotidMetadata.Value; - - var linesMvid = ProcessLinesMVID (metadata); - var lineNumber = -1; - foreach (var sfData in stackFrames) { - string mvid = null; - lineNumber++; - if (!sfData.IsValid) - continue; - if (linesMvid.ContainsKey (lineNumber)) - mvid = linesMvid [lineNumber]; - - symbolManager.TryResolveLocation (sfData, mvid, aotid); - - sb.AppendLine (sfData.ToString ()); - } - - foreach (var m in metadata) - sb.AppendLine (m.Line); - } - - private static Dictionary<int, string> ProcessLinesMVID (List<StackTraceMetadata> metadata) - { - var linesMvid = new Dictionary<int, string> (); - var mvidData = metadata.Where ( m => m.Id == "MVID" ).Select ( m => m.Value ); - foreach (var m in mvidData) { - var s1 = m.Split (new char[] {' '}, 2); - var mvid = s1 [0]; - var lines = s1 [1].Split (','); - foreach (var line in lines) - linesMvid.Add (int.Parse (line), mvid); - } - - return linesMvid; - } } } |