Support lazy reading and downloading of DWARF debuginfo
Currently valgrind attempts to read DWARF .debug_* sections as well
as separate debuginfo files for ELF binaries as soon as a shared library
is loaded. This might also result in the downloading of separate debuginfo
files via debuginfod.
This is inefficient when some of this debuginfo never ends up being used
by valgrind while running the client process.
This patch adds support for lazy reading and downloading of DWARF
debuginfo. When an ELF shared library is loaded, the reading of .debug_*
sections as well as separate or alternate debuginfo is deferred until
valgrind handles an instruction pointer corresponding to a text segment
of the shared library. At this point the deferred sections and separate
debug files are loaded.
This feature is only supported on ELF platforms.
https://bugs.kde.org/show_bug.cgi?id=471807
ChangeLog
* debuginfo.c (di_notify_ACHIEVE_ACCEPT_STATE): Replace
read_elf_debug_info with read_elf_object.
(addr_load_di): New function. Attempts to load deferred debuginfo
associated with a given address.
(load_di): New function. Attempts to load a given deferred
debuginfo associated with a given address.
(describe_IP): Add calls to load_di and addr_load_di.
(find_DiCfSI): Add call to load_di.
* priv_readelf.h (read_elf_object): New declaration.
(read_elf_debug): Ditto.
* priv_storage.h (struct _DebugInfo): New field 'bool deferred'.
* readelf.c (read_elf_debug_info): Split into read_elf_object and
read_elf_debug.
(read_elf_object): Read non .debug_* section from an ELF binary.
(read_elf_debug): Read .debug_* sections from an ELF binary as
as well any separate/alternate debuginfo files.
* storage.c (canonicaliseSymtab): Remove assert in order to support
canonicalization of deferred _DebugInfo.
(finish_CFSI_arrays): Add early return if _DebugInfo is
deferred in order to avoid freeing memory that will be needed
when reading debuginfo at a later time.
(canonicaliseTables): Ditto.
* pub_core_debuginfo.h (addr_load_di): New declaration.
(load_di): New declaration.