]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Add prerequisities into descriptors
authorPetr Machata <pmachata@redhat.com>
Mon, 30 Aug 2010 17:11:58 +0000 (19:11 +0200)
committerPetr Machata <pmachata@redhat.com>
Mon, 30 Aug 2010 17:11:58 +0000 (19:11 +0200)
- also move as many descriptors as possible into .cc

21 files changed:
dwarflint/check_debug_abbrev.cc
dwarflint/check_debug_abbrev.hh
dwarflint/check_debug_aranges.cc
dwarflint/check_debug_aranges.hh
dwarflint/check_debug_info.cc
dwarflint/check_debug_info.hh
dwarflint/check_debug_line.cc
dwarflint/check_debug_loc_range.cc
dwarflint/check_debug_loc_range.hh
dwarflint/check_debug_pub.cc
dwarflint/check_duplicate_DW_tag_variable.cc
dwarflint/check_dups_abstract_origin.cc
dwarflint/check_expected_trees.cc
dwarflint/check_matching_ranges.cc
dwarflint/check_range_out_of_scope.cc
dwarflint/checkdescriptor.cc
dwarflint/checkdescriptor.hh
dwarflint/dwarflint.cc
dwarflint/highlevel_check.hh
dwarflint/sections.cc
dwarflint/sections.hh

index 8023d389c376fdbd58074613a5ace1395ae13358..4cf80d07e2d01d538a20d5cf601972e45865bab6 100644 (file)
 
 static reg<check_debug_abbrev> reg_debug_abbrev;
 
+checkdescriptor &
+check_debug_abbrev::descriptor ()
+{
+  static checkdescriptor cd
+    (checkdescriptor::create ("check_debug_abbrev")
+     .groups ("@low")
+     .prereq <typeof (*_m_sec_abbr)> ());
+  return cd;
+}
+
 struct abbrev *
 abbrev_table_find_abbrev (struct abbrev_table const *abbrevs,
                          uint64_t abbrev_code)
index cad078831c5f97d699db5e7d6bb698644b418ee6..ded61e0620bde0477827108694fb55e9c6bd72dd 100644 (file)
 #ifndef DWARFLINT_CHECK_DEBUG_ABBREV_HH
 #define DWARFLINT_CHECK_DEBUG_ABBREV_HH
 
