From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cJN5E8U3yGIplQ4AWB0awg (envelope-from ) for ; Fri, 08 Jul 2022 09:57:25 -0400 Received: by simark.ca (Postfix, from userid 112) id 3EF671E22D; Fri, 8 Jul 2022 09:57:25 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=aCYXGRWN; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D48931E220 for ; Fri, 8 Jul 2022 09:57:24 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D1DA384F000 for ; Fri, 8 Jul 2022 13:57:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D1DA384F000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1657288644; bh=JXVSBpZu427ZN18xEWIWWcpuxjqA7mUmmHGn/xEQcp0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=aCYXGRWN/nH2JXR2xOTgEILgO9HiJDtlmfJe6Hosxvoq+Ml92o8MXMtjjRyUpwucq NkU0LzZKeILKu2YIRfocJzaLYFJCrJFgLjYfFj78utJXuNLieDHkKN2XSCUh9egFAx OaEtP5UUN0kitiq3w/WKfxtcmjoa1hHEvetpWmx0= Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id E074E38582BA for ; Fri, 8 Jul 2022 13:56:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E074E38582BA 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 1A2961FE03 for ; Fri, 8 Jul 2022 13:56:43 +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 05B3413A7D for ; Fri, 8 Jul 2022 13:56:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ZbZZAJs3yGKQSQAAMHmgww (envelope-from ) for ; Fri, 08 Jul 2022 13:56:43 +0000 Date: Fri, 8 Jul 2022 15:56:41 +0200 To: gdb-patches@sourceware.org Subject: [committed][gdb/symtab] Fix segfault in dwarf2_per_objfile::symtab_set_p Message-ID: <20220708135640.GA12287@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-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: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, When running test-case gdb.cp/cpexprs-debug-types.exp with target board cc-with-debug-names, I run into: ... (gdb) print base::operator new^M ^M ^M Fatal signal: Segmentation fault^M ----- Backtrace -----^M 0x57ea46 gdb_internal_backtrace_1^M /home/vries/gdb_versions/devel/src/gdb/bt-utils.c:122^M 0x57eae9 _Z22gdb_internal_backtracev^M /home/vries/gdb_versions/devel/src/gdb/bt-utils.c:168^M 0x75b8ad handle_fatal_signal^M /home/vries/gdb_versions/devel/src/gdb/event-top.c:946^M 0x75ba19 handle_sigsegv^M /home/vries/gdb_versions/devel/src/gdb/event-top.c:1019^M 0x7f795f46a8bf ???^M 0x6d3cb1 _ZNK18dwarf2_per_objfile12symtab_set_pEPK18dwarf2_per_cu_data^M /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:1515^M ... The problem is in this piece of code in dw2_debug_names_iterator::next: ... case DW_IDX_type_unit: /* Don't crash on bad data. */ if (ull >= 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 = per_bfd->get_cu (ull + per_bfd->tu_stats.nr_tus); break; ... The all_comp_units vector (which get_cu accesses) contains both CUs and TUs, with CUs first. So to get the nth TU we need the element at "nr_cus + n", but the code uses "nr_tus + n" instead. Fix this by using "nr_cus + n". Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29334 Committed to trunk. Thanks, - Tom [gdb/symtab] Fix segfault in dwarf2_per_objfile::symtab_set_p --- gdb/dwarf2/read.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 23fe5679cbd..9f92b420645 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -4991,7 +4991,11 @@ dw2_debug_names_iterator::next () objfile_name (objfile)); continue; } - per_cu = per_bfd->get_cu (ull + per_bfd->tu_stats.nr_tus); + { + int nr_cus = (per_bfd->all_comp_units.size () + - per_bfd->tu_stats.nr_tus); + per_cu = per_bfd->get_cu (nr_cus + ull); + } break; case DW_IDX_die_offset: /* In a per-CU index (as opposed to a per-module index), index