From: Dan Scales Date: Sat, 26 Oct 2019 13:53:07 +0000 (-0700) Subject: runtime: fix dumpgoroutine() to deal with open-coded defers X-Git-Tag: go1.14beta1~548 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1f3339f441e2053f8efd7ead417761ea319fe790;p=gostls13.git runtime: fix dumpgoroutine() to deal with open-coded defers _defer.fn can be nil, so we need to add a check when dumping _defer.fn.fn. Fixes #35172 Change-Id: Ic1138be5ec9dce915a87467cfa51ff83acc6e3a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/203697 Run-TryBot: Dan Scales TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements --- diff --git a/src/runtime/heapdump.go b/src/runtime/heapdump.go index 992df6391e..4d55b316f7 100644 --- a/src/runtime/heapdump.go +++ b/src/runtime/heapdump.go @@ -371,7 +371,12 @@ func dumpgoroutine(gp *g) { dumpint(uint64(d.sp)) dumpint(uint64(d.pc)) dumpint(uint64(uintptr(unsafe.Pointer(d.fn)))) - dumpint(uint64(uintptr(unsafe.Pointer(d.fn.fn)))) + if d.fn == nil { + // d.fn can be nil for open-coded defers + dumpint(uint64(0)) + } else { + dumpint(uint64(uintptr(unsafe.Pointer(d.fn.fn)))) + } dumpint(uint64(uintptr(unsafe.Pointer(d.link)))) } for p := gp._panic; p != nil; p = p.link { diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index eecc6a78ac..c319196557 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -824,10 +824,10 @@ type _defer struct { // defers. We have only one defer record for the entire frame (which may // currently have 0, 1, or more defers active). openDefer bool - sp uintptr // sp at time of defer - pc uintptr // pc at time of defer - fn *funcval - _panic *_panic // panic that is running defer + sp uintptr // sp at time of defer + pc uintptr // pc at time of defer + fn *funcval // can be nil for open-coded defers + _panic *_panic // panic that is running defer link *_defer // If openDefer is true, the fields below record values about the stack