From 15b43564fdcefaa36ec42772a1bbc06a4da09232 Mon Sep 17 00:00:00 2001 From: pancake Date: Thu, 24 Nov 2016 23:25:49 +0100 Subject: [PATCH] Manipulate stack.delta and stack.size with Vppc[jk+-.] --- libr/core/cmd_debug.c | 9 +++--- libr/core/visual.c | 68 +++++++++++++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/libr/core/cmd_debug.c b/libr/core/cmd_debug.c index b080661306..8f75cc2651 100644 --- a/libr/core/cmd_debug.c +++ b/libr/core/cmd_debug.c @@ -1789,9 +1789,8 @@ static void cmd_debug_reg(RCore *core, const char *str) { char *string; const char *regname; *arg = 0; - string = r_str_chop (strdup (str+1)); - regname = r_reg_get_name (core->dbg->reg, - r_reg_get_name_idx (string)); + string = r_str_chop (strdup (str + 1)); + regname = r_reg_get_name (core->dbg->reg, r_reg_get_name_idx (string)); if (!regname) { regname = string; } @@ -1813,7 +1812,9 @@ static void cmd_debug_reg(RCore *core, const char *str) { r_cons_printf ("0x%08"PFMT64x"\n", r_reg_get_value (core->dbg->reg, r)); } - } else eprintf ("Unknown register '%s'\n", string); + } else { + eprintf ("Unknown register '%s'\n", string); + } free (string); // update flags here r_core_cmdf (core, ".dr*%d", bits); diff --git a/libr/core/visual.c b/libr/core/visual.c index 3c25f1d098..2fc4de06ff 100644 --- a/libr/core/visual.c +++ b/libr/core/visual.c @@ -946,6 +946,15 @@ static void cursor_nextrow(RCore *core, bool use_ocur) { p->cur += cols > 0 ? cols: 3; return; } + if (core->seltab == 0 && core->printidx == 2) { + int w = r_config_get_i (core->config, "hex.cols"); + if (w < 1) { + w = 16; + } + r_config_set_i (core->config, "stack.delta", + r_config_get_i (core->config, "stack.delta") - w); + return; + } if (p->row_offsets != NULL) { // FIXME: cache the current row @@ -986,6 +995,16 @@ static void cursor_prevrow(RCore *core, bool use_ocur) { } cursor_ocur (core, use_ocur); + if (core->seltab == 0 && core->printidx == 2) { + int w = r_config_get_i (core->config, "hex.cols"); + if (w < 1) { + w = 16; + } + r_config_set_i (core->config, "stack.delta", + r_config_get_i (core->config, "stack.delta") + w); + return; + } + if (p->row_offsets != NULL) { int delta, prev_sz; @@ -1873,15 +1892,22 @@ R_API int r_core_visual_cmd(RCore *core, int ch) { break; case '-': if (core->print->cur_enabled) { - if (core->print->ocur == -1) { - sprintf (buf, "wos 01 @ $$+%i!1",core->print->cur); + if (core->seltab == 0 && core->printidx == 2) { + int w = r_config_get_i (core->config, "hex.cols"); + r_config_set_i (core->config, "stack.size", + r_config_get_i (core->config, "stack.size") - w); + } else { - sprintf (buf, "wos 01 @ $$+%i!%i", core->print->cur < core->print->ocur - ? core->print->cur - : core->print->ocur, - R_ABS (core->print->ocur - core->print->cur) + 1); + if (core->print->ocur == -1) { + sprintf (buf, "wos 01 @ $$+%i!1",core->print->cur); + } else { + sprintf (buf, "wos 01 @ $$+%i!%i", core->print->cur < core->print->ocur + ? core->print->cur + : core->print->ocur, + R_ABS (core->print->ocur - core->print->cur) + 1); + } + r_core_cmd (core, buf, 0); } - r_core_cmd (core, buf, 0); } else { if (!autoblocksize) { r_core_block_size (core, core->blocksize-1); @@ -1890,15 +1916,22 @@ R_API int r_core_visual_cmd(RCore *core, int ch) { break; case '+': if (core->print->cur_enabled) { - if (core->print->ocur == -1) { - sprintf (buf, "woa 01 @ $$+%i!1", core->print->cur); + if (core->seltab == 0 && core->printidx == 2) { + int w = r_config_get_i (core->config, "hex.cols"); + r_config_set_i (core->config, "stack.size", + r_config_get_i (core->config, "stack.size") + w); + } else { - sprintf (buf, "woa 01 @ $$+%i!%i", core->print->cur < core->print->ocur - ? core->print->cur - : core->print->ocur, - R_ABS (core->print->ocur - core->print->cur) + 1); + if (core->print->ocur == -1) { + sprintf (buf, "woa 01 @ $$+%i!1", core->print->cur); + } else { + sprintf (buf, "woa 01 @ $$+%i!%i", core->print->cur < core->print->ocur + ? core->print->cur + : core->print->ocur, + R_ABS (core->print->ocur - core->print->cur) + 1); + } + r_core_cmd (core, buf, 0); } - r_core_cmd (core, buf, 0); } else { if (!autoblocksize) r_core_block_size (core, core->blocksize+1); @@ -1934,6 +1967,7 @@ R_API int r_core_visual_cmd(RCore *core, int ch) { case '.': r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); if (core->print->cur_enabled) { + r_config_set_i (core->config, "stack.delta", 0); r_core_seek (core, core->offset+core->print->cur, 1); core->print->cur = 0; } else { @@ -2397,11 +2431,13 @@ dodo: default: pxw = "px"; break; } } + const char sign = (delta < 0)? '+': '-'; + const int absdelta = R_ABS(delta); snprintf (debugstr, sizeof (debugstr), - "?0;f tmp;sr SP;%s %d@$$-%d;" + "?0;f tmp;sr SP;%s %d@$$%c%d;" "?1;%s;s-;" "?1;s tmp;f-tmp;pd $r", - pxa? "pxa": pxw, size, delta, + pxa? "pxa": pxw, size, sign, absdelta, ref? "drr": "dr="); } printfmt[2] = debugstr;