Skip to content

Commit

Permalink
proc/native: partial support for Windows async preempt mechanism
Browse files Browse the repository at this point in the history
See golang/go#36494 for a description of why
full support for 1.14 under windows is problematic.
  • Loading branch information
aarzilli committed Feb 9, 2020
1 parent 36a949d commit 23d4b91
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions pkg/proc/native/threads_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,22 @@ func (t *Thread) singleStep() error {
return err
}

_, err = _ResumeThread(t.os.hThread)
if err != nil {
return err
suspendcnt := 0

// If a thread simultaneously hits a breakpoint and is suspended by the Go
// runtime it will have a suspend count greater than 1 and to actually take
// a single step we have to resume it multiple times here.
// We keep a counter of how many times it was suspended so that after
// single-stepping we can re-suspend it the corrent number of times.
for {
n, err := _ResumeThread(t.os.hThread)
if err != nil {
return err
}
suspendcnt++
if n == 1 {
break
}
}

for {
Expand All @@ -63,9 +76,11 @@ func (t *Thread) singleStep() error {
})
}

_, err = _SuspendThread(t.os.hThread)
if err != nil {
return err
for i := 0; i < suspendcnt; i++ {
_, err = _SuspendThread(t.os.hThread)
if err != nil {
return err
}
}

t.dbp.execPtraceFunc(func() {
Expand Down

0 comments on commit 23d4b91

Please sign in to comment.