45,9 → 45,6 |
|
#define OPCODE_INT3 0xCC |
|
#define ISTATE_OFF_EIP 12 |
#define ISTATE_OFF_EFLAGS 14 |
|
void arch_breakpoint_add(uintptr_t addr) |
{ |
char brkp[1]; |
57,7 → 54,7 |
|
brk = NULL; |
for (i = 0; i < MAX_BRKPTS; i++) |
if (brk_list[i].set == 0) brk = brk_list+i; |
if (brk_list[i].set == 0) { brk = brk_list+i; break; } |
|
if (!brk) { |
cons_printf("too many breakpoints\n"); |
74,16 → 71,16 |
brk->set = 1; |
} |
|
static istate_t istate; |
static breakpoint_t *lifted_brkpt; |
|
void arch_event_breakpoint(thash_t thread_hash) |
{ |
static istate_t istate; |
int rc; |
|
rc = udebug_regs_read(app_phone, thread_hash, &istate); |
cons_printf("udebug_regs_read -> %d\n", rc); |
cons_printf("EIP was 0x%08x\n", istate.eip); |
// cons_printf("udebug_regs_read -> %d\n", rc); |
// cons_printf("EIP was 0x%08x\n", istate.eip); |
int brk_addr = istate.eip - 1; |
int bi; |
for (bi = 0; bi < MAX_BRKPTS; bi++) { |
93,40 → 90,53 |
|
if (bi < MAX_BRKPTS) { |
cons_printf("breakpoint %d hit\n", bi); |
breakpoint_hit(); |
|
istate.eip = brk_addr; |
istate.eflags |= 0x0100; /* trap flag */ |
cons_printf("setting EIP to 0x%08x\n", istate.eip); |
// cons_printf("setting EIP to 0x%08x\n", istate.eip); |
rc = udebug_regs_write(app_phone, thread_hash, &istate); |
if (rc < 0) { printf("error writing regs\n"); return; } |
rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 1); |
cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc); |
if (rc < 0) { printf("error writing mem\n"); return; } |
// cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc); |
lifted_brkpt = &brk_list[bi]; |
|
breakpoint_hit(); |
} else { |
cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr); |
} |
} |
|
void arch_event_trap(thash_t thread_hash) |
void arch_event_trap(dthread_t *dt) |
{ |
static istate_t istate; |
unsigned char brkinstr[1]; |
int rc; |
|
cons_printf("trap event\n"); |
// cons_printf("trap event\n"); |
|
breakpoint_t *lb = lifted_brkpt; |
if (lb) { |
brkinstr[0] = OPCODE_INT3; |
rc = udebug_mem_write(app_phone, brkinstr, lb->addr, 1); |
cons_printf("restore breakpoint -> %d\n", rc); |
// cons_printf("restore breakpoint -> %d\n", rc); |
lifted_brkpt = NULL; |
} |
|
rc = udebug_regs_read(app_phone, thread_hash, &istate); |
cons_printf("udebug_regs_read -> %d\n", rc); |
if (!dt->arch.singlestep) { |
rc = udebug_regs_read(app_phone, dt->hash, &istate); |
// cons_printf("udebug_regs_read -> %d\n", rc); |
istate.eflags &= ~0x0100; /* trap flag */ |
rc = udebug_regs_write(app_phone, thread_hash, &istate); |
rc = udebug_regs_write(app_phone, dt->hash, &istate); |
} else { |
// printf("ss-hit\n"); |
singlestep_hit(); |
} |
} |
|
void arch_dump_regs(thash_t thash) |
{ |
static istate_t istate; |
int rc; |
|
printf("arch_dump_regs...\n"); |
142,5 → 152,22 |
istate.ds, istate.es, istate.fs, istate.gs); |
} |
|
void arch_set_singlestep(dthread_t *dt, int enable) |
{ |
static istate_t istate; |
int rc; |
|
rc = udebug_regs_read(app_phone, dt->hash, &istate); |
if (rc < 0) { printf("regs read failed\n"); return; } |
|
if (enable) istate.eflags |= 0x0100; /* trap flag */ |
else istate.eflags &= ~0x0100; /* trap flag */ |
|
rc = udebug_regs_write(app_phone, dt->hash, &istate); |
if (rc < 0) { printf("regs write failed\n"); return; } |
|
dt->arch.singlestep = enable; |
} |
|
/** @} |
*/ |