Gdb can create inferiors based on object files. With -gdwarf-4 -fdebug-types-section, we get multiple .debug_types sections, which gdb deals with, see create_all_units: ... for (dwarf2_section_info §ion : per_objfile->per_bfd->types) read_comp_units_from_section (per_objfile, §ion, &per_objfile->per_bfd->abbrev, 0, types_htab, rcuh_kind::TYPE); ... However, with -gdwarf-5 -fdebug-types-section, we get multiple .debug_info sections, and that's not supported currently.
Demonstrator: ... $ cat test.c namespace sp1 { class A { int i; const int c1 = 1; const int c2 = 2; const int c3 = 3; const int c4 = 4; const int c5 = 5; const int c6 = 6; }; } sp1::A a; int main (void) { return 0; } $ g++ test.c -g -gdwarf-5 -fdebug-types-section -S $ fgrep ".section" test.s .section .text._ZN3sp11AC2Ev,"axG",@progbits,_ZN3sp11AC5Ev,comdat .section .init_array,"aw" .section .debug_info,"G",@progbits,wi.bd7e4932b380e10c,comdat .section .debug_info,"",@progbits .section .debug_abbrev,"",@progbits .section .debug_aranges,"",@progbits .section .debug_rnglists,"",@progbits .section .debug_line,"",@progbits .section .debug_str,"MS",@progbits,1 .section .debug_line_str,"MS",@progbits,1 .section .note.GNU-stack,"",@progbits .section .note.gnu.property,"a" ...
Demonstrator using gdb: ... $ g++ test.c -g -gdwarf-5 -fdebug-types-section -c $ gdb -q -batch test.o -ex "ptype a" 'a' has unknown type; cast it to its declared type $ g++ test.c -g -gdwarf-4 -fdebug-types-section -c $ gdb -q -batch test.o -ex "ptype a" type = class sp1::A { int i; const int c1; const int c2; const int c3; const int c4; const int c5; const int c6; } ...
To trigger this in the testsuite: run test-case gdb.cp/static-print-quit.exp with target board debug-types, with a compiler defaulting to DWARF version 5, or edit the board file to force that version.
https://sourceware.org/pipermail/gdb-patches/2024-October/212611.html
The master branch has been updated by Tom de Vries <vries@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=80ac47851105702689004e07952ab6a4c04062b0 commit 80ac47851105702689004e07952ab6a4c04062b0 Author: Tom de Vries <tdevries@suse.de> Date: Tue Oct 29 10:08:04 2024 +0100 [gdb/symtab] Handle multiple .debug_info sections When compiling dw2-multiple-debug-info.c using -gdwarf-5 -fdebug-types-section, we end with two .debug_info sections in the object file: ... $ g++ gdb.dwarf2/dw2-multiple-debug-info.c -c -g \ -gdwarf-5 \ -fdebug-types-section $ readelf -WS dw2-multiple-debug-info.o | grep -v RELA | grep .debug_info [10] .debug_info PROGBITS 0 000128 0000cd 00 GC 0 0 8 [12] .debug_info PROGBITS 0 0001f8 0000ad 00 C 0 0 8 ... One of them contains the CU for dw2-multiple-debug-info.c, the other contains the TU for the type of variable a. When trying to print the type of variable a, we get: ... $ gdb -q -batch dw2-multiple-debug-info.o -ex "ptype a" 'a' has unknown type; cast it to its declared type ... because the TU hasn't been read. Fix this by adding support for reading multiple .debug_info sections, similar to how that is done for multiple .debug_types sections, getting us instead: ... $ gdb -q -batch dw2-multiple-debug-info.o -ex "ptype a" type = class sp1::A { ... } ... Tested on x86_64-linux. PR symtab/32223 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32223
Fixed.