command (next): Improvements for parallel programs

This patch aims to improve how Delve tracks the current goroutine,
especially in very highly parallel programs. The main spirit of this
patch is to ensure that even in situations where the goroutine we care
about is not executing (common for len(g) > len(m)) we still end up back
on that goroutine as a result of executing the 'next' command.

We accomplish this by tracking our original goroutine id, and any time a
breakpoint is hit or a threads stops, we examine the stopped threads and
see if any are executing the goroutine we care about. If not, we set
'next' breakpoint for them again and continue them. This is done so that
one of those threads can eventually pick up the goroutine we care about
and begin executing it again.
This commit is contained in:
Derek Parker
2015-08-20 09:28:11 -05:00
parent 71845350a0
commit b9846c7684
10 changed files with 205 additions and 74 deletions

View File

@ -12,20 +12,31 @@ type OSSpecificDetails struct {
registers sys.PtraceRegs
}
func (t *Thread) Halt() error {
if stopped(t.Id) {
return nil
func (t *Thread) Halt() (err error) {
defer func() {
if err == nil {
t.running = false
}
}()
if t.Stopped() {
return
}
err := sys.Tgkill(t.dbp.Pid, t.Id, sys.SIGSTOP)
err = sys.Tgkill(t.dbp.Pid, t.Id, sys.SIGSTOP)
if err != nil {
return fmt.Errorf("halt err %s on thread %d", err, t.Id)
err = fmt.Errorf("halt err %s on thread %d", err, t.Id)
return
}
_, _, err = wait(t.Id, t.dbp.Pid, 0)
if err != nil {
return fmt.Errorf("wait err %s on thread %d", err, t.Id)
err = fmt.Errorf("wait err %s on thread %d", err, t.Id)
return
}
t.running = false
return nil
return
}
func (thread *Thread) stopped() bool {
state := status(thread.Id)
return state == STATUS_TRACE_STOP
}
func (t *Thread) resume() (err error) {