Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
imbillow committed Sep 14, 2024
1 parent 2b95de8 commit 688de7d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
6 changes: 3 additions & 3 deletions librz/arch/dwarf_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -1673,14 +1673,14 @@ static bool try_create_var_global(
RzBinDwarfAttr *attr = NULL;
attr = rz_bin_dwarf_die_get_attr(die, DW_AT_decl_file);
RzBinDwarfLineUnit *lu = ctx->unit ? rz_pvector_at(ctx->dw->line->units, ctx->unit->index) : NULL;
ut64 file_index = rz_bin_dwarf_attr_udata(attr);
ut64 file_index = attr ? rz_bin_dwarf_attr_udata(attr) : UT64_MAX;
const char *file = file_index != 0 && lu ? rz_bin_dwarf_file_path(ctx->dw, lu, file_index) : NULL;

attr = rz_bin_dwarf_die_get_attr(die, DW_AT_decl_line);
ut32 line = rz_bin_dwarf_attr_udata(attr);
ut32 line = attr ? rz_bin_dwarf_attr_udata(attr) : UT32_MAX;

attr = rz_bin_dwarf_die_get_attr(die, DW_AT_decl_column);
ut32 column = rz_bin_dwarf_attr_udata(attr);
ut32 column = attr ? rz_bin_dwarf_attr_udata(attr) : UT32_MAX;

result = rz_analysis_var_global_create_with_sourceline(
ctx->analysis, v->prefer_name, v->type, v->location->address,
Expand Down
4 changes: 2 additions & 2 deletions librz/bin/dwarf/line.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static char *full_file_path(
RzBinDWARF *dw,
RzBinDwarfLineUnitHdr *hdr,
ut64 index) {
rz_return_val_if_fail(dw && hdr, NULL);
rz_return_val_if_fail(hdr, NULL);
if (index >= rz_vector_len(&hdr->file_names)) {
return NULL;
}
Expand All @@ -232,7 +232,7 @@ static char *full_file_path(
* or backslashes anyway, we will simply use slashes always here.
*/

const char *comp_dir = dw->info
const char *comp_dir = dw && dw->info
? ht_up_find(dw->info->comp_dir_by_offset, hdr->offset, NULL)
: NULL;
const ut64 dir_index = hdr->encoding.version < 5 ? file->directory_index - 1 : file->directory_index;
Expand Down
13 changes: 9 additions & 4 deletions librz/core/canalysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -4468,9 +4468,13 @@ static void var_global_show(RzAnalysis *analysis, RzAnalysisVarGlobal *glob, RzC
rz_cons_println(glob->name);
break;
case RZ_OUTPUT_MODE_STANDARD:
rz_cons_printf("global %s %s @ 0x%" PFMT64x " %s:%d:%d\n",
var_type, glob->name, glob->addr,
glob->coord.decl_file, glob->coord.decl_line, glob->coord.decl_col);
rz_cons_printf("global %s %s @ 0x%" PFMT64x, var_type, glob->name, glob->addr);
if (glob->coord.decl_file) {
rz_cons_printf(" %s:%" PFMT32d "%" PFMT32d "\n",
glob->coord.decl_file, glob->coord.decl_line, glob->coord.decl_col);
} else {
rz_cons_print("\n");
}
break;
case RZ_OUTPUT_MODE_JSON: {
PJ *pj = state->d.pj;
Expand All @@ -4492,7 +4496,8 @@ static void var_global_show(RzAnalysis *analysis, RzAnalysisVarGlobal *glob, RzC
}
case RZ_OUTPUT_MODE_TABLE: {
rz_table_add_rowf(state->d.t, "ssxxsnn", glob->name, var_type, var_size, glob->addr,
glob->coord.decl_file, glob->coord.decl_line, glob->coord.decl_col);
glob->coord.decl_file ? glob->coord.decl_file : "-",
glob->coord.decl_line, glob->coord.decl_col);
break;
}
default:
Expand Down
2 changes: 1 addition & 1 deletion test/db/cmd/cmd_avg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ avga bar char @ 0x1000
avglj
EOF
EXPECT=<<EOF
[{"name":"foo","type":"int","size":4,"addr":"0x100"},{"name":"bar","type":"char","size":1,"addr":"0x1000"}]
[{"name":"foo","type":"int","size":4,"addr":"0x100","decl_line":0,"decl_col":0},{"name":"bar","type":"char","size":1,"addr":"0x1000","decl_line":0,"decl_col":0}]
EOF
RUN

Expand Down
2 changes: 1 addition & 1 deletion test/db/cmd/types
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ avga foo int
avglj
EOF
EXPECT=<<EOF
[{"name":"bla","type":"short","size":2,"addr":"0x2"},{"name":"foo","type":"int","size":4,"addr":"0x8"}]
[{"name":"bla","type":"short","size":2,"addr":"0x2","decl_line":0,"decl_col":0},{"name":"foo","type":"int","size":4,"addr":"0x8","decl_line":0,"decl_col":0}]
EOF
RUN

Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_analysis_global_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ bool test_rz_analysis_global_var() {
typ = rz_type_parse_string_single(parser, "int", &errmsg);
mu_assert_notnull(typ, "parsed type");
mu_assert_true(rz_analysis_var_global_create(analysis, "crab", typ, 0x125418),
"create global var");
"create global var");

glob = rz_analysis_var_global_get_byname(analysis, "crab");
mu_assert_notnull(glob, "create a global variable");
Expand Down

0 comments on commit 688de7d

Please sign in to comment.