From: Roland McGrath Date: Thu, 2 Jul 2009 11:12:58 +0000 (-0700) Subject: Test dwarf_edit refs X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d29994ef47cddc7289583b1f506217da23cac5e9;p=thirdparty%2Felfutils.git Test dwarf_edit refs --- diff --git a/tests/dwarf_edit.cc b/tests/dwarf_edit.cc index 5510be1ce..674605334 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 91d70c997..3f4cd9d23 100644 --- a/tests/print-die.hh +++ b/tests/print-die.hh @@ -29,6 +29,7 @@ #include #include #include +#include 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 +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 (*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 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 (*i, indent + 1, limit); + print_die (*i, indent + 1, limit, refs); cout << prefix << "\n"; } @@ -101,8 +138,18 @@ template static void print_cu (const typename file::compile_unit &cu, const unsigned int limit) { - print_die (static_cast (cu), - 1, limit); + const typename file::debug_info_entry &die = cu; + // static_cast (cu), + + refs_map refs; + + if (!print_offset) + { + prewalk_die (die, refs); + finish_refs_map (refs); + } + + print_die (die, 1, limit, refs); } template diff --git a/tests/run-dwarf_edit.sh b/tests/run-dwarf_edit.sh index a7b0baf6e..2ae53209c 100755 --- a/tests/run-dwarf_edit.sh +++ b/tests/run-dwarf_edit.sh @@ -28,7 +28,8 @@ testrun_compare ./dwarf_edit <<\EOF consed: - + + EOF