From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id qGjDK1+Xymn4ij8AWB0awg (envelope-from ) for ; Mon, 30 Mar 2026 11:31:43 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Yb9Tc75U; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A05C81E0BC; Mon, 30 Mar 2026 11:31:43 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 D1A8A1E04F for ; Mon, 30 Mar 2026 11:31:42 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 05DE44BB58E6 for ; Mon, 30 Mar 2026 15:31:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05DE44BB58E6 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Yb9Tc75U Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 47B024B92088 for ; Mon, 30 Mar 2026 15:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 47B024B92088 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 47B024B92088 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774884664; cv=none; b=U6duFxhqTxiI9iXjCcoiiX9ZqMjxT9IvhecnoMOB83pYzilSZ8IHF/2d3xGVOVnDfnDFeBkqmf5AriT9njw5U3wDjnauJbrOxyO/5/SbkXKYVND0ayopwimAog2UrE8HMLxOSQp0WWoQtn3iWNprx9ttfbthkeX1xAxMtsAw0DA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774884664; c=relaxed/simple; bh=s4uTP5pVM1aqdJDnNtOLOdFm1WMu6RtQPIhdy+KhR5k=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=x5OTNoCIA+ypI+5n7tHN+ODNBO9g4TXAZCDTxBJ62nDo1gnOiDcs14h3Y3VcibezRq+RKfGYtUtASgQGA6t7z7De1yetgkxed+JRnFzxxc9NktfNaIpQoZuVR49xLNG2F81FFmHG8AIPJqf964f1tHBlvzTE5gUTxz0RYmXrZt0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47B024B92088 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774884663; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6O6qK4pVesnoV3XAtYKQPBOwPsSjP5foC/yvbRjhymk=; b=Yb9Tc75U+1fPi1jQUFetL7BTwBtA1k8sxSb86l5f2j2aEVRNMtGw3SdDHoavAGIAU76qCu wO/nzXt6YTBycIdaAdFfB6NPTDKZJy8wKO0s2xdWmYfuy0xSwSflIYQffU5hUFeQDGDfoE p3oTIv0ca2HWzgwcLhsONQ+Xz2zFK2E= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-41-9OySQTkkM4W_T30rxyr03w-1; Mon, 30 Mar 2026 11:31:02 -0400 X-MC-Unique: 9OySQTkkM4W_T30rxyr03w-1 X-Mimecast-MFC-AGG-ID: 9OySQTkkM4W_T30rxyr03w_1774884661 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4852cf0318dso51593455e9.3 for ; Mon, 30 Mar 2026 08:31:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774884661; x=1775489461; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6O6qK4pVesnoV3XAtYKQPBOwPsSjP5foC/yvbRjhymk=; b=tM6FT2J87rMZprtz7hdZ+31YPfXjBpcqFDa3A5CtT2WBSTYg7nOvAxM4ezwcz/d6DG vMQn7S+hPe4gmXwVCDbbouzjs3T5uojenwhwOAbTEq2KM5EgJRijko8WS8O7GNnTpsAN rYFBvnttpsf6YoAItfTqTHu+o7kyNBvJZLTTIZHxtPleENXN4hGHH/nqLTb13LHZNpn5 9FxYUCS1OMVpTuQ2hASAldjskAPMU7AYUEJhXLHW8yj719tP5tr415U3dUFCTFtos1d0 Ntd7zjohMoEkTUfNQ5m8pa1coxZVDnXSSD/4QrzG3tyjtindCnLsv+2W/zOgVcoMCG7A F2cg== X-Gm-Message-State: AOJu0YwV79vmSIE59ra25uRBzBUMslyKOoyr4MnCPTwheOu0wEEHmJLp pbIrSD2UrcmMbdX+vQ/vSWugoZjZOYHEYM8MN3Xy24akCRPRIB88CdTSRnPn0cw7TtoK6v/xwaz QZq1YGGtNmn85D6FA8rVyIPsHhXAUVEn+hj8mX6Z4bdANdH/OXCSeL1rNP1IPAtntYgNAgvNmnW +HYF9C7NFC0XEdyiRJZKpws8oSCAGX2IbdetfXlVXa+iWYijE= X-Gm-Gg: ATEYQzzKxgBtSgKCTC2scpUCZh2JH1VNcXDND9kZn5eZ94EY5acpQtSzMpEe8Qb1tOn /1zrLeNanVyghBHvjLftPBznA3EZEEM/YNusF6IXbctoiJbW3/lrsZgpvIIXHVK8SKG2rlmR83D giG3E5BukzxIT4mbOctzWg/dmf9xqc0rCiTJGOYkNZSIUP9NSTKuEe87yBpCyQ8a7DAlthVEY8F 3wS/rdvTvR9+SLSM+1eUK017SJvtHG0mSc56DqLpDb4P/oPoKm267KgIfUEw9aWZKUAbjFSTxEr xUuEgriozxSPlXQXwk6FUn2Olzp4/HxWSlFpuRejoEi0fOyoQZQz4u52/gKeLSIU9cuAxS60QMd qy7n4qWuTGUydL0iB X-Received: by 2002:a05:600c:c8f:b0:485:5ba3:37d8 with SMTP id 5b1f17b1804b1-48727d59cf4mr222912405e9.5.1774884660498; Mon, 30 Mar 2026 08:31:00 -0700 (PDT) X-Received: by 2002:a05:600c:c8f:b0:485:5ba3:37d8 with SMTP id 5b1f17b1804b1-48727d59cf4mr222911295e9.5.1774884659784; Mon, 30 Mar 2026 08:30:59 -0700 (PDT) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48722be608bsm431810995e9.0.2026.03.30.08.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2026 08:30:59 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/3] gdb: delete some unnecessary code from core_target::detach Date: Mon, 30 Mar 2026 16:30:51 +0100 Message-Id: <42209ecb3032e7f55e2113c15613af11056ac8c8.1774884529.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: gKkNJNBlUy_jK3GLVI2SetN_hnC9jtIFroCOviM77NM_1774884661 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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 This commit removes some unnecessary code from core_target::detach. When a core_target is created the core BFD (m_core_bfd) is set, and will never be NULL. The m_core_bfd remains set until either core_target::detach or core_target::close is called. The core_target::close function is only called when the refcount of a core_target reaches zero, the core_target::close function deletes the core_target, so we know that after calling core_target::close no other core_target member functions will be called (as the core_target will have been deleted). The core_target::detach function is called as a result of calling target_detach, which is called as a result of either the 'detach' command, or the 'core-file' command (without passing a file name). As a core_target is not shareable (see process_stratum_target::is_shareable), once a core_target is detached, its reference count will reduce to zero, and then it will be closed and deleted. What this means is that there is absolutely no way that a core_target can ever be detached twice, not that such a thing would make much sense, but it cannot happen. Understanding this we can know that when core_target::detach is called m_core_bfd will never be NULL, I've added an assert for this case. Given this assert, if we look at core_target::clear_core, which core_target::detach calls, we can see that exit_inferior will always be called. If we look at exit_inferior (in inferior.c) we see that the last two actions of that function are: /* Clear the register cache and the frame cache. */ registers_changed (); reinit_frame_cache (); Which are also two of the last three actions of core_target::detach. Clearly the calls in core_target::detach are redundant. Just for good measure, if we look in target_detach, from where core_target::detach will have been called, just before the function returns we have: registers_changed_ptid (proc_target, save_pid_ptid); reinit_frame_cache (); The registers_changed_ptid call is slightly more restrictive, only clearing the register cache for the target being detached, but that should be good enough -- I think exit_inferior could probably be changed to call registers_changed_ptid for the inferior that exited, but that's a problem for another day. What this all tells me is that the registers_changed call and the reinit_frame_cache call in core_target::detach are unnecessary, and can be deleted, which is what this patch does. There should be no user visible changes after this commit. --- gdb/corelow.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gdb/corelow.c b/gdb/corelow.c index 954607134f4..216b4e70066 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -1239,6 +1239,13 @@ core_target_open (const char *arg, int from_tty) void core_target::detach (inferior *inf, int from_tty) { + /* The core BFD is set when the core_target is created and attached to + the inferior. It is only cleared during detach or close. After + detaching the core target will be closed and deleted, so detach can + never be called twice. What this means is that detach will never be + called without the core BFD being set. */ + gdb_assert (this->core_bfd () != nullptr); + /* Get rid of the core. Don't rely on core_target::close doing it, because target_detach may be called with core_target's refcount > 1, meaning core_target::close may not be called yet by the @@ -1250,9 +1257,7 @@ core_target::detach (inferior *inf, int from_tty) implementation deletes 'this'. */ inf->unpush_target (this); - /* Clear the register cache and the frame cache. */ - registers_changed (); - reinit_frame_cache (); + /* Inform the user. */ maybe_say_no_core_file_now (from_tty); } -- 2.25.4