提交 dcf51a50 编写于 作者: A Alessandro Arzilli 提交者: Derek Parker

proc/native: error when reading/writing memory of exited process (#812)

Fixes #809
上级 a731eb66
......@@ -554,6 +554,9 @@ func (p *Process) StepInstruction() error {
}
func (p *Process) SwitchThread(tid int) error {
if p.exited {
return proc.ProcessExitedError{Pid: p.conn.pid}
}
if th, ok := p.threads[tid]; ok {
p.currentThread = th
p.selectedGoroutine, _ = proc.GetG(p.CurrentThread())
......
......@@ -8,6 +8,8 @@ import (
"unsafe"
sys "golang.org/x/sys/unix"
"github.com/derekparker/delve/pkg/proc"
)
// WaitStatus is a synonym for the platform-specific WaitStatus
......@@ -105,6 +107,9 @@ func (t *Thread) stopped() bool {
}
func (t *Thread) WriteMemory(addr uintptr, data []byte) (int, error) {
if t.dbp.exited {
return 0, proc.ProcessExitedError{Pid: t.dbp.pid}
}
if len(data) == 0 {
return 0, nil
}
......@@ -120,6 +125,9 @@ func (t *Thread) WriteMemory(addr uintptr, data []byte) (int, error) {
}
func (t *Thread) ReadMemory(buf []byte, addr uintptr) (int, error) {
if t.dbp.exited {
return 0, proc.ProcessExitedError{Pid: t.dbp.pid}
}
if len(buf) == 0 {
return 0, nil
}
......
......@@ -97,6 +97,9 @@ func (t *Thread) restoreRegisters() (err error) {
}
func (t *Thread) WriteMemory(addr uintptr, data []byte) (written int, err error) {
if t.dbp.exited {
return 0, proc.ProcessExitedError{Pid: t.dbp.pid}
}
if len(data) == 0 {
return
}
......@@ -105,6 +108,9 @@ func (t *Thread) WriteMemory(addr uintptr, data []byte) (written int, err error)
}
func (t *Thread) ReadMemory(data []byte, addr uintptr) (n int, err error) {
if t.dbp.exited {
return 0, proc.ProcessExitedError{Pid: t.dbp.pid}
}
if len(data) == 0 {
return
}
......
......@@ -133,6 +133,9 @@ func (t *Thread) stopped() bool {
}
func (t *Thread) WriteMemory(addr uintptr, data []byte) (int, error) {
if t.dbp.exited {
return 0, proc.ProcessExitedError{Pid: t.dbp.pid}
}
var count uintptr
err := _WriteProcessMemory(t.dbp.os.hProcess, addr, &data[0], uintptr(len(data)), &count)
if err != nil {
......@@ -144,6 +147,9 @@ func (t *Thread) WriteMemory(addr uintptr, data []byte) (int, error) {
var ErrShortRead = errors.New("short read")
func (t *Thread) ReadMemory(buf []byte, addr uintptr) (int, error) {
if t.dbp.exited {
return 0, proc.ProcessExitedError{Pid: t.dbp.pid}
}
if len(buf) == 0 {
return 0, nil
}
......
......@@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/derekparker/delve/service/api"
......@@ -24,6 +25,12 @@ func assertError(err error, t *testing.T, s string) {
fname := filepath.Base(file)
t.Fatalf("failed assertion at %s:%d: %s (no error)\n", fname, line, s)
}
if strings.Index(err.Error(), "Internal debugger error") >= 0 {
_, file, line, _ := runtime.Caller(1)
fname := filepath.Base(file)
t.Fatalf("failed assertion at %s:%d: %s internal debugger error: %v\n", fname, line, s, err)
}
}
func init() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册