proc/native/windows: do not call _DebugBreakProcess on a stopped process (#2140)

Fixes #2138
This commit is contained in:
Alessandro Arzilli 2020-08-31 18:42:35 +02:00 committed by GitHub
parent 788c41be76
commit 0165975470
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 0 deletions

10
_fixtures/issue2138.go Normal file

@ -0,0 +1,10 @@
package main
import (
"time"
)
func main() {
time.Sleep(time.Hour)
println("ok")
}

@ -17,6 +17,7 @@ type osProcessDetails struct {
hProcess syscall.Handle
breakThread int
entryPoint uint64
running bool
}
// Launch creates and begins debugging a new process.
@ -175,6 +176,10 @@ func (dbp *nativeProcess) kill() error {
}
func (dbp *nativeProcess) requestManualStop() error {
if !dbp.os.running {
return nil
}
dbp.os.running = false
return _DebugBreakProcess(dbp.os.hProcess)
}
@ -390,6 +395,7 @@ func (dbp *nativeProcess) resume() error {
return err
}
}
dbp.os.running = true
return nil
}
@ -400,6 +406,8 @@ func (dbp *nativeProcess) stop(trapthread *nativeThread) (err error) {
return &proc.ErrProcessExited{Pid: dbp.Pid()}
}
dbp.os.running = false
// While the debug event that stopped the target was being propagated
// other target threads could generate other debug events.
// After this function we need to know about all the threads

@ -4906,3 +4906,35 @@ func TestStepoutOneliner(t *testing.T) {
}
})
}
func TestRequestManualStopWhileStopped(t *testing.T) {
// Requesting a manual stop while stopped shouldn't cause problems (issue #2138).
withTestProcess("issue2138", t, func(p *proc.Target, fixture protest.Fixture) {
resumed := make(chan struct{})
setFileBreakpoint(p, t, fixture.Source, 8)
assertNoError(p.Continue(), t, "Continue() 1")
p.ResumeNotify(resumed)
go func() {
<-resumed
time.Sleep(1 * time.Second)
p.RequestManualStop()
}()
t.Logf("at time.Sleep call")
assertNoError(p.Continue(), t, "Continue() 2")
t.Logf("manually stopped")
p.RequestManualStop()
p.RequestManualStop()
p.RequestManualStop()
resumed = make(chan struct{})
p.ResumeNotify(resumed)
go func() {
<-resumed
time.Sleep(1 * time.Second)
p.RequestManualStop()
}()
t.Logf("resuming sleep")
assertNoError(p.Continue(), t, "Continue() 3")
t.Logf("done")
})
}