diff options
| author | Roland McGrath <[email protected]> | 2009-07-02 04:12:58 -0700 |
|---|---|---|
| committer | Roland McGrath <[email protected]> | 2009-07-02 04:17:27 -0700 |
| commit | d29994ef47cddc7289583b1f506217da23cac5e9 (patch) | |
| tree | e9792db67d0d0285c70bc3a8c022b9e8e8b7240a /tests | |
| parent | 18610f8148170420dfe8e88efee4a6207723dcf3 (diff) | |
Test dwarf_edit refs
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/dwarf_edit.cc | 9 | ||||
| -rw-r--r-- | tests/print-die.hh | 57 | ||||
| -rwxr-xr-x | tests/run-dwarf_edit.sh | 3 |
3 files changed, 62 insertions, 7 deletions
diff --git a/tests/dwarf_edit.cc b/tests/dwarf_edit.cc index 5510be1c..67460533 100644 --- a/tests/dwarf_edit.cc +++ b/tests/dwarf_edit.cc @@ -47,12 +47,19 @@ main (int argc, char **argv) cu.attributes ()[DW_AT_name].source_file () = "source-file.c"; - dwarf_edit::debug_info_entry &ent = cu.add_entry (DW_TAG_subprogram); + dwarf_edit::debug_info_entry::pointer bt = cu.add_entry (DW_TAG_base_type); + bt->attributes ()[DW_AT_name].identifier () = "int"; + + dwarf_edit::debug_info_entry &ent = *cu.add_entry (DW_TAG_subprogram); ent.attributes ()[DW_AT_name].identifier () = "foo"; ent.attributes ()[DW_AT_description] = ent.attributes ()[DW_AT_name]; + ent.attributes ()[DW_AT_external].flag (); + + ent.attributes ()[DW_AT_type].reference () = bt; + print_file ("consed", f, depth); return 0; diff --git a/tests/print-die.hh b/tests/print-die.hh index 91d70c99..3f4cd9d2 100644 --- a/tests/print-die.hh +++ b/tests/print-die.hh @@ -29,6 +29,7 @@ #include <libintl.h> #include <ostream> #include <iomanip> +#include <tr1/unordered_map> static bool print_offset; @@ -61,10 +62,34 @@ print_die_main (int &argc, char **&argv, unsigned int &depth) } } +typedef tr1::unordered_map< ::Dwarf_Off, int> refs_map; + +static void +finish_refs_map (refs_map &refs) +{ + int id = 0; + for (refs_map::iterator it = refs.begin (); it != refs.end (); ++it) + it->second = ++id; +} + +template<typename file> +static void +prewalk_die (const typename file::debug_info_entry &die, refs_map &refs) +{ + for (typename file::debug_info_entry::children_type::const_iterator i + = die.children ().begin (); i != die.children ().end (); ++i) + prewalk_die<file> (*i, refs); + + for (typename file::debug_info_entry::attributes_type::const_iterator i + = die.attributes ().begin (); i != die.attributes ().end (); ++i) + if ((*i).second.what_space () == dwarf::VS_reference) + refs[(*i).second.reference ()->identity ()]; +} + template<typename file> static void print_die (const typename file::debug_info_entry &die, - unsigned int indent, unsigned int limit) + unsigned int indent, unsigned int limit, refs_map &refs) { string prefix (indent, ' '); const string tag = dwarf::tags::name (die.tag ()); @@ -72,10 +97,22 @@ print_die (const typename file::debug_info_entry &die, cout << prefix << "<" << tag; if (print_offset) cout << " offset=[" << die.offset () << "]"; + else + { + refs_map::const_iterator it = refs.find (die.identity ()); + if (it != refs.end ()) + cout << " ref=\"" << hex << it->second << "\""; + } for (typename file::debug_info_entry::attributes_type::const_iterator i = die.attributes ().begin (); i != die.attributes ().end (); ++i) - cout << " " << to_string (*i); + { + if (!print_offset && (*i).second.what_space () == dwarf::VS_reference) + cout << " " << dwarf::attributes::name ((*i).first) << "=\"#" + << hex << refs[(*i).second.reference ()->identity ()] << "\""; + else + cout << " " << to_string (*i); + } if (die.has_children ()) { @@ -89,7 +126,7 @@ print_die (const typename file::debug_info_entry &die, for (typename file::debug_info_entry::children_type::const_iterator i = die.children ().begin (); i != die.children ().end (); ++i) - print_die<file> (*i, indent + 1, limit); + print_die<file> (*i, indent + 1, limit, refs); cout << prefix << "</" << tag << ">\n"; } @@ -101,8 +138,18 @@ template<typename file> static void print_cu (const typename file::compile_unit &cu, const unsigned int limit) { - print_die<file> (static_cast<const typename file::debug_info_entry &> (cu), - 1, limit); + const typename file::debug_info_entry &die = cu; + // static_cast<const typename file::debug_info_entry &> (cu), + + refs_map refs; + + if (!print_offset) + { + prewalk_die<file> (die, refs); + finish_refs_map (refs); + } + + print_die<file> (die, 1, limit, refs); } template<typename file> diff --git a/tests/run-dwarf_edit.sh b/tests/run-dwarf_edit.sh index a7b0baf6..2ae53209 100755 --- a/tests/run-dwarf_edit.sh +++ b/tests/run-dwarf_edit.sh @@ -28,7 +28,8 @@ testrun_compare ./dwarf_edit <<\EOF consed: <compile_unit name="source-file.c"> - <subprogram name="foo" description="foo"/> + <base_type ref="0x1" name="int"/> + <subprogram name="foo" external=1 type="#0x1" description="foo"/> </compile_unit> EOF |
