diff --git a/libr/debug/debug.c b/libr/debug/debug.c index e54bbae974..21dfb174a6 100644 --- a/libr/debug/debug.c +++ b/libr/debug/debug.c @@ -255,15 +255,15 @@ 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 dbg->h->detach (pid); return false; } diff --git a/libr/debug/p/native/xnu/xnu_debug.c b/libr/debug/p/native/xnu/xnu_debug.c index 8378782929..dbebee0ab7 100644 --- a/libr/debug/p/native/xnu/xnu_debug.c +++ b/libr/debug/p/native/xnu/xnu_debug.c @@ -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); } +#if 0 + if (thread_resume (dbg->tid) == KERN_SUCCESS) { + ret = true; + } else perror ("thread_resume"); #endif - if (task_resume (task)) { - perror ("task_resume"); - ret = false; - } else ret = true; ios_hwstep_enable (dbg, false); - ret = true; -// wat :D - ptrace (PT_THUPDATE, pid, (void*)0, 0); +// 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); diff --git a/libr/debug/p/native/xnu/xnu_threads.c b/libr/debug/p/native/xnu/xnu_threads.c index e941cd1054..b8d97ff490 100644 --- a/libr/debug/p/native/xnu/xnu_threads.c +++ b/libr/debug/p/native/xnu/xnu_threads.c @@ -28,6 +28,7 @@ static int xnu_thread_set_drx(RDebug *dbg, xnu_thread_t *thread) { memcpy (®s->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); diff --git a/sys/rebuild.sh b/sys/rebuild.sh index ccd90c69f2..ac8de89084 100755 --- a/sys/rebuild.sh +++ b/sys/rebuild.sh @@ -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