mirror of
https://github.com/golang/go
synced 2024-11-19 15:24:46 -07:00
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>
This commit is contained in:
parent
229aaac19e
commit
354fa9a84f
@ -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:]
|
||||
|
Loading…
Reference in New Issue
Block a user