diff --git a/proc/proc.go b/proc/proc.go index 36d9029f..18a70910 100644 --- a/proc/proc.go +++ b/proc/proc.go @@ -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 { diff --git a/service/api/conversions.go b/service/api/conversions.go index fb19650d..cc6bd8e9 100644 --- a/service/api/conversions.go +++ b/service/api/conversions.go @@ -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, } } diff --git a/service/api/types.go b/service/api/types.go index c1e949d2..8a2c4f80 100644 --- a/service/api/types.go +++ b/service/api/types.go @@ -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. diff --git a/terminal/command.go b/terminal/command.go index cc4ffc6a..a1de1073 100644 --- a/terminal/command.go +++ b/terminal/command.go @@ -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) {