aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2023-11-13 12:31:31 -0500
committerCherry Mui <cherryyz@google.com>2023-11-16 21:52:15 +0000
commit3a9254636c35b8d99826b203e73f335fbcd07fa9 (patch)
tree175c2ccefb7a645fb1d66feb90f9da76eb24120c /src
parent1ab9df4849d1bb527035ccf475cc5b7b4aa9b789 (diff)
downloadgo-3a9254636c35b8d99826b203e73f335fbcd07fa9.tar.xz
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 <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src')
-rw-r--r--src/runtime/traceback.go15
1 files changed, 13 insertions, 2 deletions
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)")
}