+2009-03-25 Roland McGrath <roland@redhat.com>
+
+ * dwarf-print.cc (print_die, process_file): Take LIMIT argument.
+ Punt recursion at that depth.
+ (main): Grok first argument --depth=N to set it.
+
2009-03-24 Roland McGrath <roland@redhat.com>
* dwarf-print.cc: New file.
}
static void
-print_die (const dwarf::debug_info_entry &die, unsigned int indent)
+print_die (const dwarf::debug_info_entry &die,
+ unsigned int indent, unsigned int limit)
{
string prefix (indent, ' ');
const string tag = dwarf::tags::name (die.tag ());
if (die.has_children ())
{
+ if (indent >= limit)
+ {
+ cout << ">...\n";
+ return;
+ }
+
cout << ">\n";
for (dwarf::debug_info_entry::children::const_iterator i
= die.children ().begin (); i != die.children ().end (); ++i)
- print_die (*i, indent + 1);
+ print_die (*i, indent + 1, limit);
cout << prefix << "</" << tag << ">\n";
}
}
static void
-process_file (const char *file)
+process_file (const char *file, unsigned int limit)
{
dwarf dw (open_file (file));
cout << file << ":\n";
- for (dwarf::compile_units::const_iterator i = dw.compile_units ().begin ();
- i != dw.compile_units ().end ();
- ++i)
- print_die (*i, 1);
+ if (limit > 0)
+ for (dwarf::compile_units::const_iterator i = dw.compile_units ().begin ();
+ i != dw.compile_units ().end ();
+ ++i)
+ print_die (*i, 1, limit);
}
int
cout << hex << setiosflags (ios::showbase);
+ unsigned int depth = 1;
+ if (argc > 1 && sscanf (argv[1], "--depth=%u", &depth) == 1)
+ {
+ --argc;
+ ++argv;
+ }
+
for (int i = 1; i < argc; ++i)
- process_file (argv[i]);
+ process_file (argv[i], depth);
return 0;
}