summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPetr Machata <[email protected]>2009-07-03 18:35:44 +0200
committerPetr Machata <[email protected]>2009-07-03 18:35:44 +0200
commit0451d0665372bc60e0d9dc5e20cfccf584e4e0dc (patch)
treef39f3cfe3eee3af53c11cec384692ca32a874d6e /tests
parent520733f24e6acd6432f6521e3a69b71ca98be519 (diff)
parent603e7cc9f8ec6c58fc77d0253b6fe8172d8aaaf2 (diff)
Merge commit 'origin/dwarf' into dwarf
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog16
-rw-r--r--tests/Makefile.am13
-rw-r--r--tests/dwarf-print.cc74
-rw-r--r--tests/dwarf_edit.cc66
-rw-r--r--tests/print-die.hh164
-rwxr-xr-xtests/run-dwarf-attributes.sh2
-rwxr-xr-xtests/run-dwarf_edit.sh36
-rwxr-xr-xtests/run-dwarfcmp-self.sh16
8 files changed, 309 insertions, 78 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 3c734f45..d7c99a18 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,19 @@
+2009-07-02 Roland McGrath <[email protected]>
+
+ * run-dwarf_edit.sh: New file.
+ * dwarf_edit.cc: New file.
+ * Makefile.am (noinst_PROGRAMS, TESTS, EXTRA_DIST): Add them.
+ (dwarf_edit_SOURCES, dwarf_edit_LDADD): New variables.
+
+ * dwarf-print.cc (print_die): Templatify and move ...
+ * print-die.hh: ... here, new file.
+ * Makefile.am (noinst_HEADERS): New variable, add it.
+
+2009-07-01 Roland McGrath <[email protected]>
+
+ * run-dwarfcmp-self.sh: Run on dwarflint too.
+ Fiddle failure output.
+
2009-06-15 Roland McGrath <[email protected]>
* dwarf-print.cc: Include <cstdio>.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ba950088..41cd9f32 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -52,6 +52,8 @@ else
tests_rpath = no
endif
+noinst_HEADERS = print-die.hh
+
noinst_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
showptable update1 update2 update3 update4 test-nlist \
show-die-info get-files get-lines get-pubnames \
@@ -60,7 +62,8 @@ noinst_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
find-prologues funcretval allregs rdwrmmap \
dwfl-bug-addr-overflow arls dwfl-bug-fd-leak \
dwfl-addr-sect dwfl-bug-report early-offscn \
- dwfl-bug-getmodules dwarf-getmacros dwarf-print
+ dwfl-bug-getmodules dwarf-getmacros dwarf-print \
+ dwarf_edit
# get-ciefde
asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -87,7 +90,8 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
run-dwfl-bug-offline-rel.sh run-dwfl-addr-sect.sh \
run-disasm-x86.sh run-disasm-x86-64.sh \
run-early-offscn.sh run-dwarf-getmacros.sh \
- run-dwarfcmp-self.sh run-dwarflint-self.sh run-dwarf-attributes.sh
+ run-dwarfcmp-self.sh run-dwarflint-self.sh run-dwarf-attributes.sh \
+ run-dwarf_edit.sh
# run-show-ciefde.sh
if !STANDALONE
@@ -122,7 +126,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
run-dwfl-addr-sect.sh run-early-offscn.sh \
run-dwarf-getmacros.sh \
run-dwarfcmp-self.sh run-dwarflint-self.sh \
- run-dwarf-attributes.sh \
+ run-dwarf-attributes.sh run-dwarf_edit.sh \
testfile15.bz2 testfile15.debug.bz2 \
testfile16.bz2 testfile16.debug.bz2 \
testfile17.bz2 testfile17.debug.bz2 \
@@ -193,6 +197,9 @@ libdwpp = ../libdw/libdwpp.a $(libdw)
dwarf_print_SOURCES = dwarf-print.cc
dwarf_print_LDADD = $(libdwpp) $(libmudflap) -ldl
+dwarf_edit_SOURCES = dwarf_edit.cc
+dwarf_edit_LDADD = $(libdwpp) $(libmudflap) -ldl
+
arextract_LDADD = $(libelf) $(libmudflap)
arsymtest_LDADD = $(libelf) $(libmudflap)
newfile_LDADD = $(libelf) $(libmudflap)
diff --git a/tests/dwarf-print.cc b/tests/dwarf-print.cc
index d37a006a..36b9415b 100644
--- a/tests/dwarf-print.cc
+++ b/tests/dwarf-print.cc
@@ -30,17 +30,14 @@
#include <errno.h>
#include <error.h>
#include <fcntl.h>
-#include <clocale>
-#include <cstdio>
-#include <libintl.h>
-#include <ostream>
-#include <iomanip>
#include "c++/dwarf"
using namespace elfutils;
using namespace std;
+#include "print-die.hh"
+
static Dwarf *
open_file (const char *fname)
{
@@ -57,75 +54,14 @@ open_file (const char *fname)
return dw;
}
-static void
-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 ());
-
- cout << prefix << "<" << tag << " offset=[" << die.offset () << "]";
-
- for (dwarf::debug_info_entry::attributes_type::const_iterator i
- = die.attributes ().begin (); i != die.attributes ().end (); ++i)
- cout << " " << (*i).to_string ();
-
- if (die.has_children ())
- {
- if (limit != 0 && indent >= limit)
- {
- cout << ">...\n";
- return;
- }
-
- cout << ">\n";
-
- for (dwarf::debug_info_entry::children_type::const_iterator i
- = die.children ().begin (); i != die.children ().end (); ++i)
- print_die (*i, indent + 1, limit);
-
- cout << prefix << "</" << tag << ">\n";
- }
- else
- cout << "/>\n";
-}
-
-static void
-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, limit);
-}
-
int
main (int argc, char *argv[])
{
- /* Set locale. */
- (void) setlocale (LC_ALL, "");
-
- /* Make sure the message catalog can be found. */
- (void) bindtextdomain (PACKAGE_TARNAME, LOCALEDIR);
-
- /* Initialize the message catalog. */
- (void) textdomain (PACKAGE_TARNAME);
-
- cout << hex << setiosflags (ios::showbase);
-
- unsigned int depth = 0;
- if (argc > 1 && sscanf (argv[1], "--depth=%u", &depth) == 1)
- {
- --argc;
- ++argv;
- }
+ unsigned int depth;
+ print_die_main (argc, argv, depth);
for (int i = 1; i < argc; ++i)
- process_file (argv[i], depth);
+ print_file (argv[i], dwarf (open_file (argv[i])), depth);
return 0;
}
diff --git a/tests/dwarf_edit.cc b/tests/dwarf_edit.cc
new file mode 100644
index 00000000..67460533
--- /dev/null
+++ b/tests/dwarf_edit.cc
@@ -0,0 +1,66 @@
+/* Test program for elfutils::dwarf_edit basics.
+ Copyright (C) 2009 Red Hat, Inc.
+ This file is part of Red Hat elfutils.
+
+ Red Hat elfutils is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by the
+ Free Software Foundation; version 2 of the License.
+
+ Red Hat elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Red Hat elfutils; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+ Red Hat elfutils is an included package of the Open Invention Network.
+ An included package of the Open Invention Network is a package for which
+ Open Invention Network licensees cross-license their patents. No patent
+ license is granted, either expressly or impliedly, by designation as an
+ included package. Should you wish to participate in the Open Invention
+ Network licensing program, please visit www.openinventionnetwork.com
+ <http://www.openinventionnetwork.com>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "c++/dwarf_edit"
+
+using namespace elfutils;
+using namespace std;
+
+#include "print-die.hh"
+
+
+int
+main (int argc, char **argv)
+{
+ unsigned int depth;
+ print_die_main (argc, argv, depth);
+
+ dwarf_edit f;
+
+ dwarf_edit::compile_unit &cu = f.add_unit ();
+
+ cu.attributes ()[DW_AT_name].source_file () = "source-file.c";
+
+ 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
new file mode 100644
index 00000000..3f4cd9d2
--- /dev/null
+++ b/tests/print-die.hh
@@ -0,0 +1,164 @@
+/* Pseudo-XMLish printing for elfutils::dwarf* tests.
+ Copyright (C) 2009 Red Hat, Inc.
+ This file is part of Red Hat elfutils.
+
+ Red Hat elfutils is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by the
+ Free Software Foundation; version 2 of the License.
+
+ Red Hat elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Red Hat elfutils; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+ Red Hat elfutils is an included package of the Open Invention Network.
+ An included package of the Open Invention Network is a package for which
+ Open Invention Network licensees cross-license their patents. No patent
+ license is granted, either expressly or impliedly, by designation as an
+ included package. Should you wish to participate in the Open Invention
+ Network licensing program, please visit www.openinventionnetwork.com
+ <http://www.openinventionnetwork.com>. */
+
+#include <cstring>
+#include <cstdio>
+#include <clocale>
+#include <libintl.h>
+#include <ostream>
+#include <iomanip>
+#include <tr1/unordered_map>
+
+static bool print_offset;
+
+static void
+print_die_main (int &argc, char **&argv, unsigned int &depth)
+{
+ /* Set locale. */
+ (void) setlocale (LC_ALL, "");
+
+ /* Make sure the message catalog can be found. */
+ (void) bindtextdomain (PACKAGE_TARNAME, LOCALEDIR);
+
+ /* Initialize the message catalog. */
+ (void) textdomain (PACKAGE_TARNAME);
+
+ cout << hex << setiosflags (ios::showbase);
+
+ if (argc > 1 && !strcmp (argv[1], "--offsets"))
+ {
+ print_offset = true;
+ --argc;
+ ++argv;
+ }
+
+ depth = 0;
+ if (argc > 1 && sscanf (argv[1], "--depth=%u", &depth) == 1)
+ {
+ --argc;
+ ++argv;
+ }
+}
+
+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<typename file>
+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<file> (*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<typename file>
+static void
+print_die (const typename file::debug_info_entry &die,
+ unsigned int indent, unsigned int limit, refs_map &refs)
+{
+ string prefix (indent, ' ');
+ const string tag = dwarf::tags::name (die.tag ());
+
+ 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)
+ {
+ 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 ())
+ {
+ if (limit != 0 && indent >= limit)
+ {
+ cout << ">...\n";
+ return;
+ }
+
+ cout << ">\n";
+
+ for (typename file::debug_info_entry::children_type::const_iterator i
+ = die.children ().begin (); i != die.children ().end (); ++i)
+ print_die<file> (*i, indent + 1, limit, refs);
+
+ cout << prefix << "</" << tag << ">\n";
+ }
+ else
+ cout << "/>\n";
+}
+
+template<typename file>
+static void
+print_cu (const typename file::compile_unit &cu, const unsigned int limit)
+{
+ const typename file::debug_info_entry &die = cu;
+ // static_cast<const typename file::debug_info_entry &> (cu),
+
+ refs_map refs;
+
+ if (!print_offset)
+ {
+ prewalk_die<file> (die, refs);
+ finish_refs_map (refs);
+ }
+
+ print_die<file> (die, 1, limit, refs);
+}
+
+template<typename file>
+static void
+print_file (const char *name, const file &dw, const unsigned int limit)
+{
+ cout << name << ":\n";
+
+ for (typename file::compile_units::const_iterator i
+ = dw.compile_units ().begin (); i != dw.compile_units ().end (); ++i)
+ print_cu<file> (*i, limit);
+}
diff --git a/tests/run-dwarf-attributes.sh b/tests/run-dwarf-attributes.sh
index 22c7289d..4aa170ba 100755
--- a/tests/run-dwarf-attributes.sh
+++ b/tests/run-dwarf-attributes.sh
@@ -27,7 +27,7 @@
testfiles testfile
-testrun_compare ./dwarf-print --depth=1 testfile <<\EOF
+testrun_compare ./dwarf-print --offsets --depth=1 testfile <<\EOF
testfile:
<compile_unit offset=[0xb] stmt_list=0 high_pc=0x804845a low_pc=0x804842c name="m.c" comp_dir="/home/drepper/gnu/new-bu/build/ttt" producer="GNU C 2.96 20000731 (Red Hat Linux 7.0)" language=C89>...
<compile_unit offset=[0xca] stmt_list=0x4b high_pc=0x8048466 low_pc=0x804845c name="b.c" comp_dir="/home/drepper/gnu/new-bu/build/ttt" producer="GNU C 2.96 20000731 (Red Hat Linux 7.0)" language=C89>...
diff --git a/tests/run-dwarf_edit.sh b/tests/run-dwarf_edit.sh
new file mode 100755
index 00000000..2ae53209
--- /dev/null
+++ b/tests/run-dwarf_edit.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# Copyright (C) 2009 Red Hat, Inc.
+# This file is part of Red Hat elfutils.
+#
+# Red Hat elfutils is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by the
+# Free Software Foundation; version 2 of the License.
+#
+# Red Hat elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Red Hat elfutils; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+#
+# Red Hat elfutils is an included package of the Open Invention Network.
+# An included package of the Open Invention Network is a package for which
+# Open Invention Network licensees cross-license their patents. No patent
+# license is granted, either expressly or impliedly, by designation as an
+# included package. Should you wish to participate in the Open Invention
+# Network licensing program, please visit www.openinventionnetwork.com
+# <http://www.openinventionnetwork.com>.
+
+. $srcdir/test-subr.sh
+
+testrun_compare ./dwarf_edit <<\EOF
+consed:
+ <compile_unit name="source-file.c">
+ <base_type ref="0x1" name="int"/>
+ <subprogram name="foo" external=1 type="#0x1" description="foo"/>
+ </compile_unit>
+EOF
+
+exit 0
diff --git a/tests/run-dwarfcmp-self.sh b/tests/run-dwarfcmp-self.sh
index 927083ed..cce6641a 100755
--- a/tests/run-dwarfcmp-self.sh
+++ b/tests/run-dwarfcmp-self.sh
@@ -26,21 +26,27 @@
. $srcdir/test-subr.sh
status=0
+run_one()
+{
+ file="$1"; shift
+ testrun ../src/dwarfcmp "$@" "$file" "$file" ||
+ { echo "*** failure in dwarfcmp-self $* on $file"; status=1; }
+}
+
runtest()
{
for file; do
if [ -f $file ]; then
- { testrun ../src/dwarfcmp -q -i $file $file &&
- testrun ../src/dwarfcmp -i $file $file &&
- testrun ../src/dwarfcmp -T -q -i $file $file
- } ||
- { echo "*** failure in $file"; status=1; }
+ run_one "$file" -i -q
+ run_one "$file" -i
+ run_one "$file" -i -q -T
fi
done
}
runtest ../src/addr2line
runtest ../src/dwarfcmp
+runtest ../src/dwarflint
runtest ../src/elfcmp
runtest ../src/elflint
runtest ../src/findtextrel