More cleanup for XNU debug

This commit is contained in:
Álvaro Felipe Melchor 2015-11-24 21:01:11 +01:00 committed by pancake
parent c7a444cb39
commit 434e9a0986
5 changed files with 71 additions and 35 deletions

View File

@ -64,6 +64,22 @@ return strdup (
"drx dr1 .64 8 0\n"
"drx dr2 .64 16 0\n"
"drx dr3 .64 24 0\n"
"drx dr6 .64 32 0\n"
"drx dr7 .64 40 0\n"
"drx dr4 .64 32 0\n"
"drx dr5 .64 40 0\n"
"drx dr6 .64 48 0\n"
"drx dr7 .64 56 0\n"
);
/*_STRUCT_X86_DEBUG_STATE64
{
__uint64_t dr0;
__uint64_t dr1;
__uint64_t dr2;
__uint64_t dr3;
__uint64_t dr4;
__uint64_t dr5;
__uint64_t dr6;
__uint64_t dr7;
};
*/

View File

@ -46,6 +46,8 @@ return strdup (
"drx dr1 .32 4 0\n"
"drx dr2 .32 8 0\n"
"drx dr3 .32 12 0\n"
"drx dr4 .32 16 0\n"
"drx dr5 .32 20 0\n"
"drx dr6 .32 24 0\n"
"drx dr7 .32 28 0\n"
"seg cs .32 44 0\n"
@ -54,3 +56,18 @@ return strdup (
"seg fs .32 56 0\n"
"seg gs .32 60 0\n"
);
/*
_STRUCT_X86_DEBUG_STATE32
{
unsigned int __dr0;
unsigned int __dr1;
unsigned int __dr2;
unsigned int __dr3;
unsigned int __dr4;
unsigned int __dr5;
unsigned int __dr6;
unsigned int __dr7;
};
#else
*/

View File

@ -167,9 +167,9 @@ static task_t task_for_pid_workaround(int Pid) {
bool xnu_step(RDebug *dbg) {
int ret = false;
task_t task;
#if __arm__ || __arm64__ || __aarch64__
// op-not-permitted ret = ptrace (PT_STEP, dbg->pid, (caddr_t)1, 0); //SIGINT
task_t task;
ios_hwstep_enable (dbg, true);
task = pid_to_task (dbg->pid);
if (task<1) {
@ -205,7 +205,11 @@ bool xnu_step(RDebug *dbg) {
}
int xnu_attach(RDebug *dbg, int pid) {
//this should be necessary
#if XNU_USE_PTRACE
//XXX it seems that PT_ATTACH will be deprecated
//but using PT_ATTACHEXC throw errors
if (pid != dbg->pid && ptrace (PT_ATTACH, pid, 0, 0) == -1) {
perror ("ptrace (PT_ATTACH)");
return -1;

View File

@ -18,22 +18,21 @@ static bool modify_trace_bit(RDebug *dbg, xnu_thread *th, int enable) {
unsigned int state_count = R_REG_STATE_SZ;
kern_return_t kr;
ret = xnu_thread_get_gpr (dbg, th);
if (ret == R_FALSE) {
if (!ret) {
eprintf ("error to get gpr registers in trace bit intel\n");
return false;
}
state = (R_REG_T)th->gpr;
if (th->flavor == x86_THREAD_STATE32) {
state = (R_REG_T *)&th->gpr;
if (state->tsh.flavor == x86_THREAD_STATE32) {
state->uts.ts32.__eflags = (state->uts.ts32.__eflags & \
~0x100UL) | (enable ? 0x100UL : 0);
} else if (th->flavor == x86_THREAD_STATE64) {
} else if (state->tsh.flavor == x86_THREAD_STATE64) {
state->uts.ts64.__rflags = (state->uts.ts64.__rflags & \
~0x100UL) | (enable ? 0x100UL : 0);
} else {
eprintf ("Invalid bit size\n");
return false;
}
memcpy (th->state, state->uts, th->count);
if (!xnu_thread_set_gpr (dbg, th)) {
eprintf ("error xnu_thread_set_gpr in modify_trace_bit intel\n");
return false;
@ -42,7 +41,7 @@ static bool modify_trace_bit(RDebug *dbg, xnu_thread *th, int enable) {
}
#elif __POWERPC__ //ppc processor
//XXX poor support at this stage i don't care so much. Once intel and arm done it could be done
//TODO add better support for ppc
static bool modify_trace_bit(RDebug *dbg, xnu_thread *th, int enable) {
R_REG_T state;

View File

@ -12,22 +12,22 @@ static void xnu_thread_free(xnu_thread_t *thread) {
static int xnu_thread_set_drx(RDebug *dbg, xnu_thread_t *thread) {
R_DEBUG_REG_T *regs;
if (!thread) {
thread->count = 0;
return false;
}
kern_return_t rc;
if (!dbg || !thread) return false;
regs = (R_DEBUG_REG_T*)&thread->drx;
if (!regs) return false;
#if __i386__ || __x86_64__
thread->flavor = x86_DEBUG_STATE;
thread->count = x86_DEBUG_STATE_COUNT;
if (dbg->bits == R_SYS_BITS_64) {
thread->flavor = regs->dsh.flavor = x86_DEBUG_STATE64;
thread->count = R_DEBUG_STATE_SZ; //R_MIN (thread->count, sizeof(regs->uds.ds64));
regs->dsh.flavor = x86_DEBUG_STATE64;
regs->dsh.count = x86_DEBUG_STATE64_COUNT;
} else {
thread->flavor = regs->dsh.flavor = x86_DEBUG_STATE32;
thread->count = R_DEBUG_STATE_SZ; //R_MIN (thread->count, sizeof(regs->uds.ds32));
regs->dsh.flavor = x86_DEBUG_STATE32;
regs->dsh.count = x86_DEBUG_STATE32_COUNT;
}
memcpy (&regs->uds, thread->state, thread->count);
#elif __arm || __arm64 || __aarch64
/* not supported */
//no supported yet but for no so long
return false;
#elif __POWERPC__
/* not supported */
@ -40,8 +40,8 @@ static int xnu_thread_set_drx(RDebug *dbg, xnu_thread_t *thread) {
regs->dsh.flavor = 0;
thread->count = 0;
#endif
kern_return_t rc = thread_set_state (thread->tid, thread->flavor,
(thread_state_t)thread->state, thread->count);
rc = thread_set_state (thread->tid, thread->flavor,
(thread_state_t)regs, thread->count);
if (rc != KERN_SUCCESS) {
perror ("thread_set_state");
thread->count = false;
@ -123,26 +123,26 @@ static bool xnu_thread_get_gpr(RDebug *dbg, xnu_thread_t *thread) {
return true;
}
//XXX this should work as long as in arm trace bit relies on this
static bool xnu_thread_get_drx(RDebug *dbg, xnu_thread_t *thread) {
kern_return_t rc;
R_DEBUG_REG_T *regs;
if (!thread) {
thread->count = 0;
return false;
}
thread->state = regs = (R_DEBUG_REG_T*)&thread->drx;
thread->state_size = sizeof (thread->drx);
if (!dbg || !thread) return false;
regs = (R_DEBUG_REG_T*)&thread->drx;
#if __x86_64__ || __i386__
thread->flavor = regs->dsh.flavor = x86_DEBUG_STATE;
thread->count = regs->dsh.count = R_DEBUG_STATE_SZ;
thread->flavor = x86_DEBUG_STATE;
thread->count = x86_DEBUG_STATE_COUNT;
thread->state_size = (dbg->bits == R_SYS_BITS_64) ?
sizeof (x86_debug_state64_t) :
sizeof (x86_debug_state32_t);
// XXX thread->state = regs->uds;
#elif __arm || __arm64 || __aarch64
/* not supported yet */
thread->flavor = -1;
thread->count = 0;
return true;
//no supported yet but not for so long
return false;
#endif
kern_return_t rc = thread_get_state (thread->tid, thread->flavor,
thread->state, &thread->count);
rc = thread_get_state (thread->tid, thread->flavor,
(thread_state_t)regs, &thread->count);
if (rc != KERN_SUCCESS) {
thread->count = 0;
perror ("xnu_thread_get_drx");