+#include "low.h"
+#include "checks.hh"
+#include "sections.ii"
+
 class check_debug_abbrev
   : public check<check_debug_abbrev>
 {
   section<sec_abbrev> *_m_sec_abbr;
 
 public:
-  static checkdescriptor descriptor () {
-    static checkdescriptor cd
-      (checkdescriptor::create ("check_debug_abbrev")
-       .groups ("@low"));
-    return cd;
-  }
+  static checkdescriptor &descriptor ();
 
   // offset -> abbreviations
   typedef std::map< ::Dwarf_Off, abbrev_table> abbrev_map;
index 15a12ceac09e5cf368f897b09b71b4b254f24092..e88bf9eee475d0d775055555d9fd12801525b74a 100644 (file)
 
 static reg<check_debug_aranges> reg_debug_aranges;
 
+checkdescriptor
+check_debug_aranges::descriptor ()
+{
+  static checkdescriptor cd
+    (checkdescriptor::create ("check_debug_aranges")
+     .groups ("@low")
+     .prereq<typeof (*_m_sec_aranges)> ());
+  return cd;
+}
+
 check_debug_aranges::check_debug_aranges (checkstack &stack, dwarflint &lint)
   : _m_sec_aranges (lint.check (stack, _m_sec_aranges))
 {
index c02e4ce736d671f573010aa48637fd240a166afd..d4427b495e98439f99198bbbbe8e4f7c781fa31d 100644 (file)
@@ -23,8 +23,8 @@
    Network licensing program, please visit www.openinventionnetwork.com
    <http://www.openinventionnetwork.com>.  */
 
-#ifndef DWARFLINT_CHECKS_LOW_HH
-#define DWARFLINT_CHECKS_LOW_HH
+#ifndef DWARFLINT_CHECK_DEBUG_ARANGES_HH
+#define DWARFLINT_CHECK_DEBUG_ARANGES_HH
 
 #include "low.h"
 #include "checks.hh"
@@ -36,14 +36,8 @@ class check_debug_aranges
   section<sec_aranges> *_m_sec_aranges;
 
 public:
-  static checkdescriptor descriptor () {
-    static checkdescriptor cd
-      (checkdescriptor::create ("check_debug_aranges")
-       .groups ("@low"));
-    return cd;
-  }
-
+  static checkdescriptor descriptor ();
   check_debug_aranges (checkstack &stack, dwarflint &lint);
 };
 
-#endif//DWARFLINT_CHECKS_LOW_HH
+#endif//DWARFLINT_CHECK_DEBUG_ARANGES_HH
index 5db9d8cc5921536a9f60caa2c1a91192d4fb06a1..a5a0fa056b34813ad3d326c2e85d73bf885afe60 100644 (file)
 #include "check_debug_abbrev.hh"
 #include "check_debug_info.hh"
 
+checkdescriptor
+read_cu_headers::descriptor ()
+{
+  static checkdescriptor cd
+    (checkdescriptor::create ("read_cu_headers")
+     .prereq<typeof (*_m_sec_info)> ());
+  return cd;
+}
+
 static reg<check_debug_info> reg_debug_info;
 
+checkdescriptor
+check_debug_info::descriptor ()
+{
+  static checkdescriptor cd
+    (checkdescriptor::create ("check_debug_info")
+     .groups ("@low")
+     .prereq<typeof (*_m_sec_info)> ()
+     .prereq<typeof (*_m_sec_abbrev)> ()
+     .prereq<typeof (*_m_sec_str)> ()
+     .prereq<typeof (*_m_abbrevs)> ()
+     .prereq<typeof (*_m_cu_headers)> ()
+     );
+  return cd;
+}
+
 namespace
 {
   bool
index 63082e74143fa99f9d9d662779b88b8ac0f22b02..7b33499e9bcc0938ab5e63feb28f079e93571d69 100644 (file)
 #ifndef DWARFLINT_CHECK_DEBUG_INFO_HH
 #define DWARFLINT_CHECK_DEBUG_INFO_HH
 
+#include "low.h"
+#include "checks.hh"
 #include "check_debug_abbrev.ii"
 #include "sections.ii"
-#include "checks.hh"
-#include "low.h"
 
 /** The pass for reading basic .debug_info data -- the layout of
     sections and their headers.  */
@@ -39,11 +39,7 @@ class read_cu_headers
   section<sec_info> *_m_sec_info;
 
 public:
-  static checkdescriptor descriptor () {
-    static checkdescriptor cd ("read_cu_headers @low");
-    return cd;
-  }
-
+  static checkdescriptor descriptor ();
   std::vector<cu_head> const cu_headers;
   read_cu_headers (checkstack &stack, dwarflint &lint);
 };
@@ -71,10 +67,7 @@ class check_debug_info
   void check_info_structural ();
 
 public:
-  static checkdescriptor descriptor () {
-    static checkdescriptor cd ("check_debug_info");
-    return cd;
-  }
+  static checkdescriptor descriptor ();
 
   // The check pass adds all low_pc/high_pc ranges loaded from DIE
   // tree into this following cu_cov structure.  If it finds any
index 696056ea8c6ec074a4d5b2eea2cab0becfc30089..bb27ed18c05bed22ac4dbaa0daf5d5a549b634f0 100644 (file)
@@ -59,7 +59,8 @@ namespace
     static checkdescriptor descriptor () {
       static checkdescriptor cd
        (checkdescriptor::create ("check_debug_line")
-        .groups ("@low"));
+        .groups ("@low")
+        .prereq<typeof (*_m_sec)> ());
       return cd;
     }
 
