Bug 29436 - [gdb/symtab] read.c:2352: internal-error: read_addrmap_from_aranges: Assertion `insertpair.second' failed.
Summary: [gdb/symtab] read.c:2352: internal-error: read_addrmap_from_aranges: Assertio...
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: symtab (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 13.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-02 07:16 UTC by Tom de Vries
Modified: 2022-08-08 08:19 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
tentative patch (970 bytes, patch)
2022-08-02 07:54 UTC, Tom de Vries
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2022-08-02 07:16:33 UTC
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".
Comment 1 Tom de Vries 2022-08-02 07:52:32 UTC
(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 */
...
Comment 2 Tom de Vries 2022-08-02 07:54:16 UTC
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.
...