Bug 29336

Summary: [gdb, debug-types, debug-names] Bad CU index complaint not triggered
Product: gdb Reporter: Tom de Vries <vries>
Component: symtabAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: tromey
Priority: P2    
Version: HEAD   
Target Milestone: 13.1   
Host: Target:
Build: Last reconfirmed:
Attachments: tentative patch

Description Tom de Vries 2022-07-08 09:01:13 UTC
While working on PR29334, I noticed this code right above the DW_IDX_type_unit handling code:
...
        case DW_IDX_compile_unit:
          /* 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]"),
                         pulongest (ull),
                         objfile_name (objfile));
              continue;
            }
          per_cu = per_bfd->get_cu (ull);
          break;
...

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".
Comment 1 Tom de Vries 2022-07-08 09:10:13 UTC
Hmm, there are similar complaints for gdb-index, perhaps the same problem in dw2_symtab_iter_next?
Comment 2 Tom de Vries 2022-07-14 10:36:24 UTC
Created attachment 14210 [details]
tentative patch
Comment 3 Tom de Vries 2022-07-14 13:35:28 UTC
(In reply to Tom de Vries from comment #1)
> Hmm, there are similar complaints for gdb-index, perhaps the same problem in
> dw2_symtab_iter_next?

Filed as PR29367.
Comment 4 Tom de Vries 2022-07-14 14:44:48 UTC
Submitted patch: https://sourceware.org/pipermail/gdb-patches/2022-July/190750.html