Skip to content

Commit

Permalink
sdb: remove unused cas and expire features (#4487)
Browse files Browse the repository at this point in the history
  • Loading branch information
pelijah authored May 12, 2024
1 parent 0a05e42 commit 706a6bf
Show file tree
Hide file tree
Showing 84 changed files with 1,435 additions and 1,674 deletions.
38 changes: 19 additions & 19 deletions librz/arch/analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,50 +507,50 @@ RZ_API int rz_analysis_archinfo(RzAnalysis *analysis, RzAnalysisInfoType query)
return value;
}

static bool sdb_noret_addr_set(Sdb *db, ut64 addr, bool v, ut32 cas) {
static bool sdb_noret_addr_set(Sdb *db, ut64 addr, bool v) {
char key[128];
rz_strf(key, "addr.%" PFMT64x ".noreturn", addr);
return sdb_bool_set(db, key, v, cas);
return sdb_bool_set(db, key, v);
}

static bool sdb_noret_addr_get(Sdb *db, ut64 addr, ut32 *cas) {
static bool sdb_noret_addr_get(Sdb *db, ut64 addr) {
char key[128];
rz_strf(key, "addr.%" PFMT64x ".noreturn", addr);
return sdb_bool_get(db, key, cas);
return sdb_bool_get(db, key);
}

static int sdb_noret_addr_unset(Sdb *db, ut64 addr, ut32 cas) {
static int sdb_noret_addr_unset(Sdb *db, ut64 addr) {
char key[128];
rz_strf(key, "addr.%" PFMT64x ".noreturn", addr);
return sdb_unset(db, key, cas);
return sdb_unset(db, key);
}

static bool sdb_noret_func_set(Sdb *db, const char *name, bool v, ut32 cas) {
static bool sdb_noret_func_set(Sdb *db, const char *name, bool v) {
char *key = rz_str_newf("func.%s.noreturn", name);
if (!key) {
return false;
}
bool res = sdb_bool_set(db, key, v, cas);
bool res = sdb_bool_set(db, key, v);
free(key);
return res;
}

static bool sdb_noret_func_get(Sdb *db, const char *name, ut32 *cas) {
static bool sdb_noret_func_get(Sdb *db, const char *name) {
char *key = rz_str_newf("func.%s.noreturn", name);
if (!key) {
return false;
}
bool res = sdb_bool_get(db, key, cas);
bool res = sdb_bool_get(db, key);
free(key);
return res;
}

static int sdb_noret_func_unset(Sdb *db, const char *name, ut32 cas) {
static int sdb_noret_func_unset(Sdb *db, const char *name) {
char *key = rz_str_newf("func.%s.noreturn", name);
if (!key) {
return false;
}
int res = sdb_unset(db, key, cas);
int res = sdb_unset(db, key);
free(key);
return res;
}
Expand All @@ -560,7 +560,7 @@ RZ_API bool rz_analysis_noreturn_add(RzAnalysis *analysis, const char *name, ut6
Sdb *NDB = analysis->sdb_noret;
char *fnl_name = NULL;
if (addr != UT64_MAX) {
if (sdb_noret_addr_set(NDB, addr, true, 0)) {
if (sdb_noret_addr_set(NDB, addr, true)) {
RzAnalysisFunction *fcn = rz_analysis_get_function_at(analysis, addr);
if (fcn) {
fcn->is_noreturn = true;
Expand All @@ -587,7 +587,7 @@ RZ_API bool rz_analysis_noreturn_add(RzAnalysis *analysis, const char *name, ut6
} else if (!(fnl_name = rz_analysis_function_name_guess(analysis->typedb, (char *)tmp_name))) {
if (addr == UT64_MAX) {
if (name) {
sdb_noret_func_set(NDB, name, true, 0);
sdb_noret_func_set(NDB, name, true);
} else {
RZ_LOG_ERROR("Cannot find prototype for: %s\n", tmp_name);
}
Expand All @@ -597,7 +597,7 @@ RZ_API bool rz_analysis_noreturn_add(RzAnalysis *analysis, const char *name, ut6
// return false;
}
if (fnl_name) {
sdb_noret_func_set(NDB, fnl_name, true, 0);
sdb_noret_func_set(NDB, fnl_name, true);
free(fnl_name);
}
return true;
Expand All @@ -609,7 +609,7 @@ RZ_API bool rz_analysis_noreturn_drop(RzAnalysis *analysis, const char *expr) {
const char *fcnname = NULL;
if (!strncmp(expr, "0x", 2)) {
ut64 n = rz_num_math(NULL, expr);
sdb_noret_addr_unset(NDB, n, 0);
sdb_noret_addr_unset(NDB, n);
RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(analysis, n, -1);
if (!fcn) {
// eprintf ("can't find function at 0x%"PFMT64x"\n", n);
Expand All @@ -619,13 +619,13 @@ RZ_API bool rz_analysis_noreturn_drop(RzAnalysis *analysis, const char *expr) {
} else {
fcnname = expr;
}
sdb_noret_func_unset(NDB, fcnname, 0);
sdb_noret_func_unset(NDB, fcnname);
return false;
}

static bool rz_analysis_is_noreturn(RzAnalysis *analysis, const char *name) {
return rz_type_func_is_noreturn(analysis->typedb, name) ||
sdb_noret_func_get(analysis->sdb_noret, name, NULL);
sdb_noret_func_get(analysis->sdb_noret, name);
}

static bool rz_analysis_noreturn_at_name(RzAnalysis *analysis, const char *name) {
Expand All @@ -647,7 +647,7 @@ static bool rz_analysis_noreturn_at_name(RzAnalysis *analysis, const char *name)
}

RZ_API bool rz_analysis_noreturn_at_addr(RzAnalysis *analysis, ut64 addr) {
return sdb_noret_addr_get(analysis->sdb_noret, addr, NULL);
return sdb_noret_addr_get(analysis->sdb_noret, addr);
}

static bool noreturn_recurse(RzAnalysis *analysis, ut64 addr) {
Expand Down
2 changes: 1 addition & 1 deletion librz/arch/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ RZ_API int rz_asm_get_offset(RzAsm *a, int type, int idx) { // link to rbin
}

RZ_API char *rz_asm_describe(RzAsm *a, const char *str) {
return (a && a->pair) ? sdb_get(a->pair, str, 0) : NULL;
return (a && a->pair) ? sdb_get(a->pair, str) : NULL;
}

RZ_API RzList /*<RzAsmPlugin *>*/ *rz_asm_get_plugins(RzAsm *a) {
Expand Down
42 changes: 21 additions & 21 deletions librz/arch/cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
do { \
char key[512]; \
rz_strf(key, __VA_ARGS__); \
sdb_unset(x, key, 0); \
sdb_unset(x, key); \
} while (0)

#define cc_sdb_setf(x, y, ...) \
do { \
char key[512]; \
rz_strf(key, __VA_ARGS__); \
sdb_set(x, key, y, 0); \
sdb_set(x, key, y); \
} while (0)

RZ_API void rz_analysis_cc_del(RzAnalysis *analysis, const char *name) {
rz_return_if_fail(analysis && name);
sdb_unset(DB, name, 0);
sdb_unset(DB, name);
cc_sdb_unsetf(DB, "cc.%s.ret", name);
cc_sdb_unsetf(DB, "cc.%s.maxargs", name);
cc_sdb_unsetf(DB, "cc.%s.argn", name);
Expand Down Expand Up @@ -63,7 +63,7 @@ RZ_API bool rz_analysis_cc_set(RzAnalysis *analysis, const char *expr) {
free(e);
return false;
}
sdb_set(DB, ccname, "cc", 0);
sdb_set(DB, ccname, "cc");
cc_sdb_setf(DB, e, "cc.%s.ret", ccname);

RzList *ccArgs = rz_str_split_list(args, ",", 0);
Expand Down Expand Up @@ -93,12 +93,12 @@ RZ_API char *rz_analysis_cc_get(RzAnalysis *analysis, const char *name) {
rz_return_val_if_fail(analysis && name, NULL);
char *tmp_cc = NULL;
// get cc by name and print the expr
if (rz_str_cmp(sdb_const_get(DB, name, 0), "cc", -1)) {
if (rz_str_cmp(sdb_const_get(DB, name), "cc", -1)) {
RZ_LOG_ERROR("analysis: '%s' is not a valid calling convention name\n", name);
return NULL;
}
tmp_cc = rz_str_newf("cc.%s.ret", name);
const char *ret = tmp_cc ? sdb_const_get(DB, tmp_cc, 0) : NULL;
const char *ret = tmp_cc ? sdb_const_get(DB, tmp_cc) : NULL;
free(tmp_cc);
if (!ret) {
RZ_LOG_ERROR("analysis: Cannot find return key in calling convention named '%s'\n", name);
Expand All @@ -110,7 +110,7 @@ RZ_API char *rz_analysis_cc_get(RzAnalysis *analysis, const char *name) {
bool isFirst = true;
for (int i = 0; i < RZ_ANALYSIS_CC_MAXARG; i++) {
char *k = rz_str_newf("cc.%s.arg%d", name, i);
const char *arg = k ? sdb_const_get(DB, k, 0) : NULL;
const char *arg = k ? sdb_const_get(DB, k) : NULL;
free(k);
if (!arg) {
break;
Expand All @@ -119,7 +119,7 @@ RZ_API char *rz_analysis_cc_get(RzAnalysis *analysis, const char *name) {
isFirst = false;
}
tmp_cc = rz_str_newf("cc.%s.argn", name);
const char *argn = tmp_cc ? sdb_const_get(DB, tmp_cc, 0) : NULL;
const char *argn = tmp_cc ? sdb_const_get(DB, tmp_cc) : NULL;
free(tmp_cc);
if (argn) {
rz_strbuf_appendf(sb, "%s%s", isFirst ? "" : ", ", argn);
Expand All @@ -137,7 +137,7 @@ RZ_API char *rz_analysis_cc_get(RzAnalysis *analysis, const char *name) {

RZ_API bool rz_analysis_cc_exist(RzAnalysis *analysis, const char *convention) {
rz_return_val_if_fail(analysis && convention, false);
const char *x = sdb_const_get(DB, convention, 0);
const char *x = sdb_const_get(DB, convention);
return x && *x && !strcmp(x, "cc");
}

Expand All @@ -149,11 +149,11 @@ RZ_API const char *rz_analysis_cc_arg(RzAnalysis *analysis, const char *conventi
}

char *query = rz_str_newf("cc.%s.arg%d", convention, n);
const char *ret = query ? sdb_const_get(DB, query, 0) : NULL;
const char *ret = query ? sdb_const_get(DB, query) : NULL;
free(query);
if (!ret) {
query = rz_str_newf("cc.%s.argn", convention);
ret = query ? sdb_const_get(DB, query, 0) : NULL;
ret = query ? sdb_const_get(DB, query) : NULL;
free(query);
}
return ret ? rz_str_constpool_get(&analysis->constpool, ret) : NULL;
Expand All @@ -162,7 +162,7 @@ RZ_API const char *rz_analysis_cc_arg(RzAnalysis *analysis, const char *conventi
RZ_API const char *rz_analysis_cc_self(RzAnalysis *analysis, const char *convention) {
rz_return_val_if_fail(analysis && convention, NULL);
char *query = rz_str_newf("cc.%s.self", convention);
const char *self = query ? sdb_const_get(DB, query, 0) : NULL;
const char *self = query ? sdb_const_get(DB, query) : NULL;
free(query);
return self ? rz_str_constpool_get(&analysis->constpool, self) : NULL;
}
Expand All @@ -177,14 +177,14 @@ RZ_API void rz_analysis_cc_set_self(RzAnalysis *analysis, const char *convention
RZ_LOG_ERROR("analysis: Cannot allocate key for sdb_set\n");
return;
}
sdb_set(analysis->sdb_cc, query, self, 0);
sdb_set(analysis->sdb_cc, query, self);
free(query);
}

RZ_API const char *rz_analysis_cc_error(RzAnalysis *analysis, const char *convention) {
rz_return_val_if_fail(analysis && convention, NULL);
char *query = rz_str_newf("cc.%s.error", convention);
const char *error = query ? sdb_const_get(DB, query, 0) : NULL;
const char *error = query ? sdb_const_get(DB, query) : NULL;
free(query);
return error ? rz_str_constpool_get(&analysis->constpool, error) : NULL;
}
Expand All @@ -198,7 +198,7 @@ RZ_API void rz_analysis_cc_set_error(RzAnalysis *analysis, const char *conventio
RZ_LOG_ERROR("analysis: Cannot allocate key for sdb_set\n");
return;
}
sdb_set(analysis->sdb_cc, key, error, 0);
sdb_set(analysis->sdb_cc, key, error);
free(key);
}

Expand All @@ -208,7 +208,7 @@ RZ_API int rz_analysis_cc_max_arg(RzAnalysis *analysis, const char *cc) {
if (!query) {
return 0;
}
const char *res = sdb_const_get(DB, query, 0);
const char *res = sdb_const_get(DB, query);
free(query);
int maxargs = res ? atoi(res) : 0;
if (maxargs < 0 || maxargs > RZ_ANALYSIS_CC_MAXARG) {
Expand All @@ -220,7 +220,7 @@ RZ_API int rz_analysis_cc_max_arg(RzAnalysis *analysis, const char *cc) {
RZ_API const char *rz_analysis_cc_ret(RzAnalysis *analysis, const char *convention) {
rz_return_val_if_fail(analysis && convention, NULL);
char *query = rz_str_newf("cc.%s.ret", convention);
const char *res = query ? sdb_const_get(DB, query, 0) : NULL;
const char *res = query ? sdb_const_get(DB, query) : NULL;
free(query);
return res;
}
Expand All @@ -241,22 +241,22 @@ RZ_API RzStackAddr rz_analysis_cc_shadow_store(RzAnalysis *analysis, const char

RZ_API const char *rz_analysis_cc_default(RzAnalysis *analysis) {
rz_return_val_if_fail(analysis, NULL);
return sdb_const_get(DB, "default.cc", 0);
return sdb_const_get(DB, "default.cc");
}

RZ_API void rz_analysis_set_cc_default(RzAnalysis *analysis, const char *cc) {
rz_return_if_fail(analysis && cc);
sdb_set(DB, "default.cc", cc, 0);
sdb_set(DB, "default.cc", cc);
}

RZ_API const char *rz_analysis_syscc_default(RzAnalysis *analysis) {
rz_return_val_if_fail(analysis, NULL);
return sdb_const_get(DB, "default.syscc", 0);
return sdb_const_get(DB, "default.syscc");
}

RZ_API void rz_analysis_set_syscc_default(RzAnalysis *analysis, const char *cc) {
rz_return_if_fail(analysis && cc);
sdb_set(DB, "default.syscc", cc, 0);
sdb_set(DB, "default.syscc", cc);
}

RZ_API const char *rz_analysis_cc_func(RzAnalysis *analysis, const char *func_name) {
Expand Down
Loading

0 comments on commit 706a6bf

Please sign in to comment.