github.com/phuslu/log@v1.0.100/runtime_go1.23.go (about) 1 //go:build go1.23 2 // +build go1.23 3 4 // MIT license, copy and modify from https://github.com/tlog-dev/loc 5 6 //nolint:unused 7 package log 8 9 import ( 10 "unsafe" 11 ) 12 13 // inlinedCall is the encoding of entries in the FUNCDATA_InlTree table. 14 type inlinedCall struct { 15 funcID uint8 // type of the called function 16 _ [3]byte 17 nameOff int32 // offset into pclntab for name of called function 18 parentPc int32 // position of an instruction whose source position is the call site (offset from entry) 19 startLine int32 // line number of start of function (func keyword/TEXT directive) 20 } 21 22 type inlineUnwinder struct { 23 f funcInfo 24 inlTree *[1 << 20]inlinedCall 25 } 26 27 type inlineFrame struct { 28 pc uintptr 29 index int32 30 } 31 32 type srcFunc struct { 33 datap unsafe.Pointer 34 nameOff int32 35 startLine int32 36 funcID uint8 37 } 38 39 func pcFileLineName(pc uintptr) (file string, line int32, name string) { 40 funcInfo := findfunc(pc) 41 if funcInfo._func == nil { 42 return 43 } 44 45 entry := funcInfoEntry(funcInfo) 46 47 if pc > entry { 48 // We store the pc of the start of the instruction following 49 // the instruction in question (the call or the inline mark). 50 // This is done for historical reasons, and to make FuncForPC 51 // work correctly for entries in the result of runtime.Callers. 52 pc-- 53 } 54 55 file, line = funcline1(funcInfo, pc, false) 56 57 // It's important that interpret pc non-strictly as cgoTraceback may 58 // have added bogus PCs with a valid funcInfo but invalid PCDATA. 59 u, uf := newInlineUnwinder(funcInfo, pc) 60 sf := inlineUnwinder_srcFunc(&u, uf) 61 name = srcFunc_name(sf) 62 63 return 64 } 65 66 //go:linkname newInlineUnwinder runtime.newInlineUnwinder 67 func newInlineUnwinder(f funcInfo, pc uintptr) (inlineUnwinder, inlineFrame) 68 69 //go:linkname inlineUnwinder_srcFunc runtime.(*inlineUnwinder).srcFunc 70 func inlineUnwinder_srcFunc(*inlineUnwinder, inlineFrame) srcFunc 71 72 //go:linkname srcFunc_name runtime.srcFunc.name 73 func srcFunc_name(srcFunc) string 74 75 // Fastrandn returns a pseudorandom uint32 in [0,n). 76 // 77 //go:noescape 78 //go:linkname Fastrandn runtime.cheaprandn 79 func Fastrandn(x uint32) uint32