From: Emmanuel Odeke Date: Wed, 4 May 2016 07:42:13 +0000 (-0600) Subject: runtime: print signal name in panic, if name is known X-Git-Tag: go1.7beta1~319 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1a7fc2357b1c26dcdf4fa57dee67a1172696801f;p=gostls13.git runtime: print signal name in panic, if name is known Adds a small function signame that infers a signal name from the signal table, otherwise will fallback to using hex(sig) as previously. No signal table is present for Windows hence it will always print the hex value. Sample code and new result: ```go package main import ( "fmt" "time" ) func main() { defer func() { if err := recover(); err != nil { fmt.Printf("err=%v\n", err) } }() ticker := time.Tick(1e9) for { <-ticker } } ``` ```shell $ go run main.go & $ kill -11 fatal error: unexpected signal during runtime execution [signal SIGSEGV: segmentation violation code=0x1 addr=0xb01dfacedebac1e pc=0xc71db] ... ``` Fixes #13969 Change-Id: Ie6be312eb766661f1cea9afec352b73270f27f9d Reviewed-on: https://go-review.googlesource.com/22753 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- diff --git a/src/runtime/os1_nacl.go b/src/runtime/os1_nacl.go index 622755119d..feea496652 100644 --- a/src/runtime/os1_nacl.go +++ b/src/runtime/os1_nacl.go @@ -56,6 +56,13 @@ func osinit() { //nacl_exception_handler(funcPC(sigtramp), nil); } +func signame(sig uint32) string { + if sig >= uint32(len(sigtable)) { + return "" + } + return sigtable[sig].name +} + func crash() { *(*int32)(nil) = 0 } diff --git a/src/runtime/os1_plan9.go b/src/runtime/os1_plan9.go index eb7a0c6481..6c7e36d062 100644 --- a/src/runtime/os1_plan9.go +++ b/src/runtime/os1_plan9.go @@ -286,3 +286,10 @@ func _atoi(b []byte) int { } return n } + +func signame(sig uint32) string { + if sig >= uint32(len(sigtable)) { + return "" + } + return sigtable[sig].name +} diff --git a/src/runtime/panic.go b/src/runtime/panic.go index 382a20e4e7..60b277d52c 100644 --- a/src/runtime/panic.go +++ b/src/runtime/panic.go @@ -641,7 +641,13 @@ var deadlock mutex func dopanic_m(gp *g, pc, sp uintptr) { if gp.sig != 0 { - print("[signal ", hex(gp.sig), " code=", hex(gp.sigcode0), " addr=", hex(gp.sigcode1), " pc=", hex(gp.sigpc), "]\n") + signame := signame(gp.sig) + if signame != "" { + print("[signal ", signame) + } else { + print("[signal ", hex(gp.sig)) + } + print(" code=", hex(gp.sigcode0), " addr=", hex(gp.sigcode1), " pc=", hex(gp.sigpc), "]\n") } level, all, docrash := gotraceback() diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go index 5ce2380daa..f59c9b9549 100644 --- a/src/runtime/signal_unix.go +++ b/src/runtime/signal_unix.go @@ -12,3 +12,10 @@ import _ "unsafe" // for go:linkname func os_sigpipe() { systemstack(sigpipe) } + +func signame(sig uint32) string { + if sig >= uint32(len(sigtable)) { + return "" + } + return sigtable[sig].name +} diff --git a/src/runtime/signal_windows.go b/src/runtime/signal_windows.go index d54dbf7616..298dcc96a0 100644 --- a/src/runtime/signal_windows.go +++ b/src/runtime/signal_windows.go @@ -209,6 +209,10 @@ func raisebadsignal(sig int32) { badsignal2() } +func signame(sig uint32) string { + return "" +} + func crash() { // TODO: This routine should do whatever is needed // to make the Windows program abort/crash as it