From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id ED0D63846027 for ; Tue, 2 Jul 2024 11:45:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED0D63846027 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 ED0D63846027 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719920720; cv=none; b=SYDLND2v0L/QHxkYY5p0bcjnOX7cIRNHSYvj2tYHPMf3L9ohxJGrrUVuq/OurVPXw1/zj+XcFamtD3un7h6L4EgLILPtHWVqDp2dWciDJhzZ5SJiFa6S36q5A0XgB2ErlBaF4B+79SIZq5FEDmkEAxiA/WsUscs1D3ZzMwF/FPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719920720; c=relaxed/simple; bh=nUyOd9+GQXkT3j04ZFMkE4xgIBzIkANwmEfQipmSd/Y=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=wlQboGQgSG7q0UJWrV08e/bPYYhWIOaHJ0oGPk2lezGmV5A66nZkzmLA7cI5bX0suLxxAiUcDEGMalkxucHE2HZhiO2E+GMBMGzf1ZQhGhO4W/LST1dB8421LHSHP4T6DEOV058ANQNyXZC4KHe4hPDUoSpj0hg8Dfu6hC2nlKw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719920717; x=1751456717; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=nUyOd9+GQXkT3j04ZFMkE4xgIBzIkANwmEfQipmSd/Y=; b=eqYbZsiajVzCvW9WTUNir3yjvQ2CLnUAuidRaFghwpAMalLahFbB5xWy /0lIrrGwrblpF7BMR+gQZB1CpjRYispdLzAnFTkSYG8ffQGJGp0y4vbdH lXzivMEyNTE8IPu3ksYdRsJfkRbys2PvKk0B6fAtovDCdLGndF4VpyQsz nYCqf1pUis46/9VMa7VGWsqRS9w4ntpJ01J6N2878Qt6IMc0wac9+xSd1 lSrwxKtl86drvwjSBdVjJJUToqJrCDCIFgrBOybLRh3tL7iv6/UqLvxak UtNl21vqxhSXEYTkZJQnFJKxagmqd5UJuYbHxP/i5QyJ5eDPxLeFiGmLm w==; X-CSE-ConnectionGUID: R7E6GirARyiRIBrnzPcKDw== X-CSE-MsgGUID: GsnjtqQGQRmeIbTtrMIg5Q== X-IronPort-AV: E=McAfee;i="6700,10204,11120"; a="17213434" X-IronPort-AV: E=Sophos;i="6.09,178,1716274800"; d="scan'208";a="17213434" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2024 04:45:17 -0700 X-CSE-ConnectionGUID: axkUofG6SsmygMg3v0JkPg== X-CSE-MsgGUID: XLfp0fV0TySOKtXKNNs8WQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,178,1716274800"; d="scan'208";a="69085286" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2024 04:45:16 -0700 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Subject: [PATCH 23/46] gdb, remote: do 'remote_add_inferior' in 'remote_notice_new_inferior' earlier Date: Tue, 2 Jul 2024 13:42:54 +0200 Message-Id: <2232449d2090c2b3029560c48819dca09634b3c3.1719919040.git.tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 7fe2710c576..8df2e627b66 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -2968,6 +2968,17 @@ remote_target::remote_notice_new_inferior (ptid_t currthread, bool executing) 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); + } + if (inferior_ptid.is_pid () && pid == inferior_ptid.pid ()) { @@ -2998,18 +3009,6 @@ remote_target::remote_notice_new_inferior (ptid_t currthread, bool executing) 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); - } - /* This is really a new thread. Add it. */ thread_info *new_thr = remote_add_thread (currthread, running, executing, false); -- 2.34.1 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928