1
0
mirror of https://github.com/golang/go synced 2024-11-23 15:10:12 -07:00

runtime: don't track stack separately in gentraceback

Currently, gentraceback keeps a copy of the stack bounds of the stack
it's walking in the "stack" variable. Now that "gp" always refers to
the G whose stack it's walking, we can simply use gp.stack instead of
keeping a separate copy.

For #54466.

Change-Id: I68256e5dff6212cfcf14eda615487e66a92d4914
Reviewed-on: https://go-review.googlesource.com/c/go/+/458215
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Felix Geisendörfer <felix.geisendoerfer@datadoghq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Austin Clements 2022-07-12 16:42:06 -04:00
parent 2d93805171
commit 4f132b7ef8

View File

@ -78,7 +78,6 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
}
waspanic := false
cgoCtxt := gp.cgoCtxt
stack := gp.stack
printing := pcbuf == nil && callback == nil
// If the PC is zero, it's likely a nil function call.
@ -111,7 +110,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
if !f.valid() {
if callback != nil || printing {
print("runtime: g ", gp.goid, ": unknown pc ", hex(frame.pc), "\n")
tracebackHexdump(stack, &frame, 0)
tracebackHexdump(gp.stack, &frame, 0)
}
if callback != nil {
throw("unknown pc")
@ -177,7 +176,6 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
flag = f.flag
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
@ -195,7 +193,6 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
}
gp = gp.m.curg
frame.sp = gp.sched.sp
stack = gp.stack
cgoCtxt = gp.cgoCtxt
flag &^= funcFlag_SPWRITE
}
@ -264,7 +261,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
}
if callback != nil || doPrint {
print("runtime: g ", gp.goid, ": unexpected return pc for ", funcname(f), " called from ", hex(frame.lr), "\n")
tracebackHexdump(stack, &frame, lrPtr)
tracebackHexdump(gp.stack, &frame, lrPtr)
}
if callback != nil {
throw("unknown caller pc")
@ -483,7 +480,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
if frame.pc == frame.lr && frame.sp == frame.fp {
// If the next frame is identical to the current frame, we cannot make progress.
print("runtime: traceback stuck. pc=", hex(frame.pc), " sp=", hex(frame.sp), "\n")
tracebackHexdump(stack, &frame, frame.sp)
tracebackHexdump(gp.stack, &frame, frame.sp)
throw("traceback stuck")
}