Implement Continue() for linux amd64
This commit is contained in:
parent
ea0ff20e16
commit
25783f23d6
@ -7,9 +7,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DebuggedProcess struct {
|
type DebuggedProcess struct {
|
||||||
Pid int
|
Pid int
|
||||||
Regs *syscall.PtraceRegs
|
Regs *syscall.PtraceRegs
|
||||||
Process *os.Process
|
Process *os.Process
|
||||||
|
ProcessState *os.ProcessState
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDebugProcess(pid int) (*DebuggedProcess, error) {
|
func NewDebugProcess(pid int) (*DebuggedProcess, error) {
|
||||||
@ -23,17 +24,18 @@ func NewDebugProcess(pid int) (*DebuggedProcess, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
debuggedProc := DebuggedProcess{
|
ps, err := proc.Wait()
|
||||||
Pid: pid,
|
|
||||||
Regs: &syscall.PtraceRegs{},
|
|
||||||
Process: proc,
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = proc.Wait()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debuggedProc := DebuggedProcess{
|
||||||
|
Pid: pid,
|
||||||
|
Regs: &syscall.PtraceRegs{},
|
||||||
|
Process: proc,
|
||||||
|
ProcessState: ps,
|
||||||
|
}
|
||||||
|
|
||||||
return &debuggedProc, nil
|
return &debuggedProc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,3 +61,19 @@ func (dbp *DebuggedProcess) Step() error {
|
|||||||
|
|
||||||
return nil
|
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"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func StartTestProcess() (int, error) {
|
func StartTestProcess() (*exec.Cmd, error) {
|
||||||
cmd := exec.Command("../fixtures/testprog")
|
cmd := exec.Command("../fixtures/testprog")
|
||||||
|
|
||||||
err := cmd.Start()
|
err := cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd.Process.Pid, nil
|
return cmd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStep(t *testing.T) {
|
func TestStep(t *testing.T) {
|
||||||
pid, err := StartTestProcess()
|
cmd, err := StartTestProcess()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Starting test process:", err)
|
t.Fatal("Starting test process:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid := cmd.Process.Pid
|
||||||
p, err := NewDebugProcess(pid)
|
p, err := NewDebugProcess(pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("NewDebugProcess():", err)
|
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)
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user