delve/proc/registers_darwin_amd64.go

40 lines
814 B
Go
Raw Normal View History

2015-06-12 19:49:23 +00:00
package proc
2015-01-14 02:37:10 +00:00
// #include "threads_darwin.h"
import "C"
2015-05-04 22:31:13 +00:00
import "fmt"
2015-01-14 02:37:10 +00:00
type Regs struct {
pc, sp, cx uint64
2015-01-14 02:37:10 +00:00
}
func (r *Regs) PC() uint64 {
return r.pc
}
func (r *Regs) SP() uint64 {
return r.sp
}
func (r *Regs) CX() uint64 {
return r.cx
}
2015-01-14 02:37:10 +00:00
func (r *Regs) SetPC(thread *ThreadContext, pc uint64) error {
2015-02-28 16:41:05 +00:00
kret := C.set_pc(thread.os.thread_act, C.uint64_t(pc))
if kret != C.KERN_SUCCESS {
2015-05-04 22:31:13 +00:00
return fmt.Errorf("could not set pc")
2015-02-28 16:41:05 +00:00
}
2015-01-14 02:37:10 +00:00
return nil
}
func registers(thread *ThreadContext) (Registers, error) {
2015-02-28 16:39:21 +00:00
var state C.x86_thread_state64_t
kret := C.get_registers(C.mach_port_name_t(thread.os.thread_act), &state)
if kret != C.KERN_SUCCESS {
2015-05-04 22:31:13 +00:00
return nil, fmt.Errorf("could not get registers")
2015-02-28 16:39:21 +00:00
}
regs := &Regs{pc: uint64(state.__rip), sp: uint64(state.__rsp), cx: uint64(state.__rcx)}
2015-01-14 02:37:10 +00:00
return regs, nil
}