* [PATCH 1/2] gdb: fix assertion when interrupting an empty remote target
2026-08-05 8:59 [PATCH 0/2] gdb: improve interrupting an empty remote target Stephan Rohr
@ 2026-08-05 8:59 ` Stephan Rohr
2026-08-05 8:59 ` [PATCH 2/2] gdb, remote: Skip sending of 'vCont' package if remote target is empty Stephan Rohr
2026-08-17 14:37 ` [PATCH 0/2] gdb: improve interrupting an empty remote target Rohr, Stephan
2 siblings, 0 replies; 4+ messages in thread
From: Stephan Rohr @ 2026-08-05 8:59 UTC (permalink / raw)
To: gdb-patches
From: "Rohr, Stephan" <stephan.rohr@intel.com>
GDB asserts when sending an interrupt to an empty remote target, e.g.
use stdio to connect to a remote target in non-stop mode:
'gdb -ex "set non-stop on" -ex "target extended-remote | gdbserver
--multi --once -'
Interrupting the target triggers an assertion in 'find_inferior_pid'.
Fix by checking for a valid thread in 'interrupt_target_1' for 'non-stop'
mode.
---
gdb/infcmd.c | 5 ++-
.../interrupt-empty-remote-target.exp | 40 +++++++++++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)
create mode 100644 gdb/testsuite/gdb.server/interrupt-empty-remote-target.exp
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 3e943123519..512ecde4879 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -3133,7 +3133,10 @@ interrupt_target_1 (bool all_threads)
}
}
else
- stop_current_target_threads_ns (inferior_ptid);
+ {
+ ensure_valid_thread ();
+ stop_current_target_threads_ns (inferior_ptid);
+ }
}
else
target_interrupt ();
diff --git a/gdb/testsuite/gdb.server/interrupt-empty-remote-target.exp b/gdb/testsuite/gdb.server/interrupt-empty-remote-target.exp
new file mode 100644
index 00000000000..34437a17d90
--- /dev/null
+++ b/gdb/testsuite/gdb.server/interrupt-empty-remote-target.exp
@@ -0,0 +1,40 @@
+# Copyright 2024 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 <http://www.gnu.org/licenses/>.
+
+# Tests that GDB does not assert if interrupting an empty remote target
+# in non-stop mode.
+
+load_lib gdbserver-support.exp
+
+require allow_gdbserver_tests
+
+standard_testfile server.c
+
+if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
+ return -1
+}
+
+clean_restart ${testfile}
+
+# Make sure we're disconnected, in case we're testing with an
+# extended-remote board, therefore already connected.
+gdb_test "disconnect" ".*"
+
+gdbserver_start_extended "--once"
+
+gdb_test_no_output "set non-stop on"
+
+gdb_test "interrupt" \
+ "Cannot execute this command without a live selected thread."
--
2.43.0
________________________________________
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 (89) 99143-0
www.intel.de
Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
Chairperson of the Supervisory Board: Sonja Pierer
Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 2/2] gdb, remote: Skip sending of 'vCont' package if remote target is empty
2026-08-05 8:59 [PATCH 0/2] gdb: improve interrupting an empty remote target Stephan Rohr
2026-08-05 8:59 ` [PATCH 1/2] gdb: fix assertion when " Stephan Rohr
@ 2026-08-05 8:59 ` Stephan Rohr
2026-08-17 14:37 ` [PATCH 0/2] gdb: improve interrupting an empty remote target Rohr, Stephan
2 siblings, 0 replies; 4+ messages in thread
From: Stephan Rohr @ 2026-08-05 8:59 UTC (permalink / raw)
To: gdb-patches
From: "Rohr, Stephan" <stephan.rohr@intel.com>
If the remote target has no threads that need to be stopped, we can
skip sending the 'vCont' package in 'remote_stop_ns'.
---
gdb/remote.c | 4 ++++
.../interrupt-empty-remote-target.exp | 18 +++++++++++++++++-
gdb/thread-iter.h | 3 +++
3 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/gdb/remote.c b/gdb/remote.c
index 194c4cbd9bb..8be552b4533 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -7884,6 +7884,10 @@ remote_target::remote_stop_ns (ptid_t ptid)
}
}
+ /* Skip 'vCont' package if there are no threads to be stopped. */
+ if (all_non_exited_threads (this, ptid).empty ())
+ return;
+
if (!rs->supports_vCont.t)
error (_("Remote server does not support stopping threads"));
diff --git a/gdb/testsuite/gdb.server/interrupt-empty-remote-target.exp b/gdb/testsuite/gdb.server/interrupt-empty-remote-target.exp
index 34437a17d90..c26b535be16 100644
--- a/gdb/testsuite/gdb.server/interrupt-empty-remote-target.exp
+++ b/gdb/testsuite/gdb.server/interrupt-empty-remote-target.exp
@@ -14,7 +14,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Tests that GDB does not assert if interrupting an empty remote target
-# in non-stop mode.
+# in non-stop mode. Also tests that no 'vCont' package is sent for empty
+# remote targets.
load_lib gdbserver-support.exp
@@ -38,3 +39,18 @@ gdb_test_no_output "set non-stop on"
gdb_test "interrupt" \
"Cannot execute this command without a live selected thread."
+
+gdb_test_no_output "set debug remote on"
+
+# Test that we do not see a 'vCont' package if we interrupt an empty
+# remote target.
+gdb_test_multiple "interrupt -a" "no vCont is sent" {
+ -re -wrap "vCont.*" {
+ fail $gdb_test_name
+ }
+ -re -wrap "" {
+ pass $gdb_test_name
+ }
+}
+
+gdb_test_no_output "set debug remote off"
diff --git a/gdb/thread-iter.h b/gdb/thread-iter.h
index c649560c0e1..cc2b04e7e99 100644
--- a/gdb/thread-iter.h
+++ b/gdb/thread-iter.h
@@ -248,6 +248,9 @@ class all_non_exited_threads_range
all_non_exited_threads_iterator end () const
{ return all_non_exited_threads_iterator (); }
+ bool empty ()
+ { return begin () == end (); }
+
private:
process_stratum_target *m_filter_target;
ptid_t m_filter_ptid;
--
2.43.0
________________________________________
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 (89) 99143-0
www.intel.de
Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
Chairperson of the Supervisory Board: Sonja Pierer
Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
^ permalink raw reply [flat|nested] 4+ messages in thread* RE: [PATCH 0/2] gdb: improve interrupting an empty remote target
2026-08-05 8:59 [PATCH 0/2] gdb: improve interrupting an empty remote target Stephan Rohr
2026-08-05 8:59 ` [PATCH 1/2] gdb: fix assertion when " Stephan Rohr
2026-08-05 8:59 ` [PATCH 2/2] gdb, remote: Skip sending of 'vCont' package if remote target is empty Stephan Rohr
@ 2026-08-17 14:37 ` Rohr, Stephan
2 siblings, 0 replies; 4+ messages in thread
From: Rohr, Stephan @ 2026-08-17 14:37 UTC (permalink / raw)
To: gdb-patches
Kindly pinging 😊
> -----Original Message-----
> From: Stephan Rohr <stephan.rohr@intel.com>
> Sent: Wednesday, 5 August 2026 10:59
> To: gdb-patches@sourceware.org
> Subject: [PATCH 0/2] gdb: improve interrupting an empty remote target
>
> From: "Rohr, Stephan" <stephan.rohr@intel.com>
>
> Hello all,
>
> GDB hits an assertion when interrupting an empty remote target. Fix it
> by ensuring a valid thread first. We can also skip sending the 'vCont'
> package for an empty target. This is fixed in the second patch.
>
> Regression tested on Ubuntu 24 with the native, gdbserver and extended
> gdbserver targets.
>
> I appreciate your feedback.
>
> Thanks
> Stephan
>
> Rohr, Stephan (2):
> gdb: fix assertion when interrupting an empty remote target
> gdb, remote: Skip sending of 'vCont' package if remote target is empty
>
> gdb/infcmd.c | 5 +-
> gdb/remote.c | 4 ++
> .../interrupt-empty-remote-target.exp | 56 +++++++++++++++++++
> gdb/thread-iter.h | 3 +
> 4 files changed, 67 insertions(+), 1 deletion(-)
> create mode 100644 gdb/testsuite/gdb.server/interrupt-empty-remote-
> target.exp
>
> --
> 2.43.0
>
> ________________________________________
> Intel Deutschland GmbH
>
> Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
>
> Tel: +49 (89) 99143-0
>
> www.intel.de
>
> Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran
> Sitaraman
>
> Chairperson of the Supervisory Board: Sonja Pierer
>
> Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB
> 186928
>
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
________________________________________
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 (89) 99143-0
www.intel.de
Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
Chairperson of the Supervisory Board: Sonja Pierer
Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
^ permalink raw reply [flat|nested] 4+ messages in thread