[ .gdb_index variant of PR29336. ] Do this change in the test-suite: ... diff --git a/gdb/testsuite/gdb.ada/access_tagged_param.exp b/gdb/testsuite/gdb.ada/access_t agged_param.exp index 2b8e8ef172f..9c2b1871819 100644 --- a/gdb/testsuite/gdb.ada/access_tagged_param.exp +++ b/gdb/testsuite/gdb.ada/access_tagged_param.exp @@ -22,7 +22,7 @@ if { [skip_ada_tests] } { return -1 } standard_ada_testfile foo -if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } { +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-fdebug-types-section]] != "" } { return -1 } ... and run the test-case with target board cc-with-gdb-index. Verify that there are no complaints: ... $ gdb -q -batch -iex "set complaints 100" ./outputs/gdb.ada/access_tagged_param/foo -ex "b foo" Breakpoint 1 at 0x4023f4: file /home/vries/gdb_versions/devel/binutils-gdb.git/gdb/testsuite/gdb.ada/access_tagged_param/foo.adb, line 17. ... Observe using readelf -w that nr_cus == 56 and nr_tus == 10. Now hack gdb: ... diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e554bc4f642..b3f0f5506c8 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2996,6 +2996,7 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter, int attrs_valid = (index.version >= 7 && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE); + cu_index = 56; /* Don't crash on bad data. */ if (cu_index >= per_objfile->per_bfd->all_comp_units.size (CUTU)) { ... Try again to see any complaints. Still none. Now do: ... /* Don't crash on bad data. */ - if (cu_index >= per_objfile->per_bfd->all_comp_units.size (CUTU)) + if (cu_index >= per_objfile->per_bfd->all_comp_units.size (CU)) ... [ assuming tentative patch for PR29336. ] Try again: ... $ gdb -q -batch -iex "set complaints 100" ./outputs/gdb.ada/access_tagged_param/foo -ex "b foo" During symbol reading: .gdb_index entry has bad CU index [in module /home/vries/gdb_versions/devel/build/gdb/testsuite/outputs/gdb.ada/access_tagged_param/foo] During symbol reading: .gdb_index entry has bad CU index [in module /home/vries/gdb_versions/devel/build/gdb/testsuite/outputs/gdb.ada/access_tagged_param/foo] Breakpoint 1 at 0x4023f4: file /home/vries/gdb_versions/devel/binutils-gdb.git/gdb/testsuite/gdb.ada/access_tagged_param/foo.adb, line 17. ... Bingo. Now the question: is this change correct? I can't figure out how a type in a .debug_types section would be addressed from the index. Maybe 56 is the correct way to address TU 0 ? I can't tell from the readelf output. Looking at the first type in .debug_types, ada_main__local_interrupt_states___PAD, we find it back in the index here: ... [2574] ada_main__local_interrupt_states___PAD: 0 [static, type] ... It's says zero here, but how is CU id 0 distinguished from TU id 0?
(In reply to Tom de Vries from comment #0) > Now the question: is this change correct? > > I can't figure out how a type in a .debug_types section would be addressed > from the index. > > Maybe 56 is the correct way to address TU 0 ? At https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html I find: ... Note that if there are type CUs, then conceptually CUs and type CUs form a single list for the purposes of CU indices. ... I guess that answers my question. So this: ... /* Don't crash on bad data. */ - if (cu_index >= per_objfile->per_bfd->all_comp_units.size (CUTU)) + if (cu_index >= per_objfile->per_bfd->all_comp_units.size (CU)) ... is incorrect, the current code is in fact correct. But we might be able to be more strict though: ... diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index bcd01107377..8d216318c13 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2975,7 +2975,13 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter, && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE); /* Don't crash on bad data. */ - if (cu_index >= per_objfile->per_bfd->all_comp_units.size ()) + size_t nr_tus = per_objfile->per_bfd->tu_stats.nr_tus; + size_t nr_cus = (per_objfile->per_bfd->all_comp_units.size () - nr_tus); + /* Only allow type symbols in type units. */ + size_t size_for_kind = (symbol_kind == GDB_INDEX_SYMBOL_KIND_TYPE + ? nr_cus + nr_tus + : nr_cus); + if (cu_index >= size_for_kind) { complaint (_(".gdb_index entry has bad CU index" " [in module %s]"), objfile_name (per_objfile->objfile)); ... by assuming there are only type symbols in the type units, which means for other symbols we can be more strict about the allowed indices.