Skip to content

Commit

Permalink
core/disasm: remove static variables (rizinorg#4224)
Browse files Browse the repository at this point in the history
  • Loading branch information
XVilka authored Feb 14, 2024
1 parent 2886608 commit c3535fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
6 changes: 3 additions & 3 deletions librz/core/cdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ static const char *signal_option(int opt) {
}

static bool siglistcb(void *p, const char *k, const char *v) {
static char key[32] = "cfg.";
char key[32] = "cfg.";
struct RzCoreDebugState *ds = p;
int opt;
if (atoi(k) > 0) {
Expand All @@ -1208,7 +1208,7 @@ static bool siglistcb(void *p, const char *k, const char *v) {
}

static bool siglistjsoncb(void *p, const char *k, const char *v) {
static char key[32] = "cfg.";
char key[32] = "cfg.";
struct RzCoreDebugState *ds = p;
int opt;
if (atoi(k) > 0) {
Expand All @@ -1229,7 +1229,7 @@ static bool siglistjsoncb(void *p, const char *k, const char *v) {
}

static bool siglisttblcb(void *p, const char *k, const char *v) {
static char key[32] = "cfg.";
char key[32] = "cfg.";
struct RzCoreDebugState *ds = p;
int opt;
if (atoi(k) > 0) {
Expand Down
41 changes: 15 additions & 26 deletions librz/core/disasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ typedef struct {
int maxflags;
int asm_types;

bool sparse;

RzPVector /*<RzAnalysisDisasmText *>*/ *vec;
RzFlagItem lastflagitem;
} RzDisasmState;

static void ds_setup_print_pre(RzDisasmState *ds, bool tail, bool middle);
Expand Down Expand Up @@ -1081,24 +1084,13 @@ static void ds_build_op_str(RzDisasmState *ds, bool print_color) {
}

RZ_API RzAnalysisHint *rz_core_hint_begin(RzCore *core, RzAnalysisHint *hint, ut64 at) {
static char *hint_syntax = NULL;
rz_analysis_hint_free(hint);
hint = rz_analysis_hint_get(core->analysis, at);
if (hint_syntax) {
rz_config_set(core->config, "asm.syntax", hint_syntax);
hint_syntax = NULL;
}
if (hint) {
/* syntax */
if (hint->syntax) {
if (!hint_syntax) {
hint_syntax = strdup(rz_config_get(core->config, "asm.syntax"));
}
rz_config_set(core->config, "asm.syntax", hint->syntax);
}
if (hint->high) {
/* TODO: do something here */
}
}
RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, at, 0);
if (fcn) {
Expand Down Expand Up @@ -2674,19 +2666,18 @@ static void ds_print_lines_left(RzDisasmState *ds) {
free(sect);
}
if (ds->show_symbols) {
static RzFlagItem sfi = RZ_EMPTY;
const char *name = "";
int delta = 0;
if (ds->fcn) {
sfi.offset = ds->fcn->addr;
sfi.name = ds->fcn->name;
ds->lastflag = &sfi;
ds->lastflagitem.offset = ds->fcn->addr;
ds->lastflagitem.name = ds->fcn->name;
ds->lastflag = &ds->lastflagitem;
} else {
RzFlagItem *fi = rz_flag_get_at(core->flags, ds->at, !ds->lastflag);
if (fi) { // && (!ds->lastflag || fi->offset != ds->at))
sfi.offset = fi->offset;
sfi.name = fi->name;
ds->lastflag = &sfi;
ds->lastflagitem.offset = fi->offset;
ds->lastflagitem.name = fi->name;
ds->lastflag = &ds->lastflagitem;
}
}
if (ds->lastflag && ds->lastflag->name) {
Expand Down Expand Up @@ -2788,7 +2779,6 @@ static void ds_print_offset(RzDisasmState *ds) {
}
rz_print_set_screenbounds(core->print, at);
if (ds->show_offset) {
static RzFlagItem sfi = RZ_EMPTY;
const char *label = NULL;
RzFlagItem *fi;
int delta = -1;
Expand All @@ -2802,9 +2792,9 @@ static void ds_print_offset(RzDisasmState *ds) {
}
if (f) {
delta = at - f->addr;
sfi.name = f->name;
sfi.offset = f->addr;
ds->lastflag = &sfi;
ds->lastflagitem.name = f->name;
ds->lastflagitem.offset = f->addr;
ds->lastflag = &ds->lastflagitem;
label = f->name;
} else {
if (ds->show_reloff_flags) {
Expand Down Expand Up @@ -5369,7 +5359,6 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u
ds->at -= skip_bytes_flag;
}
if (ds->pdf) {
static bool sparse = false;
RzAnalysisBlock *bb = rz_analysis_fcn_bbget_in(core->analysis, ds->pdf, ds->at);
if (!bb) {
for (inc = 1; inc < ds->oplen; inc++) {
Expand All @@ -5380,13 +5369,13 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u
}
rz_analysis_op_fini(&ds->analysis_op);
RZ_FREE(ds->opstr);
if (!sparse) {
if (!ds->sparse) {
rz_cons_printf("..\n");
sparse = true;
ds->sparse = true;
}
continue;
}
sparse = false;
ds->sparse = false;
}
ds_control_flow_comments(ds);
ds_adistrick_comments(ds);
Expand Down

0 comments on commit c3535fa

Please sign in to comment.