From: Petr Machata Date: Thu, 7 Apr 2011 15:51:32 +0000 (+0200) Subject: dwarflint: More support for message tresholds and composed messages X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=45a1f8b618731fd81fc62ed727f94dba4ee9a1a9;p=thirdparty%2Felfutils.git dwarflint: More support for message tresholds and composed messages --- diff --git a/dwarflint/check_duplicate_DW_tag_variable.cc b/dwarflint/check_duplicate_DW_tag_variable.cc index 84ab34f67..822b3d8cd 100644 --- a/dwarflint/check_duplicate_DW_tag_variable.cc +++ b/dwarflint/check_duplicate_DW_tag_variable.cc @@ -109,13 +109,15 @@ namespace varinfo &i = old->second; if ((declaration && i.decl != children.end ()) || (!declaration && i.def != children.end ())) - wr_error (to_where (*jt)) + wr_message (to_where (*jt), mc_impact_3 | mc_die_other) + .id (descriptor ()) << "Re" << (declaration ? "declaration" : "definition") << " of variable '" << name << "', originally seen at " << pri::ref (declaration ? *i.decl : *i.def) << '.' << std::endl; else - wr_error (to_where (*jt)) + wr_message (to_where (*jt), mc_impact_3 | mc_die_other) + .id (descriptor ()) << "Found " << (declaration ? "declaration" : "definition") << " of variable '" << name diff --git a/dwarflint/check_linkage_external_die.cc b/dwarflint/check_linkage_external_die.cc index 485ac8457..3731e106e 100644 --- a/dwarflint/check_linkage_external_die.cc +++ b/dwarflint/check_linkage_external_die.cc @@ -62,6 +62,7 @@ namespace { wr_message (to_where (entry), mc_impact_3 | mc_acc_suboptimal | mc_die_other) + .id (descriptor ()) << elfutils::dwarf::tags::name (entry.tag ()) << " has linkage_name attribute, but no external attribute." << std::endl; diff --git a/dwarflint/check_range_out_of_scope.cc b/dwarflint/check_range_out_of_scope.cc index daa2bc3d1..131fe187e 100644 --- a/dwarflint/check_range_out_of_scope.cc +++ b/dwarflint/check_range_out_of_scope.cc @@ -176,12 +176,12 @@ check_range_out_of_scope::recursively_validate if (!result.empty ()) { - wr_message (wh, mc_error) + wr_message (wh, mc_error).id (descriptor ()) << "PC range " << cov::format_ranges (cov1) << " is not a sub-range of containing scope." << std::endl; - wr_message (wh_parent, mc_error) + wr_message (wh_parent, mc_error).when_prev () << "in this context: " << cov::format_ranges (cov2) << std::endl; } @@ -221,19 +221,17 @@ check_range_out_of_scope::recursively_validate ::Dwarf_Addr length = end - start; if (length > 0 // skip empty ranges && !cov.is_covered (start, length)) - { - runoff = true; - wr_message (wh, mc_error) - << "attribute `" - << elfutils::dwarf::attributes::name ((*at).first) - << "': PC range " << pri::range (start, end) - << " outside containing scope." << std::endl; - } + wr_message (wh, mc_error) + .id (descriptor (), runoff) + << "attribute `" + << elfutils::dwarf::attributes::name ((*at).first) + << "': PC range " << pri::range (start, end) + << " outside containing scope." << std::endl; } - if (runoff) - wr_message (wh_parent, mc_error) - << "in this context: " << cov::format_ranges (cov) - << '.' << std::endl; + wr_message (wh_parent, mc_error) + .when (runoff) + << "in this context: " << cov::format_ranges (cov) + << '.' << std::endl; } } } diff --git a/dwarflint/check_self_referential_die.cc b/dwarflint/check_self_referential_die.cc index bf62bf4a3..c25493481 100644 --- a/dwarflint/check_self_referential_die.cc +++ b/dwarflint/check_self_referential_die.cc @@ -68,6 +68,7 @@ namespace if (ref.identity () == entry.identity ()) wr_message (to_where (entry), mc_impact_3 | mc_acc_suboptimal | mc_die_rel) + .id (descriptor ()) << dwarf::tags::name (entry.tag ()) << " attribute " << dwarf::attributes::name ((*at).first) << " references DIE itself." << std::endl; diff --git a/dwarflint/main.cc b/dwarflint/main.cc index e3ba7c6d4..548a15f54 100644 --- a/dwarflint/main.cc +++ b/dwarflint/main.cc @@ -211,13 +211,13 @@ main (int argc, char *argv[]) try { char const *fname = argv[remaining]; - unsigned int prev_error_count = error_count; if (!only_one) std::cout << std::endl << fname << ":" << std::endl; + wr_reset_counters (); dwarflint lint (fname, check_option.rules); one_passed = true; - if (prev_error_count == error_count && !be_quiet) + if (error_count == 0 && !be_quiet) puts (gettext ("No errors")); } catch (std::runtime_error &e) diff --git a/dwarflint/messages.cc b/dwarflint/messages.cc index 586bc17f1..a803a50a3 100644 --- a/dwarflint/messages.cc +++ b/dwarflint/messages.cc @@ -35,6 +35,7 @@ #include unsigned error_count = 0; +bool message_context::_m_last_emitted; bool message_accept (struct message_criteria const *cri, @@ -336,14 +337,30 @@ message_context::message_context (message_count_filter *filter, {} std::ostream & -message_context::when (bool whether) +message_context::when (bool whether) const { + _m_last_emitted = false; if (whether) - return get_stream (); + { + ++error_count; + _m_last_emitted = true; + + std::ostream &ret = get_stream (); + ret << _m_prefix; + if (_m_where) + ret << *_m_where << ": "; + return ret; + } else return nostream; } +std::ostream & +message_context::when_prev () const +{ + return when (wr_prev_emitted ()); +} + std::ostream & message_context::id (void const *key, bool &whether) { @@ -351,12 +368,11 @@ message_context::id (void const *key, bool &whether) return nostream; else if (int status = _m_filter->should_emit (key)) { - ++error_count; if (status == -1) get_stream () << "(threshold reached for the following message)" << std::endl; whether = true; - return get_stream (); + return when (true); } else return nostream; @@ -372,11 +388,7 @@ message_context::id (void const *key) std::ostream & message_context::operator << (char const *message) { - std::ostream &ret = id (message); - ret << _m_prefix; - if (_m_where) - ret << *_m_where << ": "; - return ret << message; + return id (message) << message; } std::ostream & @@ -469,3 +481,16 @@ wr_message_padding_n0 (message_category category, wh, start, end, "unreferenced non-zero bytes"); } + +void +wr_reset_counters () +{ + error_count = 0; + message_count_filter::inst ()->clear (); +} + +bool +wr_prev_emitted () +{ + return message_context::_m_last_emitted; +} diff --git a/dwarflint/messages.hh b/dwarflint/messages.hh index bd945c424..6e85d4299 100644 --- a/dwarflint/messages.hh +++ b/dwarflint/messages.hh @@ -166,6 +166,14 @@ class message_count_filter // NULL for filtered-out message, otherwise array of // pairs sorted by key. counters_t _m_counters; + friend void wr_reset_counters (); + + void + clear () + { + counters_t empty; + _m_counters.swap (empty); + } public: @@ -180,12 +188,15 @@ public: class message_context { + static bool _m_last_emitted; + message_count_filter *_m_filter; where const *_m_where; char const *_m_prefix; friend message_context wr_message (where const &wh, message_category cat); friend message_context wr_message (message_category cat); + friend bool wr_prev_emitted (); message_context (message_count_filter *filter, where const *where, char const *prefix); @@ -215,12 +226,16 @@ public: std::ostream &id (void const *key, bool &whether); // Return either the full stream, or a sink, depending on WHETHER. - std::ostream &when (bool whether); + std::ostream &when (bool whether) const; + + std::ostream &when_prev () const; }; std::ostream &wr_error (where const &wh); std::ostream &wr_error (); message_context wr_message (where const &wh, message_category cat); message_context wr_message (message_category cat); +void wr_reset_counters (); +bool wr_prev_emitted (); #endif//DWARFLINT_MESSAGES_HH diff --git a/dwarflint/tests/run-check_duplicate_DW_tag_variable.sh b/dwarflint/tests/run-check_duplicate_DW_tag_variable.sh index 9b22daf50..3a4de1b77 100755 --- a/dwarflint/tests/run-check_duplicate_DW_tag_variable.sh +++ b/dwarflint/tests/run-check_duplicate_DW_tag_variable.sh @@ -32,143 +32,143 @@ testfiles crc7.ko.debug testrun_compare ./dwarflint --check check_duplicate_DW_tag_variable crc7.ko.debug <