diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ChangeLog | 14 | ||||
| -rw-r--r-- | tests/Makefile.am | 4 | ||||
| -rw-r--r-- | tests/line2addr.c | 143 | ||||
| -rwxr-xr-x | tests/run-line2addr.sh | 32 | ||||
| -rw-r--r-- | tests/testfile23.bz2 | bin | 0 -> 956 bytes |
5 files changed, 139 insertions, 54 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index b5b6e18f..17bef797 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2005-08-22 Roland McGrath <[email protected]> + + * run-line2addr.sh: Add a case. + * testfile23.bz2: New data file. + * Makefile.am (EXTRA_DIST): Add it. + 2005-08-18 Roland McGrath <[email protected]> * run-addrscopes.sh: New file. @@ -51,6 +57,14 @@ * Makefile.am (dwflmodtest_LDADD): Add $(libebl). +2005-06-01 Roland McGrath <[email protected]> + + * line2addr.c: Rewritten using libdwfl. + * run-line2addr.sh: Update test for changed arguments. + * Makefile.am (INCLUDES): Add libdwfl source directory to path. + (libdwfl): New variable. + (line2addr_LDADD): Use it. + 2005-07-28 Roland McGrath <[email protected]> * dwflmodtest.c: New file, moved from ../libdwfl/ptest.c to here. diff --git a/tests/Makefile.am b/tests/Makefile.am index a8ae760b..99c769ca 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -69,7 +69,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ testfile18.bz2 testfile19.bz2 testfile19.index.bz2 \ testfile20.bz2 testfile20.index.bz2 \ testfile21.bz2 testfile21.index.bz2 \ - testfile22.bz2 + testfile22.bz2 testfile23.bz2 if MUDFLAP static_build=yes @@ -111,7 +111,7 @@ get_files_LDADD = $(libdw) $(libelf) $(libmudflap) get_aranges_LDADD = $(libdw) $(libelf) $(libmudflap) allfcts_LDADD = $(libdw) $(libelf) $(libmudflap) line2addr_no_Wformat = yes -line2addr_LDADD = $(libdw) $(libelf) $(libmudflap) +line2addr_LDADD = $(libdw) $(libmudflap) addrscopes_LDADD = $(libdw) $(libmudflap) #show_ciefde_LDADD = ../libdwarf/libdwarf.so $(libelf) $(libmudflap) asm_tst1_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl diff --git a/tests/line2addr.c b/tests/line2addr.c index d2017fba..73c57f49 100644 --- a/tests/line2addr.c +++ b/tests/line2addr.c @@ -1,64 +1,125 @@ -#include <fcntl.h> #include <inttypes.h> -#include <libdw.h> +#include <assert.h> +#include <libdwfl.h> +#include <argp.h> #include <stdio.h> +#include <locale.h> #include <stdlib.h> -#include <unistd.h> +#include <string.h> +#include <error.h> +static void +print_address (Dwfl_Module *mod, Dwarf_Addr address) +{ + int n = dwfl_module_relocations (mod); + if (n < 0) + error (0, 0, "dwfl_module_relocations: %s", dwfl_errmsg (-1)); + else if (n > 0) + { + int i = dwfl_module_relocate_address (mod, &address); + if (i < 0) + error (0, 0, "dwfl_module_relocate_address: %s", dwfl_errmsg (-1)); + else + { + const char *modname = dwfl_module_info (mod, NULL, NULL, NULL, + NULL, NULL, NULL, NULL); + const char *secname = dwfl_module_relocation_info (mod, i, NULL); + if (n > 1 || secname[0] != '\0') + printf ("%s(%s)+%#" PRIx64, modname, secname, address); + else + printf ("%s(%s)+%#" PRIx64, modname, secname, address); + return; + } + } + + printf ("%#" PRIx64, address); +} + + +struct args +{ + const char *arg; + char *file; + int line; +}; + +static int +handle_module (Dwfl_Module *mod __attribute__ ((unused)), + void **udata __attribute__ ((unused)), + const char *modname, Dwarf_Addr base __attribute__ ((unused)), + Dwarf *dbg __attribute__ ((unused)), + Dwarf_Addr bias __attribute__ ((unused)), void *arg) +{ + const struct args *const a = arg; + + Dwfl_Line **lines = NULL; + size_t nlines = 0; + + if (dwfl_module_getsrc_file (mod, a->file, a->line, 0, &lines, &nlines) == 0) + { + for (size_t inner = 0; inner < nlines; ++inner) + { + Dwarf_Addr addr; + int line = a->line, col = 0; + const char *file = dwfl_lineinfo (lines[inner], &addr, &line, &col, + NULL, NULL); + if (file != NULL) + { + printf ("%s -> ", a->arg); + print_address (mod, addr); + if (modname[0] != '\0') + printf (" (%s:", modname); + if (strcmp (file, a->file) || line != a->line || col != 0) + printf (" %s%s:%d", modname[0] != '\0' ? "" : "(", + file, line); + if (col != 0) + printf (":%d"); + if (modname[0] != '\0' + || strcmp (file, a->file) || line != a->line || col != 0) + puts (")"); + else + puts (""); + } + } + free (lines); + } + + return DWARF_CB_OK; +} + int main (int argc, char *argv[]) { - for (int cnt = 1; cnt < argc; ++cnt) + int cnt; + + /* Set locale. */ + (void) setlocale (LC_ALL, ""); + + Dwfl *dwfl = NULL; + (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &cnt, &dwfl); + assert (dwfl != NULL); + + for (; cnt < argc; ++cnt) { - char *fname; - char *file; - int line; + struct args a = { .arg = argv[cnt] }; - switch (sscanf (argv[cnt], "%a[^:]:%a[^:]:%d", - &fname, &file, &line)) + switch (sscanf (a.arg, "%a[^:]:%d", &a.file, &a.line)) { default: case 0: - case 1: printf ("ignored %s\n", argv[cnt]); continue; - case 2: - line = 0; + case 1: + a.line = 0; break; - case 3: + case 2: break; } - int fd = open (fname, O_RDONLY); - if (fd == -1) - continue; - - Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ); - if (dbg != NULL) - { - Dwarf_Line **lines = NULL; - size_t nlines = 0; - - if (dwarf_getsrc_file (dbg, file, line, 0, &lines, &nlines) == 0) - { - for (size_t inner = 0; inner < nlines; ++inner) - { - Dwarf_Addr addr; - if (dwarf_lineaddr (lines[inner], &addr) == 0) - printf ("%s -> %#" PRIxMAX "\n", - argv[cnt], (uintmax_t) addr); - } - - free (lines); - } - - dwarf_end (dbg); - } + (void) dwfl_getdwarf (dwfl, &handle_module, &a, 0); - close (fd); - free (fname); - free (file); + free (a.file); } return 0; diff --git a/tests/run-line2addr.sh b/tests/run-line2addr.sh index c46c8fda..e1459cd1 100755 --- a/tests/run-line2addr.sh +++ b/tests/run-line2addr.sh @@ -25,20 +25,30 @@ bunzip2 -c $srcdir/testfile8.bz2 > testfile8 2>/dev/null || exit 0 # Don't fail if we cannot decompress the file. bunzip2 -c $srcdir/testfile14.bz2 > testfile14 2>/dev/null || exit 0 -./line2addr testfile:f.c:4 testfile:f.c:8 testfile2:m.c:6 testfile2:b.c:1 testfile8:strip.c:953 testfile8:strip.c:365 testfile14:v.c:6 > line2addr.out +# Don't fail if we cannot decompress the file. +bunzip2 -c $srcdir/testfile23.bz2 > testfile23 2>/dev/null || exit 0 + +(./line2addr -e testfile f.c:4 testfile f.c:8 + ./line2addr -e testfile2 m.c:6 b.c:1 + ./line2addr -e testfile8 strip.c:953 strip.c:365 + ./line2addr -e testfile14 v.c:6 + ./line2addr -e testfile23 foo.c:2 foo.c:6 +) > line2addr.out diff -u line2addr.out - <<"EOF" -testfile:f.c:4 -> 0x804846b -testfile2:m.c:6 -> 0x100004cc -testfile2:b.c:1 -> 0x10000470 -testfile8:strip.c:953 -> 0x169f -testfile8:strip.c:953 -> 0x16aa -testfile8:strip.c:365 -> 0x278b -testfile8:strip.c:365 -> 0x2797 -testfile14:v.c:6 -> 0x400468 -testfile14:v.c:6 -> 0x400487 +f.c:4 -> 0x804846b (/home/drepper/gnu/new-bu/build/ttt/f.c:4) +m.c:6 -> 0x100004cc (/shoggoth/drepper/m.c:6) +b.c:1 -> 0x10000470 (/shoggoth/drepper/b.c:4) +strip.c:953 -> (.text)+0x169f (/home/drepper/gnu/elfutils/build/src/../../src/strip.c:953) +strip.c:953 -> (.text)+0x16aa (/home/drepper/gnu/elfutils/build/src/../../src/strip.c:953) +strip.c:365 -> (.text)+0x278b (/home/drepper/gnu/elfutils/build/src/../../src/strip.c:365) +strip.c:365 -> (.text)+0x2797 (/home/drepper/gnu/elfutils/build/src/../../src/strip.c:365) +v.c:6 -> 0x400468 (/home/drepper/local/elfutils-build/20050425/v.c:6) +v.c:6 -> 0x400487 (/home/drepper/local/elfutils-build/20050425/v.c:6) +foo.c:2 -> (.init.text)+0xc (/home/roland/stock-elfutils-build/foo.c:2) +foo.c:6 -> (.text)+0xc (/home/roland/stock-elfutils-build/foo.c:6) EOF -rm -f testfile testfile2 testfile8 testfile14 line2addr.out +rm -f testfile testfile2 testfile8 testfile14 testfile22 line2addr.out exit 0 diff --git a/tests/testfile23.bz2 b/tests/testfile23.bz2 Binary files differnew file mode 100644 index 00000000..cf0ce559 --- /dev/null +++ b/tests/testfile23.bz2 |
