From: Petr Machata Date: Tue, 28 Jul 2009 12:12:05 +0000 (+0200) Subject: dwarflint: Don't fail if high-level checks are requested on broken ELF file X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fae6d86d97ec5f75d9f72ba7b9958718a1efb4f9;p=thirdparty%2Felfutils.git dwarflint: Don't fail if high-level checks are requested on broken ELF file --- diff --git a/src/dwarflint-hl.cc b/src/dwarflint-hl.cc index c4c471775..b8d7523f1 100644 --- a/src/dwarflint-hl.cc +++ b/src/dwarflint-hl.cc @@ -62,6 +62,9 @@ struct hl_ctx : dwarf (dwarf_begin_elf (elf, DWARF_C_READ, NULL)) , dw (dwarf) { + // See if we can iterate compile units. If not, this throws an + // exception that gets caught in the C wrapper below. + dw.compile_units ().begin (); } ~hl_ctx () @@ -73,7 +76,16 @@ struct hl_ctx hl_ctx * hl_ctx_new (Elf *elf) { - return new hl_ctx (elf); + try + { + return new hl_ctx (elf); + } + catch (std::runtime_error &exc) + { + wr_error (NULL, "Cannot initialize high-level checking: %s.\n", + exc.what ()); + return NULL; + } } void @@ -262,6 +274,5 @@ check_expected_trees (hl_ctx *hlctx) for (elfutils::dwarf::compile_units::const_iterator it = cus.begin (); it != cus.end (); ++it) recursively_validate (*it, *it); - return true; } diff --git a/src/dwarflint.c b/src/dwarflint.c index 0bbffd5d7..a08c36b05 100644 --- a/src/dwarflint.c +++ b/src/dwarflint.c @@ -1225,7 +1225,10 @@ process_file (Elf *elf, const char *fname, bool only_one) struct abbrev_table *abbrev_chain = NULL; struct cu *cu_chain = NULL; struct read_ctx ctx; - struct hl_ctx *hlctx = hl_ctx_new (elf); + /* Don't attempt to do high-level checks if we couldn't initialize + high-level context. The wrapper takes care of printing out error + messages if any. */ + struct hl_ctx *hlctx = do_high_level ? hl_ctx_new (elf) : NULL; #define SEC(sec) (file.debugsec[sec_##sec]) #define HAS_SEC(sec) (SEC(sec) != NULL && SEC(sec)->data != NULL) @@ -1257,7 +1260,7 @@ process_file (Elf *elf, const char *fname, bool only_one) cu_coverage = calloc (1, sizeof (struct cu_coverage)); cu_chain = check_info_structural (&file, SEC(info), abbrev_chain, str_data, cu_coverage); - if (cu_chain != NULL && do_high_level) + if (cu_chain != NULL && hlctx != NULL) check_expected_trees (hlctx); } else if (!tolerate_nodebug) @@ -1286,7 +1289,7 @@ process_file (Elf *elf, const char *fname, bool only_one) && cu_coverage->need_ranges) ? NULL : &cu_coverage->cov; if (check_aranges_structural (&file, SEC(aranges), cu_chain, cov) - && ranges_sound && do_high_level && !be_tolerant && !be_gnu) + && ranges_sound && hlctx != NULL && !be_tolerant && !be_gnu) check_matching_ranges (hlctx); }