From fa4984d535b23c0d2b14650a8842d63083893af3 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 11 Sep 2013 11:59:19 -0400 Subject: [PATCH] runtime: show runtime.panic frame in traceback 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 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pkg/runtime/symtab.c b/src/pkg/runtime/symtab.c index 053e255079..bdf96a1b6e 100644 --- a/src/pkg/runtime/symtab.c +++ b/src/pkg/runtime/symtab.c @@ -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."); } -- 2.48.1