From: Cherry Mui Date: Mon, 13 Nov 2023 17:31:31 +0000 (-0500) Subject: runtime: print g pointer in crash stack dump X-Git-Tag: go1.22rc1~290 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3a9254636c35b8d99826b203e73f335fbcd07fa9;p=gostls13.git runtime: print g pointer in crash stack dump When debugging a runtime crash with a stack trace, sometimes we have the g pointer in some places (e.g. as an argument of a traceback function), but the g's goid in some other places (the stack trace of that goroutine), which are usually not easy to match up. This CL makes it print the g pointer. This is only printed in crash mode, so it doesn't change the usual user stack trace. Change-Id: I19140855bf020a327ab0619b665ec1d1c70cca8a Reviewed-on: https://go-review.googlesource.com/c/go/+/541996 Reviewed-by: Michael Pratt LUCI-TryBot-Result: Go LUCI --- diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go index 57feefb4a6..66a1cc85ee 100644 --- a/src/runtime/traceback.go +++ b/src/runtime/traceback.go @@ -199,7 +199,7 @@ func (u *unwinder) initAt(pc0, sp0, lr0 uintptr, gp *g, flags unwindFlags) { f := findfunc(frame.pc) if !f.valid() { if flags&unwindSilentErrors == 0 { - print("runtime: g ", gp.goid, ": unknown pc ", hex(frame.pc), "\n") + print("runtime: g ", gp.goid, " gp=", gp, ": unknown pc ", hex(frame.pc), "\n") tracebackHexdump(gp.stack, &frame, 0) } if flags&(unwindPrintErrors|unwindSilentErrors) == 0 { @@ -1177,6 +1177,8 @@ var gStatusStrings = [...]string{ } func goroutineheader(gp *g) { + level, _, _ := gotraceback() + gpstatus := readgstatus(gp) isScan := gpstatus&_Gscan != 0 @@ -1200,7 +1202,16 @@ func goroutineheader(gp *g) { if (gpstatus == _Gwaiting || gpstatus == _Gsyscall) && gp.waitsince != 0 { waitfor = (nanotime() - gp.waitsince) / 60e9 } - print("goroutine ", gp.goid, " [", status) + print("goroutine ", gp.goid) + if gp.m != nil && gp.m.throwing >= throwTypeRuntime && gp == gp.m.curg || level >= 2 { + print(" gp=", gp) + if gp.m != nil { + print(" m=", gp.m.id, " mp=", gp.m) + } else { + print(" m=nil") + } + } + print(" [", status) if isScan { print(" (scan)") }