]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: skip broken .debug_macro.dwo
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 6 May 2025 17:03:47 +0000 (13:03 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 12 May 2025 18:50:31 +0000 (14:50 -0400)
Running gdb.base/errno.exp with gcc <= 13 with split DWARF results in:

    $ make check TESTS="gdb.base/errno.exp" RUNTESTFLAGS="CC_FOR_TARGET=gcc-13 --target_board=fission"
    (gdb) break -qualified main
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:7549: internal-error: locate_dwo_sections: Assertion `!dw_sect->readin' failed.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.
    ...
    FAIL: gdb.base/errno.exp: macros: gdb_breakpoint: set breakpoint at main (GDB internal error)

The assert being hit has been added in 28f15782adab ("gdb/dwarf: read
multiple .debug_info.dwo sections"), but it merely exposed an existing
problem.

gcc versions <= 13 are affected by this bug:

  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111409

Basically, it produces .dwo files with multiple .debug_macro.dwo
sections, with some unresolved links between them.  I think that this
macro debug info is unusable, and all we can do is ignore it.

In locate_dwo_sections, if we detect a second .debug_macro.dwo section,
forget about the previous .debug_macro.dwo and any subsequent one.  This
will effectively make it as if the macro debug info wasn't there at all.

The errno test seems happy with it:

    # of expected passes            84
    # of expected failures          8

Change-Id: I6489b4713954669bf69f6e91865063ddcd1ac2c8
Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/read.c

index 550968abc95c9eb8b35fa2718cc3f1305dd8664c..891e10f6e816135e002ee32529291b59bfcb5ffe 100644 (file)
@@ -7516,6 +7516,7 @@ cutu_reader::locate_dwo_sections (objfile *objfile, dwo_file &dwo_file)
 {
   const struct dwop_section_names *names = &dwop_section_names;
   dwo_sections &dwo_sections = dwo_file.sections;
+  bool complained_about_macro_already = false;
 
   for (asection *sec : gdb_bfd_sections (dwo_file.dbfd))
     {
@@ -7534,7 +7535,24 @@ cutu_reader::locate_dwo_sections (objfile *objfile, dwo_file &dwo_file)
       else if (names->macinfo_dwo.matches (sec->name))
        dw_sect = &dwo_sections.macinfo;
       else if (names->macro_dwo.matches (sec->name))
-       dw_sect = &dwo_sections.macro;
+       {
+         /* gcc versions <= 13 generate multiple .debug_macro.dwo sections with
+            some unresolved links between them.  It's not usable, so do as if
+            there were not there.  */
+         if (!complained_about_macro_already)
+           {
+             if (dwo_sections.macro.s.section == nullptr)
+               dw_sect = &dwo_sections.macro;
+             else
+               {
+                 warning (_("Multiple .debug_macro.dwo sections found in "
+                            "%s, ignoring them."), dwo_file.dbfd->filename);
+
+                 dwo_sections.macro = dwarf2_section_info {};
+                 complained_about_macro_already = true;
+               }
+           }
+       }
       else if (names->rnglists_dwo.matches (sec->name))
        dw_sect = &dwo_sections.rnglists;
       else if (names->str_dwo.matches (sec->name))