提交 7761faad 编写于 作者: A Alessandro Arzilli 提交者: Derek Parker

terminal: show current thread of goroutines (#564)

上级 ede88013
......@@ -620,6 +620,10 @@ func (dbp *Process) GoroutinesInfo() ([]*G, error) {
return allg, nil
}
func (g *G) Thread() *Thread {
return g.thread
}
// Halt stops all threads.
func (dbp *Process) Halt() (err error) {
if dbp.exited {
......
......@@ -186,11 +186,17 @@ func ConvertFunction(fn *gosym.Func) *Function {
// ConvertGoroutine converts from proc.G to api.Goroutine.
func ConvertGoroutine(g *proc.G) *Goroutine {
th := g.Thread()
tid := 0
if th != nil {
tid = th.ID
}
return &Goroutine{
ID: g.ID,
CurrentLoc: ConvertLocation(g.CurrentLoc),
UserCurrentLoc: ConvertLocation(g.UserCurrent()),
GoStatementLoc: ConvertLocation(g.Go()),
ThreadID: tid,
}
}
......
......@@ -200,6 +200,8 @@ type Goroutine struct {
UserCurrentLoc Location `json:"userCurrentLoc"`
// Location of the go instruction that started this goroutine
GoStatementLoc Location `json:"goStatementLoc"`
// ID of the associated thread for running goroutines
ThreadID int `json:"threadID"`
}
// DebuggerCommand is a command which changes the debugger's execution state.
......
......@@ -547,7 +547,11 @@ func formatGoroutine(g *api.Goroutine, fgl formatGoroutineLoc) string {
locname = "Go"
loc = g.GoStatementLoc
}
return fmt.Sprintf("%d - %s: %s", g.ID, locname, formatLocation(loc))
thread := ""
if g.ThreadID != 0 {
thread = fmt.Sprintf(" (thread %d)", g.ThreadID)
}
return fmt.Sprintf("%d - %s: %s%s", g.ID, locname, formatLocation(loc), thread)
}
func writeGoroutineLong(w io.Writer, g *api.Goroutine, prefix string) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册