diff --git a/libr/anal/cc.c b/libr/anal/cc.c index ccad64640e..93098d1629 100644 --- a/libr/anal/cc.c +++ b/libr/anal/cc.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2011-2019 - pancake, Oddcoder */ +/* radare - LGPL - Copyright 2011-2020 - pancake, Oddcoder */ /* Universal calling convention implementation based on sdb */ @@ -6,7 +6,7 @@ #define DB anal->sdb_cc R_API void r_anal_cc_del(RAnal *anal, const char *name) { - int i; + size_t i; sdb_unset (DB, sdb_fmt ("%s", name), 0); sdb_unset (DB, sdb_fmt ("cc.%s.ret", name), 0); sdb_unset (DB, sdb_fmt ("cc.%s.argn", name), 0); diff --git a/libr/anal/dwarf_process.c b/libr/anal/dwarf_process.c index 9aa2931be2..94e745cc89 100644 --- a/libr/anal/dwarf_process.c +++ b/libr/anal/dwarf_process.c @@ -57,16 +57,6 @@ static void variable_free(Variable *var) { free (var); } -static inline bool is_parsable_tag(ut64 tag_code) { - return (tag_code == DW_TAG_structure_type || - tag_code == DW_TAG_enumeration_type || - tag_code == DW_TAG_class_type || - tag_code == DW_TAG_subprogram || - tag_code == DW_TAG_union_type || - tag_code == DW_TAG_base_type || - tag_code == DW_TAG_typedef); -} - /* return -1 if attr isn't found */ static inline st32 find_attr_idx(const RBinDwarfDie *die, st32 attr_name) { st32 i; diff --git a/libr/core/cmd_anal.c b/libr/core/cmd_anal.c index 8963883a6c..aedf3a3fec 100644 --- a/libr/core/cmd_anal.c +++ b/libr/core/cmd_anal.c @@ -654,6 +654,7 @@ static const char *help_msg_ar[] = { "ar?", " ", "Show register value", "arb", " ", "Display hexdump of the given arena", "arc", " ", "Conditional flag registers", + "arcc", "", "Show calling convention defined from the register profile", "ard", " ", "Show only different registers", "arn", " ", "Get regname for pc,sp,bp,a0-3,zf,cf,of,sg", "aro", "", "Show old (previous) register values", @@ -4357,7 +4358,13 @@ void cmd_anal_reg(RCore *core, const char *str) { } break; case 'c': // "arc" // TODO: set flag values with drc zf=1 - { + if (str[1] == 'c') { // "arcc" + char *s = r_reg_profile_to_cc (core->anal->reg); + if (s) { + r_cons_printf ("%s\n", s); + free (s); + } + } else { RRegItem *r; const char *name = r_str_trim_head_ro (str + 1); if (*name && name[1]) { diff --git a/libr/include/r_reg.h b/libr/include/r_reg.h index 83280f23a6..45a2953773 100644 --- a/libr/include/r_reg.h +++ b/libr/include/r_reg.h @@ -144,6 +144,7 @@ R_API void r_reg_free_internal(RReg *reg, bool init); R_API RReg *r_reg_new(void); 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 bool r_reg_is_readonly(RReg *reg, RRegItem *item); @@ -153,6 +154,7 @@ R_API ut64 r_reg_getv(RReg *reg, const char *name); R_API ut64 r_reg_setv(RReg *reg, const char *name, ut64 val); R_API const char *r_reg_32_to_64(RReg *reg, const char *rreg32); R_API const char *r_reg_64_to_32(RReg *reg, const char *rreg64); +R_API const char *r_reg_get_name_by_type(RReg *reg, const char *name); R_API const char *r_reg_get_type(int idx); R_API const char *r_reg_get_name(RReg *reg, int kind); R_API const char *r_reg_get_role(int role); diff --git a/libr/reg/profile.c b/libr/reg/profile.c index 8ae3115726..173b937968 100644 --- a/libr/reg/profile.c +++ b/libr/reg/profile.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2019 - pancake */ +/* radare - LGPL - Copyright 2009-2020 - pancake */ #include #include @@ -397,3 +397,29 @@ R_API bool r_reg_parse_gdb_profile(const char *profile_file) { free (str); return ret; } + +R_API char *r_reg_profile_to_cc(RReg *reg) { + const char *r0 = r_reg_get_name_by_type (reg, "R0"); + const char *a0 = r_reg_get_name_by_type (reg, "A0"); + const char *a1 = r_reg_get_name_by_type (reg, "A1"); + const char *a2 = r_reg_get_name_by_type (reg, "A2"); + const char *a3 = r_reg_get_name_by_type (reg, "A3"); + + // it is mandatory to have at least =A0 defined in the reg profile + // this will be enforced in reg/profile at parsing time + r_return_val_if_fail (a0, NULL); + if (!r0) { + r0 = a0; + } + if (a3 && a2 && a1) { + return r_str_newf ("%s reg(%s, %s, %s, %s)", r0, a0, a1, a2, a3); + } + if (a2 && a1) { + return r_str_newf ("%s reg(%s, %s, %s)", r0, a0, a1, a2); + } + if (a1) { + return r_str_newf ("%s reg(%s, %s)", r0, a0, a1); + } + return r_str_newf ("%s reg(%s)", r0, a0); +} + diff --git a/libr/reg/reg.c b/libr/reg/reg.c index 3315fd8486..ff47c829a4 100644 --- a/libr/reg/reg.c +++ b/libr/reg/reg.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2019 - pancake */ +/* radare - LGPL - Copyright 2009-2020 - pancake */ #include #include @@ -67,6 +67,11 @@ R_API const char *r_reg_get_type(int idx) { return (idx >= 0 && idx < R_REG_TYPE_LAST) ? types[idx] : NULL; } +R_API const char *r_reg_get_name_by_type(RReg *reg, const char *alias_name) { + const int n = r_reg_get_name_idx (alias_name); + return (n != -1)? r_reg_get_name (reg, n): NULL; +} + R_API int r_reg_type_by_name(const char *str) { r_return_val_if_fail (str, -1); int i; diff --git a/test/db/cmd/cmd_ara b/test/db/cmd/cmd_ara index 0006d54d5e..41af5b40b8 100644 --- a/test/db/cmd/cmd_ara +++ b/test/db/cmd/cmd_ara @@ -73,3 +73,29 @@ EXPECT=<