From 59cccab00da71a4d7e98947060718eab42e46682 Mon Sep 17 00:00:00 2001 From: Marcos Henrich Date: Fri, 20 May 2016 12:03:46 +0100 Subject: [PATCH] [corlib] Added metadata handlers to StackTrace Added a reflectable static method that can be used to customize data displayed after a stack trace. Added metadata handler that display the AOTID of the executing assembly. --- .../corlib/System.Diagnostics/StackTrace.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/mcs/class/corlib/System.Diagnostics/StackTrace.cs b/mcs/class/corlib/System.Diagnostics/StackTrace.cs index 420b497fc9a..8b3f76a439e 100644 --- a/mcs/class/corlib/System.Diagnostics/StackTrace.cs +++ b/mcs/class/corlib/System.Diagnostics/StackTrace.cs @@ -37,6 +37,7 @@ using System.Security; using System.Security.Permissions; using System.Text; using System.Threading; +using System.IO; namespace System.Diagnostics { @@ -60,6 +61,15 @@ namespace System.Diagnostics { readonly StackTrace[] captured_traces; private bool debug_info; + private static Dictionary> metadataHandlers; + + static StackTrace () + { + metadataHandlers = new Dictionary> (); + + InitMetadataHandlers (); + } + [MethodImplAttribute (MethodImplOptions.NoInlining)] public StackTrace () { @@ -295,13 +305,38 @@ namespace System.Diagnostics { } AddFrames (sb); + + 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.Append (string.Format ("[{0}] {1}", handler.Key, line)); + } + } + } + return sb.ToString (); } + internal String ToString (TraceFormat traceFormat) { // TODO: return ToString (); } + + static void InitMetadataHandlers () + { + string aotid = Assembly.GetAotId (); + if (aotid != "00000000-0000-0000-0000-000000000000") + AddMetadataHandler ("AOTID", st => { return aotid; }); + } + + private static void AddMetadataHandler (string id, Func handler) + { + metadataHandlers.Add (id, handler); + } } } -- 2.25.1