From 3e360b035f4c3014e9564f4994c68ccc296ef629 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 14 Feb 2023 12:25:11 -0500 Subject: runtime: new API for filling PC traceback buffers Currently, filling PC traceback buffers is one of the jobs of gentraceback. This moves it into a new function, tracebackPCs, with a simple API built around unwinder, and changes all callers to use this new API. Updates #54466. Change-Id: Id2038bded81bf533a5a4e71178a7c014904d938c Reviewed-on: https://go-review.googlesource.com/c/go/+/468300 Reviewed-by: Michael Pratt TryBot-Result: Gopher Robot Run-TryBot: Austin Clements --- src/runtime/proc.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/runtime/proc.go') diff --git a/src/runtime/proc.go b/src/runtime/proc.go index ee13debf54..533cf20838 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -4687,6 +4687,7 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) { // See golang.org/issue/17165. getg().m.mallocing++ + var u unwinder var stk [maxCPUProfStack]uintptr n := 0 if mp.ncgo > 0 && mp.curg != nil && mp.curg.syscallpc != 0 && mp.curg.syscallsp != 0 { @@ -4700,26 +4701,24 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) { for cgoOff < len(mp.cgoCallers) && mp.cgoCallers[cgoOff] != 0 { cgoOff++ } - copy(stk[:], mp.cgoCallers[:cgoOff]) + n += copy(stk[:], mp.cgoCallers[:cgoOff]) mp.cgoCallers[0] = 0 } // Collect Go stack that leads to the cgo call. - n = gentraceback(mp.curg.syscallpc, mp.curg.syscallsp, 0, mp.curg, 0, &stk[cgoOff], len(stk)-cgoOff, nil, nil, 0) - if n > 0 { - n += cgoOff - } + u.initAt(mp.curg.syscallpc, mp.curg.syscallsp, 0, mp.curg, unwindSilentErrors) } else if usesLibcall() && mp.libcallg != 0 && mp.libcallpc != 0 && mp.libcallsp != 0 { // Libcall, i.e. runtime syscall on windows. // Collect Go stack that leads to the call. - n = gentraceback(mp.libcallpc, mp.libcallsp, 0, mp.libcallg.ptr(), 0, &stk[n], len(stk[n:]), nil, nil, 0) + u.initAt(mp.libcallpc, mp.libcallsp, 0, mp.libcallg.ptr(), unwindSilentErrors) } else if mp != nil && mp.vdsoSP != 0 { // VDSO call, e.g. nanotime1 on Linux. // Collect Go stack that leads to the call. - n = gentraceback(mp.vdsoPC, mp.vdsoSP, 0, gp, 0, &stk[n], len(stk[n:]), nil, nil, _TraceJumpStack) + u.initAt(mp.vdsoPC, mp.vdsoSP, 0, gp, unwindSilentErrors|unwindJumpStack) } else { - n = gentraceback(pc, sp, lr, gp, 0, &stk[0], len(stk), nil, nil, _TraceTrap|_TraceJumpStack) + u.initAt(pc, sp, lr, gp, unwindSilentErrors|unwindTrap|unwindJumpStack) } + n += tracebackPCs(&u, 0, stk[n:]) if n <= 0 { // Normal traceback is impossible or has failed. -- cgit v1.3-5-g9baa