]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: print signal information during panic
authorRuss Cox <rsc@golang.org>
Tue, 18 Jan 2011 19:15:11 +0000 (14:15 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 18 Jan 2011 19:15:11 +0000 (14:15 -0500)
$ 6.out
panic: runtime error: invalid memory address or nil pointer dereference

[signal 11 code=0x1 addr=0x0 pc=0x1c16]

runtime.panic+0xa7 /Users/rsc/g/go/src/pkg/runtime/proc.c:1089
runtime.panic(0xf6c8, 0x25c010)
runtime.panicstring+0x69 /Users/rsc/g/go/src/pkg/runtime/runtime.c:88
runtime.panicstring(0x24814, 0x0)
runtime.sigpanic+0x144 /Users/rsc/g/go/src/pkg/runtime/darwin/thread.c:465
runtime.sigpanic()
main.f+0x16 /Users/rsc/x.go:5
main.f()
main.main+0x1c /Users/rsc/x.go:9
main.main()
runtime.mainstart+0xf /Users/rsc/g/go/src/pkg/runtime/amd64/asm.s:77
runtime.mainstart()
runtime.goexit /Users/rsc/g/go/src/pkg/runtime/proc.c:149
runtime.goexit()

R=r
CC=golang-dev
https://golang.org/cl/4036042

src/pkg/runtime/darwin/386/signal.c
src/pkg/runtime/darwin/amd64/signal.c
src/pkg/runtime/freebsd/386/signal.c
src/pkg/runtime/freebsd/amd64/signal.c
src/pkg/runtime/linux/386/signal.c
src/pkg/runtime/linux/amd64/signal.c
src/pkg/runtime/linux/arm/signal.c
src/pkg/runtime/proc.c
src/pkg/runtime/runtime.c
src/pkg/runtime/runtime.h
test/golden.out

index 53a4e2f17757396e0e3ca86fddf7fd7b0fa94c81..33f47d44f93bd6e7ea7fc327ece521929f33e05f 100644 (file)
@@ -66,6 +66,7 @@ runtime·sighandler(int32 sig, Siginfo *info, void *context)
                gp->sig = sig;
                gp->sigcode0 = info->si_code;
                gp->sigcode1 = (uintptr)info->si_addr;
+               gp->sigpc = r->eip;
 
                // Only push runtime·sigpanic if r->eip != 0.
                // If r->eip == 0, probably panicked because of a
index 474a1bd5c31ce69c8291affe1f52bf16d7a7ccd0..948b6c9c20a913cdc853c2e2f901b935344edb20 100644 (file)
@@ -76,6 +76,7 @@ runtime·sighandler(int32 sig, Siginfo *info, void *context)
                gp->sig = sig;
                gp->sigcode0 = info->si_code;
                gp->sigcode1 = (uintptr)info->si_addr;
+               gp->sigpc = r->rip;
                
                // Only push runtime·sigpanic if r->rip != 0.
                // If r->rip == 0, probably panicked because of a
index 52b820df13257a95674cac49dcd2501bb117e2ea..ddb11fc3bac2459020c7fd39e61ed8d41984f510 100644 (file)
@@ -63,6 +63,7 @@ runtime·sighandler(int32 sig, Siginfo* info, void* context)
                gp->sig = sig;
                gp->sigcode0 = info->si_code;
                gp->sigcode1 = (uintptr)info->si_addr;
+               gp->sigpc = r->mc_eip;
 
                // Only push runtime·sigpanic if r->mc_eip != 0.
                // If r->mc_eip == 0, probably panicked because of a
index c74ddad0b82b866b6e5cec45287b98fdbd8efd95..9f873d276b1fd3d09b2482277337765f0a96f71d 100644 (file)
@@ -71,6 +71,7 @@ runtime·sighandler(int32 sig, Siginfo* info, void* context)
                gp->sig = sig;
                gp->sigcode0 = info->si_code;
                gp->sigcode1 = (uintptr)info->si_addr;
+               gp->sigpc = r->mc_rip;
 
                // Only push runtime·sigpanic if r->mc_rip != 0.
                // If r->mc_rip == 0, probably panicked because of a
index 0dbfcf9ff3648ffa3d35917fd976a0362eeb9a1a..9651a6f28012716bfcc1e74faeda2335edf519e3 100644 (file)
@@ -60,6 +60,7 @@ runtime·sighandler(int32 sig, Siginfo* info, void* context)
                gp->sig = sig;
                gp->sigcode0 = info->si_code;
                gp->sigcode1 = ((uintptr*)info)[3];
+               gp->sigpc = r->eip;
 
                // Only push runtime·sigpanic if r->eip != 0.
                // If r->eip == 0, probably panicked because of a
index e78bbda9d4a43dfc8598b06a9a41c3f3d9c19e3d..9e501c96d855c4fca040ef060d6cd31b86d36719 100644 (file)
@@ -70,6 +70,7 @@ runtime·sighandler(int32 sig, Siginfo* info, void* context)
                gp->sig = sig;
                gp->sigcode0 = info->si_code;
                gp->sigcode1 = ((uintptr*)info)[2];
+               gp->sigpc = r->rip;
 
                // Only push runtime·sigpanic if r->rip != 0.
                // If r->rip == 0, probably panicked because of a
index c65aff913b6a0008c094d1eb796bfd80bdc585d8..481bd13c620192483af65c7cbb9544f1576f0a71 100644 (file)
@@ -67,6 +67,7 @@ runtime·sighandler(int32 sig, Siginfo *info, void *context)
                gp->sig = sig;
                gp->sigcode0 = info->si_code;
                gp->sigcode1 = r->fault_address;
+               gp->sigpc = r->arm_pc;
 
                // If this is a leaf function, we do smash LR,
                // but we're not going back there anyway.
index 35ab098944668a88466ba5895e0020971226fd26..09c7a1dbc9da85d7675405f12307484d2e52828d 100644 (file)
@@ -1070,6 +1070,8 @@ runtime·panic(Eface e)
                reflect·call(d->fn, d->args, d->siz);
                if(p->recovered) {
                        g->panic = p->link;
+                       if(g->panic == nil)     // must be done with signal
+                               g->sig = 0;
                        runtime·free(p);
                        // put recovering defer back on list
                        // for scheduler to find.
index 9d3efe966d45a38bf4ca9f466dd9836d0292c115..513675240f5127a4972d098f8172b9051bd7e24f 100644 (file)
@@ -30,11 +30,16 @@ runtime·dopanic(int32 unused)
        }
        runtime·panicking++;
 
-       runtime·printf("\npanic PC=%X\n", (uint64)(uintptr)&unused);
+       if(g->sig != 0)
+               runtime·printf("\n[signal %d code=%p addr=%p pc=%p]\n",
+                       g->sig, g->sigcode0, g->sigcode1, g->sigpc);
+
+       runtime·printf("\n");
        if(runtime·gotraceback()){
                runtime·traceback(runtime·getcallerpc(&unused), runtime·getcallersp(&unused), 0, g);
                runtime·tracebackothers(g);
        }
+       
        runtime·breakpoint();  // so we can grab it in a debugger
        runtime·exit(2);
 }
