From b992c2649e6c30d25baeb3c26aba0e90b800a1f4 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 7 Mar 2017 15:20:40 -0500 Subject: [PATCH] runtime: print SP/FP on bad pointer crashes If the bad pointer is on a stack, this makes it possible to find the frame containing the bad pointer. Change-Id: Ieda44e054aa9ebf22d15d184457c7610b056dded Reviewed-on: https://go-review.googlesource.com/37858 Run-TryBot: Austin Clements Reviewed-by: Russ Cox Reviewed-by: Keith Randall TryBot-Result: Gobot Gobot --- src/runtime/mbitmap.go | 1 + src/runtime/mgcmark.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/runtime/mbitmap.go b/src/runtime/mbitmap.go index 3e782f50da..4e1a3e29f9 100644 --- a/src/runtime/mbitmap.go +++ b/src/runtime/mbitmap.go @@ -425,6 +425,7 @@ func heapBitsForObject(p, refBase, refOff uintptr) (base uintptr, hbits heapBits print("runtime: found in object at *(", hex(refBase), "+", hex(refOff), ")\n") gcDumpObject("object", refBase, refOff) } + getg().m.traceback = 2 throw("found bad pointer in Go heap (incorrect use of unsafe or cgo?)") } return diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go index 2b45881976..dd7a2bd8eb 100644 --- a/src/runtime/mgcmark.go +++ b/src/runtime/mgcmark.go @@ -1230,6 +1230,7 @@ func greyobject(obj, base, off uintptr, hbits heapBits, span *mspan, gcw *gcWork // Dump the object gcDumpObject("obj", obj, ^uintptr(0)) + getg().m.traceback = 2 throw("checkmark found unmarked object") } if hbits.isCheckmarked(span.elemsize) { @@ -1244,6 +1245,7 @@ func greyobject(obj, base, off uintptr, hbits heapBits, span *mspan, gcw *gcWork print("runtime: marking free object ", hex(obj), " found at *(", hex(base), "+", hex(off), ")\n") gcDumpObject("base", base, off) gcDumpObject("obj", obj, ^uintptr(0)) + getg().m.traceback = 2 throw("marking free object") } -- 2.48.1