Skip to content

Commit

Permalink
DWARF: fix CU attributes parsing and application (#4148)
Browse files Browse the repository at this point in the history
  • Loading branch information
imbillow committed Jan 24, 2024
1 parent 54842b8 commit b32e00f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion librz/bin/dwarf/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ RZ_IPI bool RzBinDwarfAttr_parse(
// An index into the .debug_loc
case DW_FORM_loclistx:
value->kind = RzBinDwarfAttr_LoclistPtr;
RET_FALSE_IF_FAIL(read_offset(reader, &value->u64, is_64bit));
ULE128_OR_RET_FALSE(value->u64);
break;
// An index into the .debug_rnglists
case DW_FORM_rnglistx:
Expand Down
21 changes: 15 additions & 6 deletions librz/bin/dwarf/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ static void CU_attr_apply(DebugInfoContext *ctx, RzBinDwarfCompUnit *cu, RzBinDw
cu->language = rz_bin_dwarf_attr_udata(attr);
break;
case DW_AT_low_pc:
cu->low_pc = rz_bin_dwarf_attr_udata(attr);
cu->low_pc = rz_bin_dwarf_attr_addr(attr, ctx->dw, cu->hdr.encoding.address_size, cu->addr_base);
break;
case DW_AT_high_pc:
cu->high_pc = rz_bin_dwarf_attr_udata(attr);
cu->high_pc = rz_bin_dwarf_attr_addr(attr, ctx->dw, cu->hdr.encoding.address_size, cu->addr_base);
break;
case DW_AT_stmt_list:
cu->stmt_list = rz_bin_dwarf_attr_udata(attr);
Expand Down Expand Up @@ -70,6 +70,13 @@ static void CU_attr_apply(DebugInfoContext *ctx, RzBinDwarfCompUnit *cu, RzBinDw
}
}

static void apply_attr_opt(DebugInfoContext *ctx, RzBinDwarfCompUnit *cu, RzBinDwarfDie *die, DW_AT at) {
RzBinDwarfAttr *attr = rz_bin_dwarf_die_get_attr(die, at);
if (attr) {
CU_attr_apply(ctx, cu, attr);
}
}

static bool CU_attrs_parse(
DebugInfoContext *ctx,
RzBinDwarfDie *die,
Expand Down Expand Up @@ -109,10 +116,12 @@ static bool CU_attrs_parse(

if (die->tag == DW_TAG_compile_unit ||
die->tag == DW_TAG_skeleton_unit) {
RzBinDwarfAttr *str_offset_base = rz_bin_dwarf_die_get_attr(die, DW_AT_str_offsets_base);
if (str_offset_base) {
CU_attr_apply(ctx, cu, str_offset_base);
}
apply_attr_opt(ctx, cu, die, DW_AT_str_offsets_base);
apply_attr_opt(ctx, cu, die, DW_AT_addr_base);
apply_attr_opt(ctx, cu, die, DW_AT_GNU_addr_base);
apply_attr_opt(ctx, cu, die, DW_AT_GNU_ranges_base);
apply_attr_opt(ctx, cu, die, DW_AT_loclists_base);
apply_attr_opt(ctx, cu, die, DW_AT_rnglists_base);
RzBinDwarfAttr *attr;
rz_vector_foreach(&die->attrs, attr) {
CU_attr_apply(ctx, cu, attr);
Expand Down
3 changes: 1 addition & 2 deletions librz/include/rz_bin_dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -1849,9 +1849,8 @@ static inline ut64 rz_bin_dwarf_attr_addr(
ut64 addr = 0;
if (dw && rz_bin_dwarf_addr_get(dw->addr, &addr, addr_size, base, attr->value.u64)) {
return addr;
} else {
rz_warn_if_reached();
}
rz_warn_if_reached();
} else if (v->kind == RzBinDwarfAttr_UConstant) {
return attr->value.u64;
} else {
Expand Down

0 comments on commit b32e00f

Please sign in to comment.