summaryrefslogtreecommitdiffstats
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
* libdwelf: New function dwelf_elf_begin.Mark Wielaard2018-11-093-0/+42
| | | | | | | | | | | | | | | | | | This introduces a new function dwelf_elf_begin which creates a (read-only) ELF handle from a possibly compressed file handle or a file that start with a linux kernel header. This can be used in eu-readelf to (re)open a (pure) ELF. eu-readelf uses libdwfl to relocate addresses in the original file in case it is ET_REL. But to show the "raw" data it might need to (re)open the file. Which could fail if the file was compressed. And produced an obscure error message: "cannot create EBL handle". This rewrites __libdw_open_file a little so that the given file handle will never be closed (whether on success or failure) and introduces a new internal function __libdw_open_elf that dwelf_elf_begin wraps. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Explicitly update section data after (de)compression.Mark Wielaard2018-11-097-1/+124
| | | | | | | | | | | | | | We need to explictly trigger a section data reload after updating the ELF section rawdata to make sure it gets written out to disk on an elf_update. Doing this showed one bug/inefficiently when the underlying file has a different endianness. In that case for debug sections we would convert by allocating a new buffer and just copying over the raw data into a new buffer. This is not really necessary and would hide any relocations done on the rawdata by libdwfl. Added a couple of new ppc64 big endian testfiles that show the issue. Signed-off-by: Mark Wielaard <[email protected]>
* strip: Add --reloc-debug-sections-only option.Mark Wielaard2018-11-062-0/+15
| | | | | | | | | | | This option does the same thing as --reloc-debug-sections without doing any other strip operation. This is useful when you want to remove the debug section relocations in a separate ET_REL debug file that was created without --reloc-debug-sections, or for a file (like the linux debug vmlinux) that you don't want to strip, but for which the debug section relocations can be resolved already. Signed-off-by: Mark Wielaard <[email protected]>
* Recognize and parse GNU Property notes.Mark Wielaard2018-10-295-0/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GNU Property notes are different from normal notes because they use variable alignment/padding of their fields. They are 8 byte aligned, but use 4 byte fields. The name is aligned at 4 bytes and padded so that, the desc is aligned at 8 bytes. The whole note is padded to 8 bytes again. For normal notes all fields are both 4 bytes wide and 4 bytes aligned. To recognize these new kind of ELF Notes a new Elf_Type is introduced, ELF_T_NHDR8. This type is used in the xlate functions to determine how to align and pad the various fields. Since the fields themselves can now have different alignments we will have to keep track of the current alignement and use either NOTE_ALIGN4 or NOTE_ALIGN8 to determine the padding. To set the correct Elf_Type on the Elf_Data we use either the section sh_addralign or the segment p_align values. Assuming 8 means the section or segment contains the new style notes, otherwise normal notes. When we cannot determine the "alignment" directly, like when parsing special kernel sys files, we check the name "GNU" and type "GNU_PROPERTY_TYPE_0" fields. ebl_object_note now parses the new NT_GNU_PROPERTY_TYPE_0 and can extract the GNU_PROPERTY_STACK_SIZE, GNU_PROPERTY_NO_COPY_ON_PROTECTED and GNU_PROPERTY_X86_FEATURE_1_AND types GNU_PROPERTY_X86_FEATURE_1_IBT and GNU_PROPERTY_X86_FEATURE_1_SHSTK. Tests are added for extracting the note from sections or segments as set by gcc -fcf-protection. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Handle multiple .debug_macro sections and decode header flag.Mark Wielaard2018-10-195-3/+448
| | | | | | | | | | | | | In object files there could be multiple .debug_macro sections. These are COMDAT sections used as imports. Note that the output for DW_MACRO_import isn't ideal since the offset is printed against the start of the .debug_macro section, but it doesn't show which one. We currently don't have that information and no interface yet for libdw users. Also decode the macro header flag byte for convenience. Signed-off-by: Mark Wielaard <[email protected]>
* strip, unstrip: Handle SHT_GROUP correctly.Mark Wielaard2018-10-174-0/+40
| | | | | | | | | | | | | | | | | | | | The usage of annobin in Fedora showed a couple of bugs when using eu-strip and eu-unstrip on ET_REL files that contain multiple group sections. When stripping we should not remove the SHF_GROUP flag from sections even if the group section itself might be removed. Either the section itself gets removed, and so the flag doesn't matter. Or it gets moved together with the group section into the debug file, and then it still needs to have the flag set. Also we would "renumber" the section group flag field (which isn't a section index, and so shouldn't be changed). Often the group sections have the exact same name (".group"), flags (none) and sometimes the same sizes. Which makes matching them hard. Extract the group signature and compare those when comparing two group sections. Signed-off-by: Mark Wielaard <[email protected]>
* tests: backtrace-dwarf.c improve error handling in test framework.Mark Wielaard2018-09-212-14/+31
| | | | | | | | To debug https://sourceware.org/bugzilla/show_bug.cgi?id=23673 clean up the test framework so we know what exactly failed. Suggested-by: Dmitry V. Levin <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* strip,unstrip: Use and set shdrstrndx consistently.Mark Wielaard2018-09-143-2/+74
| | | | | | | | | | | In various places in strip we used e_shstrndx instead of shdrstrndx and we didn't setup the shdrstrndx for the debug file. In unstrip we forgot to copy the shdrstrndx in case the -o output option was used. Added a new testcase that adds many sections to a testfile and runs strip, elflint, unstrip and elfcmp. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: dwarf_begin_elf should use elf_getshdrstrndx to get section names.Mark Wielaard2018-09-143-2/+41
| | | | | | | | | | | dwarf_begin_elf used the Ehdr e_shstrndx to get the shdr string table section. This does not work for ELF files with more than SHN_LORESERVE sections. Use elf_getshdrstrndx, and don't pass around the ehdr. Add a simple testcase that fails before the patch because dwarf_begin return an error. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Fix shnum and section zero handling.Mark Wielaard2018-09-133-2/+107
| | | | | | | | | | | | | | | | | For ELF files with more than SHN_LOWRESERVE sections we always need section zero to store the section number (it doesn't just fit in the Ehdr e_shnum field). Make sure to create it if it doesn't exist yet in elf_getscn. Also fix handling on shnum in updatefile for the mmap case (we already got this correct for the non-mmap case). This adds a new test run-copymany-sections.sh which is like run-copyadd-sections.sh but tries to add two times 65535 sections. It makes sure libelf can copy the whole file and elfcmp checks they are the same. It doesn't use mmap for addsections since that doesn't work yet. ELF_C_RDWR_MMAP needs mremap which will fail since it needs too much space and the original mmap cannot move. Signed-off-by: Mark Wielaard <[email protected]>
* libelf: Fix some issues with ELF_C_RDWR_MMAP.Mark Wielaard2018-09-135-3/+678
| | | | | | | | | | | | | | | | | | When ELF_C_RDWR_MMAP is used libelf might have to write overlapping memory when moving the section data or headers. Make sure to use memmove, not memcpy. Also the size of the underlying file might have to change. That means we will have to also extend the mmap region with mremap. Since we are using direct pointers into the mmapped area we cannot move the mmap, only extend it. This might still fail if there is not enough free memory available to extend the mmap region. Two new test programs have been added. elfcopy which copies a whole elf file (using either ELF_C_WRITE or ELF_C_WRITE_MMAP). And addsections which adds new sections to an existing ELF file (using either ELF_C_RDWR or ELF_C_RDWR_MMAP). The newly added test will fail under valgrind without the fixes. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Add section attribute to defeat -freorder-blocks-and-partition.Mark Wielaard2018-09-112-0/+5
| | | | | | | | GCC could partition main into an cold and hot block causing our symbol lookup to fail in the backtrace-dwarf testcase. Add a section attribute on "main" so that it will be kept together. Signed-off-by: Mark Wielaard <[email protected]>
* unstrip: Also check sh_size in compare_unalloc_sections.Mark Wielaard2018-07-274-0/+62
| | | | | | | | | | | | compare_unalloc_sections only checked sh_flags and the section names. This would cause stripped/debug section mismatches when there were multiple sections with the same name and flags. Fix this by also checking the size of the section matches. Add a testcase that has two ".group" sections created on i386 with the gcc annobin plugin. Signed-off-by: Mark Wielaard <[email protected]>
* unstrip: Handle SHT_GROUP sections in ET_REL files.Mark Wielaard2018-07-274-1/+78
| | | | | | | | | SHT_GROUP sections are put in both the stripped and debug file. Handle correcting the symbol table/name entry of the group only once. The testfile was generated with the gcc annobin plugin. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Add core and strip tests for RISC-VAndreas Schwab2018-07-198-1/+162
| | | | Signed-off-by: Andreas Schwab <[email protected]>
* Remove previous test files before running the next roundUlf Hermann2018-07-172-0/+7
| | | | | | | | | | | strip explicitly creates the new files. This will not work on windows if the files already exist. Also, if strip fails to create the files for any reason, we would check the previous run's files and succeed. However, the test should fail then. Signed-off-by: Ulf Hermann <[email protected]>
* tests: Update hello_riscv64.ko test file with debuginfo.Mark Wielaard2018-07-173-1/+8
| | | | | | | | Also document CONFIG_DEBUG_INFO=y. Updated test file provided by Andreas Schwab <[email protected]>. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Handle compressed sections in next_cfi testcase.Mark Wielaard2018-07-102-4/+30
| | | | | | | | | | Some toolchains use compressed ELF sections by default. This would make run-next-cfi-self.sh fail because it would try to decode the compressed data. Fix by decompressing the section first. https://sourceware.org/bugzilla/show_bug.cgi?id=23370 Signed-off-by: Mark Wielaard <[email protected]>
* Consolidate error.h inclusion in system.hRoss Burton2018-07-0535-34/+66
| | | | | | | | | error.h isn't standard and so isn't part of the musl C library. To easy future porting, consolidate the inclusion of error.h into system.h. https://sourceware.org/bugzilla/show_bug.cgi?id=21008 Signed-off-by: Ross Burton <[email protected]>
* libdw: Recognize zero terminator to end frame table in dwarf_next_cfi.Mark Wielaard2018-06-295-3/+275
| | | | | | | | | | | | | When the length is zero this is a the zero terminator that ends the frame table. Return 1 (end of table) instead of -1 (error) in that case. We cannot update next_off and don't want to caller to try again. Add testcase for dwarf_next_cfi to show both .eh_frame and .debug_frame tables and check consistency (FDEs should point to existing CIEs). Also add a self check to make sure we can read the table from the just build elfutils binaries. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Allow .debug_frame only Dwarf.Mark Wielaard2018-06-2910-1/+332
| | | | | | | | | .debug_frame is useful independent from the other .debug sections. Add a simplified variant of the addrcfi testcase dwarfcfi. dwarfcfi only uses dwarf_frame calls and no dwfl helpers. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Limit varlocs print_expr_block recursion depth.Mark Wielaard2018-06-292-13/+24
| | | | | | | | This is only useful for bad DWARF where an expression block might have an expression that refers to a DIE that contains the expression block itself. But that might happen with bad DWARF generated by a fuzzer. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Add dwarf_next_lines to read .debug_line tables without CUs.Mark Wielaard2018-06-297-1/+538
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is sometimes useful to read .debug_line tables on their own without having an associated CU DIE. DWARF5 line tables are self-contained. Adjust dwarf_begin_elf to accept ELF files with just a .debug_line. Add a new function dwarf_next_lines that returns the Dwarf_Files and Dwarf_Lines while iterating over just the .debug_lines section. Since we parse and cache the information it also will try to match the CU a table is associated with. This is only necessary for DWARF4 line tables (we will need at least the compilation dir from the CU) and won't be done for DWARF5 line tables. It also isn't an error if there is no associated CU (but will mean for DWARF4 line tables the dir list and the file paths might not be complete). A typical way to call this new function is: Dwarf_Off off, next_off = 0; Dwarf_CU *cu = NULL; Dwarf_Files *files; size_t nfiles; Dwarf_Lines *lines; size_t nlines; int res; while ((res = dwarf_next_lines (dbg, off = next_off, &next_off, &cu, &files, &nfiles, &lines, &nlines)) == 0) { /* ... handle files and lines ... */ } if (res < 0) printf ("BAD dwarf_next_lines: %s\n", dwarf_errmsg (-1)); See libdw.h for the full documentation. For more examples on how to use the function see the new testcases next-files and next-lines. Also adjust the file paths for line tables missing a comp_dir. They are no longer made "absolute" by prepending a slash '/' in front of them. This really was not useful and didn't happen in any of the testcases. They are now just kept relative. Make eu-readelf --debug-dump=decodedline use dwarf_next_lines instead of iterating over the CUs to show the (decoded) line tables. This allows it to show decoded line tables even if there is no .debug_info section. New tests have been added that mimic the get-files and get-lines tests but use dwarf_next_lines instead of iterating over all CUs. They produce identical output (modulo the CU information). Also add a new test file that contains only a .debug_line section. Signed-off-by: Mark Wielaard <[email protected]>
* backends,bpf: add proper relocation supportYonghong Song2018-06-215-1/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Due to libdw does not have proper BPF relocation support, the pahole cannot display filenames correctly for objects with default llvm options. So we have to invent a special option "llc -march=bpf -mattr=dwarfris" to prevent llvm from generating cross-section dwarf relocation records (https://reviews.llvm.org/rL326505). The pahole related discussion is in linux netdev mailing list (http://lists.openwall.net/netdev/2018/06/15/38, etc.) We would like to add proper BPF relocation support to libdw so eventually we could retire the special llc bpf flag "-mattr=dwarfris". The bpf relocations are defined in llvm_repo:include/llvm/BinaryFormat/ELFRelocs/BPF.def: ELF_RELOC(R_BPF_NONE, 0) ELF_RELOC(R_BPF_64_64, 1) ELF_RELOC(R_BPF_64_32, 10) Removed the relocation type R_BPF_MAP_FD whoes name does not confirm to llvm definition and replaced it with R_BPF_64_64. The BPF object is just a relocatible object, not an executable or a shared library, so assign ELF type to REL only in bpf_reloc.def. Signed-off-by: Yonghong Song <[email protected]>
* readelf: Handle signedness of DW_FORM_implicit_const and DW_AT_const_value.Mark Wielaard2018-06-155-1/+242
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We only handles DW_FORM_sdata as a signed form, but DW_FORM_implicit_const is also signed by default. For DW_AT_const_value we can do a little better. GCC encodes some const_values with signed forms, even though the type is unsigned. Lookup the (base) type of the DIE and display the const value as their (signed) type/size (if we can determine that). Add a new testcase run-readelf-const-values.sh that shows that. With the new testcase the const values would come out as follows: name (string) "i" const_value (implicit_const) 18446744073709551615 name (string) "j" const_value (implicit_const) 18446744073709551615 name (string) "sc" const_value (sdata) -2 name (string) "uc" const_value (sdata) -2 name (string) "ss" const_value (sdata) -16 name (string) "us" const_value (sdata) -16 name (string) "si" const_value (sdata) -3 name (string) "ui" const_value (sdata) -94967296 name (string) "sl" const_value (sdata) -1 name (string) "ul" const_value (sdata) -1 With this patch they show up as: name (string) "i" const_value (implicit_const) -1 name (string) "j" const_value (implicit_const) -1 name (string) "sc" const_value (sdata) -2 name (string) "uc" const_value (sdata) 254 (-2) name (string) "ss" const_value (sdata) -16 name (string) "us" const_value (sdata) 65520 (-16) name (string) "si" const_value (sdata) -3 name (string) "ui" const_value (sdata) 4200000000 (-94967296) name (string) "sl" const_value (sdata) -1 name (string) "ul" const_value (sdata) 18446744073709551615 (-1) (for signed/unsigned int char, short and long) Signed-off-by: Mark Wielaard <[email protected]>
* tests: Don't assert on bad DW_OP_GNU_parameter_ref target in varlocs.Mark Wielaard2018-06-112-1/+7
| | | | | | | | If the target of a DW_OP_GNU_parameter_ref isn't a DW_TAG_formal_parameter that is bad data (which varlocs should error on). But it isn't an internal consistency check (for which varlocs should assert). Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Check validity of dwarf_getabbrev arguments.Mark Wielaard2018-06-113-0/+19
| | | | | | | When the given Dwarf_Die was invalid we might crash and when the offset was totally bogus we might succeed with a random abbrev. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Fix cfi_debug_bias assert in varlocs.Mark Wielaard2018-06-102-1/+7
| | | | | | | | It is only a consistency issue if we actually have an cfi_debug and the cfi_debug_bias is not zero (because they come from the same file as the other debug data). Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Turn format_print_dwarf into print_dwarf_addr.Mark Wielaard2018-06-092-26/+30
| | | | | | | | | | | We don't really need to setup a buffer, print into it and then print it out to stdout. Simplify the code by directly printing the address (and symbol name). This also showed a small error in the output of DW_LLE_startx_length. It had two unintended trailing dots. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Use error, not assert, when trying to print a non-base type DIE.Mark Wielaard2018-06-082-1/+7
| | | | | | | | | When using the varlocs test with a fuzzer using assert for internal sanity checks is great to find issues. But when encountering bad data using an assert is wrong. Just use error to show we handle the data correctly (by reporting it is bad, instead of crashing). Signed-off-by: Mark Wielaard <[email protected]>
* tests: Drop shared libraries from self_test_files_exe.Mark Wielaard2018-06-022-7/+8
| | | | | | | | | Commit 00d89086 "tests: Split self_test_files into an exe, lib and obj list" accidentially left the shared libraries in the self_test_files_exe. Causing all shared libraries to be tested twice. Drop them and keep just four ET_EXE files: addr2line, elfcmp, objdump and readelf. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Fix .debug_types printing with implicit section_info.Mark Wielaard2018-06-013-0/+130
| | | | | | | | | | | | | Commit 314e9d7d "readelf: Handle .debug_info first if any other debug section needs it" disabled section_info printing if it was already handled. But section_types was an alias for section_info. So unless section_info was explicitly printed, .debug_types wasn't. Make section_types its own thing to print .debug_types and make section_info imply section_types. Add a testcase to make sure .debug_types is now printed. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Deal with combined normal and split dwarf DebugFission .debug_loc.Mark Wielaard2018-06-016-0/+343
| | | | | | | | | | | | | Normal and split dwarf from GNU DebugFission look the same, but should be treated competely separtely. When having a file with both skeletons and real compile units only note the secoffsets into the real .debug_loc in readelf. Otherwise or known_locslistptr will get confused. Add a testfile that combines an normal -gdwarf-4 object with a -gsplit-dwarf object. libdw already got this right, but add a run-varlocs.sh test to make sure. Signed-off-by: Mark Wielaard <[email protected]>
* tests: Split self_test_files into an exe, lib and obj list.Mark Wielaard2018-06-014-6/+53
| | | | | | | | | | Introduce testrun_on_self_exe and testrun_on_self_lib. Some tests cannot handle (unrelocated) ET_REL object files. run-get-units-split.sh and run-unit-info.sh only handle executables and shared libraries. This allows running the whole testsuite on an elfutils build done with CFLAGS="-gdwarf-4 -gsplit-dwarf -O2". Signed-off-by: Mark Wielaard <[email protected]>
* tests: Run run-low_high_pc.sh testcase on split dwarf files.Mark Wielaard2018-06-013-6/+46
| | | | | | | Test that the low high pc attributes can be properly resolved also in split dwarf setups. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Don't crash on invalid die in dwarf_dieoffset.Mark Wielaard2018-05-312-1/+18
| | | | | | | | Add explicit test in get-units-invalid for dwarf_cuoffset and dwarf_dieoffset. Make sure dwarf_dieoffset returns (Dwarf_Off) -1 on failure. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Handle split Dwarf Dies in dwarf_die_addr_die.Mark Wielaard2018-05-313-0/+35
| | | | | | | | | | | | | | | | | | | dwarf_die_addr_die can be used to turn an Dwarf_Die addr back into a full Dwarf_Die, just given the original Dwarf debug handle. This now also works for Dwarf_Dies which originated from a split Dwarf. Whenever a split Dwarf_CU is found the Dwarf it originated from is registered with the Dwarf that the skeleton Dwarf_CU came from. All registered split Dwarfs are then searched by dwarf_die_addr_die if the addr didn't match the main Dwarf or the alt Dwarf. One limitation in this implementation is that only DIEs that come from the main .debug_info in the .dwo are supported. Theoretically there could also be DIEs in an .debug_type or from other/multiple (comdat) sections. New tests are added for dwarf-4, dwarf-5, split-dwarf-4, split-dwarf-5 and version 4 and 5 dwo files. Signed-off-by: Mark Wielaard <[email protected]>
* readelf, libdw: Add GNU DebugFission .debug_loc support.Mark Wielaard2018-05-313-0/+220
| | | | | | | | | | GNU DebugFission .debug_loc location lists uses the .debug_loc section in the split dwarf .dwo file. The encoding is a mix of old style DWARF .debug_loc and new style .debug_loclists. Add two testcases for the readelf and libdw decoders. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Fix regression with multiple files and implicit debug_info reading.Mark Wielaard2018-05-312-1/+46
| | | | | | | | | | | | | | Commit 314e9d7d "readelf: Handle .debug_info first if any other debug section needs it" introduced a regression when handling multiple files. The implicit and explicit printing of debuginfo weren't reset and so the second file would not show (or scan) the .debug_info section when needed. Fix by resetting the implicit and explicit section printing flags. Add a testcase that prints the .debug_loc section for two files and check that the CUs are resolved. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Fix memory corruption in libdw_find_split_unit.Mark Wielaard2018-05-303-2/+40
| | | | | | | | | | | Found by valgrind when trying to match a split unit from a .dwo file that doesn't contain the split unit (as first) match. We would close the split Dwarf too early, before we had inspected all units in it. Add a testcase that simulates this. Which failed (at least under valgrind as run by make distcheck) before the fix. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Handle .debug_str_offsets.Mark Wielaard2018-05-303-2/+219
| | | | | | | | | | | | | | | | The .debug_str_offsets tables are indirect string offsets into the .debug_str section. For DWARF5 they can be in both the main, skeleton and split dwarf (.dwo) files. For DWARF4 with the GNU DebugFission extension the tables will not have an header and they will only be in the split DWARF (.dwo) file, never in the main (skeleton) file. For DWARF5 the (non-split) unit DIE will have a DW_AT_str_offsets_base attribute pointing at the actual index (after the header). The split unit will never have this attribute (and use the table at offset zero). Signed-off-by: Mark Wielaard <[email protected]>
* readelf handle .debug_addr section.Mark Wielaard2018-05-304-2/+154
| | | | | | | | | | Add debug-dump=addr which will show the .debug_addr section tables. The only tricky bit is the fact that GNU DebugFission, a DWARF4 extension, didn't produce unit table headers. So if we see a mixed DWARF4/5 .debug_addr table we have to reconstruct the table length from the CU DIE DW_AT_[GNU_]_addr_base offsets. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Handle .debug_loclists in dwarf_getlocation.Mark Wielaard2018-05-303-8/+191
| | | | | | | | | | | | | Handle all new DW_LLE opcodes in .debug_loclists in dwarf_getlocation. __libdw_read_begin_end_pair_inc now also handles a default location (which is simply the range [0,-1]). Since expression blocks can now also come from the .debug_loclists section add a new fake_loclists_cu necessary for checking bounds while parsing expression blocks. Adapt varlocs test to handle debug-only files. Test testfileranges5.debug and testfilesplitranges5.debug with it. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Handle .debug_loclists.Mark Wielaard2018-05-292-0/+564
| | | | | | | | | The new DWARF5 .debug_loclists sections are like .debug_rnglists, but plus locations. For Split Dwarf GCC generates the .debug_loclists fully in the split .dwo file. Any references to addresses need to be resolved through the skeleton .debug_addr section. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Handle .debug_rnglists in dwarf_ranges.Mark Wielaard2018-05-288-1/+91
| | | | | | | | | Handle all new DW_RLE opcodes in .debug_rnglists in dwarf_ranges. Extract code for reading .debug_addr indexes from dwarf_formaddr as __libdw_addrx to reuse in __libdw_read_begin_end_pair_inc. And add new testcase for "plain" DWARF5 and add a new test all-dwarf-ranges to test split DWARF5. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Add .debug_rnglists support.Mark Wielaard2018-05-273-1/+244
| | | | | | | | Parse the .debug_rnglists section for DWARF5 --debug-dump=ranges. Add testcase to show both "normal" and "split" DWARF variants are handled for DWARF4 and DWARF5. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Support DW_OP_addrx/constx and split DWARF addrx/constx support.Mark Wielaard2018-05-259-14/+299
| | | | | | | | | | | | | | | | | | | DW_OP_addrx/constx and GNU DebugFission DW_OP_GNU_addr/const_index take as argument an index into the .debug_addr section for the associated CU. This index gets resolved through dwarf_getlocation_attr. A new fake addr CU is created per Dwarf for use with this new attribute. For split DWARF files, the IDX_debug_addr gets replaced with the skeleton section and the addr base is resolved immediately when constructing the split DWARF CU. Move __libdw_cu_addr_base to libdwP.h to share with eu-readelf. Also make it possible to resolve addrx[1234]/GNU_addr_index also as constant indexes to (also) show when displaying these attributes in eu-readelf. A new varlocs tests is added to test the resolving for both the DWARF4 and DWARF5 DW_OP variants. And now that addrx forms are resolved in split DWARF files add the new DIEs with "single ranges" (those DIEs that have a lowpc/highpc attribute pair) to run-all-dwarf-ranges.sh. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Add new dwarf_cu_info function.Mark Wielaard2018-05-244-3/+417
| | | | | | | | | | | | | This allows getting a (split) subdie lazily, only when needed. All arguments to dwarf_get_units are optional. When not given then unit DIE and sub DIE are not looked up. This new function allows them to be looked up when not immediately retrieved with dwarf_get_units, or for a Dwarf_CU gotten through some other way. Add a new testcase to make sure the results of calling dwarf_cu_info and dwarf_get_units are consistent. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Initialize ranges_base, add invalid DWARF test and fix expected output.Mark Wielaard2018-05-243-4/+17
| | | | | | | | We never initialized the CU ranges_base, which meant we didn't actually calculate it correctly. This caused bad ranges on some DIEs. The expected output in the testcase was wrong. We also crashed on invalid dwarf. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Handle GNU DebugFission split ranges.Mark Wielaard2018-05-237-3/+161
| | | | | | | | | | | | | | | | | GNU DebugFission split dwarf handles DW_FORM_sec_offset specially for attributes that point to ranges. The .debug_ranges section is not in the .dwo file, but in the main/skeleton object file. The sec_offset is not relocated (in the ELF file), but is an offset against the skeleton DIE DW_AT_GNU_ranges_base attribute. dwarf_formudata is changed so it still looks like a normal offset ptr into the .debug_ranges section. dwarf_ranges is adapted to look for the .debug_ranges in the main object file. dwarf_highpc and dwarf_lowpc now handle the highpc and lowpc attributes being inherited for the split unit DIE from the skeleton. A new testcase is added to iterate over all ranges in a split GNU DebugFission file. Signed-off-by: Mark Wielaard <[email protected]>