index 70206971e33598372bcbdfc35de1b86f2c69665c..751a4d0d16f1414da01e58f789643fad4cddc110 100644 (file)
 #include "../src/dwarf-opcodes.h"
 #include "pri.hh"
 
+static reg<check_debug_ranges> reg_debug_ranges;
+
+checkdescriptor const &
+check_debug_ranges::descriptor ()
+{
+  static checkdescriptor cd
+    (checkdescriptor::create ("check_debug_ranges")
+     .groups ("@low")
+     .prereq<typeof (*_m_sec_ranges)> ()
+     .prereq<typeof (*_m_cus)> ());
+  return cd;
+}
+
+static reg<check_debug_loc> reg_debug_loc;
+
+checkdescriptor const &
+check_debug_loc::descriptor ()
+{
+  static checkdescriptor cd
+    (checkdescriptor::create ("check_debug_loc")
+     .groups ("@low")
+     .prereq<typeof (*_m_sec_loc)> ()
+     .prereq<typeof (*_m_cus)> ());
+  return cd;
+}
+
 namespace
 {
   void
@@ -1019,9 +1045,3 @@ found_hole (uint64_t start, uint64_t length, void *data)
 
   return true;
 }
-
-namespace
-{
-  reg<check_debug_ranges> reg_debug_ranges;
-  reg<check_debug_loc> reg_debug_loc;
-}
index e352d0b9974fe657b3e117a187a1b1ed38515ad0..d48aebfca00dd142dd90fc40600d1e9c066c1164 100644 (file)
    Network licensing program, please visit www.openinventionnetwork.com
    <http://www.openinventionnetwork.com>.  */
 
+#include "low.h"
+#include "checks.hh"
 #include "sections.ii"
 #include "check_debug_info.ii"
-#include "checks.hh"
 #include "messages.h"
-#include "low.h"
 
 class check_debug_ranges
   : public check<check_debug_ranges>
@@ -36,13 +36,7 @@ class check_debug_ranges
   check_debug_info *_m_cus;
 
 public:
-  static checkdescriptor descriptor () {
-    static checkdescriptor cd
-      (checkdescriptor::create ("check_debug_ranges")
-       .groups ("@low"));
-    return cd;
-  }
-
+  static checkdescriptor const &descriptor ();
   check_debug_ranges (checkstack &stack, dwarflint &lint);
 };
 
@@ -53,13 +47,7 @@ class check_debug_loc
   check_debug_info *_m_cus;
 
 public:
-  static checkdescriptor descriptor () {
-    static checkdescriptor cd
-      (checkdescriptor::create ("check_debug_loc")
-       .groups ("@low"));
-    return cd;
-  }
-
+  static checkdescriptor const &descriptor ();
   check_debug_loc (checkstack &stack, dwarflint &lint);
 };
 
index 44936642df9995f00c1643b5a32bbbbc3093f7a2..65710420fca728b0a92d6e7483fc3dbd669359e3 100644 (file)
@@ -44,7 +44,9 @@ namespace
       static std::string name
        = (std::string)"check_"
        + (section_t::descriptor ().name () + 1);
-      static checkdescriptor cd (name.c_str ());
+      static checkdescriptor cd
+       (checkdescriptor::create (name.c_str ())
+        .prereq<typeof (*_m_sec)> ());
       return cd;
     }
 