index c00c40aed96bbb4c6dac145e03d3e39aa2566293..7ba7932b2b843570ef9b2a0b2a2b9f26c6d384e1 100644 (file)
@@ -199,6 +199,7 @@ struct      G
        int32   sig;
        uintptr sigcode0;
        uintptr sigcode1;
+       uintptr sigpc;
 };
 struct M
 {
index e587912a48df61fe167c1ed2d9ffd425916921b7..04c71327b1796f032f681acc4ff168167ab1c6a2 100644 (file)
@@ -4,22 +4,18 @@
 =========== ./cmp2.go
 panic: runtime error: comparing uncomparable type []int
 
-panic PC=xxx
 
 =========== ./cmp3.go
 panic: runtime error: comparing uncomparable type []int
 
-panic PC=xxx
 
 =========== ./cmp4.go
 panic: runtime error: hash of unhashable type []int
 
-panic PC=xxx
 
 =========== ./cmp5.go
 panic: runtime error: hash of unhashable type []int
 
-panic PC=xxx
 
 =========== ./deferprint.go
 printing: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
@@ -117,12 +113,10 @@ PASS
 =========== interface/fail.go
 panic: interface conversion: *main.S is not main.I: missing method Foo
 
-panic PC=xxx
 
 =========== interface/returntype.go
 panic: interface conversion: *main.S is not main.I2: missing method Name
 
-panic PC=xxx
 
 == nilptr/
 
@@ -164,12 +158,10 @@ M
 =========== fixedbugs/bug113.go
 panic: interface conversion: interface is int, not int32
 
-panic PC=xxx
 
 =========== fixedbugs/bug148.go
 2 3
 panic: interface conversion: interface is main.T, not main.T
 
-panic PC=xxx
 
 == bugs/