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
This commit is contained in:
aarzilli 2018-11-28 16:13:48 +01:00 committed by Derek Parker
parent 6611fbe919
commit 2210debf6c

@ -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