From 29412f8bb622c37fbb0bbb5f889599060407c236 Mon Sep 17 00:00:00 2001 From: phuslu Date: Sun, 18 Aug 2024 23:18:49 +0800 Subject: [PATCH] fix fastcaller inline bug --- fastcaller_go1.23.go | 23 +++++++++++++++++++++++ logger.go | 10 ---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/fastcaller_go1.23.go b/fastcaller_go1.23.go index 5e3f98cd..338de0b1 100644 --- a/fastcaller_go1.23.go +++ b/fastcaller_go1.23.go @@ -23,6 +23,16 @@ func pcFileLine(pc uintptr) (file string, line int) { return } + entry := funcInfoEntry(f) + + if pc > entry { + // We store the pc of the start of the instruction following + // the instruction in question (the call or the inline mark). + // This is done for historical reasons, and to make FuncForPC + // work correctly for entries in the result of runtime.Callers. + pc-- + } + return (*runtime.Func)(unsafe.Pointer(f._func)).FileLine(pc) } @@ -32,6 +42,16 @@ func pcFileLineName(pc uintptr) (file string, line int, name string) { return } + entry := funcInfoEntry(f) + + if pc > entry { + // We store the pc of the start of the instruction following + // the instruction in question (the call or the inline mark). + // This is done for historical reasons, and to make FuncForPC + // work correctly for entries in the result of runtime.Callers. + pc-- + } + file, line = (*runtime.Func)(unsafe.Pointer(f._func)).FileLine(pc) str := &f.datap.funcnametab[f.nameOff] ss := stringStruct{str: unsafe.Pointer(str), len: findnull(str)} @@ -121,3 +141,6 @@ type moduledata struct { //go:linkname findfunc runtime.findfunc func findfunc(pc uintptr) funcInfo + +//go:linkname funcInfoEntry runtime.funcInfo.entry +func funcInfoEntry(f funcInfo) uintptr diff --git a/logger.go b/logger.go index 0995ae9f..96a5050a 100644 --- a/logger.go +++ b/logger.go @@ -782,8 +782,6 @@ func (e *Entry) TimesFormat(key string, timefmt string, a []time.Time) *Entry { } // Bool append append the val as a bool to the entry. -// -//go:noinline func (e *Entry) Bool(key string, b bool) *Entry { if e == nil { return nil @@ -797,8 +795,6 @@ func (e *Entry) Bool(key string, b bool) *Entry { } // Bools adds the field key with val as a []bool to the entry. -// -//go:noinline func (e *Entry) Bools(key string, b []bool) *Entry { if e == nil { return nil @@ -925,8 +921,6 @@ func (e *Entry) Durs(key string, d []time.Duration) *Entry { } // Err adds the field "error" with serialized err to the entry. -// -//go:noinline func (e *Entry) Err(err error) *Entry { return e.AnErr("error", err) } @@ -2285,8 +2279,6 @@ func (e *Entry) KeysAndValues(keysAndValues ...any) *Entry { type Fields map[string]any // Fields is a helper function to use a map to set fields using type assertion. -// -//go:noinline func (e *Entry) Fields(fields Fields) *Entry { if e == nil { return nil @@ -2317,8 +2309,6 @@ func (e *Entry) Value() Context { } // Context sends the contextual fields to entry. -// -//go:noinline func (e *Entry) Context(ctx Context) *Entry { if e == nil { return nil