diff options
| author | Emmanuel Odeke <emm.odeke@gmail.com> | 2016-05-04 01:42:13 -0600 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2016-05-05 19:58:00 +0000 |
| commit | 1a7fc2357b1c26dcdf4fa57dee67a1172696801f (patch) | |
| tree | 00a0bc08765e9fa1b47792fe1aa50ab502a19ceb /src/runtime/panic.go | |
| parent | fafd792de30f46cbd822fd6bb041c60c7b5fbe6d (diff) | |
| download | go-1a7fc2357b1c26dcdf4fa57dee67a1172696801f.tar.xz | |
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 <pid>
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 <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/panic.go')
| -rw-r--r-- | src/runtime/panic.go | 8 |
1 files changed, 7 insertions, 1 deletions
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() |
