tlog.app/go/loc@v0.6.2-0.20231112073106-b6382a0ac518/name_file_line_go1.18.go (about) 1 //go:build nikandfor_loc_unsafe && go1.18 && !go1.20 2 // +build nikandfor_loc_unsafe,go1.18,!go1.20 3 4 package loc 5 6 import "unsafe" 7 8 func (l PC) nameFileLine() (name, file string, line int) { 9 funcInfo := findfunc(l) 10 if funcInfo.entry == nil { 11 return 12 } 13 14 entry := funcInfoEntry(funcInfo) 15 16 if l > entry { 17 // We store the pc of the start of the instruction following 18 // the instruction in question (the call or the inline mark). 19 // This is done for historical reasons, and to make FuncForPC 20 // work correctly for entries in the result of runtime.Callers. 21 l-- 22 } 23 24 name = funcname(funcInfo) 25 file, line32 := funcline1(funcInfo, l, false) 26 line = int(line32) 27 if inldata := funcdata(funcInfo, _FUNCDATA_InlTree); inldata != nil { 28 ix := pcdatavalue1(funcInfo, _PCDATA_InlTreeIndex, l, nil, false) 29 if ix >= 0 { 30 inltree := (*[1 << 20]inlinedCall)(inldata) 31 // Note: entry is not modified. It always refers to a real frame, not an inlined one. 32 name = funcnameFromNameoff(funcInfo, inltree[ix].func_) 33 // File/line is already correct. 34 // TODO: remove file/line from InlinedCall? 35 } 36 } 37 38 return 39 } 40 41 //go:linkname findfunc runtime.findfunc 42 func findfunc(pc PC) funcInfo 43 44 //go:linkname funcline1 runtime.funcline1 45 func funcline1(f funcInfo, targetpc PC, strict bool) (file string, line int32) 46 47 //go:linkname funcname runtime.funcname 48 func funcname(f funcInfo) string 49 50 //go:linkname funcdata runtime.funcdata 51 func funcdata(f funcInfo, i uint8) unsafe.Pointer 52 53 //go:linkname pcdatavalue runtime.pcdatavalue 54 func pcdatavalue(f funcInfo, table int32, targetpc PC, cache unsafe.Pointer) int32 55 56 //go:linkname pcdatavalue1 runtime.pcdatavalue1 57 func pcdatavalue1(f funcInfo, table int32, targetpc PC, cache unsafe.Pointer, strict bool) int32 58 59 //go:linkname funcnameFromNameoff runtime.funcnameFromNameoff 60 func funcnameFromNameoff(f funcInfo, nameoff int32) string 61 62 //go:linkname funcInfoEntry runtime.funcInfo.entry 63 func funcInfoEntry(f funcInfo) PC