diff options
| author | Mark Wielaard <[email protected]> | 2018-05-14 23:58:25 +0200 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2018-05-20 10:38:17 +0200 |
| commit | 3d4998a9edd9f88b46662b3584de89ecd8f2f4c8 (patch) | |
| tree | 1e162090152f5af68e78dc5fe42ee4d590aa6a47 /tests | |
| parent | 38ab84547a045386cc056422d37a7a7582c8afb9 (diff) | |
libdw: Search skeleton DIE for split compile unit DIE attributes.
dwarf_attr_integrate and dwarf_hasattr_integrate should also search
for attributes from the skeleton DIE in case the given DIE is a split
compile unit DIE. Split compile unit DIEs inherit various attributes
from their skeleton unit DIE in DWARF5.
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ChangeLog | 9 | ||||
| -rw-r--r-- | tests/Makefile.am | 11 | ||||
| -rw-r--r-- | tests/attr-integrate-skel.c | 109 | ||||
| -rwxr-xr-x | tests/run-attr-integrate-skel.sh | 52 |
4 files changed, 177 insertions, 4 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index b865ad54..05e8f26c 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,12 @@ +2018-05-17 Mark Wielaard <[email protected]> + + * Makefile.am (check_PROGRAMS): Add attr-integrate-skel. + (TESTS): Add run-attr-integrate-skel. + (EXTRA_DIST): Likewise. + (attr_integrate_skel_LDADD): New variable. + * attr-integrate-skel.c: New test. + * run-attr-integrate-skel.sh: New test runner. + 2018-05-16 Mark Wielaard <[email protected]> * Makefile.am (check_PROGRAMS): Add get-units-split. diff --git a/tests/Makefile.am b/tests/Makefile.am index 07165d84..05a5441b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to create Makefile.in ## -## Copyright (C) 1996-2017 Red Hat, Inc. +## Copyright (C) 1996-2018 Red Hat, Inc. ## This file is part of elfutils. ## ## This file is free software; you can redistribute it and/or modify @@ -56,7 +56,7 @@ 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 + get-units-invalid get-units-split attr-integrate-skel asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ asm-tst6 asm-tst7 asm-tst8 asm-tst9 @@ -140,7 +140,8 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-readelf-zdebug.sh run-readelf-zdebug-rel.sh \ emptyfile vendorelf fillfile dwarf_default_lower_bound \ run-dwarf-die-addr-die.sh \ - run-get-units-invalid.sh run-get-units-split.sh + run-get-units-invalid.sh run-get-units-split.sh \ + run-attr-integrate-skel.sh if !BIARCH export ELFUTILS_DISABLE_BIARCH = 1 @@ -364,7 +365,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ run-get-units-invalid.sh run-get-units-split.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 + testfile-world5.dwo.bz2 testfile-world4.dwo.bz2 \ + run-attr-integrate-skel.sh if USE_VALGRIND valgrind_cmd='valgrind -q --leak-check=full --error-exitcode=1' @@ -525,6 +527,7 @@ dwarf_default_lower_bound_LDADD = $(libdw) dwarf_die_addr_die_LDADD = $(libdw) get_units_invalid_LDADD = $(libdw) get_units_split_LDADD = $(libdw) +attr_integrate_skel_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/attr-integrate-skel.c b/tests/attr-integrate-skel.c new file mode 100644 index 00000000..644cd272 --- /dev/null +++ b/tests/attr-integrate-skel.c @@ -0,0 +1,109 @@ +/* Test dwarf_get_units finds split DWO CUs. + 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/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <dwarf.h> +#include ELFUTILS_HEADER(dw) +#include <stdio.h> +#include <inttypes.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + + +int +main (int argc, char *argv[]) +{ + for (int i = 1; i < argc; i++) + { + printf ("file: %s\n", argv[i]); + int fd = open (argv[i], O_RDONLY); + Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ); + if (dbg == NULL) + { + printf ("%s not usable: %s\n", argv[i], dwarf_errmsg (-1)); + return -1; + } + + Dwarf_CU *cu = NULL; + Dwarf_Die cudie, subdie; + uint8_t unit_type; + Dwarf_Half version; + int count = 0; + while (dwarf_get_units (dbg, cu, &cu, &version, + &unit_type, &cudie, &subdie) == 0) + { + count++; + if (unit_type == DW_UT_skeleton) + { + Dwarf_Attribute attr; + Dwarf_Word word; + Dwarf_Addr addr; + + printf ("Split DIE: %s\n", dwarf_diename (&subdie)); + + if (dwarf_attr_integrate (&subdie, + DW_AT_GNU_addr_base, &attr) == NULL + && dwarf_attr_integrate (&subdie, + DW_AT_addr_base, &attr) == NULL) + printf ("No addr_base"); + else if (dwarf_formudata (&attr, &word) != 0) + printf ("Bad addr_base: %s\n", dwarf_errmsg (-1)); + else + printf ("addr_base secoff: 0x%" PRIx64 "\n", word); + + if (dwarf_attr (&subdie, DW_AT_low_pc, &attr) != NULL) + printf ("Unexpected low_pc on split DIE.\n"); + + if (dwarf_attr_integrate (&subdie, + DW_AT_low_pc, &attr) == NULL) + printf ("No low_pc"); + else if (dwarf_formaddr (&attr, &addr) != 0) + printf ("Bad low_pc: %s\n", dwarf_errmsg (-1)); + else + printf ("low_pc addr: 0x%" PRIx64 "\n", addr); + + if (dwarf_hasattr (&subdie, DW_AT_high_pc)) + printf ("Unexpected highpc on split DIE\n"); + if (dwarf_hasattr (&subdie, DW_AT_ranges)) + printf ("Unexpected ranges on split DIE\n"); + + if (dwarf_hasattr_integrate (&subdie, DW_AT_high_pc)) + printf ("Skel has high_pc.\n"); + if (dwarf_hasattr_integrate (&subdie, DW_AT_ranges)) + printf ("Skel has ranges.\n"); + + printf ("\n"); + } + } + + if (count == 0) + { + printf ("No units found\n"); + return -1; + } + + dwarf_end (dbg); + close (fd); + } + + return 0; +} diff --git a/tests/run-attr-integrate-skel.sh b/tests/run-attr-integrate-skel.sh new file mode 100755 index 00000000..a9a9409a --- /dev/null +++ b/tests/run-attr-integrate-skel.sh @@ -0,0 +1,52 @@ +#! /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 tests/testfile-dwarf-45.source +testfiles testfile-splitdwarf-4 testfile-hello4.dwo testfile-world4.dwo +testfiles testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo + +testrun_compare ${abs_builddir}/attr-integrate-skel testfile-splitdwarf-4 << EOF +file: testfile-splitdwarf-4 +Split DIE: hello.c +addr_base secoff: 0x0 +low_pc addr: 0x401160 +Skel has high_pc. + +Split DIE: world.c +addr_base secoff: 0x98 +low_pc addr: 0x0 +Skel has ranges. + +EOF + +testrun_compare ${abs_builddir}/attr-integrate-skel testfile-splitdwarf-5 << EOF +file: testfile-splitdwarf-5 +Split DIE: hello.c +addr_base secoff: 0x8 +low_pc addr: 0x401160 +Skel has high_pc. + +Split DIE: world.c +addr_base secoff: 0xa8 +low_pc addr: 0x0 +Skel has ranges. + +EOF + +exit 0 |
