From: Petr Machata Date: Mon, 30 Aug 2010 17:11:58 +0000 (+0200) Subject: Add prerequisities into descriptors X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=918e55ac0386f2992d5c434fc32e087b71caa3bc;p=thirdparty%2Felfutils.git Add prerequisities into descriptors - also move as many descriptors as possible into .cc --- diff --git a/dwarflint/check_debug_abbrev.cc b/dwarflint/check_debug_abbrev.cc index 8023d389c..4cf80d07e 100644 --- a/dwarflint/check_debug_abbrev.cc +++ b/dwarflint/check_debug_abbrev.cc @@ -40,6 +40,16 @@ static reg reg_debug_abbrev; +checkdescriptor & +check_debug_abbrev::descriptor () +{ + static checkdescriptor cd + (checkdescriptor::create ("check_debug_abbrev") + .groups ("@low") + .prereq ()); + return cd; +} + struct abbrev * abbrev_table_find_abbrev (struct abbrev_table const *abbrevs, uint64_t abbrev_code) diff --git a/dwarflint/check_debug_abbrev.hh b/dwarflint/check_debug_abbrev.hh index cad078831..ded61e062 100644 --- a/dwarflint/check_debug_abbrev.hh +++ b/dwarflint/check_debug_abbrev.hh @@ -26,18 +26,17 @@ #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 { section *_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; diff --git a/dwarflint/check_debug_aranges.cc b/dwarflint/check_debug_aranges.cc index 15a12ceac..e88bf9eee 100644 --- a/dwarflint/check_debug_aranges.cc +++ b/dwarflint/check_debug_aranges.cc @@ -35,6 +35,16 @@ static reg reg_debug_aranges; +checkdescriptor +check_debug_aranges::descriptor () +{ + static checkdescriptor cd + (checkdescriptor::create ("check_debug_aranges") + .groups ("@low") + .prereq ()); + return cd; +} + check_debug_aranges::check_debug_aranges (checkstack &stack, dwarflint &lint) : _m_sec_aranges (lint.check (stack, _m_sec_aranges)) { diff --git a/dwarflint/check_debug_aranges.hh b/dwarflint/check_debug_aranges.hh index c02e4ce73..d4427b495 100644 --- a/dwarflint/check_debug_aranges.hh +++ b/dwarflint/check_debug_aranges.hh @@ -23,8 +23,8 @@ Network licensing program, please visit 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 *_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 diff --git a/dwarflint/check_debug_info.cc b/dwarflint/check_debug_info.cc index 5db9d8cc5..a5a0fa056 100644 --- a/dwarflint/check_debug_info.cc +++ b/dwarflint/check_debug_info.cc @@ -40,8 +40,32 @@ #include "check_debug_abbrev.hh" #include "check_debug_info.hh" +checkdescriptor +read_cu_headers::descriptor () +{ + static checkdescriptor cd + (checkdescriptor::create ("read_cu_headers") + .prereq ()); + return cd; +} + static reg reg_debug_info; +checkdescriptor +check_debug_info::descriptor () +{ + static checkdescriptor cd + (checkdescriptor::create ("check_debug_info") + .groups ("@low") + .prereq () + .prereq () + .prereq () + .prereq () + .prereq () + ); + return cd; +} + namespace { bool diff --git a/dwarflint/check_debug_info.hh b/dwarflint/check_debug_info.hh index 63082e741..7b33499e9 100644 --- a/dwarflint/check_debug_info.hh +++ b/dwarflint/check_debug_info.hh @@ -26,10 +26,10 @@ #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 *_m_sec_info; public: - static checkdescriptor descriptor () { - static checkdescriptor cd ("read_cu_headers @low"); - return cd; - } - + static checkdescriptor descriptor (); std::vector 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 diff --git a/dwarflint/check_debug_line.cc b/dwarflint/check_debug_line.cc index 696056ea8..bb27ed18c 100644 --- a/dwarflint/check_debug_line.cc +++ b/dwarflint/check_debug_line.cc @@ -59,7 +59,8 @@ namespace static checkdescriptor descriptor () { static checkdescriptor cd (checkdescriptor::create ("check_debug_line") - .groups ("@low")); + .groups ("@low") + .prereq ()); return cd; } diff --git a/dwarflint/check_debug_loc_range.cc b/dwarflint/check_debug_loc_range.cc index 70206971e..751a4d0d1 100644 --- a/dwarflint/check_debug_loc_range.cc +++ b/dwarflint/check_debug_loc_range.cc @@ -45,6 +45,32 @@ #include "../src/dwarf-opcodes.h" #include "pri.hh" +static reg reg_debug_ranges; + +checkdescriptor const & +check_debug_ranges::descriptor () +{ + static checkdescriptor cd + (checkdescriptor::create ("check_debug_ranges") + .groups ("@low") + .prereq () + .prereq ()); + return cd; +} + +static reg reg_debug_loc; + +checkdescriptor const & +check_debug_loc::descriptor () +{ + static checkdescriptor cd + (checkdescriptor::create ("check_debug_loc") + .groups ("@low") + .prereq () + .prereq ()); + return cd; +} + namespace { void @@ -1019,9 +1045,3 @@ found_hole (uint64_t start, uint64_t length, void *data) return true; } - -namespace -{ - reg reg_debug_ranges; - reg reg_debug_loc; -} diff --git a/dwarflint/check_debug_loc_range.hh b/dwarflint/check_debug_loc_range.hh index e352d0b99..d48aebfca 100644 --- a/dwarflint/check_debug_loc_range.hh +++ b/dwarflint/check_debug_loc_range.hh @@ -23,11 +23,11 @@ Network licensing program, please visit 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 @@ -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); }; diff --git a/dwarflint/check_debug_pub.cc b/dwarflint/check_debug_pub.cc index 44936642d..65710420f 100644 --- a/dwarflint/check_debug_pub.cc +++ b/dwarflint/check_debug_pub.cc @@ -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 ()); return cd; } diff --git a/dwarflint/check_duplicate_DW_tag_variable.cc b/dwarflint/check_duplicate_DW_tag_variable.cc index 77e39597f..c8a937bd2 100644 --- a/dwarflint/check_duplicate_DW_tag_variable.cc +++ b/dwarflint/check_duplicate_DW_tag_variable.cc @@ -60,6 +60,7 @@ namespace static checkdescriptor descriptor () { static checkdescriptor cd (checkdescriptor::create ("check_duplicate_DW_tag_variable") + .inherit > () .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" diff --git a/dwarflint/check_dups_abstract_origin.cc b/dwarflint/check_dups_abstract_origin.cc index 314bf6dd4..27745bf9b 100644 --- a/dwarflint/check_dups_abstract_origin.cc +++ b/dwarflint/check_dups_abstract_origin.cc @@ -45,6 +45,7 @@ namespace static checkdescriptor descriptor () { static checkdescriptor cd (checkdescriptor::create ("check_dups_abstract_origin") + .inherit > () .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" diff --git a/dwarflint/check_expected_trees.cc b/dwarflint/check_expected_trees.cc index 729d87e0f..0482919b2 100644 --- a/dwarflint/check_expected_trees.cc +++ b/dwarflint/check_expected_trees.cc @@ -43,7 +43,12 @@ namespace { public: static checkdescriptor descriptor () { - static checkdescriptor cd ("check_expected_trees"); + static checkdescriptor cd + (checkdescriptor::create ("check_expected_trees") + .inherit > () + .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; } diff --git a/dwarflint/check_matching_ranges.cc b/dwarflint/check_matching_ranges.cc index d6ce471fa..ae37c8092 100644 --- a/dwarflint/check_matching_ranges.cc +++ b/dwarflint/check_matching_ranges.cc @@ -40,7 +40,9 @@ namespace { public: static checkdescriptor descriptor () { - static checkdescriptor cd ("check_matching_ranges"); + static checkdescriptor cd + (checkdescriptor::create ("check_matching_ranges") + .inherit > ()); return cd; } diff --git a/dwarflint/check_range_out_of_scope.cc b/dwarflint/check_range_out_of_scope.cc index 89e5796d6..779fba88a 100644 --- a/dwarflint/check_range_out_of_scope.cc +++ b/dwarflint/check_range_out_of_scope.cc @@ -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 > () + .description ( +"Check whether PC ranges reported at DIEs fall into the containing scope.\n")); return cd; } diff --git a/dwarflint/checkdescriptor.cc b/dwarflint/checkdescriptor.cc index c1418bea4..c0a4e364d 100644 --- a/dwarflint/checkdescriptor.cc +++ b/dwarflint/checkdescriptor.cc @@ -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 diff --git a/dwarflint/checkdescriptor.hh b/dwarflint/checkdescriptor.hh index beffa3d0d..5e7d32450 100644 --- a/dwarflint/checkdescriptor.hh +++ b/dwarflint/checkdescriptor.hh @@ -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 create &prereq (); + + template 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 +checkdescriptor::create & +checkdescriptor::create::prereq () +{ + p.insert (T::descriptor ().name ()); + return *this; +} + +template +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 diff --git a/dwarflint/dwarflint.cc b/dwarflint/dwarflint.cc index 419f56269..94ad32462 100644 --- a/dwarflint/dwarflint.cc +++ b/dwarflint/dwarflint.cc @@ -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; diff --git a/dwarflint/highlevel_check.hh b/dwarflint/highlevel_check.hh index b2e4086d8..6d57d5fb1 100644 --- a/dwarflint/highlevel_check.hh +++ b/dwarflint/highlevel_check.hh @@ -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 ()); + return cd; + } + elfutils::dwarf const &dw; explicit highlevel_check (checkstack &stack, dwarflint &lint) diff --git a/dwarflint/sections.cc b/dwarflint/sections.cc index 641551cb0..b1eb3d508 100644 --- a/dwarflint/sections.cc +++ b/dwarflint/sections.cc @@ -37,6 +37,22 @@ #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 ()); + return cd; +} + namespace { int diff --git a/dwarflint/sections.hh b/dwarflint/sections.hh index 28b99b558..bb8c87206 100644 --- a/dwarflint/sections.hh +++ b/dwarflint/sections.hh @@ -33,10 +33,7 @@ class load_sections : public check { 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 § 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 ()); return cd; }