From d25ae603c701953a9502bbfda94a68712232dce0 Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 3 Dec 2017 18:57:42 +0100 Subject: [PATCH] Automatically set dbg.bpsize to fix bps in arm64 --- libr/bp/bp.c | 17 ++++++++++++++++- libr/bp/p/bp_arm.c | 4 +--- libr/core/cconfig.c | 5 ++++- libr/core/cmd_debug.c | 12 ++++++++---- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/libr/bp/bp.c b/libr/bp/bp.c index 49af582859..878860488f 100644 --- a/libr/bp/bp.c +++ b/libr/bp/bp.c @@ -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; +} diff --git a/libr/bp/p/bp_arm.c b/libr/bp/p/bp_arm.c index 8cb942cb07..2b5f775c6c 100644 --- a/libr/bp/p/bp_arm.c +++ b/libr/bp/p/bp_arm.c @@ -1,13 +1,11 @@ -/* radare - LGPL - Copyright 2009-2016 - pancake */ +/* radare - LGPL - Copyright 2009-2017 - pancake */ #include #include 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) diff --git a/libr/core/cconfig.c b/libr/core/cconfig.c index 65b3b9cacf..fb93da34f2 100644 --- a/libr/core/cconfig.c +++ b/libr/core/cconfig.c @@ -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; } diff --git a/libr/core/cmd_debug.c b/libr/core/cmd_debug.c index 15a0cc6bb9..c888b0a25f 100644 --- a/libr/core/cmd_debug.c +++ b/libr/core/cmd_debug.c @@ -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 ' ':