]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Support to_string on debug_info_entry.
authorRoland McGrath <roland@redhat.com>
Sat, 11 Jul 2009 00:04:44 +0000 (17:04 -0700)
committerRoland McGrath <roland@redhat.com>
Sat, 11 Jul 2009 00:04:44 +0000 (17:04 -0700)
libdw/c++/data-values.hh
libdw/c++/dwarf
libdw/c++/dwarf_edit
libdw/c++/dwarf_output
libdw/c++/edit-values.cc
libdw/c++/output-values.cc
libdw/c++/values.cc
src/dwarfcmp.cc

index 86049e2e78ffef05fba9089ee5b9030aed4daa56..712dd6bf6fa9e52cc84cea2f8d6e5fd43d2e5559 100644 (file)
@@ -100,4 +100,23 @@ namespace elfutils
     return result;
   }
 
+  template<typename die_type>
+  std::string
+  die_string (const die_type &die)
+  {
+    std::string result ("<");
+    result += dwarf::tags::name (die.tag ());
+
+    typename die_type::attributes_type::const_iterator name_attr
+      = die.attributes ().find (::DW_AT_name);
+    if (name_attr != die.attributes ().end ())
+      {
+       result += " ";
+       result += to_string (*name_attr);
+      }
+
+    result += die.has_children () ? ">" : "/>";
+    return result;
+  }
+
 };
index 103dc08dfd372a0e585f26b4b078d953a459a34f..ef2833b437d337132af78a1ff987fea1ff9d1644 100644 (file)
@@ -451,6 +451,8 @@ namespace elfutils
 
       class const_pointer;
 
+      inline std::string to_string () const;
+
       inline int tag () const
       {
        int t = ::dwarf_tag (thisdie ());
@@ -2468,6 +2470,13 @@ namespace elfutils
 
   // Explicit specializations.
   template<>
+  std::string
+  to_string<dwarf::debug_info_entry> (const dwarf::debug_info_entry &);
+  inline std::string dwarf::debug_info_entry::to_string () const
+  {
+    return elfutils::to_string (*this); // Use that.
+  }
+  template<>
   std::string to_string<dwarf::attribute> (const dwarf::attribute &);
   inline std::string dwarf::attribute::to_string () const
   {
index badb71d005f4d4e02ce60c563e6027b9e5f3818e..ebadc6cc9c7fab216b11fbb2a4712aeedc700877 100644 (file)
@@ -194,6 +194,8 @@ namespace elfutils
          _m_children (die.children (), t)
       {}
 
+      inline std::string to_string () const;
+
       inline int tag () const
       {
        return _m_tag;
@@ -371,6 +373,13 @@ namespace elfutils
 
   // Explicit specializations.
   template<>
+  std::string to_string<dwarf_edit::debug_info_entry>
+  (const dwarf_edit::debug_info_entry &);
+  inline std::string dwarf_edit::debug_info_entry::to_string () const
+  {
+    return elfutils::to_string (*this); // Use that.
+  }
+  template<>
   std::string to_string<dwarf_edit::attribute> (const dwarf_edit::attribute &);
   template<>
   std::string to_string<dwarf_edit::attr_value> (const dwarf_edit::attr_value&);
index bb50392227fdeef8eba756299c19f8c5b2028dbe..341f8e7700bfd198efcfb3bd8bd6d73bbc3817e1 100644 (file)
@@ -403,6 +403,8 @@ namespace elfutils
                && _m_children == that._m_children);
       }
 
+      inline std::string to_string () const;
+
       inline int tag () const
       {
        return _m_tag;
@@ -585,6 +587,13 @@ namespace elfutils
 
   // Explicit specializations.
   template<>
+  std::string to_string<dwarf_output::debug_info_entry>
+  (const dwarf_output::debug_info_entry &);
+  inline std::string dwarf_output::debug_info_entry::to_string () const
+  {
+    return elfutils::to_string (*this); // Use that.
+  }
+  template<>
   std::string
   to_string<dwarf_output::attribute> (const dwarf_output::attribute &);
   template<>
@@ -602,6 +611,7 @@ namespace elfutils
 
   private:
     dwarf_path_finder<dwarf_output> _m_tracker;
+    unsigned int _m_total;
 
     typedef dwarf_output::debug_info_entry die_type;
     typedef die_type::attributes_type attrs_type;
@@ -671,6 +681,7 @@ namespace elfutils
        = *_m_unique.insert (std::make_pair (die_type (other, c),
                                             die_info ())).first;
       x.second.uses++;
+      ++_m_total;
       if (has_sibling)
        x.second.with_sibling = true;
       else
@@ -710,6 +721,26 @@ namespace elfutils
     shape_map _m_shapes;
 
     void add_shape (die_type &die, bool last_sibling);
+
+  public:
+    inline dwarf_output_collector ()
+      : _m_total (0)
+    {}
+
+    static void die_stats (const die_map::value_type &elt)
+    {
+      std::cout << to_string (elt.first) << " uses="
+               << std::dec << elt.second.uses
+               << " (" << elt.second.with_sibling
+               << "," << elt.second.without_sibling << ")\n";
+    }
+
+    void stats () const
+    {
+      std::cout << "collected " << std::dec << _m_unique.size ()
+               << " unique of " << _m_total << " total DIEs\n";
+      std::for_each (_m_unique.begin (), _m_unique.end (), die_stats);
+    }
   };
 
   template<typename dw>
index 03c1574391c2c2fe99b8f791ba5809bc0d060ddd..eb26fbb6a6f041a774a2a7cc31fddc300f94f36a 100644 (file)
@@ -62,6 +62,15 @@ to_string<dwarf_edit::attribute> (const dwarf_edit::attribute &attr)
   return attribute_string (attr);
 }
 
