diff options
author | Tom de Vries <tdevries@suse.de> | 2022-08-07 08:31:37 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2022-08-07 08:31:37 +0200 |
commit | c7cd10637c40a72564bc813f3f16a4ba4b13d21b (patch) | |
tree | c610c3779745c2bd03cf2384eb2e8984c2a8ba34 /gdb/dwarf2 | |
parent | f4cbdf0b6857069d42477e06f0077f4c03bb4c82 (diff) | |
download | binutils-c7cd10637c40a72564bc813f3f16a4ba4b13d21b.zip binutils-c7cd10637c40a72564bc813f3f16a4ba4b13d21b.tar.gz binutils-c7cd10637c40a72564bc813f3f16a4ba4b13d21b.tar.bz2 |
[gdb/symtab] Fix assert in read_addrmap_from_aranges
When loading the debug-names-duplicate-cu executable included in this
test-case, we run into:
...
(gdb) file debug-names-duplicate-cu^M
Reading symbols from debug-names-duplicate-cu...^M
src/gdb/dwarf2/read.c:2353: internal-error: read_addrmap_from_aranges: \
Assertion `insertpair.second' failed.^M
...
This assert was added in recent commit 75337cbc147 ("[gdb/symtab] Fix
.debug_aranges duplicate offset warning").
The assert triggers because the CU table in the .debug_names section contains
a duplicate:
...
Version 5
Augmentation string: 47 44 42 00 ("GDB")
CU table:
[ 0] 0x0
[ 1] 0x0
...
Fix this by rejecting the .debug_names index:
...
(gdb) file debug-names-duplicate-cu^M
Reading symbols from debug-names-duplicate-cu...^M
warning: Section .debug_names has duplicate entry in CU table, \
ignoring .debug_names.^M
...
Likewise for the case where the CU table is not sorted by increasing offset.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29436
Diffstat (limited to 'gdb/dwarf2')
-rw-r--r-- | gdb/dwarf2/read.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 348fbe1..84faeb4 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -4599,7 +4599,7 @@ read_debug_names_from_section (struct objfile *objfile, /* A helper for create_cus_from_debug_names that handles the MAP's CU list. */ -static void +static bool create_cus_from_debug_names_list (dwarf2_per_bfd *per_bfd, const mapped_debug_names &map, dwarf2_section_info §ion, @@ -4624,7 +4624,7 @@ create_cus_from_debug_names_list (dwarf2_per_bfd *per_bfd, sect_off, 0); per_bfd->all_comp_units.push_back (std::move (per_cu)); } - return; + return true; } sect_offset sect_off_prev; @@ -4643,6 +4643,18 @@ create_cus_from_debug_names_list (dwarf2_per_bfd *per_bfd, sect_off_next = (sect_offset) section.size; if (i >= 1) { + if (sect_off_next == sect_off_prev) + { + warning (_("Section .debug_names has duplicate entry in CU table," + " ignoring .debug_names.")); + return false; + } + if (sect_off_next < sect_off_prev) + { + warning (_("Section .debug_names has non-ascending CU table," + " ignoring .debug_names.")); + return false; + } const ULONGEST length = sect_off_next - sect_off_prev; dwarf2_per_cu_data_up per_cu = create_cu_from_index_list (per_bfd, §ion, is_dwz, @@ -4651,12 +4663,14 @@ create_cus_from_debug_names_list (dwarf2_per_bfd *per_bfd, } sect_off_prev = sect_off_next; } + + return true; } /* Read the CU list from the mapped index, and use it to create all the CU objects for this dwarf2_per_objfile. */ -static void +static bool create_cus_from_debug_names (dwarf2_per_bfd *per_bfd, const mapped_debug_names &map, const mapped_debug_names &dwz_map) @@ -4664,15 +4678,16 @@ create_cus_from_debug_names (dwarf2_per_bfd *per_bfd, gdb_assert (per_bfd->all_comp_units.empty ()); per_bfd->all_comp_units.reserve (map.cu_count + dwz_map.cu_count); - create_cus_from_debug_names_list (per_bfd, map, per_bfd->info, - false /* is_dwz */); + if (!create_cus_from_debug_names_list (per_bfd, map, per_bfd->info, + false /* is_dwz */)) + return false; if (dwz_map.cu_count == 0) - return; + return true; dwz_file *dwz = dwarf2_get_dwz_file (per_bfd); - create_cus_from_debug_names_list (per_bfd, dwz_map, dwz->info, - true /* is_dwz */); + return create_cus_from_debug_names_list (per_bfd, dwz_map, dwz->info, + true /* is_dwz */); } /* Read .debug_names. If everything went ok, initialize the "quick" @@ -4709,7 +4724,11 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile) } } - create_cus_from_debug_names (per_bfd, *map, dwz_map); + if (!create_cus_from_debug_names (per_bfd, *map, dwz_map)) + { + per_bfd->all_comp_units.clear (); + return false; + } if (map->tu_count != 0) { |