Skip to content

Commit fa4984d

Browse files
committed
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
1 parent 382738a commit fa4984d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/pkg/runtime/symtab.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,17 @@ runtime·showframe(Func *f, G *gp)
317317
static int32 traceback = -1;
318318
String name;
319319

320-
if(m->throwing && gp != nil && (gp == m->curg || gp == m->caughtsig))
320+
if(m->throwing > 0 && gp != nil && (gp == m->curg || gp == m->caughtsig))
321321
return 1;
322322
if(traceback < 0)
323323
traceback = runtime·gotraceback(nil);
324324
name = runtime·gostringnocopy((uint8*)runtime·funcname(f));
325+
326+
// Special case: always show runtime.panic frame, so that we can
327+
// see where a panic started in the middle of a stack trace.
328+
// See golang.org/issue/5832.
329+
if(name.len == 7+1+5 && hasprefix(name, "runtime.panic"))
330+
return 1;
331+
325332
return traceback > 1 || f != nil && contains(name, ".") && !hasprefix(name, "runtime.");
326333
}

0 commit comments

Comments
 (0)