summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2009-03-26 01:52:53 +0100
committerPetr Machata <pmachata@redhat.com>2009-03-26 01:52:53 +0100
commit9a19f4dcc2ef6ab6be26003517a139acfdccf0a5 (patch)
treed21a5e3bd3c24a7ff7a5e8af0066efe2be3fff33
parent173830ca220c9aff18d2565a13a6ac97665131d0 (diff)
parentd0aa42a6e3728e3f08a8e261bd623db95e81d5d2 (diff)
downloadelfutils-9a19f4dcc2ef6ab6be26003517a139acfdccf0a5.tar.gz
Merge branch 'dwarf' into pmachata/dwarf
Conflicts: tests/ChangeLog
-rw-r--r--tests/ChangeLog6
-rw-r--r--tests/dwarf-print.cc31
2 files changed, 29 insertions, 8 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index e68018e7..e523c8cd 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -4,6 +4,12 @@
* Makefile.am (noinst_PROGRAMS): Add it.
(dwarf_attributes_SOURCES, dwarf_attributes_LDADD): New variables.
+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.
diff --git a/tests/dwarf-print.cc b/tests/dwarf-print.cc
index 85dc3a76..ece96757 100644
--- a/tests/dwarf-print.cc
+++ b/tests/dwarf-print.cc
@@ -57,7 +57,8 @@ open_file (const char *fname)
}
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 ());
@@ -70,11 +71,17 @@ print_die (const dwarf::debug_info_entry &die, unsigned int indent)
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";
}
@@ -83,16 +90,17 @@ print_die (const dwarf::debug_info_entry &die, unsigned int indent)
}
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
@@ -109,8 +117,15 @@ main (int argc, char *argv[])
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;
}