Automatically set dbg.bpsize to fix bps in arm64

This commit is contained in:
pancake 2017-12-03 18:57:42 +01:00
parent 6b539545f7
commit d25ae603c7
4 changed files with 29 additions and 9 deletions

View File

@ -58,7 +58,7 @@ R_API int r_bp_get_bytes(RBreakpoint *bp, ut8 *buf, int len, int endian, int idx
if (bp->cur) {
// find matching size breakpoint
repeat:
for (i=0; i< bp->cur->nbps; i++) {
for (i = 0; i < bp->cur->nbps; i++) {
b = &bp->cur->bps[i];
if (bp->cur->bps[i].bits) {
if (bp->bits != bp->cur->bps[i].bits) {
@ -347,3 +347,18 @@ R_API int r_bp_del_index(RBreakpoint *bp, int idx) {
}
return false;
}
R_API int r_bp_size(RBreakpoint *bp) {
RBreakpointArch *bpa;
int i, bpsize = 8;
for (i = 0; bp->cur->bps[i].bytes; i++) {
bpa = &bp->cur->bps[i];
if (bpa->bits != bp->bits) {
continue;
}
if (bpa->length < bpsize) {
bpsize = bpa->length;
}
}
return bpsize;
}

View File

@ -1,13 +1,11 @@
/* radare - LGPL - Copyright 2009-2016 - pancake */
/* radare - LGPL - Copyright 2009-2017 - pancake */
#include <r_bp.h>
#include <r_lib.h>
static struct r_bp_arch_t r_bp_plugin_arm_bps[] = {
{ 64, 4, 0, (const ut8*)"\x00\x00\x20\xd4" }, // le - arm64 brk0
{ 64, 1, 0, (const ut8*)"\x00\x00\x20\xd4" }, // le - arm64
{ 64, 4, 1, (const ut8*)"\xd4\x20\x00\x00" }, // be - arm64
{ 64, 1, 1, (const ut8*)"\xd4\x20\x00\x00" }, // be - arm64
//{ 64, 1, 0, (const ut8*)"\xfe\xde\xff\xe7" }, // le - arm64 // hacky fix
// { 32, 1, 0, (const ut8*)"\xff\xff\xff\xff" }, // le - linux only? (undefined instruction)
// { 32, 1, 1, (const ut8*)"\xff\xff\xff\xff" }, // be - linux only? (undefined instruction)

View File

@ -598,6 +598,7 @@ static int cb_asmbits(void *user, void *data) {
__setsegoff (core->config, asmarch, core->anal->bits);
if (core->dbg) {
r_bp_use (core->dbg->bp, asmarch, core->anal->bits);
r_config_set_i (core->config, "dbg.bpsize", r_bp_size (core->dbg->bp));
}
}
/* set pcalign */
@ -865,7 +866,9 @@ static int cb_cfglog(void *user, void *data) {
static int cb_cfgdebug(void *user, void *data) {
RCore *core = (RCore*) user;
RConfigNode *node = (RConfigNode*) data;
if (!core) return false;
if (!core) {
return false;
}
if (core->io) {
core->io->debug = node->i_value;
}

View File

@ -3654,9 +3654,13 @@ static bool cmd_dcu (RCore *core, const char *input) {
ut64 addr = from;
eprintf ("Continue until 0x%08"PFMT64x" using %d bpsize\n", addr, core->dbg->bpsize);
r_reg_arena_swap (core->dbg->reg, true);
r_bp_add_sw (core->dbg->bp, addr, core->dbg->bpsize, R_BP_PROT_EXEC);
r_debug_continue (core->dbg);
r_bp_del (core->dbg->bp, addr);
if (r_bp_add_sw (core->dbg->bp, addr, core->dbg->bpsize, R_BP_PROT_EXEC)) {
r_debug_continue (core->dbg);
r_bp_del (core->dbg->bp, addr);
} else {
eprintf ("Cannot set breakpoint of size %d at 0x%08"PFMT64x"\n",
core->dbg->bpsize, addr);
}
}
return true;
}
@ -3768,7 +3772,7 @@ static int cmd_debug_continue (RCore *core, const char *input) {
r_cons_break_pop ();
return 1;
}
case 'u':
case 'u': // "dcu"
cmd_dcu (core, input);
break;
case ' ':