]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libdw: Parse DWARF package file index sections
authorOmar Sandoval <osandov@fb.com>
Wed, 6 Dec 2023 09:22:16 +0000 (01:22 -0800)
committerMark Wielaard <mark@klomp.org>
Thu, 15 Feb 2024 17:33:17 +0000 (18:33 +0100)
commit985112bc7d0f4eabbaa8a33fdcb241832db54642
tree4bf7dca434d3fa791bd0ae732598d1e9488159ca
parentacd9525e93d75d6f0e34c9302051cfebbb8f783f
libdw: Parse DWARF package file index sections

The .debug_cu_index and .debug_tu_index sections in DWARF package files
are basically hash tables mapping a unit's 8 byte signature to an offset
and size in each section used by that unit [1].  Add support for parsing
and doing lookups in the index sections.

We look up a unit in the index when we intern it and cache its hash
table row in Dwarf_CU.  Then, a new function, dwarf_cu_dwp_section_info,
can be used to look up the section offsets and sizes for a unit.  This
will mostly be used internally in libdw, but it will also be needed in
static inline functions shared with eu-readelf.  Additionally, making it
public it makes dwp support much easier for external tools that do their
own low-level parsing of DWARF information, like drgn [2].

1: https://gcc.gnu.org/wiki/DebugFissionDWP#Format_of_the_CU_and_TU_Index_Sections
2: https://github.com/osandov/drgn

* libdw/dwarf.h: Add DW_SECT_TYPES.
* libdw/libdwP.h (Dwarf): Add cu_index and tu_index.
(Dwarf_CU): Add dwp_row.
(Dwarf_Package_Index): New type.
(__libdw_dwp_find_unit): New declaration.
(dwarf_cu_dwp_section_info): New INTDECL.
Add DWARF_E_UNKNOWN_SECTION.
* libdw/Makefile.am (libdw_a_SOURCES): Add
dwarf_cu_dwp_section_info.c.
* libdw/dwarf_end.c (dwarf_end): Free dwarf->cu_index and
dwarf->tu_index.
* libdw/dwarf_error.c (errmsgs): Add DWARF_E_UNKNOWN_SECTION.
* libdw/libdw.h (dwarf_cu_dwp_section_info): New declaration.
* libdw/libdw.map (ELFUTILS_0.190): Add
dwarf_cu_dwp_section_info.
* libdw/libdw_findcu.c (__libdw_intern_next_unit): Call
__libdw_dwp_find_unit, and use it to adjust abbrev_offset and
assign newp->dwp_row.
* libdw/dwarf_cu_dwp_section_info.c: New file.
* tests/Makefile.am (check_PROGRAMS): Add cu-dwp-section-info.
(TESTS): Add run-cu-dwp-section-info.sh
(EXTRA_DIST): Add run-cu-dwp-section-info.sh and new test files.
(cu_dwp_section_info_LDADD): New variable.
* tests/cu-dwp-section-info.c: New test.
* tests/run-cu-dwp-section-info.sh: New test.
* tests/testfile-dwp-4-strict.bz2: New test file.
* tests/testfile-dwp-4-strict.dwp.bz2: New test file.
* tests/testfile-dwp-4.bz2: New test file.
* tests/testfile-dwp-4.dwp.bz2: New test file.
* tests/testfile-dwp-5.bz2: New test file.
* tests/testfile-dwp-5.dwp.bz2: New test file.
* tests/testfile-dwp.source: New file.

Signed-off-by: Omar Sandoval <osandov@fb.com>
20 files changed:
libdw/Makefile.am
libdw/dwarf.h
libdw/dwarf_cu_dwp_section_info.c [new file with mode: 0644]
libdw/dwarf_end.c
libdw/dwarf_error.c
libdw/libdw.h
libdw/libdw.map
libdw/libdwP.h
libdw/libdw_findcu.c
tests/.gitignore
tests/Makefile.am
tests/cu-dwp-section-info.c [new file with mode: 0644]
tests/run-cu-dwp-section-info.sh [new file with mode: 0755]
tests/testfile-dwp-4-strict.bz2 [new file with mode: 0755]
tests/testfile-dwp-4-strict.dwp.bz2 [new file with mode: 0644]
tests/testfile-dwp-4.bz2 [new file with mode: 0755]
tests/testfile-dwp-4.dwp.bz2 [new file with mode: 0644]
tests/testfile-dwp-5.bz2 [new file with mode: 0755]
tests/testfile-dwp-5.dwp.bz2 [new file with mode: 0644]
tests/testfile-dwp.source [new file with mode: 0644]