I recently added this assert: ... /* Assume no duplicate offsets in all_comp_units. */ gdb_assert (insertpair.second); ... in read_addrmap_from_aranges, and I was curious if I could trigger it. So I started out with: ... $ gcc ~/hello.c -g -save-temps ... and then manually added this (copied and modified from gdb.dwarf2/clang-debug-names.exp.tcl): ... .ident "GCC: (SUSE Linux) 7.5.0" + .section .debug_names + .4byte .Ldebug_names_end - .Ldebug_names_start + .Ldebug_names_start: + .short 5 /* Header: version */ + .short 0 /* Header: padding */ + .long 2 /* Header: compilation unit count */ + .long 0 /* Header: local type unit count */ + .long 0 /* Header: foreign type unit count */ + .long 0 /* Header: bucket count */ + .long 0 /* Header: name count */ + .long 1 + /* Header: abbreviation table size */ + .long 0 /* Header: augmentation string size */ + .long .Ldebug_info0 /* Compilation unit 0 */ + .long .Ldebug_info0 /* Compilation unit 0 */ + .byte 0 + .p2align 2 + .Ldebug_names_end: + .section .note.GNU-stack,"",@progbits ... in hello.s. [ Actually, I started out with abbreviation table size 0, but gdb doesn't grok it, it always expects a terminating byte. ] This is an empty index, and this bit: ... /* Don't use the index if it's empty. */ if (map->name_count == 0) return false; ... in dwarf2_read_debug_names prevents us from using it, but after disabling it we have indeed: ... $ gdb -q -batch a.out src/gdb/dwarf2/read.c:2352: internal-error: read_addrmap_from_aranges: Assertion `insertpair.second' failed. ... We should handle this in create_cus_from_debug_names_list or some such. Likewise for .gdb_index. Note btw that the standard bit that is violated here is: "For a per-module index, there will be one CU entry for each compile unit in the module".
(In reply to Tom de Vries from comment #0) > + .long 0 /* Header: augmentation string size */ In order to trigger the map.augmentation_is_gdb case in create_cus_from_debug_names_list, I've changed this to: ... .long 4 /* Header: augmentation string size */ .ascii "GDB\0" /* Header: augmentation string */ ...
Created attachment 14249 [details] tentative patch Gets us: ... $ gdb -q -batch a.out warning: Section .debug_names has duplicate entry in CU table,ignoring .debug_names. ...
https://sourceware.org/pipermail/gdb-patches/2022-August/191230.html
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=c7cd10637c40a72564bc813f3f16a4ba4b13d21b