1
0
mirror of https://github.com/golang/go synced 2024-11-05 18:56:10 -07:00

runtime: switch gp when jumping stacks during traceback

Currently, when traceback jumps from the system stack to a user stack
(e.g., during profiling tracebacks), it leaves gp pointing at the g0.
This is currently harmless since it's only used during profiling, so
the code paths in gentraceback that care about gp aren't used, but
it's really confusing and would certainly break if _TraceJumpStack
were ever used in a context other than profiling.

Fix this by updating gp to point to the user g when we switch stacks.

For #54466.

Change-Id: I1541e004667a52e37671803ce45c91d8c5308830
Reviewed-on: https://go-review.googlesource.com/c/go/+/424257
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Austin Clements <austin@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Austin Clements <austin@google.com>
This commit is contained in:
Austin Clements 2022-07-12 16:35:26 -04:00 committed by Gopher Robot
parent f00fa0b98d
commit 511cd9b8af

View File

@ -167,20 +167,22 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
// This keeps morestack() from showing up in the backtrace, // This keeps morestack() from showing up in the backtrace,
// but that makes some sense since it'll never be returned // but that makes some sense since it'll never be returned
// to. // to.
frame.pc = gp.m.curg.sched.pc gp = gp.m.curg
frame.pc = gp.sched.pc
frame.fn = findfunc(frame.pc) frame.fn = findfunc(frame.pc)
f = frame.fn f = frame.fn
flag = f.flag flag = f.flag
frame.lr = gp.m.curg.sched.lr frame.lr = gp.sched.lr
frame.sp = gp.m.curg.sched.sp frame.sp = gp.sched.sp
stack = gp.m.curg.stack stack = gp.stack
cgoCtxt = gp.m.curg.cgoCtxt cgoCtxt = gp.cgoCtxt
case funcID_systemstack: case funcID_systemstack:
// systemstack returns normally, so just follow the // systemstack returns normally, so just follow the
// stack transition. // stack transition.
frame.sp = gp.m.curg.sched.sp gp = gp.m.curg
stack = gp.m.curg.stack frame.sp = gp.sched.sp
cgoCtxt = gp.m.curg.cgoCtxt stack = gp.stack
cgoCtxt = gp.cgoCtxt
flag &^= funcFlag_SPWRITE flag &^= funcFlag_SPWRITE
} }
} }