diff --git a/pkg/proc/native/proc.go b/pkg/proc/native/proc.go index 5e6d1d7a..c3086904 100644 --- a/pkg/proc/native/proc.go +++ b/pkg/proc/native/proc.go @@ -106,7 +106,7 @@ func detachWithoutGroup(dbp *nativeProcess, kill bool) error { // Detach from the process being debugged, optionally killing it. func (procgrp *processGroup) Detach(pid int, kill bool) (err error) { dbp := procgrp.procForPid(pid) - if dbp.exited { + if ok, _ := dbp.Valid(); !ok { return nil } if kill && dbp.childProcess { @@ -170,8 +170,8 @@ func (dbp *nativeProcess) Breakpoints() *proc.BreakpointMap { // RequestManualStop sets the `manualStopRequested` flag and // sends SIGSTOP to all threads. func (dbp *nativeProcess) RequestManualStop(cctx *proc.ContinueOnceContext) error { - if dbp.exited { - return proc.ErrProcessExited{Pid: dbp.pid} + if ok, err := dbp.Valid(); !ok { + return err } return dbp.requestManualStop() } @@ -300,7 +300,7 @@ func (procgrp *processGroup) ContinueOnce(cctx *proc.ContinueOnceContext) (proc. dbp.memthread = trapthread // refresh memthread for every other process for _, p2 := range procgrp.procs { - if p2.exited || p2 == dbp { + if p2.exited || p2.detached || p2 == dbp { continue } for _, th := range p2.threads { diff --git a/pkg/proc/native/proc_darwin.go b/pkg/proc/native/proc_darwin.go index 6483c5f2..aafa5d5f 100644 --- a/pkg/proc/native/proc_darwin.go +++ b/pkg/proc/native/proc_darwin.go @@ -183,7 +183,7 @@ func Attach(pid int, waitFor *proc.WaitFor, _ []string) (*proc.TargetGroup, erro // Kill kills the process. func (procgrp *processGroup) kill(dbp *nativeProcess) (err error) { - if dbp.exited { + if ok, _ := dbp.Valid(); !ok { return nil } err = sys.Kill(-dbp.pid, sys.SIGKILL) @@ -449,8 +449,8 @@ func (procgrp *processGroup) stop(cctx *proc.ContinueOnceContext, trapthread *na } func (dbp *nativeProcess) stop(trapthread *nativeThread) (*nativeThread, error) { - if dbp.exited { - return nil, proc.ErrProcessExited{Pid: dbp.pid} + if ok, err := dbp.Valid(); !ok { + return nil, err } for _, th := range dbp.threads { if !th.Stopped() { diff --git a/pkg/proc/native/proc_freebsd.go b/pkg/proc/native/proc_freebsd.go index 8549b4a0..ec93a40a 100644 --- a/pkg/proc/native/proc_freebsd.go +++ b/pkg/proc/native/proc_freebsd.go @@ -206,7 +206,7 @@ func initialize(dbp *nativeProcess) (string, error) { // kill kills the target process. func (procgrp *processGroup) kill(dbp *nativeProcess) (err error) { - if dbp.exited { + if ok, _ := dbp.Valid(); !ok { return nil } dbp.execPtraceFunc(func() { @@ -508,8 +508,8 @@ func (procgrp *processGroup) stop(cctx *proc.ContinueOnceContext, trapthread *na } func (dbp *nativeProcess) stop(trapthread *nativeThread) (*nativeThread, error) { - if dbp.exited { - return nil, proc.ErrProcessExited{Pid: dbp.pid} + if ok, err := dbp.Valid(); !ok { + return nil, err } var err error diff --git a/pkg/proc/native/proc_linux.go b/pkg/proc/native/proc_linux.go index cba5c82c..89647bfc 100644 --- a/pkg/proc/native/proc_linux.go +++ b/pkg/proc/native/proc_linux.go @@ -261,7 +261,7 @@ func (dbp *nativeProcess) GetBufferedTracepoints() []ebpf.RawUProbeParams { // kill kills the target process. func (procgrp *processGroup) kill(dbp *nativeProcess) error { - if dbp.exited { + if ok, _ := dbp.Valid(); !ok { return nil } if !dbp.threads[dbp.pid].Stopped() { @@ -680,7 +680,7 @@ func (procgrp *processGroup) stop(cctx *proc.ContinueOnceContext, trapthread *na } for _, dbp := range procgrp.procs { - if dbp.exited { + if ok, _ := dbp.Valid(); !ok { continue } for _, th := range dbp.threads { @@ -703,7 +703,7 @@ func (procgrp *processGroup) stop(cctx *proc.ContinueOnceContext, trapthread *na // stop all threads that are still running for _, dbp := range procgrp.procs { - if dbp.exited { + if ok, _ := dbp.Valid(); !ok { continue } for _, th := range dbp.threads { @@ -724,7 +724,7 @@ func (procgrp *processGroup) stop(cctx *proc.ContinueOnceContext, trapthread *na for { allstopped := true for _, dbp := range procgrp.procs { - if dbp.exited { + if ok, _ := dbp.Valid(); !ok { continue } for _, th := range dbp.threads { @@ -746,7 +746,7 @@ func (procgrp *processGroup) stop(cctx *proc.ContinueOnceContext, trapthread *na switchTrapthread := false for _, dbp := range procgrp.procs { - if dbp.exited { + if ok, _ := dbp.Valid(); !ok { continue } err := stop1(cctx, dbp, trapthread, &switchTrapthread) @@ -759,7 +759,7 @@ func (procgrp *processGroup) stop(cctx *proc.ContinueOnceContext, trapthread *na trapthreadID := trapthread.ID trapthread = nil for _, dbp := range procgrp.procs { - if dbp.exited { + if ok, _ := dbp.Valid(); !ok { continue } for _, th := range dbp.threads { diff --git a/pkg/proc/native/proc_windows.go b/pkg/proc/native/proc_windows.go index 68a3ecb6..043bf467 100644 --- a/pkg/proc/native/proc_windows.go +++ b/pkg/proc/native/proc_windows.go @@ -259,7 +259,7 @@ func waitForSearchProcess(pfx string, seen map[int]struct{}) (int, error) { // kill kills the process. func (procgrp *processGroup) kill(dbp *nativeProcess) error { - if dbp.exited { + if ok, _ := dbp.Valid(); !ok { return nil } diff --git a/pkg/proc/native/threads_darwin.go b/pkg/proc/native/threads_darwin.go index bbdaa5c9..5be7c415 100644 --- a/pkg/proc/native/threads_darwin.go +++ b/pkg/proc/native/threads_darwin.go @@ -93,8 +93,8 @@ func (t *nativeThread) Stopped() bool { } func (t *nativeThread) WriteMemory(addr uint64, data []byte) (int, error) { - if t.dbp.exited { - return 0, proc.ErrProcessExited{Pid: t.dbp.pid} + if ok, err := t.dbp.Valid(); !ok { + return 0, err } if len(data) == 0 { return 0, nil @@ -111,8 +111,8 @@ func (t *nativeThread) WriteMemory(addr uint64, data []byte) (int, error) { } func (t *nativeThread) ReadMemory(buf []byte, addr uint64) (int, error) { - if t.dbp.exited { - return 0, proc.ErrProcessExited{Pid: t.dbp.pid} + if ok, err := t.dbp.Valid(); !ok { + return 0, err } if len(buf) == 0 { return 0, nil diff --git a/pkg/proc/native/threads_freebsd.go b/pkg/proc/native/threads_freebsd.go index fd5c4a2c..94ee8334 100644 --- a/pkg/proc/native/threads_freebsd.go +++ b/pkg/proc/native/threads_freebsd.go @@ -77,8 +77,8 @@ func (t *nativeThread) restoreRegisters(savedRegs proc.Registers) error { } func (t *nativeThread) WriteMemory(addr uint64, data []byte) (written int, err error) { - if t.dbp.exited { - return 0, proc.ErrProcessExited{Pid: t.dbp.pid} + if ok, err := t.dbp.Valid(); !ok { + return 0, err } if len(data) == 0 { return 0, nil @@ -88,8 +88,8 @@ func (t *nativeThread) WriteMemory(addr uint64, data []byte) (written int, err e } func (t *nativeThread) ReadMemory(data []byte, addr uint64) (n int, err error) { - if t.dbp.exited { - return 0, proc.ErrProcessExited{Pid: t.dbp.pid} + if ok, err := t.dbp.Valid(); !ok { + return 0, err } if len(data) == 0 { return 0, nil diff --git a/pkg/proc/native/threads_linux.go b/pkg/proc/native/threads_linux.go index 571d46c8..9cf1e3a8 100644 --- a/pkg/proc/native/threads_linux.go +++ b/pkg/proc/native/threads_linux.go @@ -88,8 +88,8 @@ func (procgrp *processGroup) singleStep(t *nativeThread) (err error) { } func (t *nativeThread) WriteMemory(addr uint64, data []byte) (written int, err error) { - if t.dbp.exited { - return 0, proc.ErrProcessExited{Pid: t.dbp.pid} + if ok, err := t.dbp.Valid(); !ok { + return 0, err } if len(data) == 0 { return @@ -106,8 +106,8 @@ func (t *nativeThread) WriteMemory(addr uint64, data []byte) (written int, err e } func (t *nativeThread) ReadMemory(data []byte, addr uint64) (n int, err error) { - if t.dbp.exited { - return 0, proc.ErrProcessExited{Pid: t.dbp.pid} + if ok, err := t.dbp.Valid(); !ok { + return 0, err } if len(data) == 0 { return diff --git a/pkg/proc/native/threads_windows.go b/pkg/proc/native/threads_windows.go index 8e75c34c..f741ea58 100644 --- a/pkg/proc/native/threads_windows.go +++ b/pkg/proc/native/threads_windows.go @@ -5,8 +5,6 @@ import ( "syscall" sys "golang.org/x/sys/windows" - - "github.com/go-delve/delve/pkg/proc" ) const enableHardwareBreakpoints = false // see https://github.com/go-delve/delve/issues/2768 @@ -106,8 +104,8 @@ func (procgrp *processGroup) singleStep(t *nativeThread) error { } func (t *nativeThread) WriteMemory(addr uint64, data []byte) (int, error) { - if t.dbp.exited { - return 0, proc.ErrProcessExited{Pid: t.dbp.pid} + if ok, err := t.dbp.Valid(); !ok { + return 0, err } if len(data) == 0 { return 0, nil @@ -123,8 +121,8 @@ func (t *nativeThread) WriteMemory(addr uint64, data []byte) (int, error) { var ErrShortRead = errors.New("short read") func (t *nativeThread) ReadMemory(buf []byte, addr uint64) (int, error) { - if t.dbp.exited { - return 0, proc.ErrProcessExited{Pid: t.dbp.pid} + if ok, err := t.dbp.Valid(); !ok { + return 0, err } if len(buf) == 0 { return 0, nil