diff --git a/librz/bin/dwarf/unit.c b/librz/bin/dwarf/unit.c index cb916a947d..3fb8dbdf78 100644 --- a/librz/bin/dwarf/unit.c +++ b/librz/bin/dwarf/unit.c @@ -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; } @@ -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; } @@ -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); } diff --git a/librz/core/canalysis.c b/librz/core/canalysis.c index 34ee18cde3..232fac732d 100644 --- a/librz/core/canalysis.c +++ b/librz/core/canalysis.c @@ -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); diff --git a/librz/core/cdwarf.c b/librz/core/cdwarf.c index 34e44becb8..c55d94d021 100644 --- a/librz/core/cdwarf.c +++ b/librz/core/cdwarf.c @@ -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; @@ -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"); } diff --git a/librz/include/rz_bin_dwarf.h b/librz/include/rz_bin_dwarf.h index 7f78e7c4c9..a26940b7a8 100644 --- a/librz/include/rz_bin_dwarf.h +++ b/librz/include/rz_bin_dwarf.h @@ -1097,6 +1097,7 @@ typedef struct { * that references this particular line information. */ HtUP /**/ *offset_comp_dir; + HtUP /**/ *location_encoding; } RzBinDwarfInfo; typedef struct {