From 8eb1701823e46179e3adcb49abf57126b3c49f28 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Fri, 10 Oct 2025 11:20:42 +0200 Subject: [PATCH] gdb: fix loading compressed scripts from `.debug_gdb_scripts`-section The function `gdb_bfd_get_full_section_contents` doesn't implement decompressing debug sections. This regresses loading `.debug_gdb_scripts`-section from ELFs that were built with `-ggdb -Wa,--compress-debug-sections` giving the following warnings on load: warning: BFD: /home/ma27/.cache/debuginfod_client/8284e3a74f442359679ee97e96ee1c434e4479b7/debuginfo: unable to get decompressed section .debug_gdb_scripts warning: Couldn't read .debug_gdb_scripts section of /home/ma27/.cache/debuginfod_client/8284e3a74f442359679ee97e96ee1c434e4479b7/debuginfo The problem can be reproduced with a `test.cc` like this: __asm__(".pushsection \".debug_gdb_scripts\", \"MS\",%progbits,1\n" ".ascii \"\\4gdb.inlined-script.BOOST_OUTCOME_INLINE_GDB_PRETTY_PRINTER_H\\n\"\n" ".ascii \"import gdb.printing\\n\"\n" ".ascii \"import os\\n\"\n" /* a sufficiently long script such that it gets actually compressed */ ".byte 0\n" ".popsection\n"); #include int main(void) { std::cout << "hello world\n"; return 0; } I compiled the file with `g++ test.cc -o test-program -ggdb -Wa,--compress-debug-sections` (GCC version 14.3.0). As suggested, this refactors gdb_bfd_get_full_section_contents to use bfd_get_full_section_contents which implements decompression. Approved-By: Tom Tromey --- gdb/gdb_bfd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 4c641fe4c7b..2cba9adceea 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -1103,12 +1103,12 @@ gdb_bfd_get_full_section_contents (bfd *abfd, asection *section, gdb_bfd_data *gdata = (gdb_bfd_data *) bfd_usrdata (abfd); gdb::lock_guard guard (gdata->per_bfd_mutex); - bfd_size_type section_size = bfd_section_size (section); + bfd_size_type section_size = bfd_get_section_alloc_size (abfd, section); contents->resize (section_size); - return bfd_get_section_contents (abfd, section, contents->data (), 0, - section_size); + auto data = contents->data (); + return bfd_get_full_section_contents (abfd, section, &data); } /* See gdb_bfd.h. */