From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id D7A063858405; Fri, 22 Jul 2022 21:50:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D7A063858405 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/symtab] Fix duplicate CUs in all_comp_units X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 5ae3df226b1b1e45b9326a5eee81b92489ae52f2 X-Git-Newrev: 263ad5cc818ef8f7700c82f2aecd2a929dbd3be5 Message-Id: <20220722215051.D7A063858405@sourceware.org> Date: Fri, 22 Jul 2022 21:50:51 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jul 2022 21:50:52 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D263ad5cc818e= f8f7700c82f2aecd2a929dbd3be5 commit 263ad5cc818ef8f7700c82f2aecd2a929dbd3be5 Author: Tom de Vries Date: Fri Jul 22 23:50:48 2022 +0200 [gdb/symtab] Fix duplicate CUs in all_comp_units =20 When running test-case gdb.cp/cpexprs-debug-types.exp with target board cc-with-debug-names on a system with gcc 12.1.1 (defaulting to dwarf 5)= , I run into: ... (gdb) file cpexprs-debug-types^M Reading symbols from cpexprs-debug-types...^M warning: Section .debug_aranges in cpexprs-debug-types has duplicate \ debug_info_offset 0x0, ignoring .debug_aranges.^M gdb/dwarf2/read.h:309: internal-error: set_length: \ Assertion `m_length =3D=3D length' failed.^M ... =20 The exec contains a .debug_names section, which gdb rejects due to .debug_names containing a list of TUs, while the exec doesn't contain a .debug_types section (which is what you'd expect for dwarf 4). =20 Gdb then falls back onto the cooked index, which calls create_all_comp_= units to create all_comp_units. However, the failed index reading left some elements in all_comp_units, so we end up with duplicates in all_comp_un= its, which causes the misleading complaint and the assert. =20 Fix this by: - asserting at the start of create_all_comp_units that all_comp_units i= s empty, as we do in create_cus_from_index and create_cus_from_debug_names, and - cleaning up all_comp_units when failing in dwarf2_read_debug_names. =20 Add a similar cleanup in dwarf2_read_gdb_index. =20 Tested on x86_64-linux. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29381 Diff: --- gdb/dwarf2/read.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 42230607fe0..f7e55af3e86 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2696,7 +2696,10 @@ dwarf2_read_gdb_index /* We can only handle a single .debug_types when we have an index. */ if (per_bfd->types.size () !=3D 1) - return 0; + { + per_bfd->all_comp_units.clear (); + return 0; + } =20 dwarf2_section_info *section =3D &per_bfd->types[0]; =20 @@ -4701,7 +4704,10 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_obj= file) /* We can only handle a single .debug_types when we have an index. */ if (per_bfd->types.size () !=3D 1) - return false; + { + per_bfd->all_comp_units.clear (); + return false; + } =20 dwarf2_section_info *section =3D &per_bfd->types[0]; =20 @@ -7214,6 +7220,7 @@ static void create_all_comp_units (dwarf2_per_objfile *per_objfile) { htab_up types_htab; + gdb_assert (per_objfile->per_bfd->all_comp_units.empty ()); =20 read_comp_units_from_section (per_objfile, &per_objfile->per_bfd->info, &per_objfile->per_bfd->abbrev, 0,