From 7637377a45a3950e2ace3df9e32e0699306d000d Mon Sep 17 00:00:00 2001 From: billow Date: Sat, 30 Nov 2024 20:43:27 +0800 Subject: [PATCH] fix: DWARF5 DW_FORM_strx and '.debug_str_offsets' section load (#4752) * Fix dwarf5 DW_FORM_strx and '.debug_str_offsets' section load * Add 'cb_dwo_path' and fix dwo load * Add test --- librz/arch/dwarf_process.c | 5 +- librz/bin/dwarf/abbrev.c | 4 +- librz/bin/dwarf/addr.c | 2 +- librz/bin/dwarf/aranges.c | 2 +- librz/bin/dwarf/attr.c | 8 +- librz/bin/dwarf/dwarf.c | 41 ++++----- librz/bin/dwarf/dwarf_private.h | 4 +- librz/bin/dwarf/endian_reader.c | 57 +++++++++--- librz/bin/dwarf/line.c | 5 +- librz/bin/dwarf/line_str.c | 2 +- librz/bin/dwarf/loclists.c | 7 +- librz/bin/dwarf/op.c | 2 +- librz/bin/dwarf/rnglists.c | 7 +- librz/bin/dwarf/str.c | 4 +- librz/bin/dwarf/str_offsets.c | 4 +- librz/bin/dwarf/unit.c | 35 ++++++-- librz/core/cbin.c | 12 +-- librz/core/cconfig.c | 14 ++- librz/include/rz_bin_dwarf.h | 45 +++++----- test/db/cmd/dwarf | 103 ++++++++++++++++++++++ test/integration/test_dwarf.c | 36 ++++---- test/integration/test_dwarf_integration.c | 2 +- 22 files changed, 282 insertions(+), 119 deletions(-) diff --git a/librz/arch/dwarf_process.c b/librz/arch/dwarf_process.c index 247121cba6b..6ad0193bc41 100644 --- a/librz/arch/dwarf_process.c +++ b/librz/arch/dwarf_process.c @@ -1365,7 +1365,7 @@ static RzBinDwarfLocation *location_parse( return NULL; } ut64 offset = rz_bin_dwarf_attr_udata(attr); - RzBinDwarfLocList *loclist = rz_bin_dwarf_loclists_get(ctx->dw->loclists, ctx->dw->addr, ctx->unit, offset); + RzBinDwarfLocList *loclist = rz_bin_dwarf_loclists_get(ctx->dw->loclists, rz_bin_dwarf_addr(ctx->dw), ctx->unit, offset); if (!loclist) { /* for some reason offset isn't there, wrong parsing or malformed dwarf */ goto err_find; } @@ -1672,7 +1672,8 @@ 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; + RzBinDwarfLine *dw_line = rz_bin_dwarf_line(ctx->dw); + RzBinDwarfLineUnit *lu = ctx->unit && dw_line ? rz_pvector_at(dw_line->units, ctx->unit->index) : NULL; 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; diff --git a/librz/bin/dwarf/abbrev.c b/librz/bin/dwarf/abbrev.c index 8990349be36..20bad156a84 100644 --- a/librz/bin/dwarf/abbrev.c +++ b/librz/bin/dwarf/abbrev.c @@ -168,9 +168,9 @@ RZ_API RZ_OWN RzBinDwarfAbbrev *rz_bin_dwarf_abbrev_new(RZ_OWN RZ_NONNULL RzBinE * \return RzBinDwarfAbbrevs object */ RZ_API RZ_OWN RzBinDwarfAbbrev *rz_bin_dwarf_abbrev_from_file( - RZ_BORROW RZ_NONNULL RzBinFile *bf, bool is_dwo) { + RZ_BORROW RZ_NONNULL RzBinFile *bf) { rz_return_val_if_fail(bf, NULL); - RzBinEndianReader *r = RzBinEndianReader_from_file(bf, ".debug_abbrev", is_dwo); + RzBinEndianReader *r = RzBinEndianReader_from_file(bf, ".debug_abbrev"); RET_NULL_IF_FAIL(r); return rz_bin_dwarf_abbrev_new(r); } diff --git a/librz/bin/dwarf/addr.c b/librz/bin/dwarf/addr.c index 8bbb6c360a7..9757df313eb 100644 --- a/librz/bin/dwarf/addr.c +++ b/librz/bin/dwarf/addr.c @@ -34,7 +34,7 @@ RZ_API RZ_OWN RzBinDwarfAddr *rz_bin_dwarf_addr_new(RZ_OWN RZ_NONNULL RzBinEndia RZ_API RZ_OWN RzBinDwarfAddr *rz_bin_dwarf_addr_from_file(RZ_BORROW RZ_NONNULL RzBinFile *bf) { rz_return_val_if_fail(bf, NULL); - RzBinEndianReader *r = RzBinEndianReader_from_file(bf, ".debug_addr", false); + RzBinEndianReader *r = RzBinEndianReader_from_file(bf, ".debug_addr"); RET_NULL_IF_FAIL(r); return rz_bin_dwarf_addr_new(r); } diff --git a/librz/bin/dwarf/aranges.c b/librz/bin/dwarf/aranges.c index 17d3bffc50a..891aaf26956 100644 --- a/librz/bin/dwarf/aranges.c +++ b/librz/bin/dwarf/aranges.c @@ -114,7 +114,7 @@ RZ_API RZ_OWN RzBinDwarfARanges *rz_bin_dwarf_aranges_new(RZ_NONNULL RZ_OWN RzBi */ RZ_API RZ_OWN RzBinDwarfARanges *rz_bin_dwarf_aranges_from_file(RZ_BORROW RZ_NONNULL RzBinFile *bf) { rz_return_val_if_fail(bf, NULL); - RzBinEndianReader *R = RzBinEndianReader_from_file(bf, ".debug_aranges", false); + RzBinEndianReader *R = RzBinEndianReader_from_file(bf, ".debug_aranges"); RET_NULL_IF_FAIL(R); return rz_bin_dwarf_aranges_new(R); } diff --git a/librz/bin/dwarf/attr.c b/librz/bin/dwarf/attr.c index e8a356fbe9a..27f3dc76bba 100644 --- a/librz/bin/dwarf/attr.c +++ b/librz/bin/dwarf/attr.c @@ -134,7 +134,7 @@ RZ_IPI bool RzBinDwarfAttr_parse( /// offset into .debug_str_offsets section case DW_FORM_strx: value->kind = RzBinDwarfAttr_StrOffsetIndex; - RET_FALSE_IF_FAIL(R_read_offset(R, &value->u64, is_64bit)); + ULE128_OR_RET_FALSE(value->u64); break; case DW_FORM_strx1: value->kind = RzBinDwarfAttr_StrOffsetIndex; @@ -232,7 +232,7 @@ RZ_API const char *rz_bin_dwarf_attr_string( } else if (v->kind == RzBinDwarfAttr_StrOffsetIndex && dw) { orig = rz_bin_dwarf_str_offsets_get(dw->str, dw->str_offsets, str_offsets_base, v->u64); } else if (v->kind == RzBinDwarfAttr_LineStrRef && dw) { - orig = rz_bin_dwarf_line_str_get(dw->line_str, v->u64); + orig = rz_bin_dwarf_line_str_get(rz_bin_dwarf_line_str(dw), v->u64); } return orig; } @@ -265,11 +265,11 @@ RZ_API void rz_bin_dwarf_attr_dump( switch (attr->at) { case DW_AT_language: - rz_strbuf_append(sb, rz_bin_dwarf_lang(attr->value.u64)); + rz_strbuf_append(sb, rz_str_get_null(rz_bin_dwarf_lang(attr->value.u64))); rz_strbuf_append(sb, ", raw: "); break; case DW_AT_encoding: - rz_strbuf_append(sb, rz_bin_dwarf_ate(attr->value.u64)); + rz_strbuf_append(sb, rz_str_get_null(rz_bin_dwarf_ate(attr->value.u64))); rz_strbuf_append(sb, ", raw: "); break; default: break; diff --git a/librz/bin/dwarf/dwarf.c b/librz/bin/dwarf/dwarf.c index 5233f4813c9..086f2dad79c 100644 --- a/librz/bin/dwarf/dwarf.c +++ b/librz/bin/dwarf/dwarf.c @@ -21,26 +21,27 @@ RZ_IPI bool RzBinDwarfEncoding_from_file(RzBinDwarfEncoding *encoding, RzBinFile } static inline RZ_OWN RzBinDWARF *dwarf_from_file( - RZ_BORROW RZ_NONNULL RzBinFile *bf, bool is_dwo) { + RZ_BORROW RZ_NONNULL RzBinFile *bf, RZ_BORROW RZ_NULLABLE RzBinDWARF *parent) { rz_return_val_if_fail(bf, NULL); RzBinDWARF *dw = RZ_NEW0(RzBinDWARF); RET_NULL_IF_FAIL(dw); + dw->parent = parent; dw->addr = rz_bin_dwarf_addr_from_file(bf); dw->line_str = rz_bin_dwarf_line_str_from_file(bf); dw->aranges = rz_bin_dwarf_aranges_from_file(bf); - dw->str = rz_bin_dwarf_str_from_file(bf, is_dwo); - dw->str_offsets = rz_bin_dwarf_str_offsets_from_file(bf, is_dwo); - dw->loclists = rz_bin_dwarf_loclists_new_from_file(bf, is_dwo); - dw->rnglists = rz_bin_dwarf_rnglists_new_from_file(bf, is_dwo); - dw->abbrev = rz_bin_dwarf_abbrev_from_file(bf, is_dwo); + dw->str = rz_bin_dwarf_str_from_file(bf); + dw->str_offsets = rz_bin_dwarf_str_offsets_from_file(bf); + dw->loclists = rz_bin_dwarf_loclists_new_from_file(bf); + dw->rnglists = rz_bin_dwarf_rnglists_new_from_file(bf); + dw->abbrev = rz_bin_dwarf_abbrev_from_file(bf); if (dw->abbrev) { - dw->info = rz_bin_dwarf_info_from_file(bf, dw, is_dwo); + dw->info = rz_bin_dwarf_info_from_file(dw, bf); } if (dw->info) { - dw->line = rz_bin_dwarf_line_from_file(bf, dw, is_dwo); + dw->line = rz_bin_dwarf_line_from_file(dw, bf); } if (!(dw->addr || dw->line_str || dw->aranges || dw->str || dw->str_offsets || dw->loclists || dw->rnglists || dw->abbrev)) { rz_bin_dwarf_free(dw); @@ -54,7 +55,7 @@ static inline char *read_debuglink(RzBinFile *binfile) { const char *name = NULL; RzBinEndianReader *R = NULL; RET_NULL_IF_FAIL( - (sect = rz_bin_dwarf_section_by_name(binfile, ".gnu_debuglink", false)) && + (sect = rz_bin_dwarf_section_by_name(binfile, ".gnu_debuglink")) && (R = rz_bin_dwarf_section_reader(binfile, sect)) && R_read_cstring(R, &name)); // TODO: Verification the CRC @@ -64,7 +65,7 @@ static inline char *read_debuglink(RzBinFile *binfile) { } static inline char *read_build_id(RzBinFile *binfile) { - RzBinSection *sect = rz_bin_dwarf_section_by_name(binfile, ".note.gnu.build-id", false); + RzBinSection *sect = rz_bin_dwarf_section_by_name(binfile, ".note.gnu.build-id"); RET_NULL_IF_FAIL(sect); RzBinEndianReader *R = rz_bin_dwarf_section_reader(binfile, sect); RET_NULL_IF_FAIL(R); @@ -129,7 +130,7 @@ static inline RzBinDWARF *dwarf_from_debuglink( free(file_dir); return NULL; ok: - dw = rz_bin_dwarf_from_path(path, false); + dw = rz_bin_dwarf_from_path(path, NULL); free(dir); free(path); free(file_dir); @@ -145,7 +146,7 @@ static inline RzBinDWARF *dwarf_from_build_id( char *dir = rz_file_path_join(debug_file_directory, ".build-id"); char *path = rz_file_path_join(dir, build_id_path); if (rz_file_exists(path)) { - RzBinDWARF *dw = rz_bin_dwarf_from_path(path, false); + RzBinDWARF *dw = rz_bin_dwarf_from_path(path, NULL); free(dir); free(path); return dw; @@ -288,7 +289,7 @@ RZ_API RZ_OWN RzBinDWARF *rz_bin_dwarf_from_debuginfod( if (!url) { break; } - dw = rz_bin_dwarf_from_path(url, false); + dw = rz_bin_dwarf_from_path(url, NULL); free(url); if (dw) { break; @@ -304,24 +305,24 @@ RZ_API RZ_OWN RzBinDWARF *rz_bin_dwarf_from_debuginfod( * \return RzBinDWARF pointer or NULL if failed */ RZ_API RZ_OWN RzBinDWARF *rz_bin_dwarf_from_path( - RZ_BORROW RZ_NONNULL const char *filepath, bool is_dwo) { + RZ_BORROW RZ_NONNULL const char *filepath, RZ_BORROW RZ_NULLABLE RzBinDWARF *parent) { rz_return_val_if_fail(filepath, NULL); - RzBinDWARF *dwo = NULL; + RzBinDWARF *dw = NULL; DwBinary binary = { 0 }; if (!binary_from_path(&binary, filepath)) { goto beach; } - dwo = dwarf_from_file(binary.bf, is_dwo); + dw = dwarf_from_file(binary.bf, parent); beach: binary_close(&binary); - return dwo; + return dw; } RZ_API RZ_OWN RzBinDWARF *rz_bin_dwarf_from_file( RZ_BORROW RZ_NONNULL RzBinFile *bf) { - return dwarf_from_file(bf, false); + return dwarf_from_file(bf, NULL); } RZ_API void rz_bin_dwarf_free(RZ_OWN RZ_NULLABLE RzBinDWARF *dw) { @@ -363,7 +364,7 @@ RZ_API void rz_bin_dwarf_dump( if (dw->rnglists) { rz_bin_dwarf_rnglists_dump(dw->rnglists, sb); } - if (dw->line) { - rz_bin_dwarf_line_units_dump(dw->line, sb); + if (rz_bin_dwarf_line(dw)) { + rz_bin_dwarf_line_units_dump(rz_bin_dwarf_line(dw), sb); } } diff --git a/librz/bin/dwarf/dwarf_private.h b/librz/bin/dwarf/dwarf_private.h index cd0161119df..a9a72a903b4 100644 --- a/librz/bin/dwarf/dwarf_private.h +++ b/librz/bin/dwarf/dwarf_private.h @@ -23,12 +23,12 @@ typedef RzBinDwarfLocation Location; RZ_IPI bool ListsHdr_parse(RzBinDwarfListsHdr *hdr, RzBinEndianReader *R); -RZ_IPI RzBinSection *rz_bin_dwarf_section_by_name(RzBinFile *binfile, const char *sn, bool is_dwo); +RZ_IPI RzBinSection *rz_bin_dwarf_section_by_name(RzBinFile *binfile, const char *sn); RZ_IPI bool RzBinDwarfAttr_parse(RzBinEndianReader *R, RzBinDwarfAttr *attr, AttrOption *opt); RZ_IPI RzBinEndianReader *RzBinEndianReader_from_file( - RzBinFile *binfile, const char *sect_name, bool is_dwo); + RzBinFile *binfile, const char *sect_name); static inline bool bf_bigendian(RzBinFile *bf) { return bf->o && bf->o->info && bf->o->info->big_endian; diff --git a/librz/bin/dwarf/endian_reader.c b/librz/bin/dwarf/endian_reader.c index 7e22be9ec87..3d1cdf543eb 100644 --- a/librz/bin/dwarf/endian_reader.c +++ b/librz/bin/dwarf/endian_reader.c @@ -6,7 +6,28 @@ #include "dwarf_private.h" #include "../format/elf/elf.h" -RZ_IPI RzBinSection *rz_bin_dwarf_section_by_name(RzBinFile *binfile, const char *sn, bool is_dwo) { +typedef struct { + const char *name; + const char *alias[8]; +} SectionAlias; + +static const SectionAlias section_alias[] = { + { .name = ".debug_str_offsets", .alias = { ".__DWARF.__debug_str_offs", ".debug_str_offsets.dwo", NULL } }, + { .name = ".debug_str", .alias = { ".debug_str.dwo", NULL } }, + { .name = ".debug_addr", .alias = { ".debug_addr.dwo", NULL } }, + { .name = ".debug_line_str", .alias = { ".debug_line_str.dwo", NULL } }, + { .name = ".debug_aranges", .alias = { ".debug_aranges.dwo", NULL } }, + { .name = ".debug_loclists", .alias = { ".debug_loclists.dwo", NULL } }, + { .name = ".debug_loc", .alias = { ".debug_loc.dwo", NULL } }, + { .name = ".debug_rnglists", .alias = { ".debug_rnglists.dwo", NULL } }, + { .name = ".debug_ranges", .alias = { ".debug_ranges.dwo", NULL } }, + { .name = ".debug_abbrev", .alias = { ".debug_abbrev.dwo", NULL } }, + { .name = ".debug_info", .alias = { ".debug_info.dwo", NULL } }, + { .name = ".debug_line", .alias = { ".debug_line.dwo", NULL } }, + +}; + +RZ_IPI RzBinSection *rz_bin_dwarf_section_by_name(RzBinFile *binfile, const char *sn) { rz_return_val_if_fail(binfile && sn, NULL); void **iter = NULL; RzBinSection *section = NULL; @@ -15,22 +36,34 @@ RZ_IPI RzBinSection *rz_bin_dwarf_section_by_name(RzBinFile *binfile, const char if (!o || !o->sections || RZ_STR_ISEMPTY(sn)) { return NULL; } - char *name = is_dwo ? rz_str_newf("%s.dwo", sn) : rz_str_dup(sn); - if (!name) { - return NULL; - } rz_pvector_foreach (o->sections, iter) { section = *iter; if (!section->name) { continue; } - if (RZ_STR_EQ(section->name, name) || - rz_str_endswith(section->name, name + 1)) { - result_section = section; - break; + if (!rz_str_endswith(section->name, sn + 1)) { + continue; } + result_section = section; + goto beach; } - free(name); + for (int i = 0; i < RZ_ARRAY_SIZE(section_alias); ++i) { + const SectionAlias *alias = section_alias + i; + if (RZ_STR_NE(sn, alias->name)) { + continue; + } + rz_pvector_foreach (o->sections, iter) { + section = *iter; + for (const char **x = (const char **)alias->alias; RZ_STR_ISNOTEMPTY(*x); ++x) { + if (rz_str_endswith(section->name, *x)) { + result_section = section; + goto beach; + } + } + } + } + +beach: return result_section; } @@ -140,9 +173,9 @@ static inline void add_relocations( } } -RZ_IPI RzBinEndianReader *RzBinEndianReader_from_file(RzBinFile *binfile, const char *sect_name, bool is_dwo) { +RZ_IPI RzBinEndianReader *RzBinEndianReader_from_file(RzBinFile *binfile, const char *sect_name) { rz_return_val_if_fail(binfile && sect_name, NULL); - RzBinSection *section = rz_bin_dwarf_section_by_name(binfile, sect_name, is_dwo); + RzBinSection *section = rz_bin_dwarf_section_by_name(binfile, sect_name); OK_OR(section, return NULL); RzBinEndianReader *R = rz_bin_dwarf_section_reader(binfile, section); OK_OR(R, return NULL); diff --git a/librz/bin/dwarf/line.c b/librz/bin/dwarf/line.c index 22a086280d9..3ad240bd98f 100644 --- a/librz/bin/dwarf/line.c +++ b/librz/bin/dwarf/line.c @@ -726,16 +726,15 @@ RZ_API RZ_OWN RzBinDwarfLine *rz_bin_dwarf_line_new( * \return RzBinDwarfLineInfo or NULL if failed */ RZ_API RZ_OWN RzBinDwarfLine *rz_bin_dwarf_line_from_file( - RZ_BORROW RZ_NONNULL RzBinFile *bf, RZ_BORROW RZ_NULLABLE RzBinDWARF *dw, - bool is_dwo) { + RZ_BORROW RZ_NONNULL RzBinFile *bf) { rz_return_val_if_fail(bf, NULL); RzBinDwarfEncoding encoding = { 0 }; if (!RzBinDwarfEncoding_from_file(&encoding, bf)) { return NULL; } - RzBinEndianReader *R = RzBinEndianReader_from_file(bf, ".debug_line", is_dwo); + RzBinEndianReader *R = RzBinEndianReader_from_file(bf, ".debug_line"); RET_NULL_IF_FAIL(R); return Line_parse(R, &encoding, dw); } diff --git a/librz/bin/dwarf/line_str.c b/librz/bin/dwarf/line_str.c index cc9f790f8b3..d2cfc719cd0 100644 --- a/librz/bin/dwarf/line_str.c +++ b/librz/bin/dwarf/line_str.c @@ -9,7 +9,7 @@ RZ_API RZ_OWN RzBinDwarfLineStr *rz_bin_dwarf_line_str_new(RZ_NONNULL RZ_OWN RzB } RZ_API RZ_OWN RzBinDwarfLineStr *rz_bin_dwarf_line_str_from_file(RZ_NONNULL RZ_BORROW RzBinFile *bf) { - RzBinEndianReader *R = RzBinEndianReader_from_file(bf, ".debug_line_str", false); + RzBinEndianReader *R = RzBinEndianReader_from_file(bf, ".debug_line_str"); RET_NULL_IF_FAIL(R); return rz_bin_dwarf_str_new(R); } diff --git a/librz/bin/dwarf/loclists.c b/librz/bin/dwarf/loclists.c index 86925ba5ad5..80916d3c329 100644 --- a/librz/bin/dwarf/loclists.c +++ b/librz/bin/dwarf/loclists.c @@ -312,11 +312,10 @@ RZ_API RZ_OWN RzBinDwarfLocLists *rz_bin_dwarf_loclists_new(RzBinEndianReader *l * \param dw RzBinDwarf instance * \return RzBinDwarfLocListTable instance on success, NULL otherwise */ -RZ_API RZ_OWN RzBinDwarfLocLists *rz_bin_dwarf_loclists_new_from_file( - RZ_BORROW RZ_NONNULL RzBinFile *bf, bool is_dwo) { +RZ_API RZ_OWN RzBinDwarfLocLists *rz_bin_dwarf_loclists_new_from_file(RZ_BORROW RZ_NONNULL RzBinFile *bf) { RET_NULL_IF_FAIL(bf); - RzBinEndianReader *loclists = RzBinEndianReader_from_file(bf, ".debug_loclists", is_dwo); - RzBinEndianReader *loc = RzBinEndianReader_from_file(bf, ".debug_loc", is_dwo); + RzBinEndianReader *loclists = RzBinEndianReader_from_file(bf, ".debug_loclists"); + RzBinEndianReader *loc = RzBinEndianReader_from_file(bf, ".debug_loc"); if (!(loclists || loc)) { R_free(loclists); R_free(loc); diff --git a/librz/bin/dwarf/op.c b/librz/bin/dwarf/op.c index 2ce68532a4f..66ff828cdb2 100644 --- a/librz/bin/dwarf/op.c +++ b/librz/bin/dwarf/op.c @@ -1119,7 +1119,7 @@ static bool Evaluation_evaluate_one_operation( } case OPERATION_KIND_ADDRESS_INDEX: { ut64 addr = 0; - if (self->dw && self->unit && rz_bin_dwarf_addr_get(self->dw->addr, &addr, self->unit->hdr.encoding.address_size, self->unit->addr_base, operation.address_index.index)) { + if (self->dw && self->unit && rz_bin_dwarf_addr(self->dw) && rz_bin_dwarf_addr_get(rz_bin_dwarf_addr(self->dw), &addr, self->unit->hdr.encoding.address_size, self->unit->addr_base, operation.address_index.index)) { out->kind = OperationEvaluationResult_COMPLETE; out->complete.kind = RzBinDwarfLocationKind_ADDRESS; out->complete.address = addr; diff --git a/librz/bin/dwarf/rnglists.c b/librz/bin/dwarf/rnglists.c index 19fc6ae0382..8bfb8c637f7 100644 --- a/librz/bin/dwarf/rnglists.c +++ b/librz/bin/dwarf/rnglists.c @@ -286,11 +286,10 @@ RZ_API RZ_OWN RzBinDwarfRngLists *rz_bin_dwarf_rnglists_new( * \param dw the RzBinDWARF instance * \return the RzBinDwarfRngListTable instance on success, NULL otherwise */ -RZ_API RZ_OWN RzBinDwarfRngLists *rz_bin_dwarf_rnglists_new_from_file( - RZ_BORROW RZ_NONNULL RzBinFile *bf, bool is_dwo) { +RZ_API RZ_OWN RzBinDwarfRngLists *rz_bin_dwarf_rnglists_new_from_file(RZ_BORROW RZ_NONNULL RzBinFile *bf) { RET_NULL_IF_FAIL(bf); - RzBinEndianReader *rnglists = RzBinEndianReader_from_file(bf, ".debug_rnglists", is_dwo); - RzBinEndianReader *ranges = RzBinEndianReader_from_file(bf, ".debug_ranges", is_dwo); + RzBinEndianReader *rnglists = RzBinEndianReader_from_file(bf, ".debug_rnglists"); + RzBinEndianReader *ranges = RzBinEndianReader_from_file(bf, ".debug_ranges"); if (!(rnglists || ranges)) { R_free(rnglists); R_free(ranges); diff --git a/librz/bin/dwarf/str.c b/librz/bin/dwarf/str.c index 26278c7b83d..0c07f690a45 100644 --- a/librz/bin/dwarf/str.c +++ b/librz/bin/dwarf/str.c @@ -12,10 +12,10 @@ RZ_API RZ_OWN RzBinDwarfStr *rz_bin_dwarf_str_new(RZ_NONNULL RZ_OWN RzBinEndianR return str; } -RZ_API RZ_OWN RzBinDwarfStr *rz_bin_dwarf_str_from_file(RZ_NONNULL RZ_BORROW RzBinFile *bf, bool is_dwo) { +RZ_API RZ_OWN RzBinDwarfStr *rz_bin_dwarf_str_from_file(RZ_NONNULL RZ_BORROW RzBinFile *bf) { rz_return_val_if_fail(bf, NULL); RzBinEndianReader *r = RzBinEndianReader_from_file( - bf, ".debug_str", is_dwo); + bf, ".debug_str"); RET_NULL_IF_FAIL(r); return rz_bin_dwarf_str_new(r); } diff --git a/librz/bin/dwarf/str_offsets.c b/librz/bin/dwarf/str_offsets.c index 755d0cdaad2..22b2e73f0a9 100644 --- a/librz/bin/dwarf/str_offsets.c +++ b/librz/bin/dwarf/str_offsets.c @@ -22,10 +22,10 @@ RZ_API RZ_OWN RzBinDwarfStrOffsets *rz_bin_dwarf_str_offsets_from_buf( } RZ_API RZ_OWN RzBinDwarfStrOffsets *rz_bin_dwarf_str_offsets_from_file( - RZ_NONNULL RZ_BORROW RzBinFile *bf, bool is_dwo) { + RZ_NONNULL RZ_BORROW RzBinFile *bf) { rz_return_val_if_fail(bf, NULL); RzBinEndianReader *r = RzBinEndianReader_from_file( - bf, ".debug_str_offsets", is_dwo); + bf, ".debug_str_offsets"); RET_NULL_IF_FAIL(r); return rz_bin_dwarf_str_offsets_from_buf(r); } diff --git a/librz/bin/dwarf/unit.c b/librz/bin/dwarf/unit.c index 32ec2c93e44..d9cc8e78252 100644 --- a/librz/bin/dwarf/unit.c +++ b/librz/bin/dwarf/unit.c @@ -72,9 +72,9 @@ 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); - } + if (!attr) + return; + CU_attr_apply(ctx, cu, attr); } static bool CU_attrs_parse( @@ -233,8 +233,9 @@ static bool CU_dies_parse( /** * \brief Reads all information about compilation unit header */ -static bool CU_Hdr_parse(DebugInfoContext *ctx, RzBinDwarfCompUnitHdr *hdr) { +static bool CU_Hdr_parse(DebugInfoContext *ctx, RzBinDwarfCompUnit *cu) { RzBinEndianReader *R = ctx->info->R; + RzBinDwarfCompUnitHdr *hdr = &cu->hdr; RET_FALSE_IF_FAIL(R_read_initial_length(R, &hdr->encoding.is_64bit, &hdr->length)); RET_FALSE_IF_FAIL(hdr->length <= R_remain(R)); ut64 offset_start = R_tell(R); @@ -251,6 +252,23 @@ static bool CU_Hdr_parse(DebugInfoContext *ctx, RzBinDwarfCompUnitHdr *hdr) { U_OR_RET_FALSE(64, hdr->type_sig); RET_FALSE_IF_FAIL(R_read_offset(R, &hdr->type_offset, hdr->encoding.is_64bit)); } + if (hdr->ut == DW_UT_split_compile && ctx->dw->parent && ctx->dw->parent->info) { + RzBinDwarfInfo *info = ctx->dw->parent->info; + RzBinDwarfCompUnit *skeleton_cu = NULL; + rz_vector_foreach (&info->units, skeleton_cu) { + if (!(skeleton_cu->hdr.dwo_id == hdr->dwo_id && skeleton_cu->hdr.ut == DW_UT_skeleton)) { + continue; + } + cu->str_offsets_base = skeleton_cu->str_offsets_base; + cu->addr_base = skeleton_cu->addr_base; + cu->loclists_base = skeleton_cu->loclists_base; + cu->rnglists_base = skeleton_cu->rnglists_base; + cu->stmt_list = skeleton_cu->stmt_list; + cu->comp_dir = skeleton_cu->comp_dir; + cu->low_pc = skeleton_cu->low_pc; + cu->high_pc = skeleton_cu->high_pc; + } + } } else { RET_FALSE_IF_FAIL(R_read_offset(R, &hdr->abbrev_offset, hdr->encoding.is_64bit)); U8_OR_RET_FALSE(hdr->encoding.address_size); @@ -277,7 +295,7 @@ static bool CU_parse_all(DebugInfoContext *ctx) { if (CU_init(&unit) < 0) { goto cleanup; } - if (!CU_Hdr_parse(ctx, &unit.hdr)) { + if (!CU_Hdr_parse(ctx, &unit)) { break; } if (unit.hdr.length > R_size(buffer)) { @@ -409,12 +427,11 @@ RZ_API RZ_OWN RzBinDwarfInfo *rz_bin_dwarf_info_from_buf( * \return RzBinDwarfDebugInfo* Parsed information, NULL if error */ RZ_API RZ_OWN RzBinDwarfInfo *rz_bin_dwarf_info_from_file( - RZ_BORROW RZ_NONNULL RzBinFile *bf, - RZ_BORROW RZ_NONNULL RzBinDWARF *dw, - bool is_dwo) { + RZ_BORROW RZ_NULLABLE RzBinDWARF *dw, + RZ_BORROW RZ_NONNULL RzBinFile *bf) { rz_return_val_if_fail(bf && dw && dw->abbrev, NULL); RzBinEndianReader *R = RzBinEndianReader_from_file( - bf, ".debug_info", is_dwo); + bf, ".debug_info"); RET_NULL_IF_FAIL(R); return rz_bin_dwarf_info_from_buf(R, dw); } diff --git a/librz/core/cbin.c b/librz/core/cbin.c index 92647cd57a7..d9af06a80da 100644 --- a/librz/core/cbin.c +++ b/librz/core/cbin.c @@ -637,9 +637,8 @@ static inline RzBinDWARF *load_dwarf(RzCore *core, RzBinFile *binfile) { const char *dwo_path = rz_config_get(core->config, "bin.dbginfo.dwo_path"); if (RZ_STR_ISNOTEMPTY(dwo_path)) { - RzBinDWARF *dwo = rz_bin_dwarf_from_path(dwo_path, true); + RzBinDWARF *dwo = rz_bin_dwarf_from_path(dwo_path, dw); if (dwo) { - dwo->parent = dw; return dwo; } } @@ -711,7 +710,7 @@ RZ_API bool rz_core_bin_apply_dwarf(RzCore *core, RzBinFile *binfile) { rz_analysis_dwarf_process_info(core->analysis, dw); } - if (dw->line) { + if ((rz_bin_dwarf_line(dw))) { // move all produced rows line info out (TODO: bin loading should do that) if (!binfile->o->lines) { binfile->o->lines = RZ_NEW0(RzBinSourceLineInfo); @@ -720,7 +719,7 @@ RZ_API bool rz_core_bin_apply_dwarf(RzCore *core, RzBinFile *binfile) { } rz_str_constpool_init(&binfile->o->lines->filename_pool); } - rz_bin_source_line_info_merge(binfile->o->lines, dw->line->lines); + rz_bin_source_line_info_merge(binfile->o->lines, (rz_bin_dwarf_line(dw))->lines); } return true; } @@ -1794,8 +1793,9 @@ static bool bin_dwarf(RzCore *core, RzBinFile *binfile, RzCmdStateOutput *state) rz_bin_dwarf_dump(dw, &sb); rz_cons_strcat(rz_strbuf_drain_nofree(&sb)); } - if (dw->line && dw->line->lines) { - rz_core_bin_print_source_line_info(core, dw->line->lines, state); + RzBinDwarfLine *line = rz_bin_dwarf_line(dw); + if (line && line->lines) { + rz_core_bin_print_source_line_info(core, line->lines, state); } if (dw != core->analysis->debug_info->dw) { rz_bin_dwarf_free(dw); diff --git a/librz/core/cconfig.c b/librz/core/cconfig.c index 9e6336e135f..21f9ace5cd0 100644 --- a/librz/core/cconfig.c +++ b/librz/core/cconfig.c @@ -2603,6 +2603,18 @@ static bool cb_bindbginfo(void *user, void *data) { return true; } +static bool cb_dwo_path(void *user, void *data) { + RzCore *core = (RzCore *)user; + RzConfigNode *node = (RzConfigNode *)data; + if (!(core && core->bin && node)) { + return false; + } + if (RZ_STR_ISNOTEMPTY(node->value) && rz_bin_cur(core->bin)) { + rz_core_bin_apply_dwarf(core, rz_bin_cur(core->bin)); + } + return true; +} + static bool cb_binprefix(void *user, void *data) { RzCore *core = (RzCore *)user; RzConfigNode *node = (RzConfigNode *)data; @@ -3331,7 +3343,7 @@ RZ_API int rz_core_config_init(RzCore *core) { SETI("bin.baddr", -1, "Base address of the binary"); SETI("bin.laddr", 0, "Base address for loading library ('*.so')"); SETCB("bin.dbginfo", "true", &cb_bindbginfo, "Load debug information at startup if available"); - SETCB("bin.dbginfo.dwo_path", "", NULL, "Load separate debug information (DWARF) file if available"); + SETCB("bin.dbginfo.dwo_path", "", &cb_dwo_path, "Load separate debug information (DWARF) file if available"); SETCB("bin.dbginfo.debug_file_directory", "/usr/lib/debug", NULL, "Set the directories which searches for separate debugging information files to directory"); SETCB("bin.dbginfo.debuginfod", "false", NULL, diff --git a/librz/include/rz_bin_dwarf.h b/librz/include/rz_bin_dwarf.h index 95a79e7c804..574c170f42c 100644 --- a/librz/include/rz_bin_dwarf.h +++ b/librz/include/rz_bin_dwarf.h @@ -1443,6 +1443,19 @@ typedef struct rz_core_bin_dwarf_t { RzBinDwarfLineStr *line_str; } RzBinDWARF; +#define DWARF_FIELD_IMPL(T, F) \ + static inline T *rz_bin_dwarf_##F( \ + RZ_BORROW RZ_NONNULL const RzBinDWARF *dw) { \ + rz_return_val_if_fail(dw, NULL); \ + return dw->F ? dw->F : (dw->parent ? dw->parent->F : NULL); \ + } + +DWARF_FIELD_IMPL(RzBinDwarfAddr, addr); +DWARF_FIELD_IMPL(RzBinDwarfLine, line); +DWARF_FIELD_IMPL(RzBinDwarfLineStr, line_str); + +#undef DWARF_FIELD_IMPL + RZ_API const char *rz_bin_dwarf_tag(DW_TAG tag); RZ_API const char *rz_bin_dwarf_attr(DW_AT attr_code); RZ_API const char *rz_bin_dwarf_form(DW_FORM form_code); @@ -1458,7 +1471,7 @@ RZ_API const char *rz_bin_dwarf_ate(DW_ATE op); /// .debug_str RZ_API RZ_OWN RzBinDwarfStr *rz_bin_dwarf_str_new(RZ_NONNULL RZ_OWN RzBinEndianReader *R); -RZ_API RZ_OWN RzBinDwarfStr *rz_bin_dwarf_str_from_file(RZ_NONNULL RZ_BORROW RzBinFile *bf, bool is_dwo); +RZ_API RZ_OWN RzBinDwarfStr *rz_bin_dwarf_str_from_file(RZ_NONNULL RZ_BORROW RzBinFile *bf); RZ_API void rz_bin_dwarf_str_free(RZ_NULLABLE RzBinDwarfStr *str); RZ_API RZ_BORROW const char *rz_bin_dwarf_str_get(RZ_NONNULL RZ_BORROW RzBinDwarfStr *str, ut64 offset); @@ -1469,8 +1482,7 @@ RZ_API RZ_BORROW const char *rz_bin_dwarf_line_str_get(RZ_NONNULL RZ_BORROW RzBi /// .debug_str_offsets RZ_API RZ_OWN RzBinDwarfStrOffsets *rz_bin_dwarf_str_offsets_new(RZ_NONNULL RZ_OWN RzBinEndianReader *R); -RZ_API RZ_OWN RzBinDwarfStrOffsets *rz_bin_dwarf_str_offsets_from_file( - RZ_NONNULL RZ_BORROW RzBinFile *bf, bool is_dwo); +RZ_API RZ_OWN RzBinDwarfStrOffsets *rz_bin_dwarf_str_offsets_from_file(RZ_NONNULL RZ_BORROW RzBinFile *bf); RZ_API void rz_bin_dwarf_str_offsets_free(RZ_NULLABLE RzBinDwarfStrOffsets *str_offsets); RZ_API RZ_BORROW const char *rz_bin_dwarf_str_offsets_get( RZ_NONNULL RZ_BORROW RzBinDwarfStr *str, @@ -1488,8 +1500,7 @@ RZ_API void rz_bin_dwarf_aranges_dump( /// .debug_abbrev RZ_API RZ_OWN RzBinDwarfAbbrev *rz_bin_dwarf_abbrev_new(RZ_OWN RZ_NONNULL RzBinEndianReader *R); -RZ_API RZ_OWN RzBinDwarfAbbrev *rz_bin_dwarf_abbrev_from_file( - RZ_BORROW RZ_NONNULL RzBinFile *bf, bool is_dwo); +RZ_API RZ_OWN RzBinDwarfAbbrev *rz_bin_dwarf_abbrev_from_file(RZ_BORROW RZ_NONNULL RzBinFile *bf); RZ_API void rz_bin_dwarf_abbrev_free(RZ_OWN RZ_NULLABLE RzBinDwarfAbbrev *abbrevs); RZ_API size_t rz_bin_dwarf_abbrev_count(RZ_BORROW RZ_NONNULL const RzBinDwarfAbbrev *da); @@ -1506,9 +1517,8 @@ RZ_API RZ_OWN RzBinDwarfInfo *rz_bin_dwarf_info_from_buf( RZ_OWN RZ_NONNULL RzBinEndianReader *R, RZ_BORROW RZ_NONNULL RzBinDWARF *dw); RZ_API RZ_OWN RzBinDwarfInfo *rz_bin_dwarf_info_from_file( - RZ_BORROW RZ_NONNULL RzBinFile *bf, - RZ_BORROW RZ_NONNULL RzBinDWARF *dw, - bool is_dwo); + RZ_BORROW RZ_NULLABLE RzBinDWARF *dw, + RZ_BORROW RZ_NONNULL RzBinFile *bf); RZ_API void rz_bin_dwarf_info_free(RZ_OWN RZ_NULLABLE RzBinDwarfInfo *info); RZ_API RZ_BORROW RzBinDwarfAttr *rz_bin_dwarf_die_get_attr( RZ_BORROW RZ_NONNULL const RzBinDwarfDie *die, DW_AT name); @@ -1523,9 +1533,8 @@ RZ_API RZ_OWN RzBinDwarfLine *rz_bin_dwarf_line_new( RZ_BORROW RZ_NONNULL RzBinDwarfEncoding *encoding, RZ_BORROW RZ_NULLABLE RzBinDWARF *dw); RZ_API RZ_OWN RzBinDwarfLine *rz_bin_dwarf_line_from_file( - RZ_BORROW RZ_NONNULL RzBinFile *bf, RZ_BORROW RZ_NULLABLE RzBinDWARF *dw, - bool is_dwo); + RZ_BORROW RZ_NONNULL RzBinFile *bf); RZ_API void rz_bin_dwarf_line_free(RZ_OWN RZ_NULLABLE RzBinDwarfLine *li); RZ_API void rz_bin_dwarf_line_units_dump( RZ_NONNULL RZ_BORROW RzBinDwarfLine *line, @@ -1536,7 +1545,8 @@ RZ_API char *rz_bin_dwarf_file_path(RZ_NONNULL RZ_BORROW RzBinDWARF *dw, /// dwarf RZ_API RZ_OWN RzBinDWARF *rz_bin_dwarf_from_file(RZ_BORROW RZ_NONNULL RzBinFile *bf); RZ_API RZ_OWN RzBinDWARF *rz_bin_dwarf_from_path( - RZ_BORROW RZ_NONNULL const char *filepath, bool is_dwo); + RZ_BORROW RZ_NONNULL const char *filepath, + RZ_BORROW RZ_NULLABLE RzBinDWARF *parent); RZ_API RZ_OWN RzBinDWARF *rz_bin_dwarf_load_dsym(RZ_BORROW RZ_NONNULL RzBinFile *bf); RZ_API RZ_OWN RzBinDWARF *rz_bin_dwarf_search_debug_file_directory( RZ_BORROW RZ_NONNULL RzBinFile *bf, @@ -1807,8 +1817,7 @@ RZ_API RzBinDwarfLocList *rz_bin_dwarf_loclists_get( ut64 offset); RZ_API RZ_OWN RzBinDwarfLocLists *rz_bin_dwarf_loclists_new( RzBinEndianReader *loclists, RzBinEndianReader *loc); -RZ_API RZ_OWN RzBinDwarfLocLists *rz_bin_dwarf_loclists_new_from_file( - RZ_BORROW RZ_NONNULL RzBinFile *bf, bool is_dwo); +RZ_API RZ_OWN RzBinDwarfLocLists *rz_bin_dwarf_loclists_new_from_file(RZ_BORROW RZ_NONNULL RzBinFile *bf); RZ_API RzBinDwarfRngList *rz_bin_dwarf_rnglists_get( RZ_BORROW RZ_NONNULL RzBinDwarfRngLists *self, @@ -1821,8 +1830,7 @@ RZ_API void rz_bin_dwarf_rnglists_dump( /// rnglists RZ_API RZ_OWN RzBinDwarfRngLists *rz_bin_dwarf_rnglists_new( RZ_OWN RZ_NULLABLE RzBinEndianReader *rnglists, RZ_OWN RZ_NULLABLE RzBinEndianReader *ranges); -RZ_API RZ_OWN RzBinDwarfRngLists *rz_bin_dwarf_rnglists_new_from_file( - RZ_BORROW RZ_NONNULL RzBinFile *bf, bool is_dwo); +RZ_API RZ_OWN RzBinDwarfRngLists *rz_bin_dwarf_rnglists_new_from_file(RZ_BORROW RZ_NONNULL RzBinFile *bf); /// Block RZ_API bool rz_bin_dwarf_block_empty(RZ_NULLABLE const RzBinDwarfBlock *self); @@ -1856,16 +1864,13 @@ static inline ut64 rz_bin_dwarf_attr_addr( const RzBinDwarfAttrValue *v = &attr->value; if (v->kind == RzBinDwarfAttr_Addr) { return attr->value.u64; - } else if (v->kind == RzBinDwarfAttr_AddrIndex) { + } else if (v->kind == RzBinDwarfAttr_AddrIndex && rz_bin_dwarf_addr(dw)) { ut64 addr = 0; - if (dw && rz_bin_dwarf_addr_get(dw->addr, &addr, addr_size, base, attr->value.u64)) { + if (dw && rz_bin_dwarf_addr_get(rz_bin_dwarf_addr(dw), &addr, addr_size, base, attr->value.u64)) { return addr; } - rz_warn_if_reached(); } else if (v->kind == RzBinDwarfAttr_UConstant) { return attr->value.u64; - } else { - rz_warn_if_reached(); } return attr->value.u64; } diff --git a/test/db/cmd/dwarf b/test/db/cmd/dwarf index 478d7fe9322..be766cbf7a1 100644 --- a/test/db/cmd/dwarf +++ b/test/db/cmd/dwarf @@ -9547,3 +9547,106 @@ Line table statements: 0x000013af - 0 0 EOF RUN + +NAME="Debugging Information in dwo" +FILE=bins/dwarf/demo_dwo +CMDS=<cur, false); + da = rz_bin_dwarf_abbrev_from_file(bin->cur); mu_assert_eq(rz_bin_dwarf_abbrev_count(da), 7, "Incorrect number of abbreviation"); RzBinDwarfAbbrevTable *tbl = ht_up_find(da->by_offset, 0x0, NULL); @@ -119,8 +119,7 @@ bool test_dwarf3_c_basic(void) { // this should work for dwarf2 aswell TEST_ABBREV_ATTR(3, DW_AT_decl_column, DW_FORM_data1); TEST_ABBREV_ATTR(4, DW_AT_type, DW_FORM_ref4); - RzBinDwarfLine *li = rz_bin_dwarf_line_from_file( - bin->cur, NULL, false); + RzBinDwarfLine *li = rz_bin_dwarf_line_from_file(NULL, bin->cur); mu_assert_notnull(li, "line info"); mu_assert_eq(rz_pvector_len(li->units), 1, "line units count"); mu_assert_notnull(li->lines, "line info"); @@ -167,7 +166,7 @@ bool test_dwarf3_cpp_basic(void) { // this should work for dwarf2 aswell // mode = 0, calls // static void dump_r_bin_dwarf_debug_abbrev(FILE *f, RzBinDwarfDebugAbbrev *da) // which prints out all the abbreviation - da = rz_bin_dwarf_abbrev_from_file(bin->cur, false); + da = rz_bin_dwarf_abbrev_from_file(bin->cur); mu_assert("Incorrect number of abbreviation", rz_bin_dwarf_abbrev_count(da) == 32); RzBinDwarfAbbrevTable *tbl = ht_up_find(da->by_offset, 0x0, NULL); @@ -205,8 +204,7 @@ bool test_dwarf3_cpp_basic(void) { // this should work for dwarf2 aswell // rz_bin_dwarf_parse_aranges (core->bin, MODE); Information not stored anywhere, not testable now? - RzBinDwarfLine *li = rz_bin_dwarf_line_from_file( - bin->cur, NULL, false); + RzBinDwarfLine *li = rz_bin_dwarf_line_from_file(NULL, bin->cur); mu_assert_notnull(li, "line info"); mu_assert_eq(rz_pvector_len(li->units), 1, "line units count"); mu_assert_notnull(li->lines, "line info"); @@ -295,7 +293,7 @@ bool test_dwarf3_cpp_many_comp_units(void) { // mode = 0, calls // static void dump_r_bin_dwarf_debug_abbrev(FILE *f, RzBinDwarfDebugAbbrev *da) // which prints out all the abbreviation - da = rz_bin_dwarf_abbrev_from_file(bin->cur, false); + da = rz_bin_dwarf_abbrev_from_file(bin->cur); mu_assert_eq(rz_bin_dwarf_abbrev_count(da), 58, "Incorrect number of abbreviation"); RzBinDwarfAbbrevTable *tbl = ht_up_find(da->by_offset, 0x0, NULL); @@ -321,8 +319,7 @@ bool test_dwarf3_cpp_many_comp_units(void) { TEST_ABBREV_ATTR(5, DW_AT_GNU_all_call_sites, DW_FORM_flag); TEST_ABBREV_ATTR(6, DW_AT_sibling, DW_FORM_ref4); - RzBinDwarfLine *li = rz_bin_dwarf_line_from_file( - bin->cur, NULL, false); + RzBinDwarfLine *li = rz_bin_dwarf_line_from_file(NULL, bin->cur); mu_assert_notnull(li, "line info"); mu_assert_eq(rz_pvector_len(li->units), 2, "line units count"); mu_assert_notnull(li->lines, "line info"); @@ -435,12 +432,11 @@ bool test_dwarf_cpp_empty_line_info(void) { // this should work for dwarf2 aswel // mode = 0, calls // static void dump_r_bin_dwarf_debug_abbrev(FILE *f, RzBinDwarfDebugAbbrev *da) // which prints out all the abbreviation - da = rz_bin_dwarf_abbrev_from_file(bin->cur, false); + da = rz_bin_dwarf_abbrev_from_file(bin->cur); // not ignoring null entries -> 755 abbrevs mu_assert_eq(rz_bin_dwarf_abbrev_count(da), 731, "Incorrect number of abbreviation"); - RzBinDwarfLine *li = rz_bin_dwarf_line_from_file( - bin->cur, NULL, false); + RzBinDwarfLine *li = rz_bin_dwarf_line_from_file(NULL, bin->cur); mu_assert_notnull(li, "line info"); mu_assert_eq(rz_pvector_len(li->units), 25, "line units count"); RzBinDwarfLineUnit *lunit = rz_pvector_tail(li->units); @@ -544,7 +540,7 @@ bool test_dwarf2_cpp_many_comp_units(void) { // mode = 0, calls // static void dump_r_bin_dwarf_debug_abbrev(FILE *f, RzBinDwarfDebugAbbrev *da) // which prints out all the abbreviation - da = rz_bin_dwarf_abbrev_from_file(bin->cur, false); + da = rz_bin_dwarf_abbrev_from_file(bin->cur); mu_assert_eq(rz_bin_dwarf_abbrev_count(da), 58, "Incorrect number of abbreviation"); RzBinDwarfAbbrevTable *tbl = ht_up_find(da->by_offset, 0x0, NULL); @@ -567,8 +563,7 @@ bool test_dwarf2_cpp_many_comp_units(void) { TEST_ABBREV_ATTR(2, DW_AT_artificial, DW_FORM_flag); TEST_ABBREV_ATTR(3, DW_AT_location, DW_FORM_block1); - RzBinDwarfLine *li = rz_bin_dwarf_line_from_file( - bin->cur, NULL, false); + RzBinDwarfLine *li = rz_bin_dwarf_line_from_file(NULL, bin->cur); mu_assert_notnull(li, "line info"); mu_assert_eq(rz_pvector_len(li->units), 2, "line units count"); mu_assert_notnull(li->lines, "line info"); @@ -659,8 +654,7 @@ bool test_dwarf4_cpp_many_comp_units(void) { // TODO add abbrev checks - RzBinDwarfLine *li = rz_bin_dwarf_line_from_file( - bin->cur, NULL, false); + RzBinDwarfLine *li = rz_bin_dwarf_line_from_file(NULL, bin->cur); mu_assert_notnull(li, "line info"); mu_assert_eq(rz_pvector_len(li->units), 2, "line units count"); mu_assert_notnull(li->lines, "line info"); @@ -762,7 +756,7 @@ bool test_dwarf4_multidir_comp_units(void) { RzBinDWARF *dw = rz_bin_dwarf_from_file(bf); mu_assert_notnull(dw, "DWARF"); - RzBinDwarfAbbrev *da = rz_bin_dwarf_abbrev_from_file(bin->cur, false); + RzBinDwarfAbbrev *da = rz_bin_dwarf_abbrev_from_file(bin->cur); mu_assert_notnull(da, "abbrevs"); mu_assert_eq(rz_bin_dwarf_abbrev_count(da), 8, "abbrevs count"); @@ -805,7 +799,7 @@ bool test_big_endian_dwarf2(void) { RzBinFile *bf = rz_bin_open(bin, "bins/elf/ppc64_sudoku_dwarf", &opt); mu_assert_notnull(bf, "couldn't open file"); - RzBinDwarfLine *li = rz_bin_dwarf_line_from_file(bin->cur, NULL, false); + RzBinDwarfLine *li = rz_bin_dwarf_line_from_file(NULL, bin->cur); mu_assert_notnull(li, "line info"); mu_assert_eq(rz_pvector_len(li->units), 1, "line units count"); mu_assert_notnull(li->lines, "line info"); @@ -1367,7 +1361,7 @@ bool test_dwarf5_loclists(void) { RzBinDwarfCompUnit *cu = rz_vector_head(&dw->info->units); mu_assert_notnull(cu, ".debug_info unit"); RzBinDwarfLocList *loclist = - rz_bin_dwarf_loclists_get(dw->loclists, dw->addr, cu, 0x00000012); + rz_bin_dwarf_loclists_get(dw->loclists, rz_bin_dwarf_addr(dw), cu, 0x00000012); mu_assert_notnull(loclist, "loclist"); { @@ -1432,7 +1426,7 @@ bool test_dwarf4_loclists(void) { RzBinDwarfCompUnit *cu = rz_vector_index_ptr(&dw->info->units, 0); RzBinDwarfLocList *loclist = - rz_bin_dwarf_loclists_get(dw->loclists, dw->addr, cu, 0); + rz_bin_dwarf_loclists_get(dw->loclists, rz_bin_dwarf_addr(dw), cu, 0); mu_assert_notnull(loclist, "loclist"); { diff --git a/test/integration/test_dwarf_integration.c b/test/integration/test_dwarf_integration.c index 10a3e380004..348666dd046 100644 --- a/test/integration/test_dwarf_integration.c +++ b/test/integration/test_dwarf_integration.c @@ -240,7 +240,7 @@ static bool test_dwarf_function_parsing_rust(void) { RzBinDwarfCompUnit *cu = ht_up_find(dw->info->unit_by_offset, 0x4151, NULL); mu_assert_notnull(cu, "Couldn't get compunit"); - RzBinDwarfLocList *loclist = rz_bin_dwarf_loclists_get(dw->loclists, dw->addr, cu, 0xd973); + RzBinDwarfLocList *loclist = rz_bin_dwarf_loclists_get(dw->loclists, rz_bin_dwarf_addr(dw), cu, 0xd973); mu_assert_notnull(loclist, "Couldn't get loclist"); RzBinDwarfLocListEntry *entry = rz_pvector_at(&loclist->entries, 0); mu_assert_notnull(entry, "Couldn't get entry");