Skip to content

Commit

Permalink
DWARF: fix loclists dump (#4152)
Browse files Browse the repository at this point in the history
  • Loading branch information
imbillow committed Jan 25, 2024
1 parent d29e7ef commit 9e96854
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
12 changes: 12 additions & 0 deletions librz/bin/dwarf/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ static bool CU_attrs_parse(
case DW_AT_sibling:
die->sibling = rz_bin_dwarf_attr_udata(&attr);
break;
case DW_AT_location: {
if (attr.value.kind == RzBinDwarfAttr_LoclistPtr ||
attr.value.kind == RzBinDwarfAttr_Reference ||
attr.value.kind == RzBinDwarfAttr_UConstant ||
attr.value.kind == RzBinDwarfAttr_SecOffset) {
ut64 offset = rz_bin_dwarf_attr_udata(&attr);
ht_up_insert(ctx->info->location_encoding,
offset, &cu->hdr.encoding);
}
}
default:
break;
}
Expand Down Expand Up @@ -309,6 +319,7 @@ RZ_API RZ_BORROW RzBinDwarfAttr *rz_bin_dwarf_die_get_attr(
static bool info_init(RzBinDwarfInfo *info) {
rz_vector_init(&info->units, sizeof(RzBinDwarfCompUnit), (RzVectorFree)CU_fini, NULL);
info->offset_comp_dir = ht_up_new(NULL, NULL, NULL);
info->location_encoding = ht_up_new0();
if (!info->offset_comp_dir) {
goto beach;
}
Expand All @@ -327,6 +338,7 @@ static inline void info_free(RzBinDwarfInfo *info) {
ht_up_free(info->offset_comp_dir);
ht_up_free(info->die_by_offset);
ht_up_free(info->unit_by_offset);
ht_up_free(info->location_encoding);
free(info);
}

Expand Down
8 changes: 6 additions & 2 deletions librz/core/canalysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -4670,14 +4670,18 @@ RZ_IPI void rz_core_analysis_function_until(RzCore *core, ut64 addr_end) {
rz_config_set(core->config, "analysis.limits", c ? c : "");
}

static bool archIsThumbable(RzCore *core) {
static bool arch_is(RzCore *core, const char *x) {
RzAsm *as = core ? core->rasm : NULL;
if (as && as->cur && as->bits <= 32 && as->cur->name) {
return strstr(as->cur->name, "arm");
return strstr(as->cur->name, x);
}
return false;
}

static bool archIsThumbable(RzCore *core) {
return arch_is(core, "arm");
}

static void _CbInRangeAav(RzCore *core, ut64 from, ut64 to, int vsize, void *user) {
bool pretend = (user && *(RzOutputMode *)user == RZ_OUTPUT_MODE_RIZIN);
int arch_align = rz_analysis_archinfo(core->analysis, RZ_ANALYSIS_ARCHINFO_TEXT_ALIGN);
Expand Down
9 changes: 6 additions & 3 deletions librz/core/cdwarf.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ RZ_API RZ_OWN char *rz_core_bin_dwarf_debug_info_to_string(

typedef struct {
RzBinDWARF *dw;
RzBinDwarfCompUnit *cu;
RzStrBuf *sb;
} DumpContext;

Expand All @@ -239,20 +238,24 @@ static bool htup_loclists_cb(void *u, ut64 k, const void *v) {
return false;
}
RzStrBuf *sb = ctx->sb;

rz_strbuf_appendf(sb, "0x%" PFMT64x "\n", loclist->offset);
void **it;
rz_pvector_foreach (&loclist->entries, it) {
RzBinDwarfLocListEntry *entry = *it;
rz_strbuf_appendf(sb, "\t(0x%" PFMT64x ", 0x%" PFMT64x ")\t", entry->range->begin, entry->range->end);
if (entry->expression) {
const RzBinDwarfEncoding *enc = ht_up_find(
ctx->dw->info->location_encoding, k, NULL);
if (!enc) {
continue;
}
RzBinDWARFDumpOption dump_opt = {
.loclist_sep = ",\t",
.loclist_indent = "",
.expr_sep = ", "
};
rz_bin_dwarf_expression_dump(
&ctx->cu->hdr.encoding, entry->expression, ctx->sb, &dump_opt);
enc, entry->expression, ctx->sb, &dump_opt);
}
rz_strbuf_append(sb, "\n");
}
Expand Down
1 change: 1 addition & 0 deletions librz/include/rz_bin_dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ typedef struct {
* that references this particular line information.
*/
HtUP /*<ut64, char *>*/ *offset_comp_dir;
HtUP /*<ut64, const RzBinDwarfEncoding*>*/ *location_encoding;
} RzBinDwarfInfo;

typedef struct {
Expand Down

0 comments on commit 9e96854

Please sign in to comment.