From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id IROgIol1fGoxkyAAWB0awg (envelope-from ) for ; Wed, 12 Aug 2026 09:30:49 -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=AxGD7IKY; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 87C271E033; Wed, 12 Aug 2026 09:30:49 -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 [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 083601E033 for ; Wed, 12 Aug 2026 09:30:49 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 290F94BB3B81 for ; Wed, 12 Aug 2026 13:30:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 290F94BB3B81 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=AxGD7IKY Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by sourceware.org (Postfix) with ESMTPS id 33D424BA9035 for ; Wed, 12 Aug 2026 13:28:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 33D424BA9035 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 33D424BA9035 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786541328; cv=none; b=n9b67ZM6nPUtZjA7eqmVVXAz1+ih4BD+OICjhrP4N37UeevXBclsUpBqGJFlTG4ZM4rj1JVkbvVIgyAhmfuO3FRq6oEaeaguMOBamEBSQSdVKNTYQ83Fj7qgV16IC6NBHVGW3VejX/1SmhYLiGwsxqCPzGcUXtqwT+PnjA+THrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786541328; c=relaxed/simple; bh=juzO4jRfxzUs4BCj6Rt7hgxIf8EfmC/os9vJgQJyOhU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kwG1os9upODSGyxZdtWiPwfXkEgFxLnN0k4TWr953bOhco4lxQGEdCTXQbNUOMgD6h+3c90umgLfCRUVCFc10DhSG7H6kk0IUf06/XZFatKfrzfjZ6FWiPYwJF57rU9BJVsLNk1lneKXk8R3/ehWqtyNjxP19z4gtLWbXVafgsk= 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=AxGD7IKY DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 33D424BA9035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1786541328; x=1818077328; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=juzO4jRfxzUs4BCj6Rt7hgxIf8EfmC/os9vJgQJyOhU=; b=AxGD7IKYwQEd+YC1bpQ063uQRIW11PcoSbCYXXW/TjqRDyrwyE+lRdW4 HbP2HaWiV+EHbDDB6YF6SUHR1Mt3SgocqhAGpHbhiA2gfx4xoGQSl04mK ClQ1AeaJbPKmq1ciiwTErwDOkIvlIaJJjTW80b8OjfajJOiZrb+JIHfic glfktWwfWZdY7AdxYXM+HlLQ6HFF6jEPcClLPtzDk3ScoDE6+tU7zla53 jimG6TVbVVjj9anSUWlJRR3ZlLPPOECISx/6YqaRaLdGqIAXJJq62Pj/B Z1RhN0ga/3Vh9STc7Nj4ETLKJMYxw2maVagotYbGaoUQtzsx2xBdML1ey g==; X-CSE-ConnectionGUID: vuww3++iQuiPu86ANeb3rA== X-CSE-MsgGUID: CH/JYtEWTrKYzyLWUbthww== X-IronPort-AV: E=McAfee;i="6800,10657,11872"; a="98457688" X-IronPort-AV: E=Sophos;i="6.25,219,1779174000"; d="scan'208";a="98457688" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2026 06:28:48 -0700 X-CSE-ConnectionGUID: tFshF/kBQB2YnkXlNC+85w== X-CSE-MsgGUID: P3BWJrjeQuefttkV8d+DMw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,219,1779174000"; d="scan'208";a="267509971" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2026 06:28:47 -0700 From: Markus Metzger To: gdb-patches@sourceware.org Cc: Tankut Baris Aktemur Subject: [PATCH v4 12/44] gdb, remote: do 'remote_add_inferior' in 'remote_notice_new_inferior' earlier Date: Wed, 12 Aug 2026 15:27:32 +0200 Message-ID: <20260812132805.380163-13-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 From: Tankut Baris Aktemur In remote_target::remote_notice_new_inferior, we check if the inferior for the reported ptid exists, and if not, we add that inferior via 'remote_add_inferior'. However, before adding the new inferior, we may have already added a new thread, because the thread is not found via 'in_thread_list'. This may bring the odd situation that a new thread is being added before its inferior exists. Fix this problem by moving the check and creation of a new inferior to an earlier spot in the execution flow. Note that the code has a check for inferior_ptid.is_pid, but this is not useful to avoid the problem described above because the core infrun clears inferior_ptid (i.e. sets to null_ptid) before waiting on targets for stop events. --- gdb/remote.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 194c4cbd9bb..05cda9d0b0c 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -3223,6 +3223,23 @@ remote_target::remote_notice_new_inferior (ptid_t currthread, struct inferior *inf = NULL; int pid = currthread.pid (); + /* When connecting to a target remote, or to a target + extended-remote which already was debugging an inferior, we + may not know about it yet. Add it before adding its child + thread, so notifications are emitted in a sensible order. */ + if (find_inferior_pid (this, pid) == nullptr) + { + bool fake_pid_p = !m_features.remote_multi_process_p (); + + inf = remote_add_inferior (fake_pid_p, pid, -1, 1); + + /* Fetch the target description for this inferior. Make sure to + leave the currently selected inferior unchanged. */ + scoped_restore_current_thread restore_thread; + switch_to_inferior_no_thread (inf); + target_find_description (); + } + if (inferior_ptid.is_pid () && pid == inferior_ptid.pid ()) { @@ -3253,24 +3270,6 @@ remote_target::remote_notice_new_inferior (ptid_t currthread, return; } - /* When connecting to a target remote, or to a target - extended-remote which already was debugging an inferior, we - may not know about it yet. Add it before adding its child - thread, so notifications are emitted in a sensible order. */ - if (find_inferior_pid (this, currthread.pid ()) == NULL) - { - bool fake_pid_p = !m_features.remote_multi_process_p (); - - inf = remote_add_inferior (fake_pid_p, - currthread.pid (), -1, 1); - - /* Fetch the target description for this inferior. Make sure to - leave the currently selected inferior unchanged. */ - scoped_restore_current_thread restore_thread; - switch_to_inferior_no_thread (inf); - target_find_description (); - } - /* This is really a new thread. Add it. */ thread_info *new_thr = remote_add_thread (currthread, state, internal_state, false); -- 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.