Some rework for regs+step+cont in iosdbg

This commit is contained in:
pancake 2015-11-17 00:57:22 +01:00
parent 0327c8fb97
commit 4f1663d6bf
4 changed files with 25 additions and 29 deletions

View File

@ -255,13 +255,13 @@ R_API int r_debug_startv(struct r_debug_t *dbg, int argc, char **argv) {
return false;
}
R_API int r_debug_start(struct r_debug_t *dbg, const char *cmd) {
R_API int r_debug_start(RDebug *dbg, const char *cmd) {
/* TODO: this argc/argv parser is done in r_io */
// TODO: parse cmd and generate argc and argv
return false;
}
R_API int r_debug_detach(struct r_debug_t *dbg, int pid) {
R_API int r_debug_detach(RDebug *dbg, int pid) {
if (dbg->h && dbg->h->detach)
return dbg->h->detach (pid);
return false;

View File

@ -161,44 +161,37 @@ static task_t task_for_pid_workaround(int Pid) {
bool xnu_step(RDebug *dbg) {
int ret = false;
int pid = dbg->pid;
task_t task;
(void)getcurthread (dbg, &task);
#if __arm__ || __arm64__ || __aarch64__
// op-not-permitted ret = ptrace (PT_STEP, dbg->pid, (caddr_t)1, 0); //SIGINT
ios_hwstep_enable (dbg, true);
task = pid_to_task (dbg->pid);
if (task<1) {
perror ("task_resume");
perror ("pid_to_task");
eprintf ("step failed on task %d for pid %d\n", task, dbg->tid);
}
#if 0
ptrace-step not supported on ios
ret = ptrace (PT_STEP, pid, (caddr_t)1, 0); //SIGINT
if (ret != 0) {
perror ("ptrace-step");
eprintf ("mach-error: %d, %s\n", ret, MACH_ERROR_STRING (ret));
ret = false; /* do not wait for events */
if (task_resume (task) != KERN_SUCCESS) {
perror ("thread_resume");
} else {
eprintf ("step ok\n");
ret = true;
waitpid (dbg->pid, NULL, 0);
}
#endif
if (task_resume (task)) {
perror ("task_resume");
ret = false;
} else ret = true;
ios_hwstep_enable (dbg, false);
#if 0
if (thread_resume (dbg->tid) == KERN_SUCCESS) {
ret = true;
// wat :D
ptrace (PT_THUPDATE, pid, (void*)0, 0);
} else perror ("thread_resume");
#endif
ios_hwstep_enable (dbg, false);
// eprintf ("thu %d\n", ptrace (PT_THUPDATE, dbg->pid, (void*)0, 0));
#else
thread_t th = getcurthread (dbg, &task);
task_resume (task);
ret = ptrace (PT_STEP, pid, (caddr_t)1, 0); //SIGINT
if (ret != 0) {
ret = ptrace (PT_STEP, dbg->pid, (caddr_t)1, 0) == 0; //SIGINT
if (!ret) {
perror ("ptrace-step");
eprintf ("mach-error: %d, %s\n", ret, MACH_ERROR_STRING (ret));
ret = false; /* do not wait for events */
} else ret = true;
}
//TODO handle the signals here in xnu. Now is only supported for linux
/*r_debug_handle_signals (dbg);*/
#endif
@ -226,7 +219,6 @@ int xnu_continue(RDebug *dbg, int pid, int tid, int sig) {
//return xnu_dettach (pid);
return true;
#else
//ut64 rip = r_debug_reg_get (dbg, "pc");
void *data = (void*)(size_t)((sig != -1) ? sig : dbg->reason.signum);
task_resume (pid_to_task (pid));
return ptrace (PT_CONTINUE, pid, (void*)(size_t)1,
@ -308,8 +300,8 @@ int xnu_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
break;
}
if (!ret) {
eprintf ("Failed to read reg xnu_reg_read\n");
return false;
perror ("xnu_reg_read");
// return false;
}
if (th->state) {
int rsz = R_MIN (th->state_size, size);

View File

@ -28,6 +28,7 @@ static int xnu_thread_set_drx(RDebug *dbg, xnu_thread_t *thread) {
memcpy (&regs->uds, thread->state, thread->count);
#elif __arm || __arm64 || __aarch64
/* not supported */
return false;
#elif __POWERPC__
/* not supported */
#ifndef PPC_DEBUG_STATE32
@ -120,7 +121,7 @@ static bool xnu_thread_get_gpr(RDebug *dbg, xnu_thread_t *thread) {
(thread_state_t)thread->state, &thread->count);
if (rc != KERN_SUCCESS) {
thread->count = 0;
eprintf ("Failed to get gpr registers\n");
perror ("thread_get_state");
return false;
}
return true;
@ -142,6 +143,7 @@ static bool xnu_thread_get_drx(RDebug *dbg, xnu_thread_t *thread) {
/* not supported yet */
thread->flavor = -1;
thread->count = 0;
return true;
#endif
kern_return_t rc = thread_get_state (thread->tid, thread->flavor,
thread->state, &thread->count);

View File

@ -26,6 +26,8 @@ Build() {
RebuildIOSDebug() {
Rebuild libr/debug
# Rebuild libr/util
# Rebuild libr/core
Rebuild binr/radare2
make -C binr/radare2 ios-sign
if [ -n "${IOSIP}" ]; then