]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Implement check for ranges/aranges mismatch
authorPetr Machata <pmachata@redhat.com>
Mon, 2 Feb 2009 16:38:03 +0000 (17:38 +0100)
committerPetr Machata <pmachata@redhat.com>
Mon, 2 Feb 2009 17:02:49 +0000 (18:02 +0100)
src/dwarflint-hl.cc
src/dwarflint.c
src/dwarflint.h

index 1b7a1ab4915eda6173236aeba5956327e5edeebd..c499a18bf1465d6837a89a32c971ddff6f6b9334 100644 (file)
 #endif
 
 #include <iostream>
-#include <cinttypes>
-#include <map>
+#include <set>
 #include <algorithm>
+#include <cinttypes>
 
 #include "dwarflint.h"
 #include "c++/dwarf"
 #include "../libdw/libdwP.h"
 
+namespace
+{
+  message_category cat (message_category c1,
+                       message_category c2,
+                       message_category c3)
+  {
+    return static_cast<message_category> (c1 | c2 | c3);
+  }
+}
 
 bool
-check_aranges_hl (Dwarf *dwarf)
+check_matching_ranges (Dwarf *dwarf)
 {
+  elfutils::dwarf dw(dwarf);
+
+  struct where where_ref = WHERE (sec_info, NULL);
+  struct where where_ar = WHERE (sec_aranges, NULL);
+  where_ar.ref = &where_ref;
+  struct where where_r = WHERE (sec_ranges, NULL);
+  where_r.ref = &where_ref;
+
+  const elfutils::dwarf::aranges_map &aranges = dw.aranges ();
+  for (elfutils::dwarf::aranges_map::const_iterator i = aranges.begin ();
+       i != aranges.end (); ++i)
+    {
+      const elfutils::dwarf::compile_unit &cu = i->first;
+      where_reset_1 (&where_ref, 0);
+      where_reset_2 (&where_ref, cu.offset ());
+
+      const elfutils::dwarf::arange_list &cu_aranges = i->second;
+      const elfutils::dwarf::ranges &cu_ranges = cu.ranges ();
+
+      typedef std::vector <elfutils::dwarf::arange_list::value_type> range_vec;
+      range_vec missing;
+      std::back_insert_iterator <range_vec> i_missing (missing);
+
+      std::set_difference (cu_aranges.begin (), cu_aranges.end (),
+                          cu_ranges.begin (), cu_ranges.end (),
+                          i_missing);
+
+      for (range_vec::iterator it = missing.begin ();
+          it != missing.end (); ++it)
+       wr_message (cat (mc_ranges, mc_aranges, mc_impact_3), &where_r,
+                   ": missing range %#" PRIx64 "..%#" PRIx64
+                   ", present in .debug_aranges.\n",
+                   it->first, it->second);
+
+      missing.clear ();
+      std::set_difference (cu_ranges.begin (), cu_ranges.end (),
+                          cu_aranges.begin (), cu_aranges.end (),
+                          i_missing);
+
+      for (range_vec::iterator it = missing.begin ();
+          it != missing.end (); ++it)
+       wr_message (cat (mc_ranges, mc_aranges, mc_impact_3), &where_ar,
+                   ": missing range %#" PRIx64 "..%#" PRIx64
+                   ", present in .debug_ranges.\n",
+                   it->first, it->second);
+    }
+
   return dwarf != NULL;
 }
index f4b4913a41ae200d1499952522fe6c4a1ff61b6d..5f87c7cf787b9a0287dd1dccd58df0673c74202a 100644 (file)
@@ -757,7 +757,8 @@ process_file (int fd __attribute__((unused)),
     {
       read_ctx_init (&ctx, dwarf, aranges_data);
       if (check_aranges_structural (&ctx, cu_chain))
-       check_aranges_hl (dwarf);
+       /* XXX only do this if .debug_ranges are also OK.  */
+       check_matching_ranges (dwarf);
     }
 
   if (pubnames_data != NULL)
index 5f2b8fc1220b5ec667b4cb995cd8707a66b854af..411fe816cc1ff17b625f719feee1d1948430af8d 100644 (file)
@@ -11,7 +11,9 @@ extern "C"
 #endif
 
   /* Entry points for high-level checks.  */
-  extern bool check_aranges_hl (Dwarf *dwarf);
+
+  /* Check that .debug_aranges and .debug_ranges match.  */
+  extern bool check_matching_ranges (Dwarf *dwarf);
 
 
   /* Functions and data structures describing location in Dwarf.  */