Skip to content

Commit 1f3339f

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Austin Clements <[email protected]>
1 parent 22d3770 commit 1f3339f

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/runtime/heapdump.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,12 @@ func dumpgoroutine(gp *g) {
371371
dumpint(uint64(d.sp))
372372
dumpint(uint64(d.pc))
373373
dumpint(uint64(uintptr(unsafe.Pointer(d.fn))))
374-
dumpint(uint64(uintptr(unsafe.Pointer(d.fn.fn))))
374+
if d.fn == nil {
375+
// d.fn can be nil for open-coded defers
376+
dumpint(uint64(0))
377+
} else {
378+
dumpint(uint64(uintptr(unsafe.Pointer(d.fn.fn))))
379+
}
375380
dumpint(uint64(uintptr(unsafe.Pointer(d.link))))
376381
}
377382
for p := gp._panic; p != nil; p = p.link {

src/runtime/runtime2.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,10 @@ type _defer struct {
824824
// defers. We have only one defer record for the entire frame (which may
825825
// currently have 0, 1, or more defers active).
826826
openDefer bool
827-
sp uintptr // sp at time of defer
828-
pc uintptr // pc at time of defer
829-
fn *funcval
830-
_panic *_panic // panic that is running defer
827+
sp uintptr // sp at time of defer
828+
pc uintptr // pc at time of defer
829+
fn *funcval // can be nil for open-coded defers
830+
_panic *_panic // panic that is running defer
831831
link *_defer
832832

833833
// If openDefer is true, the fields below record values about the stack

0 commit comments

Comments
 (0)