]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: simplify stack walk in panicwrap
authorAustin Clements <austin@google.com>
Mon, 12 Jun 2017 18:24:16 +0000 (14:24 -0400)
committerAustin Clements <austin@google.com>
Fri, 22 Sep 2017 22:17:17 +0000 (22:17 +0000)
panicwrap currently uses runtime.Callers and runtime.CallersFrames to
find the name of its caller. Simplify this by using getcallerpc.

This will be important for #16723, since to fix that we're going to
make CallersFrames skip the wrapper method, which is exactly what
panicwrap needs to see.

Change-Id: Icb0776d399966e31595f3ee44f980290827e32a6
Reviewed-on: https://go-review.googlesource.com/45411
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/error.go

index eafcc9b173029e0a10a8409c876a731aa9009812..16f3e53a47f9c35f1989892e8787dcd0badb339f 100644 (file)
@@ -126,34 +126,31 @@ func printany(i interface{}) {
 //go:linkname stringsIndexByte strings.IndexByte
 func stringsIndexByte(s string, c byte) int
 
-// called from generated code
+// panicwrap generates a panic for a call to a wrapped value method
+// with a nil pointer receiver.
+//
+// It is called from the generated wrapper code.
 func panicwrap() {
-       pc := make([]uintptr, 1)
-       n := Callers(2, pc)
-       if n == 0 {
-               throw("panicwrap: Callers failed")
-       }
-       frames := CallersFrames(pc)
-       frame, _ := frames.Next()
-       name := frame.Function
+       pc := getcallerpc()
+       name := funcname(findfunc(pc))
        // name is something like "main.(*T).F".
        // We want to extract pkg ("main"), typ ("T"), and meth ("F").
        // Do it by finding the parens.
        i := stringsIndexByte(name, '(')
        if i < 0 {
-               throw("panicwrap: no ( in " + frame.Function)
+               throw("panicwrap: no ( in " + name)
        }
        pkg := name[:i-1]
        if i+2 >= len(name) || name[i-1:i+2] != ".(*" {
-               throw("panicwrap: unexpected string after package name: " + frame.Function)
+               throw("panicwrap: unexpected string after package name: " + name)
        }
        name = name[i+2:]
        i = stringsIndexByte(name, ')')
        if i < 0 {
-               throw("panicwrap: no ) in " + frame.Function)
+               throw("panicwrap: no ) in " + name)
        }
        if i+2 >= len(name) || name[i:i+2] != ")." {
-               throw("panicwrap: unexpected string after type name: " + frame.Function)
+               throw("panicwrap: unexpected string after type name: " + name)
        }
        typ := name[:i]
        meth := name[i+2:]