From 2210debf6c953f25ef854b845a784542f47fb3d5 Mon Sep 17 00:00:00 2001 From: aarzilli Date: Wed, 28 Nov 2018 16:13:48 +0100 Subject: [PATCH] proc: handle gid == 0 in FindGoroutine Goroutine id == 0 is special (there can be many goroutines with id 0). If the caller of FindGoroutine asks for gid==0 and current thread is running a goroutine 0 (i.e. either no goroutine or a special goroutine) return whatever goroutine is running on the current thread. Updates #1428 --- pkg/proc/proc.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/proc/proc.go b/pkg/proc/proc.go index a845187d..970d297e 100644 --- a/pkg/proc/proc.go +++ b/pkg/proc/proc.go @@ -590,6 +590,20 @@ func FindGoroutine(dbp Process, gid int) (*G, error) { return dbp.SelectedGoroutine(), nil } + if gid == 0 { + // goroutine 0 is special, it either means we have no current goroutine + // (for example, running C code), or that we are running on a special + // stack (system stack, signal handling stack) and we didn't properly + // detect. + // If the user requested goroutine 0 and we the current thread is running + // on a goroutine 0 (or no goroutine at all) return the goroutine running + // on the current thread. + g, _ := GetG(dbp.CurrentThread()) + if g == nil || g.ID == 0 { + return g, nil + } + } + gs, _, err := GoroutinesInfo(dbp, 0, 0) if err != nil { return nil, err