From: Austin Clements Date: Mon, 12 Jun 2017 18:24:16 +0000 (-0400) Subject: runtime: simplify stack walk in panicwrap X-Git-Tag: go1.10beta1~1010 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=354fa9a84f7b88fe6b9ebf578e6671c2b511a402;p=gostls13.git runtime: simplify stack walk in panicwrap 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/runtime/error.go b/src/runtime/error.go index eafcc9b173..16f3e53a47 100644 --- a/src/runtime/error.go +++ b/src/runtime/error.go @@ -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:]