From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mWo9M811fGpIlCAAWB0awg (envelope-from ) for ; Wed, 12 Aug 2026 09:31:57 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=nrp7n/jo; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CCFCB1E166; Wed, 12 Aug 2026 09:31:57 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.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 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 4998D1E033 for ; Wed, 12 Aug 2026 09:31:57 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7AED44BB24FE for ; Wed, 12 Aug 2026 13:31:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7AED44BB24FE Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=nrp7n/jo Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by sourceware.org (Postfix) with ESMTPS id DBF0D4BB24FB for ; Wed, 12 Aug 2026 13:29:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DBF0D4BB24FB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DBF0D4BB24FB Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786541372; cv=none; b=mZqsReT1Wo+fL5OPa2g17CPE79f5UG2xQL80F7s1toE9gdNdqcIhaPPVmOMW5T/s00W4mpnheZcrHYtCfD6+tpnzONuE9qEwqZ7skLpek0eOHfLgLONHgepUmlIcv+DCt79T2AmrV44fxAujx+ZgJqm7p+ZYmFHwlVo2lzHV3N8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786541372; c=relaxed/simple; bh=M57Q3idH4jfQ4qYFa1VzgC4RBombWD1neuKetonMQDE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EkyGo8Hz7+p121d9N1TGyjvEbPdBu3+xR/9MVU44fGcEQeNdVJZ3/hsLpPQ+Udfb+nBRuDA9GsH53nudq9p8O6O7sjUJBFa1rCBxY0DljfY0WQn51fAIR2xqeYCOCZEyYq7049NGwG+t2moyrtYVR0oXmimQdiQsZzq4R0/cl6w= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=nrp7n/jo DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DBF0D4BB24FB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1786541372; x=1818077372; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=M57Q3idH4jfQ4qYFa1VzgC4RBombWD1neuKetonMQDE=; b=nrp7n/joBypaRgcCWUzmxNcbP6jjLaqloGf8FwtK/vJ8wZ5d+HUfQp/+ Hi7l9Huhtf3QdW0lb3yXz10JGEj77i4bCCNZpjGHGo9Ew/nYaGx3SbV4D JoJAQ0PDUAREJeGs61Q285Yk5C8SIGi5uT5fqyZkqQi6aiWP+PMNWgi+I rH/HwRYsqpdzAVgiBqLzEWKTZkhIaO8criD2R6LujVWZ+wH+Rs1Rdt5Zn Gfh6uUNUVcdIkMuYsqD6ON+MFbhdhj0HXcTydsoMkpZcFVateDA317U/R lGUhYDv/Wcz6QYjTkZO2z85snoOrsXVlgAVhtRXZ5xNiU9Wz8qZamE+3b Q==; X-CSE-ConnectionGUID: 2l6zmq8SRha5ucd48uPZ0Q== X-CSE-MsgGUID: f0+OBsB6RLqDlY6n/1WNbw== X-IronPort-AV: E=McAfee;i="6800,10657,11872"; a="97757886" X-IronPort-AV: E=Sophos;i="6.25,219,1779174000"; d="scan'208";a="97757886" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2026 06:29:31 -0700 X-CSE-ConnectionGUID: Mxvd8ejARAy1m0T2j2bWzQ== X-CSE-MsgGUID: 8euazWOITKWnGlRBATjAaQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,219,1779174000"; d="scan'208";a="259817948" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2026 06:29:31 -0700 From: Markus Metzger To: gdb-patches@sourceware.org Subject: [PATCH v4 27/44] gdb, linux-nat: use current_inferior()->pid in mourn_inferior() Date: Wed, 12 Aug 2026 15:27:47 +0200 Message-ID: <20260812132805.380163-28-markus.t.metzger@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260812132805.380163-1-markus.t.metzger@intel.com> References: <20260812132805.380163-1-markus.t.metzger@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 In infrun.c:handle_process_exited(), we switch to either the eventing thread or the eventing process depending on the ptid we get for the event: static void handle_process_exited (execution_control_state *ecs) { /* Depending on the system, ecs->ptid may point to a thread or to a process. On some targets, target_mourn_inferior may need to have access to the just-exited thread. That is the case of GNU/Linux's "checkpoint" support, for example. Switch context appropriately. */ thread_info *thr = ecs->target->find_thread (ecs->ptid); if (thr != nullptr) switch_to_thread (thr); else { inferior *inf = find_inferior_ptid (ecs->target, ecs->ptid); switch_to_inferior_no_thread (inf); } While target_mourn_inferior() takes a ptid argument that could be set to the event ptid, the actual mourn_inferior() target method does not take any argument. Almost all targets use current_inferior() to determine which inferior to mourn. The linux-nat target, however, uses inferior_ptid.pid(), which is zero when switching to the event inferior and no thread, so it ended up not finding the exited inferior's LWPs when the event is delivered with a process ptid instead of a thread ptid. Change linux-nat to use current_inferior() like everybody else. I considered passing the ptid argument of target_mourn_inferior() down to the target methods to not rely on global state. To do this right, we'd need to not rely on current_inferior() inside the targets and instead find the inferior based on the ptid argument. Or pass it down since the caller most likely already has an inferior pointer. This has been exposed by gdb.multi/multi-exit.exp on a subsequent patch that introduces inferior events to allow deleting the last thread of an inferior. --- gdb/linux-nat.c | 5 +++-- gdb/target.c | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 8840dbe3f75..9e015b57379 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -3732,13 +3732,14 @@ linux_nat_target::mourn_inferior () { LINUX_NAT_SCOPED_DEBUG_ENTER_EXIT; - int pid = inferior_ptid.pid (); + inferior *inf = current_inferior (); + int pid = inf->pid; purge_lwp_list (pid); close_proc_mem_file (pid); - if (! forks_exist_p (current_inferior ())) + if (! forks_exist_p (inf)) /* Normal case, no other forks available. */ inf_ptrace_target::mourn_inferior (); else diff --git a/gdb/target.c b/gdb/target.c index a41735ef888..35d39161495 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -2767,7 +2767,8 @@ default_mourn_inferior (struct target_ops *self) void target_mourn_inferior (ptid_t ptid) { - gdb_assert (ptid.pid () == inferior_ptid.pid ()); + gdb_assert (ptid == null_ptid || ptid.pid () == current_inferior ()->pid); + gdb_assert (ptid == null_ptid || ptid.pid () == inferior_ptid.pid ()); current_inferior ()->top_target ()->mourn_inferior (); } -- 2.43.0 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.