From 4f132b7ef862d83390feb074be3e04109e43adaa Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 12 Jul 2022 16:42:06 -0400 Subject: [PATCH] runtime: don't track stack separately in gentraceback MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Michael Knyszek Reviewed-by: Michael Pratt Reviewed-by: Felix Geisendörfer TryBot-Result: Gopher Robot --- src/runtime/traceback.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go index 6773509901..507f366037 100644 --- a/src/runtime/traceback.go +++ b/src/runtime/traceback.go @@ -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") } -- 2.48.1