diff mbox

libgo patch committed: Do not report thunks/recover in backtrace

Message ID mcrr4bvcn4e.fsf@iant-glaptop.roam.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor Oct. 9, 2013, 12:18 a.m. UTC
This patch to libgo avoids returning thunk or recover functions in a
backtrace or when calling runtime.Caller or friends.  This is to give a
stack backtrace more like that generated by the gc compiler.  In
particular, it is so that runtime.Caller(n) will return stack trace that
more closely corresponds to that returned by the gc toolchain.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and 4.8 branch.

Ian
diff mbox

Patch

diff -r 17075de125b7 libgo/runtime/go-callers.c
--- a/libgo/runtime/go-callers.c	Tue Oct 08 16:51:52 2013 -0700
+++ b/libgo/runtime/go-callers.c	Tue Oct 08 16:54:42 2013 -0700
@@ -53,6 +53,21 @@ 
 	return 0;
     }
 
+  /* Skip thunks and recover functions.  There is no equivalent to
+     these functions in the gc toolchain, so returning them here means
+     significantly different results for runtime.Caller(N).  */
+  if (function != NULL)
+    {
+      const char *p;
+
+      p = __builtin_strchr (function, '.');
+      if (p != NULL && __builtin_strncmp (p + 1, "$thunk", 6) == 0)
+	return 0;
+      p = __builtin_strrchr (function, '$');
+      if (p != NULL && __builtin_strcmp(p, "$recover") == 0)
+	return 0;
+    }
+
   if (arg->skip > 0)
     {
       --arg->skip;