Fix #260 - "dr all" is broken

This commit is contained in:
pancake 2013-10-14 22:23:05 +02:00
parent 7af16bdd34
commit 47faadf31b
4 changed files with 70 additions and 56 deletions

View File

@ -524,7 +524,7 @@ static void cmd_debug_reg(RCore *core, const char *str) {
if (arg && size==0) { if (arg && size==0) {
*arg='\0'; *arg='\0';
size = atoi (arg); size = atoi (arg);
} else size = core->dbg->bits; } else size = bits;
type = r_reg_type_by_name (str+1); type = r_reg_type_by_name (str+1);
} }
if (type != R_REG_TYPE_LAST) { if (type != R_REG_TYPE_LAST) {

View File

@ -1,7 +1,8 @@
/* radare - LGPL - Copyright 2009-2013 - pancake */ /* radare - LGPL - Copyright 2009-2013 - pancake */
R_API void r_core_print_examine(RCore *core, const char *str) { R_API void r_core_print_examine(RCore *core, const char *str) {
char cmd[128]; char cmd[128], *p;
ut64 addr = core->offset;
int size = (core->anal->bits/4); int size = (core->anal->bits/4);
int count = atoi (str); int count = atoi (str);
if (count<1) count = 1; if (count<1) count = 1;
@ -16,31 +17,32 @@ Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
case 'w': size = 4; break; case 'w': size = 4; break;
case 'g': size = 8; break; case 'g': size = 8; break;
} }
#if 0 if ((p=strchr (str, ' ')))
#endif addr = r_num_math (core->num, p+1);
switch (*str) { switch (*str) {
case '?': case '?':
eprintf ( eprintf (
"Format is x/[num][format][size]\n" "Format is x/[num][format][size]\n"
"Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n" "Num specifies the number of format elements to display\n"
"Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n" "Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n"
" t(binary), f(float), a(address), i(instruction), c(char) and s(string),\n" " t(binary), f(float), a(address), i(instruction), c(char) and s(string),\n"
" T(OSType), A(floating point values in hex).\n" " T(OSType), A(floating point values in hex).\n"
"Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n"
); );
break; break;
case 's': case 's':
snprintf (cmd, sizeof (cmd), "psb %d", count*size); snprintf (cmd, sizeof (cmd), "psb %d @ 0x%"PFMT64x, count*size, addr);
r_core_cmd0 (core, cmd); r_core_cmd0 (core, cmd);
break; break;
case 'o': case 'o':
snprintf (cmd, sizeof (cmd), "pxo %d", count*size); snprintf (cmd, sizeof (cmd), "pxo %d @ 0x%"PFMT64x, count*size, addr);
r_core_cmd0 (core, cmd); r_core_cmd0 (core, cmd);
break; break;
case 'f': case 'f':
case 'A': // XXX (float in hex wtf) case 'A': // XXX (float in hex wtf)
{ {
int i, n = 3; int i, n = 3;
snprintf (cmd, sizeof (cmd), "pxo %d", count*size); snprintf (cmd, sizeof (cmd), "pxo %d @ 0x%"PFMT64x, count*size, addr);
strcpy (cmd, "pf "); strcpy (cmd, "pf ");
for (i=0;i<count && n<sizeof (cmd);i++) { for (i=0;i<count && n<sizeof (cmd);i++) {
@ -52,11 +54,11 @@ Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
break; break;
case 'a': case 'a':
case 'd': case 'd':
snprintf (cmd, sizeof (cmd), "pxw %d", count*size); snprintf (cmd, sizeof (cmd), "pxw %d @ 0x%"PFMT64x, count*size, addr);
r_core_cmd0 (core, cmd); r_core_cmd0 (core, cmd);
break; break;
case 'i': case 'i':
snprintf (cmd, sizeof (cmd), "pid %d", count); snprintf (cmd, sizeof (cmd), "pid %d @ 0x%"PFMT64x, count, addr);
r_core_cmd0 (core, cmd); r_core_cmd0 (core, cmd);
break; break;
} }

View File

@ -811,6 +811,7 @@ r_config_set (cfg, "asm.arch", R_SYS_ARCH);
r_config_set_cb (cfg, "scr.tee", "", config_teefile_callback); r_config_set_cb (cfg, "scr.tee", "", config_teefile_callback);
r_config_desc (cfg, "scr.tee", "Pipe console output to file if not empty"); r_config_desc (cfg, "scr.tee", "Pipe console output to file if not empty");
r_config_set_cb (cfg, "scr.prompt", "true", &config_scrprompt_callback); r_config_set_cb (cfg, "scr.prompt", "true", &config_scrprompt_callback);
r_config_desc (cfg, "scr.prompt", "Show/hide user prompt (used by r2 -q)");
r_config_set (cfg, "scr.pipecolor", "false"); r_config_set (cfg, "scr.pipecolor", "false");
r_config_desc (cfg, "scr.pipecolor", "enable colors when using pipes if true"); r_config_desc (cfg, "scr.pipecolor", "enable colors when using pipes if true");
#if __WINDOWS__ #if __WINDOWS__

View File

@ -30,16 +30,15 @@ R_API int r_debug_reg_sync(RDebug *dbg, int type, int write) {
} }
R_API int r_debug_reg_list(RDebug *dbg, int type, int size, int rad) { R_API int r_debug_reg_list(RDebug *dbg, int type, int size, int rad) {
ut64 diff; int i, from, to, cols, n = 0;
int cols, n = 0; const char *fmt, *fmt2;
RList *head; //struct list_head *pos, *head;
RListIter *iter; RListIter *iter;
RRegItem *item; RRegItem *item;
const char *fmt, *fmt2; RList *head;
ut64 diff;
if (!dbg || !dbg->reg) if (!dbg || !dbg->reg)
return R_FALSE; return R_FALSE;
head = r_reg_get_list (dbg->reg, type);
//if (dbg->h && dbg->h->bits & R_SYS_BITS_64) { //if (dbg->h && dbg->h->bits & R_SYS_BITS_64) {
if (dbg->bits & R_SYS_BITS_64) { if (dbg->bits & R_SYS_BITS_64) {
fmt = "%s = 0x%016"PFMT64x"%s"; fmt = "%s = 0x%016"PFMT64x"%s";
@ -52,49 +51,61 @@ R_API int r_debug_reg_list(RDebug *dbg, int type, int size, int rad) {
} }
if (rad=='j') if (rad=='j')
dbg->printf ("{"); dbg->printf ("{");
if (head) if (type == -1) {
r_list_foreach (head, iter, item) { from = 0;
ut64 value; to = R_REG_TYPE_LAST;
if (type != -1 && type != item->type) } else {
continue; from = type;
if (size != 0 && size != item->size) to = from +1;
continue; }
value = r_reg_get_value (dbg->reg, item); for (i=from; i<to; i++) {
diff = (ut64)r_reg_cmp (dbg->reg, item); head = r_reg_get_list (dbg->reg, i);
switch (rad) { if (!head) continue;
case 'j': r_list_foreach (head, iter, item) {
dbg->printf ("%s\"%s\":%"PFMT64d, ut64 value;
n?",":"",item->name, value); if (type != -1) {
break; if (type != item->type)
case 1: continue;
case '*': if (size != 0 && size != item->size)
dbg->printf ("f %s 1 0x%"PFMT64x"\n", item->name, value); continue;
break;
case 'd':
case 2:
if (diff) // TODO: DO NOT COLORIZE ALWAYS ..do debug knows about console?? use inverse colors
dbg->printf (Color_BWHITE); //INVERT); //Color_BWHITE);
if (item->flags) {
char *str = r_reg_get_bvalue (dbg->reg, item);
dbg->printf ("%s = %s%s", item->name, str, ((n+1)%cols)?" ":"\n");
free (str);
} else dbg->printf (fmt2, item->name, value, ((n+1)%cols)?" ":"\n");
if (diff) // TODO: use inverse colors
//dbg->printf (Color_INVERT_RESET); //Color_RESET);
dbg->printf (Color_RESET); //Color_RESET);
break;
case 3:
if (diff) {
char woot[32];
snprintf (woot, sizeof (woot), " was 0x%08"PFMT64x"\n", diff);
dbg->printf (fmt, item->name, value, woot);
} }
break; value = r_reg_get_value (dbg->reg, item);
default: diff = (ut64)r_reg_cmp (dbg->reg, item);
dbg->printf (fmt, item->name, value, "\n"); switch (rad) {
break; case 'j':
dbg->printf ("%s\"%s\":%"PFMT64d,
n?",":"",item->name, value);
break;
case 1:
case '*':
dbg->printf ("f %s 1 0x%"PFMT64x"\n", item->name, value);
break;
case 'd':
case 2:
if (diff) // TODO: DO NOT COLORIZE ALWAYS ..do debug knows about console?? use inverse colors
dbg->printf (Color_BWHITE); //INVERT); //Color_BWHITE);
if (item->flags) {
char *str = r_reg_get_bvalue (dbg->reg, item);
dbg->printf ("%s = %s%s", item->name, str, ((n+1)%cols)?" ":"\n");
free (str);
} else dbg->printf (fmt2, item->name, value, ((n+1)%cols)?" ":"\n");
if (diff) // TODO: use inverse colors
//dbg->printf (Color_INVERT_RESET); //Color_RESET);
dbg->printf (Color_RESET); //Color_RESET);
break;
case 3:
if (diff) {
char woot[32];
snprintf (woot, sizeof (woot), " was 0x%08"PFMT64x"\n", diff);
dbg->printf (fmt, item->name, value, woot);
}
break;
default:
dbg->printf (fmt, item->name, value, "\n");
break;
}
n++;
} }
n++;
} }
if (rad=='j') dbg->printf ("}\n"); if (rad=='j') dbg->printf ("}\n");
else if (n>0 && rad==2 && ((n%cols))) else if (n>0 && rad==2 && ((n%cols)))