diff --git a/pkg/proc/core/core.go b/pkg/proc/core/core.go index 938f2f0b..f5a48ff2 100644 --- a/pkg/proc/core/core.go +++ b/pkg/proc/core/core.go @@ -306,10 +306,6 @@ func (p *Process) Halt() error { return nil } -func (p *Process) Kill() error { - return nil -} - func (p *Process) Pid() int { return p.core.Pid } diff --git a/pkg/proc/gdbserial/gdbserver.go b/pkg/proc/gdbserial/gdbserver.go index 6ac27129..a7c8629f 100644 --- a/pkg/proc/gdbserial/gdbserver.go +++ b/pkg/proc/gdbserial/gdbserver.go @@ -745,24 +745,14 @@ func (p *Process) Halt() error { return p.conn.sendCtrlC() } -func (p *Process) Kill() error { - if p.exited { - return nil - } - err := p.conn.kill() - if _, exited := err.(proc.ProcessExitedError); exited { - p.exited = true - return nil - } - return err -} - func (p *Process) Detach(kill bool) error { - if kill { - if err := p.Kill(); err != nil { + if kill && !p.exited { + err := p.conn.kill() + if err != nil { if _, exited := err.(proc.ProcessExitedError); !exited { return err } + p.exited = true } } if !p.exited { diff --git a/pkg/proc/interface.go b/pkg/proc/interface.go index cdb21c81..a33e0e05 100644 --- a/pkg/proc/interface.go +++ b/pkg/proc/interface.go @@ -91,7 +91,6 @@ type ProcessManipulation interface { // after a call to RequestManualStop. CheckAndClearManualStopRequest() bool Halt() error - Kill() error Detach(bool) error } diff --git a/pkg/proc/native/proc.go b/pkg/proc/native/proc.go index bd2294eb..25b83937 100644 --- a/pkg/proc/native/proc.go +++ b/pkg/proc/native/proc.go @@ -79,7 +79,7 @@ func (dbp *Process) Detach(kill bool) (err error) { return nil } if kill && dbp.childProcess { - err := dbp.Kill() + err := dbp.kill() if err != nil { return err } diff --git a/pkg/proc/native/proc_darwin.go b/pkg/proc/native/proc_darwin.go index 060966ca..204fb0a1 100644 --- a/pkg/proc/native/proc_darwin.go +++ b/pkg/proc/native/proc_darwin.go @@ -166,7 +166,7 @@ func Attach(pid int) (*Process, error) { } // Kill kills the process. -func (dbp *Process) Kill() (err error) { +func (dbp *Process) kill() (err error) { if dbp.exited { return nil } diff --git a/pkg/proc/native/proc_linux.go b/pkg/proc/native/proc_linux.go index e666fecf..4275afd5 100644 --- a/pkg/proc/native/proc_linux.go +++ b/pkg/proc/native/proc_linux.go @@ -98,8 +98,8 @@ func Attach(pid int) (*Process, error) { return dbp, nil } -// Kill kills the target process. -func (dbp *Process) Kill() (err error) { +// kill kills the target process. +func (dbp *Process) kill() (err error) { if dbp.exited { return nil } diff --git a/pkg/proc/native/proc_windows.go b/pkg/proc/native/proc_windows.go index 53d500b7..6ddd9d7d 100644 --- a/pkg/proc/native/proc_windows.go +++ b/pkg/proc/native/proc_windows.go @@ -170,8 +170,8 @@ func Attach(pid int) (*Process, error) { return dbp, nil } -// Kill kills the process. -func (dbp *Process) Kill() error { +// kill kills the process. +func (dbp *Process) kill() error { if dbp.exited { return nil } diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index 65fd8694..2460b5c7 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -968,20 +968,6 @@ func TestKill(t *testing.T) { // k command presumably works but leaves the process around? return } - withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) { - if err := p.Kill(); err != nil { - t.Fatal(err) - } - if !p.Exited() { - t.Fatal("expected process to have exited") - } - if runtime.GOOS == "linux" { - _, err := os.Open(fmt.Sprintf("/proc/%d/", p.Pid())) - if err == nil { - t.Fatal("process has not exited", p.Pid()) - } - } - }) withTestProcess("testprog", t, func(p proc.Process, fixture protest.Fixture) { if err := p.Detach(true); err != nil { t.Fatal(err) @@ -2086,8 +2072,7 @@ func TestUnsupportedArch(t *testing.T) { case proc.UnsupportedLinuxArchErr, proc.UnsupportedWindowsArchErr, proc.UnsupportedDarwinArchErr: // all good case nil: - p.Halt() - p.Kill() + p.Detach(true) t.Fatal("Launch is expected to fail, but succeeded") default: t.Fatal(err) diff --git a/pkg/proc/proc_unix_test.go b/pkg/proc/proc_unix_test.go index ae3a3b9d..ccb6be71 100644 --- a/pkg/proc/proc_unix_test.go +++ b/pkg/proc/proc_unix_test.go @@ -46,7 +46,7 @@ func TestIssue419(t *testing.T) { if p.Pid() <= 0 { // if we don't stop the inferior the test will never finish p.RequestManualStop() - err := p.Kill() + err := p.Detach(true) errChan <- errIssue419{pid: p.Pid(), err: err} return } @@ -57,7 +57,7 @@ func TestIssue419(t *testing.T) { errChan <- proc.Continue(p) }) - for i :=0; i<2; i++ { + for i := 0; i < 2; i++ { err := <-errChan if v, ok := err.(errIssue419); ok {