From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ORiPL+3N82oPrwAAWB0awg (envelope-from ) for ; Tue, 10 Nov 2026 21:07:41 -0500 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=sWLpuVa1; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id BF199378002; Tue, 10 Nov 2026 21:07:41 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D35051E043 for ; Tue, 10 Nov 2026 21:07:40 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D24B4BA7986 for ; Wed, 11 Nov 2026 02:07:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D24B4BA7986 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=sWLpuVa1 Received: from omta036.useast.a.cloudfilter.net (omta036.useast.a.cloudfilter.net [44.202.169.35]) by sourceware.org (Postfix) with ESMTPS id 4245F4BA2E23 for ; Wed, 11 Nov 2026 02:07:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4245F4BA2E23 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4245F4BA2E23 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=44.202.169.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794362820; cv=none; b=vkI4GouZ3OwWA3SwgASiK800+VUisrNd91GVXrJuS4sk78sUYdMyo+bOSP2A3OKxo6D557whT4gkm8miMkpuzsqaP/I6oHN1UZ40/sC+GPTwF8e6+RIrZYLkMjtalMYXrbFL1cV0UD9NmY+w7aSycOGAl9Y3KFv540jQMJEstKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794362820; c=relaxed/simple; bh=2dV0UCvkvtbuUo90wUd6OpjdUXW6Y8bh9bnBJxdgDoo=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=DU90AAMBSu6wbuEhDSPtDy2aJPgGs5J6nBPBdCMxzpyKuXL5FksdUghIIL34G8zqSVeu1eeh0xk/IEIiNocFL8m3ePE+E0ctRSse057ydcbGobYBFKQQ1LgVaFuAHAjCqStsvxfw1n1Cr8Xrc8WUR/81WYppPQo+4lTWM7WK0qk= ARC-Authentication-Results: i=1; sourceware.org; dkim=policy (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=sWLpuVa1 reason="signing key too small" DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4245F4BA2E23 Received: from eig-obgw-5003b.ext.cloudfilter.net ([10.0.29.155]) by cmsmtp with ESMTPS id QtuHxxl5J4vCDQxjnxQU1s; Wed, 11 Nov 2026 02:06:59 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id QxjlxXxOESgq1QxjmxHUIi; Wed, 11 Nov 2026 02:06:58 +0000 X-Authority-Analysis: v=2.4 cv=c8KrQQ9l c=1 sm=1 tr=0 ts=6af3cdc2 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=ItBw4LHWJt0A:10 a=HViPXkEMr6SqYLxyOagA:9 a=QEXdDO2ut3YA:10 a=DCx65vhANUyCzuf5D8fC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=3U557jWO1ldvW0NRr6nuQz+38B2PFyIMkj9K0dvsv1U=; b=sWLpuVa1J9sK7IR9//nxfJfvTU ADaolHevBXEnaZkSRkWOSF/+Tjo+oOeF7GBwWPOgvq1lfRhMkDnUSa0bHWELcYL5Y3fjcWvxIxF1l /qPjEGZZcpfG/arZ3Ay404A+p; Received: from 97-122-110-129.hlrn.qwest.net ([97.122.110.129]:38316 helo=[192.168.122.1]) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xQxjl-00000000IPM-2m5l; Tue, 10 Nov 2026 19:06:57 -0700 From: Tom Tromey Date: Tue, 10 Nov 2026 19:06:56 -0700 Subject: [PATCH 2/5] Hoist call to gdb_bfd_check_format_matches in exec.c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261110-minor-assert-v1-2-bb33660ca557@tromey.com> References: <20261110-minor-assert-v1-0-bb33660ca557@tromey.com> In-Reply-To: <20261110-minor-assert-v1-0-bb33660ca557@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.110.129 X-Source-L: No X-Exim-ID: 1xQxjl-00000000IPM-2m5l X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-110-129.hlrn.qwest.net ([192.168.122.1]) [97.122.110.129]:38316 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfIR14y0XU08WdoE9L5Ac4NJdPmeNO2tms1M7cCHpZUiW/eGA6L1i4pijAyJlND1UnI8a7ByIKRZpMuFj3+QCC2nKFBbleheD+MEpuVW/z8rwJCZIBH+G U4gGmu0uBTnVyaYzT8LpPxCi/t0nY9etoPKO86BN70kRkTgBtpKStSKN2es2BMkfPEKTPnF05q1Qsl4kr6n79CXkq9nXdhZTZ4Y= X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Right now, exec.c calls gdb_bfd_check_format_matches after setting the program space's exec_file. This means a call to exec_close is needed before throwing an exception, to avoid leaving the exec BFD set in this case. It seems to me that hoisting this call is more straightforward, as now the exec_close isn't needed. --- gdb/exec.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/gdb/exec.c b/gdb/exec.c index 4f0a0ca23e3..aa6fc42ebe7 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -459,18 +459,25 @@ exec_file_attach (const char *filename, int from_tty) canonical_pathname = canonical_storage.get (); } - gdb_bfd_ref_ptr temp; + gdb_bfd_ref_ptr new_exec_bfd; if (write_files && !load_via_target) - temp = gdb_bfd_fopen (canonical_pathname, gnutarget, - FOPEN_RUB, scratch_chan); + new_exec_bfd = gdb_bfd_fopen (canonical_pathname, gnutarget, + FOPEN_RUB, scratch_chan); else - temp = gdb_bfd_open (canonical_pathname, gnutarget, scratch_chan); - if (temp == nullptr) + new_exec_bfd = gdb_bfd_open (canonical_pathname, gnutarget, + scratch_chan); + if (new_exec_bfd == nullptr) error (_("\"%ps\": could not open as an executable file: %s."), styled_string (file_name_style.style (), scratch_pathname), bfd_errmsg (bfd_get_error ())); - current_program_space->set_exec_bfd (std::move (temp)); + if (!gdb_bfd_check_format_matches (new_exec_bfd.get (), bfd_object, + &matching)) + error (_("\"%ps\": not in executable format: %s"), + styled_string (file_name_style.style (), scratch_pathname), + gdb_bfd_errmsg (bfd_get_error (), matching).c_str ()); + + current_program_space->set_exec_bfd (std::move (new_exec_bfd)); /* gdb_realpath_keepfile resolves symlinks on the local filesystem and so cannot be used for "target:" files. */ @@ -484,17 +491,6 @@ exec_file_attach (const char *filename, int from_tty) (make_unique_xstrdup (gdb_realpath_keepfile (scratch_pathname).c_str ())); - if (!gdb_bfd_check_format_matches (current_program_space->exec_bfd (), - bfd_object, &matching)) - { - /* Make sure to close exec_bfd, or else "run" might try to use - it. */ - current_program_space->exec_close (); - error (_("\"%ps\": not in executable format: %s"), - styled_string (file_name_style.style (), scratch_pathname), - gdb_bfd_errmsg (bfd_get_error (), matching).c_str ()); - } - std::vector sections = build_section_table (current_program_space->exec_bfd ()); -- 2.49.0