From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id IXQWHuHG8GparjUAWB0awg (envelope-from ) for ; Sun, 08 Nov 2026 14:00:49 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=alIQTsOj; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 76313378002; Sun, 08 Nov 2026 14:00:49 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 7E8B41E023 for ; Sun, 08 Nov 2026 14:00:48 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 10E7A4BA23EC for ; Sun, 8 Nov 2026 19:00:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 10E7A4BA23EC Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=alIQTsOj Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 589734BA2E2F for ; Sun, 8 Nov 2026 19:00:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 589734BA2E2F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 589734BA2E2F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::331 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794164420; cv=none; b=mPS4YNQ+XvHYHuwVh/AIIFxLCf46u+H6WRzKOq+pniry8j8aMjsq9FaVy+iNJpkhBjHWunLYAm9tSZPesvVXV0LHulc46sNGNrPDwexh5Gma+o+Q0BzlF4aCtFuzWqhu8N33XUA5KBsSBvklJb2YQB+iOd8oOtDtXjXx7VOB400= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794164420; c=relaxed/simple; bh=eQ3hy7EfmHgLfUoIvZLWtUb4egK1L3O3gILBHxL33fs=; h=DKIM-Signature:To:Date:Message-ID:MIME-Version:From:Subject; b=bPY93HlmReDFaShFGYrPQ7B7p/+w3VCV8uZrzokqGcGnlFGJS0MzkYjeGESrULQMwDCkW315KM71L7OwmvhE2dBdXRBOr2FyI/bFUwf1ZUWRwkZ0v+SbQ1UaPkcY8AL6nPGiaOI28ZwqWssKNiDY1nboAw5U79LPXAV2EeDjEzg= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=alIQTsOj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 589734BA2E2F Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4a140e7405dso1387715e9.3 for ; Sun, 08 Nov 2026 11:00:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794164419; x=1794769219; darn=sourceware.org; h=subject:from:content-transfer-encoding:content-type:mime-version :message-id:date:cc:to:from:to:cc:subject:date:message-id:reply-to :content-type; bh=RoUhFlEKF0wlNO08IW6hqnuh/HbEP4a2vaiX4uJ6hks=; b=alIQTsOjwaT0cC8vUNZHlWlpV0GF7QIx75qZtP3kS9W8G9mIK/c8rh8u2jAczA09vu KYRunEEXU+m/cwHPiGNxF3Fz6zHqi7A1eCh06uWFdnlYB7XKmqQUF+oEMjaqlayZZyTy k3ligC8WEvI/auUU6Z5HTXXZVMrjX5RrdU8k48S3bsez1XDE4N16ieDxNqxx0rZqWWWO W5ZHxN1aV4614YF38XNUFZGjH8rG4UafhXh+YHSNAeyP1UjQoWxX/OynJTj0ekAA4dY1 GRa29XSaIUbZ+1Eu4CVoywuTFdLf6tKoQlXqS86jawGMpUBlq1wM92pFC4CQg7xXYJer p3rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794164419; x=1794769219; h=subject:from:content-transfer-encoding:content-type:mime-version :message-id:date:cc:to:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=RoUhFlEKF0wlNO08IW6hqnuh/HbEP4a2vaiX4uJ6hks=; b=Ew3wPTcm2a4uqEb5uzFVSumitLeBPbgW0vJe6MVyOVxoiRJE9SLQiMWvyQvzpi0L9X 7HJHor9VbEL9Iq/3BP94HCUmHWn8GLX+mqtPlRv8BEZwbllU6y3xDblcjH37b0GDhDLr 4Z/pEhgzEBIIBB0mS09HmeUtbtFDfvIE+3MFcnvavjHF5BTX38T8OD1vJM3sEzWanubN jlmAQ9qzTwbpJR/hgeI4xWeSB68viVHRk3jvzLUuz0GGTxRPCgEA1UEaaHP7+pMM3p+k zJ21JpYJDpoH9IUC+wZy3PnZYwJufWcm6oGLn2OnKCoujEvpZkbPNJ+wrUt78SO6yS/O Ilcg== X-Gm-Message-State: APuU4Z/u1/+Lnl/fYfJQxueoH08vvXQLReI9vYCyF6gXBd4zJQybbYJl Od0DT++KbGiSFu2nfxhJ4rx20rTthObskWQVISASuSj2d863NHyMSIg+o+dayQ== X-Gm-Gg: AYBFou1MW7iWPvvnRVp73IqB4/B9LCiGmk+3/9wuhWt0LHRzj3og2gz1csNlSkkCaAb s6QS2T+xW7v7+xkUc+o5vpSVtzBoaAwJ9uLBC5jXmdk7gPQatKQ+I0ODjW6mfuRQn0W9/ZKp6eQ AH3/egtKutomph9eYe4b1X3pnk66R73bSXIAAkXLWmC5PQWSNYZbUxlQ7EgKondsE9Lardej32L ylw5QT/I2jXht3UVHYamdt23q+nrciAdYk/8PG7gOEJ173fJM03vQ3lJihsBCY7uzYIjtiRpWzG zjW4ex4Jtk1qeiUFDt9HQiUoIMNv5GMmuxbmFN7J6iFPB3hTzcg4tQVoeiISR1Rcgu28frjf4t8 eEQ4wUoLGrjhZgx4JHhKx25CYXMQMLkEFq89BVy0cDICy1UZO2kt35ma/i7xoenFWsFWoooSAPs shrqvFqf+3xjRbXCWOLLpJB1kDCXR93azLLZq/MPkQ8nYa7i3nXWSJlFEyomHJziTXMoe7QOJvU KhCl36o8IUmUfy1NRCdf+MEfwuXoJTCf+n2oWu9gL/jphPIRUqULzsEWC2b9LP+i3QqP0wQhTMb PHOumVglUKQ/ojWkFM+9o2dTePV5EOOoUILp2HxcFOLeQze5tWUrzw== X-Received: by 2002:a05:600c:4e4e:b0:4a0:23f:8b0d with SMTP id 5b1f17b1804b1-4b94d763141mr39560915e9.2.1794164418639; Sun, 08 Nov 2026 11:00:18 -0800 (PST) Received: from [127.0.1.1] ([212.23.215.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4b7efb1f3acsm185258665e9.14.2026.11.08.11.00.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Nov 2026 11:00:18 -0800 (PST) To: gdb-patches@sourceware.org Cc: Pedro Alves Date: Sun, 08 Nov 2026 19:00:06 +0000 Message-ID: <179416440671.1563501.827160066079108554@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Josip Seketa Subject: [PATCH] gdb/remote: tell the stub about "set non-stop" before run and attach 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 GDB tells a remote stub its mode with QNonStop once, when connecting. But "set non-stop" only refuses to change while the program is running, so on an extended-remote connection with no program yet the user can change it, and the stub is never told: (gdb) target extended-remote :1234 (gdb) set non-stop on (gdb) run Unexpected vCont reply in non-stop mode: T05swbreak:;... The two now disagree on how to talk to each other. The first stop is rejected, and the program stays shown as running. The other direction, "set non-stop off", hangs in run, and attach is affected the same way. Remember what the stub was last told, and tell it again before run and attach if that is no longer what GDB is in. A session that does not change the setting sends the same packets as before. Do not do that while another program runs on the same connection. "set non-stop" only checks the current inferior, so it can be changed with a second, empty inferior selected, and switching the stub would change how it runs the first program too. That case stays as it was. A stub that does not support QNonStop now gets the same error at run and attach as at connect, "Non-stop mode requested, but remote does not support non-stop", instead of running into the mismatch above. Move the QNonStop code to a function, to use it for this. --- gdb.server/non-stop-after-connect.exp is new. It does not cover a stub without QNonStop: gdbserver always supports it, and GDB has no "set remote" command to turn it off. On native-extended-gdbserver this also fixes the "run to main" failures of gdb.threads/break-while-running.exp, multi-create-ns-info-thr.exp, non-stop-fair-events.exp and thread-execl.exp, 7 in all, which set non-stop after the board connected. Tested on x86_64 GNU/Linux, master at 819dfa7b532, against the same commit without the patch, with an unpatched gdbserver, on gdb.server and the four tests above. The new test fails 10 of 26 on master with native-extended-gdbserver and with unix, and 5 of 14 with native-gdbserver, and passes on all three with the patch; the four tests go from 7 failures to none. No new failures, and with "maint set target-non-stop on" the results are the same with and without the patch. I have no FSF copyright assignment. This is my own work, not my employer's. gdb/remote.c | 96 +++++++++++++------ .../gdb.server/non-stop-after-connect.exp | 93 ++++++++++++++++++ 2 files changed, 160 insertions(+), 29 deletions(-) create mode 100644 gdb/testsuite/gdb.server/non-stop-after-connect.exp diff --git a/gdb/remote.c b/gdb/remote.c index a728d57df6e..132840259b3 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -609,6 +609,10 @@ class remote_state because we allow GDB commands while the target is running. */ bool waiting_for_stop_reply = false; + /* The mode the stub was last told about with QNonStop. "set + non-stop" can change GDB's side of this while connected. */ + bool stub_non_stop = false; + /* The status of the stub support for the various vCont actions. */ vCont_action_support supports_vCont; @@ -1307,6 +1311,14 @@ class remote_target : public process_stratum_target ptid_t ptid); static void open_1 (const char *name, int from_tty, int extended_p); void start_remote (int from_tty, int extended_p); + + /* Tell the stub to be in non-stop mode if ON, else all-stop. */ + void set_stub_non_stop (bool on); + + /* Call set_stub_non_stop if the stub's mode is not GDB's, and no + program is running on this connection. */ + void update_stub_non_stop (); + void remote_detach_1 (struct inferior *inf, int from_tty); char *append_resumption (char *p, char *endp, @@ -5553,36 +5565,13 @@ remote_target::start_remote_1 (int from_tty, int extended_p) if (gdbarch_has_global_solist (current_inferior ()->arch ())) solib_add (NULL, from_tty, auto_solib_add); - if (target_is_non_stop_p ()) - { - if (m_features.packet_support (PACKET_QNonStop) != PACKET_ENABLE) - error (_("Non-stop mode requested, but remote " - "does not support non-stop")); - - putpkt ("QNonStop:1"); - getpkt (&rs->buf); - - if (!streq (rs->buf.data (), "OK")) - error (_("Remote refused setting non-stop mode with: %s"), - rs->buf.data ()); + set_stub_non_stop (target_is_non_stop_p ()); - /* Find about threads and processes the stub is already - controlling. We default to adding them in the running state. - The '?' query below will then tell us about which threads are - stopped. */ - this->update_thread_list (); - } - else if (m_features.packet_support (PACKET_QNonStop) == PACKET_ENABLE) - { - /* Don't assume that the stub can operate in all-stop mode. - Request it explicitly. */ - putpkt ("QNonStop:0"); - getpkt (&rs->buf); - - if (!streq (rs->buf.data (), "OK")) - error (_("Remote refused setting all-stop mode with: %s"), - rs->buf.data ()); - } + /* Find about threads and processes the stub is already controlling. + We default to adding them in the running state. The '?' query + below will then tell us about which threads are stopped. */ + if (target_is_non_stop_p ()) + this->update_thread_list (); /* Upload TSVs regardless of whether the target is running or not. The remote stub, such as GDBserver, may have some predefined or builtin @@ -5776,6 +5765,49 @@ remote_target::start_remote_1 (int from_tty, int extended_p) return true; } +void +remote_target::set_stub_non_stop (bool on) +{ + remote_state *rs = get_remote_state (); + + if (m_features.packet_support (PACKET_QNonStop) != PACKET_ENABLE) + { + if (on) + error (_("Non-stop mode requested, but remote " + "does not support non-stop")); + + /* Don't assume that the stub can operate in all-stop mode, but + if it has no other mode there is nothing to request. */ + return; + } + + putpkt (on ? "QNonStop:1" : "QNonStop:0"); + getpkt (&rs->buf); + + if (!streq (rs->buf.data (), "OK")) + error (on + ? _("Remote refused setting non-stop mode with: %s") + : _("Remote refused setting all-stop mode with: %s"), + rs->buf.data ()); + + rs->stub_non_stop = on; +} + +void +remote_target::update_stub_non_stop () +{ + if (target_is_non_stop_p () == get_remote_state ()->stub_non_stop) + return; + + /* "set non-stop" only checks the current inferior. Do not switch + the stub under a program that is already running on this + connection. */ + if (number_of_live_inferiors (this) > 0) + return; + + set_stub_non_stop (target_is_non_stop_p ()); +} + /* Start the remote connection and sync state. */ void @@ -7002,6 +7034,9 @@ extended_remote_target::attach (const char *args, int from_tty) if (m_features.packet_support (PACKET_vAttach) == PACKET_DISABLE) error (_("This target does not support attaching to a process")); + /* "set non-stop" may have been used since connecting. */ + update_stub_non_stop (); + target_announce_attach (from_tty, pid); xsnprintf (rs->buf.data (), get_remote_packet_size (), "vAttach;%x", pid); @@ -11451,6 +11486,9 @@ extended_remote_target::create_inferior (const char *exec_file, std::string remote_exec_file = get_exec_file_for_create_inferior (exec_file); + /* "set non-stop" may have been used since connecting. */ + update_stub_non_stop (); + /* If running asynchronously, register the target file descriptor with the event loop. */ if (target_can_async_p ()) diff --git a/gdb/testsuite/gdb.server/non-stop-after-connect.exp b/gdb/testsuite/gdb.server/non-stop-after-connect.exp new file mode 100644 index 00000000000..d5384afcaa1 --- /dev/null +++ b/gdb/testsuite/gdb.server/non-stop-after-connect.exp @@ -0,0 +1,93 @@ +# 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 . + +# Test changing "set non-stop" while connected with extended-remote, but +# with no program yet. GDB has to tell the stub before it starts or +# attaches to one, otherwise the two disagree on how to talk to each +# other: in non-stop mode GDB rejects the stop reply of an all-stop stub, +# and the program is left shown as running. + +load_lib gdbserver-support.exp + +standard_testfile ext-attach.c + +require allow_gdbserver_tests + +if {[build_executable "failed to prepare" $testfile $srcfile debug]} { + return +} + +# Connect with "set non-stop FROM", change that to TO, and then get a +# program with HOW, which is "run" or "attach". +proc run_test { how from to } { + save_vars { ::GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to + # avoid reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + append ::GDBFLAGS " -ex \"set sysroot\"" + } + + clean_restart $::testfile + } + + # Make sure we're disconnected, in case we're testing with an + # extended-remote board, therefore already connected. + gdb_test "disconnect" ".*" + + gdb_test_no_output "set non-stop $from" + + set target_exec [gdbserver_download_current_prog] + gdbserver_start_extended + + gdb_test_no_output "set non-stop $to" + + if { $how eq "run" } { + gdb_test_no_output "set remote exec-file $target_exec" + + gdb_breakpoint main + gdb_test "run" "Breakpoint $::decimal.* main .*" "run to main" + } else { + set test_spawn_id [spawn_wait_for_attach $::binfile] + set testpid [spawn_id_get_pid $test_spawn_id] + + gdb_test "attach $testpid" "Attaching to .* $testpid.*" "attach" + } + + gdb_test_multiple "info threads" "thread is stopped" { + -re "\\(running\\)\r\n$::gdb_prompt $" { + fail $gdb_test_name + } + -re -wrap "\\* 1 .*" { + pass $gdb_test_name + } + } + + gdb_test "kill" "\\\[Inferior $::decimal \\(.*\\) killed\\\]" "kill" \ + "Kill the program being debugged\\? \\(y or n\\) $" "y" + + if { $how eq "attach" } { + kill_wait_spawned_process $test_spawn_id + } +} + +foreach_with_prefix how {run attach} { + if { $how eq "attach" && ![can_spawn_for_attach] } { + continue + } + + foreach_with_prefix change {{off on} {on off}} { + run_test $how [lindex $change 0] [lindex $change 1] + } +} -- 2.56.0