mirror of
https://github.com/go-delve/delve.git
synced 2025-10-30 02:07:58 +08:00
Handle set_pc errors
This commit is contained in:
@ -17,7 +17,10 @@ func (r *Regs) SP() uint64 {
|
||||
}
|
||||
|
||||
func (r *Regs) SetPC(thread *ThreadContext, pc uint64) error {
|
||||
C.set_pc(thread.os.thread_act, C.uint64_t(pc))
|
||||
kret := C.set_pc(thread.os.thread_act, C.uint64_t(pc))
|
||||
if kret != C.KERN_SUCCESS {
|
||||
return fmt.Errorf("could not set pc")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -47,19 +47,18 @@ get_registers(mach_port_name_t task, x86_thread_state64_t *state) {
|
||||
}
|
||||
|
||||
// TODO(dp) this should return kret instead of void
|
||||
void
|
||||
kern_return_t
|
||||
set_pc(thread_act_t task, uint64_t pc) {
|
||||
kern_return_t kret;
|
||||
x86_thread_state64_t state;
|
||||
mach_msg_type_number_t stateCount = x86_THREAD_STATE64_COUNT;
|
||||
|
||||
kret = thread_get_state(task, x86_THREAD_STATE64, (thread_state_t)&state, &stateCount);
|
||||
if (kret != KERN_SUCCESS) puts(mach_error_string(kret));
|
||||
if (kret != KERN_SUCCESS) return kret;
|
||||
state.__rip = pc;
|
||||
|
||||
kret = thread_set_state(task, x86_THREAD_STATE64, (thread_state_t)&state, stateCount);
|
||||
if (kret != KERN_SUCCESS) puts(mach_error_string(kret));
|
||||
// TODO(dp) - possible memory leak - vm_deallocate state
|
||||
return thread_set_state(task, x86_THREAD_STATE64, (thread_state_t)&state, stateCount);
|
||||
}
|
||||
|
||||
// TODO(dp) this should return kret instead of void
|
||||
|
||||
@ -13,7 +13,7 @@ read_memory(mach_port_name_t, mach_vm_address_t, void *, mach_msg_type_number_t)
|
||||
kern_return_t
|
||||
get_registers(mach_port_name_t, x86_thread_state64_t*);
|
||||
|
||||
void
|
||||
kern_return_t
|
||||
set_pc(thread_act_t, uint64_t);
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user