diff options
Diffstat (limited to 'tests')
102 files changed, 7861 insertions, 347 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index 04efdc81..765a874b 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,489 @@ +2018-06-28 Mark Wielaard <mark@klomp.org> + + * next_cfi.c: New file. + * run-next-cfi.sh: New test. + * run-next-cfi-self.sh: Likewise. + * Makefile.am (check_PROGRAMS): Add next_cfi. + (TESTS): Add run-next-cfi.sh and run-next-cfi-self.sh. + (EXTRA_DIST): Likewise. + (next_cfi_LDADD): New variable. + +2018-06-27 Mark Wielaard <mark@klomp.org> + + * dwarf_cfi.c: New file. + * run-dwarfcfi.sh: New test. + * testfile11-debugframe.bz2: New testfile. + * testfile12-debugframe.bz2: Likewise. + * testfileaarch64-debugframe.bz2: Likewise. + * testfilearm-debugframe.bz2: Likewise. + * testfileppc32-debugframe.bz2: Likewise. + * testfileppc64-debugframe.bz2: Likewise. + * Makefile.am (check_PROGRAMS): Add dwarfcfi. + (TESTS): Add run-dwarfcfi.sh. + (EXTRA_DIST): Add run-dwarfcfi.sh, testfile11-debugframe.bz2, + testfile12-debugframe.bz2, testfileaarch64-debugframe.bz2, + testfilearm-debugframe.bz2, testfileppc32-debugframe.bz2 and + testfileppc64-debugframe.bz2. + +2018-06-23 Mark Wielaard <mark@klomp.org> + + * varlocs.c (print_expr): Take a new depth argument. Check it isn't + greater than MAX_DEPTH (64). Pass on to print_expr_block. + (print_expr_block): Take a new depth argument. Pass it to print_expr. + (print_expr_block_addrs): Call print_expr_block with zero depth. + +2018-06-25 Mark Wielaard <mark@klomp.org> + + * next-files.c: New file. + * next-lines.c: Likewise. + * run-next-files.sh: New test. + * run-next-lines.sh: Likewise. + * testfile-only-debug-line.bz2: New test file. + * Makefile.am (check_PROGRAMS): Add next-files and next-lines. + (TESTS): Add run-next-files.sh and run-next-lines.sh. + (EXTRA_DIST): Add run-next-files.sh, run-next-lines.sh and + testfile-only-debug-line.bz2. + (next_lines_LDADD): New variable. + (next_files_LDADD): Likewise. + +2018-06-16 Yonghong Song <yhs@fb.com> + + * run-reloc-bpf.sh: New test. + * testfile-bpf-reloc.o.bz2: New test file. + * testfile-bpf-reloc.expect.bz2: New test file. + * Makefile.am (TESTS): Add run-reloc-bpf.sh. + (EXTRA_DIST): Add run-reloc-bpf.sh, testfile-bpf-reloc.o.bz2 and + testfile-bpf-reloc.expect.bz2. + +2018-06-13 Mark Wielaard <mark@klomp.org> + + * run-readelf-const-values.sh: New test. + * testfile-const-values.debug.bz2: New test file. + * run-readelf-zdebug-rel.sh: Adjust expected const_value. + * Makefile.am (TESTS): Add run-readelf-const-values.sh. + (EXTRA_DIST): Add run-readelf-const-values.sh and + testfile-const-values.debug.bz2. + +2018-06-08 Mark Wielaard <mark@klomp.org> + + * varlocs.c (print_expr): Error on bad DW_OP_GNU_parameter_ref + target, do not assert. + +2018-06-08 Mark Wielaard <mark@klomp.org> + + * get-units-invalid.c (main): Check invalid dwarf_getabbrev call. + * show-abbrev.c (main): Check illegal dwarf_getabbrev offset call. + +2018-06-08 Mark Wielaard <mark@klomp.org> + + * varlocs.c (main): Only assert when cfi_debug_bias != 0 if there + actually is a cfi_debug. + +2018-06-07 Mark Wielaard <mark@klomp.org> + + * run-readelf-loc.sh: Fix expected output for startx_length. + +2018-06-06 Mark Wielaard <mark@klomp.org> + + * varlocs.c (print_base_type): Use error, not assert when the DIE + isn't a base type. + +2018-06-02 Mark Wielaard <mark@klomp.org> + + * test-subr.sh (self_test_files_exe): Drop shared libraries. + Keep addr2line, elfcmp, objdump and readelf. + +2018-05-31 Mark Wielaard <mark@klomp.org> + + * run-readelf-types.sh: New test. + * Makefile.am (TESTS): Add run-readelf-types.sh. + (EXTRA_DIST): Likewise. + +2018-05-31 Mark Wielaard <mark@klomp.org> + + * splitdwarf4-not-split4.dwo.bz2: New test file. + * testfile-splitdwarf4-not-split4.debug.bz2: Likewise. + * run-readelf-loc.sh: Add test for splitdwarf4-not-split4.dwo + and testfile-splitdwarf4-not-split4.debug. + * run-varlocs.sh: Test testfile-splitdwarf4-not-split4.debug. + * Makefile.am (EXTRA_DIST): Add splitdwarf4-not-split4.dwo.bz2 + and testfile-splitdwarf4-not-split4.debug.bz2. + +2018-05-31 Mark Wielaard <mark@klomp.org> + + * test-subr.sh (self_test_files): Split into self_test_files_exe, + self_test_files_lib and self_test_obj. + (testrun_on_self_exe): New function. + (testrun_on_self_lib): Likewise. + * run-get-units-split.sh: Replace testrun_on_self with + testrun_on_self_exe and testrun_on_self_lib. + * run-unit-info.sh: Likewise. + +2018-05-31 Mark Wielaard <mark@klomp.org> + + * low_high_pc.c (handle_die): Handle NULL name. Print offset and + name of die. + (main): Check if the cu DIE is a skeleton, then get and handle + the split subdie. + * run-low-high-pc.sh: Run on testfile-splitdwarf-4 and + testfile-splitdwarf-5. Run on all selftest files. + +2018-05-31 Mark Wielaard <mark@klomp.org> + + * get-units-invalid.c (main): Check dwarf_cuoffset and + dwarf_dieoffset. + +2018-05-29 Mark Wielaard <mark@klomp.org> + + * dwarf-die-addr-die.c (check_dbg): Also check subdies, split or + type, gotten through dwarf_get_units. + * run-dwarf-die-addr-die.sh: Add tests for dwarf-4, dwarf-5, + split-dwarf-4, split-dwarf-5 and dwo files. + +2018-05-29 Mark Wielaard <mark@klomp.org> + + * run-readelf-loc.sh: Add GNU DebugFission split-dwarf variant. + * run-varlocs.sh: Likewise. + +2018-05-29 Mark Wielaard <mark@klomp.org> + + * run-readelf-twofiles.sh: Add --debug-dump=loc testcase. + +2018-05-28 Mark Wielaard <mark@klomp.org> + + * run-readelf-info-plus.sh: New test. + * Makefile.am (TESTS): Add run-readelf-info-plus.sh. + (EXTRA_DIST): Likewise. + +2018-04-29 Mark Wielaard <mark@klomp.org> + + * run-readelf-addr.sh: New test. + * Makefile.am (TESTS): Add run-readelf-addr.sh. + (EXTRA_DIST): Likewise. + +2018-04-27 Mark Wielaard <mark@klomp.org> + + * run-readelf-ranges.sh: Adjust expected output for address base. + * run-readelf-addr.sh: New test. + * Makefile.am (TESTS): Add run-readelf-addr.sh. + (EXTRA_DIST): Likewise. + +2018-04-07 Mark Wielaard <mark@klomp.org> + + * run-varlocs.sh: Run on testfileranges5.debug and + testsplitfileranges5.debug. + * varlocs.c (is_debug): New bool. + (print_expr): Don't fail on missing CFI for is_debug. + (main): Parse --debug, set is_debug. + +2018-04-12 Mark Wielaard <mark@klomp.org> + + * run-readelf-loc.sh: Add new testcases. + +2018-04-06 Mark Wielaard <mark@klomp.org> + + * testfileranges5.debug.bz2: New testfile. + * testfilesplitranges5.debug.bz2: Likewise. + * testfile-ranges-hello5.dwo.bz2: Likewise. + * testfile-ranges-world5.dwo.bz2: Likewise. + * run-dwarf-ranges.sh: Run on testfileranges5.debug. + * run-all-dwarf-ranges.sh: Run on testfilesplitranges5.debug. + * tests/Makefile.am (EXTRA_DIST): Add testfileranges5.debug.bz2, + testfilesplitranges5.debug.bz2, testfile-ranges-hello5.dwo.bz2 and + testfile-ranges-world5.dwo.bz2. + +2018-04-11 Mark Wielaard <mark@klomp.org> + + * run-readelf-ranges.sh: New test. + * Makefile.am (TESTS): Add run-readelf-ranges.sh. + (EXTRA_DIST): Likewise. + +2018-05-21 Mark Wielaard <mark@klomp.org> + + * addrx_constx-4.dwo.bz2: New testfile. + * addrx_constx-5.dwo.bz2: Likewise. + * testfile-addrx_constx-4.bz2: Likewise. + * testfile-addrx_constx-5.bz2: Likewise + * Makefile.am (EXTRA_DIST): Add addrx_constx-5.dwo.bz2 + testfile-addrx_constx-4\ .bz2 testfile-addrx_constx-5.bz2. + * run-varlocs.sh: Add addrx_constx tests for DWARF4 and DWARF5. + * varlocx.c (print_expr): Handle DW_OP_GNU_addr_index, + DW_OP_addrx, DW_OP_GNU_const_index and DW_OP_constx. + (main): Handle split DWARF. + * run-all-dwarf-ranges.sh: Add new ranges for addrx low/highpc. + +2018-05-20 Mark Wielaard <mark@klomp.org> + + * unit-info.c: New test. + * run-unit-info.sh: New test runner. + * Makefile.am (check_PROGRAMS): Add unit-info. + (TESTS): Add run-unit-info.sh + (EXTRA_INFO): Likewise. + (unit_info_LDADD): New variable. + +2018-05-24 Mark Wielaard <mark@klomp.org> + + * get-units-invalid.c (main): Add check for invalid dwarf_ranges. + * run-all-dwarf-ranges.sh: Correct expected output. + +2018-05-18 Mark Wielaard <mark@klomp.org> + + * 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 <mark@klomp.org> + + * 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. + +2018-05-17 Mark Wielaard <mark@klomp.org> + + * 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 <mark@klomp.org> + + * Makefile.am (check_PROGRAMS): Add get-units-split. + (TESTS): Add run-get-units-split.sh. + (EXTRA_DIST): Add 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 and + testfile-world4.dwo.bz2. + (get_units_split_LDADD): New variable. + * get-units-split.c: New test. + * run-get-units-split.sh: New test runner. + * testfile-dwarf-45.source: Extend with build instructions for new + test files. + * testfile-hello4.dwo.bz2: New test file. + * testfile-hello5.dwo.bz2: Likewise. + * testfile-splitdwarf-4.bz2: Likewise. + * testfile-splitdwarf-5.bz2: Likewise. + * testfile-world5.dwo.bz2 and: Likewise. + * testfile-world4.dwo.bz2: Likewise. + +2018-05-09 Mark Wielaard <mark@klomp.org> + + * run-readelf-zdebug.sh: Adjust test output for new header layout. + * run-readelf-line.sh: Likewise. Add new tests for testfile-dwarf-4 + and testfile-dwarf-5. + +2018-05-11 Mark Wielaard <mark@klomp.org> + + * Makefile.am (check_PROGRAMS): Add get-units-invalid. + (TESTS): Add run-get-units-invalid.sh. + (EXTRA_DIST): Likewise. + (get_units_invalid_LDADD): New variable. + * get-units-invalid.c: New test program. + * run-get-units-invalid.sh: New test program runner. + +2018-05-05 Mark Wielaard <mark@klomp.org> + + * testfile-dwarf-45.source: New file. + * testfile-dwarf-4.bz2: New test file. + * testfile-dwarf-5.bz2: Likewise. + * run-readelf-line.sh: Add testcases for testfile-dwarf-4 and + testfile-dwarf-5. + * Makefile (EXTRA_DIST): Add testfile-dwarf-45.source, + testfile-dwarf-4.bz2 and testfile-dwarf-5.bz2. + +2018-04-19 Andreas Schwab <schwab@suse.de> + + * hello_riscv64.ko.bz2: New file. + * run-strip-reloc.sh: Test it. + * Makefile.am (EXTRA_DIST): Add it. + +2018-04-16 Mark Wielaard <mark@klomp.org> + + * testfile-ppc64-min-instr.bz2: New testfile. + * run-readelf-line.sh: Run against testfile-ppc64-min-instr.bz2. + * Makefile.am (EXTRA_DIST): Add testfile-ppc64-min-instr.bz2. + +2018-04-11 Mark Wielaard <mark@klomp.org> + + * run-addrcfi.sh: Adjust expected rule for aarch64 sp. + +2018-04-03 Mark Wielaard <mark@klomp.org> + + * testfileranges4.debug.bz2: New testfile. + * run-dwarf-ranges.sh: Run on testfileranges4.debug. + * tests/Makefile.am (EXTRA_DIST): Add testfileranges4.debug.bz2. + +2018-03-06 Mark Wielaard <mark@klomp.org> + + * varlocs.c (print_expr): Handle DW_OP_implicit_pointer, + DW_OP_entry_value, DW_OP_convert, DW_OP_reinterpret, + DW_OP_regval_type, DW_OP_deref_type, DW_OP_xderef_type and + DW_OP_const_type. + +2018-02-16 Mark Wielaard <mark@klomp.org> + + * backtrace-subr.sh (check_native_core): Check if there is any core, + if so, use it. + +2018-02-15 Mark Wielaard <mark@klomp.org> + + * backtrace-child.c: Include signal.h after sys/ptrace.h. + * backtrace-dwarf.c: Include sys/wait.h and signal.h after + sys/ptrace.h. + +2018-01-25 Mark Wielaard <mark@klomp.org> + + * Makefile.am (check_PROGRAMS): Add dwarf-die-addr-die. + (TESTS): Add run-dwarf-die-addr-die.sh. + (EXTRA_DIST): Likewise. + (dwarf_die_addr_die_LDADD): New variable. + * dwarf-die-addr-die.c: New file. + * run-dwarf-die-addr-die.sh: New test. + +2018-02-09 Joshua Watt <JPEWhacker@gmail.com> + + * elfstrmerge.c (main): Use FALLTHROUGH macro instead of comment. + +2018-01-22 Mark Wielaard <mark@klomp.org> + + * allfcts.c (setup_alt): Print warning when alt file couldn't be + found. + * run-allfcts-multi.sh: Add testcase where alt file is in a subdir + where it cannot be found by allfcts itself (but it can by libdw). + +2018-01-25 Mark Wielaard <mark@klomp.org> + + * elfstrmerge.c (main): Initialize and check symtabshdr instead of + symtabndx. + +2018-01-14 Petr Machata <pmachata@gmail.com> + + * testfile-sizes4.o.bz2: New test file. + * testfile-sizes4.s: New test source. + * run-aggregate-size.sh: Check testfile-sizes4.o v size 257. + +2017-12-23 Mark Wielaard <mark@klomp.org> + + * backtrace-subr.sh (check_native_core): Use a lock file and try + to extract core using coredumpctl. + * Makefile.am (CLEANFILES): Clean core-dump-backtrace.lock. + +2017-12-11 Dima Kogan <dima@secretsauce.net> + + * run-aggregate-size.sh: Added check for multi-dimensional arrays. + * run-peel-type.sh: Likewise. + * testfile-sizes3.o.bz2: Likewise. + +2017-12-07 Mark Wielaard <mark@klomp.org> + + * run-readelf-variant.sh: New test. + * testfile-ada-variant.bz2: New testfile. + * Makefile.am (TESTS): Add run-readelf-variant.sh. + (EXTRA_DISTS): Add run-readelf-variant.sh and + testfile-ada-variant.bz2. + +2017-11-29 Mark Wielaard <mark@klomp.org> + + * run-readelf-loc.sh: Adjust expected loc list output. + * run-readelf-zdebug-rel.sh: Likewise. + * run-readelf-zdebug.sh: Likewise. + +2017-11-29 Mark Wielaard <mark@klomp.org> + + * run-readelf-loc.sh: Adjust expected range list output. + * run-readelf-zdebug.sh: Likewise. + +2017-11-29 Mark Wielaard <mark@klomp.org> + + * run-readelf-dwz-multi.sh: Add expected file names. + * run-readelf-zdebug-rel.sh: Likewise. + +2017-11-29 Mark Wielaard <mark@klomp.org> + + * run-readelf-dwz-multi.sh: Add expected abbrev codes. + * run-readelf-zdebug-rel.sh: Likewise. + +2017-11-29 Mark Wielaard <mark@klomp.org> + + * run-readelf-dwz-multi.sh: Adjust expected ops index spaces. + * run-readelf-loc.sh: Likewise. + * run-readelf-zdebug-rel.sh: Likewise. + * run-readelf-zdebug.sh: Likewise. + +2017-11-16 Mark Wielaard <mark@klomp.org> + + * varlocs.c (main): Fix cfi_debug => cfi_debug_bias typo in assert. + +2017-11-10 Mark Wielaard <mark@klomp.org> + + * run-exprlocs-self.sh: New test. + * run-varlocs-self.sh: Likewise. + * Makefile.am (TESTS) Add run-exprlocs-self.sh and + run-varlocs-self.sh. + (EXTRA_DIST): Likewise. + * varlocs.c (cfi_debug_bias): New global variable. + (is_ET_REL): Likewise. + (print_expr): Don't crash and burn when CFI cannot be found for an + ET_REL file for DW_OP_call_frame_cfa. + (handle_die): If there is no entry_pc pick the lowest pc start range + for the DIE. + (main): Check at least one CU was found. Use dwfl_module_dwarf_cfi + and dwfl_module_eh_cfi to fix memory leak. Set is_ET_REL. + +2017-11-03 Mark Wielaard <mark@klomp.org> + + * run-exprlocs.sh: New test. + * testfile-stridex.bz2: New testfile. + * Makefile.am (TESTS): Add run-exprlocs.sh. + (EXTRA_DIST): Add run-exprlocs.sh and testfile-stridex.bz2. + * varlocs.c (dwarf_tag_string): New function. + (dwarf_attr_string): Likewise. + (dwarf_form_string): Likewise. + (print_expr): Fix typo in error message.r + Handle DW_OP_GNU_variable_value. + (attr_arg): New struct. + (handle_attr): New function. + (handle_die): Likewise. + (main): Handle --exprlocs argument. Call handle_die. + +2017-10-16 Mark Wielaard <mark@klomp.org> + + * md5-sha1-test.c: Removed. + * Makefile.am (check_PROGRAMS): Remove md5-sha1-test. + (TESTS): Likewise. + (md5_sha1_test_LDADD): Removed. + +2017-10-04 Mark Wielaard <mark@klomp.org> + + * msg_tst.c: Handle ELF_E_INVALID_ELF. + +2017-09-10 Mark Wielaard <mark@klomp.org> + + * run-ar.sh: New test. + * Makefile.am (TESTS): Add run-ar.sh. + (EXTRA_DIST): Likewise. + +2017-08-18 Ulf Hermann <ulf.hermann@qt.io> + + * Makefile.am: Drop -rdynamic from deleted_lib_so_LDFLAGS. + +2017-04-27 Ulf Hermann <ulf.hermann@qt.io> + + * Makefile.am: Use fpie_CFLAGS and fpic_CFLAGS. + +2017-08-08 Dmitry V. Levin <ldv@altlinux.org> + + * run-strip-nothing.sh: Add -s. + 2017-07-26 Mark Wielaard <mark@klomp.org> * dwarf-getmacros.c (mac): Use DW_MACRO names instead of DW_MACRO_GNU. diff --git a/tests/Makefile.am b/tests/Makefile.am index 483f3878..e89163d5 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 @@ -38,15 +38,17 @@ endif check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ showptable update1 update2 update3 update4 test-nlist \ - show-die-info get-files get-lines get-pubnames \ + show-die-info get-files next-files get-lines next-lines \ + get-pubnames \ get-aranges allfcts line2addr addrscopes funcscopes \ show-abbrev hash newscn ecp dwflmodtest \ 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 dwarf-getmacros dwarf-ranges addrcfi \ + dwarfcfi \ test-flag-nobits dwarf-getstring rerequest_tag \ - alldts md5-sha1-test typeiter typeiter2 low_high_pc \ + alldts typeiter typeiter2 low_high_pc \ test-elf_cntl_gelf_getshdr dwflsyms dwfllines \ dwfl-report-elf-align varlocs backtrace backtrace-child \ backtrace-data backtrace-dwarf debuglink debugaltlink \ @@ -55,7 +57,9 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ getsrc_die strptr newdata elfstrtab dwfl-proc-attach \ elfshphehdr elfstrmerge dwelfgnucompressed elfgetchdr \ elfgetzdata elfputzdata zstrptr emptyfile vendorelf \ - fillfile dwarf_default_lower_bound + fillfile dwarf_default_lower_bound dwarf-die-addr-die \ + get-units-invalid get-units-split attr-integrate-skel \ + all-dwarf-ranges unit-info next_cfi asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ asm-tst6 asm-tst7 asm-tst8 asm-tst9 @@ -72,9 +76,10 @@ backtrace-child-biarch$(EXEEXT): backtrace-child.c $(AM_LDFLAGS) $(LDFLAGS) $(backtrace_child_LDFLAGS) \ -o $@ $< -TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ +TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ update1 update2 update3 update4 \ run-show-die-info.sh run-get-files.sh run-get-lines.sh \ + run-next-files.sh run-next-lines.sh \ run-get-pubnames.sh run-get-aranges.sh run-allfcts.sh \ run-show-abbrev.sh run-line2addr.sh hash \ newscn run-strip-test.sh run-strip-test2.sh \ @@ -91,10 +96,13 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-ranlib-test2.sh run-ranlib-test3.sh run-ranlib-test4.sh \ run-addrscopes.sh run-strings-test.sh run-funcscopes.sh \ run-find-prologues.sh run-allregs.sh run-addrcfi.sh \ - run-nm-self.sh run-readelf-self.sh \ + run-dwarfcfi.sh \ + run-nm-self.sh run-readelf-self.sh run-readelf-info-plus.sh \ + run-readelf-const-values.sh \ + run-varlocs-self.sh run-exprlocs-self.sh \ run-readelf-test1.sh run-readelf-test2.sh run-readelf-test3.sh \ run-readelf-test4.sh run-readelf-twofiles.sh \ - run-readelf-macro.sh run-readelf-loc.sh \ + run-readelf-macro.sh run-readelf-loc.sh run-readelf-ranges.sh \ run-readelf-aranges.sh run-readelf-line.sh run-readelf-z.sh \ run-native-test.sh run-bug1-test.sh \ run-debuglink.sh run-debugaltlink.sh run-buildid.sh \ @@ -109,10 +117,11 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-low_high_pc.sh run-macro-test.sh run-elf_cntl_gelf_getshdr.sh \ run-test-archive64.sh run-readelf-vmcoreinfo.sh \ run-readelf-mixed-corenote.sh run-dwfllines.sh \ + run-readelf-variant.sh \ run-dwfl-report-elf-align.sh run-addr2line-test.sh \ run-addr2line-i-test.sh run-addr2line-i-lex-test.sh \ run-addr2line-i-demangle-test.sh run-addr2line-alt-debugpath.sh \ - run-varlocs.sh run-funcretval.sh \ + run-varlocs.sh run-exprlocs.sh run-funcretval.sh \ run-backtrace-native.sh run-backtrace-data.sh run-backtrace-dwarf.sh \ run-backtrace-native-biarch.sh run-backtrace-native-core.sh \ run-backtrace-native-core-biarch.sh run-backtrace-core-x86_64.sh \ @@ -126,6 +135,8 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-backtrace-core-aarch64.sh run-backtrace-core-sparc.sh \ run-backtrace-demangle.sh run-stack-d-test.sh run-stack-i-test.sh \ run-stack-demangled-test.sh run-readelf-zx.sh run-readelf-zp.sh \ + run-readelf-addr.sh run-readelf-str.sh \ + run-readelf-types.sh \ run-readelf-dwz-multi.sh run-allfcts-multi.sh run-deleted.sh \ run-linkmap-cut.sh run-aggregate-size.sh run-peel-type.sh \ vdsosyms run-readelf-A.sh \ @@ -135,7 +146,13 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-elfgetzdata.sh run-elfputzdata.sh run-zstrptr.sh \ run-compress-test.sh \ run-readelf-zdebug.sh run-readelf-zdebug-rel.sh \ - emptyfile vendorelf fillfile dwarf_default_lower_bound + 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-all-dwarf-ranges.sh run-unit-info.sh \ + run-reloc-bpf.sh \ + run-next-cfi.sh run-next-cfi-self.sh if !BIARCH export ELFUTILS_DISABLE_BIARCH = 1 @@ -146,8 +163,8 @@ export ELFUTILS_DISABLE_DEMANGLE = 1 endif if !STANDALONE -check_PROGRAMS += msg_tst md5-sha1-test system-elf-libelf-test -TESTS += msg_tst md5-sha1-test system-elf-libelf-test +check_PROGRAMS += msg_tst system-elf-libelf-test +TESTS += msg_tst system-elf-libelf-test endif if LZMA @@ -159,8 +176,9 @@ check_PROGRAMS += $(asm_TESTS) TESTS += $(asm_TESTS) run-disasm-bpf.sh endif -EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ +EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ run-show-die-info.sh run-get-files.sh run-get-lines.sh \ + run-next-files.sh run-next-lines.sh testfile-only-debug-line.bz2 \ run-get-pubnames.sh run-get-aranges.sh \ run-show-abbrev.sh run-strip-test.sh \ run-strip-test2.sh run-ecp-test.sh run-ecp-test2.sh \ @@ -178,7 +196,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ testfile-nobitsalign.bz2 testfile-nobitsalign.strip.bz2 \ run-strip-reloc.sh hello_i386.ko.bz2 hello_x86_64.ko.bz2 \ hello_ppc64.ko.bz2 hello_s390.ko.bz2 hello_aarch64.ko.bz2 \ - hello_m68k.ko.bz2 \ + hello_m68k.ko.bz2 hello_riscv64.ko.bz2 \ run-unstrip-test.sh run-unstrip-test2.sh \ testfile-info-link.bz2 testfile-info-link.debuginfo.bz2 \ testfile-info-link.stripped.bz2 run-unstrip-test3.sh \ @@ -188,12 +206,21 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ run-elflint-self.sh run-ranlib-test.sh run-ranlib-test2.sh \ run-ranlib-test3.sh run-ranlib-test4.sh \ run-addrscopes.sh run-strings-test.sh run-funcscopes.sh \ - run-nm-self.sh run-readelf-self.sh run-addrcfi.sh \ + run-nm-self.sh run-readelf-self.sh run-readelf-info-plus.sh \ + run-readelf-const-values.sh testfile-const-values.debug.bz2 \ + run-addrcfi.sh run-dwarfcfi.sh \ + testfile11-debugframe.bz2 testfile12-debugframe.bz2 \ + testfileaarch64-debugframe.bz2 testfilearm-debugframe.bz2 \ + testfileppc32-debugframe.bz2 testfileppc64-debugframe.bz2 \ + run-varlocs-self.sh run-exprlocs-self.sh \ run-find-prologues.sh run-allregs.sh run-native-test.sh \ run-addrname-test.sh run-dwfl-bug-offline-rel.sh \ run-dwfl-addr-sect.sh run-early-offscn.sh \ run-dwarf-getmacros.sh \ run-dwarf-ranges.sh debug-ranges-no-lowpc.o.bz2 \ + testfileranges4.debug.bz2 testfileranges5.debug.bz2 \ + testfilesplitranges5.debug.bz2 \ + testfile-ranges-hello5.dwo.bz2 testfile-ranges-world5.dwo.bz2 \ run-test-flag-nobits.sh \ run-dwarf-getstring.sh run-rerequest_tag.sh run-alldts.sh \ testfile15.bz2 testfile15.debug.bz2 \ @@ -224,11 +251,19 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ testfile-macros-0xff.bz2 \ run-readelf-macro.sh testfilemacro.bz2 \ run-readelf-loc.sh testfileloc.bz2 \ + splitdwarf4-not-split4.dwo.bz2 \ + testfile-splitdwarf4-not-split4.debug.bz2 \ + run-readelf-ranges.sh \ run-readelf-aranges.sh run-readelf-line.sh testfilefoobarbaz.bz2 \ + testfile-ppc64-min-instr.bz2 \ + testfile-dwarf-45.source \ + testfile-dwarf-4.bz2 testfile-dwarf-5.bz2 \ run-readelf-z.sh \ run-readelf-dwz-multi.sh libtestfile_multi_shared.so.bz2 \ testfile_multi.dwz.bz2 testfile_multi_main.bz2 \ testfile-dwzstr.bz2 testfile-dwzstr.multi.bz2 \ + run-readelf-addr.sh run-readelf-str.sh \ + run-readelf-types.sh \ run-allfcts-multi.sh \ test-offset-loop.bz2 test-offset-loop.alt.bz2 \ run-prelink-addr-test.sh \ @@ -262,6 +297,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ testfilebazdynppc64.bz2 testfilebazmdbppc64.bz2 \ testfilebazminppc64.bz2 testfilebazminppc64_pl.bz2 \ testfilebazminppc64_plr.bz2 testfilebaztabppc64.bz2 \ + run-readelf-variant.sh testfile-ada-variant.bz2 \ run-dwflsyms.sh \ run-unstrip-n.sh testcore-rtlib.bz2 testcore-rtlib-ppc.bz2 \ run-low_high_pc.sh testfile_low_high_pc.bz2 \ @@ -284,13 +320,15 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ testfileppc32.bz2 testfileppc64.bz2 \ testfiles390.bz2 testfiles390x.bz2 \ testfilearm.bz2 testfileaarch64.bz2 \ - run-varlocs.sh \ + run-varlocs.sh run-exprlocs.sh testfile-stridex.bz2 \ testfile_const_type.c testfile_const_type.bz2 \ testfile_implicit_pointer.c testfile_implicit_pointer.bz2 \ testfile_parameter_ref.c testfile_parameter_ref.bz2 \ testfile_entry_value.c testfile_entry_value.bz2 \ testfile_implicit_value.c testfile_implicit_value.bz2 \ testfile_aarch64_core.bz2 testfile_i686_core.bz2 \ + addrx_constx-4.dwo.bz2 addrx_constx-5.dwo.bz2 \ + testfile-addrx_constx-4.bz2 testfile-addrx_constx-5.bz2 \ run-funcretval.sh funcretval_test.c funcretval_test_aarch64.bz2 \ run-backtrace-data.sh run-backtrace-dwarf.sh cleanup-13.c \ run-backtrace-native.sh run-backtrace-native-biarch.sh \ @@ -329,7 +367,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ run-deleted.sh run-linkmap-cut.sh linkmap-cut-lib.so.bz2 \ linkmap-cut.bz2 linkmap-cut.core.bz2 \ run-aggregate-size.sh testfile-sizes1.o.bz2 testfile-sizes2.o.bz2 \ - testfile-sizes3.o.bz2 run-peel-type.sh \ + testfile-sizes3.o.bz2 testfile-sizes4.o.bz2 testfile-sizes4.s \ + run-peel-type.sh \ run-readelf-A.sh testfileppc32attrs.o.bz2 \ testfilesparc64attrs.o.bz2 testfileppc64attrs.o.bz2 \ testfile-debug-types.bz2 \ @@ -347,7 +386,18 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ run-zstrptr.sh run-compress-test.sh \ run-disasm-bpf.sh \ testfile-bpf-dis1.expect.bz2 testfile-bpf-dis1.o.bz2 \ - testfile-m68k-core.bz2 testfile-m68k.bz2 testfile-m68k-s.bz2 + run-reloc-bpf.sh \ + testfile-bpf-reloc.expect.bz2 testfile-bpf-reloc.o.bz2 \ + testfile-m68k-core.bz2 testfile-m68k.bz2 testfile-m68k-s.bz2 \ + run-dwarf-die-addr-die.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 \ + run-attr-integrate-skel.sh \ + run-all-dwarf-ranges.sh testfilesplitranges4.debug.bz2 \ + testfile-ranges-hello.dwo.bz2 testfile-ranges-world.dwo.bz2 \ + run-unit-info.sh run-next-cfi.sh run-next-cfi-self.sh if USE_VALGRIND valgrind_cmd='valgrind -q --leak-check=full --error-exitcode=1' @@ -430,7 +480,9 @@ show_die_info_LDADD = $(libdw) $(libelf) get_pubnames_LDADD = $(libdw) $(libelf) show_abbrev_LDADD = $(libdw) $(libelf) get_lines_LDADD = $(libdw) $(libelf) +next_lines_LDADD = $(libdw) $(libelf) get_files_LDADD = $(libdw) $(libelf) +next_files_LDADD = $(libdw) $(libelf) get_aranges_LDADD = $(libdw) $(libelf) allfcts_LDADD = $(libdw) $(libelf) line2addr_no_Wformat = yes @@ -462,10 +514,10 @@ dwarf_getmacros_LDADD = $(libdw) dwarf_ranges_LDADD = $(libdw) dwarf_getstring_LDADD = $(libdw) addrcfi_LDADD = $(libdw) $(libebl) $(libelf) $(argp_LDADD) -ldl +dwarfcfi_LDADD = $(libdw) $(libelf) test_flag_nobits_LDADD = $(libelf) rerequest_tag_LDADD = $(libdw) alldts_LDADD = $(libdw) $(libelf) -md5_sha1_test_LDADD = $(libeu) typeiter_LDADD = $(libdw) $(libelf) typeiter2_LDADD = $(libdw) $(libelf) low_high_pc_LDADD = $(libdw) $(libelf) $(argp_LDADD) @@ -476,7 +528,7 @@ dwfl_report_elf_align_LDADD = $(libdw) varlocs_LDADD = $(libdw) $(libelf) $(argp_LDADD) backtrace_LDADD = $(libdw) $(libelf) $(argp_LDADD) # backtrace-child-biarch also uses those *_CFLAGS and *_LDLAGS variables: -backtrace_child_CFLAGS = -fPIE +backtrace_child_CFLAGS = $(fpie_CFLAGS) backtrace_child_LDFLAGS = -pie -pthread backtrace_child_biarch_SOURCES = backtrace-child.c backtrace_data_LDADD = $(libdw) $(libelf) @@ -486,8 +538,8 @@ debuglink_LDADD = $(libdw) $(libelf) debugaltlink_LDADD = $(libdw) $(libelf) buildid_LDADD = $(libdw) $(libelf) deleted_LDADD = ./deleted-lib.so -deleted_lib_so_LDFLAGS = -shared -rdynamic -deleted_lib_so_CFLAGS = -fPIC -fasynchronous-unwind-tables +deleted_lib_so_LDFLAGS = -shared +deleted_lib_so_CFLAGS = $(fpic_CFLAGS) -fasynchronous-unwind-tables aggregate_size_LDADD = $(libdw) $(libelf) $(argp_LDADD) peel_type_LDADD = $(libdw) $(libelf) $(argp_LDADD) vdsosyms_LDADD = $(libdw) $(libelf) @@ -508,12 +560,22 @@ emptyfile_LDADD = $(libelf) vendorelf_LDADD = $(libelf) fillfile_LDADD = $(libelf) 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) +all_dwarf_ranges_LDADD = $(libdw) +unit_info_LDADD = $(libdw) +next_cfi_LDADD = $(libelf) $(libdw) # We want to test the libelf header against the system elf.h header. # Don't include any -I CPPFLAGS. system_elf_libelf_test_CPPFLAGS = system_elf_libelf_test_LDADD = $(libelf) +# A lock file used to make sure only one test dumps core at a time +CLEANFILES += core-dump-backtrace.lock + if GCOV check: check-am coverage .PHONY: coverage diff --git a/tests/addrx_constx-4.dwo.bz2 b/tests/addrx_constx-4.dwo.bz2 Binary files differnew file mode 100644 index 00000000..f0bae1cd --- /dev/null +++ b/tests/addrx_constx-4.dwo.bz2 diff --git a/tests/addrx_constx-5.dwo.bz2 b/tests/addrx_constx-5.dwo.bz2 Binary files differnew file mode 100644 index 00000000..a5f4b1a6 --- /dev/null +++ b/tests/addrx_constx-5.dwo.bz2 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/allfcts.c b/tests/allfcts.c index d3c8d26a..f6373117 100644 --- a/tests/allfcts.c +++ b/tests/allfcts.c @@ -51,7 +51,10 @@ setup_alt (Dwarf *main) errx (1, "dwelf_dwarf_gnu_debugaltlink: %s", dwarf_errmsg (-1)); int fd = open (alt_name, O_RDONLY); if (fd < 0) - err (1, "open (%s)", alt_name); + { + printf ("Warning: no alt file found.\n"); + return NULL; + } Dwarf *dbg_alt = dwarf_begin (fd, DWARF_C_READ); if (dbg_alt == NULL) errx (1, "dwarf_begin (%s): %s", alt_name, dwarf_errmsg (-1)); 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/backtrace-child.c b/tests/backtrace-child.c index 2c27414f..9c6ba94f 100644 --- a/tests/backtrace-child.c +++ b/tests/backtrace-child.c @@ -81,7 +81,6 @@ #include <config.h> #include <assert.h> #include <stdlib.h> -#include <signal.h> #include <errno.h> #include <string.h> #include <pthread.h> @@ -100,6 +99,7 @@ main (int argc __attribute__ ((unused)), char **argv) #else /* __linux__ */ #include <sys/ptrace.h> +#include <signal.h> #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) #define NOINLINE_NOCLONE __attribute__ ((noinline, noclone)) diff --git a/tests/backtrace-dwarf.c b/tests/backtrace-dwarf.c index 2dc8a9a2..7ff826cd 100644 --- a/tests/backtrace-dwarf.c +++ b/tests/backtrace-dwarf.c @@ -17,7 +17,6 @@ #include <config.h> #include <assert.h> -#include <signal.h> #include <inttypes.h> #include <stdio_ext.h> #include <locale.h> @@ -25,7 +24,6 @@ #include <error.h> #include <unistd.h> #include <sys/types.h> -#include <sys/wait.h> #include ELFUTILS_HEADER(dwfl) #ifndef __linux__ @@ -40,6 +38,8 @@ main (int argc __attribute__ ((unused)), char **argv) #else /* __linux__ */ #include <sys/ptrace.h> +#include <sys/wait.h> +#include <signal.h> #define main cleanup_13_main #include "cleanup-13.c" diff --git a/tests/backtrace-subr.sh b/tests/backtrace-subr.sh index c1f31569..ff42c6ff 100644 --- a/tests/backtrace-subr.sh +++ b/tests/backtrace-subr.sh @@ -137,19 +137,53 @@ check_native() # Backtrace core file. check_native_core() { +# systemd-coredump/coredumpctl doesn't seem to like concurrent core dumps +# use a lock file (fd 200) tests/core-dump-backtrace.lock +( child=$1 # Disable valgrind while dumping core. SAVED_VALGRIND_CMD="$VALGRIND_CMD" unset VALGRIND_CMD + # Wait for lock for 10 seconds or skip. + flock -x -w 10 200 || exit 77; + # Skip the test if we cannot adjust core ulimit. - core="core.`ulimit -c unlimited || exit 77; set +ex; testrun ${abs_builddir}/$child --gencore; true`" + pid="`ulimit -c unlimited || exit 77; set +ex; testrun ${abs_builddir}/$child --gencore; true`" + core="core.$pid" # see if /proc/sys/kernel/core_uses_pid is set to 0 if [ -f core ]; then mv core "$core" fi - if [ ! -f "$core" ]; then echo "No $core file generated"; exit 77; fi + type -P coredumpctl && have_coredumpctl=1 || have_coredumpctl=0 + if [ ! -f "$core" -a $have_coredumpctl -eq 1 ]; then + # Maybe systemd-coredump took it. But give it some time to dump first... + sleep 1 + coredumpctl --output="$core" dump $pid || rm -f $core + + # Try a couple of times after waiting some more if something went wrong... + if [ ! -f "$core" ]; then + sleep 2 + coredumpctl --output="$core" dump $pid || rm -f $core + fi + + if [ ! -f "$core" ]; then + sleep 3 + coredumpctl --output="$core" dump $pid || rm -f $core + fi + fi + if [ ! -f "$core" ]; then + # In some containers our view of pids is confused. Since tests are + # run in a new fresh directory any core here is most like is ours. + if ls core.[0-9]* 1> /dev/null 2>&1; then + mv core.[0-9]* "$core" + fi + fi + if [ ! -f "$core" ]; then + echo "No $core file generated"; + exit 77; + fi if [ "x$SAVED_VALGRIND_CMD" != "x" ]; then VALGRIND_CMD="$SAVED_VALGRIND_CMD" @@ -163,4 +197,6 @@ check_native_core() cat $core.{bt,err} check_native_unsupported $core.err $child-$core check_all $core.{bt,err} $child-$core + rm $core{,.{bt,err}} +) 200>${abs_builddir}/core-dump-backtrace.lock } diff --git a/tests/backtrace.c b/tests/backtrace.c index 21abe8af..f5dd761f 100644 --- a/tests/backtrace.c +++ b/tests/backtrace.c @@ -127,7 +127,7 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc, assert (symname2 == NULL || strcmp (symname2, "jmp") != 0); break; } - /* FALLTHRU */ + FALLTHROUGH; case 4: /* Some simple frame unwinders get this wrong and think sigusr2 is calling itself again. Allow it and just pretend there is diff --git a/tests/dwarf-die-addr-die.c b/tests/dwarf-die-addr-die.c new file mode 100644 index 00000000..7899988f --- /dev/null +++ b/tests/dwarf-die-addr-die.c @@ -0,0 +1,186 @@ +/* Test program for dwarf_die_addr_die. + 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/>. */ + +#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> +#include <string.h> +#include <errno.h> +#include <unistd.h> + +/* The main Dwarf file. */ +static Dwarf *dwarf; + +int +check_die (Dwarf_Die *die) +{ + if (dwarf_tag (die) == DW_TAG_invalid) + { + printf ("Invalid die\n"); + return -1; + } + + int res = 0; + void *addr = die->addr; + Dwarf_Die die2; + if (dwarf_die_addr_die (dwarf, addr, &die2) == NULL) + { + printf ("Bad die addr die at offset %" PRIx64 "\n", + dwarf_dieoffset (die)); + res = -1; + } + + if (dwarf_tag (die) != dwarf_tag (&die2)) + { + printf ("Tags differ for die at offset %" PRIx64 "\n", + dwarf_dieoffset (die)); + res = -1; + } + + if (dwarf_cuoffset (die) != dwarf_cuoffset (&die2)) + { + printf ("CU offsets differ for die at offset %" PRIx64 "\n", + dwarf_dieoffset (die)); + res = -1; + } + + Dwarf_Die child; + if (dwarf_child (die, &child) == 0) + res |= check_die (&child); + + Dwarf_Die sibling; + if (dwarf_siblingof (die, &sibling) == 0) + res |= check_die (&sibling); + + return res; +} + +int +check_dbg (Dwarf *dbg) +{ + int res = 0; + Dwarf_Off off = 0; + Dwarf_Off old_off = 0; + size_t hsize; + Dwarf_Off abbrev; + uint8_t addresssize; + uint8_t offsetsize; + while (dwarf_nextcu (dbg, off, &off, &hsize, &abbrev, &addresssize, + &offsetsize) == 0) + { + Dwarf_Die die; + if (dwarf_offdie (dbg, old_off + hsize, &die) != NULL) + { + printf ("checking CU at %" PRIx64 "\n", old_off); + res |= check_die (&die); + } + + old_off = off; + } + + // Same for type... + Dwarf_Half version; + uint64_t typesig; + Dwarf_Off typeoff; + off = 0; + old_off = 0; + while (dwarf_next_unit (dbg, off, &off, &hsize, &version, &abbrev, + &addresssize, &offsetsize, &typesig, &typeoff) == 0) + { + Dwarf_Die die; + if (dwarf_offdie_types (dbg, old_off + hsize, &die) != NULL) + { + printf ("checking TU at %" PRIx64 "\n", old_off); + res |= check_die (&die); + } + + // We should have seen this already, but double check... + if (dwarf_offdie_types (dbg, old_off + typeoff, &die) != NULL) + { + printf ("checking Type DIE at %" PRIx64 "\n", + old_off + hsize + typeoff); + res |= check_die (&die); + } + + old_off = off; + } + + Dwarf *alt = dwarf_getalt (dbg); + if (alt != NULL) + { + printf ("checking alt debug\n"); + res |= check_dbg (alt); + } + + // Split or Type Dwarf_Dies gotten through dwarf_get_units. + Dwarf_CU *cu = NULL; + Dwarf_Die subdie; + uint8_t unit_type; + while (dwarf_get_units (dbg, cu, &cu, NULL, + &unit_type, NULL, &subdie) == 0) + { + if (dwarf_tag (&subdie) != DW_TAG_invalid) + { + printf ("checking %" PRIx8 " subdie\n", unit_type); + res |= check_die (&subdie); + } + } + + return res; +} + +int +main (int argc, char *argv[]) +{ + if (argc < 2) + { + printf ("No file given.\n"); + return -1; + } + + const char *name = argv[1]; + int fd = open (name, O_RDONLY); + if (fd < 0) + { + printf ("Cannnot open '%s': %s\n", name, strerror (errno)); + return -1; + } + + dwarf = dwarf_begin (fd, DWARF_C_READ); + if (dwarf == NULL) + { + printf ("Not a Dwarf file '%s': %s\n", name, dwarf_errmsg (-1)); + close (fd); + return -1; + } + + printf ("checking %s\n", name); + int res = check_dbg (dwarf); + + dwarf_end (dwarf); + close (fd); + + return res; +} diff --git a/tests/dwarfcfi.c b/tests/dwarfcfi.c new file mode 100644 index 00000000..db4a36ff --- /dev/null +++ b/tests/dwarfcfi.c @@ -0,0 +1,175 @@ +/* Test program for DWARF (.debug_frame) CFI handling. + Copyright (C) 2009-2010, 2013, 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 <assert.h> +#include <inttypes.h> +#include <error.h> +#include ELFUTILS_HEADER(dw) +#include <dwarf.h> +#include <argp.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <locale.h> +#include <stdlib.h> +#include <string.h> + +#include "../libdw/known-dwarf.h" + +static const char * +op_name (unsigned int code) +{ + static const char *const known[] = + { +#define DWARF_ONE_KNOWN_DW_OP(NAME, CODE) [CODE] = #NAME, + DWARF_ALL_KNOWN_DW_OP +#undef DWARF_ONE_KNOWN_DW_OP + }; + + if (likely (code < sizeof (known) / sizeof (known[0]))) + return known[code]; + + return NULL; +} + +static void +print_detail (int result, const Dwarf_Op *ops, size_t nops) +{ + if (result < 0) + printf ("indeterminate (%s)\n", dwarf_errmsg (-1)); + else if (nops == 0) + printf ("%s\n", ops == NULL ? "same_value" : "undefined"); + else + { + printf ("%s expression:", result == 0 ? "location" : "value"); + for (size_t i = 0; i < nops; ++i) + { + printf (" %s", op_name(ops[i].atom)); + if (ops[i].number2 == 0) + { + if (ops[i].atom == DW_OP_addr) + printf ("(%#" PRIx64 ")", ops[i].number); + else if (ops[i].number != 0) + printf ("(%" PRId64 ")", ops[i].number); + } + else + printf ("(%" PRId64 ",%" PRId64 ")", + ops[i].number, ops[i].number2); + } + puts (""); + } +} + +static int +handle_address (Dwarf_CFI *cfi, GElf_Addr pc) +{ + Dwarf_Frame *frame; + int result = dwarf_cfi_addrframe (cfi, pc, &frame); + if (result != 0) + { + printf ("dwarf_cfi_addrframe: %s\n", dwarf_errmsg (-1)); + return 1; + } + + Dwarf_Addr start = pc; + Dwarf_Addr end = pc; + bool signalp; + int ra_regno = dwarf_frame_info (frame, &start, &end, &signalp); + + printf ("%#" PRIx64 " => [%#" PRIx64 ", %#" PRIx64 "):\n", + pc, start, end); + + if (ra_regno < 0) + printf ("\treturn address register unavailable (%s)\n", + dwarf_errmsg (-1)); + else + printf ("\treturn address in reg%u%s\n", + ra_regno, signalp ? " (signal frame)" : ""); + + // Point cfa_ops to dummy to match print_detail expectations. + // (nops == 0 && cfa_ops != NULL => "undefined") + Dwarf_Op dummy; + Dwarf_Op *cfa_ops = &dummy; + size_t cfa_nops; + result = dwarf_frame_cfa (frame, &cfa_ops, &cfa_nops); + + printf ("\tCFA "); + print_detail (result, cfa_ops, cfa_nops); + + // Print the location of the first 10 (DWARF nr) registers + for (int r = 0; r < 10; r++) + { + Dwarf_Op ops_mem[3]; + Dwarf_Op *ops; + size_t nops; + printf ("\treg%d: ", r); + int reg_result = dwarf_frame_register (frame, r, ops_mem, &ops, &nops); + print_detail (reg_result, ops, nops); + result |= reg_result; + } + + free (frame); + return result; +} + +int +main (int argc, char *argv[]) +{ + if (argc <= 2) + error (EXIT_FAILURE, 0, "need file name argument and addresses"); + + int fd = open (argv[1], O_RDONLY); + if (fd == -1) + error (EXIT_FAILURE, errno, "cannot open input file `%s'", argv[1]); + + elf_version (EV_CURRENT); + + Elf *elf = elf_begin (fd, ELF_C_READ, NULL); + if (elf == NULL) + error (EXIT_FAILURE, 0, "cannot create ELF descriptor: %s", + elf_errmsg (-1)); + + Dwarf *dwarf = dwarf_begin_elf (elf, DWARF_C_READ, NULL); + if (dwarf == NULL) + error (EXIT_FAILURE, 0, "cannot create DWARF descriptor: %s", + dwarf_errmsg (-1)); + + Dwarf_CFI *cfi = dwarf_getcfi (dwarf); + if (cfi == NULL) + error (EXIT_FAILURE, 0, "cannot get DWARF CFI from .dwarf_frame: %s", + dwarf_errmsg (-1)); + + int result = 0; + int args = 2; + do + { + char *endp; + uintmax_t addr = strtoumax (argv[args], &endp, 0); + if (endp != argv[args]) + result |= handle_address (cfi, addr); + else + result = 1; + } + while (args++ < argc - 1); + + dwarf_end (dwarf); + elf_end (elf); + + return result; +} diff --git a/tests/elfstrmerge.c b/tests/elfstrmerge.c index 8d5b53cb..3bb90c42 100644 --- a/tests/elfstrmerge.c +++ b/tests/elfstrmerge.c @@ -195,7 +195,7 @@ main (int argc, char **argv) size_t symtabndx = 0; Elf_Scn *symtabscn = NULL; GElf_Shdr symtabshdr_mem; - GElf_Shdr *symtabshdr; + GElf_Shdr *symtabshdr = NULL; while ((symtabscn = elf_nextscn (elf, symtabscn)) != NULL) { symtabshdr = gelf_getshdr (symtabscn, &symtabshdr_mem); @@ -210,7 +210,7 @@ main (int argc, char **argv) } } - if (symtabndx == 0) + if (symtabshdr == NULL) fail ("No symtab found", fname); if ((symtabshdr->sh_flags & SHF_ALLOC) != 0) @@ -578,7 +578,8 @@ main (int argc, char **argv) break; case SHT_DYNAMIC: - /* Fallthrough. There are string indexes in here, but + FALLTHROUGH; + /* There are string indexes in here, but they (should) point to a allocated string table, which we don't alter. */ default: diff --git a/tests/get-units-invalid.c b/tests/get-units-invalid.c new file mode 100644 index 00000000..155e12db --- /dev/null +++ b/tests/get-units-invalid.c @@ -0,0 +1,121 @@ +/* Test cudie and subdie properties. + 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; + while (dwarf_get_units (dbg, cu, &cu, NULL, + &unit_type, &cudie, &subdie) == 0) + { + printf ("Got cudie: %s, unit_type: %" PRIx8 "\n", + dwarf_diename (&cudie), unit_type); + + int tag = dwarf_tag (&subdie); + if (unit_type == DW_UT_compile) + { + if (tag != DW_TAG_invalid) + { + printf ("Not invalid: %x\n", dwarf_tag (&subdie)); + return -1; + } + if (dwarf_diename (&subdie) != NULL) + { + printf ("Should have NULL name: %s\n", + dwarf_diename (&subdie)); + return -1; + } + Dwarf_Die result; + if (dwarf_siblingof (&subdie, &result) != -1) + { + printf ("Should NOT have a valid sibling: %s\n", + dwarf_diename (&result)); + return -1; + } + if (dwarf_child (&subdie, &result) != -1) + { + printf ("Should NOT have a valid child: %s\n", + dwarf_diename (&result)); + return -1; + } + Dwarf_Addr base, start, end; + if (dwarf_ranges (&subdie, 0, &base, &start, &end) != -1) + { + printf ("Should NOT have a ranges: %s\n", + dwarf_diename (&subdie)); + return -1; + } + if (dwarf_cuoffset (&subdie) != (Dwarf_Off) -1) + { + printf ("Should NOT have a cuoffset: %s\n", + dwarf_diename (&subdie)); + return -1; + } + if (dwarf_dieoffset (&subdie) != (Dwarf_Off) -1) + { + printf ("Should NOT have a die offset: %s\n", + dwarf_diename (&subdie)); + return -1; + } + if (dwarf_getabbrev (&subdie, 0, NULL) != NULL) + { + printf ("Should NOT have an abbrev: %s\n", + dwarf_diename (&subdie)); + return -1; + } + } + else if (unit_type == DW_UT_type) + printf ("subdie: %s\n", dwarf_diename (&subdie)); + else + printf ("subdie tag: %x\n", dwarf_tag (&subdie)); + } + + dwarf_end (dbg); + close (fd); + + printf ("\n"); + } + + return 0; +} diff --git a/tests/get-units-split.c b/tests/get-units-split.c new file mode 100644 index 00000000..410483a0 --- /dev/null +++ b/tests/get-units-split.c @@ -0,0 +1,101 @@ +/* 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; + int count = 0; + while (dwarf_get_units (dbg, cu, &cu, NULL, + &unit_type, &cudie, &subdie) == 0) + { + count++; + printf ("Got cudie unit_type: %" PRIx8 "\n", unit_type); + + if (unit_type == DW_UT_skeleton) + { + Dwarf_CU *skel_cu = cudie.cu; + Dwarf_CU *split_cu = subdie.cu; + Dwarf_Die skel_die, split_die; + uint64_t skel_id, split_id; + + printf ("Found a skeleton unit, with split die: %s\n", + dwarf_diename (&subdie)); + + if (dwarf_cu_die (skel_cu, &skel_die, NULL, NULL, NULL, NULL, + &skel_id, NULL) == NULL) + { + printf ("bad skel_cu: %s\n", dwarf_errmsg (-1)); + return -1; + } + + if (dwarf_cu_die (split_cu, &split_die, NULL, NULL, NULL, NULL, + &split_id, NULL) == NULL) + { + printf ("bad skel_cu: %s\n", dwarf_errmsg (-1)); + return -1; + } + + if (skel_id != split_id) + { + printf ("Skeleton id and Split id not equal!\n"); + return -1; + } + } + } + + if (count == 0) + { + printf ("No units found\n"); + return -1; + } + + dwarf_end (dbg); + close (fd); + + printf ("\n"); + } + + return 0; +} diff --git a/tests/hello_riscv64.ko.bz2 b/tests/hello_riscv64.ko.bz2 Binary files differnew file mode 100644 index 00000000..355a5122 --- /dev/null +++ b/tests/hello_riscv64.ko.bz2 diff --git a/tests/low_high_pc.c b/tests/low_high_pc.c index d0f43023..5c6b343c 100644 --- a/tests/low_high_pc.c +++ b/tests/low_high_pc.c @@ -1,5 +1,5 @@ /* Test program for dwarf_lowpc and dwarf_highpc - Copyright (C) 2012 Red Hat, Inc. + Copyright (C) 2012, 2018 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -55,7 +55,9 @@ handle_die (Dwarf_Die *die, void *arg) const char *name = dwarf_diename (die); if (name == NULL) - fail (off, "<no name>", "die without a name"); + name = "<no name>"; + + printf ("[%" PRIx64 "] %s\n", off, name); Dwarf_Addr lowpc = 0; Dwarf_Addr highpc = 0; @@ -101,9 +103,31 @@ main (int argc, char *argv[]) a.file = dwarf_diename (a.cu); handle_die (a.cu, &a); dwarf_getfuncs (a.cu, &handle_die, &a, 0); + + uint8_t unit_type; + Dwarf_Die subdie; + if (dwarf_cu_info (a.cu->cu, NULL, &unit_type, NULL, &subdie, + NULL, NULL, NULL) != 0) + { + Dwarf_Off off = dwarf_dieoffset (a.cu); + fail (off, "dwarf_cu_info", dwarf_errmsg (-1)); + } + + if (unit_type == DW_UT_skeleton) + { + const char *name = dwarf_diename (&subdie) ?: "<unknown>"; + printf ("Following split subdie: %s\n", name); + struct args b = a; + b.cu = &subdie; + handle_die (b.cu, &b); + dwarf_getfuncs (b.cu, &handle_die, &b, 0); + printf ("Done subdie: %s\n", name); + } } dwfl_end (a.dwfl); + printf ("\n"); + return result; } diff --git a/tests/md5-sha1-test.c b/tests/md5-sha1-test.c deleted file mode 100644 index d50355e9..00000000 --- a/tests/md5-sha1-test.c +++ /dev/null @@ -1,93 +0,0 @@ -/* Copyright (C) 2011 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 <string.h> -#include <error.h> - -#include "md5.h" -#include "sha1.h" - -static const struct expected -{ - const char *sample; - const char *md5_expected; - const char *sha1_expected; -} tests[] = - { - { - "abc", - "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f\x72", - "\xa9\x99\x3e\x36\x47\x06\x81\x6a\xba\x3e" - "\x25\x71\x78\x50\xc2\x6c\x9c\xd0\xd8\x9d" - }, - { - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "\x82\x15\xef\x07\x96\xa2\x0b\xca\xaa\xe1\x16\xd3\x87\x6c\x66\x4a", - "\x84\x98\x3e\x44\x1c\x3b\xd2\x6e\xba\xae" - "\x4a\xa1\xf9\x51\x29\xe5\xe5\x46\x70\xf1" - }, - { - "\0a", - "\x77\x07\xd6\xae\x4e\x02\x7c\x70\xee\xa2\xa9\x35\xc2\x29\x6f\x21", - "\x34\xaa\x97\x3c\xd4\xc4\xda\xa4\xf6\x1e" - "\xeb\x2b\xdb\xad\x27\x31\x65\x34\x01\x6f", - }, - { - "When in the Course of human events it becomes necessary", - "\x62\x6b\x5e\x22\xcd\x3d\x02\xea\x07\xde\xd4\x50\x62\x3d\xb9\x96", - "\x66\xc3\xc6\x8d\x62\x91\xc5\x1e\x63\x0c" - "\x85\xc8\x6c\xc4\x4b\x3a\x79\x3e\x07\x28", - }, - }; -#define NTESTS (sizeof tests / sizeof tests[0]) - -#define md5_size 16 -#define sha1_size 20 - -#define TEST_HASH(ALGO, I) \ - { \ - struct ALGO##_ctx ctx; \ - uint32_t result_buffer[(ALGO##_size + 3) / 4]; \ - ALGO##_init_ctx (&ctx); \ - if (tests[I].sample[0] == '\0') \ - { \ - char input_buffer[1000]; \ - memset (input_buffer, tests[I].sample[1], sizeof input_buffer); \ - for (int rept = 0; rept < 1000; ++rept) \ - ALGO##_process_bytes (input_buffer, sizeof input_buffer, &ctx); \ - } \ - else \ - ALGO##_process_bytes (tests[I].sample, strlen (tests[I].sample), &ctx); \ - char *result = ALGO##_finish_ctx (&ctx, result_buffer); \ - if (result != (void *) result_buffer \ - || memcmp (result, tests[I].ALGO##_expected, ALGO##_size) != 0) \ - error (0, 0, #ALGO " test %zu failed", 1 + I); \ - } - -int -main (void) -{ - for (size_t i = 0; i < NTESTS; ++i) - { - TEST_HASH (md5, i); - TEST_HASH (sha1, i); - } - return error_message_count; -} diff --git a/tests/msg_tst.c b/tests/msg_tst.c index 7baea0a2..aa974d00 100644 --- a/tests/msg_tst.c +++ b/tests/msg_tst.c @@ -39,6 +39,7 @@ static struct { ELF_E_INVALID_ENCODING, "invalid encoding" }, { ELF_E_NOMEM, "out of memory" }, { ELF_E_INVALID_FILE, "invalid file descriptor" }, + { ELF_E_INVALID_ELF, "invalid ELF file data" }, { ELF_E_INVALID_OP, "invalid operation" }, { ELF_E_NO_VERSION, "ELF version not set" }, { ELF_E_INVALID_CMD, "invalid command" }, diff --git a/tests/next-files.c b/tests/next-files.c new file mode 100644 index 00000000..9de5c8b0 --- /dev/null +++ b/tests/next-files.c @@ -0,0 +1,93 @@ +/* A variant of get-files test that uses dwarf_next_lines. + Copyright (C) 2002, 2004, 2005, 2007, 2014, 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 <fcntl.h> +#include <inttypes.h> +#include <libelf.h> +#include ELFUTILS_HEADER(dw) +#include <stdio.h> +#include <unistd.h> + + +int +main (int argc, char *argv[]) +{ + int result = 0; + int cnt; + + for (cnt = 1; cnt < argc; ++cnt) + { + int fd = open (argv[cnt], O_RDONLY); + + Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ); + if (dbg == NULL) + { + printf ("%s not usable\n", argv[cnt]); + result = 1; + if (fd != -1) + close (fd); + continue; + } + + Dwarf_Off off; + Dwarf_Off next_off = 0; + Dwarf_CU *cu = NULL; + Dwarf_Files *files; + size_t nfiles; + int res; + while ((res = dwarf_next_lines (dbg, off = next_off, &next_off, &cu, + &files, &nfiles, NULL, NULL)) == 0) + { + printf ("off = %" PRIu64 "\n", off); + + const char *const *dirs; + size_t ndirs; + if (dwarf_getsrcdirs (files, &dirs, &ndirs) != 0) + { + printf ("%s: cannot get include directories\n", argv[cnt]); + result = 1; + break; + } + + if (dirs[0] == NULL) + puts (" dirs[0] = (null)"); + else + printf (" dirs[0] = \"%s\"\n", dirs[0]); + for (size_t i = 1; i < ndirs; ++i) + printf (" dirs[%zu] = \"%s\"\n", i, dirs[i]); + + for (size_t i = 0; i < nfiles; ++i) + printf (" file[%zu] = \"%s\"\n", i, + dwarf_filesrc (files, i, NULL, NULL)); + } + + if (res < 0) + { + printf ("dwarf_next_lines failed: %s\n", dwarf_errmsg (-1)); + result = 1; + } + + dwarf_end (dbg); + close (fd); + } + + return result; +} diff --git a/tests/next-lines.c b/tests/next-lines.c new file mode 100644 index 00000000..cfb74cde --- /dev/null +++ b/tests/next-lines.c @@ -0,0 +1,144 @@ +/* A variant of get-lines that uses dwarf_next_lines. + Copyright (C) 2002, 2004, 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 <fcntl.h> +#include <inttypes.h> +#include <libelf.h> +#include ELFUTILS_HEADER(dw) +#include <stdio.h> +#include <string.h> +#include <unistd.h> + + +int +main (int argc, char *argv[]) +{ + int result = 0; + int cnt; + + for (cnt = 1; cnt < argc; ++cnt) + { + int fd = open (argv[cnt], O_RDONLY); + + Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ); + if (dbg == NULL) + { + printf ("%s not usable: %s\n", argv[cnt], dwarf_errmsg (-1)); + close (fd); + continue; + } + + Dwarf_Off off; + Dwarf_Off next_off = 0; + Dwarf_CU *cu = NULL; + Dwarf_Lines *lb; + size_t nlb; + int res; + while ((res = dwarf_next_lines (dbg, off = next_off, &next_off, &cu, + NULL, NULL, &lb, &nlb)) == 0) + { + printf ("off = %" PRIu64 "\n", off); + printf (" %zu lines\n", nlb); + + for (size_t i = 0; i < nlb; ++i) + { + Dwarf_Line *l = dwarf_onesrcline (lb, i); + if (l == NULL) + { + printf ("%s: cannot get individual line\n", argv[cnt]); + result = 1; + break; + } + + Dwarf_Addr addr; + if (dwarf_lineaddr (l, &addr) != 0) + addr = 0; + const char *file = dwarf_linesrc (l, NULL, NULL); + int line; + if (dwarf_lineno (l, &line) != 0) + line = 0; + + printf ("%" PRIx64 ": %s:%d:", (uint64_t) addr, + file ?: "???", line); + + /* Getting the file path through the Dwarf_Files should + result in the same path. */ + Dwarf_Files *files; + size_t idx; + if (dwarf_line_file (l, &files, &idx) != 0) + { + printf ("%s: cannot get file from line (%zd): %s\n", + argv[cnt], i, dwarf_errmsg (-1)); + result = 1; + break; + } + const char *path = dwarf_filesrc (files, idx, NULL, NULL); + if ((path == NULL && file != NULL) + || (path != NULL && file == NULL) + || (strcmp (file, path) != 0)) + { + printf ("%s: line %zd srcline (%s) != file srcline (%s)\n", + argv[cnt], i, file ?: "???", path ?: "???"); + result = 1; + break; + } + + int column; + if (dwarf_linecol (l, &column) != 0) + column = 0; + if (column >= 0) + printf ("%d:", column); + + bool is_stmt; + if (dwarf_linebeginstatement (l, &is_stmt) != 0) + is_stmt = false; + bool end_sequence; + if (dwarf_lineendsequence (l, &end_sequence) != 0) + end_sequence = false; + bool basic_block; + if (dwarf_lineblock (l, &basic_block) != 0) + basic_block = false; + bool prologue_end; + if (dwarf_lineprologueend (l, &prologue_end) != 0) + prologue_end = false; + bool epilogue_begin; + if (dwarf_lineepiloguebegin (l, &epilogue_begin) != 0) + epilogue_begin = false; + + printf (" is_stmt:%s, end_seq:%s, bb:%s, prologue:%s, epilogue:%s\n", + is_stmt ? "yes" : "no", end_sequence ? "yes" : "no", + basic_block ? "yes" : "no", prologue_end ? "yes" : "no", + epilogue_begin ? "yes" : "no"); + } + } + + if (res < 0) + { + printf ("dwarf_next_lines failed: %s\n", dwarf_errmsg (-1)); + result = 1; + } + + dwarf_end (dbg); + close (fd); + } + + return result; +} diff --git a/tests/next_cfi.c b/tests/next_cfi.c new file mode 100644 index 00000000..b923744f --- /dev/null +++ b/tests/next_cfi.c @@ -0,0 +1,131 @@ +/* Test program for dwarf_next_cfi + 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/>. */ + +#include <config.h> +#include <assert.h> +#include <inttypes.h> +#include <error.h> +#include ELFUTILS_HEADER(dw) +#include <dwarf.h> +#include <argp.h> +#include <stdbool.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <locale.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +void +handle_section (const unsigned char e_ident[], + Elf_Scn *scn, const bool is_eh) +{ + if (is_eh) + printf (".eh_frame\n"); + else + printf (".debug_frame\n"); + + Elf_Data *data = elf_getdata (scn, NULL); + if (data == NULL || data->d_buf == NULL) + error (EXIT_FAILURE, 0, "no section data"); + + int res; + Dwarf_Off off; + Dwarf_Off next_off = 0; + Dwarf_CFI_Entry entry; + while ((res = dwarf_next_cfi (e_ident, data, is_eh, off = next_off, + &next_off, &entry)) == 0) + { + printf ("[%" PRId64 "] ", off); + if (dwarf_cfi_cie_p (&entry)) + printf ("CIE augmentation=\"%s\"\n", entry.cie.augmentation); + else + { + printf ("FDE cie=[%" PRId64 "]\n", entry.fde.CIE_pointer); + + Dwarf_Off cie_off = entry.fde.CIE_pointer; + Dwarf_Off cie_off_next; + Dwarf_CFI_Entry cie_entry; + if (dwarf_next_cfi (e_ident, data, is_eh, cie_off, &cie_off_next, + &cie_entry) != 0 + || !dwarf_cfi_cie_p (&cie_entry)) + error (EXIT_FAILURE, 0, "FDE doesn't point to CIE"); + } + } + + if (res < 0) + error (EXIT_FAILURE, 0, "dwarf_next_cfi failed: %s\n", + dwarf_errmsg (-1)); +} + +int +main (int argc, char *argv[]) +{ + if (argc != 2) + error (EXIT_FAILURE, 0, "need file name argument"); + + const char *file = argv[1]; + printf ("%s\n", file); + + int fd = open (file, O_RDONLY); + if (fd == -1) + error (EXIT_FAILURE, errno, "cannot open input file `%s'", file); + + elf_version (EV_CURRENT); + + Elf *elf = elf_begin (fd, ELF_C_READ, NULL); + if (elf == NULL) + error (EXIT_FAILURE, 0, "cannot create ELF descriptor: %s", + elf_errmsg (-1)); + + size_t esize; + const unsigned char *ident = (const unsigned char *) elf_getident (elf, + &esize); + if (ident == NULL || esize < EI_NIDENT) + error (EXIT_FAILURE, 0, "no, or too small, ELF ident"); + + GElf_Ehdr ehdr; + if (gelf_getehdr (elf, &ehdr) == NULL) + error (EXIT_FAILURE, 0, "cannot get the ELF header: %s\n", + elf_errmsg (-1)); + + size_t strndx = ehdr.e_shstrndx; + + Elf_Scn *scn = NULL; + while ((scn = elf_nextscn (elf, scn)) != NULL) + { + GElf_Shdr shdr; + if (gelf_getshdr (scn, &shdr) != NULL) + { + char *name = elf_strptr (elf, strndx, (size_t) shdr.sh_name); + if (name != NULL && shdr.sh_type == SHT_PROGBITS) + { + if (strcmp (name, ".eh_frame") == 0) + handle_section (ident, scn, true); + if (strcmp (name, ".debug_frame") == 0) + handle_section (ident, scn, false); + } + } + } + + elf_end (elf); + close (fd); + + return 0; +} diff --git a/tests/run-addrcfi.sh b/tests/run-addrcfi.sh index 7fc46e58..76db7d2d 100755 --- a/tests/run-addrcfi.sh +++ b/tests/run-addrcfi.sh @@ -3561,7 +3561,7 @@ dwarf_cfi_addrframe (.eh_frame): no matching address range integer reg28 (x28): same_value integer reg29 (x29): same_value integer reg30 (x30): same_value - integer reg31 (sp): undefined + integer reg31 (sp): location expression: call_frame_cfa stack_value integer reg33 (elr): undefined FP/SIMD reg64 (v0): undefined FP/SIMD reg65 (v1): undefined diff --git a/tests/run-aggregate-size.sh b/tests/run-aggregate-size.sh index 42b0742b..08d57bbf 100755 --- a/tests/run-aggregate-size.sh +++ b/tests/run-aggregate-size.sh @@ -54,6 +54,7 @@ # volatile int ia[32]; # const volatile void * const volatile restrict va[64]; # struct s sa[8]; +# double d3d[3][4][5]; # # typedef const int foo; # typedef volatile foo bar; @@ -62,7 +63,9 @@ # # gcc -std=c99 -g -c -o testfile-sizes3.o sizes.c -testfiles testfile-sizes1.o testfile-sizes2.o testfile-sizes3.o +# The file testfile-size4.o is hand-crafted. + +testfiles testfile-sizes1.o testfile-sizes2.o testfile-sizes3.o testfile-sizes4.o testrun_compare ${abs_builddir}/aggregate_size -e testfile-sizes1.o <<\EOF c size 1 @@ -98,8 +101,13 @@ ca size 16 ia size 128 va size 512 sa size 128 +d3d size 480 f size 4 b size 4 EOF +testrun_compare ${abs_builddir}/aggregate_size -e testfile-sizes4.o <<\EOF +v size 257 +EOF + exit 0 diff --git a/tests/run-all-dwarf-ranges.sh b/tests/run-all-dwarf-ranges.sh new file mode 100755 index 00000000..cefb4231 --- /dev/null +++ b/tests/run-all-dwarf-ranges.sh @@ -0,0 +1,129 @@ +#! /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: no_say (2e) + 4004f0..4004ff + +die: main (2e) + 4003e0..4003f7 + +die: subject (1d) + 4003e3..4003ef + +die: subject (2e) + 4004e0..4004f0 + +die: world.c (11) + 400500..400567 + +die: no_main (2e) + 400550..400567 + +die: no_subject (1d) + 400553..40055f + +die: say (2e) + 400500..400540 + +die: happy (1d) + 40051c..400526 + 400530..400534 + 400535..40053f + +die: sad (1d) + 40051c..400526 + 400535..40053f + +die: no_subject (2e) + 400540..400550 + +EOF + +# Same with -gdwarf-5 +# gcc -c -O2 -o testfile-ranges-hello5.o -gsplit-dwarf -gdwarf-5 hello.c +# gcc -c -O2 -o testfile-ranges-world5.o -gsplit-dwarf -gdwarf-5 world.c +# gcc -o testfilesplitranges5 -O2 testfile-ranges-hello5.o testfile-ranges-world5.o +# eu-strip -f testfilesplitranges5.debug testfilesplitranges5 + +testfiles testfilesplitranges5.debug +testfiles testfile-ranges-hello5.dwo testfile-ranges-world5.dwo + +testrun_compare ${abs_builddir}/all-dwarf-ranges testfilesplitranges5.debug <<\EOF +die: hello.c (11) + 401150..40117a + 401050..401067 + +die: no_say (2e) + 401160..40117a + +die: main (2e) + 401050..401067 + +die: subject (1d) + 401053..40105f + +die: subject (2e) + 401150..401160 + +die: world.c (11) + 401180..4011e7 + +die: no_main (2e) + 4011d0..4011e7 + +die: no_subject (1d) + 4011d3..4011df + +die: say (2e) + 401180..4011c0 + +die: happy (1d) + 40119b..40119b + 40119c..4011a6 + 4011b0..4011b4 + 4011b5..4011bf + +die: sad (1d) + 40119b..40119b + 40119c..4011a6 + 4011b4..4011b4 + 4011b5..4011bf + +die: no_subject (2e) + 4011c0..4011d0 + +EOF + +exit 0 diff --git a/tests/run-allfcts-multi.sh b/tests/run-allfcts-multi.sh index 727b76ee..ef7bb30e 100755 --- a/tests/run-allfcts-multi.sh +++ b/tests/run-allfcts-multi.sh @@ -53,4 +53,20 @@ testrun_compare cat allfcts.out <<\EOF /tmp/test-offset-loop.c:7:main EOF +# allfcts has a too simple mechanism for setting the alt file. +# check that if we don't set it, things still work (because libdw will +# find the alt file for us). +mkdir subdir +mv test-offset-loop test-offset-loop.alt subdir/ +testrun ${abs_builddir}/allfcts subdir/test-offset-loop > allfcts.out +testrun_compare cat allfcts.out <<\EOF +Warning: no alt file found. +/tmp/test-offset-loop.c:6:get_errno +/tmp/test-offset-loop.c:5:is_error +/tmp/test-offset-loop.c:4:padding +/tmp/test-offset-loop.c:7:main +EOF + +rm -rf subdir + exit 0 diff --git a/tests/run-ar.sh b/tests/run-ar.sh new file mode 100755 index 00000000..fb9394d5 --- /dev/null +++ b/tests/run-ar.sh @@ -0,0 +1,40 @@ +#! /bin/bash +# Copyright (C) 2017 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 + +tempfiles objects.list test.ar + +echo Make a sorted list of the just build src .o files. +(cd ${abs_top_builddir}/src; ls *.o | sort) > objects.list +cat objects.list + +echo Create a new ar file with the .o files. +testrun ${abs_top_builddir}/src/ar -r test.ar \ + $(echo ${abs_top_builddir}/src/*.o | sort) + +echo List the ar file contents. +testrun_compare ${abs_top_builddir}/src/ar -t test.ar < objects.list + +echo Delete all objects again. +testrun ${abs_top_builddir}/src/ar -d test.ar $(cat objects.list) + +echo Check new ar file is now empty +testrun_compare ${abs_top_builddir}/src/ar -t test.ar << EOF +EOF + +exit 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 diff --git a/tests/run-dwarf-die-addr-die.sh b/tests/run-dwarf-die-addr-die.sh new file mode 100755 index 00000000..951d1c52 --- /dev/null +++ b/tests/run-dwarf-die-addr-die.sh @@ -0,0 +1,52 @@ +#! /bin/sh +# Copyright (C) 2012, 2015 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-typeiter.sh +testfiles testfile-debug-types + +testrun ${abs_builddir}/dwarf-die-addr-die testfile-debug-types + +# see run-readelf-dwz-multi.sh +testfiles testfile_multi_main testfile_multi.dwz + +testrun ${abs_builddir}/dwarf-die-addr-die testfile_multi_main + +# see tests/run-dwflsyms.sh +testfiles testfilebazdbgppc64.debug + +testrun ${abs_builddir}/dwarf-die-addr-die testfilebazdbgppc64.debug + +# see tests/testfile-dwarf-45.source +testfiles testfile-dwarf-4 testfile-dwarf-5 +testfiles testfile-splitdwarf-4 testfile-hello4.dwo testfile-world4.dwo +testfiles testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo + +testrun ${abs_builddir}/dwarf-die-addr-die testfile-dwarf-4 +testrun ${abs_builddir}/dwarf-die-addr-die testfile-dwarf-5 +testrun ${abs_builddir}/dwarf-die-addr-die testfile-splitdwarf-4 +testrun ${abs_builddir}/dwarf-die-addr-die testfile-splitdwarf-5 +testrun ${abs_builddir}/dwarf-die-addr-die testfile-hello4.dwo +testrun ${abs_builddir}/dwarf-die-addr-die testfile-world4.dwo +testrun ${abs_builddir}/dwarf-die-addr-die testfile-hello5.dwo +testrun ${abs_builddir}/dwarf-die-addr-die testfile-world5.dwo + +# Self test +testrun_on_self ${abs_builddir}/dwarf-die-addr-die + +exit 0 diff --git a/tests/run-dwarf-ranges.sh b/tests/run-dwarf-ranges.sh index d202ed3f..ae25d6ef 100755 --- a/tests/run-dwarf-ranges.sh +++ b/tests/run-dwarf-ranges.sh @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2015 Red Hat, Inc. +# 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 @@ -24,4 +24,103 @@ testrun_compare ${abs_builddir}/dwarf-ranges debug-ranges-no-lowpc.o 0xb <<\EOF 3..4 (base 0) EOF +# - hello.c +# int say (const char *prefix); +# +# char * +# subject (char *word, int count) +# { +# return count > 0 ? word : (word + count); +# } +# +# int +# main (int argc, char **argv) +# { +# return say (subject (argv[0], argc)); +# } +# +# int +# no_say (const char *prefix) +# { +# const char *world = subject ("World", 42); +# return prefix ? say (prefix) : say (world); +# } +# +# - world.c +# char * subject (char *word, int count); +# int no_say (const char *prefix); +# +# static int +# sad (char c) +# { +# return c > 0 ? c : c + 1; +# } +# +# static int +# happy (const char *w) +# { +# return sad (w[1]); +# } +# +# int +# say (const char *prefix) +# { +# const char *world = subject ("World", 42);; +# return prefix ? sad (prefix[0]) : happy (world); +# } +# +# char * +# no_subject (char *word, int count) +# { +# return count > 0 ? word : (word + count); +# } +# +# int +# no_main (int argc, char **argv) +# { +# return no_say (no_subject (argv[0], argc)); +# } +# +# - gcc -c -O2 -gdwarf-4 hello.c +# - gcc -c -O2 -gdwarf-4 world.c +# - gcc -o testfileranges4 -O2 -gdwarf-4 hello.o world.o +# - eu-strip -f testfileranges4.debug testfileranges4 + +testfiles testfileranges4.debug +testrun_compare ${abs_builddir}/dwarf-ranges testfileranges4.debug 0xb <<\EOF +400500..40053a (base 0) +400400..400415 (base 0) +EOF + +testrun_compare ${abs_builddir}/dwarf-ranges testfileranges4.debug 0xcd <<\EOF +400400..400402 (base 0) +400405..40040d (base 0) +EOF + +testrun_compare ${abs_builddir}/dwarf-ranges testfileranges4.debug 0x374 <<\EOF +4005a0..4005a2 (base 400540) +4005a5..4005ad (base 400540) +EOF + +# Like above, but with -gdwarf-5. +testfiles testfileranges5.debug +testrun_compare ${abs_builddir}/dwarf-ranges testfileranges5.debug 0xc <<\EOF +401150..40117a (base 0) +401050..401067 (base 0) +EOF + +testrun_compare ${abs_builddir}/dwarf-ranges testfileranges5.debug 0x2ce <<\EOF +40119b..40119b (base 401180) +40119c..4011a6 (base 401180) +4011b0..4011b4 (base 401180) +4011b5..4011bf (base 401180) +EOF + +testrun_compare ${abs_builddir}/dwarf-ranges testfileranges5.debug 0x2ef <<\EOF +40119b..40119b (base 401180) +40119c..4011a6 (base 401180) +4011b4..4011b4 (base 401180) +4011b5..4011bf (base 401180) +EOF + exit 0 diff --git a/tests/run-dwarfcfi.sh b/tests/run-dwarfcfi.sh new file mode 100755 index 00000000..87691ae5 --- /dev/null +++ b/tests/run-dwarfcfi.sh @@ -0,0 +1,116 @@ +#! /bin/sh +# Test for dwarf_getcfi. +# 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 + +# Test files come from run-addrcfi with all sections stripped except +# the .debug_frame. +# for i in <testfiles> +# eu-strip -f $i-debugframe $i +# eu-strip -g --remove-comment --keep-section=.debug_frame $i-debugframe +# done +testfiles testfile11-debugframe testfile12-debugframe +testfiles testfileaarch64-debugframe +testfiles testfilearm-debugframe +testfiles testfileppc32-debugframe +testfiles testfileppc64-debugframe + +testfiles testfile11-debugframe +testrun_compare ${abs_builddir}/dwarfcfi testfile11-debugframe 0x080489b8 <<\EOF +0x80489b8 => [0x80489b8, 0x80489b9): + return address in reg8 + CFA location expression: bregx(4,4) + reg0: undefined + reg1: undefined + reg2: undefined + reg3: same_value + reg4: location expression: call_frame_cfa stack_value + reg5: same_value + reg6: same_value + reg7: same_value + reg8: location expression: call_frame_cfa plus_uconst(-4) + reg9: undefined +EOF + +testfiles testfile12-debugframe +testrun_compare ${abs_builddir}/dwarfcfi testfile12-debugframe 0x00000000000009d0 <<\EOF +0x9d0 => [0x9d0, 0x9d1): + return address in reg16 + CFA location expression: bregx(7,8) + reg0: same_value + reg1: undefined + reg2: undefined + reg3: undefined + reg4: undefined + reg5: undefined + reg6: same_value + reg7: location expression: call_frame_cfa stack_value + reg8: undefined + reg9: undefined +EOF + +testfiles testfileppc32-debugframe +testrun_compare ${abs_builddir}/dwarfcfi testfileppc32-debugframe 0x100004c0 <<\EOF +0x100004c0 => [0x100004c0, 0x100004d0): + return address in reg65 + CFA location expression: bregx(1) + reg0: undefined + reg1: location expression: call_frame_cfa stack_value + reg2: same_value + reg3: undefined + reg4: undefined + reg5: undefined + reg6: undefined + reg7: undefined + reg8: undefined + reg9: undefined +EOF + +testfiles testfileppc64-debugframe +testrun_compare ${abs_builddir}/dwarfcfi testfileppc64-debugframe 0x00000000100005b0 <<\EOF +0x100005b0 => [0x100005b0, 0x100005d0): + return address in reg65 + CFA location expression: bregx(1) + reg0: undefined + reg1: location expression: call_frame_cfa stack_value + reg2: same_value + reg3: undefined + reg4: undefined + reg5: undefined + reg6: undefined + reg7: undefined + reg8: undefined + reg9: undefined +EOF + +testfiles testfileaarch64-debugframe +testrun_compare ${abs_builddir}/dwarfcfi testfileaarch64-debugframe 0x400550 <<\EOF +0x400550 => [0x400550, 0x400568): + return address in reg30 + CFA location expression: bregx(31) + reg0: undefined + reg1: undefined + reg2: undefined + reg3: undefined + reg4: undefined + reg5: undefined + reg6: undefined + reg7: undefined + reg8: undefined + reg9: undefined +EOF diff --git a/tests/run-exprlocs-self.sh b/tests/run-exprlocs-self.sh new file mode 100755 index 00000000..73d3ab9f --- /dev/null +++ b/tests/run-exprlocs-self.sh @@ -0,0 +1,22 @@ +#! /bin/sh +# Copyright (C) 2017 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 + +# Just makes sure exprlocs doesn't crash, triggers self-check/asserts +# or leaks memory under valgrind. +testrun_on_self_quiet ${abs_top_builddir}/tests/varlocs --exprlocs -e diff --git a/tests/run-exprlocs.sh b/tests/run-exprlocs.sh new file mode 100755 index 00000000..379ca52b --- /dev/null +++ b/tests/run-exprlocs.sh @@ -0,0 +1,180 @@ +#! /bin/sh +# Copyright (C) 2017 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 + +# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77589 +# +# program repro +# type small_stride +# character*40 long_string +# integer small_pad +# end type small_stride +# type(small_stride), dimension (20), target :: unpleasant +# character*40, pointer, dimension(:):: c40pt +# integer i +# do i = 0,19 +# unpleasant(i+1)%small_pad = i+1 +# unpleasant(i+1)%long_string = char (ichar('0') + i) // '-hello' +# end do +# c40pt => unpleasant%long_string +# print *, c40pt ! break-here +# end program repro +# +# Needs GCC7+ +# gfortran -o testfile-stridex dwarf-stridex.f90 -Wall -g + +testfiles testfile-stridex + +testrun_compare ${abs_top_builddir}/tests/varlocs --exprlocs -e testfile-stridex <<\EOF +module 'testfile-stridex' +[b] CU 'dwarf-stridex.f90'@400717 + producer (strp) + language (data1) + identifier_case (data1) + name (strp) + comp_dir (strp) + low_pc (addr) + high_pc (data8) + stmt_list (sec_offset) + [2e] base_type "integer(kind=8)" + byte_size (data1) + encoding (data1) + name (strp) + [35] structure_type "small_stride" + name (strp) + byte_size (data1) + decl_file (data1) + decl_line (data1) + sibling (ref4) + [41] member "long_string" + name (strp) + decl_file (data1) + decl_line (data1) + type (ref4) + data_member_location (data1) {plus_uconst(0)} + [4d] member "small_pad" + name (strp) + decl_file (data1) + decl_line (data1) + type (ref4) + data_member_location (data1) {plus_uconst(40)} + [5a] string_type + byte_size (data1) + [5c] base_type "integer(kind=4)" + byte_size (data1) + encoding (data1) + name (strp) + [63] const_type + type (ref4) + [68] subprogram "main" + external (flag_present) + name (strp) + decl_file (data1) + decl_line (data1) + type (ref4) + low_pc (addr) + high_pc (data8) + frame_base (exprloc) {call_frame_cfa {bregx(7,8)}} + GNU_all_tail_call_sites (flag_present) + sibling (ref4) + [89] formal_parameter "argc" + name (strp) + decl_file (data1) + decl_line (data1) + type (ref4) + location (exprloc) {fbreg(-20)} + [97] formal_parameter "argv" + name (strp) + decl_file (data1) + decl_line (data1) + type (ref4) + location (exprloc) {fbreg(-32), deref} + [a7] pointer_type + byte_size (data1) + type (ref4) + [ad] base_type "character(kind=1)" + byte_size (data1) + encoding (data1) + name (strp) + [b4] subprogram "repro" + name (strp) + decl_file (data1) + decl_line (data1) + main_subprogram (flag_present) + calling_convention (data1) + low_pc (addr) + high_pc (data8) + frame_base (exprloc) {call_frame_cfa {bregx(7,8)}} + GNU_all_tail_call_sites (flag_present) + sibling (ref4) + [d2] variable "c40pt" + name (strp) + decl_file (data1) + decl_line (data1) + type (ref4) + location (exprloc) {fbreg(-128)} + [e1] variable "span.0" + name (strp) + type (ref4) + artificial (flag_present) + location (exprloc) {fbreg(-80)} + [ee] variable "i" + name (string) + decl_file (data1) + decl_line (data1) + type (ref4) + location (exprloc) {fbreg(-68)} + [fb] variable "unpleasant" + name (strp) + decl_file (data1) + decl_line (data1) + type (ref4) + location (exprloc) {fbreg(-1008)} + [10a] lexical_block + low_pc (addr) + high_pc (data8) + sibling (ref4) + [11f] lexical_block + low_pc (addr) + high_pc (data8) + [131] lexical_block + low_pc (addr) + high_pc (data8) + [142] lexical_block + low_pc (addr) + high_pc (data8) + [153] lexical_block + low_pc (addr) + high_pc (data8) + [167] array_type + data_location (exprloc) {push_object_address, deref} + associated (exprloc) {push_object_address, deref, lit0, ne} + type (ref4) + sibling (ref4) + [178] subrange_type + lower_bound (exprloc) {push_object_address, plus_uconst(32), deref} + upper_bound (exprloc) {push_object_address, plus_uconst(40), deref} + byte_stride (exprloc) {push_object_address, plus_uconst(24), deref, GNU_variable_value([e1]) {fbreg(-80)}, mul} + [18f] array_type + type (ref4) + [194] subrange_type + type (ref4) + upper_bound (sdata) +EOF + +exit 0 diff --git a/tests/run-get-files.sh b/tests/run-get-files.sh index a2f2373b..6f90be7d 100755 --- a/tests/run-get-files.sh +++ b/tests/run-get-files.sh @@ -64,4 +64,70 @@ cuhl = 11, o = 267, asz = 4, osz = 4, ncu = 2680 file[1] = "/shoggoth/drepper/m.c" EOF +# 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}/get-files testfile-splitdwarf-4 testfile-hello4.dwo testfile-world4.dwo <<\EOF +cuhl = 11, o = 0, asz = 8, osz = 4, ncu = 52 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include" + file[0] = "???" + file[1] = "/home/mark/src/elfutils/tests/hello.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include/stddef.h" +cuhl = 11, o = 26, asz = 8, osz = 4, ncu = 104 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/usr/include" + file[0] = "???" + file[1] = "/home/mark/src/elfutils/tests/world.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/usr/include/stdlib.h" +cuhl = 11, o = 0, asz = 8, osz = 4, ncu = 414 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include" + file[0] = "???" + file[1] = "/home/mark/src/elfutils/tests/hello.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include/stddef.h" +cuhl = 11, o = 0, asz = 8, osz = 4, ncu = 331 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/usr/include" + file[0] = "???" + file[1] = "/home/mark/src/elfutils/tests/world.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/usr/include/stdlib.h" +EOF + +testrun_compare ${abs_builddir}/get-files testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo <<\EOF +cuhl = 20, o = 0, asz = 8, osz = 4, ncu = 53 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include" + file[0] = "/home/mark/src/elfutils/tests/hello.c" + file[1] = "/home/mark/src/elfutils/tests/hello.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include/stddef.h" +cuhl = 20, o = 21, asz = 8, osz = 4, ncu = 106 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/usr/include" + file[0] = "/home/mark/src/elfutils/tests/world.c" + file[1] = "/home/mark/src/elfutils/tests/world.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/usr/include/stdlib.h" +cuhl = 20, o = 0, asz = 8, osz = 4, ncu = 386 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include" + file[0] = "/home/mark/src/elfutils/tests/hello.c" + file[1] = "/home/mark/src/elfutils/tests/hello.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include/stddef.h" +cuhl = 20, o = 0, asz = 8, osz = 4, ncu = 296 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/usr/include" + file[0] = "/home/mark/src/elfutils/tests/world.c" + file[1] = "/home/mark/src/elfutils/tests/world.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/usr/include/stdlib.h" +EOF + exit 0 diff --git a/tests/run-get-units-invalid.sh b/tests/run-get-units-invalid.sh new file mode 100755 index 00000000..66ef9444 --- /dev/null +++ b/tests/run-get-units-invalid.sh @@ -0,0 +1,44 @@ +#! /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-typeiter.sh +testfiles testfile-debug-types + +testrun ${abs_builddir}/get-units-invalid testfile-debug-types + +# see run-readelf-dwz-multi.sh +testfiles testfile_multi_main testfile_multi.dwz + +testrun ${abs_builddir}/get-units-invalid testfile_multi_main + +# see tests/run-dwflsyms.sh +testfiles testfilebazdbgppc64.debug + +testrun ${abs_builddir}/get-units-invalid testfilebazdbgppc64.debug + +# see tests/testfile-dwarf-45.source +testfiles testfile-dwarf-4 testfile-dwarf-5 + +testrun ${abs_builddir}/get-units-invalid testfile-dwarf-4 +testrun ${abs_builddir}/get-units-invalid testfile-dwarf-5 + +# Self test +testrun_on_self ${abs_builddir}/get-units-invalid + +exit 0 diff --git a/tests/run-get-units-split.sh b/tests/run-get-units-split.sh new file mode 100755 index 00000000..7a43c670 --- /dev/null +++ b/tests/run-get-units-split.sh @@ -0,0 +1,66 @@ +#! /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-typeiter.sh +testfiles testfile-debug-types + +testrun ${abs_builddir}/get-units-split testfile-debug-types + +# see run-readelf-dwz-multi.sh +testfiles testfile_multi_main testfile_multi.dwz + +testrun ${abs_builddir}/get-units-split testfile_multi_main + +# see tests/run-dwflsyms.sh +testfiles testfilebazdbgppc64.debug + +testrun ${abs_builddir}/get-units-split testfilebazdbgppc64.debug + +# see tests/testfile-dwarf-45.source +testfiles testfile-dwarf-4 testfile-dwarf-5 +testfiles testfile-splitdwarf-4 testfile-hello4.dwo testfile-world4.dwo +testfiles testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo + +testrun ${abs_builddir}/get-units-split testfile-dwarf-4 +testrun ${abs_builddir}/get-units-split testfile-dwarf-5 + +# These two files are the only ones that actually have skeleton units. +testrun_compare ${abs_builddir}/get-units-split testfile-splitdwarf-4 << \EOF +file: testfile-splitdwarf-4 +Got cudie unit_type: 4 +Found a skeleton unit, with split die: hello.c +Got cudie unit_type: 4 +Found a skeleton unit, with split die: world.c + +EOF + +testrun_compare ${abs_builddir}/get-units-split testfile-splitdwarf-5 << \EOF +file: testfile-splitdwarf-5 +Got cudie unit_type: 4 +Found a skeleton unit, with split die: hello.c +Got cudie unit_type: 4 +Found a skeleton unit, with split die: world.c + +EOF + +# Self test (Not on obj files since those need relocation first). +testrun_on_self_exe ${abs_builddir}/get-units-split +testrun_on_self_lib ${abs_builddir}/get-units-split + +exit 0 diff --git a/tests/run-low_high_pc.sh b/tests/run-low_high_pc.sh index ab5f2c37..41ec4208 100755 --- a/tests/run-low_high_pc.sh +++ b/tests/run-low_high_pc.sh @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2005 Red Hat, Inc. +# Copyright (C) 2005, 2018 Red Hat, Inc. # This file is part of elfutils. # # This file is free software; you can redistribute it and/or modify @@ -27,8 +27,15 @@ testfiles testfile_low_high_pc testrun ${abs_builddir}/low_high_pc -e ./testfile_low_high_pc testrun ${abs_builddir}/low_high_pc -e ${abs_builddir}/low_high_pc -testrun ${abs_builddir}/low_high_pc -e ${abs_top_builddir}/src/strip -testrun ${abs_builddir}/low_high_pc -e ${abs_top_builddir}/src/strip.o -testrun ${abs_builddir}/low_high_pc -e ${abs_top_builddir}/libelf/libelf.so + +# see tests/testfile-dwarf-45.source +testfiles testfile-splitdwarf-4 testfile-splitdwarf-5 +testfiles testfile-hello4.dwo testfile-hello5.dwo +testfiles testfile-world4.dwo testfile-world5.dwo + +testrun ${abs_builddir}/low_high_pc -e testfile-splitdwarf-4 +testrun ${abs_builddir}/low_high_pc -e testfile-splitdwarf-5 + +testrun_on_self ${abs_builddir}/low_high_pc -e exit 0 diff --git a/tests/run-next-cfi-self.sh b/tests/run-next-cfi-self.sh new file mode 100755 index 00000000..2c42ea3f --- /dev/null +++ b/tests/run-next-cfi-self.sh @@ -0,0 +1,21 @@ +#! /bin/sh +# Copyright (C) 2012 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 + +# Sanity check toolchain/dwarf_next_cfi +testrun_on_self ${abs_builddir}/next_cfi diff --git a/tests/run-next-cfi.sh b/tests/run-next-cfi.sh new file mode 100755 index 00000000..23c0d7d1 --- /dev/null +++ b/tests/run-next-cfi.sh @@ -0,0 +1,108 @@ +#! /bin/sh +# Test for dwarf_next_cfi. +# 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 + +# Test files come from run-addrcfi +testfiles testfile11 testfile12 +testfiles testfilearm testfileaarch64 +testfiles testfileppc32 testfileppc64 + +testrun_compare ${abs_builddir}/next_cfi testfile11 <<\EOF +testfile11 +.eh_frame +[0] CIE augmentation="zPL" +[28] FDE cie=[0] +[64] FDE cie=[0] +[96] FDE cie=[0] +[128] FDE cie=[0] +.debug_frame +[0] CIE augmentation="" +[20] FDE cie=[0] +[52] FDE cie=[0] +[76] FDE cie=[0] +[100] FDE cie=[0] +[124] FDE cie=[0] +[148] FDE cie=[0] +[172] FDE cie=[0] +[196] FDE cie=[0] +EOF + +testrun_compare ${abs_builddir}/next_cfi testfile12 <<\EOF +testfile12 +.eh_frame +[0] CIE augmentation="" +[16] CIE augmentation="zR" +[40] FDE cie=[16] +.debug_frame +[0] CIE augmentation="" +[24] FDE cie=[0] +EOF + +testrun_compare ${abs_builddir}/next_cfi testfilearm <<\EOF +testfilearm +.eh_frame +.debug_frame +[0] CIE augmentation="" +[16] FDE cie=[0] +[32] CIE augmentation="" +[48] FDE cie=[32] +EOF + +testrun_compare ${abs_builddir}/next_cfi testfileaarch64 <<\EOF +testfileaarch64 +.eh_frame +[0] CIE augmentation="zR" +[24] FDE cie=[0] +[80] FDE cie=[0] +.debug_frame +[0] CIE augmentation="" +[16] FDE cie=[0] +[40] CIE augmentation="" +[56] FDE cie=[40] +EOF + +testrun_compare ${abs_builddir}/next_cfi testfileppc32 <<\EOF +testfileppc32 +.eh_frame +[0] CIE augmentation="zR" +[20] FDE cie=[0] +[40] FDE cie=[0] +[96] FDE cie=[0] +.debug_frame +[0] CIE augmentation="" +[16] FDE cie=[0] +[32] CIE augmentation="" +[48] FDE cie=[32] +EOF + +testrun_compare ${abs_builddir}/next_cfi testfileppc64 <<\EOF +testfileppc64 +.eh_frame +[0] CIE augmentation="zR" +[20] FDE cie=[0] +[40] FDE cie=[0] +[64] CIE augmentation="zR" +[88] FDE cie=[64] +[144] FDE cie=[64] +.debug_frame +[0] CIE augmentation="" +[16] FDE cie=[0] +[56] CIE augmentation="" +[72] FDE cie=[56] +EOF diff --git a/tests/run-next-files.sh b/tests/run-next-files.sh new file mode 100755 index 00000000..7a3b6d0f --- /dev/null +++ b/tests/run-next-files.sh @@ -0,0 +1,165 @@ +#! /bin/sh +# Variant of run-get-files that uses dwarf_next_lines. +# 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 + +testfiles testfile testfile2 + +testrun_compare ${abs_builddir}/next-files testfile testfile2 <<\EOF +off = 0 + dirs[0] = "/home/drepper/gnu/new-bu/build/ttt" + file[0] = "???" + file[1] = "/home/drepper/gnu/new-bu/build/ttt/m.c" +off = 75 + dirs[0] = "/home/drepper/gnu/new-bu/build/ttt" + file[0] = "???" + file[1] = "/home/drepper/gnu/new-bu/build/ttt/b.c" + file[2] = "/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.h" + file[3] = "/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stdarg.h" + file[4] = "/usr/include/bits/types.h" + file[5] = "/usr/include/bits/sched.h" + file[6] = "/usr/include/bits/pthreadtypes.h" + file[7] = "/usr/include/stdio.h" + file[8] = "/usr/include/libio.h" + file[9] = "/usr/include/wchar.h" + file[10] = "/usr/include/_G_config.h" + file[11] = "/usr/include/gconv.h" +off = 480 + dirs[0] = "/home/drepper/gnu/new-bu/build/ttt" + file[0] = "???" + file[1] = "/home/drepper/gnu/new-bu/build/ttt/f.c" +off = 0 + dirs[0] = "/shoggoth/drepper" + file[0] = "???" + file[1] = "/shoggoth/drepper/b.c" + file[2] = "/home/geoffk/objs/laurel-000912-branch/lib/gcc-lib/powerpc-unknown-linux-gnu/2.96-laurel-000912/include/stddef.h" + file[3] = "/home/geoffk/objs/laurel-000912-branch/lib/gcc-lib/powerpc-unknown-linux-gnu/2.96-laurel-000912/include/stdarg.h" + file[4] = "/shoggoth/drepper/<built-in>" + file[5] = "/usr/include/bits/types.h" + file[6] = "/usr/include/stdio.h" + file[7] = "/usr/include/libio.h" + file[8] = "/usr/include/_G_config.h" +off = 418 + dirs[0] = "/shoggoth/drepper" + file[0] = "???" + file[1] = "/shoggoth/drepper/f.c" +off = 485 + dirs[0] = "/shoggoth/drepper" + file[0] = "???" + file[1] = "/shoggoth/drepper/m.c" +EOF + +# 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}/next-files testfile-splitdwarf-4 testfile-hello4.dwo testfile-world4.dwo <<\EOF +off = 0 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include" + file[0] = "???" + file[1] = "/home/mark/src/elfutils/tests/hello.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include/stddef.h" +off = 612 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/usr/include" + file[0] = "???" + file[1] = "/home/mark/src/elfutils/tests/world.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/usr/include/stdlib.h" +off = 0 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include" + file[0] = "???" + file[1] = "/home/mark/src/elfutils/tests/hello.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include/stddef.h" +off = 0 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/usr/include" + file[0] = "???" + file[1] = "/home/mark/src/elfutils/tests/world.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/usr/include/stdlib.h" +EOF + +# No problem with dirs[0] for DWARF5 line tables. +testrun_compare ${abs_builddir}/next-files testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo <<\EOF +off = 0 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include" + file[0] = "/home/mark/src/elfutils/tests/hello.c" + file[1] = "/home/mark/src/elfutils/tests/hello.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include/stddef.h" +off = 655 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/usr/include" + file[0] = "/home/mark/src/elfutils/tests/world.c" + file[1] = "/home/mark/src/elfutils/tests/world.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/usr/include/stdlib.h" +off = 0 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include" + file[0] = "/home/mark/src/elfutils/tests/hello.c" + file[1] = "/home/mark/src/elfutils/tests/hello.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include/stddef.h" +off = 0 + dirs[0] = "/home/mark/src/elfutils/tests" + dirs[1] = "/usr/include" + file[0] = "/home/mark/src/elfutils/tests/world.c" + file[1] = "/home/mark/src/elfutils/tests/world.c" + file[2] = "/home/mark/src/elfutils/tests/hello.h" + file[3] = "/usr/include/stdlib.h" +EOF + +# Created from testfile using +# cp testfile testfile-only-debug-line +# eu-strip -g --keep-section .debug_line +# +# Note how the comp dir cannot be retrieved and some files become relative. +testfiles testfile-only-debug-line +testrun_compare ${abs_builddir}/next-files testfile-only-debug-line <<\EOF +off = 0 + dirs[0] = (null) + file[0] = "???" + file[1] = "m.c" +off = 75 + dirs[0] = (null) + file[0] = "???" + file[1] = "b.c" + file[2] = "/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.h" + file[3] = "/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stdarg.h" + file[4] = "/usr/include/bits/types.h" + file[5] = "/usr/include/bits/sched.h" + file[6] = "/usr/include/bits/pthreadtypes.h" + file[7] = "/usr/include/stdio.h" + file[8] = "/usr/include/libio.h" + file[9] = "/usr/include/wchar.h" + file[10] = "/usr/include/_G_config.h" + file[11] = "/usr/include/gconv.h" +off = 480 + dirs[0] = (null) + file[0] = "???" + file[1] = "f.c" +EOF + +exit 0 diff --git a/tests/run-next-lines.sh b/tests/run-next-lines.sh new file mode 100755 index 00000000..84aee1c7 --- /dev/null +++ b/tests/run-next-lines.sh @@ -0,0 +1,116 @@ +#! /bin/sh +# Variant of run-get-lines that uses dwarf_next_lines. +# 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 + +testfiles testfile testfile2 testfilenolines + +testrun_compare ${abs_builddir}/next-lines testfile testfile2 <<\EOF +off = 0 + 5 lines +804842c: /home/drepper/gnu/new-bu/build/ttt/m.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +8048432: /home/drepper/gnu/new-bu/build/ttt/m.c:6:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +804844d: /home/drepper/gnu/new-bu/build/ttt/m.c:7:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +8048458: /home/drepper/gnu/new-bu/build/ttt/m.c:8:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +804845a: /home/drepper/gnu/new-bu/build/ttt/m.c:8:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no +off = 75 + 4 lines +804845c: /home/drepper/gnu/new-bu/build/ttt/b.c:4:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +804845f: /home/drepper/gnu/new-bu/build/ttt/b.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +8048464: /home/drepper/gnu/new-bu/build/ttt/b.c:6:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +8048466: /home/drepper/gnu/new-bu/build/ttt/b.c:6:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no +off = 480 + 4 lines +8048468: /home/drepper/gnu/new-bu/build/ttt/f.c:3:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +804846b: /home/drepper/gnu/new-bu/build/ttt/f.c:4:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +8048470: /home/drepper/gnu/new-bu/build/ttt/f.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +8048472: /home/drepper/gnu/new-bu/build/ttt/f.c:5:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no +off = 0 + 4 lines +10000470: /shoggoth/drepper/b.c:4:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +1000047c: /shoggoth/drepper/b.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +10000480: /shoggoth/drepper/b.c:6:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +10000490: /shoggoth/drepper/b.c:6:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no +off = 418 + 4 lines +10000490: /shoggoth/drepper/f.c:3:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +1000049c: /shoggoth/drepper/f.c:4:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +100004a0: /shoggoth/drepper/f.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +100004b0: /shoggoth/drepper/f.c:5:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no +off = 485 + 5 lines +100004b0: /shoggoth/drepper/m.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +100004cc: /shoggoth/drepper/m.c:6:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +100004e8: /shoggoth/drepper/m.c:7:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +100004f4: /shoggoth/drepper/m.c:8:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +10000514: /shoggoth/drepper/m.c:8:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no +EOF + +# - lines.c +# int ft; +# +# int +# main (int argc, char **argv) +# { +# return ft - 42; +# } +# +# - nolines.c +# int ft = 42; +# +# gcc -g -c lines.c +# gcc -g -c nolines.c +# gcc -g -o testfilenolines lines.o nolines.o + +testrun_compare ${abs_builddir}/next-lines testfilenolines <<\EOF +off = 0 + 4 lines +400474: /home/mark/src/tests/lines.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +40047f: /home/mark/src/tests/lines.c:6:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +400488: /home/mark/src/tests/lines.c:7:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +40048a: /home/mark/src/tests/lines.c:7:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no +off = 59 + 0 lines +EOF + +# See run-next-files. +# Note no, comp_dir, so all paths are relative. +testfiles testfile-only-debug-line +testrun_compare ${abs_builddir}/next-lines testfile-only-debug-line <<\EOF +off = 0 + 5 lines +804842c: m.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +8048432: m.c:6:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +804844d: m.c:7:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +8048458: m.c:8:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +804845a: m.c:8:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no +off = 75 + 4 lines +804845c: b.c:4:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +804845f: b.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +8048464: b.c:6:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +8048466: b.c:6:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no +off = 480 + 4 lines +8048468: f.c:3:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +804846b: f.c:4:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +8048470: f.c:5:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no +8048472: f.c:5:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no +EOF + +exit 0 diff --git a/tests/run-peel-type.sh b/tests/run-peel-type.sh index 7fd96e84..668e3161 100755 --- a/tests/run-peel-type.sh +++ b/tests/run-peel-type.sh @@ -55,6 +55,7 @@ ca raw type array_type ia raw type array_type va raw type array_type sa raw type array_type +d3d raw type array_type f raw type base_type b raw type base_type EOF diff --git a/tests/run-readelf-addr.sh b/tests/run-readelf-addr.sh new file mode 100755 index 00000000..ea723c27 --- /dev/null +++ b/tests/run-readelf-addr.sh @@ -0,0 +1,143 @@ +#! /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-splitdwarf-5 + +# DWARF4 GNU DebugFission No real table header. +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=addr testfile-splitdwarf-4<<\EOF + +DWARF section [33] '.debug_addr' at offset 0x3671: +Table at offset 0 for CU [ b]: + + Length: 152 + DWARF version: 4 + Address size: 8 + Segment size: 0 + + Addresses start at offset 0x0: + [ 0] 0x000000000040116a <foo+0xa> + [ 1] 0x0000000000401189 <foo+0x29> + [ 2] 0x000000000040118d <foo+0x2d> + [ 3] 0x0000000000401194 + [ 4] 0x0000000000401181 <foo+0x21> + [ 5] 0x00000000004011af <baz+0xf> + [ 6] 0x00000000004011b1 + [ 7] 0x00000000004011a0 <baz> + [ 8] 0x0000000000401160 <foo> + [ 9] 0x00000000004011a0 <baz> + [10] 0x000000000040117b <foo+0x1b> + [11] 0x000000000040117b <foo+0x1b> + [12] 0x0000000000401181 <foo+0x21> + [13] 0x0000000000401181 <foo+0x21> + [14] 0x000000000040118d <foo+0x2d> + [15] 0x0000000000401160 <foo> + [16] 0x0000000000401060 <main> + [17] 0x000000000040117b <foo+0x1b> + [18] 0x0000000000404038 <m> + +Table at offset 98 for CU [ 3f]: + + Length: 136 + DWARF version: 4 + Address size: 8 + Segment size: 0 + + Addresses start at offset 0x98: + [ 0] 0x00000000004011df <calc+0x1f> + [ 1] 0x00000000004011e4 <calc+0x24> + [ 2] 0x0000000000401060 <main> + [ 3] 0x0000000000401071 <main+0x11> + [ 4] 0x0000000000401074 <main+0x14> + [ 5] 0x0000000000401079 <main+0x19> + [ 6] 0x00000000004011d3 <calc+0x13> + [ 7] 0x0000000000401078 <main+0x18> + [ 8] 0x00000000004011a0 <baz> + [ 9] 0x0000000000401040 + [10] 0x0000000000401080 <_start> + [11] 0x00000000004011c0 <calc> + [12] 0x0000000000401060 <main> + [13] 0x00000000004011c0 <calc> + [14] 0x00000000004011c8 <calc+0x8> + [15] 0x00000000004011d8 <calc+0x18> + [16] 0x00000000004011da <calc+0x1a> + +EOF + +# DWARF5 Real table header. +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=addr testfile-splitdwarf-5<<\EOF + +DWARF section [32] '.debug_addr' at offset 0x365e: +Table at offset 0 for CU [ 14]: + + Length: 156 + DWARF version: 5 + Address size: 8 + Segment size: 0 + + Addresses start at offset 0x8: + [ 0] 0x000000000040116a <foo+0xa> + [ 1] 0x0000000000401189 <foo+0x29> + [ 2] 0x000000000040118d <foo+0x2d> + [ 3] 0x0000000000401194 + [ 4] 0x0000000000401181 <foo+0x21> + [ 5] 0x00000000004011af <baz+0xf> + [ 6] 0x00000000004011b1 + [ 7] 0x00000000004011a0 <baz> + [ 8] 0x0000000000401160 <foo> + [ 9] 0x00000000004011a0 <baz> + [10] 0x000000000040117b <foo+0x1b> + [11] 0x000000000040117b <foo+0x1b> + [12] 0x0000000000401181 <foo+0x21> + [13] 0x0000000000401181 <foo+0x21> + [14] 0x000000000040118d <foo+0x2d> + [15] 0x0000000000401160 <foo> + [16] 0x0000000000401060 <main> + [17] 0x000000000040117b <foo+0x1b> + [18] 0x0000000000404038 <m> + +Table at offset a0 for CU [ 49]: + + Length: 140 + DWARF version: 5 + Address size: 8 + Segment size: 0 + + Addresses start at offset 0xa8: + [ 0] 0x00000000004011df <calc+0x1f> + [ 1] 0x00000000004011e4 <calc+0x24> + [ 2] 0x0000000000401060 <main> + [ 3] 0x0000000000401071 <main+0x11> + [ 4] 0x0000000000401074 <main+0x14> + [ 5] 0x0000000000401079 <main+0x19> + [ 6] 0x00000000004011d3 <calc+0x13> + [ 7] 0x0000000000401078 <main+0x18> + [ 8] 0x00000000004011a0 <baz> + [ 9] 0x0000000000401040 + [10] 0x0000000000401080 <_start> + [11] 0x00000000004011c0 <calc> + [12] 0x0000000000401060 <main> + [13] 0x00000000004011c0 <calc> + [14] 0x00000000004011c8 <calc+0x8> + [15] 0x00000000004011d8 <calc+0x18> + [16] 0x00000000004011da <calc+0x1a> + +EOF + +exit 0 diff --git a/tests/run-readelf-const-values.sh b/tests/run-readelf-const-values.sh new file mode 100755 index 00000000..0a6356f1 --- /dev/null +++ b/tests/run-readelf-const-values.sh @@ -0,0 +1,230 @@ +#! /bin/sh +# Test for displaying DW_AT_const_types with the "correct" sign. +# 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 + +# = s.c +# +# int s() +# { +# int i = -1; +# int j = -1; +# +# return i - j; +# } +# +# = m.c +# +# extern int s(); +# +# int +# main () +# { +# const signed char sc = -2; +# const unsigned char uc = 254; +# +# const signed short ss = -16; +# const unsigned short us = 65520; +# +# const signed int si = -3; +# const unsigned int ui = 4200000000; +# +# signed long sl = -1; +# unsigned long ul = 0xffffffffffffffffUL; +# +# return s (); +# } +# +# gcc -gdwarf-5 -O2 -c s.c +# gcc -gdwarf-4 -O2 -c m.c +# gcc -o testfile-const-values s.o m.o +# eu-strip -g -f testfile-const-values.debug testfile-const-values + +testfiles testfile-const-values.debug + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info testfile-const-values.debug << EOF + +DWARF section [28] '.debug_info' at offset 0x2e0: + [Offset] + Compilation unit at offset 0: + Version: 5, Abbreviation section offset: 0, Address size: 8, Offset size: 4 + Unit type: compile (1) + [ c] compile_unit abbrev: 2 + producer (strp) "GNU C11 7.3.1 20180303 (Red Hat 7.3.1-5) -mtune=generic -march=x86-64 -gdwarf-5 -O2" + language (data1) C11 (29) + name (string) "s.c" + comp_dir (strp) "/home/mark/build/elfutils-obj" + low_pc (addr) 0x00000000004004d0 + high_pc (data8) 3 (0x00000000004004d3) + stmt_list (sec_offset) 0 + [ 2e] subprogram abbrev: 3 + external (flag_present) yes + name (string) "s" + decl_file (data1) s.c (1) + decl_line (data1) 1 + type (ref4) [ 5e] + low_pc (addr) 0x00000000004004d0 + high_pc (data8) 3 (0x00000000004004d3) + frame_base (exprloc) + [ 0] call_frame_cfa + call_all_calls (flag_present) yes + sibling (ref4) [ 5e] + [ 4d] variable abbrev: 1 + name (string) "i" + decl_file (implicit_const) s.c (1) + decl_line (data1) 3 + type (ref4) [ 5e] + const_value (implicit_const) -1 + [ 55] variable abbrev: 1 + name (string) "j" + decl_file (implicit_const) s.c (1) + decl_line (data1) 4 + type (ref4) [ 5e] + const_value (implicit_const) -1 + [ 5e] base_type abbrev: 4 + byte_size (data1) 4 + encoding (data1) signed (5) + name (string) "int" + Compilation unit at offset 102: + Version: 4, Abbreviation section offset: 73, Address size: 8, Offset size: 4 + [ 71] compile_unit abbrev: 1 + producer (strp) "GNU C11 7.3.1 20180303 (Red Hat 7.3.1-5) -mtune=generic -march=x86-64 -gdwarf-4 -O2" + language (data1) C99 (12) + name (string) "m.c" + comp_dir (strp) "/home/mark/build/elfutils-obj" + ranges (sec_offset) range list [ 0] + low_pc (addr) 000000000000000000 + stmt_list (sec_offset) 54 + [ 8f] subprogram abbrev: 2 + external (flag_present) yes + name (strp) "main" + decl_file (data1) m.c (1) + decl_line (data1) 4 + type (ref4) [ 119] + low_pc (addr) 0x00000000004003e0 + high_pc (data8) 7 (0x00000000004003e7) + frame_base (exprloc) + [ 0] call_frame_cfa + GNU_all_call_sites (flag_present) yes + sibling (ref4) [ 119] + [ b0] variable abbrev: 3 + name (string) "sc" + decl_file (data1) m.c (1) + decl_line (data1) 6 + type (ref4) [ 12c] + const_value (sdata) -2 + [ bb] variable abbrev: 3 + name (string) "uc" + decl_file (data1) m.c (1) + decl_line (data1) 7 + type (ref4) [ 138] + const_value (sdata) 254 (-2) + [ c6] variable abbrev: 3 + name (string) "ss" + decl_file (data1) m.c (1) + decl_line (data1) 9 + type (ref4) [ 144] + const_value (sdata) -16 + [ d1] variable abbrev: 3 + name (string) "us" + decl_file (data1) m.c (1) + decl_line (data1) 10 + type (ref4) [ 150] + const_value (sdata) 65520 (-16) + [ dc] variable abbrev: 3 + name (string) "si" + decl_file (data1) m.c (1) + decl_line (data1) 12 + type (ref4) [ 120] + const_value (sdata) -3 + [ e7] variable abbrev: 3 + name (string) "ui" + decl_file (data1) m.c (1) + decl_line (data1) 13 + type (ref4) [ 15c] + const_value (sdata) 4200000000 (-94967296) + [ f5] variable abbrev: 3 + name (string) "sl" + decl_file (data1) m.c (1) + decl_line (data1) 15 + type (ref4) [ 161] + const_value (sdata) -1 + [ 100] variable abbrev: 3 + name (string) "ul" + decl_file (data1) m.c (1) + decl_line (data1) 16 + type (ref4) [ 168] + const_value (sdata) 18446744073709551615 (-1) + [ 10b] GNU_call_site abbrev: 4 + low_pc (addr) 0x00000000004003e7 + GNU_tail_call (flag_present) yes + abstract_origin (ref4) [ 16f] + [ 119] base_type abbrev: 5 + byte_size (data1) 4 + encoding (data1) signed (5) + name (string) "int" + [ 120] const_type abbrev: 6 + type (ref4) [ 119] + [ 125] base_type abbrev: 7 + byte_size (data1) 1 + encoding (data1) signed_char (6) + name (strp) "signed char" + [ 12c] const_type abbrev: 6 + type (ref4) [ 125] + [ 131] base_type abbrev: 7 + byte_size (data1) 1 + encoding (data1) unsigned_char (8) + name (strp) "unsigned char" + [ 138] const_type abbrev: 6 + type (ref4) [ 131] + [ 13d] base_type abbrev: 7 + byte_size (data1) 2 + encoding (data1) signed (5) + name (strp) "short int" + [ 144] const_type abbrev: 6 + type (ref4) [ 13d] + [ 149] base_type abbrev: 7 + byte_size (data1) 2 + encoding (data1) unsigned (7) + name (strp) "short unsigned int" + [ 150] const_type abbrev: 6 + type (ref4) [ 149] + [ 155] base_type abbrev: 7 + byte_size (data1) 4 + encoding (data1) unsigned (7) + name (strp) "unsigned int" + [ 15c] const_type abbrev: 6 + type (ref4) [ 155] + [ 161] base_type abbrev: 7 + byte_size (data1) 8 + encoding (data1) signed (5) + name (strp) "long int" + [ 168] base_type abbrev: 7 + byte_size (data1) 8 + encoding (data1) unsigned (7) + name (strp) "long unsigned int" + [ 16f] subprogram abbrev: 8 + external (flag_present) yes + declaration (flag_present) yes + linkage_name (string) "s" + name (string) "s" + decl_file (data1) m.c (1) + decl_line (data1) 1 +EOF + +exit 0 diff --git a/tests/run-readelf-dwz-multi.sh b/tests/run-readelf-dwz-multi.sh index 23ca944c..4f317ac9 100755 --- a/tests/run-readelf-dwz-multi.sh +++ b/tests/run-readelf-dwz-multi.sh @@ -84,7 +84,7 @@ DWARF section [28] '.debug_info' at offset 0x1078: [Offset] Compilation unit at offset 0: Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 - [ b] compile_unit + [ b] compile_unit abbrev: 6 producer (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -mtune=generic -march=x86-64 -g" language (data1) C89 (1) name (strp) "main.c" @@ -92,46 +92,46 @@ DWARF section [28] '.debug_info' at offset 0x1078: low_pc (addr) 0x00000000004006ac <main> high_pc (udata) 44 (0x00000000004006d8) stmt_list (sec_offset) 0 - [ 26] imported_unit + [ 26] imported_unit abbrev: 5 import (GNU_ref_alt) [ b] - [ 2b] pointer_type + [ 2b] pointer_type abbrev: 1 byte_size (data1) 8 type (GNU_ref_alt) [ 53] - [ 31] subprogram + [ 31] subprogram abbrev: 3 external (flag_present) yes name (strp) "main" - decl_file (data1) 1 + decl_file (data1) main.c (1) decl_line (data1) 3 prototyped (flag_present) yes type (GNU_ref_alt) [ 3e] low_pc (addr) 0x00000000004006ac <main> high_pc (udata) 44 (0x00000000004006d8) frame_base (exprloc) - [ 0] call_frame_cfa + [ 0] call_frame_cfa GNU_all_tail_call_sites (flag_present) yes sibling (ref_udata) [ 6e] - [ 48] formal_parameter + [ 48] formal_parameter abbrev: 8 name (strp) "argc" - decl_file (data1) 1 + decl_file (data1) main.c (1) decl_line (data1) 3 type (GNU_ref_alt) [ 3e] location (exprloc) - [ 0] fbreg -36 - [ 56] formal_parameter + [ 0] fbreg -36 + [ 56] formal_parameter abbrev: 4 name (strp) "argv" - decl_file (data1) 1 + decl_file (data1) main.c (1) decl_line (data1) 3 type (ref_udata) [ 6e] location (exprloc) - [ 0] fbreg -48 - [ 61] variable + [ 0] fbreg -48 + [ 61] variable abbrev: 7 name (string) "b" - decl_file (data1) 1 + decl_file (data1) main.c (1) decl_line (data1) 5 type (GNU_ref_alt) [ 5a] location (exprloc) - [ 0] fbreg -32 - [ 6e] pointer_type + [ 0] fbreg -32 + [ 6e] pointer_type abbrev: 2 byte_size (data1) 8 type (ref_udata) [ 2b] EOF @@ -145,7 +145,7 @@ DWARF section [28] '.debug_info' at offset 0x1078: [Offset] Compilation unit at offset 0: Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 - [ b] compile_unit + [ b] compile_unit abbrev: 6 producer (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -mtune=generic -march=x86-64 -g" language (data1) C89 (1) name (strp) "main.c" @@ -153,46 +153,46 @@ DWARF section [28] '.debug_info' at offset 0x1078: low_pc (addr) 0x00000000004006ac <main> high_pc (udata) 44 (0x00000000004006d8) stmt_list (sec_offset) 0 - [ 26] imported_unit + [ 26] imported_unit abbrev: 5 import (GNU_ref_alt) [ b] - [ 2b] pointer_type + [ 2b] pointer_type abbrev: 1 byte_size (data1) 8 type (GNU_ref_alt) [ 53] - [ 31] subprogram + [ 31] subprogram abbrev: 3 external (flag_present) yes name (strp) "main" - decl_file (data1) 1 + decl_file (data1) main.c (1) decl_line (data1) 3 prototyped (flag_present) yes type (GNU_ref_alt) [ 3e] low_pc (addr) 0x00000000004006ac <main> high_pc (udata) 44 (0x00000000004006d8) frame_base (exprloc) - [ 0] call_frame_cfa + [ 0] call_frame_cfa GNU_all_tail_call_sites (flag_present) yes sibling (ref_udata) [ 6e] - [ 48] formal_parameter + [ 48] formal_parameter abbrev: 8 name (strp) "argc" - decl_file (data1) 1 + decl_file (data1) main.c (1) decl_line (data1) 3 type (GNU_ref_alt) [ 3e] location (exprloc) - [ 0] fbreg -36 - [ 56] formal_parameter + [ 0] fbreg -36 + [ 56] formal_parameter abbrev: 4 name (strp) "argv" - decl_file (data1) 1 + decl_file (data1) main.c (1) decl_line (data1) 3 type (ref_udata) [ 6e] location (exprloc) - [ 0] fbreg -48 - [ 61] variable + [ 0] fbreg -48 + [ 61] variable abbrev: 7 name (string) "b" - decl_file (data1) 1 + decl_file (data1) main.c (1) decl_line (data1) 5 type (GNU_ref_alt) [ 5a] location (exprloc) - [ 0] fbreg -32 - [ 6e] pointer_type + [ 0] fbreg -32 + [ 6e] pointer_type abbrev: 2 byte_size (data1) 8 type (ref_udata) [ 2b] EOF @@ -205,7 +205,7 @@ DWARF section [25] '.debug_info' at offset 0x106c: [Offset] Compilation unit at offset 0: Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 - [ b] compile_unit + [ b] compile_unit abbrev: 3 producer (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -fpreprocessed -mtune=generic -march=x86-64 -g -fPIC" language (data1) C89 (1) name (strp) "shared.c" @@ -213,27 +213,27 @@ DWARF section [25] '.debug_info' at offset 0x106c: low_pc (addr) +0x0000000000000670 <call_foo> high_pc (udata) 23 (+0x0000000000000687) stmt_list (sec_offset) 0 - [ 26] imported_unit + [ 26] imported_unit abbrev: 2 import (GNU_ref_alt) [ b] - [ 2b] subprogram + [ 2b] subprogram abbrev: 1 external (flag_present) yes name (strp) "call_foo" - decl_file (data1) 1 + decl_file (data1) shared.c (1) decl_line (data1) 3 prototyped (flag_present) yes type (GNU_ref_alt) [ 3e] low_pc (addr) +0x0000000000000670 <call_foo> high_pc (udata) 23 (+0x0000000000000687) frame_base (exprloc) - [ 0] call_frame_cfa + [ 0] call_frame_cfa GNU_all_call_sites (flag_present) yes - [ 41] formal_parameter + [ 41] formal_parameter abbrev: 4 name (string) "fb" - decl_file (data1) 1 + decl_file (data1) shared.c (1) decl_line (data1) 3 type (GNU_ref_alt) [ 76] location (exprloc) - [ 0] fbreg -24 + [ 0] fbreg -24 EOF # Same as above, but find alt debug file in a .dwz subdir. @@ -245,7 +245,7 @@ DWARF section [25] '.debug_info' at offset 0x106c: [Offset] Compilation unit at offset 0: Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 - [ b] compile_unit + [ b] compile_unit abbrev: 3 producer (strp) "GNU C 4.7.0 20120507 (Red Hat 4.7.0-5) -fpreprocessed -mtune=generic -march=x86-64 -g -fPIC" language (data1) C89 (1) name (strp) "shared.c" @@ -253,27 +253,27 @@ DWARF section [25] '.debug_info' at offset 0x106c: low_pc (addr) +0x0000000000000670 <call_foo> high_pc (udata) 23 (+0x0000000000000687) stmt_list (sec_offset) 0 - [ 26] imported_unit + [ 26] imported_unit abbrev: 2 import (GNU_ref_alt) [ b] - [ 2b] subprogram + [ 2b] subprogram abbrev: 1 external (flag_present) yes name (strp) "call_foo" - decl_file (data1) 1 + decl_file (data1) shared.c (1) decl_line (data1) 3 prototyped (flag_present) yes type (GNU_ref_alt) [ 3e] low_pc (addr) +0x0000000000000670 <call_foo> high_pc (udata) 23 (+0x0000000000000687) frame_base (exprloc) - [ 0] call_frame_cfa + [ 0] call_frame_cfa GNU_all_call_sites (flag_present) yes - [ 41] formal_parameter + [ 41] formal_parameter abbrev: 4 name (string) "fb" - decl_file (data1) 1 + decl_file (data1) shared.c (1) decl_line (data1) 3 type (GNU_ref_alt) [ 76] location (exprloc) - [ 0] fbreg -24 + [ 0] fbreg -24 EOF mv .dwz/testfile_multi.dwz . rmdir .dwz @@ -284,7 +284,7 @@ DWARF section [28] '.debug_info' at offset 0x1088: [Offset] Compilation unit at offset 0: Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 - [ b] compile_unit + [ b] compile_unit abbrev: 5 producer (GNU_strp_alt) "GNU C 4.7.2 20121109 (Red Hat 4.7.2-8) -mtune=generic -march=x86-64 -g" language (data1) C89 (1) name (GNU_strp_alt) "main.c" @@ -292,41 +292,41 @@ DWARF section [28] '.debug_info' at offset 0x1088: low_pc (addr) 0x00000000004004ec <main> high_pc (udata) 18 (0x00000000004004fe) stmt_list (sec_offset) 0 - [ 26] imported_unit + [ 26] imported_unit abbrev: 2 import (GNU_ref_alt) [ b] - [ 2b] subprogram + [ 2b] subprogram abbrev: 4 external (flag_present) yes name (GNU_strp_alt) "main" - decl_file (data1) 1 + decl_file (data1) main.c (1) decl_line (data1) 8 prototyped (flag_present) yes type (GNU_ref_alt) [ 30] low_pc (addr) 0x00000000004004ec <main> high_pc (udata) 18 (0x00000000004004fe) frame_base (exprloc) - [ 0] call_frame_cfa + [ 0] call_frame_cfa GNU_all_call_sites (flag_present) yes - [ 41] formal_parameter + [ 41] formal_parameter abbrev: 1 name (GNU_strp_alt) "argc" - decl_file (data1) 1 + decl_file (data1) main.c (1) decl_line (data1) 8 type (GNU_ref_alt) [ 30] location (exprloc) - [ 0] fbreg -36 - [ 4f] formal_parameter + [ 0] fbreg -36 + [ 4f] formal_parameter abbrev: 1 name (GNU_strp_alt) "argv" - decl_file (data1) 1 + decl_file (data1) main.c (1) decl_line (data1) 8 type (GNU_ref_alt) [ 41] location (exprloc) - [ 0] fbreg -48 - [ 5d] variable + [ 0] fbreg -48 + [ 5d] variable abbrev: 3 name (string) "fbb" - decl_file (data1) 1 + decl_file (data1) main.c (1) decl_line (data1) 10 type (GNU_ref_alt) [ 14] location (exprloc) - [ 0] fbreg -32 + [ 0] fbreg -32 EOF exit 0 diff --git a/tests/run-readelf-info-plus.sh b/tests/run-readelf-info-plus.sh new file mode 100755 index 00000000..ee1db021 --- /dev/null +++ b/tests/run-readelf-info-plus.sh @@ -0,0 +1,31 @@ +#! /bin/sh +# Test for --debug-dump=info+ and finding split unit (in wrong file). +# 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-5 +testfiles testfile-world5.dwo + +# note, wrong file, renamed as if this contains the correct dwo... +tempfiles testfile-hello5.dwo +cp testfile-world5.dwo testfile-hello5.dwo + +testrun ${abs_top_builddir}/src/readelf --debug-dump=info+ testfile-splitdwarf-5 + +exit 0 diff --git a/tests/run-readelf-line.sh b/tests/run-readelf-line.sh index 32bcf9d5..a95e6aa9 100755 --- a/tests/run-readelf-line.sh +++ b/tests/run-readelf-line.sh @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2013 Red Hat, Inc. +# Copyright (C) 2013, 2018 Red Hat, Inc. # This file is part of elfutils. # # This file is free software; you can redistribute it and/or modify @@ -28,15 +28,17 @@ DWARF section [30] '.debug_line' at offset 0x15f6: Table at offset 0: - Length: 83 - DWARF version: 2 - Prologue length: 43 - Minimum instruction length: 1 - Maximum operations per instruction: 1 - Initial value if 'is_stmt': 1 - Line base: -5 - Line range: 14 - Opcode base: 13 + Length: 83 + DWARF version: 2 + Prologue length: 43 + Address size: 4 + Segment selector size: 0 + Min instruction length: 1 + Max operations per instruction: 1 + Initial value if 'is_stmt': 1 + Line base: -5 + Line range: 14 + Opcode base: 13 Opcodes: [ 1] 0 arguments @@ -83,15 +85,17 @@ Line number statements: Table at offset 87: - Length: 72 - DWARF version: 2 - Prologue length: 28 - Minimum instruction length: 1 - Maximum operations per instruction: 1 - Initial value if 'is_stmt': 1 - Line base: -5 - Line range: 14 - Opcode base: 13 + Length: 72 + DWARF version: 2 + Prologue length: 28 + Address size: 4 + Segment selector size: 0 + Min instruction length: 1 + Max operations per instruction: 1 + Initial value if 'is_stmt': 1 + Line base: -5 + Line range: 14 + Opcode base: 13 Opcodes: [ 1] 0 arguments @@ -133,15 +137,17 @@ Line number statements: Table at offset 163: - Length: 106 - DWARF version: 2 - Prologue length: 43 - Minimum instruction length: 1 - Maximum operations per instruction: 1 - Initial value if 'is_stmt': 1 - Line base: -5 - Line range: 14 - Opcode base: 13 + Length: 106 + DWARF version: 2 + Prologue length: 43 + Address size: 4 + Segment selector size: 0 + Min instruction length: 1 + Max operations per instruction: 1 + Initial value if 'is_stmt': 1 + Line base: -5 + Line range: 14 + Opcode base: 13 Opcodes: [ 1] 0 arguments @@ -256,4 +262,888 @@ DWARF section [30] '.debug_line' at offset 0x15f6: EOF +# A .debug_line table with mininum instruction length > 1. +# +# = hello.c +# #include <stdio.h> +# +# int +# main (int argc, char **argv) +# { +# printf ("Hello, %s\n", (argc > 0 +# ? argv[1]: "World")); +# return 0; +# } +# +# clang version 5.0.1 (tags/RELEASE_501/final) +# Target: powerpc64-unknown-linux-gnu +# clang -g -O2 -o testfile-ppc64-min-instr hello.c +testfiles testfile-ppc64-min-instr + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=line testfile-ppc64-min-instr <<\EOF + +DWARF section [29] '.debug_line' at offset 0xdf6: + +Table at offset 0: + + Length: 69 + DWARF version: 2 + Prologue length: 30 + Address size: 8 + Segment selector size: 0 + Min instruction length: 4 + Max operations per instruction: 1 + Initial value if 'is_stmt': 1 + Line base: -5 + Line range: 14 + Opcode base: 13 + +Opcodes: + [ 1] 0 arguments + [ 2] 1 argument + [ 3] 1 argument + [ 4] 1 argument + [ 5] 1 argument + [ 6] 0 arguments + [ 7] 0 arguments + [ 8] 0 arguments + [ 9] 1 argument + [10] 0 arguments + [11] 0 arguments + [12] 1 argument + +Directory table: + +File name table: + Entry Dir Time Size Name + 1 0 0 0 hello.c + +Line number statements: + [ 28] extended opcode 2: set address to 0x100005a4 <main> + [ 33] special opcode 22: address+0 = 0x100005a4 <main>, line+4 = 5 + [ 34] set column to 27 + [ 36] set prologue end flag + [ 37] special opcode 19: address+0 = 0x100005a4 <main>, line+1 = 6 + [ 38] set column to 8 + [ 3a] special opcode 47: address+8 = 0x100005ac <main+0x8>, line+1 = 7 + [ 3b] set 'is_stmt' to 0 + [ 3c] advance line by constant -7 to 0 + [ 3e] special opcode 32: address+4 = 0x100005b0 <main+0xc>, line+0 = 0 + [ 3f] set column to 3 + [ 41] set 'is_stmt' to 1 + [ 42] special opcode 108: address+24 = 0x100005c8 <main+0x24>, line+6 = 6 + [ 43] special opcode 76: address+16 = 0x100005d8 <main+0x34>, line+2 = 8 + [ 44] advance address by 32 to 0x100005f8 + [ 46] extended opcode 1: end of sequence +EOF + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=decodedline testfile-ppc64-min-instr <<\EOF + +DWARF section [29] '.debug_line' at offset 0xdf6: + + CU [b] hello.c + line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End) + /home/fedora/mjw/hello.c (mtime: 0, length: 0) + 5:0 S 0 0 0 0x00000000100005a4 <main> + 6:27 S P 0 0 0 0x00000000100005a4 <main> + 7:8 S 0 0 0 0x00000000100005ac <main+0x8> + 0:8 0 0 0 0x00000000100005b0 <main+0xc> + 6:3 S 0 0 0 0x00000000100005c8 <main+0x24> + 8:3 S 0 0 0 0x00000000100005d8 <main+0x34> + 8:3 S * 0 0 0 0x00000000100005f7 <main+0x53> + +EOF + +# Two tests for the same code but encoded using DWARF4 or DWARF5. +# Output is identical except for the section offset and CU numbers. +# See tests/testfile-dwarf-45.source. + +testfiles testfile-dwarf-4 testfile-dwarf-5 + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=decodedline testfile-dwarf-4 << \EOF + +DWARF section [29] '.debug_line' at offset 0x1734: + + CU [b] hello.c + line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End) + /var/tmp/hello/hello.c (mtime: 0, length: 0) + 21:0 S 0 0 0 0x0000000000400510 <foo> + 22:1 S 0 0 0 0x0000000000400510 <foo> + 22:3 0 0 0 0x0000000000400510 <foo> + 25:6 0 0 0 0x0000000000400514 <foo+0x4> + 25:34 S 0 0 0 0x000000000040051a <foo+0xa> + 25:3 0 0 0 0x000000000040051a <foo+0xa> + 26:34 0 0 0 0x000000000040051e <foo+0xe> + 25:1 1 0 0 0x0000000000400528 <foo+0x18> + /var/tmp/hello/hello.h (mtime: 0, length: 0) + 7:18 S 0 0 0 0x000000000040052b <foo+0x1b> + 9:3 S 0 0 0 0x000000000040052b <foo+0x1b> + 9:3 0 0 0 0x000000000040052b <foo+0x1b> + 10:6 S 0 0 0 0x000000000040052f <foo+0x1f> + 10:5 0 0 0 0x000000000040052f <foo+0x1f> + 12:7 S 0 0 0 0x0000000000400531 <foo+0x21> + /var/tmp/hello/hello.c (mtime: 0, length: 0) + 10:3 S 0 0 0 0x0000000000400531 <foo+0x21> + 12:3 S 0 0 0 0x0000000000400531 <foo+0x21> + 12:3 0 0 0 0x0000000000400531 <foo+0x21> + 13:6 S 0 0 0 0x0000000000400535 <foo+0x25> + 13:5 0 0 0 0x0000000000400535 <foo+0x25> + 15:7 S 0 0 0 0x0000000000400539 <foo+0x29> + 22:3 S 0 0 0 0x0000000000400539 <foo+0x29> + 22:3 0 0 0 0x0000000000400539 <foo+0x29> + 23:6 S 0 0 0 0x000000000040053d <foo+0x2d> + 23:5 0 0 0 0x000000000040053d <foo+0x2d> + 9:12 S 0 0 0 0x0000000000400550 <baz> + 10:1 S 0 0 0 0x0000000000400550 <baz> + 12:3 S 0 0 0 0x0000000000400550 <baz> + 12:3 0 0 0 0x0000000000400550 <baz> + 13:9 0 0 0 0x0000000000400556 <baz+0x6> + 15:7 S 0 0 0 0x000000000040055f <baz+0xf> + 15:3 0 0 0 0x000000000040055f <baz+0xf> + 15:7 * 0 0 0 0x0000000000400560 <baz+0x10> + + CU [21c] world.c + line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End) + /var/tmp/hello/world.c (mtime: 0, length: 0) + 15:0 S 0 0 0 0x0000000000400410 <main> + 16:1 S 0 0 0 0x0000000000400410 <main> + 17:3 S 0 0 0 0x0000000000400410 <main> + 15:3 0 0 0 0x0000000000400410 <main> + 17:1 0 0 0 0x0000000000400419 <main+0x9> + 18:6 S 0 0 0 0x000000000040041e <main+0xe> + 18:5 0 0 0 0x000000000040041e <main+0xe> + 22:7 S 0 0 0 0x0000000000400421 <main+0x11> + 22:3 S * 0 0 0 0x000000000040042f <main+0x1f> + + 6:0 S 0 0 0 0x0000000000400570 <calc> + 7:1 S 0 0 0 0x0000000000400570 <calc> + 7:3 0 0 0 0x0000000000400570 <calc> + 7:6 1 0 0 0x0000000000400575 <calc+0x5> + 7:24 0 0 0 0x0000000000400578 <calc+0x8> + 10:17 S 0 0 0 0x000000000040057d <calc+0xd> + 10:3 0 0 0 0x000000000040057d <calc+0xd> + /var/tmp/hello/hello.h (mtime: 0, length: 0) + 10:10 0 0 0 0x0000000000400583 <calc+0x13> + /var/tmp/hello/world.c (mtime: 0, length: 0) + 10:7 0 0 0 0x0000000000400585 <calc+0x15> + /var/tmp/hello/hello.h (mtime: 0, length: 0) + 7:10 S 0 0 0 0x0000000000400588 <calc+0x18> + 9:3 S 0 0 0 0x0000000000400588 <calc+0x18> + 10:3 0 0 0 0x0000000000400588 <calc+0x18> + 12:7 S 0 0 0 0x000000000040058f <calc+0x1f> + 12:3 0 0 0 0x000000000040058f <calc+0x1f> + /var/tmp/hello/world.c (mtime: 0, length: 0) + 11:10 0 0 0 0x0000000000400598 <calc+0x28> + 11:1 * 0 0 0 0x000000000040059a <calc+0x2a> + +EOF + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=decodedline testfile-dwarf-5 << \EOF + +DWARF section [29] '.debug_line' at offset 0x171f: + + CU [c] hello.c + line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End) + /var/tmp/hello/hello.c (mtime: 0, length: 0) + 21:0 S 0 0 0 0x0000000000400510 <foo> + 22:1 S 0 0 0 0x0000000000400510 <foo> + 22:3 0 0 0 0x0000000000400510 <foo> + 25:6 0 0 0 0x0000000000400514 <foo+0x4> + 25:34 S 0 0 0 0x000000000040051a <foo+0xa> + 25:3 0 0 0 0x000000000040051a <foo+0xa> + 26:34 0 0 0 0x000000000040051e <foo+0xe> + 25:1 1 0 0 0x0000000000400528 <foo+0x18> + /var/tmp/hello/hello.h (mtime: 0, length: 0) + 7:18 S 0 0 0 0x000000000040052b <foo+0x1b> + 9:3 S 0 0 0 0x000000000040052b <foo+0x1b> + 9:3 0 0 0 0x000000000040052b <foo+0x1b> + 10:6 S 0 0 0 0x000000000040052f <foo+0x1f> + 10:5 0 0 0 0x000000000040052f <foo+0x1f> + 12:7 S 0 0 0 0x0000000000400531 <foo+0x21> + /var/tmp/hello/hello.c (mtime: 0, length: 0) + 10:3 S 0 0 0 0x0000000000400531 <foo+0x21> + 12:3 S 0 0 0 0x0000000000400531 <foo+0x21> + 12:3 0 0 0 0x0000000000400531 <foo+0x21> + 13:6 S 0 0 0 0x0000000000400535 <foo+0x25> + 13:5 0 0 0 0x0000000000400535 <foo+0x25> + 15:7 S 0 0 0 0x0000000000400539 <foo+0x29> + 22:3 S 0 0 0 0x0000000000400539 <foo+0x29> + 22:3 0 0 0 0x0000000000400539 <foo+0x29> + 23:6 S 0 0 0 0x000000000040053d <foo+0x2d> + 23:5 0 0 0 0x000000000040053d <foo+0x2d> + 9:12 S 0 0 0 0x0000000000400550 <baz> + 10:1 S 0 0 0 0x0000000000400550 <baz> + 12:3 S 0 0 0 0x0000000000400550 <baz> + 12:3 0 0 0 0x0000000000400550 <baz> + 13:9 0 0 0 0x0000000000400556 <baz+0x6> + 15:7 S 0 0 0 0x000000000040055f <baz+0xf> + 15:3 0 0 0 0x000000000040055f <baz+0xf> + 15:7 * 0 0 0 0x0000000000400560 <baz+0x10> + + CU [218] world.c + line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End) + /var/tmp/hello/world.c (mtime: 0, length: 0) + 15:0 S 0 0 0 0x0000000000400410 <main> + 16:1 S 0 0 0 0x0000000000400410 <main> + 17:3 S 0 0 0 0x0000000000400410 <main> + 15:3 0 0 0 0x0000000000400410 <main> + 17:1 0 0 0 0x0000000000400419 <main+0x9> + 18:6 S 0 0 0 0x000000000040041e <main+0xe> + 18:5 0 0 0 0x000000000040041e <main+0xe> + 22:7 S 0 0 0 0x0000000000400421 <main+0x11> + 22:3 S * 0 0 0 0x000000000040042f <main+0x1f> + + 6:0 S 0 0 0 0x0000000000400570 <calc> + 7:1 S 0 0 0 0x0000000000400570 <calc> + 7:3 0 0 0 0x0000000000400570 <calc> + 7:6 1 0 0 0x0000000000400575 <calc+0x5> + 7:24 0 0 0 0x0000000000400578 <calc+0x8> + 10:17 S 0 0 0 0x000000000040057d <calc+0xd> + 10:3 0 0 0 0x000000000040057d <calc+0xd> + /var/tmp/hello/hello.h (mtime: 0, length: 0) + 10:10 0 0 0 0x0000000000400583 <calc+0x13> + /var/tmp/hello/world.c (mtime: 0, length: 0) + 10:7 0 0 0 0x0000000000400585 <calc+0x15> + /var/tmp/hello/hello.h (mtime: 0, length: 0) + 7:10 S 0 0 0 0x0000000000400588 <calc+0x18> + 9:3 S 0 0 0 0x0000000000400588 <calc+0x18> + 10:3 0 0 0 0x0000000000400588 <calc+0x18> + 12:7 S 0 0 0 0x000000000040058f <calc+0x1f> + 12:3 0 0 0 0x000000000040058f <calc+0x1f> + /var/tmp/hello/world.c (mtime: 0, length: 0) + 11:10 0 0 0 0x0000000000400598 <calc+0x28> + 11:1 * 0 0 0 0x000000000040059a <calc+0x2a> + +EOF + +# After discarding the different offsets in the line number statements, +# the remaining difference between 4 and 5 is (besides the header/length) +# Just the representation of the directory and line tables: + +# Directory table: +# - /opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include +# + [path(line_strp)] +# + 0 /var/tmp/hello (90) +# + 1 /opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include (17) +# +# File name table: +# - Entry Dir Time Size Name +# - 1 0 0 0 hello.c +# - 2 0 0 0 hello.h +# - 3 1 0 0 stddef.h +# + [path(line_strp), directory_index(data1)] +# + 0 hello.c (9), 0 +# + 1 hello.c (9), 0 +# + 2 hello.h (82), 0 +# + 3 stddef.h (0), 1 +# +# Directory table: +# - /usr/include +# + [path(line_strp)] +# + 0 /var/tmp/hello (90) +# + 1 /usr/include (122) +# +# File name table: +# - Entry Dir Time Size Name +# - 1 0 0 0 world.c +# - 2 0 0 0 hello.h +# - 3 1 0 0 stdlib.h +# + [path(line_strp), directory_index(data1)] +# + 0 world.c (114), 0 +# + 1 world.c (114), 0 +# + 2 hello.h (82), 0 +# + 3 stdlib.h (105), 1 + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=line testfile-dwarf-4 << \EOF + +DWARF section [29] '.debug_line' at offset 0x1734: + +Table at offset 0: + + Length: 608 + DWARF version: 4 + Prologue length: 119 + Address size: 8 + Segment selector size: 0 + Min instruction length: 1 + Max operations per instruction: 1 + Initial value if 'is_stmt': 1 + Line base: -10 + Line range: 242 + Opcode base: 13 + +Opcodes: + [ 1] 0 arguments + [ 2] 1 argument + [ 3] 1 argument + [ 4] 1 argument + [ 5] 1 argument + [ 6] 0 arguments + [ 7] 0 arguments + [ 8] 0 arguments + [ 9] 1 argument + [10] 0 arguments + [11] 0 arguments + [12] 1 argument + +Directory table: + /opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include + +File name table: + Entry Dir Time Size Name + 1 0 0 0 hello.c + 2 0 0 0 hello.h + 3 1 0 0 stddef.h + +Line number statements: + [ 81] extended opcode 2: set address to 0x400510 <foo> + [ 8c] special opcode 43: address+0 = 0x400510 <foo>, line+20 = 21 + [ 8d] set column to 1 + [ 8f] extended opcode 2: set address to 0x400510 <foo> + [ 9a] special opcode 24: address+0 = 0x400510 <foo>, line+1 = 22 + [ 9b] set column to 3 + [ 9d] extended opcode 2: set address to 0x400510 <foo> + [ a8] set 'is_stmt' to 0 + [ a9] copy + [ aa] set column to 6 + [ ac] extended opcode 2: set address to 0x400514 <foo+0x4> + [ b7] special opcode 26: address+0 = 0x400514 <foo+0x4>, line+3 = 25 + [ b8] set column to 34 + [ ba] extended opcode 2: set address to 0x40051a <foo+0xa> + [ c5] set 'is_stmt' to 1 + [ c6] copy + [ c7] set column to 3 + [ c9] extended opcode 2: set address to 0x40051a <foo+0xa> + [ d4] set 'is_stmt' to 0 + [ d5] copy + [ d6] set column to 34 + [ d8] extended opcode 2: set address to 0x40051e <foo+0xe> + [ e3] special opcode 24: address+0 = 0x40051e <foo+0xe>, line+1 = 26 + [ e4] set column to 1 + [ e6] extended opcode 2: set address to 0x400528 <foo+0x18> + [ f1] extended opcode 4: set discriminator to 1 + [ f5] special opcode 22: address+0 = 0x400528 <foo+0x18>, line-1 = 25 + [ f6] set column to 18 + [ f8] extended opcode 2: set address to 0x40052b <foo+0x1b> + [ 103] set file to 2 + [ 105] set 'is_stmt' to 1 + [ 106] advance line by constant -18 to 7 + [ 108] copy + [ 109] set column to 3 + [ 10b] extended opcode 2: set address to 0x40052b <foo+0x1b> + [ 116] special opcode 25: address+0 = 0x40052b <foo+0x1b>, line+2 = 9 + [ 117] set column to 3 + [ 119] extended opcode 2: set address to 0x40052b <foo+0x1b> + [ 124] set 'is_stmt' to 0 + [ 125] copy + [ 126] set column to 6 + [ 128] extended opcode 2: set address to 0x40052f <foo+0x1f> + [ 133] extended opcode 4: set discriminator to 0 + [ 137] set 'is_stmt' to 1 + [ 138] special opcode 24: address+0 = 0x40052f <foo+0x1f>, line+1 = 10 + [ 139] set column to 5 + [ 13b] extended opcode 2: set address to 0x40052f <foo+0x1f> + [ 146] set 'is_stmt' to 0 + [ 147] copy + [ 148] set column to 7 + [ 14a] extended opcode 2: set address to 0x400531 <foo+0x21> + [ 155] set 'is_stmt' to 1 + [ 156] special opcode 25: address+0 = 0x400531 <foo+0x21>, line+2 = 12 + [ 157] set column to 3 + [ 159] extended opcode 2: set address to 0x400531 <foo+0x21> + [ 164] set file to 1 + [ 166] special opcode 21: address+0 = 0x400531 <foo+0x21>, line-2 = 10 + [ 167] set column to 3 + [ 169] extended opcode 2: set address to 0x400531 <foo+0x21> + [ 174] special opcode 25: address+0 = 0x400531 <foo+0x21>, line+2 = 12 + [ 175] set column to 3 + [ 177] extended opcode 2: set address to 0x400531 <foo+0x21> + [ 182] set 'is_stmt' to 0 + [ 183] copy + [ 184] set column to 6 + [ 186] extended opcode 2: set address to 0x400535 <foo+0x25> + [ 191] set 'is_stmt' to 1 + [ 192] special opcode 24: address+0 = 0x400535 <foo+0x25>, line+1 = 13 + [ 193] set column to 5 + [ 195] extended opcode 2: set address to 0x400535 <foo+0x25> + [ 1a0] set 'is_stmt' to 0 + [ 1a1] copy + [ 1a2] set column to 7 + [ 1a4] extended opcode 2: set address to 0x400539 <foo+0x29> + [ 1af] set 'is_stmt' to 1 + [ 1b0] special opcode 25: address+0 = 0x400539 <foo+0x29>, line+2 = 15 + [ 1b1] set column to 3 + [ 1b3] extended opcode 2: set address to 0x400539 <foo+0x29> + [ 1be] special opcode 30: address+0 = 0x400539 <foo+0x29>, line+7 = 22 + [ 1bf] set column to 3 + [ 1c1] extended opcode 2: set address to 0x400539 <foo+0x29> + [ 1cc] set 'is_stmt' to 0 + [ 1cd] copy + [ 1ce] set column to 6 + [ 1d0] extended opcode 2: set address to 0x40053d <foo+0x2d> + [ 1db] set 'is_stmt' to 1 + [ 1dc] special opcode 24: address+0 = 0x40053d <foo+0x2d>, line+1 = 23 + [ 1dd] set column to 5 + [ 1df] extended opcode 2: set address to 0x40053d <foo+0x2d> + [ 1ea] set 'is_stmt' to 0 + [ 1eb] copy + [ 1ec] set column to 12 + [ 1ee] extended opcode 2: set address to 0x400550 <baz> + [ 1f9] set 'is_stmt' to 1 + [ 1fa] advance line by constant -14 to 9 + [ 1fc] copy + [ 1fd] set column to 1 + [ 1ff] extended opcode 2: set address to 0x400550 <baz> + [ 20a] special opcode 24: address+0 = 0x400550 <baz>, line+1 = 10 + [ 20b] set column to 3 + [ 20d] extended opcode 2: set address to 0x400550 <baz> + [ 218] special opcode 25: address+0 = 0x400550 <baz>, line+2 = 12 + [ 219] set column to 3 + [ 21b] extended opcode 2: set address to 0x400550 <baz> + [ 226] set 'is_stmt' to 0 + [ 227] copy + [ 228] set column to 9 + [ 22a] extended opcode 2: set address to 0x400556 <baz+0x6> + [ 235] special opcode 24: address+0 = 0x400556 <baz+0x6>, line+1 = 13 + [ 236] set column to 7 + [ 238] extended opcode 2: set address to 0x40055f <baz+0xf> + [ 243] set 'is_stmt' to 1 + [ 244] special opcode 25: address+0 = 0x40055f <baz+0xf>, line+2 = 15 + [ 245] set column to 3 + [ 247] extended opcode 2: set address to 0x40055f <baz+0xf> + [ 252] set 'is_stmt' to 0 + [ 253] copy + [ 254] set column to 7 + [ 256] extended opcode 2: set address to 0x400561 + [ 261] extended opcode 1: end of sequence + +Table at offset 612: + + Length: 450 + DWARF version: 4 + Prologue length: 67 + Address size: 8 + Segment selector size: 0 + Min instruction length: 1 + Max operations per instruction: 1 + Initial value if 'is_stmt': 1 + Line base: -10 + Line range: 242 + Opcode base: 13 + +Opcodes: + [ 1] 0 arguments + [ 2] 1 argument + [ 3] 1 argument + [ 4] 1 argument + [ 5] 1 argument + [ 6] 0 arguments + [ 7] 0 arguments + [ 8] 0 arguments + [ 9] 1 argument + [10] 0 arguments + [11] 0 arguments + [12] 1 argument + +Directory table: + /usr/include + +File name table: + Entry Dir Time Size Name + 1 0 0 0 world.c + 2 0 0 0 hello.h + 3 1 0 0 stdlib.h + +Line number statements: + [ 2b1] extended opcode 2: set address to 0x400410 <main> + [ 2bc] special opcode 37: address+0 = 0x400410 <main>, line+14 = 15 + [ 2bd] set column to 1 + [ 2bf] extended opcode 2: set address to 0x400410 <main> + [ 2ca] special opcode 24: address+0 = 0x400410 <main>, line+1 = 16 + [ 2cb] set column to 3 + [ 2cd] extended opcode 2: set address to 0x400410 <main> + [ 2d8] special opcode 24: address+0 = 0x400410 <main>, line+1 = 17 + [ 2d9] set column to 3 + [ 2db] extended opcode 2: set address to 0x400410 <main> + [ 2e6] set 'is_stmt' to 0 + [ 2e7] special opcode 21: address+0 = 0x400410 <main>, line-2 = 15 + [ 2e8] set column to 1 + [ 2ea] extended opcode 2: set address to 0x400419 <main+0x9> + [ 2f5] special opcode 25: address+0 = 0x400419 <main+0x9>, line+2 = 17 + [ 2f6] set column to 6 + [ 2f8] extended opcode 2: set address to 0x40041e <main+0xe> + [ 303] set 'is_stmt' to 1 + [ 304] special opcode 24: address+0 = 0x40041e <main+0xe>, line+1 = 18 + [ 305] set column to 5 + [ 307] extended opcode 2: set address to 0x40041e <main+0xe> + [ 312] set 'is_stmt' to 0 + [ 313] copy + [ 314] set column to 7 + [ 316] extended opcode 2: set address to 0x400421 <main+0x11> + [ 321] set 'is_stmt' to 1 + [ 322] special opcode 27: address+0 = 0x400421 <main+0x11>, line+4 = 22 + [ 323] set column to 3 + [ 325] extended opcode 2: set address to 0x400430 <_start> + [ 330] extended opcode 1: end of sequence + [ 333] extended opcode 2: set address to 0x400570 <calc> + [ 33e] special opcode 28: address+0 = 0x400570 <calc>, line+5 = 6 + [ 33f] set column to 1 + [ 341] extended opcode 2: set address to 0x400570 <calc> + [ 34c] special opcode 24: address+0 = 0x400570 <calc>, line+1 = 7 + [ 34d] set column to 3 + [ 34f] extended opcode 2: set address to 0x400570 <calc> + [ 35a] set 'is_stmt' to 0 + [ 35b] copy + [ 35c] set column to 6 + [ 35e] extended opcode 2: set address to 0x400575 <calc+0x5> + [ 369] extended opcode 4: set discriminator to 1 + [ 36d] copy + [ 36e] set column to 24 + [ 370] extended opcode 2: set address to 0x400578 <calc+0x8> + [ 37b] copy + [ 37c] set column to 17 + [ 37e] extended opcode 2: set address to 0x40057d <calc+0xd> + [ 389] extended opcode 4: set discriminator to 0 + [ 38d] set 'is_stmt' to 1 + [ 38e] special opcode 26: address+0 = 0x40057d <calc+0xd>, line+3 = 10 + [ 38f] set column to 3 + [ 391] extended opcode 2: set address to 0x40057d <calc+0xd> + [ 39c] set 'is_stmt' to 0 + [ 39d] copy + [ 39e] set column to 10 + [ 3a0] extended opcode 2: set address to 0x400583 <calc+0x13> + [ 3ab] set file to 2 + [ 3ad] copy + [ 3ae] set column to 7 + [ 3b0] extended opcode 2: set address to 0x400585 <calc+0x15> + [ 3bb] set file to 1 + [ 3bd] copy + [ 3be] set column to 10 + [ 3c0] extended opcode 2: set address to 0x400588 <calc+0x18> + [ 3cb] set file to 2 + [ 3cd] set 'is_stmt' to 1 + [ 3ce] special opcode 20: address+0 = 0x400588 <calc+0x18>, line-3 = 7 + [ 3cf] set column to 3 + [ 3d1] extended opcode 2: set address to 0x400588 <calc+0x18> + [ 3dc] special opcode 25: address+0 = 0x400588 <calc+0x18>, line+2 = 9 + [ 3dd] set column to 3 + [ 3df] extended opcode 2: set address to 0x400588 <calc+0x18> + [ 3ea] set 'is_stmt' to 0 + [ 3eb] special opcode 24: address+0 = 0x400588 <calc+0x18>, line+1 = 10 + [ 3ec] set column to 7 + [ 3ee] extended opcode 2: set address to 0x40058f <calc+0x1f> + [ 3f9] set 'is_stmt' to 1 + [ 3fa] special opcode 25: address+0 = 0x40058f <calc+0x1f>, line+2 = 12 + [ 3fb] set column to 3 + [ 3fd] extended opcode 2: set address to 0x40058f <calc+0x1f> + [ 408] set 'is_stmt' to 0 + [ 409] copy + [ 40a] set column to 10 + [ 40c] extended opcode 2: set address to 0x400598 <calc+0x28> + [ 417] set file to 1 + [ 419] special opcode 22: address+0 = 0x400598 <calc+0x28>, line-1 = 11 + [ 41a] set column to 1 + [ 41c] extended opcode 2: set address to 0x40059b + [ 427] extended opcode 1: end of sequence +EOF + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=line testfile-dwarf-5 << \EOF + +DWARF section [29] '.debug_line' at offset 0x171f: + +Table at offset 0: + + Length: 547 + DWARF version: 5 + Prologue length: 56 + Address size: 8 + Segment selector size: 0 + Min instruction length: 1 + Max operations per instruction: 1 + Initial value if 'is_stmt': 1 + Line base: -10 + Line range: 242 + Opcode base: 13 + +Opcodes: + [ 1] 0 arguments + [ 2] 1 argument + [ 3] 1 argument + [ 4] 1 argument + [ 5] 1 argument + [ 6] 0 arguments + [ 7] 0 arguments + [ 8] 0 arguments + [ 9] 1 argument + [10] 0 arguments + [11] 0 arguments + [12] 1 argument + +Directory table: + [path(line_strp)] + 0 /var/tmp/hello (90) + 1 /opt/local/install/gcc/lib/gcc/x86_64-pc-linux-gnu/9.0.0/include (17) + +File name table: + [path(line_strp), directory_index(data1)] + 0 hello.c (9), 0 + 1 hello.c (9), 0 + 2 hello.h (82), 0 + 3 stddef.h (0), 1 + +Line number statements: + [ 44] extended opcode 2: set address to 0x400510 <foo> + [ 4f] special opcode 43: address+0 = 0x400510 <foo>, line+20 = 21 + [ 50] set column to 1 + [ 52] extended opcode 2: set address to 0x400510 <foo> + [ 5d] special opcode 24: address+0 = 0x400510 <foo>, line+1 = 22 + [ 5e] set column to 3 + [ 60] extended opcode 2: set address to 0x400510 <foo> + [ 6b] set 'is_stmt' to 0 + [ 6c] copy + [ 6d] set column to 6 + [ 6f] extended opcode 2: set address to 0x400514 <foo+0x4> + [ 7a] special opcode 26: address+0 = 0x400514 <foo+0x4>, line+3 = 25 + [ 7b] set column to 34 + [ 7d] extended opcode 2: set address to 0x40051a <foo+0xa> + [ 88] set 'is_stmt' to 1 + [ 89] copy + [ 8a] set column to 3 + [ 8c] extended opcode 2: set address to 0x40051a <foo+0xa> + [ 97] set 'is_stmt' to 0 + [ 98] copy + [ 99] set column to 34 + [ 9b] extended opcode 2: set address to 0x40051e <foo+0xe> + [ a6] special opcode 24: address+0 = 0x40051e <foo+0xe>, line+1 = 26 + [ a7] set column to 1 + [ a9] extended opcode 2: set address to 0x400528 <foo+0x18> + [ b4] extended opcode 4: set discriminator to 1 + [ b8] special opcode 22: address+0 = 0x400528 <foo+0x18>, line-1 = 25 + [ b9] set column to 18 + [ bb] extended opcode 2: set address to 0x40052b <foo+0x1b> + [ c6] set file to 2 + [ c8] set 'is_stmt' to 1 + [ c9] advance line by constant -18 to 7 + [ cb] copy + [ cc] set column to 3 + [ ce] extended opcode 2: set address to 0x40052b <foo+0x1b> + [ d9] special opcode 25: address+0 = 0x40052b <foo+0x1b>, line+2 = 9 + [ da] set column to 3 + [ dc] extended opcode 2: set address to 0x40052b <foo+0x1b> + [ e7] set 'is_stmt' to 0 + [ e8] copy + [ e9] set column to 6 + [ eb] extended opcode 2: set address to 0x40052f <foo+0x1f> + [ f6] extended opcode 4: set discriminator to 0 + [ fa] set 'is_stmt' to 1 + [ fb] special opcode 24: address+0 = 0x40052f <foo+0x1f>, line+1 = 10 + [ fc] set column to 5 + [ fe] extended opcode 2: set address to 0x40052f <foo+0x1f> + [ 109] set 'is_stmt' to 0 + [ 10a] copy + [ 10b] set column to 7 + [ 10d] extended opcode 2: set address to 0x400531 <foo+0x21> + [ 118] set 'is_stmt' to 1 + [ 119] special opcode 25: address+0 = 0x400531 <foo+0x21>, line+2 = 12 + [ 11a] set column to 3 + [ 11c] extended opcode 2: set address to 0x400531 <foo+0x21> + [ 127] set file to 1 + [ 129] special opcode 21: address+0 = 0x400531 <foo+0x21>, line-2 = 10 + [ 12a] set column to 3 + [ 12c] extended opcode 2: set address to 0x400531 <foo+0x21> + [ 137] special opcode 25: address+0 = 0x400531 <foo+0x21>, line+2 = 12 + [ 138] set column to 3 + [ 13a] extended opcode 2: set address to 0x400531 <foo+0x21> + [ 145] set 'is_stmt' to 0 + [ 146] copy + [ 147] set column to 6 + [ 149] extended opcode 2: set address to 0x400535 <foo+0x25> + [ 154] set 'is_stmt' to 1 + [ 155] special opcode 24: address+0 = 0x400535 <foo+0x25>, line+1 = 13 + [ 156] set column to 5 + [ 158] extended opcode 2: set address to 0x400535 <foo+0x25> + [ 163] set 'is_stmt' to 0 + [ 164] copy + [ 165] set column to 7 + [ 167] extended opcode 2: set address to 0x400539 <foo+0x29> + [ 172] set 'is_stmt' to 1 + [ 173] special opcode 25: address+0 = 0x400539 <foo+0x29>, line+2 = 15 + [ 174] set column to 3 + [ 176] extended opcode 2: set address to 0x400539 <foo+0x29> + [ 181] special opcode 30: address+0 = 0x400539 <foo+0x29>, line+7 = 22 + [ 182] set column to 3 + [ 184] extended opcode 2: set address to 0x400539 <foo+0x29> + [ 18f] set 'is_stmt' to 0 + [ 190] copy + [ 191] set column to 6 + [ 193] extended opcode 2: set address to 0x40053d <foo+0x2d> + [ 19e] set 'is_stmt' to 1 + [ 19f] special opcode 24: address+0 = 0x40053d <foo+0x2d>, line+1 = 23 + [ 1a0] set column to 5 + [ 1a2] extended opcode 2: set address to 0x40053d <foo+0x2d> + [ 1ad] set 'is_stmt' to 0 + [ 1ae] copy + [ 1af] set column to 12 + [ 1b1] extended opcode 2: set address to 0x400550 <baz> + [ 1bc] set 'is_stmt' to 1 + [ 1bd] advance line by constant -14 to 9 + [ 1bf] copy + [ 1c0] set column to 1 + [ 1c2] extended opcode 2: set address to 0x400550 <baz> + [ 1cd] special opcode 24: address+0 = 0x400550 <baz>, line+1 = 10 + [ 1ce] set column to 3 + [ 1d0] extended opcode 2: set address to 0x400550 <baz> + [ 1db] special opcode 25: address+0 = 0x400550 <baz>, line+2 = 12 + [ 1dc] set column to 3 + [ 1de] extended opcode 2: set address to 0x400550 <baz> + [ 1e9] set 'is_stmt' to 0 + [ 1ea] copy + [ 1eb] set column to 9 + [ 1ed] extended opcode 2: set address to 0x400556 <baz+0x6> + [ 1f8] special opcode 24: address+0 = 0x400556 <baz+0x6>, line+1 = 13 + [ 1f9] set column to 7 + [ 1fb] extended opcode 2: set address to 0x40055f <baz+0xf> + [ 206] set 'is_stmt' to 1 + [ 207] special opcode 25: address+0 = 0x40055f <baz+0xf>, line+2 = 15 + [ 208] set column to 3 + [ 20a] extended opcode 2: set address to 0x40055f <baz+0xf> + [ 215] set 'is_stmt' to 0 + [ 216] copy + [ 217] set column to 7 + [ 219] extended opcode 2: set address to 0x400561 + [ 224] extended opcode 1: end of sequence + +Table at offset 551: + + Length: 441 + DWARF version: 5 + Prologue length: 56 + Address size: 8 + Segment selector size: 0 + Min instruction length: 1 + Max operations per instruction: 1 + Initial value if 'is_stmt': 1 + Line base: -10 + Line range: 242 + Opcode base: 13 + +Opcodes: + [ 1] 0 arguments + [ 2] 1 argument + [ 3] 1 argument + [ 4] 1 argument + [ 5] 1 argument + [ 6] 0 arguments + [ 7] 0 arguments + [ 8] 0 arguments + [ 9] 1 argument + [10] 0 arguments + [11] 0 arguments + [12] 1 argument + +Directory table: + [path(line_strp)] + 0 /var/tmp/hello (90) + 1 /usr/include (122) + +File name table: + [path(line_strp), directory_index(data1)] + 0 world.c (114), 0 + 1 world.c (114), 0 + 2 hello.h (82), 0 + 3 stdlib.h (105), 1 + +Line number statements: + [ 26b] extended opcode 2: set address to 0x400410 <main> + [ 276] special opcode 37: address+0 = 0x400410 <main>, line+14 = 15 + [ 277] set column to 1 + [ 279] extended opcode 2: set address to 0x400410 <main> + [ 284] special opcode 24: address+0 = 0x400410 <main>, line+1 = 16 + [ 285] set column to 3 + [ 287] extended opcode 2: set address to 0x400410 <main> + [ 292] special opcode 24: address+0 = 0x400410 <main>, line+1 = 17 + [ 293] set column to 3 + [ 295] extended opcode 2: set address to 0x400410 <main> + [ 2a0] set 'is_stmt' to 0 + [ 2a1] special opcode 21: address+0 = 0x400410 <main>, line-2 = 15 + [ 2a2] set column to 1 + [ 2a4] extended opcode 2: set address to 0x400419 <main+0x9> + [ 2af] special opcode 25: address+0 = 0x400419 <main+0x9>, line+2 = 17 + [ 2b0] set column to 6 + [ 2b2] extended opcode 2: set address to 0x40041e <main+0xe> + [ 2bd] set 'is_stmt' to 1 + [ 2be] special opcode 24: address+0 = 0x40041e <main+0xe>, line+1 = 18 + [ 2bf] set column to 5 + [ 2c1] extended opcode 2: set address to 0x40041e <main+0xe> + [ 2cc] set 'is_stmt' to 0 + [ 2cd] copy + [ 2ce] set column to 7 + [ 2d0] extended opcode 2: set address to 0x400421 <main+0x11> + [ 2db] set 'is_stmt' to 1 + [ 2dc] special opcode 27: address+0 = 0x400421 <main+0x11>, line+4 = 22 + [ 2dd] set column to 3 + [ 2df] extended opcode 2: set address to 0x400430 <_start> + [ 2ea] extended opcode 1: end of sequence + [ 2ed] extended opcode 2: set address to 0x400570 <calc> + [ 2f8] special opcode 28: address+0 = 0x400570 <calc>, line+5 = 6 + [ 2f9] set column to 1 + [ 2fb] extended opcode 2: set address to 0x400570 <calc> + [ 306] special opcode 24: address+0 = 0x400570 <calc>, line+1 = 7 + [ 307] set column to 3 + [ 309] extended opcode 2: set address to 0x400570 <calc> + [ 314] set 'is_stmt' to 0 + [ 315] copy + [ 316] set column to 6 + [ 318] extended opcode 2: set address to 0x400575 <calc+0x5> + [ 323] extended opcode 4: set discriminator to 1 + [ 327] copy + [ 328] set column to 24 + [ 32a] extended opcode 2: set address to 0x400578 <calc+0x8> + [ 335] copy + [ 336] set column to 17 + [ 338] extended opcode 2: set address to 0x40057d <calc+0xd> + [ 343] extended opcode 4: set discriminator to 0 + [ 347] set 'is_stmt' to 1 + [ 348] special opcode 26: address+0 = 0x40057d <calc+0xd>, line+3 = 10 + [ 349] set column to 3 + [ 34b] extended opcode 2: set address to 0x40057d <calc+0xd> + [ 356] set 'is_stmt' to 0 + [ 357] copy + [ 358] set column to 10 + [ 35a] extended opcode 2: set address to 0x400583 <calc+0x13> + [ 365] set file to 2 + [ 367] copy + [ 368] set column to 7 + [ 36a] extended opcode 2: set address to 0x400585 <calc+0x15> + [ 375] set file to 1 + [ 377] copy + [ 378] set column to 10 + [ 37a] extended opcode 2: set address to 0x400588 <calc+0x18> + [ 385] set file to 2 + [ 387] set 'is_stmt' to 1 + [ 388] special opcode 20: address+0 = 0x400588 <calc+0x18>, line-3 = 7 + [ 389] set column to 3 + [ 38b] extended opcode 2: set address to 0x400588 <calc+0x18> + [ 396] special opcode 25: address+0 = 0x400588 <calc+0x18>, line+2 = 9 + [ 397] set column to 3 + [ 399] extended opcode 2: set address to 0x400588 <calc+0x18> + [ 3a4] set 'is_stmt' to 0 + [ 3a5] special opcode 24: address+0 = 0x400588 <calc+0x18>, line+1 = 10 + [ 3a6] set column to 7 + [ 3a8] extended opcode 2: set address to 0x40058f <calc+0x1f> + [ 3b3] set 'is_stmt' to 1 + [ 3b4] special opcode 25: address+0 = 0x40058f <calc+0x1f>, line+2 = 12 + [ 3b5] set column to 3 + [ 3b7] extended opcode 2: set address to 0x40058f <calc+0x1f> + [ 3c2] set 'is_stmt' to 0 + [ 3c3] copy + [ 3c4] set column to 10 + [ 3c6] extended opcode 2: set address to 0x400598 <calc+0x28> + [ 3d1] set file to 1 + [ 3d3] special opcode 22: address+0 = 0x400598 <calc+0x28>, line-1 = 11 + [ 3d4] set column to 1 + [ 3d6] extended opcode 2: set address to 0x40059b + [ 3e1] extended opcode 1: end of sequence +EOF + exit 0 diff --git a/tests/run-readelf-loc.sh b/tests/run-readelf-loc.sh index 98870fcf..8594b540 100755 --- a/tests/run-readelf-loc.sh +++ b/tests/run-readelf-loc.sh @@ -63,15 +63,40 @@ testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc --debug-dump=ra testfileloc<<\EOF DWARF section [33] '.debug_loc' at offset 0xd2a: - [ 0] 0x0000000000400480 <main>..0x000000000040048d <main+0xd> [ 0] reg5 - [ 23] 0x0000000000400485 <main+0x5>..0x000000000040048d <main+0xd> [ 0] reg5 - [ 46] 0x00000000004004b2 <say+0x12>..0x00000000004004ba <say+0x1a> [ 0] breg5 0 + + CU [ b] base: 0x0000000000400480 <main> + [ 0] range 0, d + 0x0000000000400480 <main>.. + 0x000000000040048c <main+0xc> + [ 0] reg5 + [ 23] range 5, d + 0x0000000000400485 <main+0x5>.. + 0x000000000040048c <main+0xc> + [ 0] reg5 + + CU [ e0] base: 0x00000000004004a0 <say> + [ 46] range 12, 1a + 0x00000000004004b2 <say+0x12>.. + 0x00000000004004b9 <say+0x19> + [ 0] breg5 0 DWARF section [34] '.debug_ranges' at offset 0xd94: - [ 0] 0x0000000000400480 <main>..0x0000000000400482 <main+0x2> - 0x0000000000400485 <main+0x5>..0x000000000040048d <main+0xd> - [ 30] 0x00000000004004ad <say+0xd>..0x00000000004004af <say+0xf> - 0x00000000004004b2 <say+0x12>..0x00000000004004ba <say+0x1a> + + CU [ b] base: 0x0000000000400480 <main> + [ 0] range 0, 2 + 0x0000000000400480 <main>.. + 0x0000000000400481 <main+0x1> + range 5, d + 0x0000000000400485 <main+0x5>.. + 0x000000000040048c <main+0xc> + + CU [ e0] base: 0x00000000004004a0 <say> + [ 30] range d, f + 0x00000000004004ad <say+0xd>.. + 0x00000000004004ae <say+0xe> + range 12, 1a + 0x00000000004004b2 <say+0x12>.. + 0x00000000004004b9 <say+0x19> EOF # Don't resolve addresses to symbols. @@ -79,15 +104,40 @@ testrun_compare ${abs_top_builddir}/src/readelf -N --debug-dump=loc --debug-dump testfileloc<<\EOF DWARF section [33] '.debug_loc' at offset 0xd2a: - [ 0] 0x0000000000400480..0x000000000040048d [ 0] reg5 - [ 23] 0x0000000000400485..0x000000000040048d [ 0] reg5 - [ 46] 0x00000000004004b2..0x00000000004004ba [ 0] breg5 0 + + CU [ b] base: 0x0000000000400480 + [ 0] range 0, d + 0x0000000000400480.. + 0x000000000040048c + [ 0] reg5 + [ 23] range 5, d + 0x0000000000400485.. + 0x000000000040048c + [ 0] reg5 + + CU [ e0] base: 0x00000000004004a0 + [ 46] range 12, 1a + 0x00000000004004b2.. + 0x00000000004004b9 + [ 0] breg5 0 DWARF section [34] '.debug_ranges' at offset 0xd94: - [ 0] 0x0000000000400480..0x0000000000400482 - 0x0000000000400485..0x000000000040048d - [ 30] 0x00000000004004ad..0x00000000004004af - 0x00000000004004b2..0x00000000004004ba + + CU [ b] base: 0x0000000000400480 + [ 0] range 0, 2 + 0x0000000000400480.. + 0x0000000000400481 + range 5, d + 0x0000000000400485.. + 0x000000000040048c + + CU [ e0] base: 0x00000000004004a0 + [ 30] range d, f + 0x00000000004004ad.. + 0x00000000004004ae + range 12, 1a + 0x00000000004004b2.. + 0x00000000004004b9 EOF # Produce "raw" unprocessed content. @@ -95,15 +145,1016 @@ testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc --debug-dump testfileloc<<\EOF DWARF section [33] '.debug_loc' at offset 0xd2a: - [ 0] 000000000000000000..0x000000000000000d [ 0] reg5 - [ 23] 0x0000000000000005..0x000000000000000d [ 0] reg5 - [ 46] 0x0000000000000012..0x000000000000001a [ 0] breg5 0 + + CU [ b] base: 0x0000000000400480 + [ 0] range 0, d + [ 0] reg5 + [ 23] range 5, d + [ 0] reg5 + + CU [ e0] base: 0x00000000004004a0 + [ 46] range 12, 1a + [ 0] breg5 0 DWARF section [34] '.debug_ranges' at offset 0xd94: - [ 0] 000000000000000000..0x0000000000000002 - 0x0000000000000005..0x000000000000000d - [ 30] 0x000000000000000d..0x000000000000000f - 0x0000000000000012..0x000000000000001a + + CU [ b] base: 0x0000000000400480 + [ 0] range 0, 2 + range 5, d + + CU [ e0] base: 0x00000000004004a0 + [ 30] range d, f + range 12, 1a +EOF + +# .debug_rnglists (DWARF5), see tests/testfile-dwarf-45.source +testfiles testfile-dwarf-5 +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc testfile-dwarf-5<<\EOF + +DWARF section [31] '.debug_loclists' at offset 0x1c0c: +Table at Offset 0x0: + + Length: 96 + DWARF version: 5 + Address size: 8 + Segment size: 0 + Offset entries: 0 + CU [ c] base: 0x0000000000400510 <foo> + + Offset: c, Index: 0 + offset_pair 0, a + 0x0000000000400510 <foo>.. + 0x0000000000400519 <foo+0x9> + [ 0] reg5 + offset_pair a, 34 + 0x000000000040051a <foo+0xa>.. + 0x0000000000400543 <foo+0x33> + [ 0] entry_value: + [ 0] reg5 + [ 3] stack_value + end_of_list + + Offset: 1a, Index: e + offset_pair 1b, 2d + 0x000000000040052b <foo+0x1b>.. + 0x000000000040053c <foo+0x2c> + [ 0] addr 0x601038 <m> + end_of_list + + Offset: 28, Index: 1c + offset_pair 1b, 21 + 0x000000000040052b <foo+0x1b>.. + 0x0000000000400530 <foo+0x20> + [ 0] reg5 + end_of_list + + Offset: 2e, Index: 22 + offset_pair 1b, 27 + 0x000000000040052b <foo+0x1b>.. + 0x0000000000400536 <foo+0x26> + [ 0] reg5 + offset_pair 29, 2d + 0x0000000000400539 <foo+0x29>.. + 0x000000000040053c <foo+0x2c> + [ 0] reg5 + end_of_list + + Offset: 39, Index: 2d + offset_pair 21, 27 + 0x0000000000400531 <foo+0x21>.. + 0x0000000000400536 <foo+0x26> + [ 0] reg5 + offset_pair 29, 2d + 0x0000000000400539 <foo+0x29>.. + 0x000000000040053c <foo+0x2c> + [ 0] reg5 + end_of_list + + Offset: 44, Index: 38 + offset_pair 21, 2d + 0x0000000000400531 <foo+0x21>.. + 0x000000000040053c <foo+0x2c> + [ 0] reg5 + end_of_list + + Offset: 4a, Index: 3e + offset_pair 2d, 33 + 0x000000000040053d <foo+0x2d>.. + 0x0000000000400542 <foo+0x32> + [ 0] reg5 + end_of_list + + Offset: 50, Index: 44 + offset_pair 40, 4f + 0x0000000000400550 <baz>.. + 0x000000000040055e <baz+0xe> + [ 0] reg5 + offset_pair 4f, 51 + 0x000000000040055f <baz+0xf>.. + 0x0000000000400560 <baz+0x10> + [ 0] entry_value: + [ 0] reg5 + [ 3] stack_value + end_of_list + + Offset: 5e, Index: 52 + offset_pair 40, 50 + 0x0000000000400550 <baz>.. + 0x000000000040055f <baz+0xf> + [ 0] reg5 + end_of_list + +Table at Offset 0x64: + + Length: 159 + DWARF version: 5 + Address size: 8 + Segment size: 0 + Offset entries: 0 + CU [ 218] base: 000000000000000000 + + Offset: 70, Index: 0 + base_address 0x400410 + 0x0000000000400410 <main> + offset_pair 0, 14 + 0x0000000000400410 <main>.. + 0x0000000000400423 <main+0x13> + [ 0] reg5 + offset_pair 14, 20 + 0x0000000000400424 <main+0x14>.. + 0x000000000040042f <main+0x1f> + [ 0] entry_value: + [ 0] reg5 + [ 3] stack_value + end_of_list + + Offset: 87, Index: 17 + base_address 0x400410 + 0x0000000000400410 <main> + offset_pair 0, 18 + 0x0000000000400410 <main>.. + 0x0000000000400427 <main+0x17> + [ 0] reg4 + offset_pair 18, 20 + 0x0000000000400428 <main+0x18>.. + 0x000000000040042f <main+0x1f> + [ 0] entry_value: + [ 0] reg4 + [ 3] stack_value + end_of_list + + Offset: 9e, Index: 2e + start_length 0x400421, 7 + 0x0000000000400421 <main+0x11>.. + 0x0000000000400427 <main+0x17> + [ 0] reg0 + end_of_list + + Offset: ab, Index: 3b + base_address 0x400570 + 0x0000000000400570 <calc> + offset_pair 0, 8 + 0x0000000000400570 <calc>.. + 0x0000000000400577 <calc+0x7> + [ 0] reg5 + offset_pair 8, 2b + 0x0000000000400578 <calc+0x8>.. + 0x000000000040059a <calc+0x2a> + [ 0] entry_value: + [ 0] reg5 + [ 3] stack_value + end_of_list + + Offset: c2, Index: 52 + start_length 0x400588, b + 0x0000000000400588 <calc+0x18>.. + 0x0000000000400592 <calc+0x22> + [ 0] reg0 + end_of_list + + Offset: cf, Index: 5f + base_address 0x400588 + 0x0000000000400588 <calc+0x18> + offset_pair 0, 2 + 0x0000000000400588 <calc+0x18>.. + 0x0000000000400589 <calc+0x19> + [ 0] reg1 + offset_pair 2, 7 + 0x000000000040058a <calc+0x1a>.. + 0x000000000040058e <calc+0x1e> + [ 0] reg5 + offset_pair 7, b + 0x000000000040058f <calc+0x1f>.. + 0x0000000000400592 <calc+0x22> + [ 0] entry_value: + [ 0] reg5 + [ 3] deref_size 1 + [ 5] const1u 56 + [ 7] shl + [ 8] const1u 56 + [10] shra + [11] stack_value + end_of_list + + Offset: f3, Index: 83 + base_address 0x400588 + 0x0000000000400588 <calc+0x18> + offset_pair 0, 2 + 0x0000000000400588 <calc+0x18>.. + 0x0000000000400589 <calc+0x19> + [ 0] reg1 + offset_pair 2, b + 0x000000000040058a <calc+0x1a>.. + 0x0000000000400592 <calc+0x22> + [ 0] reg5 + end_of_list + +EOF + +# Same as above, but for DWARF4, note completely different encoding, but +# the information is the same (check with diff -uwb). +testfiles testfile-dwarf-4 +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc testfile-dwarf-4<<\EOF + +DWARF section [31] '.debug_loc' at offset 0x1c86: + + CU [ b] base: 0x0000000000400510 <foo> + [ 0] range 0, a + 0x0000000000400510 <foo>.. + 0x0000000000400519 <foo+0x9> + [ 0] reg5 + range a, 34 + 0x000000000040051a <foo+0xa>.. + 0x0000000000400543 <foo+0x33> + [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] stack_value + [ 39] range 1b, 2d + 0x000000000040052b <foo+0x1b>.. + 0x000000000040053c <foo+0x2c> + [ 0] addr 0x601038 <m> + [ 64] range 1b, 21 + 0x000000000040052b <foo+0x1b>.. + 0x0000000000400530 <foo+0x20> + [ 0] reg5 + [ 87] range 1b, 27 + 0x000000000040052b <foo+0x1b>.. + 0x0000000000400536 <foo+0x26> + [ 0] reg5 + range 29, 2d + 0x0000000000400539 <foo+0x29>.. + 0x000000000040053c <foo+0x2c> + [ 0] reg5 + [ bd] range 21, 27 + 0x0000000000400531 <foo+0x21>.. + 0x0000000000400536 <foo+0x26> + [ 0] reg5 + range 29, 2d + 0x0000000000400539 <foo+0x29>.. + 0x000000000040053c <foo+0x2c> + [ 0] reg5 + [ f3] range 21, 2d + 0x0000000000400531 <foo+0x21>.. + 0x000000000040053c <foo+0x2c> + [ 0] reg5 + [ 116] range 2d, 33 + 0x000000000040053d <foo+0x2d>.. + 0x0000000000400542 <foo+0x32> + [ 0] reg5 + [ 139] range 40, 4f + 0x0000000000400550 <baz>.. + 0x000000000040055e <baz+0xe> + [ 0] reg5 + range 4f, 51 + 0x000000000040055f <baz+0xf>.. + 0x0000000000400560 <baz+0x10> + [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] stack_value + [ 172] range 40, 50 + 0x0000000000400550 <baz>.. + 0x000000000040055f <baz+0xf> + [ 0] reg5 + + CU [ 21c] base: 000000000000000000 + [ 195] range 400410, 400424 + 0x0000000000400410 <main>.. + 0x0000000000400423 <main+0x13> + [ 0] reg5 + range 400424, 400430 + 0x0000000000400424 <main+0x14>.. + 0x000000000040042f <main+0x1f> + [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] stack_value + [ 1ce] range 400410, 400428 + 0x0000000000400410 <main>.. + 0x0000000000400427 <main+0x17> + [ 0] reg4 + range 400428, 400430 + 0x0000000000400428 <main+0x18>.. + 0x000000000040042f <main+0x1f> + [ 0] GNU_entry_value: + [ 0] reg4 + [ 3] stack_value + [ 207] range 400421, 400428 + 0x0000000000400421 <main+0x11>.. + 0x0000000000400427 <main+0x17> + [ 0] reg0 + [ 22a] range 400570, 400578 + 0x0000000000400570 <calc>.. + 0x0000000000400577 <calc+0x7> + [ 0] reg5 + range 400578, 40059b + 0x0000000000400578 <calc+0x8>.. + 0x000000000040059a <calc+0x2a> + [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] stack_value + [ 263] range 400588, 400593 + 0x0000000000400588 <calc+0x18>.. + 0x0000000000400592 <calc+0x22> + [ 0] reg0 + [ 286] range 400588, 40058a + 0x0000000000400588 <calc+0x18>.. + 0x0000000000400589 <calc+0x19> + [ 0] reg1 + range 40058a, 40058f + 0x000000000040058a <calc+0x1a>.. + 0x000000000040058e <calc+0x1e> + [ 0] reg5 + range 40058f, 400593 + 0x000000000040058f <calc+0x1f>.. + 0x0000000000400592 <calc+0x22> + [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] deref_size 1 + [ 5] const1u 56 + [ 7] shl + [ 8] const1u 56 + [10] shra + [11] stack_value + [ 2da] range 400588, 40058a + 0x0000000000400588 <calc+0x18>.. + 0x0000000000400589 <calc+0x19> + [ 0] reg1 + range 40058a, 400593 + 0x000000000040058a <calc+0x1a>.. + 0x0000000000400592 <calc+0x22> + [ 0] reg5 +EOF + +# Split DWARF5 variant. Note that the .debug_loclists moved to the .dwo file +# and now uses an index and addrx indirections. +testfiles testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc --dwarf-skeleton=testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo <<\EOF + +testfile-hello5.dwo: + + +DWARF section [ 3] '.debug_loclists.dwo' at offset 0x236: +Table at Offset 0x0: + + Length: 125 + DWARF version: 5 + Address size: 8 + Segment size: 0 + Offset entries: 9 + CU [ 14] base: 0x0000000000401160 <foo> + + Offsets starting at 0xc: + [ 0] 0x24 + [ 1] 0x32 + [ 2] 0x39 + [ 3] 0x3f + [ 4] 0x4a + [ 5] 0x55 + [ 6] 0x5b + [ 7] 0x61 + [ 8] 0x6f + + Offset: 30, Index: 24 + startx_length f, a + 0x0000000000401160 <foo>.. + 0x0000000000401169 <foo+0x9> + [ 0] reg5 + startx_length 0, 2a + 0x000000000040116a <foo+0xa>.. + 0x0000000000401193 <foo+0x33> + [ 0] entry_value: + [ 0] reg5 + [ 3] stack_value + end_of_list + + Offset: 3e, Index: 32 + startx_length 11, 12 + 0x000000000040117b <foo+0x1b>.. + 0x000000000040118c <foo+0x2c> + [ 0] addrx [18] 0x404038 <m> + end_of_list + + Offset: 45, Index: 39 + startx_length 11, 6 + 0x000000000040117b <foo+0x1b>.. + 0x0000000000401180 <foo+0x20> + [ 0] reg5 + end_of_list + + Offset: 4b, Index: 3f + startx_length 11, c + 0x000000000040117b <foo+0x1b>.. + 0x0000000000401186 <foo+0x26> + [ 0] reg5 + startx_length 1, 4 + 0x0000000000401189 <foo+0x29>.. + 0x000000000040118c <foo+0x2c> + [ 0] reg5 + end_of_list + + Offset: 56, Index: 4a + startx_length 4, 6 + 0x0000000000401181 <foo+0x21>.. + 0x0000000000401186 <foo+0x26> + [ 0] reg5 + startx_length 1, 4 + 0x0000000000401189 <foo+0x29>.. + 0x000000000040118c <foo+0x2c> + [ 0] reg5 + end_of_list + + Offset: 61, Index: 55 + startx_length 4, c + 0x0000000000401181 <foo+0x21>.. + 0x000000000040118c <foo+0x2c> + [ 0] reg5 + end_of_list + + Offset: 67, Index: 5b + startx_length 2, 6 + 0x000000000040118d <foo+0x2d>.. + 0x0000000000401192 <foo+0x32> + [ 0] reg5 + end_of_list + + Offset: 6d, Index: 61 + startx_length 9, f + 0x00000000004011a0 <baz>.. + 0x00000000004011ae <baz+0xe> + [ 0] reg5 + startx_length 5, 2 + 0x00000000004011af <baz+0xf>.. + 0x00000000004011b0 <baz+0x10> + [ 0] entry_value: + [ 0] reg5 + [ 3] stack_value + end_of_list + + Offset: 7b, Index: 6f + startx_length 9, 10 + 0x00000000004011a0 <baz>.. + 0x00000000004011af <baz+0xf> + [ 0] reg5 + end_of_list + + +testfile-world5.dwo: + + +DWARF section [ 3] '.debug_loclists.dwo' at offset 0x217: +Table at Offset 0x0: + + Length: 128 + DWARF version: 5 + Address size: 8 + Segment size: 0 + Offset entries: 7 + CU [ 14] base: 000000000000000000 + + Offsets starting at 0xc: + [ 0] 0x1c + [ 1] 0x2a + [ 2] 0x38 + [ 3] 0x3e + [ 4] 0x4c + [ 5] 0x52 + [ 6] 0x6d + + Offset: 28, Index: 1c + startx_length 2, 14 + 0x0000000000401060 <main>.. + 0x0000000000401073 <main+0x13> + [ 0] reg5 + startx_length 4, c + 0x0000000000401074 <main+0x14>.. + 0x000000000040107f <main+0x1f> + [ 0] entry_value: + [ 0] reg5 + [ 3] stack_value + end_of_list + + Offset: 36, Index: 2a + startx_length 2, 18 + 0x0000000000401060 <main>.. + 0x0000000000401077 <main+0x17> + [ 0] reg4 + startx_length 7, 6 + 0x0000000000401078 <main+0x18>.. + 0x000000000040107d <main+0x1d> + [ 0] entry_value: + [ 0] reg4 + [ 3] stack_value + end_of_list + + Offset: 44, Index: 38 + startx_length 3, 7 + 0x0000000000401071 <main+0x11>.. + 0x0000000000401077 <main+0x17> + [ 0] reg0 + end_of_list + + Offset: 4a, Index: 3e + startx_length d, 8 + 0x00000000004011c0 <calc>.. + 0x00000000004011c7 <calc+0x7> + [ 0] reg5 + startx_length e, 23 + 0x00000000004011c8 <calc+0x8>.. + 0x00000000004011ea <calc+0x2a> + [ 0] entry_value: + [ 0] reg5 + [ 3] stack_value + end_of_list + + Offset: 58, Index: 4c + startx_length f, b + 0x00000000004011d8 <calc+0x18>.. + 0x00000000004011e2 <calc+0x22> + [ 0] reg0 + end_of_list + + Offset: 5e, Index: 52 + startx_length f, 2 + 0x00000000004011d8 <calc+0x18>.. + 0x00000000004011d9 <calc+0x19> + [ 0] reg1 + startx_length 10, 5 + 0x00000000004011da <calc+0x1a>.. + 0x00000000004011de <calc+0x1e> + [ 0] reg5 + startx_length 0, 4 + 0x00000000004011df <calc+0x1f>.. + 0x00000000004011e2 <calc+0x22> + [ 0] entry_value: + [ 0] reg5 + [ 3] deref_size 1 + [ 5] const1u 56 + [ 7] shl + [ 8] const1u 56 + [10] shra + [11] stack_value + end_of_list + + Offset: 79, Index: 6d + startx_length f, 2 + 0x00000000004011d8 <calc+0x18>.. + 0x00000000004011d9 <calc+0x19> + [ 0] reg1 + startx_length 10, 9 + 0x00000000004011da <calc+0x1a>.. + 0x00000000004011e2 <calc+0x22> + [ 0] reg5 + end_of_list + +EOF + +# GNU DebugFission split-dwarf variant. Still uses .debug_loc, but now in +# .dwo file, with somewhat similar, but different encoding from DWARF5. +testfiles testfile-splitdwarf-4 testfile-hello4.dwo testfile-world4.dwo +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc --dwarf-skeleton=testfile-splitdwarf-4 testfile-hello4.dwo testfile-world4.dwo <<\EOF + +testfile-hello4.dwo: + + +DWARF section [ 3] '.debug_loc.dwo' at offset 0x253: + + CU [ b] base: 0x0000000000401160 <foo> + [ 0] range 401160, 40116a + 0x0000000000401160 <foo>.. + 0x0000000000401169 <foo+0x9> + [ 0] reg5 + range 40116a, 401194 + 0x000000000040116a <foo+0xa>.. + 0x0000000000401193 <foo+0x33> + [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] stack_value + [ 16] range 40117b, 40118d + 0x000000000040117b <foo+0x1b>.. + 0x000000000040118c <foo+0x2c> + [ 0] GNU_addr_index [18] 0x404038 <m> + [ 21] range 40117b, 401181 + 0x000000000040117b <foo+0x1b>.. + 0x0000000000401180 <foo+0x20> + [ 0] reg5 + [ 2b] range 40117b, 401187 + 0x000000000040117b <foo+0x1b>.. + 0x0000000000401186 <foo+0x26> + [ 0] reg5 + range 401189, 40118d + 0x0000000000401189 <foo+0x29>.. + 0x000000000040118c <foo+0x2c> + [ 0] reg5 + [ 3e] range 401181, 401187 + 0x0000000000401181 <foo+0x21>.. + 0x0000000000401186 <foo+0x26> + [ 0] reg5 + range 401189, 40118d + 0x0000000000401189 <foo+0x29>.. + 0x000000000040118c <foo+0x2c> + [ 0] reg5 + [ 51] range 401181, 40118d + 0x0000000000401181 <foo+0x21>.. + 0x000000000040118c <foo+0x2c> + [ 0] reg5 + [ 5b] range 40118d, 401193 + 0x000000000040118d <foo+0x2d>.. + 0x0000000000401192 <foo+0x32> + [ 0] reg5 + [ 65] range 4011a0, 4011af + 0x00000000004011a0 <baz>.. + 0x00000000004011ae <baz+0xe> + [ 0] reg5 + range 4011af, 4011b1 + 0x00000000004011af <baz+0xf>.. + 0x00000000004011b0 <baz+0x10> + [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] stack_value + [ 7b] range 4011a0, 4011b0 + 0x00000000004011a0 <baz>.. + 0x00000000004011af <baz+0xf> + [ 0] reg5 + +testfile-world4.dwo: + + +DWARF section [ 3] '.debug_loc.dwo' at offset 0x225: + + CU [ b] base: 000000000000000000 + [ 0] range 401060, 401074 + 0x0000000000401060 <main>.. + 0x0000000000401073 <main+0x13> + [ 0] reg5 + range 401074, 401080 + 0x0000000000401074 <main+0x14>.. + 0x000000000040107f <main+0x1f> + [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] stack_value + [ 16] range 401060, 401078 + 0x0000000000401060 <main>.. + 0x0000000000401077 <main+0x17> + [ 0] reg4 + range 401078, 40107e + 0x0000000000401078 <main+0x18>.. + 0x000000000040107d <main+0x1d> + [ 0] GNU_entry_value: + [ 0] reg4 + [ 3] stack_value + [ 2c] range 401071, 401078 + 0x0000000000401071 <main+0x11>.. + 0x0000000000401077 <main+0x17> + [ 0] reg0 + [ 36] range 4011c0, 4011c8 + 0x00000000004011c0 <calc>.. + 0x00000000004011c7 <calc+0x7> + [ 0] reg5 + range 4011c8, 4011eb + 0x00000000004011c8 <calc+0x8>.. + 0x00000000004011ea <calc+0x2a> + [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] stack_value + [ 4c] range 4011d8, 4011e3 + 0x00000000004011d8 <calc+0x18>.. + 0x00000000004011e2 <calc+0x22> + [ 0] reg0 + [ 56] range 4011d8, 4011da + 0x00000000004011d8 <calc+0x18>.. + 0x00000000004011d9 <calc+0x19> + [ 0] reg1 + range 4011da, 4011df + 0x00000000004011da <calc+0x1a>.. + 0x00000000004011de <calc+0x1e> + [ 0] reg5 + range 4011df, 4011e3 + 0x00000000004011df <calc+0x1f>.. + 0x00000000004011e2 <calc+0x22> + [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] deref_size 1 + [ 5] const1u 56 + [ 7] shl + [ 8] const1u 56 + [10] shra + [11] stack_value + [ 7d] range 4011d8, 4011da + 0x00000000004011d8 <calc+0x18>.. + 0x00000000004011d9 <calc+0x19> + [ 0] reg1 + range 4011da, 4011e3 + 0x00000000004011da <calc+0x1a>.. + 0x00000000004011e2 <calc+0x22> + [ 0] reg5 +EOF + +# Partial dwarf-4 and partial GNU DebugFission split-dwarf. +# +# = popcount.c = +# +# int popcount (unsigned char u) +# { +# int c = 0; +# while (u != 0) +# { +# if ((u & 1) == 1) +# c++; +# u >>= 1; +# } +# return c; +# } +# +# = splitdwarf4-not-split4.c = +# +# extern int popcount (unsigned char); +# +# int main (int argc, char **argv) +# { +# int i; +# int p = argc; +# for (i = 0; i < argc; ++i) +# p += popcount (argv[i][0]); +# i += p; +# return i; +# } +# +# gcc -gdwarf-4 -O2 -c popcount.c +# gcc -gdwarf-4 -gsplit-dwarf -O2 -c splitdwarf4-not-split4.c +# gcc -o testfile-splitdwarf4-not-split4 splitdwarf4-not-split4.o popcount.o +# eu-strip -f testfile-splitdwarf4-not-split4.debug \ +# testfile-splitdwarf4-not-split4 + +testfiles testfile-splitdwarf4-not-split4.debug +testfiles splitdwarf4-not-split4.dwo + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info+ --debug-dump=loc testfile-splitdwarf4-not-split4.debug <<\EOF + +DWARF section [28] '.debug_info' at offset 0x330: + [Offset] + Compilation unit at offset 0: + Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 + Unit type: skeleton (4), Unit id: 0x3d909d7bd0e69c0b + [ b] compile_unit abbrev: 1 + ranges (sec_offset) range list [ 0] + low_pc (addr) 000000000000000000 + stmt_list (sec_offset) 0 + GNU_dwo_name (strp) "splitdwarf4-not-split4.dwo" + comp_dir (strp) "/tmp" + GNU_pubnames (flag_present) yes + GNU_addr_base (sec_offset) address base [ 0] + GNU_dwo_id (data8) 0x3d909d7bd0e69c0b + GNU_ranges_base (sec_offset) 0 + Split compilation unit at offset 0: + Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 + Unit type: skeleton (4), Unit id: 0x3d909d7bd0e69c0b + { b} compile_unit abbrev: 1 + producer (GNU_str_index) "GNU C17 9.0.0 20180528 (experimental) -mtune=generic -march=x86-64 -gdwarf-4 -gsplit-dwarf -O2" + language (data1) C99 (12) + name (GNU_str_index) "splitdwarf4-not-split4.c" + comp_dir (GNU_str_index) "/tmp" + GNU_dwo_id (data8) 0x3d909d7bd0e69c0b + { 18} subprogram abbrev: 2 + external (flag_present) yes + name (GNU_str_index) "main" + decl_file (data1) splitdwarf4-not-split4.c (1) + decl_line (data1) 3 + decl_column (data1) 5 + prototyped (flag_present) yes + type (ref4) { 6d} + low_pc (GNU_addr_index) [4] 0x0000000000401050 <main> + high_pc (data8) 76 (0x000000000040109c <_start>) + frame_base (exprloc) + [ 0] call_frame_cfa + GNU_all_call_sites (flag_present) yes + sibling (ref4) { 6d} + { 30} formal_parameter abbrev: 3 + name (GNU_str_index) "argc" + decl_file (data1) splitdwarf4-not-split4.c (1) + decl_line (data1) 3 + decl_column (data1) 15 + type (ref4) { 6d} + location (sec_offset) location list [ 0] + { 3d} formal_parameter abbrev: 3 + name (GNU_str_index) "argv" + decl_file (data1) splitdwarf4-not-split4.c (1) + decl_line (data1) 3 + decl_column (data1) 28 + type (ref4) { 74} + location (sec_offset) location list [ 28] + { 4a} variable abbrev: 4 + name (string) "i" + decl_file (data1) splitdwarf4-not-split4.c (1) + decl_line (data1) 5 + decl_column (data1) 7 + type (ref4) { 6d} + location (sec_offset) location list [ 47] + { 58} variable abbrev: 4 + name (string) "p" + decl_file (data1) splitdwarf4-not-split4.c (1) + decl_line (data1) 6 + decl_column (data1) 7 + type (ref4) { 6d} + location (sec_offset) location list [ 73] + { 66} GNU_call_site abbrev: 5 + low_pc (GNU_addr_index) [1] 0x000000000040107f <main+0x2f> + abstract_origin (ref4) { 84} + { 6d} base_type abbrev: 6 + byte_size (data1) 4 + encoding (data1) signed (5) + name (string) "int" + { 74} pointer_type abbrev: 7 + byte_size (data1) 8 + type (ref4) { 7a} + { 7a} pointer_type abbrev: 7 + byte_size (data1) 8 + type (ref4) { 80} + { 80} base_type abbrev: 8 + byte_size (data1) 1 + encoding (data1) signed_char (6) + name (GNU_str_index) "char" + { 84} subprogram abbrev: 9 + external (flag_present) yes + declaration (flag_present) yes + linkage_name (GNU_str_index) "popcount" + name (GNU_str_index) "popcount" + decl_file (data1) splitdwarf4-not-split4.c (1) + decl_line (data1) 1 + decl_column (data1) 12 + Compilation unit at offset 52: + Version: 4, Abbreviation section offset: 29, Address size: 8, Offset size: 4 + [ 3f] compile_unit abbrev: 1 + producer (strp) "GNU C17 9.0.0 20180528 (experimental) -mtune=generic -march=x86-64 -gdwarf-4 -O2" + language (data1) C99 (12) + name (strp) "popcount.c" + comp_dir (strp) "/tmp" + low_pc (addr) 0x0000000000401180 <popcount> + high_pc (data8) 33 (0x00000000004011a1) + stmt_list (sec_offset) 145 + [ 61] subprogram abbrev: 2 + external (flag_present) yes + name (strp) "popcount" + decl_file (data1) popcount.c (1) + decl_line (data1) 1 + decl_column (data1) 5 + prototyped (flag_present) yes + type (ref4) [ a0] + low_pc (addr) 0x0000000000401180 <popcount> + high_pc (data8) 33 (0x00000000004011a1) + frame_base (exprloc) + [ 0] call_frame_cfa + GNU_all_call_sites (flag_present) yes + sibling (ref4) [ a0] + [ 83] formal_parameter abbrev: 3 + name (string) "u" + decl_file (data1) popcount.c (1) + decl_line (data1) 1 + decl_column (data1) 29 + type (ref4) [ a7] + location (sec_offset) location list [ 0] + [ 91] variable abbrev: 4 + name (string) "c" + decl_file (data1) popcount.c (1) + decl_line (data1) 3 + decl_column (data1) 7 + type (ref4) [ a0] + location (sec_offset) location list [ 60] + [ a0] base_type abbrev: 5 + byte_size (data1) 4 + encoding (data1) signed (5) + name (string) "int" + [ a7] base_type abbrev: 6 + byte_size (data1) 1 + encoding (data1) unsigned_char (8) + name (strp) "unsigned char" + +DWARF section [32] '.debug_loc' at offset 0x5ef: + + CU [ 3f] base: 0x0000000000401180 <popcount> + [ 0] range 0, 9 + 0x0000000000401180 <popcount>.. + 0x0000000000401188 <popcount+0x8> + [ 0] reg5 + range 9, 1b + 0x0000000000401189 <popcount+0x9>.. + 0x000000000040119a <popcount+0x1a> + [ 0] reg1 + range 1b, 1d + 0x000000000040119b <popcount+0x1b>.. + 0x000000000040119c <popcount+0x1c> + [ 0] breg1 0 + [ 2] lit1 + [ 3] shr + [ 4] stack_value + range 1d, 21 + 0x000000000040119d <popcount+0x1d>.. + 0x00000000004011a0 <popcount+0x20> + [ 0] reg1 + [ 60] range 0, 9 + 0x0000000000401180 <popcount>.. + 0x0000000000401188 <popcount+0x8> + [ 0] lit0 + [ 1] stack_value + range 9, 20 + 0x0000000000401189 <popcount+0x9>.. + 0x000000000040119f <popcount+0x1f> + [ 0] reg0 + range 20, 21 + 0x00000000004011a0 <popcount+0x20>.. + 0x00000000004011a0 <popcount+0x20> + [ 0] lit0 + [ 1] stack_value +EOF + +testrun_compare ${abs_top_builddir}/src/readelf --dwarf-skeleton=testfile-splitdwarf4-not-split4.debug --debug-dump=loc splitdwarf4-not-split4.dwo <<\EOF + +DWARF section [ 3] '.debug_loc.dwo' at offset 0x15b: + + CU [ b] base: 000000000000000000 + [ 0] range 401050, 40106e + 0x0000000000401050 <main>.. + 0x000000000040106d <main+0x1d> + [ 0] reg5 + range 40106e, 401086 + 0x000000000040106e <main+0x1e>.. + 0x0000000000401085 <main+0x35> + [ 0] reg12 + range 401086, 401095 + 0x0000000000401086 <main+0x36>.. + 0x0000000000401094 <main+0x44> + [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] stack_value + range 401095, 40109c + 0x0000000000401095 <main+0x45>.. + 0x000000000040109b <main+0x4b> + [ 0] reg5 + [ 28] range 401050, 40106e + 0x0000000000401050 <main>.. + 0x000000000040106d <main+0x1d> + [ 0] reg4 + range 40106e, 401095 + 0x000000000040106e <main+0x1e>.. + 0x0000000000401094 <main+0x44> + [ 0] GNU_entry_value: + [ 0] reg4 + [ 3] stack_value + range 401095, 40109c + 0x0000000000401095 <main+0x45>.. + 0x000000000040109b <main+0x4b> + [ 0] reg4 + [ 47] range 401050, 40106e + 0x0000000000401050 <main>.. + 0x000000000040106d <main+0x1d> + [ 0] lit0 + [ 1] stack_value + range 401086, 40108e + 0x0000000000401086 <main+0x36>.. + 0x000000000040108d <main+0x3d> + [ 0] breg12 0 + [ 2] breg6 0 + [ 4] plus + [ 5] stack_value + range 40108e, 401095 + 0x000000000040108e <main+0x3e>.. + 0x0000000000401094 <main+0x44> + [ 0] reg0 + range 401095, 40109c + 0x0000000000401095 <main+0x45>.. + 0x000000000040109b <main+0x4b> + [ 0] lit0 + [ 1] stack_value + [ 73] range 401050, 40106e + 0x0000000000401050 <main>.. + 0x000000000040106d <main+0x1d> + [ 0] reg5 + range 40106e, 401090 + 0x000000000040106e <main+0x1e>.. + 0x000000000040108f <main+0x3f> + [ 0] reg6 + range 401095, 40109c + 0x0000000000401095 <main+0x45>.. + 0x000000000040109b <main+0x4b> + [ 0] reg5 EOF exit 0 diff --git a/tests/run-readelf-ranges.sh b/tests/run-readelf-ranges.sh new file mode 100755 index 00000000..ca3e3024 --- /dev/null +++ b/tests/run-readelf-ranges.sh @@ -0,0 +1,236 @@ +#! /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-readelf-loc.sh + +testfiles testfileloc + +# Process values as offsets from base addresses and resolve to symbols. +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=ranges testfileloc<<\EOF + +DWARF section [34] '.debug_ranges' at offset 0xd94: + + CU [ b] base: 0x0000000000400480 <main> + [ 0] range 0, 2 + 0x0000000000400480 <main>.. + 0x0000000000400481 <main+0x1> + range 5, d + 0x0000000000400485 <main+0x5>.. + 0x000000000040048c <main+0xc> + + CU [ e0] base: 0x00000000004004a0 <say> + [ 30] range d, f + 0x00000000004004ad <say+0xd>.. + 0x00000000004004ae <say+0xe> + range 12, 1a + 0x00000000004004b2 <say+0x12>.. + 0x00000000004004b9 <say+0x19> +EOF + +# Don't resolve addresses to symbols. +testrun_compare ${abs_top_builddir}/src/readelf -N --debug-dump=ranges testfileloc<<\EOF + +DWARF section [34] '.debug_ranges' at offset 0xd94: + + CU [ b] base: 0x0000000000400480 + [ 0] range 0, 2 + 0x0000000000400480.. + 0x0000000000400481 + range 5, d + 0x0000000000400485.. + 0x000000000040048c + + CU [ e0] base: 0x00000000004004a0 + [ 30] range d, f + 0x00000000004004ad.. + 0x00000000004004ae + range 12, 1a + 0x00000000004004b2.. + 0x00000000004004b9 +EOF + +# Produce "raw" unprocessed content. +testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=ranges testfileloc<<\EOF + +DWARF section [34] '.debug_ranges' at offset 0xd94: + + CU [ b] base: 0x0000000000400480 + [ 0] range 0, 2 + range 5, d + + CU [ e0] base: 0x00000000004004a0 + [ 30] range d, f + range 12, 1a +EOF + +# .debug_rnglists (DWARF5), see tests/testfile-dwarf-45.source +testfiles testfile-dwarf-5 +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=ranges testfile-dwarf-5<<\EOF + +DWARF section [33] '.debug_rnglists' at offset 0x1d9a: +Table at Offset 0x0: + + Length: 45 + DWARF version: 5 + Address size: 8 + Segment size: 0 + Offset entries: 0 + CU [ 218] base: 000000000000000000 + + Offset: c, Index: 0 + base_address 0x400583 + 0x0000000000400583 <calc+0x13> + offset_pair 0, 2 + 0x0000000000400583 <calc+0x13>.. + 0x0000000000400584 <calc+0x14> + offset_pair 5, 15 + 0x0000000000400588 <calc+0x18>.. + 0x0000000000400597 <calc+0x27> + end_of_list + + Offset: 1c, Index: 10 + start_length 0x400570, 2b + 0x0000000000400570 <calc>.. + 0x000000000040059a <calc+0x2a> + start_length 0x400410, 20 + 0x0000000000400410 <main>.. + 0x000000000040042f <main+0x1f> + end_of_list + +EOF + +# Same as above, but for DWARF4, note no header, and base address is not +# given, but ranges are the same. +testfiles testfile-dwarf-4 +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=ranges testfile-dwarf-4<<\EOF + +DWARF section [32] '.debug_ranges' at offset 0x1f96: + + CU [ 21c] base: 000000000000000000 + [ 0] range 400583, 400585 + 0x0000000000400583 <calc+0x13>.. + 0x0000000000400584 <calc+0x14> + range 400588, 400598 + 0x0000000000400588 <calc+0x18>.. + 0x0000000000400597 <calc+0x27> + [ 30] range 400570, 40059b + 0x0000000000400570 <calc>.. + 0x000000000040059a <calc+0x2a> + range 400410, 400430 + 0x0000000000400410 <main>.. + 0x000000000040042f <main+0x1f> +EOF + +# Now with split dwarf. See tests/testfile-dwarf-45.source. +# Note that this will have an offsets table that the .dwo can refer to. +testfiles testfile-splitdwarf-5 testfile-hello5.dwo testfile-world5.dwo +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=ranges testfile-splitdwarf-5<<\EOF + +DWARF section [35] '.debug_rnglists' at offset 0x393a: +Table at Offset 0x0: + + Length: 53 + DWARF version: 5 + Address size: 8 + Segment size: 0 + Offset entries: 2 + CU [ 49] base: 000000000000000000 + + Offsets starting at 0xc: + [ 0] 0x8 + [ 1] 0x18 + + Offset: 14, Index: 8 + base_address 0x4011d3 + 0x00000000004011d3 <calc+0x13> + offset_pair 0, 2 + 0x00000000004011d3 <calc+0x13>.. + 0x00000000004011d4 <calc+0x14> + offset_pair 5, 15 + 0x00000000004011d8 <calc+0x18>.. + 0x00000000004011e7 <calc+0x27> + end_of_list + + Offset: 24, Index: 18 + start_length 0x4011c0, 2b + 0x00000000004011c0 <calc>.. + 0x00000000004011ea <calc+0x2a> + start_length 0x401060, 20 + 0x0000000000401060 <main>.. + 0x000000000040107f <main+0x1f> + end_of_list + +EOF + +# Note that the rnglist_base attribute of the second CU points to the offsets +# above 0xc [c]. +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info testfile-splitdwarf-5<<\EOF + +DWARF section [28] '.debug_info' at offset 0x3102: + [Offset] + Compilation unit at offset 0: + Version: 5, Abbreviation section offset: 0, Address size: 8, Offset size: 4 + Unit type: skeleton (4), Unit id: 0xc422aa5c31fec205 + [ 14] skeleton_unit abbrev: 1 + low_pc (addr) 0x0000000000401160 <foo> + high_pc (data8) 81 (0x00000000004011b1) + stmt_list (sec_offset) 0 + dwo_name (strp) "testfile-hello5.dwo" + comp_dir (strp) "/home/mark/src/elfutils/tests" + GNU_pubnames (flag_present) yes + addr_base (sec_offset) address base [ 8] + Compilation unit at offset 53: + Version: 5, Abbreviation section offset: 21, Address size: 8, Offset size: 4 + Unit type: skeleton (4), Unit id: 0xb6c8b9d97e6dfdfe + [ 49] skeleton_unit abbrev: 1 + ranges (sec_offset) range list [ 24] + low_pc (addr) 000000000000000000 + stmt_list (sec_offset) 655 + dwo_name (strp) "testfile-world5.dwo" + comp_dir (strp) "/home/mark/src/elfutils/tests" + GNU_pubnames (flag_present) yes + addr_base (sec_offset) address base [ a8] + rnglists_base (sec_offset) range list [ c] +EOF + +# Same for DWARF4 GNU DebugFission. But now we need to scan the .dwo +# explicitly to know it will use the first ranges. +testfiles testfile-splitdwarf-4 testfile-hello4.dwo testfile-world4.dwo +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=ranges testfile-splitdwarf-4<<\EOF + +DWARF section [32] '.debug_ranges' at offset 0x3611: + + CU [ b] base: 000000000000000000 + [ 0] range 4011d3, 4011d5 + 0x00000000004011d3 <calc+0x13>.. + 0x00000000004011d4 <calc+0x14> + range 4011d8, 4011e8 + 0x00000000004011d8 <calc+0x18>.. + 0x00000000004011e7 <calc+0x27> + + CU [ 3f] base: 000000000000000000 + [ 30] range 4011c0, 4011eb + 0x00000000004011c0 <calc>.. + 0x00000000004011ea <calc+0x2a> + range 401060, 401080 + 0x0000000000401060 <main>.. + 0x000000000040107f <main+0x1f> +EOF + +exit 0 diff --git a/tests/run-readelf-str.sh b/tests/run-readelf-str.sh new file mode 100755 index 00000000..8b894e8d --- /dev/null +++ b/tests/run-readelf-str.sh @@ -0,0 +1,211 @@ +#! /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-splitdwarf-5 +testfiles testfile-hello4.dwo testfile-hello5.dwo +testfiles testfile-world4.dwo testfile-world5.dwo + +# DWARF4 GNU DebugFission No real table header. +# We don't really need the skeleton, but we don't want any Warnings. +testrun_compare ${abs_top_builddir}/src/readelf --dwarf-skeleton testfile-splitdwarf-4 --debug-dump=str testfile-hello4.dwo testfile-world4.dwo<<\EOF + +testfile-hello4.dwo: + + +DWARF section [ 5] '.debug_str_offsets.dwo' at offset 0x335: +Table at offset 0 + Offsets start at 0x0: + [ 0] [ 0] "long long int" + [ 1] [ e] "frob" + [ 2] [ 13] "long unsigned int" + [ 3] [ 25] "/home/mark/src/elfutils/tests" + [ 4] [ 43] "wchar_t" + [ 5] [ 4b] "main" + [ 6] [ 50] "long int" + [ 7] [ 59] "GNU C17 9.0.0 20180515 (experimental) -mtune=generic -march=x86-64 -gdwarf-4 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2" + [ 8] [ e9] "long double" + [ 9] [ f5] "hello.c" + + +DWARF section [ 6] '.debug_str.dwo' at offset 0x35d: + Offset String + [ 0] "long long int" + [ e] "frob" + [ 13] "long unsigned int" + [ 25] "/home/mark/src/elfutils/tests" + [ 43] "wchar_t" + [ 4b] "main" + [ 50] "long int" + [ 59] "GNU C17 9.0.0 20180515 (experimental) -mtune=generic -march=x86-64 -gdwarf-4 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2" + [ e9] "long double" + [ f5] "hello.c" + +testfile-world4.dwo: + + +DWARF section [ 5] '.debug_str_offsets.dwo' at offset 0x2e7: +Table at offset 0 + Offsets start at 0x0: + [ 0] [ 0] "long long unsigned int" + [ 1] [ 17] "/home/mark/src/elfutils/tests" + [ 2] [ 35] "long long int" + [ 3] [ 43] "signed char" + [ 4] [ 4f] "long int" + [ 5] [ 58] "world.c" + [ 6] [ 60] "unsigned int" + [ 7] [ 6d] "long unsigned int" + [ 8] [ 7f] "short unsigned int" + [ 9] [ 92] "frob" + [10] [ 97] "calc" + [11] [ 9c] "unsigned char" + [12] [ aa] "short int" + [13] [ b4] "exit" + [14] [ b9] "GNU C17 9.0.0 20180515 (experimental) -mtune=generic -march=x86-64 -gdwarf-4 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2" + [15] [ 149] "char" + [16] [ 14e] "word" + [17] [ 153] "argv" + [18] [ 158] "argc" + [19] [ 15d] "main" + + +DWARF section [ 6] '.debug_str.dwo' at offset 0x337: + Offset String + [ 0] "long long unsigned int" + [ 17] "/home/mark/src/elfutils/tests" + [ 35] "long long int" + [ 43] "signed char" + [ 4f] "long int" + [ 58] "world.c" + [ 60] "unsigned int" + [ 6d] "long unsigned int" + [ 7f] "short unsigned int" + [ 92] "frob" + [ 97] "calc" + [ 9c] "unsigned char" + [ aa] "short int" + [ b4] "exit" + [ b9] "GNU C17 9.0.0 20180515 (experimental) -mtune=generic -march=x86-64 -gdwarf-4 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2" + [ 149] "char" + [ 14e] "word" + [ 153] "argv" + [ 158] "argc" + [ 15d] "main" +EOF + +# DWARF5 Real table header. +# We don't really need the skeleton, but we don't want any Warnings. +testrun_compare ${abs_top_builddir}/src/readelf --dwarf-skeleton testfile-splitdwarf-5 --debug-dump=str testfile-hello5.dwo testfile-world5.dwo<<\EOF + +testfile-hello5.dwo: + + +DWARF section [ 5] '.debug_str_offsets.dwo' at offset 0x353: +Table at offset 0 + + Length: 44 + Offset size: 4 + DWARF version: 5 + Padding: 0 + + Offsets start at 0x8: + [ 0] [ 0] "long long int" + [ 1] [ e] "frob" + [ 2] [ 13] "long unsigned int" + [ 3] [ 25] "/home/mark/src/elfutils/tests" + [ 4] [ 43] "wchar_t" + [ 5] [ 4b] "main" + [ 6] [ 50] "long int" + [ 7] [ 59] "GNU C17 9.0.0 20180515 (experimental) -mtune=generic -march=x86-64 -gdwarf-5 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2" + [ 8] [ e9] "long double" + [ 9] [ f5] "hello.c" + + +DWARF section [ 6] '.debug_str.dwo' at offset 0x383: + Offset String + [ 0] "long long int" + [ e] "frob" + [ 13] "long unsigned int" + [ 25] "/home/mark/src/elfutils/tests" + [ 43] "wchar_t" + [ 4b] "main" + [ 50] "long int" + [ 59] "GNU C17 9.0.0 20180515 (experimental) -mtune=generic -march=x86-64 -gdwarf-5 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2" + [ e9] "long double" + [ f5] "hello.c" + +testfile-world5.dwo: + + +DWARF section [ 5] '.debug_str_offsets.dwo' at offset 0x313: +Table at offset 0 + + Length: 84 + Offset size: 4 + DWARF version: 5 + Padding: 0 + + Offsets start at 0x8: + [ 0] [ 0] "long long unsigned int" + [ 1] [ 17] "GNU C17 9.0.0 20180515 (experimental) -mtune=generic -march=x86-64 -gdwarf-5 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2" + [ 2] [ a7] "/home/mark/src/elfutils/tests" + [ 3] [ c5] "long long int" + [ 4] [ d3] "signed char" + [ 5] [ df] "long int" + [ 6] [ e8] "world.c" + [ 7] [ f0] "unsigned int" + [ 8] [ fd] "long unsigned int" + [ 9] [ 10f] "short unsigned int" + [10] [ 122] "frob" + [11] [ 127] "calc" + [12] [ 12c] "unsigned char" + [13] [ 13a] "short int" + [14] [ 144] "exit" + [15] [ 149] "char" + [16] [ 14e] "word" + [17] [ 153] "argv" + [18] [ 158] "argc" + [19] [ 15d] "main" + + +DWARF section [ 6] '.debug_str.dwo' at offset 0x36b: + Offset String + [ 0] "long long unsigned int" + [ 17] "GNU C17 9.0.0 20180515 (experimental) -mtune=generic -march=x86-64 -gdwarf-5 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2" + [ a7] "/home/mark/src/elfutils/tests" + [ c5] "long long int" + [ d3] "signed char" + [ df] "long int" + [ e8] "world.c" + [ f0] "unsigned int" + [ fd] "long unsigned int" + [ 10f] "short unsigned int" + [ 122] "frob" + [ 127] "calc" + [ 12c] "unsigned char" + [ 13a] "short int" + [ 144] "exit" + [ 149] "char" + [ 14e] "word" + [ 153] "argv" + [ 158] "argc" + [ 15d] "main" +EOF + +exit 0 diff --git a/tests/run-readelf-twofiles.sh b/tests/run-readelf-twofiles.sh index 46eec7b5..fc5f3e78 100755 --- a/tests/run-readelf-twofiles.sh +++ b/tests/run-readelf-twofiles.sh @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2011 Red Hat, Inc. +# Copyright (C) 2011, 2018 Red Hat, Inc. # This file is part of elfutils. # # This file is free software; you can redistribute it and/or modify @@ -21,4 +21,45 @@ testfiles testfile14 testrun >/dev/null ${abs_top_builddir}/src/readelf -w testfile14 testfile14 +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc testfile14 testfile14 << EOF + +testfile14: + + +DWARF section [33] '.debug_loc' at offset 0xca9: + + CU [ b] base: 0x0000000000400468 <caller> + [ 0] range 34, 35 + 0x000000000040049c <main>.. + 0x000000000040049c <main> + [ 0] breg7 -8 + range 35, 46 + 0x000000000040049d <main+0x1>.. + 0x00000000004004ad <main+0x11> + [ 0] breg7 0 + range 46, 47 + 0x00000000004004ae <main+0x12>.. + 0x00000000004004ae <main+0x12> + [ 0] breg7 -8 + +testfile14: + + +DWARF section [33] '.debug_loc' at offset 0xca9: + + CU [ b] base: 0x0000000000400468 <caller> + [ 0] range 34, 35 + 0x000000000040049c <main>.. + 0x000000000040049c <main> + [ 0] breg7 -8 + range 35, 46 + 0x000000000040049d <main+0x1>.. + 0x00000000004004ad <main+0x11> + [ 0] breg7 0 + range 46, 47 + 0x00000000004004ae <main+0x12>.. + 0x00000000004004ae <main+0x12> + [ 0] breg7 -8 +EOF + exit 0 diff --git a/tests/run-readelf-types.sh b/tests/run-readelf-types.sh new file mode 100755 index 00000000..a7af5734 --- /dev/null +++ b/tests/run-readelf-types.sh @@ -0,0 +1,122 @@ +#! /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 + +# Make sure --debug-dump=info implies .debug_types, even when implicit. +# See run-typeiter.sh +testfiles testfile-debug-types + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=str --debug-dump=info testfile-debug-types<<\EOF + +DWARF section [28] '.debug_info' at offset 0x1089: + [Offset] + Compilation unit at offset 0: + Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 + [ b] compile_unit abbrev: 8 + producer (strp) "GNU C++ 4.8.2 20140120 (Red Hat 4.8.2-16) -mtune=generic -march=x86-64 -g -fdebug-types-section" + language (data1) C_plus_plus (4) + comp_dir (strp) "/home/mark/src/elfutils/tests" + low_pc (addr) 0x00000000004005b0 <main> + high_pc (data8) 11 (0x00000000004005bb) + stmt_list (sec_offset) 0 + [ 29] subprogram abbrev: 9 + external (flag_present) yes + name (strp) "main" + decl_file (data1) <stdin> (1) + decl_line (data1) 1 + type (ref4) [ 46] + low_pc (addr) 0x00000000004005b0 <main> + high_pc (data8) 11 (0x00000000004005bb) + frame_base (exprloc) + [ 0] call_frame_cfa + GNU_all_call_sites (flag_present) yes + [ 46] base_type abbrev: 10 + byte_size (data1) 4 + encoding (data1) signed (5) + name (string) "int" + [ 4d] variable abbrev: 11 + name (string) "a" + decl_file (data1) <stdin> (1) + decl_line (data1) 1 + type (ref_sig8) {18763953736e2de0} + external (flag_present) yes + location (exprloc) + [ 0] addr 0x601030 <a> + [ 64] variable abbrev: 11 + name (string) "b" + decl_file (data1) <stdin> (1) + decl_line (data1) 1 + type (ref_sig8) {7cf9bbf793fcaf13} + external (flag_present) yes + location (exprloc) + [ 0] addr 0x601031 <b> + +DWARF section [31] '.debug_str' at offset 0x11dd: + Offset String + [ 0] "/home/mark/src/elfutils/tests" + [ 1e] "GNU C++ 4.8.2 20140120 (Red Hat 4.8.2-16) -mtune=generic -march=x86-64 -g -fdebug-types-section" + [ 7e] "main" + +DWARF section [32] '.debug_types' at offset 0x1260: + [Offset] + Type unit at offset 0: + Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 + Type signature: 0x7cf9bbf793fcaf13, Type offset: 0x38 [38] + [ 17] type_unit abbrev: 1 + language (data1) C_plus_plus (4) + GNU_odr_signature (data8) 4783233826607187165 + stmt_list (sec_offset) 0 + [ 25] structure_type abbrev: 2 + name (string) "A" + signature (ref_sig8) {18763953736e2de0} + declaration (flag_present) yes + sibling (ref4) [ 38] + [ 34] structure_type abbrev: 3 + name (string) "B" + declaration (flag_present) yes + [ 38] structure_type abbrev: 4 + name (string) "B" + byte_size (data1) 1 + decl_file (data1) <stdin> (1) + decl_line (data1) 1 + specification (ref4) [ 34] + Type unit at offset 67: + Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 + Type signature: 0x18763953736e2de0, Type offset: 0x25 [25] + [ 5a] type_unit abbrev: 1 + language (data1) C_plus_plus (4) + GNU_odr_signature (data8) 16005269134005989797 + stmt_list (sec_offset) 0 + [ 68] structure_type abbrev: 5 + name (string) "A" + byte_size (data1) 1 + decl_file (data1) <stdin> (1) + decl_line (data1) 1 + [ 6e] structure_type abbrev: 6 + name (string) "B" + declaration (flag_present) yes + signature (ref_sig8) {7cf9bbf793fcaf13} + [ 79] member abbrev: 7 + name (string) "x" + decl_file (data1) <stdin> (1) + decl_line (data1) 1 + type (ref4) [ 6e] + data_member_location (data1) 0 +EOF + +exit 0 diff --git a/tests/run-readelf-variant.sh b/tests/run-readelf-variant.sh new file mode 100755 index 00000000..dcc0d5e1 --- /dev/null +++ b/tests/run-readelf-variant.sh @@ -0,0 +1,89 @@ +#! /bin/sh +# Copyright (C) 2017 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 + +# Tests exprloc for an Ada record variants byte_size. + +# = pck.ads +# +# with System; +# +# package Pck is +# +# type One_To_Five is range 1 .. 5; +# +# type Rec (Discr : One_To_Five) is +# record +# case Discr is +# when 1 => Field1 : Integer; +# when 4 => null; +# when 3 => Field3 : Boolean; +# when 5 => null; +# when others => null; +# end case; +# end record; +# +# procedure Do_Nothing (A : System.Address); +# +# end Pck; + +# = pck.adb +# +# package body Pck is +# +# procedure Do_Nothing (A : System.Address) is +# begin +# null; +# end Do_Nothing; +# +# end Pck; + +# = foo.adb +# +# with Pck; use Pck; +# +# procedure Foo is +# +# R : Rec (1); +# +# begin +# Do_Nothing (R'Address); +# end Foo; + +# gnatmake -g -fgnat-encodings=minimal foo.adb -cargs + +testfiles testfile-ada-variant + +tempfiles testfile.temp testfile2.temp + +testrun ${abs_top_builddir}/src/readelf --debug-dump=info \ + testfile-ada-variant > testfile.temp + +grep -A6 byte_size testfile.temp | grep -A6 exprloc > testfile2.temp + +diff -u testfile2.temp - <<EOF + byte_size (exprloc) + [ 0] push_object_address + [ 1] deref_size 1 + [ 3] call4 [ 95] + [ 8] plus_uconst 7 + [10] const1s -4 + [12] and +EOF + +exit 0 diff --git a/tests/run-readelf-zdebug-rel.sh b/tests/run-readelf-zdebug-rel.sh index 1232d63b..3f20078c 100755 --- a/tests/run-readelf-zdebug-rel.sh +++ b/tests/run-readelf-zdebug-rel.sh @@ -51,7 +51,7 @@ DWARF section [ 4] '.debug_info' at offset 0x58: [Offset] Compilation unit at offset 0: Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 - [ b] compile_unit + [ b] compile_unit abbrev: 1 producer (strp) "GNU C11 5.3.1 20151207 (Red Hat 5.3.1-2) -mtune=generic -march=x86-64 -g -Og" language (data1) C99 (12) name (strp) "testfile-zdebug-rel.c" @@ -59,60 +59,60 @@ DWARF section [ 4] '.debug_info' at offset 0x58: low_pc (addr) 000000000000000000 high_pc (data8) 24 (0x0000000000000018) stmt_list (sec_offset) 0 - [ 2d] subprogram + [ 2d] subprogram abbrev: 2 external (flag_present) yes name (strp) "main" - decl_file (data1) 1 + decl_file (data1) testfile-zdebug-rel.c (1) decl_line (data1) 4 prototyped (flag_present) yes type (ref4) [ 80] low_pc (addr) 000000000000000000 high_pc (data8) 24 (0x0000000000000018) frame_base (exprloc) - [ 0] call_frame_cfa + [ 0] call_frame_cfa GNU_all_call_sites (flag_present) yes sibling (ref4) [ 80] - [ 4e] formal_parameter + [ 4e] formal_parameter abbrev: 3 name (strp) "argc" - decl_file (data1) 1 + decl_file (data1) testfile-zdebug-rel.c (1) decl_line (data1) 4 type (ref4) [ 80] location (sec_offset) location list [ 0] - [ 5d] formal_parameter + [ 5d] formal_parameter abbrev: 4 name (strp) "argv" - decl_file (data1) 1 + decl_file (data1) testfile-zdebug-rel.c (1) decl_line (data1) 4 type (ref4) [ 87] location (exprloc) - [ 0] reg4 - [ 6a] variable + [ 0] reg4 + [ 6a] variable abbrev: 5 name (string) "a" - decl_file (data1) 1 + decl_file (data1) testfile-zdebug-rel.c (1) decl_line (data1) 6 type (ref4) [ 9a] - const_value (sdata) -9 - [ 74] variable + const_value (sdata) 18446744073709551607 (-9) + [ 74] variable abbrev: 6 name (string) "b" - decl_file (data1) 1 + decl_file (data1) testfile-zdebug-rel.c (1) decl_line (data1) 7 type (ref4) [ 9a] location (exprloc) - [ 0] reg5 - [ 80] base_type + [ 0] reg5 + [ 80] base_type abbrev: 7 byte_size (data1) 4 encoding (data1) signed (5) name (string) "int" - [ 87] pointer_type + [ 87] pointer_type abbrev: 8 byte_size (data1) 8 type (ref4) [ 8d] - [ 8d] pointer_type + [ 8d] pointer_type abbrev: 8 byte_size (data1) 8 type (ref4) [ 93] - [ 93] base_type + [ 93] base_type abbrev: 9 byte_size (data1) 1 encoding (data1) signed_char (6) name (strp) "char" - [ 9a] base_type + [ 9a] base_type abbrev: 9 byte_size (data1) 8 encoding (data1) unsigned (7) name (strp) "long unsigned int" @@ -127,12 +127,17 @@ cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=i cat > loc.out << \EOF DWARF section [ 7] '.debug_loc' at offset 0x185: - [ 0] 000000000000000000..0x0000000000000003 [ 0] reg5 - 0x0000000000000003..0x0000000000000010 [ 0] breg5 -42 - [ 2] stack_value - 0x0000000000000010..0x0000000000000018 [ 0] GNU_entry_value: - [ 0] reg5 - [ 3] stack_value + + CU [ b] base: 000000000000000000 + [ 0] range 0, 3 + [ 0] reg5 + range 3, 10 + [ 0] breg5 -42 + [ 2] stack_value + range 10, 18 + [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] stack_value EOF cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel.o diff --git a/tests/run-readelf-zdebug.sh b/tests/run-readelf-zdebug.sh index 37cf7eaa..878e0ba8 100755 --- a/tests/run-readelf-zdebug.sh +++ b/tests/run-readelf-zdebug.sh @@ -46,12 +46,17 @@ tempfiles loc.out aranges.out ranges.out macro.out line.out frame.out cat > loc.out << \EOF DWARF section [30] '.debug_loc' at offset 0xa17: - [ 0] 0x00000000004003c0..0x00000000004003c3 [ 0] reg5 - 0x00000000004003c3..0x00000000004003d6 [ 0] breg5 -42 - [ 2] stack_value - 0x00000000004003d6..0x00000000004003d9 [ 0] GNU_entry_value: - [ 0] reg5 - [ 3] stack_value + + CU [ b] base: 000000000000000000 + [ 0] range 4003c0, 4003c3 + [ 0] reg5 + range 4003c3, 4003d6 + [ 0] breg5 -42 + [ 2] stack_value + range 4003d6, 4003d9 + [ 0] GNU_entry_value: + [ 0] reg5 + [ 3] stack_value EOF cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug @@ -80,7 +85,9 @@ cat aranges.out | sed -e "s/.debug_aranges' at offset 0xa65/.zdebug_aranges' at cat > ranges.out << \EOF DWARF section [32] '.debug_ranges' at offset 0xa95: - [ 0] 0x00000000004003c0..0x00000000004003d9 + + CU [ b] base: 000000000000000000 + [ 0] range 4003c0, 4003d9 EOF cat ranges.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=ranges testfile-debug @@ -354,15 +361,17 @@ DWARF section [34] '.debug_line' at offset 0x104c: Table at offset 0: - Length: 70 - DWARF version: 2 - Prologue length: 40 - Minimum instruction length: 1 - Maximum operations per instruction: 1 - Initial value if 'is_stmt': 1 - Line base: -5 - Line range: 14 - Opcode base: 13 + Length: 70 + DWARF version: 2 + Prologue length: 40 + Address size: 8 + Segment selector size: 0 + Min instruction length: 1 + Max operations per instruction: 1 + Initial value if 'is_stmt': 1 + Line base: -5 + Line range: 14 + Opcode base: 13 Opcodes: [ 1] 0 arguments @@ -476,15 +485,15 @@ Call frame information section [16] '.eh_frame' at offset 0x5b8: def_cfa_offset 24 advance_loc 10 to 0x3b0 def_cfa_expression 11 - [ 0] breg7 8 - [ 2] breg16 0 - [ 4] lit15 - [ 5] and - [ 6] lit11 - [ 7] ge - [ 8] lit3 - [ 9] shl - [ 10] plus + [ 0] breg7 8 + [ 2] breg16 0 + [ 4] lit15 + [ 5] and + [ 6] lit11 + [ 7] ge + [ 8] lit3 + [ 9] shl + [10] plus nop nop nop diff --git a/tests/run-reloc-bpf.sh b/tests/run-reloc-bpf.sh new file mode 100755 index 00000000..feb75575 --- /dev/null +++ b/tests/run-reloc-bpf.sh @@ -0,0 +1,33 @@ +#! /bin/sh +# Copyright (C) 2018 Facebook, 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 + +# This test file is created with +# $ cat t.c +# struct tt { +# int a; +# char b; +# }; +# int test(struct tt *t) { +# return t->a; +# } +# $ clang -O2 -g -emit-llvm -c t.c -o - | llc -march=bpf -filetype=obj -o t.o +# $ mv t.o testfile-bpf-reloc.o + +testfiles testfile-bpf-reloc.o testfile-bpf-reloc.expect +testrun_compare ${abs_top_builddir}/src/objdump -r testfile-bpf-reloc.o < testfile-bpf-reloc.expect diff --git a/tests/run-strip-nothing.sh b/tests/run-strip-nothing.sh index e80bd906..914fdfbf 100755 --- a/tests/run-strip-nothing.sh +++ b/tests/run-strip-nothing.sh @@ -23,7 +23,7 @@ tempfiles a.out strip.out debug.out # Create no-debug a.out. -echo "int main() { return 1; }" | gcc -xc - +echo "int main() { return 1; }" | gcc -s -xc - # strip to file testrun ${abs_top_builddir}/src/strip -g -o strip.out || diff --git a/tests/run-unit-info.sh b/tests/run-unit-info.sh new file mode 100755 index 00000000..328fe78b --- /dev/null +++ b/tests/run-unit-info.sh @@ -0,0 +1,81 @@ +#! /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-typeiter.sh +testfiles testfile-debug-types + +testrun ${abs_builddir}/unit-info testfile-debug-types + +# see run-readelf-dwz-multi.sh +testfiles testfile_multi_main testfile_multi.dwz + +testrun ${abs_builddir}/unit-info testfile_multi_main + +# see tests/run-dwflsyms.sh +testfiles testfilebazdbgppc64.debug + +testrun ${abs_builddir}/unit-info testfilebazdbgppc64.debug + +# see tests/testfile-dwarf-45.source +testfiles testfile-dwarf-4 testfile-dwarf-5 +testfiles testfile-splitdwarf-4 testfile-splitdwarf-5 +testfiles testfile-hello4.dwo testfile-hello5.dwo +testfiles testfile-world4.dwo testfile-world5.dwo + +testrun ${abs_builddir}/unit-info testfile-dwarf-4 +testrun ${abs_builddir}/unit-info testfile-dwarf-5 + +# The consistency checks should find most issue, but make sure the +# output is also what we expect in case we break dwarf_get_units and +# dwarf_cu_info at the same time. +testrun_compare ${abs_builddir}/unit-info \ + testfile-splitdwarf-4 testfile-splitdwarf-5 <<\EOF +file: testfile-splitdwarf-4 +Iterate getting all info, compare with dwarf_cu_info. +0 cu dietag: 11, subtag: 11, version 4, unit_type 4 +0 subdietag: 11, subtag: 0, version 4, unit_type 5 +1 cu dietag: 11, subtag: 11, version 4, unit_type 4 +1 subdietag: 11, subtag: 0, version 4, unit_type 5 +rechecking: testfile-splitdwarf-4 +Iterate no info, compare recorded info with dwarf_cu_info. +0 re dietag: 11, subtag: 11, version 4, unit_type 4 +0 subdietag: 11, subtag: 0, version 4, unit_type 5 +1 re dietag: 11, subtag: 11, version 4, unit_type 4 +1 subdietag: 11, subtag: 0, version 4, unit_type 5 + +file: testfile-splitdwarf-5 +Iterate getting all info, compare with dwarf_cu_info. +0 cu dietag: 4a, subtag: 11, version 5, unit_type 4 +0 subdietag: 11, subtag: 0, version 5, unit_type 5 +1 cu dietag: 4a, subtag: 11, version 5, unit_type 4 +1 subdietag: 11, subtag: 0, version 5, unit_type 5 +rechecking: testfile-splitdwarf-5 +Iterate no info, compare recorded info with dwarf_cu_info. +0 re dietag: 4a, subtag: 11, version 5, unit_type 4 +0 subdietag: 11, subtag: 0, version 5, unit_type 5 +1 re dietag: 4a, subtag: 11, version 5, unit_type 4 +1 subdietag: 11, subtag: 0, version 5, unit_type 5 + +EOF + +# Self test (not on obj files, since those need relocation first). +testrun_on_self_exe ${abs_builddir}/unit-info +testrun_on_self_lib ${abs_builddir}/unit-info + +exit 0 diff --git a/tests/run-varlocs-self.sh b/tests/run-varlocs-self.sh new file mode 100755 index 00000000..54b6a8d7 --- /dev/null +++ b/tests/run-varlocs-self.sh @@ -0,0 +1,22 @@ +#! /bin/sh +# Copyright (C) 2017 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 + +# Make sure varlocs doesn't crash, doesn't trigger self-check/asserts +# or leaks running under valgrind. +testrun_on_self_quiet ${abs_top_builddir}/tests/varlocs -e diff --git a/tests/run-varlocs.sh b/tests/run-varlocs.sh index 9c4b313e..b2621776 100755 --- a/tests/run-varlocs.sh +++ b/tests/run-varlocs.sh @@ -124,5 +124,481 @@ module 'testfile_implicit_pointer' frame_base: {call_frame_cfa {bregx(7,8)}} EOF +# Multi CU DWARF5. See run-dwarf-ranges.sh. +testfiles testfileranges5.debug +testrun_compare ${abs_top_builddir}/tests/varlocs --debug -e testfileranges5.debug <<\EOF +module 'testfileranges5.debug' +[c] CU 'hello.c'@0 + [2a] function 'no_say'@401160 + frame_base: {call_frame_cfa {...}} + [4a] parameter 'prefix' + [401160,401169) {reg5} + [401169,40116a) {entry_value(1) {reg5}, stack_value} + [40116a,401175) {reg5} + [401175,40117a) {entry_value(1) {reg5}, stack_value} + [59] variable 'world' + [401160,40117a) {addr(0x402004), stack_value} + [bd] function 'main'@401050 + frame_base: {call_frame_cfa {...}} + [dd] parameter 'argc' + [401050,401062) {reg5} + [401062,401067) {entry_value(1) {reg5}, stack_value} + [ec] parameter 'argv' + [401050,401066) {reg4} + [401066,401067) {entry_value(1) {reg4}, stack_value} + [fb] inlined function 'subject'@401053 + [117] parameter 'count' + [401053,40105f) {reg5} + [120] parameter 'word' + [401053,40105f) {reg0} + [168] function 'subject'@401150 + frame_base: {call_frame_cfa {...}} + [183] parameter 'word' + [401150,401160) {reg5} + [18a] parameter 'count' + [401150,401160) {reg4} +module 'testfileranges5.debug' +[1ab] CU 'world.c'@401180 + [1cd] function 'no_main'@4011d0 + frame_base: {call_frame_cfa {...}} + [1ef] parameter 'argc' + [4011d0,4011e2) {reg5} + [4011e2,4011e7) {entry_value(1) {reg5}, stack_value} + [1fe] parameter 'argv' + [4011d0,4011e6) {reg4} + [4011e6,4011e7) {entry_value(1) {reg4}, stack_value} + [20d] inlined function 'no_subject'@4011d3 + [229] parameter 'count' + [4011d3,4011df) {reg5} + [232] parameter 'word' + [4011d3,4011df) {reg0} + [28d] function 'say'@401180 + frame_base: {call_frame_cfa {...}} + [2af] parameter 'prefix' + [401180,40118e) {reg5} + [40118e,40119c) {reg3} + [40119c,4011a7) {entry_value(1) {reg5}, stack_value} + [4011a7,4011b5) {reg3} + [4011b5,4011c0) {entry_value(1) {reg5}, stack_value} + [2be] variable 'world' + [401193,40119b) {reg0} + [4011a7,4011b4) {reg0} + [2ce] inlined function 'happy'@40119b + [2e6] parameter 'w' + [4011a7,4011b4) {reg0} + [2ef] inlined function 'sad'@40119b + [303] parameter 'c' + [40119b,4011a6) {reg0} + [4011a6,4011a7) {entry_value(1) {reg5}} + [4011b4,4011bf) {reg0} + [36b] function 'no_subject'@4011c0 + frame_base: {call_frame_cfa {...}} + [386] parameter 'word' + [4011c0,4011d0) {reg5} + [38d] parameter 'count' + [4011c0,4011d0) {reg4} +EOF + +# Multi CU Split DWARF5. See run-dwarf-ranges.sh. +# Note that the DIE numbers change, but the actual location addresses are +# the same as above, even though the representation is totally different. +testfiles testfilesplitranges5.debug +testfiles testfile-ranges-hello5.dwo testfile-ranges-world5.dwo +testrun_compare ${abs_top_builddir}/tests/varlocs --debug -e testfilesplitranges5.debug <<\EOF +module 'testfilesplitranges5.debug' +[14] CU 'hello.c' + [1d] function 'no_say'@401160 + frame_base: {call_frame_cfa {...}} + [33] parameter 'prefix' + [401160,401169) {reg5} + [401169,40116a) {entry_value(1) {reg5}, stack_value} + [40116a,401175) {reg5} + [401175,40117a) {entry_value(1) {reg5}, stack_value} + [3c] variable 'world' + [401160,40117a) {addr: 0x402004, stack_value} + [7e] function 'main'@401050 + frame_base: {call_frame_cfa {...}} + [94] parameter 'argc' + [401050,401062) {reg5} + [401062,401067) {entry_value(1) {reg5}, stack_value} + [9d] parameter 'argv' + [401050,401066) {reg4} + [401066,401067) {entry_value(1) {reg4}, stack_value} + [a6] inlined function 'subject'@401053 + [bb] parameter 'count' + [401053,40105f) {reg5} + [c1] parameter 'word' + [401053,40105f) {reg0} + [f6] function 'subject'@401150 + frame_base: {call_frame_cfa {...}} + [10a] parameter 'word' + [401150,401160) {reg5} + [111] parameter 'count' + [401150,401160) {reg4} +module 'testfilesplitranges5.debug' +[14] CU 'world.c' + [1d] function 'no_main'@4011d0 + frame_base: {call_frame_cfa {...}} + [35] parameter 'argc' + [4011d0,4011e2) {reg5} + [4011e2,4011e7) {entry_value(1) {reg5}, stack_value} + [3e] parameter 'argv' + [4011d0,4011e6) {reg4} + [4011e6,4011e7) {entry_value(1) {reg4}, stack_value} + [47] inlined function 'no_subject'@4011d3 + [5c] parameter 'count' + [4011d3,4011df) {reg5} + [62] parameter 'word' + [4011d3,4011df) {reg0} + [a7] function 'say'@401180 + frame_base: {call_frame_cfa {...}} + [c2] parameter 'prefix' + [401180,40118e) {reg5} + [40118e,40119c) {reg3} + [40119c,4011a7) {entry_value(1) {reg5}, stack_value} + [4011a7,4011b5) {reg3} + [4011b5,4011c0) {entry_value(1) {reg5}, stack_value} + [cb] variable 'world' + [401193,40119b) {reg0} + [4011a7,4011b4) {reg0} + [d5] inlined function 'happy'@40119b + [e3] parameter 'w' + [4011a7,4011b4) {reg0} + [e9] inlined function 'sad'@40119b + [f3] parameter 'c' + [40119b,4011a6) {reg0} + [4011a6,4011a7) {entry_value(1) {reg5}} + [4011b4,4011bf) {reg0} + [147] function 'no_subject'@4011c0 + frame_base: {call_frame_cfa {...}} + [15b] parameter 'word' + [4011c0,4011d0) {reg5} + [162] parameter 'count' + [4011c0,4011d0) {reg4} +EOF + +# GNU DebugFissuon Multi CU Split DWARF. See run-dwarf-ranges.sh. +testfiles testfilesplitranges4.debug +testfiles testfile-ranges-hello.dwo testfile-ranges-world.dwo +testrun_compare ${abs_top_builddir}/tests/varlocs --debug -e testfilesplitranges4.debug <<\EOF +module 'testfilesplitranges4.debug' +[b] CU 'hello.c' + [18] function 'no_say'@4004f0 + frame_base: {call_frame_cfa {...}} + [2f] parameter 'prefix' + [4004f0,4004fa) {reg5} + [4004fa,4004ff) {GNU_entry_value(1) {reg5}, stack_value} + [3b] variable 'world' + <no value> + [60] function 'main'@4003e0 + frame_base: {call_frame_cfa {...}} + [77] parameter 'argc' + [4003e0,4003f2) {reg5} + [4003f2,4003f7) {GNU_entry_value(1) {reg5}, stack_value} + [83] parameter 'argv' + [4003e0,4003f6) {reg4} + [4003f6,1004003f5) {GNU_entry_value(1) {reg4}, stack_value} + [8f] inlined function 'subject'@4003e3 + [a3] parameter 'count' + [4003e3,4003ef) {reg5} + [ac] parameter 'word' + [4003e3,4003ef) {reg0} + [e7] function 'subject'@4004e0 + frame_base: {call_frame_cfa {...}} + [fb] parameter 'word' + [4004e0,4004f0) {reg5} + [102] parameter 'count' + [4004e0,4004f0) {reg4} +module 'testfilesplitranges4.debug' +[b] CU 'world.c' + [18] function 'no_main'@400550 + frame_base: {call_frame_cfa {...}} + [2f] parameter 'argc' + [400550,400562) {reg5} + [400562,400567) {GNU_entry_value(1) {reg5}, stack_value} + [3b] parameter 'argv' + [400550,400566) {reg4} + [400566,100400565) {GNU_entry_value(1) {reg4}, stack_value} + [47] inlined function 'no_subject'@400553 + [5b] parameter 'count' + [400553,40055f) {reg5} + [64] parameter 'word' + [400553,40055f) {reg0} + [af] function 'say'@400500 + frame_base: {call_frame_cfa {...}} + [c9] parameter 'prefix' + [400500,40050e) {reg5} + [40050e,40051c) {reg3} + [40051c,400527) {GNU_entry_value(1) {reg5}, stack_value} + [400527,400535) {reg3} + [400535,400540) {GNU_entry_value(1) {reg5}, stack_value} + [d5] variable 'world' + [400513,40051b) {reg0} + [400527,400534) {reg0} + [e1] inlined function 'happy'@40051c + [f1] parameter 'w' + [400527,400534) {reg0} + [fa] inlined function 'sad'@40051c + [106] parameter 'c' + [40051b,400526) {reg0} + [400526,400527) {GNU_entry_value(1) {reg5}} + [400534,40053f) {reg0} + [15c] function 'no_subject'@400540 + frame_base: {call_frame_cfa {...}} + [170] parameter 'word' + [400540,400550) {reg5} + [177] parameter 'count' + [400540,400550) {reg4} +EOF + +# DW_OP_addrx and DW_OP_constx testcases. +# +# int i, j, k; +# __thread int l, m, n; +# +# int main () +# { +# int r1 = i + j + k; +# int r2 = l + m + n; +# int res = r1 + r2; +# +# return res; +# } +# +# gcc -O2 -gdwarf-5 -gsplit-dwarf -o addrx_constx-5.o -c addrx_constx.c +# gcc -O2 -gdwarf-5 -gsplit-dwarf -o testfile-addrx_constx-5 addrx_constx-5.o +# gcc -O2 -gdwarf-4 -gsplit-dwarf -o addrx_constx-4.o -c addrx_constx.c +# gcc -O2 -gdwarf-4 -gsplit-dwarf -o testfile-addrx_constx-4 addrx_constx-4.o + +testfiles testfile-addrx_constx-5 addrx_constx-5.dwo +testrun_compare ${abs_top_builddir}/tests/varlocs --exprlocs -e testfile-addrx_constx-5 <<\EOF +module 'testfile-addrx_constx-5' +[14] CU 'addrx_constx.c' + producer (strx) + language (data1) + name (strx) + comp_dir (strx) + [19] variable "i" + name (string) + decl_file (implicit_const) + decl_line (data1) + decl_column (data1) + type (ref4) + external (flag_present) + location (exprloc) {addr: 0x404038} + [25] base_type "int" + byte_size (data1) + encoding (data1) + name (string) + [2c] variable "j" + name (string) + decl_file (implicit_const) + decl_line (data1) + decl_column (data1) + type (ref4) + external (flag_present) + location (exprloc) {addr: 0x404034} + [38] variable "k" + name (string) + decl_file (implicit_const) + decl_line (data1) + decl_column (data1) + type (ref4) + external (flag_present) + location (exprloc) {addr: 0x40403c} + [44] variable "l" + name (string) + decl_file (implicit_const) + decl_line (data1) + decl_column (data1) + type (ref4) + external (flag_present) + location (exprloc) {const: 0x403e10, form_tls_address} + [51] variable "m" + name (string) + decl_file (implicit_const) + decl_line (data1) + decl_column (data1) + type (ref4) + external (flag_present) + location (exprloc) {const: 0x403e0c, form_tls_address} + [5e] variable "n" + name (string) + decl_file (implicit_const) + decl_line (data1) + decl_column (data1) + type (ref4) + external (flag_present) + location (exprloc) {const: 0x403e08, form_tls_address} + [6b] subprogram "main" + external (flag_present) + name (strx) + decl_file (data1) + decl_line (data1) + decl_column (data1) + type (ref4) + low_pc (addrx) + high_pc (data8) + frame_base (exprloc) {call_frame_cfa {bregx(7,8)}} + call_all_calls (flag_present) + [7f] variable "r1" + name (string) + decl_file (implicit_const) + decl_line (data1) + decl_column (implicit_const) + type (ref4) + location (exprloc) {addr: 0x404038, deref_size(4), addr: 0x404034, deref_size(4), plus, addr: 0x40403c, deref_size(4), plus, stack_value} + [98] variable "r2" + name (string) + decl_file (implicit_const) + decl_line (data1) + decl_column (implicit_const) + type (ref4) + location (exprloc) {form_tls_address, const: 0x403e10, deref_size(4), form_tls_address, const: 0x403e0c, deref_size(4), plus, form_tls_address, const: 0x403e08, deref_size(4), plus, stack_value} + [b4] variable "res" + name (string) + decl_file (implicit_const) + decl_line (data1) + decl_column (implicit_const) + type (ref4) + location (exprloc) {addr: 0x404038, deref_size(4), form_tls_address, const: 0x403e08, deref_size(4), plus, form_tls_address, const: 0x403e0c, deref_size(4), plus, form_tls_address, const: 0x403e10, deref_size(4), plus, addr: 0x404034, deref_size(4), plus, addr: 0x40403c, deref_size(4), plus, stack_value} +EOF + +testfiles testfile-addrx_constx-4 addrx_constx-4.dwo +testrun_compare ${abs_top_builddir}/tests/varlocs --exprlocs -e testfile-addrx_constx-4 <<\EOF +module 'testfile-addrx_constx-4' +[b] CU 'addrx_constx.c' + producer (GNU_str_index) + language (data1) + name (GNU_str_index) + comp_dir (GNU_str_index) + GNU_dwo_id (data8) + [18] variable "i" + name (string) + decl_file (data1) + decl_line (data1) + decl_column (data1) + type (ref4) + external (flag_present) + location (exprloc) {addr: 0x404038} + [25] base_type "int" + byte_size (data1) + encoding (data1) + name (string) + [2c] variable "j" + name (string) + decl_file (data1) + decl_line (data1) + decl_column (data1) + type (ref4) + external (flag_present) + location (exprloc) {addr: 0x404034} + [39] variable "k" + name (string) + decl_file (data1) + decl_line (data1) + decl_column (data1) + type (ref4) + external (flag_present) + location (exprloc) {addr: 0x40403c} + [46] variable "l" + name (string) + decl_file (data1) + decl_line (data1) + decl_column (data1) + type (ref4) + external (flag_present) + location (exprloc) {const: 0x403e10, GNU_push_tls_address} + [54] variable "m" + name (string) + decl_file (data1) + decl_line (data1) + decl_column (data1) + type (ref4) + external (flag_present) + location (exprloc) {const: 0x403e0c, GNU_push_tls_address} + [62] variable "n" + name (string) + decl_file (data1) + decl_line (data1) + decl_column (data1) + type (ref4) + external (flag_present) + location (exprloc) {const: 0x403e08, GNU_push_tls_address} + [70] subprogram "main" + external (flag_present) + name (GNU_str_index) + decl_file (data1) + decl_line (data1) + decl_column (data1) + type (ref4) + low_pc (GNU_addr_index) + high_pc (data8) + frame_base (exprloc) {call_frame_cfa {bregx(7,8)}} + GNU_all_call_sites (flag_present) + [84] variable "r1" + name (string) + decl_file (data1) + decl_line (data1) + decl_column (data1) + type (ref4) + location (exprloc) {addr: 0x404038, deref_size(4), addr: 0x404034, deref_size(4), plus, addr: 0x40403c, deref_size(4), plus, stack_value} + [9f] variable "r2" + name (string) + decl_file (data1) + decl_line (data1) + decl_column (data1) + type (ref4) + location (exprloc) {GNU_push_tls_address, const: 0x403e10, deref_size(4), GNU_push_tls_address, const: 0x403e0c, deref_size(4), plus, GNU_push_tls_address, const: 0x403e08, deref_size(4), plus, stack_value} + [bd] variable "res" + name (string) + decl_file (data1) + decl_line (data1) + decl_column (data1) + type (ref4) + location (exprloc) {addr: 0x404038, deref_size(4), GNU_push_tls_address, const: 0x403e08, deref_size(4), plus, GNU_push_tls_address, const: 0x403e0c, deref_size(4), plus, GNU_push_tls_address, const: 0x403e10, deref_size(4), plus, addr: 0x404034, deref_size(4), plus, addr: 0x40403c, deref_size(4), plus, stack_value} +EOF + +# See run-readelf-loc.sh +testfiles testfile-splitdwarf4-not-split4.debug +testfiles splitdwarf4-not-split4.dwo + +testrun_compare ${abs_top_builddir}/tests/varlocs --debug -e testfile-splitdwarf4-not-split4.debug <<\EOF +module 'testfile-splitdwarf4-not-split4.debug' +[b] CU 'splitdwarf4-not-split4.c' + [18] function 'main'@401050 + frame_base: {call_frame_cfa {...}} + [30] parameter 'argc' + [401050,40106e) {reg5} + [40106e,401086) {reg12} + [401086,401095) {GNU_entry_value(1) {reg5}, stack_value} + [401095,40109c) {reg5} + [3d] parameter 'argv' + [401050,40106e) {reg4} + [40106e,401095) {GNU_entry_value(1) {reg4}, stack_value} + [401095,40109c) {reg4} + [4a] variable 'i' + [401050,40106e) {lit0, stack_value} + [401086,40108e) {breg12(0), breg6(0), plus, stack_value} + [40108e,401095) {reg0} + [401095,40109c) {lit0, stack_value} + [58] variable 'p' + [401050,40106e) {reg5} + [40106e,401090) {reg6} + [401095,40109c) {reg5} +module 'testfile-splitdwarf4-not-split4.debug' +[3f] CU 'popcount.c'@401180 + [61] function 'popcount'@401180 + frame_base: {call_frame_cfa {...}} + [83] parameter 'u' + [401180,401189) {reg5} + [401189,40119b) {reg1} + [40119b,40119d) {breg1(0), lit1, shr, stack_value} + [40119d,4011a1) {reg1} + [91] variable 'c' + [401180,401189) {lit0, stack_value} + [401189,4011a0) {reg0} + [4011a0,4011a1) {lit0, stack_value} +EOF exit 0 diff --git a/tests/show-abbrev.c b/tests/show-abbrev.c index b0af0297..002ae25e 100644 --- a/tests/show-abbrev.c +++ b/tests/show-abbrev.c @@ -51,6 +51,14 @@ main (int argc, char *argv[]) /* Something went wrong. */ break; + /* Test something obviously wrong. */ + Dwarf_Abbrev *a = dwarf_getabbrev (&die, (Dwarf_Off) -1, NULL); + if (a != NULL) + { + printf ("dwarf_getabbrev -1 succeeded?\n"); + break; + } + Dwarf_Off offset = 0; while (1) diff --git a/tests/splitdwarf4-not-split4.dwo.bz2 b/tests/splitdwarf4-not-split4.dwo.bz2 Binary files differnew file mode 100644 index 00000000..4346b2e6 --- /dev/null +++ b/tests/splitdwarf4-not-split4.dwo.bz2 diff --git a/tests/test-subr.sh b/tests/test-subr.sh index a765db63..09f428d1 100644 --- a/tests/test-subr.sh +++ b/tests/test-subr.sh @@ -115,16 +115,21 @@ program_transform() echo "$*" | sed "${program_transform_name}" } -self_test_files=`echo ${abs_top_builddir}/src/addr2line \ -${abs_top_builddir}/src/elfcmp ${abs_top_builddir}/src/elflint \ -${abs_top_builddir}/src/nm ${abs_top_builddir}/src/objdump \ -${abs_top_builddir}/src/readelf \ -${abs_top_builddir}/src/size.o ${abs_top_builddir}/src/strip.o \ -${abs_top_builddir}/libelf/libelf.so \ +self_test_files_exe=`echo ${abs_top_builddir}/src/addr2line \ +${abs_top_builddir}/src/elfcmp \ +${abs_top_builddir}/src/objdump \ +${abs_top_builddir}/src/readelf` + +self_test_files_lib=`echo ${abs_top_builddir}/libelf/libelf.so \ ${abs_top_builddir}/libdw/libdw.so \ ${abs_top_builddir}/backends/libebl_i386.so \ ${abs_top_builddir}/backends/libebl_x86_64.so` +self_test_files_obj=`echo ${abs_top_builddir}/src/size.o \ +${abs_top_builddir}/src/strip.o` + +self_test_files="$self_test_files_exe $self_test_files_lib $self_test_files_obj" + # Provide a command to run on all self-test files with testrun. testrun_on_self() { @@ -139,6 +144,32 @@ testrun_on_self() if test $exit_status != 0; then exit $exit_status; fi } +testrun_on_self_exe() +{ + exit_status=0 + + for file in $self_test_files_exe; do + testrun $* $file \ + || { echo "*** failure in $* $file"; exit_status=1; } + done + + # Only exit if something failed + if test $exit_status != 0; then exit $exit_status; fi +} + +testrun_on_self_lib() +{ + exit_status=0 + + for file in $self_test_files_lib; do + testrun $* $file \ + || { echo "*** failure in $* $file"; exit_status=1; } + done + + # Only exit if something failed + if test $exit_status != 0; then exit $exit_status; fi +} + # Compress the files first. Compress both debug sections and symtab. testrun_on_self_compressed() { diff --git a/tests/testfile-ada-variant.bz2 b/tests/testfile-ada-variant.bz2 Binary files differnew file mode 100644 index 00000000..459774d6 --- /dev/null +++ b/tests/testfile-ada-variant.bz2 diff --git a/tests/testfile-addrx_constx-4.bz2 b/tests/testfile-addrx_constx-4.bz2 Binary files differnew file mode 100755 index 00000000..cf10fbb1 --- /dev/null +++ b/tests/testfile-addrx_constx-4.bz2 diff --git a/tests/testfile-addrx_constx-5.bz2 b/tests/testfile-addrx_constx-5.bz2 Binary files differnew file mode 100755 index 00000000..eb2a1f17 --- /dev/null +++ b/tests/testfile-addrx_constx-5.bz2 diff --git a/tests/testfile-bpf-reloc.expect.bz2 b/tests/testfile-bpf-reloc.expect.bz2 Binary files differnew file mode 100644 index 00000000..0ff8cc4c --- /dev/null +++ b/tests/testfile-bpf-reloc.expect.bz2 diff --git a/tests/testfile-bpf-reloc.o.bz2 b/tests/testfile-bpf-reloc.o.bz2 Binary files differnew file mode 100644 index 00000000..295634f9 --- /dev/null +++ b/tests/testfile-bpf-reloc.o.bz2 diff --git a/tests/testfile-const-values.debug.bz2 b/tests/testfile-const-values.debug.bz2 Binary files differnew file mode 100755 index 00000000..167da166 --- /dev/null +++ b/tests/testfile-const-values.debug.bz2 diff --git a/tests/testfile-dwarf-4.bz2 b/tests/testfile-dwarf-4.bz2 Binary files differnew file mode 100755 index 00000000..fd3aaea5 --- /dev/null +++ b/tests/testfile-dwarf-4.bz2 diff --git a/tests/testfile-dwarf-45.source b/tests/testfile-dwarf-45.source new file mode 100644 index 00000000..584c8f7e --- /dev/null +++ b/tests/testfile-dwarf-45.source @@ -0,0 +1,89 @@ +# Nonsensical program used to generate an example DWARF4 and DWARF5 file. +# The generated code is the same, but the DWARF representation is different. + +# = hello.h = + +extern int m; +extern int baz (int x); + +static inline int +frob (int a, int b) +{ + int c = a; + + if (a > b) + c -= b; + + return baz (c); +} + +# = hello.c = + +#include <stddef.h> +#include "hello.h" + +extern int main (int, char **); +int m = 2; + +wchar_t foo (wchar_t); +int baz (int x) +{ + int r = x; + + if (x > m) + r -= m; + + r = foo (r); + return r; +} + +wchar_t +foo (wchar_t f) +{ + if (f < 0) + return main (f, NULL); + + return f > 0 ? frob (f - 1, m) : 0; +} + +# = world.c = + +#include "hello.h" +#include <stdlib.h> + +int +calc (const char *word) +{ + if (word == 0 || word[0] == '\0') + return 0; + + return frob (word[0], m + 42); +} + +int +main (int argc, const char **argv) +{ + const char *n; + if (argc > 1) + n = argv[0]; + else + n = "world"; + + exit (calc (n)); +} + +$ gcc -gdwarf-4 -gno-as-loc-support -gno-variable-location-views -O2 -c world.c +$ gcc -gdwarf-4 -gno-as-loc-support -gno-variable-location-views -O2 -c hello.c +$ gcc -o testfile-dwarf-4 hello.o world.o + +$ gcc -gdwarf-5 -gno-as-loc-support -gno-variable-location-views -O2 -c world.c +$ gcc -gdwarf-5 -gno-as-loc-support -gno-variable-location-views -O2 -c hello.c +$ gcc -o testfile-dwarf-5 hello.o world.o + +$ gcc -gdwarf-4 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2 -o testfile-world4.o -c world.c +$ gcc -gdwarf-4 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2 -o testfile-hello4.o -c hello.c +$ gcc -o testfile-splitdwarf-4 testfile-hello4.o testfile-world4.o + +$ gcc -gdwarf-5 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2 -o testfile-world5.o -c world.c +$ gcc -gdwarf-5 -gsplit-dwarf -gno-as-loc-support -gno-variable-location-views -O2 -o testfile-hello5.o -c hello.c +$ gcc -o testfile-splitdwarf-5 testfile-hello5.o testfile-world5.o diff --git a/tests/testfile-dwarf-5.bz2 b/tests/testfile-dwarf-5.bz2 Binary files differnew file mode 100755 index 00000000..689fa4fc --- /dev/null +++ b/tests/testfile-dwarf-5.bz2 diff --git a/tests/testfile-hello4.dwo.bz2 b/tests/testfile-hello4.dwo.bz2 Binary files differnew file mode 100644 index 00000000..fe02d65c --- /dev/null +++ b/tests/testfile-hello4.dwo.bz2 diff --git a/tests/testfile-hello5.dwo.bz2 b/tests/testfile-hello5.dwo.bz2 Binary files differnew file mode 100644 index 00000000..e911375e --- /dev/null +++ b/tests/testfile-hello5.dwo.bz2 diff --git a/tests/testfile-only-debug-line.bz2 b/tests/testfile-only-debug-line.bz2 Binary files differnew file mode 100644 index 00000000..a931bcd4 --- /dev/null +++ b/tests/testfile-only-debug-line.bz2 diff --git a/tests/testfile-ppc64-min-instr.bz2 b/tests/testfile-ppc64-min-instr.bz2 Binary files differnew file mode 100755 index 00000000..85bef57b --- /dev/null +++ b/tests/testfile-ppc64-min-instr.bz2 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-hello5.dwo.bz2 b/tests/testfile-ranges-hello5.dwo.bz2 Binary files differnew file mode 100644 index 00000000..5e6e9e21 --- /dev/null +++ b/tests/testfile-ranges-hello5.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/testfile-ranges-world5.dwo.bz2 b/tests/testfile-ranges-world5.dwo.bz2 Binary files differnew file mode 100644 index 00000000..6bde196b --- /dev/null +++ b/tests/testfile-ranges-world5.dwo.bz2 diff --git a/tests/testfile-sizes3.o.bz2 b/tests/testfile-sizes3.o.bz2 Binary files differindex 7fa6a8a5..86333826 100644 --- a/tests/testfile-sizes3.o.bz2 +++ b/tests/testfile-sizes3.o.bz2 diff --git a/tests/testfile-sizes4.o.bz2 b/tests/testfile-sizes4.o.bz2 Binary files differnew file mode 100644 index 00000000..046e0a23 --- /dev/null +++ b/tests/testfile-sizes4.o.bz2 diff --git a/tests/testfile-sizes4.s b/tests/testfile-sizes4.s new file mode 100644 index 00000000..a2430215 --- /dev/null +++ b/tests/testfile-sizes4.s @@ -0,0 +1,77 @@ + .section .debug_info +.Lcu1_begin: + .4byte .Lcu1_end - .Lcu1_start +.Lcu1_start: + .2byte 4 /* Version */ + .4byte .Labbrev1_begin /* Abbrevs */ + .byte 8 /* Pointer size */ + .uleb128 2 /* Abbrev (DW_TAG_compile_unit) */ + .uleb128 3 /* Abbrev (DW_TAG_variable) */ + .ascii "v\0" + .4byte .Llabel1 - .Lcu1_begin +.Llabel1: + .uleb128 4 /* Abbrev (DW_TAG_array_type) */ + .4byte .Llabel2 - .Lcu1_begin + .uleb128 5 /* Abbrev (DW_TAG_subrange_type) */ + .byte -1 + .2byte 255 + .byte 0x0 /* Terminate children */ +.Llabel2: + .uleb128 6 /* Abbrev (DW_TAG_base_type) */ + .byte 1 + .byte 0x0 /* Terminate children */ +.Lcu1_end: + .section .note.gnu.build-id, "a", %note + .4byte 4 + .4byte 8 + .4byte 3 + .ascii "GNU\0" + .byte 0x01 + .byte 0x02 + .byte 0x03 + .byte 0x04 + .byte 0x05 + .byte 0x06 + .byte 0x07 + .byte 0x08 + .section .debug_abbrev +.Labbrev1_begin: + .uleb128 2 /* Abbrev start */ + .uleb128 0x11 /* DW_TAG_compile_unit */ + .byte 1 /* has_children */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + .uleb128 3 /* Abbrev start */ + .uleb128 0x34 /* DW_TAG_variable */ + .byte 0 /* has_children */ + .uleb128 0x03 /* DW_AT_name */ + .uleb128 0x08 /* DW_FORM_string */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + .uleb128 4 /* Abbrev start */ + .uleb128 0x01 /* DW_TAG_array_type */ + .byte 1 /* has_children */ + .uleb128 0x49 /* DW_AT_type */ + .uleb128 0x13 /* DW_FORM_ref4 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + .uleb128 5 /* Abbrev start */ + .uleb128 0x21 /* DW_TAG_subrange_type */ + .byte 0 /* has_children */ + .uleb128 0x22 /* DW_AT_lower_bound */ + .uleb128 0x0b /* DW_FORM_data1 */ + .uleb128 0x2f /* DW_AT_upper_bound */ + .uleb128 0x05 /* DW_FORM_data2 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + .uleb128 6 /* Abbrev start */ + .uleb128 0x24 /* DW_TAG_base_type */ + .byte 0 /* has_children */ + .uleb128 0x0b /* DW_AT_byte_size */ + .uleb128 0x0b /* DW_FORM_data1 */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ + .byte 0x0 /* Terminator */ diff --git a/tests/testfile-splitdwarf-4.bz2 b/tests/testfile-splitdwarf-4.bz2 Binary files differnew file mode 100755 index 00000000..a1871e61 --- /dev/null +++ b/tests/testfile-splitdwarf-4.bz2 diff --git a/tests/testfile-splitdwarf-5.bz2 b/tests/testfile-splitdwarf-5.bz2 Binary files differnew file mode 100755 index 00000000..27ff3bd6 --- /dev/null +++ b/tests/testfile-splitdwarf-5.bz2 diff --git a/tests/testfile-splitdwarf4-not-split4.debug.bz2 b/tests/testfile-splitdwarf4-not-split4.debug.bz2 Binary files differnew file mode 100755 index 00000000..6f4d701a --- /dev/null +++ b/tests/testfile-splitdwarf4-not-split4.debug.bz2 diff --git a/tests/testfile-stridex.bz2 b/tests/testfile-stridex.bz2 Binary files differnew file mode 100755 index 00000000..ff909f4a --- /dev/null +++ b/tests/testfile-stridex.bz2 diff --git a/tests/testfile-world4.dwo.bz2 b/tests/testfile-world4.dwo.bz2 Binary files differnew file mode 100644 index 00000000..297fe5fa --- /dev/null +++ b/tests/testfile-world4.dwo.bz2 diff --git a/tests/testfile-world5.dwo.bz2 b/tests/testfile-world5.dwo.bz2 Binary files differnew file mode 100644 index 00000000..d5c852c3 --- /dev/null +++ b/tests/testfile-world5.dwo.bz2 diff --git a/tests/testfile11-debugframe.bz2 b/tests/testfile11-debugframe.bz2 Binary files differnew file mode 100644 index 00000000..5c07d16a --- /dev/null +++ b/tests/testfile11-debugframe.bz2 diff --git a/tests/testfile12-debugframe.bz2 b/tests/testfile12-debugframe.bz2 Binary files differnew file mode 100644 index 00000000..b8cc19c3 --- /dev/null +++ b/tests/testfile12-debugframe.bz2 diff --git a/tests/testfileaarch64-debugframe.bz2 b/tests/testfileaarch64-debugframe.bz2 Binary files differnew file mode 100755 index 00000000..e77494a1 --- /dev/null +++ b/tests/testfileaarch64-debugframe.bz2 diff --git a/tests/testfilearm-debugframe.bz2 b/tests/testfilearm-debugframe.bz2 Binary files differnew file mode 100755 index 00000000..51ce2d37 --- /dev/null +++ b/tests/testfilearm-debugframe.bz2 diff --git a/tests/testfileppc32-debugframe.bz2 b/tests/testfileppc32-debugframe.bz2 Binary files differnew file mode 100755 index 00000000..b6ae4ea6 --- /dev/null +++ b/tests/testfileppc32-debugframe.bz2 diff --git a/tests/testfileppc64-debugframe.bz2 b/tests/testfileppc64-debugframe.bz2 Binary files differnew file mode 100755 index 00000000..85c80ac6 --- /dev/null +++ b/tests/testfileppc64-debugframe.bz2 diff --git a/tests/testfileranges4.debug.bz2 b/tests/testfileranges4.debug.bz2 Binary files differnew file mode 100755 index 00000000..67ba573d --- /dev/null +++ b/tests/testfileranges4.debug.bz2 diff --git a/tests/testfileranges5.debug.bz2 b/tests/testfileranges5.debug.bz2 Binary files differnew file mode 100755 index 00000000..ef28efc1 --- /dev/null +++ b/tests/testfileranges5.debug.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 diff --git a/tests/testfilesplitranges5.debug.bz2 b/tests/testfilesplitranges5.debug.bz2 Binary files differnew file mode 100755 index 00000000..5796cbf0 --- /dev/null +++ b/tests/testfilesplitranges5.debug.bz2 diff --git a/tests/unit-info.c b/tests/unit-info.c new file mode 100644 index 00000000..4fb9a984 --- /dev/null +++ b/tests/unit-info.c @@ -0,0 +1,323 @@ +/* Test dwarf_cu_info properties. + 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> + +/* Yeah, lazy, 16K CUs should be enough for everybody... */ +#define MAX_UNITS 16384 +struct info +{ + int dietag; + int subtag; + Dwarf_Half version; + uint8_t unit_type; + uint64_t id; + uint8_t addr_size; + uint8_t off_size; +}; +static struct info unit_info[MAX_UNITS]; + +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_Half version; + Dwarf_Die cudie, subdie; + uint8_t unit_type; + size_t u, units; + u = units = 0; + printf ("Iterate getting all info, compare with dwarf_cu_info.\n"); + while (dwarf_get_units (dbg, cu, &cu, &version, + &unit_type, &cudie, &subdie) == 0) + { + int dietag = dwarf_tag (&cudie); + int subtag = dwarf_tag (&subdie); + + unit_info[u].dietag = dietag; + unit_info[u].subtag = subtag; + unit_info[u].version = version; + unit_info[u].unit_type = unit_type; + + printf ("%zu cu dietag: %x, subtag: %x, version %" PRIx32 + ", unit_type %" PRIx8 "\n", + u, dietag, subtag, version, unit_type); + + uint64_t unit_id; + uint8_t addr_size, off_size; + if (dwarf_cu_info (cu, + &version, &unit_type, &cudie, &subdie, + &unit_id, &addr_size, &off_size) != 0) + { + printf ("Invalid dwarf_cu_info: %s\n", dwarf_errmsg (-1)); + return -1; + } + + dietag = dwarf_tag (&cudie); + subtag = dwarf_tag (&subdie); + + if (unit_info[u].dietag != dietag) + { + printf("Unequal dietags\n"); + return -1; + } + + if (unit_info[u].subtag != subtag) + { + printf("Unequal subtags\n"); + return -1; + } + + if (unit_info[u].version != version) + { + printf("Unequal versions\n"); + return -1; + } + + if (unit_info[u].unit_type != unit_type) + { + printf("Unequal unit_types\n"); + return -1; + } + + unit_info[u].id = unit_id; + unit_info[u].addr_size = addr_size; + unit_info[u].off_size = off_size; + + if (unit_type == DW_UT_skeleton) + { + if (dwarf_cu_info (subdie.cu, + &version, &unit_type, &cudie, &subdie, + &unit_id, &addr_size, &off_size) != 0) + { + printf ("Invalid subdie dwarf_cu_info: %s\n", + dwarf_errmsg (-1)); + return -1; + } + + dietag = dwarf_tag (&cudie); + subtag = dwarf_tag (&subdie); + + printf ("%zu subdietag: %x, subtag: %x, version %" PRIx32 + ", unit_type %" PRIx8 "\n", + u, dietag, subtag, version, unit_type); + + /* subdie is now cudie. */ + if (unit_info[u].subtag != dietag) + { + printf ("Inconsistent subdie tag\n"); + return -1; + } + + if (unit_info[u].id != unit_id) + { + printf ("Unequal subdie ids\n"); + return -1; + } + + if (unit_info[u].addr_size != addr_size) + { + printf ("Unequal subdie addr_size\n"); + return -1; + } + + if (unit_info[u].off_size != off_size) + { + printf ("Unequal subdie off_size\n"); + return -1; + } + } + + if (u >= MAX_UNITS) + { + printf ("Oops, more than 16K units...\n"); + return -1; + } + u = ++units; + } + + dwarf_end (dbg); + close (fd); + + /* And again... */ + printf ("rechecking: %s\n", argv[i]); + fd = open (argv[i], O_RDONLY); + dbg = dwarf_begin (fd, DWARF_C_READ); + if (dbg == NULL) + { + printf ("%s not usable: %s\n", argv[i], dwarf_errmsg (-1)); + return -1; + } + + cu = NULL; + u = 0; + printf ("Iterate no info, compare recorded info with dwarf_cu_info.\n"); + while (dwarf_get_units (dbg, cu, &cu, NULL, NULL, NULL, NULL) == 0) + { + if (u > units) + { + printf ("Got too many units???\n"); + return -1; + } + + uint64_t unit_id; + uint8_t addr_size, off_size; + if (dwarf_cu_info (cu, + &version, &unit_type, &cudie, &subdie, + &unit_id, &addr_size, &off_size) != 0) + { + printf ("Invalid dwarf_cu_info: %s\n", dwarf_errmsg (-1)); + return -1; + } + + int dietag = dwarf_tag (&cudie); + int subtag = dwarf_tag (&subdie); + + printf ("%zu re dietag: %x, subtag: %x, version %" PRIx32 + ", unit_type %" PRIx8 "\n", + u, dietag, subtag, version, unit_type); + + if (unit_info[u].dietag != dietag) + { + printf("Unequal dietags %x != %x\n", unit_info[u].dietag, dietag); + return -1; + } + + if (unit_info[u].subtag != subtag) + { + printf("Unequal subtags\n"); + return -1; + } + + if (unit_info[u].version != version) + { + printf("Unequal versions\n"); + return -1; + } + + if (unit_info[u].unit_type != unit_type) + { + printf("Unequal unit_types\n"); + return -1; + } + + if (unit_info[u].id != unit_id) + { + printf ("Unequal subdie ids\n"); + return -1; + } + + if (unit_info[u].addr_size != addr_size) + { + printf ("Unequal subdie addr_size\n"); + return -1; + } + + if (unit_info[u].off_size != off_size) + { + printf ("Unequal subdie off_size\n"); + return -1; + } + + if (unit_type == DW_UT_skeleton) + { + if (dwarf_cu_info (subdie.cu, + &version, &unit_type, &cudie, &subdie, + &unit_id, &addr_size, &off_size) != 0) + { + printf ("Invalid subdie dwarf_cu_info: %s\n", + dwarf_errmsg (-1)); + return -1; + } + + dietag = dwarf_tag (&cudie); + subtag = dwarf_tag (&subdie); + + printf ("%zu subdietag: %x, subtag: %x, version %" PRIx32 + ", unit_type %" PRIx8 "\n", + u, dietag, subtag, version, unit_type); + + /* subdie is now cudie. */ + subtag = dwarf_tag (&cudie); + if (unit_info[u].subtag != subtag) + { + printf ("Inconsistent subdie tag\n"); + return -1; + } + + if (unit_info[u].id != unit_id) + { + printf ("Unequal subdie ids\n"); + return -1; + } + + if (unit_info[u].addr_size != addr_size) + { + printf ("Unequal subdie addr_size\n"); + return -1; + } + + if (unit_info[u].off_size != off_size) + { + printf ("Unequal subdie off_size\n"); + return -1; + } + } + + if (u >= MAX_UNITS) + { + printf ("Oops, more than 16K units...\n"); + return -1; + } + u++; + } + + if (u != units) + { + printf ("Got not enough units???\n"); + return -1; + } + + dwarf_end (dbg); + close (fd); + + printf ("\n"); + } + + return 0; +} diff --git a/tests/varlocs.c b/tests/varlocs.c index c3fba89e..25124399 100644 --- a/tests/varlocs.c +++ b/tests/varlocs.c @@ -1,5 +1,5 @@ /* Test program for dwarf location functions. - Copyright (C) 2013, 2015 Red Hat, Inc. + Copyright (C) 2013, 2015, 2017, 2018 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -39,9 +39,13 @@ // Needed for DW_OP_call_frame_cfa. static Dwarf *dw; Dwarf_CFI *cfi_debug; +Dwarf_Addr cfi_debug_bias; Dwarf_CFI *cfi_eh; Dwarf_Addr cfi_eh_bias; +bool is_ET_REL; +bool is_debug; + // Whether the current function has a DW_AT_frame_base defined. // Needed for DW_OP_fbreg. bool has_frame_base; @@ -75,11 +79,51 @@ dwarf_encoding_string (unsigned int code) return NULL; } +static const char * +dwarf_tag_string (unsigned int tag) +{ + switch (tag) + { +#define DWARF_ONE_KNOWN_DW_TAG(NAME, CODE) case CODE: return #NAME; + DWARF_ALL_KNOWN_DW_TAG +#undef DWARF_ONE_KNOWN_DW_TAG + default: + return NULL; + } +} + +static const char * +dwarf_attr_string (unsigned int attrnum) +{ + switch (attrnum) + { +#define DWARF_ONE_KNOWN_DW_AT(NAME, CODE) case CODE: return #NAME; + DWARF_ALL_KNOWN_DW_AT +#undef DWARF_ONE_KNOWN_DW_AT + default: + return NULL; + } +} + +static const char * +dwarf_form_string (unsigned int form) +{ + switch (form) + { +#define DWARF_ONE_KNOWN_DW_FORM(NAME, CODE) case CODE: return #NAME; + DWARF_ALL_KNOWN_DW_FORM +#undef DWARF_ONE_KNOWN_DW_FORM + default: + return NULL; + } +} + /* BASE must be a base type DIE referenced by a typed DWARF expression op. */ static void print_base_type (Dwarf_Die *base) { - assert (dwarf_tag (base) == DW_TAG_base_type); + if (dwarf_tag (base) != DW_TAG_base_type) + error (EXIT_FAILURE, 0, "not a base type"); Dwarf_Attribute encoding; Dwarf_Word enctype = 0; @@ -120,16 +164,16 @@ dwarf_opcode_string (unsigned int code) } // Forward reference for print_expr_block. -static void print_expr (Dwarf_Attribute *, Dwarf_Op *, Dwarf_Addr); +static void print_expr (Dwarf_Attribute *, Dwarf_Op *, Dwarf_Addr, int); static void print_expr_block (Dwarf_Attribute *attr, Dwarf_Op *exprs, int len, - Dwarf_Addr addr) + Dwarf_Addr addr, int depth) { printf ("{"); for (int i = 0; i < len; i++) { - print_expr (attr, &exprs[i], addr); + print_expr (attr, &exprs[i], addr, depth); printf ("%s", (i + 1 < len ? ", " : "")); } printf ("}"); @@ -141,13 +185,17 @@ print_expr_block_addrs (Dwarf_Attribute *attr, Dwarf_Op *exprs, int len) { printf (" [%" PRIx64 ",%" PRIx64 ") ", begin, end); - print_expr_block (attr, exprs, len, begin); + print_expr_block (attr, exprs, len, begin, 0); printf ("\n"); } static void -print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) +print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr, int depth) { +#define MAX_DEPTH 64 + if (depth++ > MAX_DEPTH) + error (EXIT_FAILURE, 0, "print_expr recursion depth exceeded"); + uint8_t atom = expr->atom; const char *opname = dwarf_opcode_string (atom); assert (opname != NULL); @@ -215,24 +263,33 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) error (EXIT_FAILURE, 0, "%s used in CFI", opname); printf ("%s ", opname); - if (cfi_eh == NULL && cfi_debug == NULL) + if (cfi_eh == NULL && cfi_debug == NULL && !is_debug) error (EXIT_FAILURE, 0, "DW_OP_call_frame_cfa used but no cfi found."); Dwarf_Frame *frame; - if (dwarf_cfi_addrframe (cfi_eh, addr + cfi_eh_bias, &frame) != 0 - && dwarf_cfi_addrframe (cfi_debug, addr, &frame) != 0) + if (dwarf_cfi_addrframe (cfi_eh, addr + cfi_eh_bias, &frame) == 0 + || dwarf_cfi_addrframe (cfi_debug, addr + cfi_debug_bias, + &frame) == 0) + { + Dwarf_Op *cfa_ops; + size_t cfa_nops; + if (dwarf_frame_cfa (frame, &cfa_ops, &cfa_nops) != 0) + error (EXIT_FAILURE, 0, "dwarf_frame_cfa 0x%" PRIx64 ": %s", + addr, dwarf_errmsg (-1)); + if (cfa_nops < 1) + error (EXIT_FAILURE, 0, "dwarf_frame_cfa no ops"); + print_expr_block (NULL, cfa_ops, cfa_nops, 0, depth); + free (frame); + } + else if (is_ET_REL || is_debug) + { + /* XXX In ET_REL files there might be an .eh_frame with relocations + we don't handle (e.g. X86_64_PC32). Maybe we should? */ + printf ("{...}"); + } + else error (EXIT_FAILURE, 0, "dwarf_cfi_addrframe 0x%" PRIx64 ": %s", addr, dwarf_errmsg (-1)); - - Dwarf_Op *cfa_ops; - size_t cfa_nops; - if (dwarf_frame_cfa (frame, &cfa_ops, &cfa_nops) != 0) - error (EXIT_FAILURE, 0, "dwarf_frame_cfa 0x%" PRIx64 ": %s", - addr, dwarf_errmsg (-1)); - if (cfa_nops < 1) - error (EXIT_FAILURE, 0, "dwarf_frame_cfa no ops"); - print_expr_block (NULL, cfa_ops, cfa_nops, 0); - free (frame); break; case DW_OP_push_object_address: @@ -290,7 +347,7 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) dwarf_errmsg (-1)); printf ("%s([%" PRIx64 "]) ", opname, dwarf_dieoffset (&call_die)); - print_expr_block (&call_attr, call_ops, call_len, addr); + print_expr_block (&call_attr, call_ops, call_len, addr, depth); } break; @@ -360,6 +417,7 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) } break; + case DW_OP_implicit_pointer: case DW_OP_GNU_implicit_pointer: /* Special, DIE offset, signed offset. Referenced DIE has a location or const_value attribute. */ @@ -386,7 +444,7 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) Dwarf_Die impl_die; if (dwarf_getlocation_die (attr, expr, &impl_die) != 0) - error (EXIT_FAILURE, 0, "dwarf_getlocation_due: %s", + error (EXIT_FAILURE, 0, "dwarf_getlocation_die: %s", dwarf_errmsg (-1)); printf ("%s([%" PRIx64 "],%" PRId64 ") ", opname, @@ -404,7 +462,7 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) if (locs == 0) printf ("<no location>"); // This means "optimized out". else if (locs == 1) - print_expr_block (&attrval, exprval, exprval_len, addr); + print_expr_block (&attrval, exprval, exprval_len, addr, depth); else error (EXIT_FAILURE, 0, "dwarf_getlocation_addr attrval at addr 0x%" PRIx64 @@ -413,6 +471,47 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) } break; + case DW_OP_GNU_variable_value: + /* Special, DIE offset. Referenced DIE has a location or const_value + attribute. */ + { + if (attr == NULL) + error (EXIT_FAILURE, 0, "%s used in CFI", opname); + + Dwarf_Attribute attrval; + if (dwarf_getlocation_attr (attr, expr, &attrval) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_attr: %s", + dwarf_errmsg (-1)); + + Dwarf_Die impl_die; + if (dwarf_getlocation_die (attr, expr, &impl_die) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_die: %s", + dwarf_errmsg (-1)); + + printf ("%s([%" PRIx64 "]) ", opname, dwarf_dieoffset (&impl_die)); + + if (dwarf_whatattr (&attrval) == DW_AT_const_value) + printf ("<constant value>"); // Lookup type... + else + { + // Lookup the location description at the current address. + Dwarf_Op *exprval; + size_t exprval_len; + int locs = dwarf_getlocation_addr (&attrval, addr, + &exprval, &exprval_len, 1); + if (locs == 0) + printf ("<no location>"); // This means "optimized out". + else if (locs == 1) + print_expr_block (&attrval, exprval, exprval_len, addr, depth); + else + error (EXIT_FAILURE, 0, + "dwarf_getlocation_addr attrval at addr 0x%" PRIx64 + ", locs (%d): %s", addr, locs, dwarf_errmsg (-1)); + } + } + break; + + case DW_OP_entry_value: case DW_OP_GNU_entry_value: /* Special, unsigned size plus expression block. All registers inside the block should be interpreted as they had on @@ -432,7 +531,7 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) dwarf_errmsg (-1)); printf ("%s(%zd) ", opname, entry_len); - print_expr_block (attr, entry_ops, entry_len, addr); + print_expr_block (attr, entry_ops, entry_len, addr, depth); } break; @@ -451,11 +550,14 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) // XXX actually lookup DW_TAG_GNU_call_site_parameter printf ("%s[%" PRIx64 "]", opname, dwarf_dieoffset (¶m)); assert (expr->number == dwarf_cuoffset (¶m)); - assert (dwarf_tag (¶m) == DW_TAG_formal_parameter); + if (dwarf_tag (¶m) != DW_TAG_formal_parameter) + error (EXIT_FAILURE, 0, "Not a formal parameter"); } break; + case DW_OP_convert: case DW_OP_GNU_convert: + case DW_OP_reinterpret: case DW_OP_GNU_reinterpret: /* Special, unsigned CU relative DIE offset pointing to a DW_TAG_base_type. Pops a value, converts or reinterprets the @@ -480,6 +582,7 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) } break; + case DW_OP_regval_type: case DW_OP_GNU_regval_type: /* Special, unsigned register number plus unsigned CU relative DIE offset pointing to a DW_TAG_base_type. */ @@ -495,9 +598,10 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) } break; + case DW_OP_deref_type: case DW_OP_GNU_deref_type: /* Special, unsigned size plus unsigned CU relative DIE offset - pointing to a DW_TAG_base_type. */ + pointing to a DW_TAG_base_type. */ { Dwarf_Die type; if (dwarf_getlocation_die (attr, expr, &type) != 0) @@ -510,6 +614,21 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) } break; + case DW_OP_xderef_type: + /* Special, unsigned size plus unsigned DIE offset + pointing to a DW_TAG_base_type. */ + { + Dwarf_Die type; + if (dwarf_getlocation_die (attr, expr, &type) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_die: %s", + dwarf_errmsg (-1)); + // XXX check size against base_type size? + printf ("%s(%" PRIu64 ")", opname, expr->number); + print_base_type (&type); + } + break; + + case DW_OP_const_type: case DW_OP_GNU_const_type: /* Special, unsigned CU relative DIE offset pointing to a DW_TAG_base_type, an unsigned size length plus a block with @@ -540,6 +659,42 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr) } break; + case DW_OP_GNU_addr_index: + case DW_OP_addrx: + /* Address from the .debug_addr section (indexed based on CU). */ + { + Dwarf_Attribute addr_attr; + if (dwarf_getlocation_attr (attr, expr, &addr_attr) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_attr for addr: %s", + dwarf_errmsg (-1)); + + Dwarf_Addr address; + if (dwarf_formaddr (&addr_attr, &address) != 0) + error (EXIT_FAILURE, 0, "dwarf_formaddr address failed: %s", + dwarf_errmsg (-1)); + + printf ("addr: 0x%" PRIx64, address); + } + break; + + case DW_OP_GNU_const_index: + case DW_OP_constx: + /* Constant from the .debug_addr section (indexed based on CU). */ + { + Dwarf_Attribute addr_attr; + if (dwarf_getlocation_attr (attr, expr, &addr_attr) != 0) + error (EXIT_FAILURE, 0, "dwarf_getlocation_attr for addr: %s", + dwarf_errmsg (-1)); + + Dwarf_Word constant; + if (dwarf_formudata (&addr_attr, &constant) != 0) + error (EXIT_FAILURE, 0, "dwarf_formudata constant failed: %s", + dwarf_errmsg (-1)); + + printf ("const: 0x%" PRIx64, constant); + } + break; + default: error (EXIT_FAILURE, 0, "unhandled opcode: DW_OP_%s (0x%x)", opname, atom); @@ -572,7 +727,7 @@ print_varlocs (Dwarf_Die *funcdie) if (entrypc == 0) printf ("XXX zero address"); // XXX bad DWARF? else - print_expr_block (&fb_attr, fb_expr, fb_exprlen, entrypc); + print_expr_block (&fb_attr, fb_expr, fb_exprlen, entrypc, 0); printf ("\n"); } else @@ -585,7 +740,7 @@ print_varlocs (Dwarf_Die *funcdie) &fb_expr, &fb_exprlen)) > 0) { printf (" (%" PRIx64 ",%" PRIx64 ") ", start, end); - print_expr_block (&fb_attr, fb_expr, fb_exprlen, start); + print_expr_block (&fb_attr, fb_expr, fb_exprlen, start, 0); printf ("\n"); } @@ -759,9 +914,162 @@ handle_function (Dwarf_Die *funcdie, void *arg __attribute__((unused))) return DWARF_CB_OK; } +struct attr_arg +{ + int depth; + Dwarf_Addr entrypc; +}; + +static int +handle_attr (Dwarf_Attribute *attr, void *arg) +{ + int depth = ((struct attr_arg *) arg)->depth; + Dwarf_Addr entrypc = ((struct attr_arg *) arg)->entrypc; + + unsigned int code = dwarf_whatattr (attr); + unsigned int form = dwarf_whatform (attr); + + printf ("%*s%s (%s)", depth * 2, "", + dwarf_attr_string (code), dwarf_form_string (form)); + + /* If we can get an DWARF expression (or location lists) from this + attribute we'll print it, otherwise we'll ignore it. But if + there is an error while the attribute has the "correct" form then + we'll report an error (we can only really check DW_FORM_exprloc + other forms can be ambiguous). */ + Dwarf_Op *expr; + size_t exprlen; + bool printed = false; + int res = dwarf_getlocation (attr, &expr, &exprlen); + if (res == 0) + { + printf (" "); + print_expr_block (attr, expr, exprlen, entrypc, 0); + printf ("\n"); + printed = true; + } + else if (form == DW_FORM_exprloc) + { + error (0, 0, "%s dwarf_getlocation failed: %s", + dwarf_attr_string (code), dwarf_errmsg (-1)); + return DWARF_CB_ABORT; + } + else + { + Dwarf_Addr base, begin, end; + ptrdiff_t offset = 0; + while ((offset = dwarf_getlocations (attr, offset, + &base, &begin, &end, + &expr, &exprlen)) > 0) + { + if (! printed) + printf ("\n"); + printf ("%*s", depth * 2, ""); + print_expr_block_addrs (attr, begin, end, expr, exprlen); + printed = true; + } + } + + if (! printed) + printf ("\n"); + + return DWARF_CB_OK; +} + +static void +handle_die (Dwarf_Die *die, int depth, bool outer_has_frame_base, + Dwarf_Addr outer_entrypc) +{ + /* CU DIE already printed. */ + if (depth > 0) + { + const char *name = dwarf_diename (die); + if (name != NULL) + printf ("%*s[%" PRIx64 "] %s \"%s\"\n", depth * 2, "", + dwarf_dieoffset (die), dwarf_tag_string (dwarf_tag (die)), + name); + else + printf ("%*s[%" PRIx64 "] %s\n", depth * 2, "", + dwarf_dieoffset (die), dwarf_tag_string (dwarf_tag (die))); + } + + struct attr_arg arg; + arg.depth = depth + 1; + + /* The (lowest) address to use for (looking up) operands that depend + on address. */ + Dwarf_Addr die_entrypc; + if (dwarf_entrypc (die, &die_entrypc) != 0 || die_entrypc == 0) + { + /* Try to get the lowest address of the first range covered. */ + Dwarf_Addr base, start, end; + if (dwarf_ranges (die, 0, &base, &start, &end) <= 0 || start == 0) + die_entrypc = outer_entrypc; + else + die_entrypc = start; + } + arg.entrypc = die_entrypc; + + /* Whether this or the any outer DIE has a frame base. Used as + sanity check when printing experssions that use DW_OP_fbreg. */ + bool die_has_frame_base = dwarf_hasattr (die, DW_AT_frame_base); + die_has_frame_base |= outer_has_frame_base; + has_frame_base = die_has_frame_base; + + /* Look through all attributes to find those that contain DWARF + expressions and print those. We expect to handle all attributes, + anything else is an error. */ + if (dwarf_getattrs (die, handle_attr, &arg, 0) != 1) + error (EXIT_FAILURE, 0, "Couldn't get all attributes: %s", + dwarf_errmsg (-1)); + + /* Handle children and siblings recursively depth first. */ + Dwarf_Die child; + if (dwarf_haschildren (die) != 0 && dwarf_child (die, &child) == 0) + handle_die (&child, depth + 1, die_has_frame_base, die_entrypc); + + Dwarf_Die sibling; + if (dwarf_siblingof (die, &sibling) == 0) + handle_die (&sibling, depth, outer_has_frame_base, outer_entrypc); +} + int main (int argc, char *argv[]) { + /* With --exprlocs we process all DIEs looking for any attribute + which contains an DWARF expression (but not location lists) and + print those. Otherwise we process all function DIEs and print + all DWARF expressions and location lists associated with + parameters and variables). It must be the first argument, + or the second, after --debug. */ + bool exprlocs = false; + + /* With --debug we ignore not being able to find .eh_frame. + It must come as first argument. */ + is_debug = false; + if (argc > 1) + { + if (strcmp ("--exprlocs", argv[1]) == 0) + { + exprlocs = true; + argv[1] = ""; + } + else if (strcmp ("--debug", argv[1]) == 0) + { + is_debug = true; + argv[1] = ""; + } + } + + if (argc > 2) + { + if (strcmp ("--exprlocs", argv[2]) == 0) + { + exprlocs = true; + argv[2] = ""; + } + } + int remaining; Dwfl *dwfl; (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining, @@ -770,14 +1078,27 @@ main (int argc, char *argv[]) Dwarf_Die *cu = NULL; Dwarf_Addr dwbias; + bool found_cu = false; while ((cu = dwfl_nextcu (dwfl, cu, &dwbias)) != NULL) { /* Only walk actual compile units (not partial units) that - contain code. */ + contain code if we are only interested in the function variable + locations. */ + Dwarf_Die cudie; + Dwarf_Die subdie; + uint8_t unit_type; + if (dwarf_cu_info (cu->cu, NULL, &unit_type, &cudie, &subdie, + NULL, NULL, NULL) != 0) + error (EXIT_FAILURE, 0, "dwarf_cu_info: %s", dwarf_errmsg (-1)); + if (unit_type == DW_UT_skeleton) + cudie = subdie; + Dwarf_Addr cubase; - if (dwarf_tag (cu) == DW_TAG_compile_unit - && dwarf_lowpc (cu, &cubase) == 0) + if (dwarf_tag (&cudie) == DW_TAG_compile_unit + && (exprlocs || dwarf_lowpc (&cudie, &cubase) == 0)) { + found_cu = true; + Dwfl_Module *mod = dwfl_cumodule (cu); Dwarf_Addr modbias; dw = dwfl_module_getdwarf (mod, &modbias); @@ -796,29 +1117,46 @@ main (int argc, char *argv[]) ? modname : basename (mainfile)); printf ("module '%s'\n", name); - print_die (cu, "CU", 0); + print_die (&cudie, "CU", 0); Dwarf_Addr elfbias; Elf *elf = dwfl_module_getelf (mod, &elfbias); // CFI. We need both since sometimes neither is complete. - cfi_debug = dwarf_getcfi (dw); // No bias needed, same file. - cfi_eh = dwarf_getcfi_elf (elf); - cfi_eh_bias = dwbias - elfbias; - - // Get the actual CU DIE and walk all functions inside it. - Dwarf_Die cudie; - uint8_t offsize; - uint8_t addrsize; - if (dwarf_diecu (cu, &cudie, &addrsize, &offsize) == NULL) - error (EXIT_FAILURE, 0, "dwarf_diecu %s", dwarf_errmsg (-1)); - - if (dwarf_getfuncs (cu, handle_function, NULL, 0) != 0) + cfi_debug = dwfl_module_dwarf_cfi (mod, &cfi_debug_bias); + cfi_eh = dwfl_module_eh_cfi (mod, &cfi_eh_bias); + + // No bias needed, same file. + assert (cfi_debug == NULL || cfi_debug_bias == 0); + + // We are a bit forgiving for object files. There might be + // relocations we don't handle that are needed in some + // places... + GElf_Ehdr ehdr_mem, *ehdr = gelf_getehdr (elf, &ehdr_mem); + is_ET_REL = ehdr->e_type == ET_REL; + + if (exprlocs) + { + Dwarf_Addr entrypc; + if (dwarf_entrypc (&cudie, &entrypc) != 0) + entrypc = 0; + + /* XXX - Passing true for has_frame_base is not really true. + We do it because we want to resolve all DIEs and all + attributes. Technically we should check that the DIE + (types) are referenced from variables that are defined in + a context (function) that has a frame base. */ + handle_die (&cudie, 0, true /* Should be false */, entrypc); + } + else if (dwarf_getfuncs (&cudie, handle_function, NULL, 0) != 0) error (EXIT_FAILURE, 0, "dwarf_getfuncs %s", dwarf_errmsg (-1)); } } + if (! found_cu) + error (EXIT_FAILURE, 0, "No DWARF CU found?"); + dwfl_end (dwfl); return 0; } |