Skip to content

Commit

Permalink
proc: bugfix: race condition between termination and Continue (linux)
Browse files Browse the repository at this point in the history
resume loops in continueOnce moved to a OS specific resume function,
this makes the problem easier to deal with and seems to be more
appropriate to a windows port given what transpired from discussion
of Pull Request go-delve#276
  • Loading branch information
aarzilli committed Nov 19, 2015
1 parent 032945b commit 00f49a2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
16 changes: 2 additions & 14 deletions proc/proc.go
Expand Up @@ -394,20 +394,8 @@ func (dbp *Process) runBreakpointConditions() error {

// Resume process, does not evaluate breakpoint conditionals
func (dbp *Process) continueOnce() error {
// all threads stopped over a breakpoint are made to step over it
for _, thread := range dbp.Threads {
if thread.CurrentBreakpoint != nil {
if err := thread.Step(); err != nil {
return err
}
thread.CurrentBreakpoint = nil
}
}
// everything is resumed
for _, thread := range dbp.Threads {
if err := thread.resume(); err != nil {
return dbp.exitGuard(err)
}
if err := dbp.resume(); err != nil {
return err
}
return dbp.run(func() error {
thread, err := dbp.trapWait(-1)
Expand Down
19 changes: 19 additions & 0 deletions proc/proc_darwin.go
Expand Up @@ -356,3 +356,22 @@ func (dbp *Process) exitGuard(err error) error {
}
return err
}

func (dbp *Process) resume() error {
// all threads stopped over a breakpoint are made to step over it
for _, thread := range dbp.Threads {
if thread.CurrentBreakpoint != nil {
if err := thread.Step(); err != nil {
return err
}
thread.CurrentBreakpoint = nil
}
}
// everything is resumed
for _, thread := range dbp.Threads {
if err := thread.resume(); err != nil {
return dbp.exitGuard(err)
}
}
return nil
}
23 changes: 22 additions & 1 deletion proc/proc_linux.go
Expand Up @@ -286,7 +286,9 @@ func (dbp *Process) trapWait(pid int) (*Thread, error) {
return nil, fmt.Errorf("could not continue new thread %d %s", cloned, err)
}
if err = dbp.Threads[int(wpid)].Continue(); err != nil {
return nil, fmt.Errorf("could not continue existing thread %d %s", cloned, err)
if err != sys.ESRCH {
return nil, fmt.Errorf("could not continue existing thread %d %s", wpid, err)
}
}
continue
}
Expand Down Expand Up @@ -401,3 +403,22 @@ func (dbp *Process) exitGuard(err error) error {

return err
}

func (dbp *Process) resume() error {
// all threads stopped over a breakpoint are made to step over it
for _, thread := range dbp.Threads {
if thread.CurrentBreakpoint != nil {
if err := thread.Step(); err != nil {
return err
}
thread.CurrentBreakpoint = nil
}
}
// everything is resumed
for _, thread := range dbp.Threads {
if err := thread.resume(); err != nil && err != sys.ESRCH {
return err
}
}
return nil
}

0 comments on commit 00f49a2

Please sign in to comment.