diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ChangeLog | 27 | ||||
-rw-r--r-- | tests/Makefile.am | 9 | ||||
-rw-r--r-- | tests/debuginfo.c | 114 | ||||
-rw-r--r-- | tests/relocate.c | 109 | ||||
-rwxr-xr-x | tests/run-debuginfo.sh | 34 | ||||
-rwxr-xr-x | tests/run-relocate.sh | 34 | ||||
-rw-r--r-- | tests/sharing1.c | 178 |
7 files changed, 503 insertions, 2 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index b1471c1b..5d82e594 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -29,6 +29,13 @@ * testfile47.bz2: New data file. * Makefile.am (TESTS, EXTRA_DIST): Add them. +2008-04-29 Petr Machata <pmachata@redhat.com> + + * run-debuginfo.sh: New file. + * debuginfo.c: New file. + * Makefile.am (noinst_PROGRAMS, TESTS, EXTRA_DIST): Add them. + (debuginfo_LDADD): New variable. + 2008-03-31 Roland McGrath <roland@redhat.com> * run-early-offscn.sh: New file. @@ -40,6 +47,20 @@ * run-addrname-test.sh: Add a new case. +2008-03-13 Petr Machata <pmachata@redhat.com> + + * run-relocate.sh: New test. + * relocate.c: New file. + +2008-03-13 Petr Machata <pmachata@redhat.com> + + * sharing1.c: Test feeding bogus file to libdwfl. + * run-sharing1.sh: Adjust to above. + +2008-03-05 Petr Machata <pmachata@redhat.com> + + * sharing1.c: Adjust for changes in libdwfl. + 2008-02-22 Roland McGrath <roland@redhat.com> * run-elflint-test.sh: Typo fix. @@ -163,6 +184,12 @@ * run-allregs.sh: Change expected output for powerpc spefscr. +2007-12-10 Petr Machata <pmachata@redhat.com> + + * run-sharing1.sh: New file. + * sharing1.c: New file. + * Makefile.am (noinst_PROGRAMS, EXTRA_DIST, TESTS): Add it. + 2007-10-20 Roland McGrath <roland@redhat.com> * run-dwfl-addr-sect.sh: Change expected output, no errors. diff --git a/tests/Makefile.am b/tests/Makefile.am index b533521c..c9d2bc47 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -60,7 +60,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 + dwfl-bug-getmodules \ + sharing1 relocate debuginfo # get-ciefde asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ asm-tst6 asm-tst7 asm-tst8 asm-tst9 @@ -86,6 +87,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ dwfl-bug-fd-leak dwfl-bug-report \ run-dwfl-bug-offline-rel.sh run-dwfl-addr-sect.sh \ run-disasm-x86.sh run-disasm-x86-64.sh \ + sharing1 run-relocate.sh run-debuginfo.sh \ run-early-offscn.sh # run-show-ciefde.sh @@ -141,7 +143,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ testfile44.S.bz2 testfile44.expect.bz2 run-disasm-x86.sh \ testfile45.S.bz2 testfile45.expect.bz2 run-disasm-x86-64.sh \ testfile46.bz2 testfile47.bz2 testfile48.bz2 testfile48.debug.bz2 \ - testfile49.bz2 + testfile49.bz2 run-relocate.sh installed_TESTS_ENVIRONMENT = libdir=$(DESTDIR)$(libdir) \ bindir=$(DESTDIR)$(bindir) \ @@ -233,6 +235,9 @@ dwfl_bug_report_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl dwfl_bug_getmodules_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl dwfl_addr_sect_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl sha1_tst_LDADD = $(libeu) $(libmudflap) +sharing1_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl +relocate_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl +debuginfo_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl CLEANFILES = xxx *.gcno *.gcda *gconv diff --git a/tests/debuginfo.c b/tests/debuginfo.c new file mode 100644 index 00000000..cf621ac7 --- /dev/null +++ b/tests/debuginfo.c @@ -0,0 +1,114 @@ +/* Copyright (C) 2008 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 ELFUTILS_HEADER(dwfl) + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +static char *filename = NULL; +static char *dfilename = NULL; +bool was_there = false; + +static char *debuginfo_path = NULL; + +static void +die (const char *message) +{ + fprintf (stderr, "%s\n", message); + exit (1); +} + +int +my_find_debuginfo (Dwfl_Module *mod, + void **userdata, + const char *modname, + GElf_Addr base, + const char *file_name, + const char *debuglink_file, + GElf_Word debuglink_crc, + char **debuginfo_file_name) +{ + int ret = dwfl_standard_find_debuginfo (mod, userdata, modname, base, + file_name, debuglink_file, + debuglink_crc, debuginfo_file_name); + + if (*debuginfo_file_name == NULL + || strcmp (*debuginfo_file_name, dfilename)) + die ("Unexpected debuginfo found."); + + was_there = true; + return ret; +} + +static const Dwfl_Callbacks my_callbacks = +{ + .find_debuginfo = my_find_debuginfo, + .debuginfo_path = &debuginfo_path, +}; + +int +main(int argc, char ** argv) +{ + if (argc != 3) + die ("Usage: debuginfo <binary> <matching debuginfo>\n"); + filename = argv[1]; + dfilename = argv[2]; + + Dwfl *dwfl = dwfl_begin (&my_callbacks); + if (dwfl == NULL) + die ("Couldn't create dwfl."); + dwfl_report_begin (dwfl); + Dwfl_Module *mod1 = dwfl_report_elf (dwfl, "mod1", filename, -1, 0); + if (mod1 == NULL) + die ("Couldn't create a module."); + dwfl_report_end (dwfl, NULL, NULL); + + const unsigned char *bits; + GElf_Addr vaddr; + GElf_Addr bias; + dwfl_module_getelf (mod1, &bias); + int bytes = dwfl_module_build_id (mod1, &bits, &vaddr); + if (bytes != 20) + die ("Expected 20 bytes of debuginfo."); + + Dwarf_Die *d = dwfl_module_nextcu (mod1, NULL, &bias); + if (!was_there) + die ("Suspicious: find_debuginfo hook not called."); + if (d == NULL) + die ("No dwarf die found in debuginfo."); + + dwfl_end (dwfl); + + return 0; +} diff --git a/tests/relocate.c b/tests/relocate.c new file mode 100644 index 00000000..2669a7c1 --- /dev/null +++ b/tests/relocate.c @@ -0,0 +1,109 @@ +/* Copyright (C) 2007,2008 Red Hat, Inc. + This file is part of Red Hat elfutils. + Written by Petr Machata <pmachata@redhat.com>, 2007. + + 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 ELFUTILS_HEADER(dwfl) +#include <unistd.h> +#include <error.h> +#include <stdio.h> +#include <stdio_ext.h> +#include <stdlib.h> + +static int my_find_elf (Dwfl_Module *, void **, const char *, Dwarf_Addr, + char **, Elf **); + +static const Dwfl_Callbacks my_callbacks = +{ + .find_elf = my_find_elf, +}; + +static int +my_find_elf (Dwfl_Module * mod __attribute__ ((unused)), + void ** userdata __attribute__ ((unused)), + const char * module_name __attribute__ ((unused)), + Dwarf_Addr addr __attribute__ ((unused)), + char ** file_name __attribute__ ((unused)), + Elf ** elf __attribute__ ((unused))) +{ + return 0; +} + +int +main(int argc, char ** argv) +{ + /* We use no threads here which can interfere with handling a stream. */ + (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER); + + /* Order is significant. If in doubt, check that libdwfl's + * resolve_symbol still gets hit: + * $ ftrace -sym=resolve_symbol ./relocate ~/testfile9 + * should give you roughly: + * 14395.14395 attached /home/ant/elfutils-mtn/build/tests/relocate + * 14395.14395 call libdw.so.1->resolve_symbol(0x96e6758, 0x96e6800, 0xbfa4b474, 0x0, 0xbfa4b470, 0xbfa4b4ac) = 12 + * 14395.14395 call libdw.so.1->resolve_symbol(0x96e6758, 0x96e6800, 0xbfa4b474, 0x0, 0xbfa4b470, 0xbfa4b4ac) = 12 + * 14395.14395 call libdw.so.1->resolve_symbol(0x96e6758, 0x96e6800, 0xbfa4b474, 0x0, 0xbfa4b470, 0xbfa4b4ac) = 12 + * 14395.14395 exited with status 0 + * + * Granted this test is very fragile, and depends a lot on knowledge + * of libdwfl internals. + */ + if (argc < 2) + exit(77); + char const *name = argv[1]; + char const *name2 = argv[0]; + + Dwfl *dwfl = dwfl_begin (&my_callbacks); + dwfl_report_begin (dwfl); + Dwfl_Module *module = dwfl_report_offline (dwfl, name, name, -1); + if (module == NULL) + { + fprintf (stderr, "DWFL error 1: %s\n", dwfl_errmsg (dwfl_errno ())); + exit (1); + } + Dwfl_Module *module2 = dwfl_report_offline (dwfl, name2, name2, -1); + if (module2 == NULL) + { + fprintf (stderr, "DWFL error 2: %s\n", dwfl_errmsg (dwfl_errno ())); + exit (1); + } + if (dwfl_report_end (dwfl, NULL, NULL) != 0) + { + fprintf (stderr, "DWFL error 3: %s\n", dwfl_errmsg (dwfl_errno ())); + exit (1); + } + Dwarf_Addr base; + Elf * elf = dwfl_module_getelf (module, &base); + if (elf == NULL) + { + fprintf (stderr, "DWFL error 4: %s\n", dwfl_errmsg (dwfl_errno ())); + exit (1); + } + + dwfl_end (dwfl); + exit(0); +} diff --git a/tests/run-debuginfo.sh b/tests/run-debuginfo.sh new file mode 100755 index 00000000..7a207911 --- /dev/null +++ b/tests/run-debuginfo.sh @@ -0,0 +1,34 @@ +#! /bin/sh +# Copyright (C) 2008 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 + +files="testfile40 testfile40.debug" +testfiles $files + +export LC_ALL=C +testrun ./debuginfo $files + +exit 0 diff --git a/tests/run-relocate.sh b/tests/run-relocate.sh new file mode 100755 index 00000000..0929ed17 --- /dev/null +++ b/tests/run-relocate.sh @@ -0,0 +1,34 @@ +#! /bin/sh +# Copyright (C) 2008 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 + +files=testfile9 +testfiles $files + +export LC_ALL=C +testrun ./relocate $files + +exit 0 diff --git a/tests/sharing1.c b/tests/sharing1.c new file mode 100644 index 00000000..7b03ce9b --- /dev/null +++ b/tests/sharing1.c @@ -0,0 +1,178 @@ +/* Copyright (C) 2007 Red Hat, Inc. + This file is part of Red Hat elfutils. + Written by Petr Machata <pmachata@redhat.com>, 2007. + + 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 ELFUTILS_HEADER(dwflP) +#include <unistd.h> +#include <error.h> +#include <stdio.h> +#include <stdio_ext.h> +#include <string.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +static int bogus_find_elf (Dwfl_Module *, void **, + const char *, Dwarf_Addr, + char **, Elf **); + +static char *debuginfo_path; +static const Dwfl_Callbacks proc_callbacks = +{ + .find_debuginfo = dwfl_standard_find_debuginfo, + .debuginfo_path = &debuginfo_path, + + .find_elf = dwfl_linux_proc_find_elf, +}; + +static const Dwfl_Callbacks bogus_callbacks = +{ + .find_debuginfo = dwfl_standard_find_debuginfo, + .debuginfo_path = &debuginfo_path, + + .find_elf = bogus_find_elf, +}; + +struct testdata +{ + Dwfl_Module *module; + char *name; + Elf *elf; +}; + + +static int +bogus_find_elf (Dwfl_Module *mod __attribute__ ((unused)), + void **userdata __attribute__ ((unused)), + const char *modname __attribute__ ((unused)), + Dwarf_Addr base __attribute__ ((unused)), + char ** file_name __attribute__ ((unused)), + Elf ** elf __attribute__ ((unused))) +{ + char * fn = strdup ("."); + *file_name = fn; + int fd = open(fn, O_RDONLY); + return fd; +} + +int +each_module (Dwfl_Module *module, + void **userdata __attribute__ ((unused)), + const char *name, + Dwarf_Addr base __attribute__ ((unused)), + void *arg) +{ + struct testdata *t = (struct testdata *)arg; + + GElf_Addr bias; + Elf *elf = dwfl_module_getelf (module, &bias); + + if (elf == NULL + || dwfl_module_getsymtab (module) <= 0) + return DWARF_CB_OK; /* Continue iteration until first ordinary + mapping with symbol table is found. */ + else + { + t->name = strdup (name); + t->elf = elf; + t->module = module; + return DWARF_CB_ABORT; + } +} + +Dwfl * +initdwfl (pid_t pid, struct testdata *t, Dwfl_Callbacks const *cb, bool check) +{ + Dwfl *dwfl = dwfl_begin (cb); + if (dwfl == NULL) + error (2, 0, "dwfl_begin: %s", dwfl_errmsg (-1)); + + int result = dwfl_linux_proc_report (dwfl, pid); + if (result < 0) + error (2, 0, "dwfl_linux_proc_report: %s", dwfl_errmsg (-1)); + else if (result > 0) + error (2, result, "dwfl_linux_proc_report"); + + if (dwfl_report_end (dwfl, NULL, NULL) != 0) + error (2, 0, "dwfl_report_end: %s", dwfl_errmsg (-1)); + + t->module = NULL; + t->elf = NULL; + t->name = NULL; + dwfl_getmodules (dwfl, each_module, (void*)t, 0); + if (check && (t->elf == NULL || t->name == NULL || t->module == NULL)) + error (2, 0, "couldn't init testdata."); + + return dwfl; +} + +int +proc_test (void) +{ + struct testdata ta; + Dwfl *a = initdwfl (getpid(), &ta, &proc_callbacks, true); + + struct testdata tb; + Dwfl *b = initdwfl (getpid(), &tb, &proc_callbacks, true); + + if (ta.module == tb.module) + error (2, 0, "Strange. Both dwfls contain the same module?"); + + if (strcmp (ta.name, tb.name)) + error (2, 0, "ELF files from different files."); + + if (ta.elf != tb.elf) + error (2, 0, "ELF files not shared."); + + if (ta.module->symfile->shared->symdata != tb.module->symfile->shared->symdata) + error (2, 0, "Symdata not shared."); + + dwfl_end (a); + dwfl_end (b); + return 0; +} + +int +bogus_test (void) +{ + struct testdata ta; + Dwfl *a = initdwfl (getpid(), &ta, &bogus_callbacks, false); + dwfl_end (a); + return 0; +} + +int +main (void) +{ + /* We use no threads here which can interfere with handling a stream. */ + (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER); + + return proc_test () + | bogus_test (); +} |