From b7396fffa570692eef10e6e11be9bdb05d556f48 Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 8 Feb 2017 12:14:52 +0100 Subject: [PATCH] Enhance Vx - visual xrefs browser, with more highlight and less glitches --- libr/core/cmd_debug.c | 72 +++++++++++++++++++++---------------------- libr/core/visual.c | 64 ++++++++++++++++++++++---------------- 2 files changed, 73 insertions(+), 63 deletions(-) diff --git a/libr/core/cmd_debug.c b/libr/core/cmd_debug.c index 83ad004c2f..a1e151afc9 100644 --- a/libr/core/cmd_debug.c +++ b/libr/core/cmd_debug.c @@ -2437,52 +2437,52 @@ static void r_core_cmd_bp(RCore *core, const char *input) { break; case 'h': switch (input[2]) { - case 0: - r_bp_plugin_list (core->dbg->bp); - break; - case ' ': - if (!r_bp_use (core->dbg->bp, input + 3, core->anal->bits)) - eprintf ("Invalid name: '%s'.\n", input + 3); - break; - case '?': - default: - eprintf ("Usage: dh [plugin-name] # select a debug handler plugin\n"); - break; + case 0: + r_bp_plugin_list (core->dbg->bp); + break; + case ' ': + if (!r_bp_use (core->dbg->bp, input + 3, core->anal->bits)) + eprintf ("Invalid name: '%s'.\n", input + 3); + break; + case '?': + default: + eprintf ("Usage: dh [plugin-name] # select a debug handler plugin\n"); + break; } break; - case ' ': - for (p = input + 1; *p == ' '; p++); - if (*p == '-') { - r_bp_del (core->dbg->bp, r_num_math (core->num, p + 1)); - } else { - addr = r_num_math (core->num, input + 2); - if (validAddress (core, addr)) { - bpi = r_debug_bp_add (core->dbg, addr, hwbp, NULL, 0); - if (bpi) { - free (bpi->name); - if (!strcmp (input + 2, "$$")) { - char *newname = NULL; - RFlagItem *f = r_flag_get_i2 (core->flags, addr); + case ' ': // "db" + for (p = input + 1; *p == ' '; p++); + if (*p == '-') { + r_bp_del (core->dbg->bp, r_num_math (core->num, p + 1)); + } else { + addr = r_num_math (core->num, input + 2); + if (validAddress (core, addr)) { + bpi = r_debug_bp_add (core->dbg, addr, hwbp, NULL, 0); + if (bpi) { + free (bpi->name); + if (!strcmp (input + 2, "$$")) { + char *newname = NULL; + RFlagItem *f = r_flag_get_i2 (core->flags, addr); - if (f) { - if (addr > f->offset) { - newname = r_str_newf ("%s+0x%" PFMT64x, f->name, addr - f->offset); - } else { - newname = strdup (f->name); - } + if (f) { + if (addr > f->offset) { + newname = r_str_newf ("%s+0x%" PFMT64x, f->name, addr - f->offset); + } else { + newname = strdup (f->name); } - bpi->name = newname; - } else { - bpi->name = strdup (input + 2); } + bpi->name = newname; } else { - eprintf ("Cannot set breakpoint at '%s'\n", input + 2); + bpi->name = strdup (input + 2); } } else { - eprintf ("Cannot place a breakpoint on 0x%08"PFMT64x" unmapped memory. See dbg.bpinmaps\n", addr); + eprintf ("Cannot set breakpoint at '%s'\n", input + 2); } + } else { + eprintf ("Cannot place a breakpoint on 0x%08"PFMT64x" unmapped memory. See dbg.bpinmaps\n", addr); } - break; + } + break; case 'i': switch (input[2]) { case 0: // "dbi" diff --git a/libr/core/visual.c b/libr/core/visual.c index df0c904b69..a40689d353 100644 --- a/libr/core/visual.c +++ b/libr/core/visual.c @@ -734,34 +734,22 @@ repeat: r_cons_any_key (NULL); r_cons_clear00 (); } else { + int maxcount = 9; int rows, cols = r_cons_get_size (&rows); idx = 0; count = 0; + char *dis = NULL; rows -= 3; - // int maxcount = rows > 20 ? 9: 4; - int maxcount = cols < 90 ? 4: 9; - if (cols > 90) { - r_list_foreach (xrefs, iter, refi) { - if (idx == skip) { - char *dis = r_core_cmd_strf (core, "pd $r-10 @ 0x%08"PFMT64x, refi->addr); - char *d = r_str_ansi_crop (dis, 0, 0, cols - 50, rows - 3); - r_cons_printf ("%s", d); - r_cons_column (50); - free (d); - free (dis); - r_cons_gotoxy (1, 1); - r_cons_printf ("[GOTO XREF]> 0x%08"PFMT64x"\n", addr); - break; - } - idx ++; - } - } idx = 0; + ut64 curat = UT64_MAX; r_list_foreach (xrefs, iter, refi) { if (idx - skip > maxcount) { - r_cons_printf ("...\n"); + r_cons_printf ("..."); break; } + if (!iter->n && idx < skip) { + skip = idx; + } if (idx >= skip) { if (count > maxcount) { strcpy (cstr, "?"); @@ -787,21 +775,43 @@ repeat: name); free (name); if (idx == skip) { - if (cols <= 90) { - char *dis = r_core_cmd_strf (core, "pd $r-5 @ 0x%08"PFMT64x, refi->addr); - char *d = r_str_ansi_crop (dis, 0, 0, cols, rows - 5); - r_cons_printf ("%s", d); - free (d); - free (dis); - } + free (dis); + curat = refi->addr; + // TODO: show disasm with context. not seek addr + // dis = r_core_cmd_strf (core, "pd $r-4 @ 0x%08"PFMT64x, refi->addr); + dis = r_core_cmd_strf (core, "pd $r-4 @ 0x%08"PFMT64x, refi->addr - 32); } if (++count >= rows) { - r_cons_printf ("...\n"); + r_cons_printf ("..."); break; } } idx++; } + if (dis) { + if (count < rows) { + r_cons_newline (); + } + int i = count; + for (; i < 10; i++) { + r_cons_newline (); + } + /* prepare highlight */ + char *cmd = strdup (r_config_get (core->config, "scr.highlight")); + char *ats = r_str_newf ("%"PFMT64x, curat); + r_config_set (core->config, "scr.highlight", ats); + /* print disasm */ + char *d = r_str_ansi_crop (dis, 0, 0, cols, rows - 9); + r_cons_printf ("%s", d); + free (d); + /* flush and restore highlight */ + r_cons_flush (); + r_config_set (core->config, "scr.highlight", cmd); + free (ats); + free (cmd); + free (dis); + dis = NULL; + } } r_config_set_i (core->config, "asm.bytes", asm_bytes); } else {