aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2022-07-12 16:35:26 -0400
committerGopher Robot <gobot@golang.org>2022-09-02 19:08:50 +0000
commit511cd9b8af10de9cad86be38a22e5eb2e5d4cd8d (patch)
tree961a1214fd0a62de3e505e4b10c0c1a0956e34dd /src/runtime
parentf00fa0b98da9f4353839da99e6f6f7f109f9954f (diff)
downloadgo-511cd9b8af10de9cad86be38a22e5eb2e5d4cd8d.tar.xz
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>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/traceback.go18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go
index ed64343470..8ecddc8935 100644
--- a/src/runtime/traceback.go
+++ b/src/runtime/traceback.go
@@ -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,
// but that makes some sense since it'll never be returned
// to.
- frame.pc = gp.m.curg.sched.pc
+ gp = gp.m.curg
+ frame.pc = gp.sched.pc
frame.fn = findfunc(frame.pc)
f = frame.fn
flag = f.flag
- frame.lr = gp.m.curg.sched.lr
- frame.sp = gp.m.curg.sched.sp
- stack = gp.m.curg.stack
- cgoCtxt = gp.m.curg.cgoCtxt
+ frame.lr = gp.sched.lr
+ frame.sp = gp.sched.sp
+ stack = gp.stack
+ cgoCtxt = gp.cgoCtxt
case funcID_systemstack:
// systemstack returns normally, so just follow the
// stack transition.
- frame.sp = gp.m.curg.sched.sp
- stack = gp.m.curg.stack
- cgoCtxt = gp.m.curg.cgoCtxt
+ gp = gp.m.curg
+ frame.sp = gp.sched.sp
+ stack = gp.stack
+ cgoCtxt = gp.cgoCtxt
flag &^= funcFlag_SPWRITE
}
}