From: Roland McGrath Date: Thu, 1 Oct 2009 22:41:16 +0000 (-0700) Subject: dwarfcmp: Describe reference mismatch details at the end. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=87eed597758ba3c6733a32ea5f2ce15cb74dc228;p=thirdparty%2Felfutils.git dwarfcmp: Describe reference mismatch details at the end. --- diff --git a/src/ChangeLog b/src/ChangeLog index 9d5a50a5e..7fd73b0c5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2009-10-01 Roland McGrath + + * dwarfcmp.cc (talker): Describe reference mismatch details at the + end, iterating when that mentions new mismatches. + 2009-09-30 Roland McGrath * dwarfcmp.cc: Support four-argument usage to compare specific entries. diff --git a/src/dwarfcmp.cc b/src/dwarfcmp.cc index aba8c86b7..50c6d96a6 100644 --- a/src/dwarfcmp.cc +++ b/src/dwarfcmp.cc @@ -158,10 +158,27 @@ struct talker : public dwarf_ref_tracker } }; - typedef std::tr1::unordered_set > die2_set; + template + struct die_equal_to + : public std::equal_to + { + inline dwarf::debug_info_entry::identity_type + operator () (const die &a, const die &b) const + { + return (*a).identity () == (*b).identity (); + } + }; + + typedef std::tr1::unordered_set, die_equal_to + > die2_set; typedef std::tr1::unordered_map > context_map; + die_hasher, die_equal_to + > context_map; context_map bad_context_; + context_map reference_mismatches_; + typedef std::pair identity_pair; + std::set mismatches_printed_; string prefix_; @@ -169,9 +186,10 @@ struct talker : public dwarf_ref_tracker const typename dwarf2::debug_info_entry *b_; bool result_; bool visiting_result_; + bool mismatches_pending_; inline talker () - : a_ (NULL), b_ (NULL), result_ (true) + : a_ (NULL), b_ (NULL), result_ (true), mismatches_pending_ (false) {} inline talker (const talker &proto, typename subtracker::reference_match &m, @@ -321,6 +339,60 @@ struct talker : public dwarf_ref_tracker cout << " (" << ref1->to_string () << " != " << ref2->to_string () << ")"; + if (reference_mismatches_[ref1].insert (ref2).second) + mismatches_pending_ = true; + } + } + + struct prefixer + { + string &string_; + inline explicit prefixer (string &p) : string_ (p) {} + inline ~prefixer () + { + string_.clear (); + } + }; + + inline void + for_context_map (const context_map &context, + void (talker::*method) (const die1 &, const die2 &)) + { + for (typename context_map::const_iterator i = context.begin (); + i != context.end (); + ++i) + for (typename die2_set::const_iterator j = i->second.begin (); + j != i->second.end (); + ++j) + (this->*method) (i->first, *j); + } + + inline void print_one_reference_mismatch (const die1 &ref1, const die2 &ref2) + { + if (mismatches_printed_.insert (identity_pair ((*ref1).identity (), + (*ref2).identity ())).second) + { + prefixer here (prefix_); + { + ostringstream pfx; + pfx << "reference " + << hex << (*ref1).offset () << " vs " << (*ref2).offset () + << ": "; + prefix_ = pfx.str (); + } + dwarf_comparator (*this) + .equals (ref1, ref2); + } + } + + inline void print_reference_mismatches () + { + // Print the pending mismatches and loop if that adds more fresh ones. + while (mismatches_pending_) + { + mismatches_pending_ = false; + for_context_map (reference_mismatches_, + &talker::print_one_reference_mismatch); } } @@ -328,6 +400,7 @@ struct talker : public dwarf_ref_tracker { dwarf_comparator cmp (*this); + prefixer here (prefix_); { ostringstream pfx; pfx << hex << (*ref1).offset () << " vs " << (*ref2).offset () @@ -369,13 +442,7 @@ struct talker : public dwarf_ref_tracker inline void print_bad_context () { - for (typename context_map::const_iterator i = bad_context_.begin (); - i != bad_context_.end (); - ++i) - for (typename die2_set::const_iterator j = i->second.begin (); - j != i->second.end (); - ++j) - print_one_bad_context (i->first, *j); + for_context_map (bad_context_, &talker::print_one_bad_context); } }; @@ -462,6 +529,7 @@ struct noisy_cmp assert (this->_m_tracker.bad_context_.empty ()); return true; } + this->_m_tracker.print_reference_mismatches (); this->_m_tracker.print_bad_context (); return false; }