]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: print g pointer in crash stack dump
authorCherry Mui <cherryyz@google.com>
Mon, 13 Nov 2023 17:31:31 +0000 (12:31 -0500)
committerCherry Mui <cherryyz@google.com>
Thu, 16 Nov 2023 21:52:15 +0000 (21:52 +0000)
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 <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/runtime/traceback.go

index 57feefb4a65609e477aef77be1d6a29ee83ada3d..66a1cc85ee47d5da44cbf5326c2fbeabecaa800b 100644 (file)
@@ -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)")
        }