From c5abbd81011342d23d7aeedeb93a29202daaf7ef Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Wed, 19 Aug 2009 20:59:19 -0700 Subject: closest yet --- tests/print-die.hh | 57 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/print-die.hh b/tests/print-die.hh index 7b4fa3f5..d946a9eb 100644 --- a/tests/print-die.hh +++ b/tests/print-die.hh @@ -39,6 +39,8 @@ static bool print_offset; static bool sort_attrs; +static bool elide_refs; +static bool dump_refs; static enum { copy_none, copy_edit, copy_output } make_copy; @@ -63,6 +65,20 @@ print_die_main (int &argc, char **&argv, unsigned int &depth) ++argv; } + if (argc > 1 && !strcmp (argv[1], "--norefs")) + { + elide_refs = true; + --argc; + ++argv; + } + + if (argc > 1 && !strcmp (argv[1], "--dump-refs")) + { + dump_refs = true; + --argc; + ++argv; + } + if (argc > 1 && !strcmp (argv[1], "--sort-attrs")) { sort_attrs = true; @@ -92,7 +108,8 @@ print_die_main (int &argc, char **&argv, unsigned int &depth) } static int next_ref = 1; -typedef tr1::unordered_map< ::Dwarf_Off, int> refs_map; +typedef tr1::unordered_map refs_map; templateidentity ()] << "\""; + { + if (elide_refs) + cout << " " << dwarf::attributes::name (attr.first) << "=\"ref\""; + else + cout << " " << dwarf::attributes::name (attr.first) << "=\"#ref" + << dec << refs[attr.second.reference ()->identity ()] << "\""; + } else cout << " " << to_string (attr); } @@ -174,6 +196,9 @@ prewalk_die (const typename file::debug_info_entry &die, refs_map &refs) prewalk_attrs (die.attributes (), refs); } +static int nth; +static std::map nth_ref; + template static void print_die (const typename file::debug_info_entry &die, @@ -182,14 +207,21 @@ print_die (const typename file::debug_info_entry &die, string prefix (indent, ' '); const string tag = dwarf::tags::name (die.tag ()); + ++nth; + if (dump_refs) + cout << dec << nth << ": "; + cout << prefix << "<" << tag; if (print_offset) - cout << " offset=[" << die.offset () << "]"; - else + cout << " offset=[" << hex << die.offset () << "]"; + else if (!elide_refs) { refs_map::const_iterator it = refs.find (die.identity ()); if (it != refs.end ()) - cout << " ref=\"ref" << dec << it->second << "\""; + { + cout << " ref=\"ref" << dec << it->second << "\""; + nth_ref[nth] = it->second; + } } print_attrs (die.attributes (), refs); @@ -214,6 +246,12 @@ print_die (const typename file::debug_info_entry &die, cout << "/>\n"; } +static inline void +dump_nth (pair p) +{ + cout << dec << p.first << ": ref" << p.second << "\n"; +} + template static void print_cu (const typename file::compile_unit &cu, const unsigned int limit) @@ -223,10 +261,13 @@ print_cu (const typename file::compile_unit &cu, const unsigned int limit) refs_map refs; - if (!print_offset) + if (!print_offset && !elide_refs) prewalk_die (die, refs); print_die (die, 1, limit, refs); + + if (dump_refs) + for_each (nth_ref.begin (), nth_ref.end (), dump_nth); } template -- cgit v1.2.3