+namespace elfutils
+{
+  template<>
+  std::string to_string (const dwarf_edit::debug_info_entry &die)
+  {
+    return die_string (die);
+  }
+};
+
 std::string
 dwarf_data::source_file::to_string () const
 {
index 07212134ce7392bbb9238bb53e61d87bacc785b0..1114d9b75dbabca5d2b451645f722980f9dfc01a 100644 (file)
@@ -64,5 +64,14 @@ to_string<dwarf_output::attribute> (const dwarf_output::attribute &attr)
   return attribute_string (attr);
 }
 
+namespace elfutils
+{
+  template<>
+  std::string to_string (const dwarf_output::debug_info_entry &die)
+  {
+    return die_string (die);
+  }
+};
+
 const dwarf_output::value::value_flag dwarf_output_collector::flag_true (1);
 const dwarf_output::value::value_flag dwarf_output_collector::flag_false (0);
index ccfbd574f8029ed79d18a1d13a2ff8ec7ec24ad6..f012434bcddd6527c83d21f1376c8be3c6cd0fe2 100644 (file)
@@ -363,6 +363,15 @@ dwarf::attr_value::constant_block () const
 
   return const_vector<uint8_t> (block);
 }
+
+namespace elfutils
+{
+  template<>
+  std::string to_string (const dwarf::debug_info_entry &die)
+  {
+    return die_string (die);
+  }
+};
 \f
 // dwarf::range_list
 
index 6d3ee0647e023c3ddcaf78e76117e848bf7c81d8..dda5af75a68035caf9cb4475bd8ed4b9988a8937 100644 (file)
@@ -288,7 +288,9 @@ test_output (const dwarf &file1, const dwarf &file2,
   dwarf_output_collector c1;
   dwarf_output_collector c2;
   dwarf_output out1 (in1, c1);
+  c1.stats ();
   dwarf_output out2 (in2, c2);
+  c2.stats ();
 
   test_classes (file1, file2, out1, out2, same);