提交 6527f15e 编写于 作者: I Ilia Choly 提交者: Derek Parker

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.
上级 c185b7d0
......@@ -501,7 +501,9 @@ func (dbp *Process) GoroutinesInfo() ([]*G, error) {
g.Line = loc.Line
g.Func = loc.Fn
}
allg = append(allg, g)
if g.Status != Gdead {
allg = append(allg, g)
}
}
dbp.allGCache = allg
return allg, nil
......
......@@ -37,6 +37,19 @@ type M struct {
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
// fields that Delve is interested in).
type G struct {
......@@ -45,6 +58,7 @@ type G struct {
SP uint64 // SP of goroutine when it was parked.
GoPC uint64 // PC of 'go' statement that created this goroutine.
WaitReason string // Reason for goroutine being parked.
Status uint64
// Information on goroutine location.
File string
......@@ -176,6 +190,12 @@ func parseG(thread *Thread, gaddr uint64, deref bool) (*G, error) {
if err != nil {
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
goidAddr, err := rdr.AddrForMember("goid", initialInstructions)
if err != nil {
......@@ -215,6 +235,7 @@ func parseG(thread *Thread, gaddr uint64, deref bool) (*G, error) {
Func: fn,
WaitReason: waitreason,
DeferPC: deferPC,
Status: atomicStatus,
}
return g, nil
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册