diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ChangeLog | 9 | ||||
| -rw-r--r-- | tests/Makefile.am | 5 | ||||
| -rw-r--r-- | tests/dwfl-bug-fd-leak.c | 110 | ||||
| -rw-r--r-- | tests/dwflmodtest.c | 34 |
4 files changed, 155 insertions, 3 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index 5b188f84..770f3375 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,12 @@ +2007-03-04 Roland McGrath <[email protected]> + + * dwfl-bug-fd-leak.c: New file. + * Makefile.am (noinst_PROGRAMS, TESTS): Add it. + (dwfl_bug_fd_leak_LDADD): New variable. + + * dwflmodtest.c: Test dwfl_getmodules before and after getdwarf, + show what files have been located. + 2007-02-02 Roland McGrath <[email protected]> * run-addrname-test.sh: New file. diff --git a/tests/Makefile.am b/tests/Makefile.am index bff5568b..c72ea3ce 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -58,7 +58,7 @@ noinst_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ get-aranges allfcts line2addr addrscopes funcscopes \ show-abbrev hash newscn ecp dwflmodtest \ find-prologues funcretval allregs rdwrmmap \ - dwfl-bug-addr-overflow arls + dwfl-bug-addr-overflow arls dwfl-bug-fd-leak # get-ciefde asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ asm-tst6 asm-tst7 asm-tst8 asm-tst9 @@ -76,7 +76,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-addrscopes.sh run-strings-test.sh run-funcscopes.sh \ run-find-prologues.sh run-allregs.sh run-readelf-test1.sh \ run-native-test.sh run-bug1-test.sh \ - dwfl-bug-addr-overflow run-addrname-test.sh + dwfl-bug-addr-overflow run-addrname-test.sh dwfl-bug-fd-leak # run-show-ciefde.sh if !STANDALONE @@ -203,6 +203,7 @@ dwflmodtest_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl rdwrmmap_LDADD = $(libelf) dwfl_bug_addr_overflow_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl arls_LDADD = $(libelf) $(libmudflap) +dwfl_bug_fd_leak_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl CLEANFILES = xxx *.gcno *.gcda *gconv diff --git a/tests/dwfl-bug-fd-leak.c b/tests/dwfl-bug-fd-leak.c new file mode 100644 index 00000000..c75a79b6 --- /dev/null +++ b/tests/dwfl-bug-fd-leak.c @@ -0,0 +1,110 @@ +/* Test program for libdwfl file decriptors leakage. + Copyright (C) 2007 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 <config.h> +#include <assert.h> +#include <inttypes.h> +#include <stdio.h> +#include <stdio_ext.h> +#include <locale.h> +#include <dirent.h> +#include <stdlib.h> +#include <errno.h> +#include <error.h> +#include <unistd.h> +#include <dwarf.h> +#include <sys/resource.h> +#include ELFUTILS_HEADER(dwfl) + + +static Dwfl * +elfutils_open (pid_t pid, Dwarf_Addr address) +{ + 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, + }; + Dwfl *dwfl = dwfl_begin (&proc_callbacks); + 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)); + + Dwarf_Addr bias; + Dwarf *dbg = dwfl_addrdwarf (dwfl, address, &bias); + if (dbg != NULL) + { + Elf *elf = dwarf_getelf (dbg); + if (elf == NULL) + error (2, 0, "dwarf_getelf: %s", dwarf_errmsg (-1)); + } + else + { + Elf *elf = dwfl_module_getelf (dwfl_addrmodule (dwfl, address), &bias); + if (elf == NULL) + error (2, 0, "dwfl_module_getelf: %s", dwfl_errmsg (-1)); + } + + return dwfl; +} + +static void +elfutils_close (Dwfl *dwfl) +{ + dwfl_end (dwfl); +} + +int +main (void) +{ + /* We use no threads here which can interfere with handling a stream. */ + (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER); + + /* Set locale. */ + (void) setlocale (LC_ALL, ""); + + struct rlimit fd_limit = { .rlim_cur = 32, .rlim_max = 32 }; + if (setrlimit (RLIMIT_NOFILE, &fd_limit) < 0) + error (2, errno, "setrlimit"); + + for (int i = 0; i < 5000; ++i) + { + Dwfl *dwfl = elfutils_open (getpid (), (Dwarf_Addr) main); + elfutils_close (dwfl); + } + + return 0; +} diff --git a/tests/dwflmodtest.c b/tests/dwflmodtest.c index 7e454e47..c34cac42 100644 --- a/tests/dwflmodtest.c +++ b/tests/dwflmodtest.c @@ -1,5 +1,5 @@ /* Test program for libdwfl basic module tracking, relocation. - Copyright (C) 2005 Red Hat, Inc. + Copyright (C) 2005, 2007 Red Hat, Inc. This file is part of Red Hat elfutils. Red Hat elfutils is free software; you can redistribute it and/or modify @@ -163,6 +163,25 @@ print_func (Dwarf_Die *func, void *arg) } static int +list_module (Dwfl_Module *mod __attribute__ ((unused)), + void **userdata __attribute__ ((unused)), + const char *name, Dwarf_Addr base, + void *arg __attribute__ ((unused))) +{ + Dwarf_Addr start; + Dwarf_Addr end; + const char *file; + const char *debug; + if (dwfl_module_info (mod, NULL, &start, &end, + NULL, NULL, &file, &debug) != name + || start != base) + abort (); + printf ("module: %30s %08" PRIx64 "..%08" PRIx64 " %s %s\n", + name, start, end, file, debug); + return DWARF_CB_OK; +} + +static int print_module (Dwfl_Module *mod __attribute__ ((unused)), void **userdata __attribute__ ((unused)), const char *name, Dwarf_Addr base, @@ -252,11 +271,24 @@ main (int argc, char **argv) ptrdiff_t p = 0; do + p = dwfl_getmodules (dwfl, &list_module, NULL, p); + while (p > 0); + if (p < 0) + error (2, 0, "dwfl_getmodules: %s", dwfl_errmsg (-1)); + + do p = dwfl_getdwarf (dwfl, &print_module, &show_functions, p); while (p > 0); if (p < 0) error (2, 0, "dwfl_getdwarf: %s", dwfl_errmsg (-1)); + p = 0; + do + p = dwfl_getmodules (dwfl, &list_module, NULL, p); + while (p > 0); + if (p < 0) + error (2, 0, "dwfl_getmodules: %s", dwfl_errmsg (-1)); + dwfl_end (dwfl); return 0; |
