summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRoland McGrath <[email protected]>2009-03-25 17:29:22 -0700
committerRoland McGrath <[email protected]>2009-03-25 17:29:22 -0700
commitd0aa42a6e3728e3f08a8e261bd623db95e81d5d2 (patch)
treeb87aecc5cdef71c79a3541eb6656cbd65ca8b620 /tests
parent9fc0ebb133c332ed9392003e09001ec8cd779931 (diff)
Add output limiting to dwarf-print test.
Diffstat (limited to 'tests')
-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 5affd0c4..6bc5000e 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,9 @@
+2009-03-25 Roland McGrath <[email protected]>
+
+ * 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 <[email protected]>
* 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;
}