diff options
| author | Austin Clements <austin@google.com> | 2017-06-12 14:24:16 -0400 |
|---|---|---|
| committer | Austin Clements <austin@google.com> | 2017-09-22 22:17:17 +0000 |
| commit | 354fa9a84f7b88fe6b9ebf578e6671c2b511a402 (patch) | |
| tree | ac4e4bb9c364b7880ec6050531c173d700bb12a2 /src/runtime | |
| parent | 229aaac19e041ac74ab043d6ef09c8406bb0a9e7 (diff) | |
| download | go-354fa9a84f7b88fe6b9ebf578e6671c2b511a402.tar.xz | |
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 <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/error.go | 23 |
1 files changed, 10 insertions, 13 deletions
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:] |
