From 719efc70eb84b74a93d236f7c7ddca9901f65436 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 20 May 2015 11:50:48 -0400 Subject: [PATCH] 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/10292 Reviewed-by: Daniel Morsing Reviewed-by: Rick Hudson --- src/runtime/traceback.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go index 12b2a53603..5ed601e6f3 100644 --- a/src/runtime/traceback.go +++ b/src/runtime/traceback.go @@ -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 }