]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: print signal name in panic, if name is known
authorEmmanuel Odeke <emm.odeke@gmail.com>
Wed, 4 May 2016 07:42:13 +0000 (01:42 -0600)
committerIan Lance Taylor <iant@golang.org>
Thu, 5 May 2016 19:58:00 +0000 (19:58 +0000)
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>

src/runtime/os1_nacl.go
src/runtime/os1_plan9.go
src/runtime/panic.go
src/runtime/signal_unix.go
src/runtime/signal_windows.go

index 622755119d0336b2edb1536dc97f2a4874baa13b..feea49665294967050e32658645d532d0cf1c47d 100644 (file)
@@ -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
 }
index eb7a0c6481f996c83014b0db37bba7d55f08b606..6c7e36d0620a0f44f6c25d1c4c714879c388d8ee 100644 (file)
@@ -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
+}
index 382a20e4e706ff3dbd094071ff7b9756a87ae915..60b277d52cd8198ffc431fe7c7325bcd550686a8 100644 (file)
@@ -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()
index 5ce2380daa24f5dc598a5de882133995efd5e9cf..f59c9b954975b4b0a7d5a6f769c9babf2d138feb 100644 (file)
@@ -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
+}
index d54dbf76163f45926b986d1be750ca6ddb3810f6..298dcc96a0710fc9903f9eaa5c06cdd2faaad8e4 100644 (file)
@@ -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