diff options
| author | Mark Wielaard <[email protected]> | 2018-05-19 00:46:02 +0200 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2018-05-23 00:31:22 +0200 |
| commit | 144b73c49acf3ed894e4635aedb9b0d1208ade2e (patch) | |
| tree | 53ce2f235c75324b4010c419b5d5fe1a524c09ba /tests | |
| parent | a4c74cc67de22cb3208fc768989c509d6837cd77 (diff) | |
libdw: Handle GNU DebugFission split ranges.
GNU DebugFission split dwarf handles DW_FORM_sec_offset specially for
attributes that point to ranges. The .debug_ranges section is not in
the .dwo file, but in the main/skeleton object file. The sec_offset is
not relocated (in the ELF file), but is an offset against the skeleton
DIE DW_AT_GNU_ranges_base attribute. dwarf_formudata is changed so it
still looks like a normal offset ptr into the .debug_ranges section.
dwarf_ranges is adapted to look for the .debug_ranges in the main object
file. dwarf_highpc and dwarf_lowpc now handle the highpc and lowpc
attributes being inherited for the split unit DIE from the skeleton.
A new testcase is added to iterate over all ranges in a split GNU
DebugFission file.
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ChangeLog | 14 | ||||
| -rw-r--r-- | tests/Makefile.am | 11 | ||||
| -rw-r--r-- | tests/all-dwarf-ranges.c | 90 | ||||
| -rwxr-xr-x | tests/run-all-dwarf-ranges.sh | 49 | ||||
| -rw-r--r-- | tests/testfile-ranges-hello.dwo.bz2 | bin | 0 -> 948 bytes | |||
| -rw-r--r-- | tests/testfile-ranges-world.dwo.bz2 | bin | 0 -> 1176 bytes | |||
| -rwxr-xr-x | tests/testfilesplitranges4.debug.bz2 | bin | 0 -> 2154 bytes |
7 files changed, 161 insertions, 3 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index 0370fbc6..a021a019 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,5 +1,19 @@ 2018-05-18 Mark Wielaard <[email protected]> + * tests/Makefiles.am (check_PROGRAMS): Add all-dwarf-ranges. + (TESTS): Add run-all-dwarf-ranges.sh. + (EXTRA_DIST): Add run-all-dwarf-ranges.sh, + testfilesplitranges4.debug.bz2, testfile-ranges-hello.dwo.bz2 + and testfile-ranges-world.dwo.bz2. + (all_dwarf_ranges_LDADD): New variable. + * all-dwarf-ranges.c: New test program. + * run-all-dwarf-ranges: New test runner. + * testfile-ranges-hello.dwo.bz2: New test file. + * testfile-ranges-world.dwo.bz2: Likewise. + * testfilesplitranges4.debug.bz2: Likewise. + +2018-05-18 Mark Wielaard <[email protected]> + * run-get-files.sh: Add testcases for testfile-splitdwarf-4, testfile-hello4.dwo, testfile-world4.dwo and testfile-splitdwarf-5, testfile-hello5.dwo, testfile-world5.dwo. diff --git a/tests/Makefile.am b/tests/Makefile.am index 05a5441b..08d84649 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -56,7 +56,8 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ elfshphehdr elfstrmerge dwelfgnucompressed elfgetchdr \ elfgetzdata elfputzdata zstrptr emptyfile vendorelf \ fillfile dwarf_default_lower_bound dwarf-die-addr-die \ - get-units-invalid get-units-split attr-integrate-skel + get-units-invalid get-units-split attr-integrate-skel \ + all-dwarf-ranges asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ asm-tst6 asm-tst7 asm-tst8 asm-tst9 @@ -141,7 +142,8 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ emptyfile vendorelf fillfile dwarf_default_lower_bound \ run-dwarf-die-addr-die.sh \ run-get-units-invalid.sh run-get-units-split.sh \ - run-attr-integrate-skel.sh + run-attr-integrate-skel.sh \ + run-all-dwarf-ranges.sh if !BIARCH export ELFUTILS_DISABLE_BIARCH = 1 @@ -366,7 +368,9 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ testfile-hello4.dwo.bz2 testfile-hello5.dwo.bz2 \ testfile-splitdwarf-4.bz2 testfile-splitdwarf-5.bz2 \ testfile-world5.dwo.bz2 testfile-world4.dwo.bz2 \ - run-attr-integrate-skel.sh + run-attr-integrate-skel.sh \ + run-all-dwarf-ranges.sh testfilesplitranges4.debug.bz2 \ + testfile-ranges-hello.dwo.bz2 testfile-ranges-world.dwo.bz2 if USE_VALGRIND valgrind_cmd='valgrind -q --leak-check=full --error-exitcode=1' @@ -528,6 +532,7 @@ dwarf_die_addr_die_LDADD = $(libdw) get_units_invalid_LDADD = $(libdw) get_units_split_LDADD = $(libdw) attr_integrate_skel_LDADD = $(libdw) +all_dwarf_ranges_LDADD = $(libdw) # We want to test the libelf header against the system elf.h header. # Don't include any -I CPPFLAGS. diff --git a/tests/all-dwarf-ranges.c b/tests/all-dwarf-ranges.c new file mode 100644 index 00000000..4331a05b --- /dev/null +++ b/tests/all-dwarf-ranges.c @@ -0,0 +1,90 @@ +/* Test program for dwarf_ranges + Copyright (C) 2015, 2018 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 <config.h> +#include ELFUTILS_HEADER(dw) +#include <dwarf.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <assert.h> +#include <inttypes.h> + +static void +ranges_die (Dwarf_Die *die) +{ + Dwarf_Addr base, start, end; + int ranges = dwarf_ranges (die, 0, &base, &start, &end); + if (ranges < 0) + puts (dwarf_errmsg (-1)); + else if (ranges > 0) + { + printf ("die: %s (%x)\n", dwarf_diename (die) ?: "<unknown>", + dwarf_tag (die)); + for (ptrdiff_t off = 0; + (off = dwarf_ranges (die, off, &base, &start, &end)); ) + if (off == -1) + { + puts (dwarf_errmsg (-1)); + break; + } + else + printf (" %"PRIx64"..%"PRIx64"\n", start, end); + printf ("\n"); + } +} + +static void +walk_tree (Dwarf_Die *dwarf_die) +{ + Dwarf_Die die = *dwarf_die; + do + { + Dwarf_Die child; + ranges_die (&die); + if (dwarf_child (&die, &child) == 0) + walk_tree (&child); + } + while (dwarf_siblingof (&die, &die) == 0); +} + +int +main (int argc, char *argv[]) +{ + assert (argc >= 2); + const char *name = argv[1]; + + int fd = open (name, O_RDONLY); + Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ); + + Dwarf_CU *cu = NULL; + Dwarf_Die cudie, subdie; + uint8_t unit_type; + while (dwarf_get_units (dbg, cu, &cu, NULL, + &unit_type, &cudie, &subdie) == 0) + { + Dwarf_Die die = (unit_type == DW_UT_skeleton + ? subdie : cudie); + walk_tree (&die); + } + dwarf_end (dbg); + + return 0; +} diff --git a/tests/run-all-dwarf-ranges.sh b/tests/run-all-dwarf-ranges.sh new file mode 100755 index 00000000..0bd641b0 --- /dev/null +++ b/tests/run-all-dwarf-ranges.sh @@ -0,0 +1,49 @@ +#! /bin/sh +# Copyright (C) 2018 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 + +# See run-dwarf-ranges.sh +# Compiled with: +# gcc -c -O2 -o testfile-ranges-hello.o -gsplit-dwarf -gdwarf-4 hello.c +# gcc -c -O2 -o testfile-ranges-world.o -gsplit-dwarf -gdwarf-4 world.c +# gcc -o testfilesplitranges4 -O2 \ +# testfile-ranges-hello.o testfile-ranges-world.o +# eu-strip -f testfilesplitranges4.debug testfilesplitranges4 + +testfiles testfilesplitranges4.debug +testfiles testfile-ranges-hello.dwo testfile-ranges-world.dwo + +testrun_compare ${abs_builddir}/all-dwarf-ranges testfilesplitranges4.debug <<\EOF +die: hello.c (11) + 4004e0..4004ff + 4003e0..4003f7 + +die: world.c (11) + 400500..400567 + +die: happy (1d) + 8009e0..8009ff + 8008e0..8008f7 + +die: sad (1d) + 400530..400534 + 400535..40053f + +EOF + +exit 0 diff --git a/tests/testfile-ranges-hello.dwo.bz2 b/tests/testfile-ranges-hello.dwo.bz2 Binary files differnew file mode 100644 index 00000000..fac24672 --- /dev/null +++ b/tests/testfile-ranges-hello.dwo.bz2 diff --git a/tests/testfile-ranges-world.dwo.bz2 b/tests/testfile-ranges-world.dwo.bz2 Binary files differnew file mode 100644 index 00000000..27ad06d5 --- /dev/null +++ b/tests/testfile-ranges-world.dwo.bz2 diff --git a/tests/testfilesplitranges4.debug.bz2 b/tests/testfilesplitranges4.debug.bz2 Binary files differnew file mode 100755 index 00000000..df8e3ac4 --- /dev/null +++ b/tests/testfilesplitranges4.debug.bz2 |
