]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: fix loading compressed scripts from `.debug_gdb_scripts`-section
authorMaximilian Bosch <maximilian@mbosch.me>
Fri, 10 Oct 2025 09:20:42 +0000 (11:20 +0200)
committerTom Tromey <tromey@adacore.com>
Wed, 22 Oct 2025 14:42:27 +0000 (08:42 -0600)
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 <iostream>
    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 <tom@tromey.com>
gdb/gdb_bfd.c

index 4c641fe4c7b88094003b47ca77040b533f039453..2cba9adceea86303a0249796e0daa4391119c280 100644 (file)
@@ -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<gdb::mutex> 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.  */