summaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* readelf: Call __fsetlocking (stdout, FSETLOCKING_BYCALLER).Mark Wielaard2018-06-042-0/+9
| | | | | | | | | | We only call printf on stdout from one thread, so we don't need internal stdio locking for stdout. On my machine eu-readelf -N --debug-dump=info libxul.so > /dev/null goes from 65 seconds to 63 seconds. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Try both the relative and absolute paths when finding a .dwo file.Mark Wielaard2018-06-012-1/+17
| | | | | | | | We would give up if one of them failed. With this fixed a self-test with make check succeeds when building elfutils itself with CFLAGS set to "-gdwarf-4 -gdwarf-split -O2". Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Fix .debug_types printing with implicit section_info.Mark Wielaard2018-06-012-6/+19
| | | | | | | | | | | | | 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-012-3/+16
| | | | | | | | | | | | | 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]>
* readelf: Use correct listptr when looking up next loc for locview attr.Mark Wielaard2018-05-312-1/+6
| | | | | | | | We were using loclistsptr instead of locsptr in print_debug_loc_section. https://sourceware.org/bugzilla/show_bug.cgi?id=23247 Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Don't crash on invalid die in dwarf_dieoffset.Mark Wielaard2018-05-312-1/+5
| | | | | | | | 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]>
* readelf, libdw: Add GNU DebugFission .debug_loc support.Mark Wielaard2018-05-312-6/+79
| | | | | | | | | | 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/+14
| | | | | | | | | | | | | | 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-302-1/+6
| | | | | | | | | | | 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-302-1/+221
| | | | | | | | | | | | | | | | 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-302-2/+277
| | | | | | | | | | 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-302-1/+8
| | | | | | | | | | | | | 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-13/+568
| | | | | | | | | 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]>
* readelf: Find skeleton units when inspecting split .dwo (--dwarf-skeleton).Mark Wielaard2018-05-282-26/+257
| | | | | | | | | | | | | | | | | | | To get the right context (especially addresses) when looking at a .dwo file we really need the skeleton file. If we can find it (simply replace .dwo with .o) then use that to get to the split DWARF units so that libdw sets up all relevant information to resolve. Also adds a --dwarf-skeleton option so the user can explicitly give a skeleton file to use (for example when all .o files are linked and removed already). Unfortunately this might not work if libdw cannot get from the skeleton file to the .dwo file (because they have been moved around). In that case eu-readelf "cheats", it will link up the libdw datastructures so that the skeleton and split DWARF units are setup correctly anyway. This does introduce a problem when trying to cleanup the Dwarf handle ownership graph. So we will deliberately leak memory by not closing the underlying Dwfl in that case. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Handle .debug_rnglists in dwarf_ranges.Mark Wielaard2018-05-282-1/+4
| | | | | | | | | 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-272-15/+524
| | | | | | | | 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-252-7/+66
| | | | | | | | | | | | | | | | | | | 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]>
* readelf: print split CUs when given --debug-dump=info+Mark Wielaard2018-05-242-18/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To show the difference between "regular" CUs and split CUs print offsets and references between { and } instead of [ and ]. When --debug-dump=info+ is given (implied by -w) instead of --debug-dump=info any skeleton unit will be immediately followed by the corresponding split compile unit (from the .dwo file). DWARF section [27] '.debug_info' at offset 0x1075: [Offset] Compilation unit at offset 0: Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4 Unit type: skeleton (4), Unit id: 0xc152129eb4b99599 [ b] compile_unit abbrev: 1 ranges (sec_offset) range list [ 0] low_pc (addr) +000000000000000000 stmt_list (sec_offset) 0 GNU_dwo_name (strp) "foo.dwo" comp_dir (strp) "/tmp" GNU_pubnames (flag_present) yes GNU_addr_base (sec_offset) 0 GNU_dwo_id (data8) 0xc152129eb4b99599 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: 0xc152129eb4b99599 { b} compile_unit abbrev: 1 producer (GNU_str_index) "GNU C11 7.3.0 -gsplit-dwarf -g" language (data1) C99 (12) name (GNU_str_index) "foo.c" comp_dir (GNU_str_index) "/tmp" GNU_dwo_id (data8) 0xc152129eb4b99599 { 18} subprogram abbrev: 2 external (flag_present) yes name (GNU_str_index) "main" decl_file (data1) foo.c (1) decl_line (data1) 1 type (ref4) { 2b} high_pc (data8) 3 frame_base (exprloc) [ 0] call_frame_cfa GNU_all_call_sites (flag_present) yes { 2b} base_type abbrev: 3 byte_size (data1) 4 encoding (data1) signed (5) name (string) "int" Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Recognize GNU DebugFission split units.Mark Wielaard2018-05-192-1/+7
| | | | | | | | | The split dwarf dwo unit id and type are not in the CU header itself, but can be found in the CU DIE DW_AT_GNU_dwo attributes. Use this to set the correct unit_type and id for GNU DebugFission split units. Also show this information in eu-readelf when printing units. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Add GNU DebugFission attributes, tags, forms and operands.Mark Wielaard2018-05-192-2/+27
| | | | | | Most are handled just like their DWARF5 counterparts. Signed-off-by: Mark Wielaard <[email protected]>
* libdw, readelf: Handle .debug_*.dwo section name variants.Mark Wielaard2018-05-192-11/+25
| | | | | | | | | | | The .debug_*.dwo section names are handled just like their none .dwo variants. The section contents is the same as sections without the .dwo name, but they are only found in split-dwarf files. This patch allows opening and inspecting split-dwarf files. It doesn't yet connect the split-dwarf with their skeleton (or the other way around). It also doesn't yet handle any special split-dwarf attributes or tags. Signed-off-by: Mark Wielaard <[email protected]>
* elflint: fix typo in error diagnosticsDmitry V. Levin2018-05-152-2/+6
| | | | Signed-off-by: Dmitry V. Levin <[email protected]>
* readelf: Fix 32bit compile issues.Mark Wielaard2018-05-152-5/+11
| | | | Signed-off-by: Mark Wielaard <[email protected]>
* readelf, libdw: Handle DWARF5 .debug_macro.Mark Wielaard2018-05-152-45/+30
| | | | | | | | | | Almost identical to GNU .debug_macro extension. Just accept and use DW_AT_macros where we accept or use DW_AT_GNU_macros. And be a little stricter in which FORMs we accept (this could have caused problems with the GNU variant too). Deals with DW_FORM_strx[1234], but not yet with imported macros through DW_MACRO_import_sup. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Add DWARF5 .debug_line support.Mark Wielaard2018-05-152-194/+528
| | | | | | | | | | | | This only changes the parsing of the directory and file name tables. It does this by sharing the printing of (non-CU based) from data from the .debug_macro code. Adding support for printing strx[1234] form data by sharing the code that detects the correct str_offsets_base in libdw. The header format is also cleaned up a bit so that it better lines out. Testcases adjusted and new ones added. Signed-off-by: Mark Wielaard <[email protected]>
* addr2line: Add explicit fflush for stdout when reading from stdin.Mark Wielaard2018-05-122-0/+6
| | | | | | | | | To make it possible to use eu-addr2line interactively through a pipe we need to explicitly flush stdout after handling each line from stdin. https://sourceware.org/bugzilla/show_bug.cgi?id=23173 Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Use raw section data if nothing is available through libdw.Mark Wielaard2018-05-112-11/+28
| | | | | | | | | | For various debug data sections readelf has its own parsers that don't rely on libdw data structures or functions. But we still like to get the data through libdw since that will be uncompressed and/or relocated. But there can be reasons for libdw to have rejected the section data. In that case we want to try to parse the "raw" section data. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Handle .debug_info first if any other debug section needs it.Mark Wielaard2018-05-112-1/+45
| | | | | | | | | | Some debug sections need information from the CU DIEs to properly parse the data. Normally the .debug_info section is one of the first. But some DWARF producers reorder the sections and put it after some other debug sections. Make sure we first handle .debug_info if it is needed by any other debug section. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Handle DW_FORM_[ref|strp]_sup[48] as DW_FORM_GNU_[ref|strp]_alt.Mark Wielaard2018-05-112-0/+7
| | | | | | | | Although we don't yet handle DWARF5 supplemental files, they are like mostly like GNU alt files. This way using any of the supplemental files will at least generate an appropriate error message. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Handle .debug_line_str section.Mark Wielaard2018-05-062-8/+20
| | | | | | It is just a .debug_str section with another name. Signed-off-by: Mark Wielaard <[email protected]>
* Add support for RISC-VAndreas Schwab2018-04-232-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implements initial support for the RISC-V architecture. It has been tested with qemu linux-user emulation <https://build.opensuse.org/package/live_build_log/openSUSE:Factory:RISCV/elfutils/standard/riscv64>, with the following unresolved issues FAIL: run-strip-strmerge.sh =========================== elflint /home/abuild/rpmbuild/BUILD/elfutils-0.170/tests/elfstrmerge section [32] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0x51c0 does not match .got section address 0x5010 section [32] '.symtab': symbol 119: st_value out of bounds FAIL run-strip-strmerge.sh (exit status: 1) FAIL: run-elflint-self.sh ========================= section [33] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0x6220 does not match .got section address 0x6008 section [33] '.symtab': symbol 135: st_value out of bounds *** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/elflint --quiet --gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/addr2line section [33] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0x91d8 does not match .got section address 0x9040 section [33] '.symtab': symbol 163: st_value out of bounds *** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/elflint --quiet --gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/elfcmp section [33] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0x1a2a0 does not match .got section address 0x1a040 section [33] '.symtab': symbol 267: st_value out of bounds *** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/elflint --quiet --gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/elflint section [33] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0xd418 does not match .got section address 0xd0f0 section [33] '.symtab': symbol 238: st_value out of bounds *** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/elflint --quiet --gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/nm section [33] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0xa2d0 does not match .got section address 0xa0b0 section [33] '.symtab': symbol 193: st_value out of bounds *** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/elflint --quiet --gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/objdump section [33] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0x2e5b8 does not match .got section address 0x2e058 section [33] '.symtab': symbol 410: st_value out of bounds *** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/elflint --quiet --gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/readelf section [32] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0x171b8 does not match .got section address 0x17010 *** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/elflint --quiet --gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.170/libelf/libelf.so section [32] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0x3a5b0 does not match .got section address 0x3a0d8 *** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/elflint --quiet --gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.170/libdw/libdw.so section [31] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0xd0c8 does not match .got section address 0xd008 *** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/elflint --quiet --gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.170/backends/libebl_i386.so section [31] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0xf0c8 does not match .got section address 0xf008 *** failure in /home/abuild/rpmbuild/BUILD/elfutils-0.170/src/elflint --quiet --gnu-ld /home/abuild/rpmbuild/BUILD/elfutils-0.170/backends/libebl_x86_64.so FAIL run-elflint-self.sh (exit status: 1) FAIL: run-native-test.sh ======================== /home/abuild/rpmbuild/BUILD/elfutils-0.170/tests/allregs: dwfl_module_register_names: no backend registers known FAIL run-native-test.sh (exit status: 1) FAIL: run-backtrace-native-core.sh ================================== backtrace: backtrace.c:111: callback_verify: Assertion `symname && strcmp (symname, "raise") == 0' failed. ./test-subr.sh: line 84: 26040 Aborted (core dumped) LD_LIBRARY_PATH="${built_library_path}${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH" $VALGRIND_CMD "$@" backtrace-child-core.26027: no main rmdir: failed to remove 'test-26016': Directory not empty FAIL run-backtrace-native-core.sh (exit status: 1) In addition, all tests that use ptrace are failing as linux-user emulation does not implement it. There are no regressions for a x86_64 build. Signed-off-by: Andreas Schwab <[email protected]>
* readelf: Fix advance_pc to use op_addr_advance, not just op_advance.Mark Wielaard2018-04-162-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | Found by John Mellor-Crummey. The reason this bug wasn't found earlier is because gcc fixes minimum_instr_len and max_ops_per_instr to 1 for all architectures (in theory max_ops_per_instr could be overridden, but I didn't find any architecture that does). And op_index always seems zero (it looks like it is really only for special VLWI architectures). So in all cases I saw it means that: op_addr_advance = minimum_instr_len * ((op_index + op_advance) / max_ops_per_instr) = 1 * ((0 + op_advance) / 1) = op_advance Completely masking the bug. The libdw dwarf_getsrclines.c implementation does get this right. Because it doesn't care about the data representation and so does the calculation directly. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Only lookup files and show errors in attr_callback when not silent.Mark Wielaard2018-04-132-0/+7
| | | | | | | | | | | | We recently added a couple more sanity checks and show an error when attributes that represent files cannot be resolved. We should only do this when the attr_callback should print the attribute information. When not (for example when not showing the .debug_info section, but only collecting information about the CUs containing pointers into other sections) we don't need to lookup the file names, nor print the errors/warnings. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Add support for reading DW_FORM_strx[1234] in .debug_str_offsets.Mark Wielaard2018-04-032-0/+9
| | | | | | | | | Recognize the new .debug_str_offsets section. The CU will now hold a new str_off_base offset in that section for that CU. dwarf_form_string will decode DW_FORM_strx[1234] and return strings using that str_off_base from the .debug_addr. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Add support for reading DW_FORM_addrx[1234] in .debug_addr.Mark Wielaard2018-04-032-0/+9
| | | | | | | | | | | Recognize the new .debug_addr section. The CU will now hold a new address base offset in that section for that CU. dwarf_form_addr will decode DW_FORM_addrx[1234] and return addresses using that address base from the .debug_addr. A new internal function read_3ubyte_unaligned will try to read a 24-bit value depending on endianness of the underlying file. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Break sysv[64] symbol hash bucket chain loops.Mark Wielaard2018-03-302-0/+14
| | | | | | | | | | | The bucket chain should not contain loops. If it does we should mark the hash bucket chain as invalid. This is easily checked by noticing when we have seen more than the number of chain elements. Which equals the max number as symbols in the table. https://sourceware.org/bugzilla/show_bug.cgi?id=23011 Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Print dwarf_dieoffset as %PRIx64, not %zx.Mark Wielaard2018-03-272-1/+6
| | | | | | On 32bit architectures size_t is not 64bit... Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Report error when decl_file or call_file attribute is invalid.Mark Wielaard2018-03-272-3/+22
| | | | | | | | Report an error for why the DW_AT_decl_file or DW_AT_call_file cannot be resolved to a file name. This is likely invalid DWARF, a missing DW_AT_stmt_list attribute on the CU or a missing .debug_line section. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Add new DWARF5 Dwarf expression operations.Mark Wielaard2018-03-112-1/+31
| | | | | | | | | | | | | | DW_OP_implicit_pointer, DW_OP_entry_value, DW_OP_const_type, DW_OP_regval_type, DW_OP_deref_type, DW_OP_xderef_type, DW_OP_convert and OP_reinterpret are implemented like their pre-DWARF5 GNU variants. DW_OP_xderef_type is implemented as a (non-CU relative) variant of DW_OP_deref_type. DW_OP_addrx and DW_OP_constx are recognized but not interpreted yet. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Add some support for locviews.Mark Wielaard2018-03-052-7/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds minimal support for locviews as output by GCC8. It changes readelf to keep track of loclistptrs from DW_AT_GNU_locviews and prints the locview pairs for those. Since there is no terminator we have to keep track of where the next loclist entry starts. The --debug-dump=loc output looks as follows: CU [ 714] base: +0x0000000000003020 <elf_hash> [ b4] view pair 1, 2 [ b6] range 4, 7f +0x0000000000003024 <elf_hash+0x4>.. +0x000000000000309e <elf_hash+0x7e> [ 0] reg5 [ d9] view pair 3, 1 view pair 1, 2 [ dd] range 4, 4c +0x0000000000003024 <elf_hash+0x4>.. +0x000000000000306b <elf_hash+0x4b> [ 0] reg5 range 4c, 7f +0x000000000000306c <elf_hash+0x4c>.. +0x000000000000309e <elf_hash+0x7e> [ 0] reg2 Note that in the above output the view pairs correspond to the ranges immediately following in the loc list. This is how GCC8 currently outputs the locview pairs and ranges, but this is not guaranteed and you'll need to look at the location and GNU_locviews attributes of the DIE to know which really match up together. We might want to adjust the output to make this more clear. This does not yet add an locview accessor to libdw. It just recognizes the DW_AT_GNU_locviews attribute as a loclistptr when encoded as a sec_offset form. Signed-off-by: Mark Wielaard <[email protected]>
* elflint: Make sure we can read a whole element when iterating over group.Mark Wielaard2018-03-052-1/+6
| | | | | | | | Change the for loop so that we can always read a full element. https://sourceware.org/bugzilla/show_bug.cgi?id=22892 Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Add support for DWARF5 DW_FORM_data16.Mark Wielaard2018-02-212-1/+6
| | | | | | | | | | | | | | The DWARF5 spec says DW_FORM_data16 is constant class (128bit value). But we treat it as if it is block class. So to use a attribute that is encoded as DW_FORM_data16 use dwarf_formblock, not dwarf_form[us]data. We cannot use dwarf_form[us]data since they return a Dwarf_Word/Sword, which are only 64bits. This does mean we don't try to convert the value but just return it as a block of 16 raw bytes. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Handle DWARF5 DW_FORM_implicit_const. Add dwarf_getabbrevattr_data.Mark Wielaard2018-02-212-6/+15
| | | | | | | | | | Handle the new DW_FORM_implicit_const. The value of this form is embedded in the abbrev data (as sleb128) and not in the info DIE data. This also adds a new function dwarf_getabbrevattr_data which allows getting any data/value associated with a form. eu-readelf will use this new function to show the DW_FORM_implicit_const value. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Add new dwarf_get_units function to iterate over all units.Mark Wielaard2018-02-212-35/+112
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The dwarf_nextcu and dwarf_next_unit functions provide information to construct the offset to construct the associated CU DIE using dwarf_offdie or dwarf_offdie_types. This requires the user to know beforehand where to DIE data is stored (in the .debug_info or .debug_types section). For type units one also needs to use the type offset to create the actual type DIE. In DWARF5 DIEs can come from even more data locations. And there are also skeleton units which require the user to find the associated split compile unit DIE (which would come from a different file). The new dwarf_get_units function simplifies iterating over the units in a DWARF file. It doesn't require the user to know where the DIE data is stored, it will automagically iterate over all know data sources (sections) returning the Dwarf_CU and the associated Dwarf_Die if requested. If the user requests to know the associated "subdie" it will also be resolved. This implementation returns the correct subdie for type units. A future version will also handle skeleton units and return the associated skeleton DIE and split unit DIE. readelf has been adapted to use the new iterator and print the new DWARF5 unit header information (which it gets through dwarf_cu_die). The new interface hides which section exactly to iterate on (by design). readelf works around that by "cheating". It sets up a Dwarf_CU so that it gets the data from the right section, using the (normally) internal data structure. Signed-off-by: Mark Wielaard <[email protected]>
* Use fallthrough attribute.Joshua Watt2018-02-107-12/+27
| | | | | | | | | | | | | | | Use __attribute__ ((fallthrough)) to indicate switch case fall through instead of a comment. This ensures that the fallthrough warning is not triggered even if the file is pre-processed (hence stripping the comments) before it is compiled. The actual fallback implementation is hidden behind a FALLBACK macro in case the compiler doesn't support it. Finally, the -Wimplict-fallthrough warning was upgraded to only allow the attribute to satisfy it; a comment alone is no longer sufficient. Signed-off-by: Joshua Watt <[email protected]>
* readelf: Fix crash on reading loc data or range data with bad/no CUs.Mark Wielaard2018-01-252-2/+7
| | | | | | | | | | | | In print_debug_ranges_section and print_debug_loc_section we try to get the associated CU through skip_listptr_hole for the first data data. If no CU at all can be found (because the .debug_info section was bogus) this would keep the Dwarf_CU uninitialized causing a crash later on when it was compared to the last_cu and used because it was unequal. Fix this by explicitly initializing cu to last_cu (which is NULL on first use). Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Use dwarf_form_name for printing (unknown) forms.Mark Wielaard2018-01-012-3/+8
| | | | | | | | | | | | Use dwarf_form_name consistently to print forms. attr_callback was using its own string conversion, print_debug_macro_section was using dwarf_form_string instead of dwarf_form_name. The difference between dwarf_form_string and dwarf_form_name is that the first returns NULL if the form is unknown and the second returns an hexadecimal string representation in that case. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Format offset as DIE index (hex).Mark Wielaard2017-12-292-2/+7
| | | | | | That makes it so much easier to find the actual DIE offset in the output. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Try to continue after encountering bogus ELF Note data.Mark Wielaard2017-12-182-3/+8
| | | | | | | | There might be other sections or segments with ELF Notes that are readable. Also adjust error message depending on whether or not we actually got any data for the ELF Note segment or section. Signed-off-by: Mark Wielaard <[email protected]>
* readelf: Handle DW_OP_call2 and DW_OP_call4 correctly.Mark Wielaard2017-12-122-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | DW_OP_call2 and DW_OP_call4 didn't correctly advance the data pointer. This caused print_ops to produce garbage operands. Also format the arguments as DIE offsets. That makes it easier to follow the call to the actual dwarf_procedure DIE. Testcase from https://sourceware.org/bugzilla/show_bug.cgi?id=22532 The testcase only checks the eu-readelf output is correct for the byte_size attribute. But it might be interesting to write a full expression parser to check the actual sizes. [ 3e] structure_type name (strp) "pck__rec" byte_size (exprloc) [ 0] push_object_address [ 1] deref_size 1 [ 3] call4 [ 95] [ 8] plus_uconst 7 [ 10] const1s -4 [ 12] and [ 95] dwarf_procedure location (exprloc) [ 0] dup [ 1] lit1 [ 2] ne [ 3] bra 10 [ 6] lit4 [ 7] skip 31 [ 10] dup [ 11] lit4 [ 12] ne [ 13] bra 20 [ 16] lit0 [ 17] skip 31 [ 20] dup [ 21] lit3 [ 22] eq [ 23] bra 30 [ 26] lit0 [ 27] skip 31 [ 30] lit4 [ 31] swap [ 32] drop The "answer" depends on the Discr value (first byte at object address), and is rounded up to 4 or 8 bytes. Signed-off-by: Mark Wielaard <[email protected]>