While working on PR29334, I noticed this code right above the DW_IDX_type_unit handling code:
/* Don't crash on bad data. */
if (ull >= per_bfd->all_comp_units.size ())
complaint (_(".debug_names entry has bad CU index %s"
" [in module %s]"),
per_cu = per_bfd->get_cu (ull);
So, if I have 5 CUs and 5 TUs, and a ull CU index of 7, we should complain.
But we don't because we compare with "per_bfd->all_comp_units.size ()" instead of with "per_bfd->all_comp_units.size () - per_bfd->tu_stats.nr_tus".
Hmm, there are similar complaints for gdb-index, perhaps the same problem in dw2_symtab_iter_next?
Created attachment 14210 [details]
(In reply to Tom de Vries from comment #1)
> Hmm, there are similar complaints for gdb-index, perhaps the same problem in
Filed as PR29367.
Submitted patch: https://sourceware.org/pipermail/gdb-patches/2022-July/190750.html