index 77e39597f987e514a27a05d9c31fcca77ac8dd0a..c8a937bd26ca2f9d667099f934d1e0ab9bb970d7 100644 (file)
@@ -60,6 +60,7 @@ namespace
     static checkdescriptor descriptor () {
       static checkdescriptor cd
        (checkdescriptor::create ("check_duplicate_DW_tag_variable")
+        .inherit<highlevel_check<check_duplicate_DW_tag_variable> > ()
         .description (
 "Implements a check for two full DW_TAG_variable DIEs with the same\n"
 "DW_AT_name value.  This covers duplicate declaration, duplicate\n"
index 314bf6dd4ed59790ce8402f3b52681b5fa17f7ad..27745bf9b85098624a38b301d0bc7b36c75d9956 100644 (file)
@@ -45,6 +45,7 @@ namespace
     static checkdescriptor descriptor () {
       static checkdescriptor cd
        (checkdescriptor::create ("check_dups_abstract_origin")
+        .inherit<highlevel_check<check_dups_abstract_origin> > ()
         .description (
 "If a given attribute name is present on a DIE, it is\n"
 "suspicious if that attribute name appears on the DIE that's the\n"
index 729d87e0f41b0d2200f728d4b49e760768d216fc..0482919b2497e398c49efa966972e1d397f5e819 100644 (file)
@@ -43,7 +43,12 @@ namespace
   {
   public:
     static checkdescriptor descriptor () {
-      static checkdescriptor cd ("check_expected_trees");
+      static checkdescriptor cd
+       (checkdescriptor::create ("check_expected_trees")
+        .inherit<highlevel_check<check_expected_trees> > ()
+        .description (
+"Checks whether all DIEs have the right attributes and the right children.\n"
+"Currently this is very much a work in progress.\n"));
       return cd;
     }
 
index d6ce471fa0377891aa830e77c843f4dfe3653652..ae37c80924ad15f0d35a7a07753b84587a54051d 100644 (file)
@@ -40,7 +40,9 @@ namespace
   {
   public:
     static checkdescriptor descriptor () {
-      static checkdescriptor cd ("check_matching_ranges");
+      static checkdescriptor cd
+       (checkdescriptor::create ("check_matching_ranges")
+        .inherit<highlevel_check<check_matching_ranges> > ());
       return cd;
     }
 
index 89e5796d6136282fe1ab9727996864b86d3d58d3..779fba88abd3cd2651c82f3e06532ae9d41f3376 100644 (file)
@@ -49,7 +49,11 @@ namespace
 
   public:
     static checkdescriptor descriptor () {
-      static checkdescriptor cd ("check_range_out_of_scope");
+      static checkdescriptor cd
+       (checkdescriptor::create ("check_range_out_of_scope")
+        .inherit<highlevel_check<check_range_out_of_scope> > ()
+        .description (
+"Check whether PC ranges reported at DIEs fall into the containing scope.\n"));
       return cd;
     }
 
index c1418bea435b64994253b528becd735b594c957d..c0a4e364ded8cf108390a3be888f659a35bca7a8 100644 (file)
@@ -61,6 +61,7 @@ checkdescriptor::checkdescriptor (create const &c)
   : _m_name (c.name)
   , _m_description (c.desc)
   , _m_groups (c.g)
+  , _m_prereq (c.p)
 {}
 
 bool
index beffa3d0d1af95c7f65316adbe1c5ebc332789fc..5e7d32450e407ec79f158010a6a87896881a3724 100644 (file)
@@ -40,19 +40,25 @@ struct checkdescriptor
   struct create
   {
     checkgroups g;
+    checkgroups p;
     char const *const name;
     char const *desc;
-    create (char const *name);
+    create (char const *name = NULL);
     create &groups (char const *name);
 
     create &description (char const *d)
     { desc = d; return *this; }
+
+    template <class T> create &prereq ();
+
+    template <class T> create &inherit ();
   };
 
   checkdescriptor (create const &c);
 
   char const *name () const { return _m_name; }
   char const *description () const { return _m_description; }
+  checkgroups const &prereq () const { return _m_prereq; }
 
   checkgroups const &groups () const { return _m_groups; }
   bool in_group (std::string const &group) const;
@@ -61,6 +67,26 @@ private:
   char const *const _m_name;
   char const *const _m_description;
   checkgroups const _m_groups;
+  checkgroups const _m_prereq;
 };
 
+template <class T>
+checkdescriptor::create &
+checkdescriptor::create::prereq ()
+{
+  p.insert (T::descriptor ().name ());
+  return *this;
+}
+
+template <class T>
+checkdescriptor::create &
+checkdescriptor::create::inherit ()
+{
+  checkdescriptor const &cd = T::descriptor ();
+  for (checkgroups::const_iterator it = cd.prereq ().begin ();
+       it != cd.prereq ().end (); ++it)
+    p.insert (*it);
+  return *this;
+}
+
 #endif//DWARFLINT_CHECKDESCRIPTOR_HH
index 419f56269177fde7bfc25631d75a7bcdfaa9ec64..94ad32462dfc5d4f5ed21398ac3988a3649ae2a7 100644 (file)
@@ -104,9 +104,24 @@ dwarflint::check_registrar::list_checks () const
        it != _m_items.end (); ++it)
     {
       checkdescriptor const &cd = (*it)->descriptor ();
-      std::cout << cd.name () << ' ' << cd.groups () << std::endl;
+      std::cout << cd.name ();
+
+      checkgroups const &groups = cd.groups ();
+      if (!groups.empty ())
+       {
+         if (be_verbose)
+           std::cout << std::endl << "groups: ";
+         else
+           std::cout << ' ';
+         std::cout << groups;
+       }
+      std::cout << std::endl;
+
       if (be_verbose)
        {
+         checkgroups const &prereq = cd.prereq ();
+         if (!prereq.empty ())
+           std::cout << "prerequisites: " << prereq << std::endl;
          char const *desc = cd.description ();
          if (desc != NULL)
            std::cout << desc;
index b2e4086d8b3c9a2b0d213749b0738f3d5e9ce5fa..6d57d5fb1ad9fc9bf8ff468565878ca2e549ee46 100644 (file)
@@ -57,6 +57,13 @@ class highlevel_check
 {
   open_highlevel_dwarf *_m_loader;
 public:
+  static checkdescriptor const &descriptor () {
+    static checkdescriptor cd
+      (checkdescriptor::create ("open_highlevel_dwarf")
+       .prereq<typeof (*_m_loader)> ());
+    return cd;
+  }
+
   elfutils::dwarf const &dw;
 
   explicit highlevel_check (checkstack &stack, dwarflint &lint)
index 641551cb05e65394f7054114a687fd1d8ac7f174..b1eb3d50858e80ab9f10bdd762aac36400eee7cf 100644 (file)
 #include "pri.hh"
 #include "options.h"
 
+checkdescriptor const &
+load_sections::descriptor ()
+{
+  static checkdescriptor cd ("load_sections");
+  return cd;
+}
+
+checkdescriptor const &
+section_base::descriptor ()
+{
+  static checkdescriptor cd
+    (checkdescriptor::create ()
+     .prereq<typeof (*sections)> ());
+  return cd;
+}
+
 namespace
 {
   int
index 28b99b55841407b80f5bb88be5b99b23ebbf3a3c..bb8c872062c4950733219e1bdb14ef6247a1d4df 100644 (file)
@@ -33,10 +33,7 @@ class load_sections
   : public check<load_sections>
 {
 public:
-  static checkdescriptor descriptor () {
-    static checkdescriptor cd ("load_sections");
-    return cd;
-  }
+  static checkdescriptor const &descriptor ();
 
   elf_file file;
   load_sections (checkstack &stack, dwarflint &lint);
@@ -47,7 +44,10 @@ class section_base
 {
   load_sections *sections;
   sec &get_sec_or_throw (section_id secid);
+
 public:
+  static checkdescriptor const &descriptor ();
+
   sec &sect;
   elf_file &file;
   section_base (checkstack &stack,
@@ -66,7 +66,9 @@ class section
 {
 public:
   static checkdescriptor const &descriptor () {
-    static checkdescriptor cd(section_name[sec_id]);
+    static checkdescriptor cd
+      (checkdescriptor::create (section_name[sec_id])
+       .inherit<section_base> ());
     return cd;
   }