From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mXJbEvZ6+WnTkBQAWB0awg (envelope-from ) for ; Tue, 05 May 2026 01:07:02 -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=IsHmxeA2; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 405371E093; Tue, 05 May 2026 01:07:02 -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=unavailable 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 760741E093 for ; Tue, 05 May 2026 01:07:01 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 7BA084B9DB56 for ; Tue, 5 May 2026 05:07:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BA084B9DB56 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=IsHmxeA2 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by sourceware.org (Postfix) with ESMTPS id A7CA84B9DB52 for ; Tue, 5 May 2026 05:06:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A7CA84B9DB52 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 A7CA84B9DB52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777957586; cv=none; b=WuDcGWNqi1We+OMvdL4W6pNnJkf9pKk5Ob0dSmdUq6kSXSYfH8tcYuxEOxCZVWiehmqyaDB3rpnHjGuz3JvEi03o0H1Qw0ezwzc7Cs70T8+btWpxRdVnN+P9RoZLEJlwmvugJT9H8YmIf7h8TrksYcusfWGCbbEeNxVxWsNdgBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777957586; c=relaxed/simple; bh=1DvuGoEvUEEI1tM88wtjZCrft+t/6mU8pIRHKP8vZ3Q=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=M5TI2bFyfOt/cOf+zA3j+E+tK/qFWwbZP3okoszkr3BCOmIgmx5WxBWNIt63YG47LQvjC2jClTS+ZiXNjIR0A96upc8K747hW44iYeunaLxaTBWDa8Nf/3sQdSg82fbqD3l3ktTuNiKak+YcYowe3kdHgLOiV0+AujXfJfurvjo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7CA84B9DB52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777957587; x=1809493587; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=1DvuGoEvUEEI1tM88wtjZCrft+t/6mU8pIRHKP8vZ3Q=; b=IsHmxeA2F7+tWPXO31IDfW3PKkNlHW2Ugzo8YITBLNVpGvopWiq5SJTB snl4GtaeflOS6/GhGVzNuJH+CKy5qnbWU9Yx6bZh6IqG/Z0mDBHAS/hqQ ZHzpJGVsQy4jmUhPOJdh+TKV1rYjkpyYLbG01JZgvrv/BcXlFhzXUpi7/ scHawDp+FQFtdRAn6eH/ivIoGOY/4FO9vxo5IB01deBOO+kNT/1MhTBqp OPNUX/f5e7nL8XPbzjCuzaeTmnAH0C63ZpbWVubgo1bsn54iDMmUbeClM YFuI4QO1VQp7+jILVpsfO5tAPh6CR7r+5mkmh8tCyXzhf5c3T2KZU1w/V g==; X-CSE-ConnectionGUID: iSnpK81yT0uHoy+KZj/JYw== X-CSE-MsgGUID: 1/1TzzqkRHCd1lrGgmiSvw== X-IronPort-AV: E=McAfee;i="6800,10657,11776"; a="104269824" X-IronPort-AV: E=Sophos;i="6.23,216,1770624000"; d="scan'208";a="104269824" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 22:06:26 -0700 X-CSE-ConnectionGUID: AHEfNI1eSdGxVyfpTb/pcg== X-CSE-MsgGUID: d/+qjkwYRrycqwrA1BqOEw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,216,1770624000"; d="scan'208";a="240006497" 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; 04 May 2026 22:06:21 -0700 From: Markus Metzger To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH v2] gdb: fix an issue with thread list corruption Date: Tue, 5 May 2026 05:06:18 +0000 Message-Id: <20260505050618.1366426-1-markus.t.metzger@intel.com> X-Mailer: git-send-email 2.34.1 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(). CC: Simon Marchi --- gdb/infcmd.c | 53 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index f3f15c9ae1d..af61c468f7a 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,31 @@ 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, because it's possible for the next + thread to get removed while resuming THREAD. We know that thread + is stopped and should not disappear under our feet. */ + 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