aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/amd64
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-08-22 23:26:39 -0400
committerRuss Cox <rsc@golang.org>2011-08-22 23:26:39 -0400
commit03e9ea5b74a4138fbaa7278c735cf7300484e1eb (patch)
tree6081b5af66d1dd36b0d48c80b80e9ffe1393f1ce /src/pkg/runtime/amd64
parent45407bd5599299b90e4d060d10993fb456d1d84a (diff)
downloadgo-03e9ea5b74a4138fbaa7278c735cf7300484e1eb.tar.xz
runtime: simplify stack traces
Make the stack traces more readable for new Go programmers while preserving their utility for old hands. - Change status number [4] to string. - Elide frames in runtime package (internal details). - Swap file:line and arguments. - Drop 'created by' for main goroutine. - Show goroutines in order of allocation: implies main goroutine first if nothing else. There is no option to get the extra frames back. Uncomment 'return 1' at the bottom of symtab.c. $ 6.out throw: all goroutines are asleep - deadlock! goroutine 1 [chan send]: main.main() /Users/rsc/g/go/src/pkg/runtime/x.go:22 +0x8a goroutine 2 [select (no cases)]: main.sel() /Users/rsc/g/go/src/pkg/runtime/x.go:11 +0x18 created by main.main /Users/rsc/g/go/src/pkg/runtime/x.go:19 +0x23 goroutine 3 [chan receive]: main.recv(0xf8400010a0, 0x0) /Users/rsc/g/go/src/pkg/runtime/x.go:15 +0x2e created by main.main /Users/rsc/g/go/src/pkg/runtime/x.go:20 +0x50 goroutine 4 [chan receive (nil chan)]: main.recv(0x0, 0x0) /Users/rsc/g/go/src/pkg/runtime/x.go:15 +0x2e created by main.main /Users/rsc/g/go/src/pkg/runtime/x.go:21 +0x66 $ $ 6.out index panic: runtime error: index out of range goroutine 1 [running]: main.main() /Users/rsc/g/go/src/pkg/runtime/x.go:25 +0xb9 $ $ 6.out nil panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x0 pc=0x22ca] goroutine 1 [running]: main.main() /Users/rsc/g/go/src/pkg/runtime/x.go:28 +0x211 $ $ 6.out panic panic: panic goroutine 1 [running]: main.main() /Users/rsc/g/go/src/pkg/runtime/x.go:30 +0x101 $ R=golang-dev, qyzhai, n13m3y3r, r CC=golang-dev https://golang.org/cl/4907048
Diffstat (limited to 'src/pkg/runtime/amd64')
-rw-r--r--src/pkg/runtime/amd64/traceback.c53
1 files changed, 29 insertions, 24 deletions
diff --git a/src/pkg/runtime/amd64/traceback.c b/src/pkg/runtime/amd64/traceback.c
index 3e85d36bd7..6b758c270d 100644
--- a/src/pkg/runtime/amd64/traceback.c
+++ b/src/pkg/runtime/amd64/traceback.c
@@ -123,27 +123,30 @@ runtime·gentraceback(byte *pc0, byte *sp, byte *lr0, G *g, int32 skip, uintptr
else if(pcbuf != nil)
pcbuf[n++] = pc;
else {
- // Print during crash.
- // main+0xf /home/rsc/go/src/runtime/x.go:23
- // main(0x1, 0x2, 0x3)
- runtime·printf("%S", f->name);
- if(pc > f->entry)
- runtime·printf("+%p", (uintptr)(pc - f->entry));
- tracepc = pc; // back up to CALL instruction for funcline.
- if(n > 0 && pc > f->entry && !waspanic)
- tracepc--;
- runtime·printf(" %S:%d\n", f->src, runtime·funcline(f, tracepc));
- runtime·printf("\t%S(", f->name);
- for(i = 0; i < f->args; i++) {
- if(i != 0)
- runtime·prints(", ");
- runtime·printhex(((uintptr*)fp)[i]);
- if(i >= 4) {
- runtime·prints(", ...");
- break;
+ if(showframe(f)) {
+ // Print during crash.
+ // main(0x1, 0x2, 0x3)
+ // /home/rsc/go/src/runtime/x.go:23 +0xf
+ //
+ tracepc = pc; // back up to CALL instruction for funcline.
+ if(n > 0 && pc > f->entry && !waspanic)
+ tracepc--;
+ runtime·printf("%S(", f->name);
+ for(i = 0; i < f->args; i++) {
+ if(i != 0)
+ runtime·prints(", ");
+ runtime·printhex(((uintptr*)fp)[i]);
+ if(i >= 4) {
+ runtime·prints(", ...");
+ break;
+ }
}
+ runtime·prints(")\n");
+ runtime·printf("\t%S:%d", f->src, runtime·funcline(f, tracepc));
+ if(pc > f->entry)
+ runtime·printf(" +%p", (uintptr)(pc - f->entry));
+ runtime·printf("\n");
}
- runtime·prints(")\n");
n++;
}
@@ -189,14 +192,16 @@ runtime·gentraceback(byte *pc0, byte *sp, byte *lr0, G *g, int32 skip, uintptr
fp = nil;
}
- if(pcbuf == nil && (pc = g->gopc) != 0 && (f = runtime·findfunc(pc)) != nil) {
- runtime·printf("----- goroutine created by -----\n%S", f->name);
- if(pc > f->entry)
- runtime·printf("+%p", (uintptr)(pc - f->entry));
+ // Show what created goroutine, except main goroutine (goid 1).
+ if(pcbuf == nil && (pc = g->gopc) != 0 && (f = runtime·findfunc(pc)) != nil && g->goid != 1) {
+ runtime·printf("created by %S\n", f->name);
tracepc = pc; // back up to CALL instruction for funcline.
if(n > 0 && pc > f->entry)
tracepc--;
- runtime·printf(" %S:%d\n", f->src, runtime·funcline(f, tracepc));
+ runtime·printf("\t%S:%d", f->src, runtime·funcline(f, tracepc));
+ if(pc > f->entry)
+ runtime·printf(" +%p", (uintptr)(pc - f->entry));
+ runtime·printf("\n");
}
return n;