runtime: in getTraceback, set gp->m before gogo

Currently, when collecting a traceback for another goroutine,
getTraceback calls gogo(gp) switching to gp, which will resume in
mcall, which will call gtraceback, which will set up gp->m. There
is a gap between setting the current running g to gp and setting
gp->m. If a profiling signal arrives in between, sigtramp will
see a non-nil gp with a nil m, and will seg fault. Fix this by
setting up gp->m first.

Fixes golang/go#29448.

Change-Id: Ic2c65e2692c48b08279079408d47d07e16375025
Reviewed-by: Ian Lance Taylor <>
2 files changed