From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +YU7BQ5I+GkuuhEAWB0awg (envelope-from ) for ; Mon, 04 May 2026 03:17:34 -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=c8cCX4bl; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 07CBF1E0BA; Mon, 04 May 2026 03:17:34 -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 0E90B1E093 for ; Mon, 04 May 2026 03:17:33 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 6F7114B9DB68 for ; Mon, 4 May 2026 07:17:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F7114B9DB68 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=c8cCX4bl Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by sourceware.org (Postfix) with ESMTPS id 13C564B99F73 for ; Mon, 4 May 2026 07:16:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13C564B99F73 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 13C564B99F73 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777879017; cv=none; b=a6OV6Xqb2jRjC6G4quApGJZGhJFUzHy+VgCHidNuCtatQGwB2+ouZiZrFctR992m/P89pUhbZC3pX9Hit7Y/9dRCZ5DuW/o6j/kYkGJdDMh21iwKmAD54u4qx6wX6MuveyGmPjsaN1K4yN6FK/0IaF5I36uWsoPeuNQWK2nWXVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777879017; c=relaxed/simple; bh=ALtIGOurBHrYw0d053CziaUzGhBxCXB9c/V7lGD7F38=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=PeNpBPcdGNzOo5AyQHIWW1mdoudMUAkJt3w34BbApngQYbIuuqLRntR3cHzzxsw9o18g1x3PNhHJvtXOEuwD1ef9L2u4y6e0jfiYuQAfP7aJoMXDCZdapRW1Du/SqGfW4R6OfCVdSspd5zN5qZBxzEvwPiDRdgDrDwMpsSVGHDs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13C564B99F73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777879017; x=1809415017; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=ALtIGOurBHrYw0d053CziaUzGhBxCXB9c/V7lGD7F38=; b=c8cCX4blXa2FBEjDWS3b2AlXbvQtAwIEcBk/A8nzwC73Ga/KrO3on1lO Vd7df5x1edFygK220++9Df6w6GXvu1LyJ9w6R3zN+AXxaYSs8u3VS3uiA NKy6t8jC8L5sW2k88jEDz+fS3HO+ucJ5/j4Y+LpnP5+hdIFbtAgMiFkuJ zRd+jo38Kt1fj+s8zctqBOPikab/5RE/LIjsCnsIuFEmTVHdNpP+EmhUg twAj/GVJYV42x/A8QiAR3rfElYkoHKeywLX3TgH48HD0/ZPku4E+cS76n MEEUAFxely8hXpRhphhJT/TSGSUUwYotXKrxnuQ1pAbuJ2y/4a7zBZiG6 A==; X-CSE-ConnectionGUID: kHu/HLr/T6S964BOLNOqsQ== X-CSE-MsgGUID: l1jaJ8Y6Q8KfGpSXN0LOYw== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="78925998" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="78925998" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 00:16:56 -0700 X-CSE-ConnectionGUID: UoLAqE7mRPCAjEeaxtP7Jw== X-CSE-MsgGUID: wgREyLj9SaWRz/o3zmNb5g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="237221238" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 00:16:41 -0700 From: Markus Metzger To: gdb-patches@sourceware.org Subject: [PATCH] gdb: fix an issue with thread list corruption Date: Mon, 4 May 2026 07:16:31 +0000 Message-Id: <20260504071636.1571615-2-markus.t.metzger@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260504071636.1571615-1-markus.t.metzger@intel.com> References: <20260504071636.1571615-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 When resuming a target in non-stop mode with 'c -a', the continue command uses for_each_thread() to proceed each stopped thread individually. This uses an all_threads_safe() iteration. If one of the stopped threads does an inline step-over, since the target is non-stop, we stop_all_threads(), which involves update_thread_list(), which, in turn, may delete_thread(). If this deleted the thread pointed to by the m_next safe iterator member, the above all_threads_safe() iteration will be corrupted. The thread we're proceeding is stopped and there is no reason to delete it. Consequently, there is no reason for all_threads_safe(), which isn't that safe in this scenario. Iterate using all_threads() and inline proceed_thread_callback(). --- gdb/infcmd.c | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index f3f15c9ae1d..692158e1aaf 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -685,29 +685,6 @@ starti_command (const char *args, int from_tty) run_command_1 (args, from_tty, RUN_STOP_AT_FIRST_INSN); } -static void -proceed_thread_callback (struct thread_info *thread) -{ - /* We go through all threads individually instead of compressing - into a single target `resume_all' request, because some threads - may be stopped in internal breakpoints/events, or stopped waiting - for its turn in the displaced stepping queue (that is, they are - running from the user's perspective but internally stopped). The - target side has no idea about why the thread is stopped, so a - `resume_all' command would resume too much. If/when GDB gains a - way to tell the target `hold this thread stopped until I say - otherwise', then we can optimize this. */ - if (thread->state () != THREAD_STOPPED) - return; - - if (!thread->inf->has_execution ()) - return; - - switch_to_thread (thread); - clear_proceed_status (0); - proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); -} - static void ensure_valid_thread (void) { @@ -746,12 +723,12 @@ ensure_not_running (void) } void -continue_1 (int all_threads) +continue_1 (int all) { ERROR_NO_INFERIOR; ensure_not_tfind_mode (); - if (non_stop && all_threads) + if (non_stop && all) { /* Don't error out if the current thread is running, because there may be other stopped threads. */ @@ -762,7 +739,30 @@ continue_1 (int all_threads) scoped_disable_commit_resumed disable_commit_resumed ("continue all threads in non-stop"); - for_each_thread (proceed_thread_callback); + /* Do not use all_threads_safe in case threads get removed while + resuming THREAD. */ + for (thread_info &thread : all_threads ()) + { + /* We go through all threads individually instead of compressing + into a single target `resume_all' request, because some + threads may be stopped in internal breakpoints/events, or + stopped waiting for its turn in the displaced stepping queue + (that is, they are running from the user's perspective but + internally stopped). The target side has no idea about why + the thread is stopped, so a `resume_all' command would resume + too much. If/when GDB gains a way to tell the target `hold + this thread stopped until I say otherwise', then we can + optimize this. */ + if (thread.state () != THREAD_STOPPED) + continue; + + if (!thread.inf->has_execution ()) + continue; + + switch_to_thread (&thread); + clear_proceed_status (0); + proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT); + } if (current_ui->prompt_state == PROMPT_BLOCKED) { -- 2.34.1 Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 89 991 430, www.intel.de Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell Chairperson of the Supervisory Board: Nicole Lau Registered Seat: Munich Commercial Register: Amtsgericht Muenchen HRB 186928