]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Don't fail if high-level checks are requested on broken ELF file
authorPetr Machata <pmachata@redhat.com>
Tue, 28 Jul 2009 12:12:05 +0000 (14:12 +0200)
committerPetr Machata <pmachata@redhat.com>
Tue, 4 Aug 2009 14:14:06 +0000 (16:14 +0200)
src/dwarflint-hl.cc
src/dwarflint.c

index c4c471775e680569048a9adcea649f05370d3849..b8d7523f1ed669c4003d02994417bc2bd81fd984 100644 (file)
@@ -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;
 }
index 0bbffd5d72b7deec95c1f0034094368fe3a22bd6..a08c36b05bcbb3f78610976c6dc687e033d656f8 100644 (file)
@@ -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);
     }