github.com/oarkflow/log@v1.0.78/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 *uintptr 34 nameOff int32 35 startLine int32 36 funcID uint8 37 } 38 39 func pcNameFileLine(pc uintptr) (name, file string, line int32) { 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 // name = funcNameForPrint(srcFunc_name(sf)) 63 64 return 65 } 66 67 //go:linkname newInlineUnwinder runtime.newInlineUnwinder 68 func newInlineUnwinder(f funcInfo, pc uintptr) (inlineUnwinder, inlineFrame) 69 70 //go:linkname inlineUnwinder_srcFunc runtime.(*inlineUnwinder).srcFunc 71 func inlineUnwinder_srcFunc(*inlineUnwinder, inlineFrame) srcFunc 72 73 //go:linkname inlineUnwinder_isInlined runtime.(*inlineUnwinder).isInlined 74 func inlineUnwinder_isInlined(*inlineUnwinder, inlineFrame) bool 75 76 //go:linkname srcFunc_name runtime.srcFunc.name 77 func srcFunc_name(srcFunc) string 78 79 //go:linkname funcNameForPrint runtime.funcNameForPrint 80 func funcNameForPrint(name string) string 81 82 // Fastrandn returns a pseudorandom uint32 in [0,n). 83 // 84 //go:noescape 85 //go:linkname Fastrandn runtime.cheaprandn 86 func Fastrandn(x uint32) uint32