mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-27 07:00:30 +00:00
Move arp gdb into arpg, improve error and parsing + tests ##debug (#17658)
This commit is contained in:
parent
23c029522d
commit
413437e2b6
@ -2013,45 +2013,54 @@ static void show_drpi(RCore *core) {
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_reg_profile (RCore *core, char from, const char *str) { // "arp" and "drp"
|
||||
static void cmd_reg_profile(RCore *core, char from, const char *str) { // "arp" and "drp"
|
||||
const char *ptr;
|
||||
RReg *r = r_config_get_i (core->config, "cfg.debug")? core->dbg->reg: core->anal->reg;
|
||||
switch (str[1]) {
|
||||
case '\0': // "drp"
|
||||
case '\0': // "drp" "arp"
|
||||
if (r->reg_profile_str) {
|
||||
r_cons_println (r->reg_profile_str);
|
||||
} else {
|
||||
eprintf ("No register profile defined. Try 'dr.'\n");
|
||||
}
|
||||
break;
|
||||
case 'c': // drpc
|
||||
case 'c': // "drpc" "arpc"
|
||||
if (core->dbg->reg->reg_profile_cmt) {
|
||||
r_cons_println (r->reg_profile_cmt);
|
||||
}
|
||||
break;
|
||||
case ' ': // "drp "
|
||||
ptr = str + 2;
|
||||
while (isspace ((ut8)*ptr)) {
|
||||
ptr++;
|
||||
case 'g': // "drpg" "arpg"
|
||||
ptr = r_str_trim_head_ro (str + 2);
|
||||
if (!R_STR_ISEMPTY (ptr)) {
|
||||
char *r2profile = r_reg_parse_gdb_profile (ptr);
|
||||
if (r2profile) {
|
||||
r_cons_println (r2profile);
|
||||
core->num->value = 0;
|
||||
free (r2profile);
|
||||
} else {
|
||||
core->num->value = 1;
|
||||
eprintf ("Warning: Cannot parse gdb profile.\n");
|
||||
}
|
||||
} else {
|
||||
eprintf ("Usage: arpg [gdb-reg-profile]\n");
|
||||
}
|
||||
if (r_str_startswith (ptr, "gdb ")) {
|
||||
r_reg_parse_gdb_profile (ptr + 4);
|
||||
break;
|
||||
}
|
||||
r_reg_set_profile (r, str + 2);
|
||||
r_debug_plugin_set_reg_profile (core->dbg, str + 2);
|
||||
break;
|
||||
case ' ': // "drp " "arp "
|
||||
ptr = r_str_trim_head_ro (str + 2);
|
||||
r_reg_set_profile (r, ptr);
|
||||
r_debug_plugin_set_reg_profile (core->dbg, ptr);
|
||||
break;
|
||||
case '.': { // "drp."
|
||||
RRegSet *rs = r_reg_regset_get (r, R_REG_TYPE_GPR);
|
||||
if (rs) {
|
||||
eprintf ("size = %d\n", rs->arena->size);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'i': // "drpi"
|
||||
case 'i': // "drpi" "arpi"
|
||||
show_drpi (core);
|
||||
break;
|
||||
case 's': // "drps"
|
||||
case 's': // "drps" "arps"
|
||||
if (str[2] == ' ') {
|
||||
ut64 n = r_num_math (core->num, str+2);
|
||||
// TODO: move this thing into the r_reg API
|
||||
@ -2079,7 +2088,7 @@ static void cmd_reg_profile (RCore *core, char from, const char *str) { // "arp"
|
||||
} else eprintf ("Cannot find GPR register arena.\n");
|
||||
}
|
||||
break;
|
||||
case 'j': // "drpj"
|
||||
case 'j': // "drpj" "arpj"
|
||||
{
|
||||
// "drpj" .. dup from "arpj"
|
||||
RListIter *iter;
|
||||
@ -2118,10 +2127,10 @@ static void cmd_reg_profile (RCore *core, char from, const char *str) { // "arp"
|
||||
pj_free (pj);
|
||||
}
|
||||
break;
|
||||
case '?': // "drp?"
|
||||
case '?': // "drp?" "arp?"
|
||||
default:
|
||||
{
|
||||
const char *from_a[] = { "arp", "arpi", "arp.", "arpj", "arps" };
|
||||
const char *from_a[] = { "arp", "arpi", "arpg", "arp.", "arpj", "arps" };
|
||||
// TODO #7967 help refactor
|
||||
const char **help_msg = help_msg_drp;
|
||||
if (from == 'a') {
|
||||
|
@ -887,7 +887,7 @@ static const char *radare_argv[] = {
|
||||
"ao?", "ao", "aoj", "aoe", "aor", "aos", "aom", "aod", "aoda", "aoc", "ao*",
|
||||
"aO", "ap",
|
||||
"ar?", "ar", "ar0", "ara?", "ara", "ara+", "ara-", "aras", "arA", "arC", "arr", "arrj", "ar=",
|
||||
"arb", "arc", "ard", "arn", "aro", "arp?", "arp", "arpi", "arp.", "arpj", "arps",
|
||||
"arb", "arc", "ard", "arn", "aro", "arp?", "arp", "arpi", "arpg", "arp.", "arpj", "arps",
|
||||
"ars", "art", "arw",
|
||||
"as?", "as", "asc", "asca", "asf", "asj", "asl", "ask",
|
||||
"av?", "av", "avj", "av*", "avr", "avra", "avraj", "avrr", "avrD",
|
||||
@ -2352,7 +2352,7 @@ static void __init_autocomplete_default (RCore* core) {
|
||||
};
|
||||
const char *files[] = {
|
||||
".", "..", ".*", "/F", "/m", "!", "!!", "#!c", "#!v", "#!cpipe", "#!vala",
|
||||
"#!rust", "#!zig", "#!pipe", "#!python", "aeli", "arp", "dmd", "drp", "o",
|
||||
"#!rust", "#!zig", "#!pipe", "#!python", "aeli", "arp", "arpg", "dmd", "drp", "drpg", "o",
|
||||
"idp", "idpi", "L", "obf", "o+", "oc", "r2", "rabin2", "rasm2", "rahash2", "rax2",
|
||||
"rafind2", "cd", "on", "op", "wf", "rm", "wF", "wp", "Sd", "Sl", "to", "pm",
|
||||
"/m", "zos", "zfd", "zfs", "zfz", "cat", "wta", "wtf", "wxf", "dml", "vi",
|
||||
|
@ -146,7 +146,7 @@ R_API bool r_reg_set_name(RReg *reg, int role, const char *name);
|
||||
R_API bool r_reg_set_profile_string(RReg *reg, const char *profile);
|
||||
R_API char* r_reg_profile_to_cc(RReg *reg);
|
||||
R_API bool r_reg_set_profile(RReg *reg, const char *profile);
|
||||
R_API bool r_reg_parse_gdb_profile(const char *profile);
|
||||
R_API char *r_reg_parse_gdb_profile(const char *profile);
|
||||
R_API bool r_reg_is_readonly(RReg *reg, RRegItem *item);
|
||||
|
||||
R_API RRegSet *r_reg_regset_get(RReg *r, int type);
|
||||
|
@ -243,6 +243,7 @@ R_API bool r_reg_set_profile_string(RReg *reg, const char *str) {
|
||||
}
|
||||
|
||||
R_API bool r_reg_set_profile(RReg *reg, const char *profile) {
|
||||
r_return_val_if_fail (reg && profile, NULL);
|
||||
char *base, *file;
|
||||
char *str = r_file_slurp (profile, NULL);
|
||||
if (!str) {
|
||||
@ -262,23 +263,25 @@ R_API bool r_reg_set_profile(RReg *reg, const char *profile) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool gdb_to_r2_profile(char *gdb) {
|
||||
char *ptr = gdb, *ptr1, *gptr, *gptr1;
|
||||
static char *gdb_to_r2_profile(const char *gdb) {
|
||||
r_return_val_if_fail (gdb, NULL);
|
||||
RStrBuf *sb = r_strbuf_new ("");
|
||||
if (!sb) {
|
||||
return NULL;
|
||||
}
|
||||
char *ptr1, *gptr, *gptr1;
|
||||
char name[16], groups[128], type[16];
|
||||
const int all = 1, gpr = 2, save = 4, restore = 8, float_ = 16,
|
||||
sse = 32, vector = 64, system = 128, mmx = 256;
|
||||
int number, rel, offset, size, type_bits, ret;
|
||||
// Every line is -
|
||||
// Name Number Rel Offset Size Type Groups
|
||||
char *ptr = r_str_trim_head_ro (gdb);
|
||||
|
||||
// Skip whitespace at beginning of line and empty lines
|
||||
while (isspace ((ut8)*ptr)) {
|
||||
ptr++;
|
||||
}
|
||||
// It's possible someone includes the heading line too. Skip it
|
||||
if (r_str_startswith (ptr, "Name")) {
|
||||
if (!(ptr = strchr (ptr, '\n'))) {
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
@ -297,9 +300,9 @@ static bool gdb_to_r2_profile(char *gdb) {
|
||||
&offset, &size, type, groups);
|
||||
// Groups is optional, others not
|
||||
if (ret < 6) {
|
||||
eprintf ("Could not parse line: %s\n", ptr);
|
||||
if (!ptr1) {
|
||||
return true;
|
||||
if (*ptr != '*') {
|
||||
eprintf ("Could not parse line: %s\n", ptr);
|
||||
return false;
|
||||
}
|
||||
ptr = ptr1 + 1;
|
||||
continue;
|
||||
@ -307,7 +310,7 @@ static bool gdb_to_r2_profile(char *gdb) {
|
||||
// If name is '', then skip
|
||||
if (r_str_startswith (name, "''")) {
|
||||
if (!ptr1) {
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
ptr = ptr1 + 1;
|
||||
continue;
|
||||
@ -315,7 +318,7 @@ static bool gdb_to_r2_profile(char *gdb) {
|
||||
// If size is 0, skip
|
||||
if (size == 0) {
|
||||
if (!ptr1) {
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
ptr = ptr1 + 1;
|
||||
continue;
|
||||
@ -354,7 +357,7 @@ static bool gdb_to_r2_profile(char *gdb) {
|
||||
// If type is not defined, skip
|
||||
if (!*type) {
|
||||
if (!ptr1) {
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
ptr = ptr1 + 1;
|
||||
continue;
|
||||
@ -364,38 +367,40 @@ static bool gdb_to_r2_profile(char *gdb) {
|
||||
type_bits |= gpr;
|
||||
}
|
||||
// Print line
|
||||
eprintf ("%s\t%s\t.%d\t%d\t0\n",
|
||||
r_strbuf_appendf (sb, "%s\t%s\t.%d\t%d\t0\n",
|
||||
// Ref: Comment above about more register type mappings
|
||||
((type_bits & mmx) || (type_bits & float_) || (type_bits & sse)) ? "fpu" : "gpr",
|
||||
name, size * 8, offset);
|
||||
// Go to next line
|
||||
if (!ptr1) {
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
ptr = ptr1 + 1;
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
return r_strbuf_drain (sb);
|
||||
}
|
||||
|
||||
R_API bool r_reg_parse_gdb_profile(const char *profile_file) {
|
||||
R_API char *r_reg_parse_gdb_profile(const char *profile_file) {
|
||||
char *base, *str = NULL;
|
||||
if (!(str = r_file_slurp (profile_file, NULL))) {
|
||||
if ((base = r_sys_getenv (R_LIB_ENV))) {
|
||||
char *file = r_str_append (base, profile_file);
|
||||
char *base = r_sys_getenv (R_LIB_ENV);
|
||||
if (base) {
|
||||
char *file = r_str_appendf (base, R_SYS_DIR "%s", profile_file);
|
||||
if (file) {
|
||||
str = r_file_slurp (file, NULL);
|
||||
free (file);
|
||||
}
|
||||
free (base);
|
||||
}
|
||||
}
|
||||
if (!str) {
|
||||
eprintf ("r_reg_parse_gdb_profile: Cannot find '%s'\n", profile_file);
|
||||
return false;
|
||||
if (str) {
|
||||
char *ret = gdb_to_r2_profile (str);
|
||||
free (str);
|
||||
return ret;
|
||||
}
|
||||
bool ret = gdb_to_r2_profile (str);
|
||||
free (str);
|
||||
return ret;
|
||||
eprintf ("r_reg_parse_gdb_profile: Cannot find '%s'\n", profile_file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API char *r_reg_profile_to_cc(RReg *reg) {
|
||||
|
17
test/db/cmd/cmd_arp
Normal file
17
test/db/cmd/cmd_arp
Normal file
@ -0,0 +1,17 @@
|
||||
NAME=arpg
|
||||
FILE=-
|
||||
CMDS=<<EOF
|
||||
arpg scripts/gdb-reg-profile.txt > $a
|
||||
?v $?
|
||||
$a~?
|
||||
arpg scripts/gdb-reg-profile-invalid.txt > $b
|
||||
?v $?
|
||||
$b~?
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
0x0
|
||||
98
|
||||
0x1
|
||||
0
|
||||
EOF
|
||||
RUN
|
36
test/scripts/gdb-reg-profile-invalid.txt
Normal file
36
test/scripts/gdb-reg-profile-invalid.txt
Normal file
@ -0,0 +1,36 @@
|
||||
Name Nr Offset Size Type
|
||||
0 0 4 uint32_t
|
||||
1 4 4 uint32_t
|
||||
2 8 4 uint32_t
|
||||
3 12 4 uint32_t
|
||||
4 16 4 uint32_t
|
||||
5 20 4 uint32_t
|
||||
r6 6 6 24 4 uint32_t
|
||||
r7 7 7 28 4 uint32_t
|
||||
r8 8 8 32 4 uint32_t
|
||||
r9 9 t32_t
|
||||
r10 10 1t32_t
|
||||
r11 11 1t32_t
|
||||
r12 12 1t32_t
|
||||
sp 13 1
|
||||
lr 14 1g
|
||||
pc 15 1
|
||||
'' 16 10_t
|
||||
'' 22 20_t
|
||||
'' 23 20_t
|
||||
'' 24 20_t
|
||||
cpsr 25 25 64 4 long
|
||||
'' 26 26 68 0 int0_t
|
||||
'' 27 27 68 0 int0_t
|
||||
'' 28 28 68 0 int0_t
|
||||
'' 29 29 68 0 int0_t
|
||||
'' 30 30 68 0 int0_t
|
||||
'' 31 31 68 0 int0_t
|
||||
'' 32 32 68 0 int0_t
|
||||
'' 33 33 68 0 int0_t
|
||||
'' 34 34 68 0 int0_t
|
||||
'' 35 35 68 0 int0_t
|
||||
'' 36 36 68 0 int0_t
|
||||
s14 105 14 384 4 float
|
||||
q15 138 47 696 16 neon_q
|
||||
*1: Register type's name NULL.
|
141
test/scripts/gdb-reg-profile.txt
Normal file
141
test/scripts/gdb-reg-profile.txt
Normal file
@ -0,0 +1,141 @@
|
||||
Name Nr Rel Offset Size Type
|
||||
r0 0 0 0 4 uint32_t
|
||||
r1 1 1 4 4 uint32_t
|
||||
r2 2 2 8 4 uint32_t
|
||||
r3 3 3 12 4 uint32_t
|
||||
r4 4 4 16 4 uint32_t
|
||||
r5 5 5 20 4 uint32_t
|
||||
r6 6 6 24 4 uint32_t
|
||||
r7 7 7 28 4 uint32_t
|
||||
r8 8 8 32 4 uint32_t
|
||||
r9 9 9 36 4 uint32_t
|
||||
r10 10 10 40 4 uint32_t
|
||||
r11 11 11 44 4 uint32_t
|
||||
r12 12 12 48 4 uint32_t
|
||||
sp 13 13 52 4 *1
|
||||
lr 14 14 56 4 long
|
||||
pc 15 15 60 4 *1
|
||||
'' 16 16 64 0 int0_t
|
||||
'' 17 17 64 0 int0_t
|
||||
'' 18 18 64 0 int0_t
|
||||
'' 19 19 64 0 int0_t
|
||||
'' 20 20 64 0 int0_t
|
||||
'' 21 21 64 0 int0_t
|
||||
'' 22 22 64 0 int0_t
|
||||
'' 23 23 64 0 int0_t
|
||||
'' 24 24 64 0 int0_t
|
||||
cpsr 25 25 64 4 long
|
||||
'' 26 26 68 0 int0_t
|
||||
'' 27 27 68 0 int0_t
|
||||
'' 28 28 68 0 int0_t
|
||||
'' 29 29 68 0 int0_t
|
||||
'' 30 30 68 0 int0_t
|
||||
'' 31 31 68 0 int0_t
|
||||
'' 32 32 68 0 int0_t
|
||||
'' 33 33 68 0 int0_t
|
||||
'' 34 34 68 0 int0_t
|
||||
'' 35 35 68 0 int0_t
|
||||
'' 36 36 68 0 int0_t
|
||||
'' 37 37 68 0 int0_t
|
||||
'' 38 38 68 0 int0_t
|
||||
'' 39 39 68 0 int0_t
|
||||
'' 40 40 68 0 int0_t
|
||||
'' 41 41 68 0 int0_t
|
||||
'' 42 42 68 0 int0_t
|
||||
'' 43 43 68 0 int0_t
|
||||
'' 44 44 68 0 int0_t
|
||||
'' 45 45 68 0 int0_t
|
||||
'' 46 46 68 0 int0_t
|
||||
'' 47 47 68 0 int0_t
|
||||
'' 48 48 68 0 int0_t
|
||||
'' 49 49 68 0 int0_t
|
||||
'' 50 50 68 0 int0_t
|
||||
'' 51 51 68 0 int0_t
|
||||
'' 52 52 68 0 int0_t
|
||||
'' 53 53 68 0 int0_t
|
||||
'' 54 54 68 0 int0_t
|
||||
'' 55 55 68 0 int0_t
|
||||
'' 56 56 68 0 int0_t
|
||||
'' 57 57 68 0 int0_t
|
||||
d0 58 58 68 8 neon_d
|
||||
d1 59 59 76 8 neon_d
|
||||
d2 60 60 84 8 neon_d
|
||||
d3 61 61 92 8 neon_d
|
||||
d4 62 62 100 8 neon_d
|
||||
d5 63 63 108 8 neon_d
|
||||
d6 64 64 116 8 neon_d
|
||||
d7 65 65 124 8 neon_d
|
||||
d8 66 66 132 8 neon_d
|
||||
d9 67 67 140 8 neon_d
|
||||
d10 68 68 148 8 neon_d
|
||||
d11 69 69 156 8 neon_d
|
||||
d12 70 70 164 8 neon_d
|
||||
d13 71 71 172 8 neon_d
|
||||
d14 72 72 180 8 neon_d
|
||||
d15 73 73 188 8 neon_d
|
||||
d16 74 74 196 8 neon_d
|
||||
d17 75 75 204 8 neon_d
|
||||
d18 76 76 212 8 neon_d
|
||||
d19 77 77 220 8 neon_d
|
||||
d20 78 78 228 8 neon_d
|
||||
d21 79 79 236 8 neon_d
|
||||
d22 80 80 244 8 neon_d
|
||||
d23 81 81 252 8 neon_d
|
||||
d24 82 82 260 8 neon_d
|
||||
d25 83 83 268 8 neon_d
|
||||
d26 84 84 276 8 neon_d
|
||||
d27 85 85 284 8 neon_d
|
||||
d28 86 86 292 8 neon_d
|
||||
d29 87 87 300 8 neon_d
|
||||
d30 88 88 308 8 neon_d
|
||||
d31 89 89 316 8 neon_d
|
||||
fpscr 90 90 324 4 long
|
||||
s0 91 0 328 4 float
|
||||
s1 92 1 332 4 float
|
||||
s2 93 2 336 4 float
|
||||
s3 94 3 340 4 float
|
||||
s4 95 4 344 4 float
|
||||
s5 96 5 348 4 float
|
||||
s6 97 6 352 4 float
|
||||
s7 98 7 356 4 float
|
||||
s8 99 8 360 4 float
|
||||
s9 100 9 364 4 float
|
||||
s10 101 10 368 4 float
|
||||
s11 102 11 372 4 float
|
||||
s12 103 12 376 4 float
|
||||
s13 104 13 380 4 float
|
||||
s14 105 14 384 4 float
|
||||
s15 106 15 388 4 float
|
||||
s16 107 16 392 4 float
|
||||
s17 108 17 396 4 float
|
||||
s18 109 18 400 4 float
|
||||
s19 110 19 404 4 float
|
||||
s20 111 20 408 4 float
|
||||
s21 112 21 412 4 float
|
||||
s22 113 22 416 4 float
|
||||
s23 114 23 420 4 float
|
||||
s24 115 24 424 4 float
|
||||
s25 116 25 428 4 float
|
||||
s26 117 26 432 4 float
|
||||
s27 118 27 436 4 float
|
||||
s28 119 28 440 4 float
|
||||
s29 120 29 444 4 float
|
||||
s30 121 30 448 4 float
|
||||
s31 122 31 452 4 float
|
||||
q0 123 32 456 16 neon_q
|
||||
q1 124 33 472 16 neon_q
|
||||
q2 125 34 488 16 neon_q
|
||||
q3 126 35 504 16 neon_q
|
||||
q4 127 36 520 16 neon_q
|
||||
q5 128 37 536 16 neon_q
|
||||
q6 129 38 552 16 neon_q
|
||||
q7 130 39 568 16 neon_q
|
||||
q8 131 40 584 16 neon_q
|
||||
q9 132 41 600 16 neon_q
|
||||
q10 133 42 616 16 neon_q
|
||||
q11 134 43 632 16 neon_q
|
||||
q12 135 44 648 16 neon_q
|
||||
q13 136 45 664 16 neon_q
|
||||
q14 137 46 680 16 neon_q
|
||||
q15 138 47 696 16 neon_q
|
||||
*1: Register type's name NULL.
|
Loading…
Reference in New Issue
Block a user