diff --git a/proctl/threads.go b/proctl/threads.go index 080f36ca..7e4ded09 100644 --- a/proctl/threads.go +++ b/proctl/threads.go @@ -90,14 +90,11 @@ func (thread *ThreadContext) CallFn(name string, fn func() error) error { } defer thread.Process.Clear(bp.Addr) - if err = thread.saveRegisters(); err != nil { - return err - } - - regs, err := thread.Registers() + regs, err := thread.saveRegisters() if err != nil { return err } + previousFrame := make([]byte, f.FrameSize) frameSize := uintptr(regs.SP() + uint64(f.FrameSize)) if _, err := readMemory(thread, frameSize, previousFrame); err != nil { diff --git a/proctl/threads_darwin.go b/proctl/threads_darwin.go index a005e8df..00b656f0 100644 --- a/proctl/threads_darwin.go +++ b/proctl/threads_darwin.go @@ -83,12 +83,12 @@ func readMemory(thread *ThreadContext, addr uintptr, data []byte) (int, error) { return len(data), nil } -func (thread *ThreadContext) saveRegisters() error { +func (thread *ThreadContext) saveRegisters() (Registers, error) { kret := C.get_registers(C.mach_port_name_t(thread.os.thread_act), &thread.os.registers) if kret != C.KERN_SUCCESS { - return fmt.Errorf("could not save register contents") + return nil, fmt.Errorf("could not save register contents") } - return nil + return &Regs{pc: uint64(thread.os.registers.__rip), sp: uint64(thread.os.registers.__rsp)}, nil } func (thread *ThreadContext) restoreRegisters() error { diff --git a/proctl/threads_linux.go b/proctl/threads_linux.go index 603a6cd8..eca030d6 100644 --- a/proctl/threads_linux.go +++ b/proctl/threads_linux.go @@ -50,8 +50,11 @@ func (t *ThreadContext) blocked() bool { return false } -func (thread *ThreadContext) saveRegisters() error { - return sys.PtraceGetRegs(thread.Id, &thread.os.registers) +func (thread *ThreadContext) saveRegisters() (Registers, error) { + if err := sys.PtraceGetRegs(thread.Id, &thread.os.registers); err != nil { + return nil, fmt.Errorf("could not save register contents") + } + return &Regs{&thread.os.registers}, nil } func (thread *ThreadContext) restoreRegisters() error {