提交 25783f23 编写于 作者: D Derek Parker

Implement Continue() for linux amd64

上级 ea0ff20e
......@@ -7,9 +7,10 @@ import (
)
type DebuggedProcess struct {
Pid int
Regs *syscall.PtraceRegs
Process *os.Process
Pid int
Regs *syscall.PtraceRegs
Process *os.Process
ProcessState *os.ProcessState
}
func NewDebugProcess(pid int) (*DebuggedProcess, error) {
......@@ -23,17 +24,18 @@ func NewDebugProcess(pid int) (*DebuggedProcess, error) {
return nil, err
}
debuggedProc := DebuggedProcess{
Pid: pid,
Regs: &syscall.PtraceRegs{},
Process: proc,
}
_, err = proc.Wait()
ps, err := proc.Wait()
if err != nil {
return nil, err
}
debuggedProc := DebuggedProcess{
Pid: pid,
Regs: &syscall.PtraceRegs{},
Process: proc,
ProcessState: ps,
}
return &debuggedProc, nil
}
......@@ -59,3 +61,19 @@ func (dbp *DebuggedProcess) Step() error {
return nil
}
func (dbp *DebuggedProcess) Continue() error {
err := syscall.PtraceCont(dbp.Pid, 0)
if err != nil {
return err
}
ps, err := dbp.Process.Wait()
if err != nil {
return err
}
dbp.ProcessState = ps
return nil
}
......@@ -5,23 +5,24 @@ import (
"testing"
)
func StartTestProcess() (int, error) {
func StartTestProcess() (*exec.Cmd, error) {
cmd := exec.Command("../fixtures/testprog")
err := cmd.Start()
if err != nil {
return 0, err
return nil, err
}
return cmd.Process.Pid, nil
return cmd, nil
}
func TestStep(t *testing.T) {
pid, err := StartTestProcess()
cmd, err := StartTestProcess()
if err != nil {
t.Fatal("Starting test process:", err)
}
pid := cmd.Process.Pid
p, err := NewDebugProcess(pid)
if err != nil {
t.Fatal("NewDebugProcess():", err)
......@@ -48,3 +49,29 @@ func TestStep(t *testing.T) {
t.Errorf("Expected %#v to be greater than %#v", regs.PC(), rip)
}
}
func TestContinue(t *testing.T) {
cmd, err := StartTestProcess()
if err != nil {
t.Fatal("Starting test process:", err)
}
pid := cmd.Process.Pid
p, err := NewDebugProcess(pid)
if err != nil {
t.Fatal("NewDebugProcess():", err)
}
if p.ProcessState.Exited() {
t.Fatal("Process already exited")
}
err = p.Continue()
if err != nil {
t.Fatal("Continue():", err)
}
if !p.ProcessState.Exited() {
t.Fatal("Process did not continue")
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册