Commit 719efc70 authored by Austin Clements's avatar Austin Clements

runtime: make runtime.callers walk calling G, not g0

Currently runtime.callers invokes gentraceback with the pc and sp of
the G it is called from, but always passes g0 even if it was called
from a regular g. Right now this has no ill effects because
runtime.callers does not use either callback argument or the
_TraceJumpStack flag, but it makes the code fragile and will break
some upcoming changes.

Fix this by lifting the getg() call outside of the systemstack in
runtime.callers.

Change-Id: I4e1e927961c0e0cd4dcf28693be47df7bae9e122
Reviewed-on: https://go-review.googlesource.com/10292Reviewed-by: 's avatarDaniel Morsing <daniel.morsing@gmail.com>
Reviewed-by: 's avatarRick Hudson <rlh@golang.org>
parent 91191e7b
......@@ -531,9 +531,10 @@ func traceback1(pc, sp, lr uintptr, gp *g, flags uint) {
func callers(skip int, pcbuf []uintptr) int {
sp := getcallersp(unsafe.Pointer(&skip))
pc := uintptr(getcallerpc(unsafe.Pointer(&skip)))
gp := getg()
var n int
systemstack(func() {
n = gentraceback(pc, sp, 0, getg(), skip, &pcbuf[0], len(pcbuf), nil, nil, 0)
n = gentraceback(pc, sp, 0, gp, skip, &pcbuf[0], len(pcbuf), nil, nil, 0)
})
return n
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment