mirror of
https://github.com/go-delve/delve.git
synced 2025-10-30 10:17:03 +08:00
proc: Exclude dead goroutines from results.
Some of the goroutines stored in runtime.allg are in the dead state and should not be displayed. The state is determined by the 'g.atomicstatus' member.
This commit is contained in:
@ -501,7 +501,9 @@ func (dbp *Process) GoroutinesInfo() ([]*G, error) {
|
|||||||
g.Line = loc.Line
|
g.Line = loc.Line
|
||||||
g.Func = loc.Fn
|
g.Func = loc.Fn
|
||||||
}
|
}
|
||||||
allg = append(allg, g)
|
if g.Status != Gdead {
|
||||||
|
allg = append(allg, g)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dbp.allGCache = allg
|
dbp.allGCache = allg
|
||||||
return allg, nil
|
return allg, nil
|
||||||
|
|||||||
@ -37,6 +37,19 @@ type M struct {
|
|||||||
curg uintptr // Current G running on this thread.
|
curg uintptr // Current G running on this thread.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
// G status, from: src/runtime/runtime2.go
|
||||||
|
Gidle uint64 = iota // 0
|
||||||
|
Grunnable // 1 runnable and on a run queue
|
||||||
|
Grunning // 2
|
||||||
|
Gsyscall // 3
|
||||||
|
Gwaiting // 4
|
||||||
|
Gmoribund_unused // 5 currently unused, but hardcoded in gdb scripts
|
||||||
|
Gdead // 6
|
||||||
|
Genqueue // 7 Only the Gscanenqueue is used.
|
||||||
|
Gcopystack // 8 in this state when newstack is moving the stack
|
||||||
|
)
|
||||||
|
|
||||||
// Represents a runtime G (goroutine) structure (at least the
|
// Represents a runtime G (goroutine) structure (at least the
|
||||||
// fields that Delve is interested in).
|
// fields that Delve is interested in).
|
||||||
type G struct {
|
type G struct {
|
||||||
@ -45,6 +58,7 @@ type G struct {
|
|||||||
SP uint64 // SP of goroutine when it was parked.
|
SP uint64 // SP of goroutine when it was parked.
|
||||||
GoPC uint64 // PC of 'go' statement that created this goroutine.
|
GoPC uint64 // PC of 'go' statement that created this goroutine.
|
||||||
WaitReason string // Reason for goroutine being parked.
|
WaitReason string // Reason for goroutine being parked.
|
||||||
|
Status uint64
|
||||||
|
|
||||||
// Information on goroutine location.
|
// Information on goroutine location.
|
||||||
File string
|
File string
|
||||||
@ -176,6 +190,12 @@ func parseG(thread *Thread, gaddr uint64, deref bool) (*G, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// Parse atomicstatus
|
||||||
|
atomicStatusAddr, err := rdr.AddrForMember("atomicstatus", initialInstructions)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
atomicStatus, err := thread.readUintRaw(uintptr(atomicStatusAddr), 4)
|
||||||
// Parse goid
|
// Parse goid
|
||||||
goidAddr, err := rdr.AddrForMember("goid", initialInstructions)
|
goidAddr, err := rdr.AddrForMember("goid", initialInstructions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -215,6 +235,7 @@ func parseG(thread *Thread, gaddr uint64, deref bool) (*G, error) {
|
|||||||
Func: fn,
|
Func: fn,
|
||||||
WaitReason: waitreason,
|
WaitReason: waitreason,
|
||||||
DeferPC: deferPC,
|
DeferPC: deferPC,
|
||||||
|
Status: atomicStatus,
|
||||||
}
|
}
|
||||||
return g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user