]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: show runtime.panic frame in traceback
authorRuss Cox <rsc@golang.org>
Wed, 11 Sep 2013 15:59:19 +0000 (11:59 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 11 Sep 2013 15:59:19 +0000 (11:59 -0400)
Otherwise, if panic starts running deferred functions,
the code that panicked appears to be calling those
functions directly, which is not the case and can be
confusing.

For example:

main.Two()
        /Users/rsc/x.go:12 +0x2a
runtime.panic(0x20dc0, 0x2100cc010)
        /Users/rsc/g/go/src/pkg/runtime/panic.c:248 +0x106
main.One()
        /Users/rsc/x.go:8 +0x55

This makes clear(er) that main.Two is being called during
a panic, not as a direct call from main.One.

Fixes #5832.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13302051

src/pkg/runtime/symtab.c

index 053e255079ae6732bd540b41e860f1e20a78b137..bdf96a1b6ea42636267a7f514ebcb51b8e651089 100644 (file)
@@ -317,10 +317,17 @@ runtime·showframe(Func *f, G *gp)
        static int32 traceback = -1;
        String name;
 
-       if(m->throwing && gp != nil && (gp == m->curg || gp == m->caughtsig))
+       if(m->throwing > 0 && gp != nil && (gp == m->curg || gp == m->caughtsig))
                return 1;
        if(traceback < 0)
                traceback = runtime·gotraceback(nil);
        name = runtime·gostringnocopy((uint8*)runtime·funcname(f));
+
+       // Special case: always show runtime.panic frame, so that we can
+       // see where a panic started in the middle of a stack trace.
+       // See golang.org/issue/5832.
+       if(name.len == 7+1+5 && hasprefix(name, "runtime.panic"))
+               return 1;
+
        return traceback > 1 || f != nil && contains(name, ".") && !hasprefix(name, "runtime.");
 }