]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libdw: dwarf_getsrcfiles should not imply dwarf_getsrclines
authorAaron Merey <amerey@redhat.com>
Mon, 25 Mar 2024 19:57:25 +0000 (15:57 -0400)
committerAaron Merey <amerey@redhat.com>
Thu, 11 Apr 2024 16:34:43 +0000 (12:34 -0400)
commitd4b0848be5f575ff9464fee12ce7be416e4fb392
tree069c99466a5e380ed949dedac2c695f9a576339e
parentdb33cb0cac3253c34881c0377ada51d9803eaae0
libdw: dwarf_getsrcfiles should not imply dwarf_getsrclines

dwarf_getsrcfiles causes line data to be read in addition to file data.
This is wasteful for programs which only need file or directory names.
Debuginfod server is one such example.

Fix this by moving the srcfile reading in read_srclines into a separate
function read_srcfiles.  This change improves debuginfod server's max
resident set size by up to 75% during rpm indexing.

* libdw/dwarf_getsrcfiles.c (dwarf_getsrcfiles): Replace
dwarf_getsrclines and __libdw_getsrclines with
__libdw_getsrcfiles.
* libdw/dwarf_getsrclines.c (read_line_header): New function.
(read_srcfiles): New function.
(read_srclines): Move srcfile reading into read_srcfiles.
Add parameter to use cached srcfiles if available.
Also merge srcfiles with any files from DW_LNE_define_file.
(__libdw_getsrclines): Changed to call get_lines_or_files.
(__libdw_getsrcfiles): New function.  Calls get_lines_or_files.
(get_lines_or_files): New function based on the old
__libdw_getsrclines.  Call read_srcfiles if linesp is NULL,
otherwise call read_srclines.  Pass previously read srcfiles
to read_srclines if available.
* libdw/dwarf_macro_getsrcfiles.c (dwarf_macro_getsrcfiles):
Replace __libdw_getsrclines with __libdw_getsrcfiles.
* libdw/libdwP.h (__libdw_getsrcfiles): New declaration.
* tests/.gitignore: Add new test binary.
* tests/get-files.c: Verify that dwarf_getsrcfiles does
not cause srclines to be read.
* tests/get-lines.c: Verify that srclines can be read
after srcfiles have been read.
* tests/Makefile.am: Add new testfiles.
* tests/get-files-define-file.c: Print file names before
and after reading DW_LNE_define_file.
* tests/run-get-files.sh: Add get-files-define-file test.
* tests/testfile-define-file.bz2: New testfile.  Copy of
testfile36.debug but with a line program consisting of two
DW_LNE_define_file opcodes.

https://sourceware.org/bugzilla/show_bug.cgi?id=27405

Signed-off-by: Aaron Merey <amerey@redhat.com>
libdw/dwarf_getsrcfiles.c
libdw/dwarf_getsrclines.c
libdw/dwarf_macro_getsrcfiles.c
libdw/libdwP.h
tests/.gitignore
tests/Makefile.am
tests/get-files-define-file.c [new file with mode: 0644]
tests/get-files.c
tests/get-lines.c
tests/run-get-files.sh
tests/testfile-define-file.bz2 [new file with mode: 0644]