mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-03 19:01:31 +00:00
Implement arcc command using the new r_reg_profile_to_cc API ##types (#17618)
This commit is contained in:
parent
18af675e05
commit
2ad2744796
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -654,6 +654,7 @@ static const char *help_msg_ar[] = {
|
||||
"ar?", " <reg>", "Show register value",
|
||||
"arb", " <type>", "Display hexdump of the given arena",
|
||||
"arc", " <name>", "Conditional flag registers",
|
||||
"arcc", "", "Show calling convention defined from the register profile",
|
||||
"ard", " <name>", "Show only different registers",
|
||||
"arn", " <regalias>", "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]) {
|
||||
|
@ -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);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2019 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2020 - pancake */
|
||||
|
||||
#include <r_reg.h>
|
||||
#include <r_util.h>
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2019 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2020 - pancake */
|
||||
|
||||
#include <r_reg.h>
|
||||
#include <r_util.h>
|
||||
@ -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;
|
||||
|
@ -73,3 +73,29 @@ EXPECT=<<EOF
|
||||
8
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=arcc+tcc
|
||||
FILE=-
|
||||
CMDS=<<EOF
|
||||
afcl
|
||||
e asm.arch=arm
|
||||
e asm.bits=32
|
||||
arcc
|
||||
e asm.arch=x86
|
||||
e asm.bits=64
|
||||
arcc
|
||||
tcc `arcc`
|
||||
afcl
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
amd64
|
||||
ms
|
||||
swift
|
||||
r0 reg(r0, r1, r2, r3)
|
||||
rdi reg(rdi, rsi, rdx, rcx)
|
||||
ms
|
||||
amd64
|
||||
swift
|
||||
reg
|
||||
EOF
|
||||
RUN
|
||||
|
Loading…
Reference in New Issue
Block a user