summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <roland@redhat.com>2009-07-10 17:04:44 -0700
committerRoland McGrath <roland@redhat.com>2009-07-10 17:04:44 -0700
commitd966424b595fc17959d6ab408e9a5ae89fd1bbc4 (patch)
treeaa07938df5366bf5fdaf1a3a15f773b5b4ec50f4
parentc58d5a90e7f616b7b27196e984e55ec2d6a80b87 (diff)
downloadelfutils-d966424b595fc17959d6ab408e9a5ae89fd1bbc4.tar.gz
Support to_string on debug_info_entry.
-rw-r--r--libdw/c++/data-values.hh19
-rw-r--r--libdw/c++/dwarf9
-rw-r--r--libdw/c++/dwarf_edit9
-rw-r--r--libdw/c++/dwarf_output31
-rw-r--r--libdw/c++/edit-values.cc9
-rw-r--r--libdw/c++/output-values.cc9
-rw-r--r--libdw/c++/values.cc9
-rw-r--r--src/dwarfcmp.cc2
8 files changed, 97 insertions, 0 deletions
diff --git a/libdw/c++/data-values.hh b/libdw/c++/data-values.hh
index 86049e2e..712dd6bf 100644
--- a/libdw/c++/data-values.hh
+++ b/libdw/c++/data-values.hh
@@ -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;
+ }
+
};
diff --git a/libdw/c++/dwarf b/libdw/c++/dwarf
index 103dc08d..ef2833b4 100644
--- a/libdw/c++/dwarf
+++ b/libdw/c++/dwarf
@@ -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
{
diff --git a/libdw/c++/dwarf_edit b/libdw/c++/dwarf_edit
index badb71d0..ebadc6cc 100644
--- a/libdw/c++/dwarf_edit
+++ b/libdw/c++/dwarf_edit
@@ -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&);
diff --git a/libdw/c++/dwarf_output b/libdw/c++/dwarf_output
index bb503922..341f8e77 100644
--- a/libdw/c++/dwarf_output
+++ b/libdw/c++/dwarf_output
@@ -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>
diff --git a/libdw/c++/edit-values.cc b/libdw/c++/edit-values.cc
index 03c15743..eb26fbb6 100644
--- a/libdw/c++/edit-values.cc
+++ b/libdw/c++/edit-values.cc
@@ -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
{
diff --git a/libdw/c++/output-values.cc b/libdw/c++/output-values.cc
index 07212134..1114d9b7 100644
--- a/libdw/c++/output-values.cc
+++ b/libdw/c++/output-values.cc
@@ -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);
diff --git a/libdw/c++/values.cc b/libdw/c++/values.cc
index ccfbd574..f012434b 100644
--- a/libdw/c++/values.cc
+++ b/libdw/c++/values.cc
@@ -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);
+ }
+};
// dwarf::range_list
diff --git a/src/dwarfcmp.cc b/src/dwarfcmp.cc
index 6d3ee064..dda5af75 100644
--- a/src/dwarfcmp.cc
+++ b/src/dwarfcmp.cc
@@ -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);