summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2015-04-03 10:11:34 +0200
committerPetr Machata <pmachata@redhat.com>2015-04-14 16:35:10 +0200
commit205c1b156380e060ae49ef0cd1b108744286efd5 (patch)
tree20819fc6751902bf98f5fc88a022cbce5178bdc8 /tests
parent00cbd21384d3a77637200496c9c3bfb4c54f7a4a (diff)
downloadelfutils-205c1b156380e060ae49ef0cd1b108744286efd5.tar.gz
Add C++ iterators
- Add unit_iterator, child_iterator, die_tree_iterator and attr_iterator for libdw, and dwfl_module_iterator for libdwfl. - The code is shipped in a new library called libdwpp. Signed-off-by: Petr Machata <pmachata@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog7
-rw-r--r--tests/Makefile.am13
-rwxr-xr-xtests/run-test-iterators.sh52
-rw-r--r--tests/test-iterators.cc87
4 files changed, 158 insertions, 1 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index b6861849..728058f4 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2015-04-14 Petr Machata <pmachata@redhat.com>
+
+ * test-iterators.cc, run-test-iterators.sh: New files.
+ * Makefile.am (check_PROGRAMS) [HAVE_CXX]: Add test-iterators.
+ (TESTS) [HAVE_CXX]: Add run-test-iterators.sh.
+ (libdwpp): New variable.
+
2015-04-01 H.J. Lu <hjl.tools@gmail.com>
* Makefile.am (TESTS): Add run-strip-test10.sh.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 45bb74df..5c5cfbfd 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -143,6 +143,11 @@ check_PROGRAMS += $(asm_TESTS)
TESTS += $(asm_TESTS)
endif
+if HAVE_CXX
+check_PROGRAMS += test-iterators
+TESTS += run-test-iterators.sh
+endif
+
EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
run-show-die-info.sh run-get-files.sh run-get-lines.sh \
run-get-pubnames.sh run-get-aranges.sh \
@@ -293,7 +298,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
run-getsrc-die.sh run-strptr.sh \
testfile-x32-core.bz2 testfile-x32.bz2 \
backtrace.x32.core.bz2 backtrace.x32.exec.bz2 \
- testfile-x32-s.bz2 testfile-x32-d.bz2 testfile-x32-debug.bz2
+ testfile-x32-s.bz2 testfile-x32-d.bz2 testfile-x32-debug.bz2 \
+ run-test-iterators.sh
if USE_VALGRIND
valgrind_cmd='valgrind -q --error-exitcode=1 --run-libc-freeres=no'
@@ -337,16 +343,19 @@ endif !STANDALONE
if STANDALONE
libdw = -ldw
+libdwpp = -ldwpp
libelf = -lelf
libasm = -lasm
libebl = -lebl
else !STANDALONE
if BUILD_STATIC
libdw = ../libdw/libdw.a $(zip_LIBS) $(libelf) $(libebl) -ldl
+libdwpp = ../libdw/libdwpp.a $(libdw)
libelf = ../libelf/libelf.a
libasm = ../libasm/libasm.a
else
libdw = ../libdw/libdw.so
+libdwpp = ../libdw/libdwpp.so
libelf = ../libelf/libelf.so
libasm = ../libasm/libasm.so
endif
@@ -438,6 +447,8 @@ getsrc_die_LDADD = $(libdw) $(libelf)
strptr_LDADD = $(libelf)
newdata_LDADD = $(libelf)
elfstrtab_LDADD = $(libelf)
+test_iterators_SOURCES = test-iterators.cc
+test_iterators_LDADD = $(libdw) $(libdwpp)
if GCOV
check: check-am coverage
diff --git a/tests/run-test-iterators.sh b/tests/run-test-iterators.sh
new file mode 100755
index 00000000..69425704
--- /dev/null
+++ b/tests/run-test-iterators.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+# Copyright (C) 2015 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file 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; either version 3 of the License, or
+# (at your option) any later version.
+#
+# 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 this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+testfiles testfile39 testfile-debug-types
+
+testrun_compare ${abs_top_builddir}/tests/test-iterators testfile39 <<\EOF
+0xb
+0x9e
+0x135
+0x1c8
+0 7
+0 7
+0 7
+0 7
+EOF
+
+testrun_compare ${abs_top_builddir}/tests/test-iterators testfile-debug-types <<\EOF
+0xb
+0x17
+0x5a
+4 6
+0 9
+0 3
+0 6
+0 6
+2 3
+1 4
+0 2
+0 5
+1 3
+2 4
+0 3
+0 5
+EOF
+
+exit 0
diff --git a/tests/test-iterators.cc b/tests/test-iterators.cc
new file mode 100644
index 00000000..987bc6af
--- /dev/null
+++ b/tests/test-iterators.cc
@@ -0,0 +1,87 @@
+/* Copyright (C) 2015 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file 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; either version 3 of the License, or
+ (at your option) any later version.
+
+ 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 this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <iostream>
+#include <cassert>
+#include <stdexcept>
+
+#include "../libdw/c++/libdw"
+#include "../libdwfl/c++/libdwfl"
+#include "../libdw/c++/libdwP.hh"
+#include "../libdwfl/c++/libdwflP.hh"
+
+int
+main (int, char *argv[])
+{
+ int fd = open (argv[1], O_RDONLY);
+ if (fd < 0)
+ throw std::runtime_error (strerror (errno));
+
+ const static Dwfl_Callbacks callbacks =
+ {
+ .find_elf = dwfl_build_id_find_elf,
+ .find_debuginfo = dwfl_standard_find_debuginfo,
+ .section_address = dwfl_offline_section_address,
+ .debuginfo_path = NULL,
+ };
+
+ Dwfl *dwfl = dwfl_begin (&callbacks);
+ if (dwfl == NULL)
+ throw_libdwfl ();
+
+ dwfl_report_begin (dwfl);
+ if (dwfl_report_offline (dwfl, argv[1], argv[1], fd) == NULL)
+ throw_libdwfl ();
+ dwfl_report_end (dwfl, NULL, NULL);
+
+ for (elfutils::dwfl_module_iterator modit (dwfl);
+ modit != elfutils::dwfl_module_iterator::end (); ++modit)
+ {
+ Dwarf_Off bias;
+ Dwarf *dw = dwfl_module_getdwarf (&*modit, &bias);
+ std::vector <std::pair <elfutils::unit_iterator, Dwarf_Die> > cudies;
+ for (elfutils::unit_iterator it (dw); it != elfutils::unit_iterator::end (); ++it)
+ cudies.push_back (std::make_pair (it, it->cudie));
+
+ for (size_t i = 0; i < cudies.size (); ++i)
+ {
+ elfutils::unit_iterator jt (dw, cudies[i].second);
+ std::cerr << std::hex << std::showbase
+ << dwarf_dieoffset (&jt->cudie) << std::endl;
+ for (size_t j = i; jt != elfutils::unit_iterator::end (); ++jt, ++j)
+ assert (jt == cudies[j].first);
+ }
+
+ assert (elfutils::die_tree_iterator (elfutils::unit_iterator::end ())
+ == elfutils::die_tree_iterator::end ());
+
+ for (elfutils::die_tree_iterator it (dw);
+ it != elfutils::die_tree_iterator::end (); ++it)
+ std::cerr << std::dec
+ << std::distance (elfutils::child_iterator (*it),
+ elfutils::child_iterator::end ()) << ' '
+ << std::distance (elfutils::attr_iterator (&*it),
+ elfutils::attr_iterator::end ())
+ << std::endl;
+ }
+
+ dwfl_end (dwfl);
+}