Refactoring ptrace register write for BSD ##debug (#15725)

This commit is contained in:
David CARLIER 2019-12-29 13:27:34 +00:00 committed by radare
parent a9b13e7d05
commit bac525d8e9
3 changed files with 31 additions and 8 deletions

View File

@ -738,12 +738,8 @@ static int r_debug_native_reg_write (RDebug *dbg, int type, const ut8* buf, int
return w32_reg_write (dbg, type, buf, size);
#elif __linux__
return linux_reg_write (dbg, type, buf, size);
#elif __KFBSD__
return (0 == ptrace (PT_SETDBREGS, dbg->pid,
(caddr_t)buf, sizeof (struct dbreg)));
#else
//eprintf ("TODO: No support for write DRX registers\n");
return false;
return bsd_reg_write (dbg, type, buf, size);
#endif
#else // i386/x86-64
return false;
@ -755,18 +751,24 @@ static int r_debug_native_reg_write (RDebug *dbg, int type, const ut8* buf, int
return w32_reg_write (dbg, type, buf, size);
#elif __linux__
return linux_reg_write (dbg, type, buf, size);
#elif __sun || __NetBSD__ || __KFBSD__ || __OpenBSD__ || __DragonFly__
#elif __sun
int ret = ptrace (PTRACE_SETREGS, dbg->pid,
(void*)(size_t)buf, sizeof (R_DEBUG_REG_T));
if (sizeof (R_DEBUG_REG_T) < size)
size = sizeof (R_DEBUG_REG_T);
return (ret != 0) ? false: true;
#else
#warning r_debug_native_reg_write not implemented
return bsd_reg_write (dbg, type, buf, size);
#endif
} else if (type == R_REG_TYPE_FPU) {
#if __linux__
return linux_reg_write (dbg, type, buf, size);
#elif __APPLE__
return false;
#elif __WINDOWS__
return false;
#else
return bsd_reg_write (dbg, type, buf, size);
#endif
} //else eprintf ("TODO: reg_write_non-gpr (%d)\n", type);
return false;

View File

@ -101,6 +101,26 @@ int bsd_handle_signals(RDebug *dbg) {
#endif
}
int bsd_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) {
int r = -1;
switch (type) {
case R_REG_TYPE_GPR:
r = ptrace (PT_SETREGS, dbg->pid,
(caddr_t)buf, sizeof (struct reg));
break;
case R_REG_TYPE_DRX:
#if __KFBSD__ || __NetBSD__
r = ptrace (PT_SETDBREGS, dbg->pid, (caddr_t)buf, sizeof (struct dbreg));
#endif
break;
case R_REG_TYPE_FPU:
r = ptrace (PT_SETFPREGS, dbg->pid, (caddr_t)buf, sizeof (struct fpreg));
break;
}
return (r == 0 ? true : false);
}
RDebugInfo *bsd_info(RDebug *dbg, const char *arg) {
#if __KFBSD__
struct kinfo_proc *kp;

View File

@ -7,7 +7,8 @@
#define R_DEBUG_REG_T struct reg
int bsd_handle_signals(RDebug *dbg);
RDebugInfo *bsd_info (RDebug *dbg, const char *arg);
int bsd_reg_write(RDebug *dbg, int type, const ut8 *buf, int size);
RDebugInfo *bsd_info(RDebug *dbg, const char *arg);
RList *bsd_pid_list(RDebug *dbg, RList *list);
RList *bsd_native_sysctl_map(RDebug *dbg);
RList *bsd_desc_list(int pid);