From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 7A18F384F000 for ; Fri, 8 Jul 2022 13:57:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7A18F384F000 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A9B461FE03 for ; Fri, 8 Jul 2022 13:57:02 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 988D413A7D for ; Fri, 8 Jul 2022 13:57:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ZBc5JK43yGLXSQAAMHmgww (envelope-from ) for ; Fri, 08 Jul 2022 13:57:02 +0000 Date: Fri, 8 Jul 2022 15:56:56 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [committed][gdb/symtab] Fix assert in process_imported_unit_die Message-ID: <20220708135654.GA12317@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2022 13:57:05 -0000 Hi, When running test-case gdb.dwarf2/dw2-symtab-includes.exp with target board cc-with-debug-names, I run into: ... (gdb) maint expand-symtab dw2-symtab-includes.h^M src/gdb/dwarf2/read.h:311: internal-error: unit_type: \ Assertion `m_unit_type != 0' failed.^M A problem internal to GDB has been detected,^M further debugging may prove unreliable.^M ----- Backtrace -----^M FAIL: gdb.dwarf2/dw2-symtab-includes.exp: maint expand-symtab \ dw2-symtab-includes.h (GDB internal error) ... The assert was recently added in commit 2c474c46943 ("[gdb/symtab] Add get/set functions for per_cu->lang/unit_type"). The assert is triggered here: ... /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit into another compilation unit, at root level. Regard this as a hint, and ignore it. */ if (die->parent && die->parent->parent == NULL && per_cu->unit_type () == DW_UT_compile && per_cu->lang () == language_cplus) return; ... We're trying to access unit_type / lang which hasn't been set yet. Normally, these are set during cooked index creation, but that's not the case when using an index (or using -readnow). In other words, this lto binary reading speed optimization only works in the normal use case. IWBN to have this working in all use cases, but for now, allow lang () and unit_type () to return language_unknown and 0 here. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29321 Committed to trunk. Thanks, - Tom [gdb/symtab] Fix assert in process_imported_unit_die --- gdb/dwarf2/read.c | 7 ++++--- gdb/dwarf2/read.h | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 9f92b420645..55e61b882a9 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -8538,10 +8538,11 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu) /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit into another compilation unit, at root level. Regard this as a hint, - and ignore it. */ + and ignore it. This is a best effort, it only works if unit_type and + lang are already set. */ if (die->parent && die->parent->parent == NULL - && per_cu->unit_type () == DW_UT_compile - && per_cu->lang () == language_cplus) + && per_cu->unit_type (false) == DW_UT_compile + && per_cu->lang (false) == language_cplus) return; /* If necessary, add it to the queue and load its DIEs. */ diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 1d9c66aafad..c9afa074ae9 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -306,9 +306,10 @@ struct dwarf2_per_cu_data gdb_assert (m_dwarf_version == version); } - dwarf_unit_type unit_type () const + dwarf_unit_type unit_type (bool strict_p = true) const { - gdb_assert (m_unit_type != 0); + if (strict_p) + gdb_assert (m_unit_type != 0); return m_unit_type; } @@ -322,9 +323,10 @@ struct dwarf2_per_cu_data gdb_assert (m_unit_type == unit_type); } - enum language lang () const + enum language lang (bool strict_p = true) const { - gdb_assert (m_lang != language_unknown); + if (strict_p) + gdb_assert (m_lang != language_unknown); return m_lang; }