From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ASIFGkwLNWomFQ8AWB0awg (envelope-from ) for ; Fri, 19 Jun 2026 05:26:36 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=bachmann.info header.i=@bachmann.info header.a=rsa-sha256 header.s=selector1 header.b=tEOHJXZS; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 629691E098; Fri, 19 Jun 2026 05:26:36 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 951451E024 for ; Fri, 19 Jun 2026 05:26:35 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2908C4B9DB6F for ; Fri, 19 Jun 2026 09:26:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2908C4B9DB6F Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=bachmann.info header.i=@bachmann.info header.a=rsa-sha256 header.s=selector1 header.b=tEOHJXZS Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazlp170120005.outbound.protection.outlook.com [IPv6:2a01:111:f403:c200::5]) by sourceware.org (Postfix) with ESMTPS id 062B84BA2E0F for ; Fri, 19 Jun 2026 09:26:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 062B84BA2E0F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=bachmann.info Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bachmann.info ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 062B84BA2E0F Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:c200::5 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1781861165; cv=pass; b=sXK+J7wOJf1TH2PpWodR7VPsm9i+I6HBcnqB59QIKVSMmxKh0KExCja3Z+4mr7/+IJF4TKDsNC3LwptUwDvL9dpjf+q0/g5klq5+Dlw4pql0xhYNuWvmB+HN3eYbvRWnv+XDWcHQFGoJgvl1Juwq8GGq5z7AOz4k/WrsNZb/PGU= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1781861165; c=relaxed/simple; bh=0Au6SDzOZiGgeDPHsolPKax/Gx8LZZLYaz5fZqPJCkw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vbY4IujsZPsH4bCC2zqJEVVglv0QonbfTHFUAh7+Z3kClvJ3+XPkjmaIeIEU/9c2i3mFq0kRpAp4/aIEboNNeqkAviUDfJSp2N9dQV90DCmowrY2csLSTpghxto9d3h+niBOWxfEaZsQ7Ugji1SyXDSjvGG9sqbZJXdXUeyztw0= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=bachmann.info header.i=@bachmann.info header.a=rsa-sha256 header.s=selector1 header.b=tEOHJXZS DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 062B84BA2E0F ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BDrrhmCoKyDXmYLbzfz3vxRMTJQaqep2i20Y2HM+GRi/7Xb0juq1QO+IUFaPsOU9U7Ytd8JpUxsWT+rYFMd1SriWEbuXTJtcDRGe9mCJ+Tod4j+bbYBIrGG3N7qDMJiiaICaLHg2z+TuffYBkx5ORUksFJPLb8UUf0APDqsbnkUr84T+Y09wk6JHQCRgtvpRjzs5qbGO3SfjQ3IaqfDdIZBS1wdcgHbnriZclvow0e6/6G/VWzsrTe6qKtz8ZatypQeXiA86vNGwRExYoyNnAHqPlpP2mBx/KJWq2/DXNl0d5HMLQfjdsKtX9R+m8jOj32YpUbKvRF4KdGEG+D5jxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=z01EQ7CpqduzUa4M4rDURX3P1webD7Nm7Tm6wtL/kTs=; b=hSn8XO1Xvz+3gmOU3X8bNla5fNsB9+hnTjIw6rMVocEr+hYgCZ4mDQmNYPQi6cv7v8D7DNyNI9A8eveOviGdtoNN/U/qtZP79VbSkc0SMs9cm1q98Fbpnk7nLf7r0WbwTRYwhZlJK9PpY/umC6Tq1eQwn4tYOVKiKPFOfdLfFsxn2XPQdynLW/F49S0b8erCkRNQOyjMmhN7Uhamrg/3gniixsCFLq/6sddVkfUZwGC4tIXj2rqFx7JihB+yHZy1RWRfsdVdG6qByojfdRSieEYzjpu5r3I55+PTOpaGYABR3UieMBHmI25GMebHlsfvgQHR0Y5N+DYoS+ogyvZJAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=softfail (sender ip is 185.67.228.71) smtp.rcpttodomain=sourceware.org smtp.mailfrom=bachmann.info; dmarc=fail (p=quarantine sp=quarantine pct=100) action=quarantine header.from=bachmann.info; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bachmann.info; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=z01EQ7CpqduzUa4M4rDURX3P1webD7Nm7Tm6wtL/kTs=; b=tEOHJXZSH4qakF6JPzDJ2t27Tl9ZyjFnYsfOeoAlRNaNDkOgNQ+9dI7DJXjiWFA1TxpJCpfZgqfOtsLGKrJtE2W5SwF9nwi7U7a+gttCrliLyrkufia5KibVyNNaKmaUXVgrOQbA08FUS1wLBywahRS/bWWnzuT36RvUgD38OCk= Received: from DU2PR04CA0244.eurprd04.prod.outlook.com (2603:10a6:10:28e::9) by PR3PR05MB6937.eurprd05.prod.outlook.com (2603:10a6:102:65::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.139.11; Fri, 19 Jun 2026 09:25:59 +0000 Received: from DU2PEPF00028D06.eurprd03.prod.outlook.com (2603:10a6:10:28e:cafe::b) by DU2PR04CA0244.outlook.office365.com (2603:10a6:10:28e::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.139.15 via Frontend Transport; Fri, 19 Jun 2026 09:25:58 +0000 X-MS-Exchange-Authentication-Results: spf=softfail (sender IP is 185.67.228.71) smtp.mailfrom=bachmann.info; dkim=none (message not signed) header.d=none;dmarc=fail action=quarantine header.from=bachmann.info; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning bachmann.info discourages use of 185.67.228.71 as permitted sender) Received: from webmail.bachmann.info (185.67.228.71) by DU2PEPF00028D06.mail.protection.outlook.com (10.167.242.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.7 via Frontend Transport; Fri, 19 Jun 2026 09:25:58 +0000 Received: from ATFKPCLXMAKO.bachmann.at (10.204.44.221) by atfkex03.bachmann.at (10.10.10.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.29; Fri, 19 Jun 2026 11:25:57 +0200 From: Martin KOCH To: CC: , Martin KOCH Subject: [PATCH v2] gdb/remote: fix assertions when attaching in non-stop mode Date: Fri, 19 Jun 2026 11:25:35 +0200 Message-ID: <20260619092535.2476689-1-Martin.KOCH@bachmann.info> X-Mailer: git-send-email 2.43.0 In-Reply-To: <15e03eb6-40b4-4f69-a96b-57e3650e021f@simark.ca> References: <15e03eb6-40b4-4f69-a96b-57e3650e021f@simark.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: atfkex03.bachmann.at (10.10.10.31) To atfkex03.bachmann.at (10.10.10.31) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D06:EE_|PR3PR05MB6937:EE_ X-MS-Office365-Filtering-Correlation-Id: 7b8fa5fe-aa90-4ec9-3e1e-08decde4c56a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|36860700016|23010399003|376014|11063799006|5023799004|56012099006|6133799003|13003099007|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: HBn2inunVq9hGWWGpGYxqZxhzJ7oT3gumRklBUqmlFd73ayPop9fFbX6PXkxgOWPDgQa2W4Vvcfby08mqw+vXTML6p4BmAcbKVa0k3yFKzSZ1szs8UZbKOn+s8ogIrtYXXPUQ0HJN2XY6xuz0g7mc/jR2pBQM1Zc2qOoR45ez5sjyAZiGYKcQEKoxYUghGNclIuNFMsxsGEHktfKa8qsnxAJAP4qWlMsCNbiE3TX6615kpst5P7voyl6fizh0WNYH5G/cyybi5PbQ4cTyKWgtjYQglTXW0r731VyUTiIcSiNXiq1CCghzJsMGxW4MbpEsYNvvBQguecFNQCWexlmKlKCwt7Gn+DZ8q7+ApFdPkTfkynXgMIG/f5lH7akcalvxFBUU5FZ+M7NEv6BCmNJ+kivcKKpUjVgUT3iq0q2oK/+hikYhCz5crs0/aein/sxV5DAJmQwIQ5J9oQPsdqpAliCDOTWb1WmwiuGuT9To7Rw9AXavmeA7iT4uJeIRbnq+9+wGG7Ue5L4i4pvem1MwXEQOPToifFOQt12T6XHFK+ShzuOddhxPUo0lnH+i0rUt65oea4CNKB+rkyJNcy5vQnqzXu3kHFpyuVmtiNi4ouFkRa28cuwER5RGh4QrMdqzyZfkX1H3tWaFFiZGuHJ8g== X-Forefront-Antispam-Report: CIP:185.67.228.71; CTRY:AT; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:webmail.bachmann.info; PTR:ErrorRetry; CAT:NONE; SFS:(13230040)(82310400026)(1800799024)(36860700016)(23010399003)(376014)(11063799006)(5023799004)(56012099006)(6133799003)(13003099007)(22082099003)(18002099003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tRGsEGPqCFBjnj+ZlrjJsefIq4QyjXtqbsd+Y6sNBlEXESD4wC0mBVySnfF3p50Ydxw4/tZHzfOTldU4sjsosl4dVOY6X90/zuS+bFT/pTlPZZuo06sVB6VRwUAY8EXLSc1UXuwODYdS3AkWEfm68KCGMK+pHd/568vJBYdaZzoIC/uCsbkyOMj6mM6e4GDZYRIHU7SbDl0/GTRs0ewy1T2VHRNySESOkhquHBQJ8To8CTgTzrc9XiFrOtLo8SvHLXtZkOWrgrEnrJDXQk56KmGY22GQFtqyNHoi+YwvE+N8gR4KC07beYbQPnA/LEUw6xom3dMUi5oAQ+XG9aAOEX6MJ3HSVT1e74B/l+fYs1k/AmkFUuOmoTYoEGdqby1mf0TWG7Cm87RJnXMSjbo5FvBJApHwZgd5FHSJz1B1Zb7RAVzY1VesVfZxii0crhTG X-OriginatorOrg: bachmann.info X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2026 09:25:58.0452 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7b8fa5fe-aa90-4ec9-3e1e-08decde4c56a X-MS-Exchange-CrossTenant-Id: e3bace4d-d2e7-4d8f-afb8-152509ee3f1a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=e3bace4d-d2e7-4d8f-afb8-152509ee3f1a; Ip=[185.67.228.71]; Helo=[webmail.bachmann.info] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D06.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR05MB6937 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 connecting to a remote target in non-stop mode against a multi-threaded inferior stopped at raise(SIGSTOP), three internal-error assertions can fire in sequence: remote.c:546: mark_async_event_handler: Assertion 'this->is_async_p ()' failed. thread.c:429: set_pending_waitstatus: Assertion 'this->internal_state () == THREAD_INT_STOPPED || ...' failed. thread.c:426: set_pending_waitstatus: Assertion '!this->has_pending_waitstatus ()' failed. The first one is what PR 30630 reports and is fixed with the PR proposed by Mikhail Terekhov, but with the fix the two other assertions surface: * thread.c:429: addressed by reordering set_internal_state / set_state to run before set_pending_waitstatus. * thread.c:426: addressed by clearing any existing pending wait status before installing the new one, when gdbserver delivers multiple events for the same thread. These assertions are reached through remote.c:process_initial_stop_replies, which only runs on the initial connection to a remote target, not via GDB's own "attach" command. The new test gdb.threads/attach-non-stop-stopped.exp reproduces the issue: it starts gdbserver attached to a multi-threaded inferior that is already stopped via a pending SIGSTOP, then connects GDB to it in non-stop mode. Without this fix the connection trips the assertions above; with it, the connection succeeds. [1] https://sourceware.org/pipermail/gdb-patches/2023-October/202937.html Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30630 Signed-off-by: Martin KOCH --- gdb/remote.c | 14 ++- .../gdb.threads/attach-non-stop-stopped.c | 78 +++++++++++++ .../gdb.threads/attach-non-stop-stopped.exp | 104 ++++++++++++++++++ 3 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 gdb/testsuite/gdb.threads/attach-non-stop-stopped.c create mode 100644 gdb/testsuite/gdb.threads/attach-non-stop-stopped.exp diff --git a/gdb/remote.c b/gdb/remote.c index 2961664cf33..4148301bc6f 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -5237,13 +5237,17 @@ remote_target::process_initial_stop_replies (int from_tty) ws.set_stopped (sig); } - if (ws.kind () != TARGET_WAITKIND_STOPPED - || ws.sig () != GDB_SIGNAL_0) - evthread->set_pending_waitstatus (ws); - set_internal_state (this, event_ptid, THREAD_INT_STOPPED); set_state (this, event_ptid, THREAD_STOPPED); get_remote_thread_info (evthread)->set_not_resumed (); + + if (ws.kind () != TARGET_WAITKIND_STOPPED + || ws.sig () != GDB_SIGNAL_0) + { + if (evthread->has_pending_waitstatus ()) + evthread->clear_pending_waitstatus (); + evthread->set_pending_waitstatus (ws); + } } /* "Notice" the new inferiors before anything related to @@ -8384,7 +8388,7 @@ remote_target::queued_stop_reply (ptid_t ptid) remote_state *rs = get_remote_state (); stop_reply_up r = remote_notif_remove_queued_reply (ptid); - if (!rs->stop_reply_queue.empty () && target_can_async_p ()) + if (!rs->stop_reply_queue.empty () && target_is_async_p ()) { /* There's still at least an event left. */ rs->mark_async_event_handler (); diff --git a/gdb/testsuite/gdb.threads/attach-non-stop-stopped.c b/gdb/testsuite/gdb.threads/attach-non-stop-stopped.c new file mode 100644 index 00000000000..c58562892e9 --- /dev/null +++ b/gdb/testsuite/gdb.threads/attach-non-stop-stopped.c @@ -0,0 +1,78 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2026 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* This program creates a few threads and then stops the whole process + with a pending SIGSTOP, leaving it group-stopped. It is intended to + be started outside of GDB and then attached to. See + attach-non-stop-stopped.exp. */ + +#include +#include +#include +#include + +/* Number of threads we'll create, in addition to the main thread. */ +#define N_THREADS 4 + +/* Used to make sure all threads are running before we stop the + process. */ +static pthread_barrier_t barrier; + +/* Entry point for threads. Loops forever. */ + +static void * +thread_func (void *arg) +{ + pthread_barrier_wait (&barrier); + + while (1) + sleep (1); + + return NULL; +} + +int +main (void) +{ + pthread_t threads[N_THREADS]; + int i; + + /* Safety net, in case the process is left running. */ + alarm (300); + + pthread_barrier_init (&barrier, NULL, N_THREADS + 1); + + for (i = 0; i < N_THREADS; ++i) + { + int rc = pthread_create (&threads[i], NULL, thread_func, NULL); + assert (rc == 0); + } + + /* Wait until all threads are up and running. */ + pthread_barrier_wait (&barrier); + + /* Stop the whole process (all threads) with a real, pending SIGSTOP. + When GDB later attaches in non-stop mode against a remote target, + each thread is reported with this pending signal. That is what + used to trigger the assertions described in PR gdb/30630. */ + raise (SIGSTOP); + + while (1) + sleep (1); + + return 0; +} diff --git a/gdb/testsuite/gdb.threads/attach-non-stop-stopped.exp b/gdb/testsuite/gdb.threads/attach-non-stop-stopped.exp new file mode 100644 index 00000000000..af68f8f781a --- /dev/null +++ b/gdb/testsuite/gdb.threads/attach-non-stop-stopped.exp @@ -0,0 +1,104 @@ +# Copyright 2026 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Regression test for PR gdb/30630. +# +# Start gdbserver attached to a multi-threaded inferior that is already +# stopped (here, via a pending SIGSTOP), then connect GDB to it in +# non-stop mode. + +load_lib gdbserver-support.exp + +require allow_gdbserver_tests +require can_spawn_for_attach + +standard_testfile + +if {[build_executable "failed to prepare" $testfile $srcfile \ + {debug pthreads}] == -1} { + return +} + +# Number of threads the test program creates (see N_THREADS in .c file) +set n_threads 4 +set total [expr {$n_threads + 1}] + +# Spawn the program. It creates its threads and then stops the whole +# process with a pending SIGSTOP. +set test_spawn_id [spawn_wait_for_attach $binfile] +set testpid [spawn_id_get_pid $test_spawn_id] + +save_vars { GDBFLAGS } { + append GDBFLAGS " -ex \"set non-stop on\"" + + if { ![is_remote host] && ![is_remote target] } { + append GDBFLAGS " -ex \"set sysroot\"" + } + + clean_restart $testfile +} + +gdb_test "disconnect" ".*" + +# Start gdbserver already attached to the stopped process. +set res [gdbserver_start "--attach" $testpid] +if { [llength $res] == 0 } { + kill_wait_spawned_process $test_spawn_id + unsupported "gdbserver --attach failed" + return +} +set gdbserver_gdbport [lindex $res 1] + +# Connect to gdbserver in non-stop mode. Without the fix for PR 30630, +# GDB hits an internal error here. +set connected 0 +gdb_test_multiple "target remote $gdbserver_gdbport" \ + "connect to gdbserver in non-stop mode" { + -re "Non-stop mode requested, but remote does not support non-stop.*$gdb_prompt $" { + unsupported $gdb_test_name + } + -re "Remote debugging using .*$gdb_prompt $" { + pass $gdb_test_name + set connected 1 + } +} + +if { !$connected } { + kill_wait_spawned_process $test_spawn_id + return +} + +# GDB survived the connection. As a sanity check, confirm it is +# responsive and that all threads are present. +for {set attempt 0} {$attempt < 10} {incr attempt} { + set thread_count 0 + gdb_test_multiple "info threads" "" { + -re "\r\n\[ *\]+$decimal\[ \t\]+(Thread|LWP|process)\[^\r\n\]*" { + incr thread_count + exp_continue + } + -re "$gdb_prompt " { + } + } + if {$thread_count >= $total} { + break + } + sleep 1 +} +gdb_assert {$thread_count == $total} "all threads present" + +gdb_test "detach" "Detaching from.*" + +kill_wait_spawned_process $test_spawn_id base-commit: ddc575edf104eb477018a32b31074beffb179034 -- 2.43.0