mirror of
https://github.com/golang/go
synced 2024-11-02 11:50:30 +00:00
runtime: look up funcInfo by func pointer
runtime.Func.{Name,FileLine} need to be able to go from a *_func to a funcInfo. The missing bit of information is what module contains that *_func. The existing implementation looked up the module using the *_func's entry PC. A subsequent change will store *_func's entry PC relative to the containing module. Change the module lookup to instead for the module whose pclntable contains the *_func, cutting all dependencies on the contents of the *_func. Change-Id: I2dbbfec043ebc2e9a6ef19bbdec623ac84353b10 Reviewed-on: https://go-review.googlesource.com/c/go/+/351458 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
parent
f961d8e5b1
commit
e54843f2f4
1 changed files with 16 additions and 1 deletions
|
@ -273,7 +273,22 @@ func (f *Func) raw() *_func {
|
|||
|
||||
func (f *Func) funcInfo() funcInfo {
|
||||
fn := f.raw()
|
||||
return funcInfo{fn, findmoduledatap(fn.entry)}
|
||||
// Find the module containing fn. fn is located in the pclntable.
|
||||
// The unsafe.Pointer to uintptr conversions and arithmetic
|
||||
// are safe because we are working with module addresses.
|
||||
ptr := uintptr(unsafe.Pointer(fn))
|
||||
var mod *moduledata
|
||||
for datap := &firstmoduledata; datap != nil; datap = datap.next {
|
||||
if len(datap.pclntable) == 0 {
|
||||
continue
|
||||
}
|
||||
base := uintptr(unsafe.Pointer(&datap.pclntable[0]))
|
||||
if base <= ptr && ptr < base+uintptr(len(datap.pclntable)) {
|
||||
mod = datap
|
||||
break
|
||||
}
|
||||
}
|
||||
return funcInfo{fn, mod}
|
||||
}
|
||||
|
||||
// PCDATA and FUNCDATA table indexes.
|
||||
|
|
Loading…
Reference in a new issue