From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AFCB63850217; Fri, 8 Jul 2022 07:24:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFCB63850217 From: "vries at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug symtab/29334] [gdb, debug-types, debug-names] segfault in dwarf2_per_objfile::symtab_set_p Date: Fri, 08 Jul 2022 07:24:31 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: symtab X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2022 07:24:31 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29334 --- Comment #1 from Tom de Vries --- Happens because dwarf2_per_objfile::symtab_set_p is called with per_cu =3D= =3D nullptr. This happens the first time we process a DW_IDX_type_unit in dw2_debug_names_iterator::next: ... case DW_IDX_type_unit: /* Don't crash on bad data. */ if (ull >=3D per_bfd->tu_stats.nr_tus) { complaint (_(".debug_names entry has bad TU index %s" " [in module %s]"), pulongest (ull), objfile_name (objfile)); continue; } per_cu =3D per_bfd->get_cu (ull + per_bfd->tu_stats.nr_tus); break; ... We have a reference to type unit 14: ... (gdb) p ull $2 =3D 14 ... The CU table in .debug_names contains 6 entries (0-5) and the TU table cont= ains 62 (0-61). So type unit 14 is a valid index. We correctly kept track of the number of TUs: ... (gdb) p per_bfd->tu_stats.nr_tus $3 =3D 62 ... And the all_comp_units.size () is 68, which indeed 62 + 6: ... (gdb) s dwarf2_per_bfd::get_cu (this=3D0x3659360, index=3D76) at /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.h:401 401 return this->all_comp_units[index].get (); (gdb) p this->all_comp_units.size () $4 =3D 68 ... However, the index used is 76, which is too big. Looking at the CU/TU table, we have: ... CU table: [ 0] 0x0 [ 1] 0x2e [ 2] 0x6d [ 3] 0x8f [ 4] 0x4db7 [ 5] 0x4f6f TU table: [ 0] 0x0 [ 1] 0x15b [ 2] 0x2e0 ... And: ... (gdb) p this->all_comp_units[0].get().sect_off $16 =3D 0 (gdb) p this->all_comp_units[1].get().sect_off $17 =3D (unknown: 0x2e) (gdb) p this->all_comp_units[2].get().sect_off $18 =3D (unknown: 0x6d) ... and: ... (gdb) p this->all_comp_units[6].get().sect_off $19 =3D 0 (gdb) p this->all_comp_units[7].get().sect_off $20 =3D (unknown: 0x15b) (gdb) p this->all_comp_units[8].get().sect_off $21 =3D (unknown: 0x2e0) ... So, at first glance, it seems the fix should be something like: ... - per_cu =3D per_bfd->get_cu (ull + per_bfd->tu_stats.nr_tus); + per_cu =3D per_bfd->get_cu (ull + per_bfd->cu_stats.nr_cus); ... --=20 You are receiving this mail because: You are on the CC list for the bug.=