Skip to content

Commit

Permalink
afvl command improvements (#3945)
Browse files Browse the repository at this point in the history
- in SHORT mode only print `@ COMPOSITE` or `@ LOCLIST` and omit the details
- in LONG and TABLE mode `[(0x8010fb1c, 0x8010fb3f): a4,	(0x8010fb42, 0x8010fb48): a13,	(0x8010fb48, 0x8010fb5e): a4,	(0x8010fb5e, 0x8010fb64): a13,	(0x8010fb64, 0x8010fb6d): a4]`
  => `[(0x8010fb1c, 23): a4,	(0x8010fb42, 6): a13,	(0x8010fb48, 16): a4,	(0x8010fb5e, 6): a13,	(0x8010fb64, 9): a4]`
  • Loading branch information
imbillow authored Oct 31, 2023
1 parent 7340fa4 commit fde0358
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 70 deletions.
32 changes: 11 additions & 21 deletions librz/analysis/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,10 @@ static void strbuf_append_sign_hex(RzStrBuf *sb, st64 x) {
rz_strbuf_appendf(sb, " %c 0x%" PFMT64x, sign, RZ_ABS(x));
}

static void composite_dump(RZ_NONNULL RZ_BORROW RzAnalysis *a,
RZ_NONNULL RZ_BORROW RZ_OUT RzStrBuf *sb,
RZ_NONNULL RZ_BORROW const RzVector /*<RzAnalysisVarStoragePiece>*/ *composite) {
rz_strbuf_append(sb, "composite: [");
ut32 i;
ut32 end = rz_vector_len(composite) - 1;
RzAnalysisVarStoragePiece *piece = NULL;
rz_vector_enumerate(composite, piece, i) {
rz_strbuf_appendf(sb, "(.%" PFMT32u ", %" PFMT32u "): ",
piece->offset_in_bits, piece->size_in_bits);
rz_analysis_var_storage_dump(a, sb, piece->storage);
if (i < end) {
rz_strbuf_append(sb, ", ");
}
}
rz_strbuf_append(sb, "]");
}

RZ_API void rz_analysis_var_storage_dump(
RZ_NONNULL RZ_BORROW RzAnalysis *a,
RZ_NONNULL RZ_BORROW RZ_OUT RzStrBuf *sb,
RZ_NULLABLE RZ_BORROW const RzAnalysisVar *var,
RZ_NONNULL RZ_BORROW const RzAnalysisVarStorage *storage) {
rz_return_if_fail(a && sb && storage);
switch (storage->type) {
Expand All @@ -139,12 +122,18 @@ RZ_API void rz_analysis_var_storage_dump(
break;
}
case RZ_ANALYSIS_VAR_STORAGE_COMPOSITE: {
composite_dump(a, sb, storage->composite);
rz_strbuf_append(sb, "COMPOSITE");
break;
}
case RZ_ANALYSIS_VAR_STORAGE_EVAL_PENDING:
/// Omit storage information
rz_strbuf_append(sb, "...");
if (var && var->origin.kind == RZ_ANALYSIS_VAR_ORIGIN_DWARF &&
var->origin.dw_var && var->origin.dw_var->location &&
var->origin.dw_var->location->kind == RzBinDwarfLocationKind_LOCLIST) {
rz_strbuf_append(sb, "LOCLIST");
} else {
rz_strbuf_append(sb, "...");
}
break;
default:
rz_warn_if_reached();
Expand All @@ -154,10 +143,11 @@ RZ_API void rz_analysis_var_storage_dump(

RZ_API RZ_OWN char *rz_analysis_var_storage_to_string(
RZ_NONNULL RZ_BORROW RzAnalysis *a,
RZ_NULLABLE RZ_BORROW const RzAnalysisVar *var,
RZ_NONNULL RZ_BORROW const RzAnalysisVarStorage *storage) {
rz_return_val_if_fail(a && storage, NULL);
RzStrBuf *sb = rz_strbuf_new(NULL);
rz_analysis_var_storage_dump(a, sb, storage);
rz_analysis_var_storage_dump(a, sb, var, storage);
return rz_strbuf_drain(sb);
}

Expand Down
3 changes: 2 additions & 1 deletion librz/bin/dwarf/op.c
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,8 @@ RZ_API void rz_bin_dwarf_loclist_dump(
void **it = NULL;
rz_pvector_foreach (&loclist->entries, it) {
RzBinDwarfLocListEntry *entry = *it;
rz_strbuf_appendf(sb, "%s(0x%" PFMT64x ", 0x%" PFMT64x "):", rz_str_get(opt->loclist_indent), entry->range->begin, entry->range->end);
rz_strbuf_appendf(sb, "%s(0x%" PFMT64x ", %" PFMT64d "):",
rz_str_get(opt->loclist_indent), entry->range->begin, entry->range->end - entry->range->begin);

if (entry->location) {
rz_strbuf_append(sb, " ");
Expand Down
2 changes: 1 addition & 1 deletion librz/core/canalysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -6519,6 +6519,6 @@ RZ_API RZ_OWN char *rz_core_analysis_var_to_string(RZ_NONNULL RzCore *core, RZ_N
constr ? "} " : "");
free(vartype);
free(constr);
rz_analysis_var_storage_dump(core->analysis, sb, &var->storage);
rz_analysis_var_storage_dump(core->analysis, sb, var, &var->storage);
return rz_strbuf_drain(sb);
}
4 changes: 2 additions & 2 deletions librz/core/cmd/cmd_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,7 @@ static void var_show(
RZ_NONNULL RzAnalysisVar *var) {
char *constr = rz_analysis_var_get_constraints_readable(var);
char *var_type_string = rz_type_as_string(ctx->core->analysis->typedb, var->type);
char *storage_string = rz_analysis_var_storage_to_string(ctx->core->analysis, &var->storage);
char *storage_string = rz_analysis_var_storage_to_string(ctx->core->analysis, var, &var->storage);
RzBinDWARFDumpOption dump_opt = {
.dwarf_register_mapping = ctx->core->analysis->debug_info->dwarf_register_mapping,
.loclist_sep = ",\t",
Expand Down Expand Up @@ -2949,7 +2949,7 @@ static RzCmdStatus analysis_function_vars_getsetref(RzCore *core, RzAnalysisVarS

RzAnalysisVar *var = rz_analysis_function_get_var_at(fcn, stor);
if (!var) {
char *stor_str = rz_analysis_var_storage_to_string(core->analysis, stor);
char *stor_str = rz_analysis_var_storage_to_string(core->analysis, NULL, stor);
RZ_LOG_ERROR("core: Cannot find variable with %s\n", stor_str);
free(stor_str);
return RZ_CMD_STATUS_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion librz/core/tui/vmenus.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static ut64 var_variables_show(RzCore *core, int idx, int *vindex, int show, int
rz_cons_printf("%s%s %s %s @ ", i == *vindex ? "* " : " ", rz_analysis_var_is_arg(var) ? "arg" : "var", vartype, var->name);
free(vartype);

char *storage_str = rz_analysis_var_storage_to_string(core->analysis, &var->storage);
char *storage_str = rz_analysis_var_storage_to_string(core->analysis, var, &var->storage);
rz_cons_strcat(storage_str);
free(storage_str);
}
Expand Down
2 changes: 2 additions & 0 deletions librz/include/rz_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -1804,13 +1804,15 @@ RZ_API bool rz_analysis_var_storage_type_from_string(
RZ_API void rz_analysis_var_storage_dump(
RZ_NONNULL RZ_BORROW RzAnalysis *a,
RZ_NONNULL RZ_BORROW RZ_OUT RzStrBuf *sb,
RZ_NULLABLE RZ_BORROW const RzAnalysisVar *var,
RZ_NONNULL RZ_BORROW const RzAnalysisVarStorage *storage);
RZ_API void rz_analysis_var_storage_dump_pj(
RZ_NONNULL RZ_BORROW RZ_OUT PJ *pj,
RZ_NONNULL RZ_BORROW const RzAnalysisVar *var,
RZ_NONNULL RZ_BORROW const RzAnalysisVarStorage *storage);
RZ_API RZ_OWN char *rz_analysis_var_storage_to_string(
RZ_NONNULL RZ_BORROW RzAnalysis *a,
RZ_NULLABLE RZ_BORROW const RzAnalysisVar *var,
RZ_NONNULL RZ_BORROW const RzAnalysisVarStorage *storage);
RZ_API void rz_analysis_var_storage_poolify(
RZ_NONNULL RZ_BORROW RzAnalysis *analysis,
Expand Down
Loading

0 comments on commit fde0358

Please sign in to comment.