github.com/nikandfor/loc@v0.5.1/name_file_line_safe.go (about)

     1  //go:build !nikandfor_loc_unsafe
     2  // +build !nikandfor_loc_unsafe
     3  
     4  package loc
     5  
     6  import (
     7  	"runtime"
     8  )
     9  
    10  func (l PC) nameFileLine() (name, file string, line int) {
    11  	fs := callersFrames(PCs{l})
    12  	f, _ := fs.Next()
    13  	return f.Function, f.File, f.Line
    14  }
    15  
    16  func (l PC) FuncEntry() PC {
    17  	if l == 0 {
    18  		return 0
    19  	}
    20  
    21  	f := runtime.FuncForPC(uintptr(l))
    22  	if f == nil {
    23  		return 0
    24  	}
    25  
    26  	return PC(f.Entry())
    27  }