[corlib] Changes StackTrace.ToString to use Exception format.
authorMarcos Henrich <marcos.henrich@xamarin.com>
Fri, 28 Aug 2015 11:51:13 +0000 (12:51 +0100)
committerMarcos Henrich <marcos.henrich@xamarin.com>
Fri, 28 Aug 2015 14:29:39 +0000 (15:29 +0100)
StackTrace.ToString format was different from Exception.ToString.
StackTrace.ToString had an identation of 3 spaces instead of 2, outputed
"line " before the line number which Exception.ToString does not, and it
did not print offsets.

This change allows StackTrace.ToString output to be used by the mono-symbolicate tool.

mcs/class/corlib/System.Diagnostics/StackTrace.cs

index e66221766c995169c191024e16b020be1e95378f..4b90b6fe8aeb9d55ea39d9c5475df0e47e4600d7 100644 (file)
@@ -170,21 +170,14 @@ namespace System.Diagnostics {
                        return frames;
                }
 
-               bool AddFrames (StringBuilder sb, bool isException = false)
+               bool AddFrames (StringBuilder sb)
                {
                        bool printOffset;
                        string debugInfo, indentation;
                        string unknown = Locale.GetText ("<unknown method>");
 
-                       if (isException) {
-                               printOffset = true;
-                               indentation = "  ";
-                               debugInfo = Locale.GetText (" in {0}:{1} ");
-                       } else {
-                               printOffset = false;
-                               indentation = "   ";
-                               debugInfo = Locale.GetText (" in {0}:line {1}");
-                       }
+                       indentation = "  ";
+                       debugInfo = Locale.GetText (" in {0}:{1} ");
 
                        var newline = String.Format ("{0}{1}{2} ", Environment.NewLine, indentation,
                                        Locale.GetText ("at"));
@@ -201,21 +194,17 @@ namespace System.Diagnostics {
                                        string internal_name = frame.GetInternalMethodName ();
                                        if (internal_name != null)
                                                sb.Append (internal_name);
-                                       else if (printOffset)
-                                               sb.AppendFormat ("<0x{0:x5} + 0x{1:x5}> {2}", frame.GetMethodAddress (), frame.GetNativeOffset (), unknown);
                                        else
-                                               sb.AppendFormat (unknown);
+                                               sb.AppendFormat ("<0x{0:x5} + 0x{1:x5}> {2}", frame.GetMethodAddress (), frame.GetNativeOffset (), unknown);
                                } else {
                                        GetFullNameForStackTrace (sb, frame.GetMethod ());
 
-                                       if (printOffset) {
-                                               if (frame.GetILOffset () == -1) {
-                                                       sb.AppendFormat (" <0x{0:x5} + 0x{1:x5}>", frame.GetMethodAddress (), frame.GetNativeOffset ());
-                                                       if (frame.GetMethodIndex () != 0xffffff)
-                                                               sb.AppendFormat (" {0}", frame.GetMethodIndex ());
-                                               } else {
-                                                       sb.AppendFormat (" [0x{0:x5}]", frame.GetILOffset ());
-                                               }
+                                       if (frame.GetILOffset () == -1) {
+                                               sb.AppendFormat (" <0x{0:x5} + 0x{1:x5}>", frame.GetMethodAddress (), frame.GetNativeOffset ());
+                                               if (frame.GetMethodIndex () != 0xffffff)
+                                                       sb.AppendFormat (" {0}", frame.GetMethodIndex ());
+                                       } else {
+                                               sb.AppendFormat (" [0x{0:x5}]", frame.GetILOffset ());
                                        }
 
                                        sb.AppendFormat (debugInfo, frame.GetSecureFileName (),
@@ -293,7 +282,7 @@ namespace System.Diagnostics {
                        //
                        if (captured_traces != null) {
                                foreach (var t in captured_traces) {
-                                       if (!t.AddFrames (sb, true))
+                                       if (!t.AddFrames (sb))
                                                continue;
 
                                        sb.Append (Environment.NewLine);