diff options
| author | Austin Clements <austin@google.com> | 2023-02-14 12:25:11 -0500 |
|---|---|---|
| committer | Austin Clements <austin@google.com> | 2023-03-10 17:59:37 +0000 |
| commit | 3e360b035f4c3014e9564f4994c68ccc296ef629 (patch) | |
| tree | 1eddb9edefe065d015026fe628b8b62e7f7e3320 /src/runtime/proc.go | |
| parent | 9872428a715a907a122ad705b5fa42f11a385664 (diff) | |
| download | go-3e360b035f4c3014e9564f4994c68ccc296ef629.tar.xz | |
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 <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/proc.go')
| -rw-r--r-- | src/runtime/proc.go | 15 |
1 files changed, 7 insertions, 8 deletions
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. |
