Skip to content

Commit 511cd9b

Browse files
aclementsgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Auto-Submit: Austin Clements <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Austin Clements <[email protected]>
1 parent f00fa0b commit 511cd9b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/runtime/traceback.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,22 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
167167
// This keeps morestack() from showing up in the backtrace,
168168
// but that makes some sense since it'll never be returned
169169
// to.
170-
frame.pc = gp.m.curg.sched.pc
170+
gp = gp.m.curg
171+
frame.pc = gp.sched.pc
171172
frame.fn = findfunc(frame.pc)
172173
f = frame.fn
173174
flag = f.flag
174-
frame.lr = gp.m.curg.sched.lr
175-
frame.sp = gp.m.curg.sched.sp
176-
stack = gp.m.curg.stack
177-
cgoCtxt = gp.m.curg.cgoCtxt
175+
frame.lr = gp.sched.lr
176+
frame.sp = gp.sched.sp
177+
stack = gp.stack
178+
cgoCtxt = gp.cgoCtxt
178179
case funcID_systemstack:
179180
// systemstack returns normally, so just follow the
180181
// stack transition.
181-
frame.sp = gp.m.curg.sched.sp
182-
stack = gp.m.curg.stack
183-
cgoCtxt = gp.m.curg.cgoCtxt
182+
gp = gp.m.curg
183+
frame.sp = gp.sched.sp
184+
stack = gp.stack
185+
cgoCtxt = gp.cgoCtxt
184186
flag &^= funcFlag_SPWRITE
185187
}
186188
}

0 commit comments

Comments
 (0)