Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Markus Metzger <markus.t.metzger@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v4 29/44] gdb, remote: allow deleting the last thread in inferior in update_thread_list()
Date: Wed, 12 Aug 2026 15:27:49 +0200	[thread overview]
Message-ID: <20260812132805.380163-30-markus.t.metzger@intel.com> (raw)
In-Reply-To: <20260812132805.380163-1-markus.t.metzger@intel.com>

We do want to support inferiors without threads, e.g. for GPU inferiors
that may not have any thread when no work is dispatched to that GPU but
that may get new threads again when new work is dispatched.

The test (added in a subsequent patch)

    gdb.arch/intelgt-interrupt-exited-thread.exp

resumes a single GPU thread with scheduler-locking on and then interrupts
the target with C-c.  The GPU thread meanwhile finished its dispatch, so
when the target interrupts the device, it does not respond.

In response to vCtrlC, gdbserver-intelgt sends

    %Stop:N

to indicate that nothing is running on the device anymore.  GDB receives
the notification.  In handle_no_resumed(), GDB updates the thread list.
In this scenario, the thread that GDB had resumed was the last thread on
the device, so the thread list is now empty.  If we're not deleting that
thread, handle_no_resumed() will ignore the event since it found a resumed
thread, and we're stuck.

To the user, it would appear as if GDB were hanging.  Interrupting the
target with C-c does not have any effect and there is no way to get the
prompt back.

This patch causes regressions in

    gdb.replay/missing.thread.exp

When the replay log is updated to remove all threads like this

    w $qXfer:threads:read::0,1000#92
    r $l<threads>\n</threads>\n#68<Timeout: 0 seconds>

GDB removes the thread and no longer interacts with it, so replay fails at
the subsequent

    w $QThreadOptions;0#00
    r $OK#9a<Timeout: 0 seconds>

This patch removes that part of the test.
---
 gdb/remote.c                                | 20 ---------------
 gdb/testsuite/gdb.replay/missing-thread.exp | 28 +++------------------
 2 files changed, 3 insertions(+), 45 deletions(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index 5721e791612..10bceb2c798 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4479,18 +4479,6 @@ remote_target::remote_get_threads_with_qthreadinfo (threads_listing_context *con
   return 0;
 }
 
-/* Return true if INF only has one non-exited thread.  */
-
-static bool
-has_single_non_exited_thread (inferior *inf)
-{
-  int count = 0;
-  for (thread_info &tp ATTRIBUTE_UNUSED : inf->non_exited_threads ())
-    if (++count > 1)
-      break;
-  return count == 1;
-}
-
 /* Implement the to_update_thread_list function for the remote
    targets.  */
 
@@ -4526,14 +4514,6 @@ remote_target::update_thread_list ()
       for (thread_info &tp : all_threads_safe (this))
 	if (!context.contains_thread (tp.ptid))
 	  {
-	    /* Do not remove the thread if it is the last thread in
-	       the inferior.  This situation happens when we have a
-	       pending exit process status to process.  Otherwise we
-	       may end up with a seemingly live inferior (i.e.  pid
-	       != 0) that has no threads.  */
-	    if (has_single_non_exited_thread (tp.inf))
-	      continue;
-
 	    /* Do not remove the thread if we've requested to be
 	       notified of its exit.  For example, the thread may be
 	       displaced stepping, infrun will need to handle the
diff --git a/gdb/testsuite/gdb.replay/missing-thread.exp b/gdb/testsuite/gdb.replay/missing-thread.exp
index 23bbddac556..a27a0181c7f 100644
--- a/gdb/testsuite/gdb.replay/missing-thread.exp
+++ b/gdb/testsuite/gdb.replay/missing-thread.exp
@@ -83,10 +83,7 @@ proc_with_prefix record_initial_logfile { log_filename } {
 # The line to be modified is the last <threads>...</threads> line, this is
 # the reply from the remote that indicates the thread list.  It is expected
 # that the thread list will contain two threads.
-#
-# When DROP_BOTH is true then both threads will be removed from the modified
-# line.  Otherwise, only the second thread is removed.
-proc update_replay_log { in_filename out_filename drop_both } {
+proc update_replay_log { in_filename out_filename } {
     # Read IN_FILENAME into a list.
     set fd [open $in_filename]
     set data [read $fd]
@@ -108,11 +105,7 @@ proc update_replay_log { in_filename out_filename drop_both } {
     set fixed_log false
     if {[regexp "^(r .*<threads>\\\\n)(<thread id.*/>\\\\n)(<thread id.*/>\\\\n)(</threads>.*)$" $line \
 	     match part1 part2 part3 part4]} {
-	if { $drop_both } {
-	    set line $part1$part4
-	} else {
-	    set line $part1$part2$part4
-	}
+	set line $part1$part2$part4
 	set lines [lreplace $lines $idx $idx $line]
 	set fixed_log true
     }
@@ -192,18 +185,13 @@ proc run_test { non_stop } {
     # The replay log is placed in 'replay.log'.
     set remote_log [standard_output_file replay${suffix}.log]
     set missing_1_log [standard_output_file replay-missing-1${suffix}.log]
-    set missing_2_log [standard_output_file replay-missing-2${suffix}.log]
 
     record_initial_logfile $remote_log
 
-    if { ![update_replay_log $remote_log $missing_1_log false] } {
+    if { ![update_replay_log $remote_log $missing_1_log] } {
 	fail "couldn't update remote replay log (drop 1 case)"
     }
 
-    if { ![update_replay_log $remote_log $missing_2_log true] } {
-	fail "couldn't update remote replay log (drop 2 case)"
-    }
-
     with_test_prefix "with unmodified log" {
 	# Replay with the unmodified log.  This confirms that we can replay this
 	# scenario correctly.
@@ -216,16 +204,6 @@ proc run_test { non_stop } {
 	# error when the inferior stops.
 	replay_with_log $missing_1_log true $non_stop
     }
-
-    with_test_prefix "missing 2 threads log" {
-	# When we drop both threads from the <threads> reply, GDB doesn't
-	# actually remove both threads from the inferior; an inferior must
-	# always have at least one thread.  So in this case, as the primary
-	# thread is first, GDB drops this, then retains the second thread, which
-	# is the one we're stopping in, and so, we don't expect to see the error
-	# in this case.
-	replay_with_log $missing_2_log false $non_stop
-    }
 }
 
 # Run the test twice, with non-stop on and off.
-- 
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.


  parent reply	other threads:[~2026-08-12 13:35 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12 13:27 [PATCH v4 00/44] A new target to debug Intel GPUs Markus Metzger
2026-08-12 13:27 ` [PATCH v4 01/44] bfd: add intelgt target to BFD Markus Metzger
2026-08-12 13:27 ` [PATCH v4 02/44] opcodes: add intelgt as a configuration Markus Metzger
2026-08-12 13:27 ` [PATCH v4 03/44] gdbserver: allow configuring for a heterogeneous target Markus Metzger
2026-08-12 13:27 ` [PATCH v4 04/44] config.sub: recognize level-zero as "ze" Markus Metzger
2026-08-12 13:27 ` [PATCH v4 05/44] gdbserver: import AC_LIB_HAVE_LINKFLAGS macro into the autoconf script Markus Metzger
2026-08-12 13:27 ` [PATCH v4 06/44] gdb, gdbserver, gdbsupport: add 'device' tag to XML target description Markus Metzger
2026-08-12 13:27 ` [PATCH v4 07/44] gdb, arch, intelgt: add intelgt arch definitions Markus Metzger
2026-08-12 13:27 ` [PATCH v4 08/44] gdb: add a new extract_integer variant that takes two array_views Markus Metzger
2026-08-12 13:27 ` [PATCH v4 09/44] gdb, intelgt: add the target-dependent definitions for the Intel GT architecture Markus Metzger
2026-08-12 13:27 ` [PATCH v4 10/44] gdb, intelgt: add disassemble feature " Markus Metzger
2026-08-12 13:27 ` [PATCH v4 11/44] gdb: revise the pid_to_exec_file target op Markus Metzger
2026-08-12 13:27 ` [PATCH v4 12/44] gdb, remote: do 'remote_add_inferior' in 'remote_notice_new_inferior' earlier Markus Metzger
2026-08-12 13:27 ` [PATCH v4 13/44] gdbserver: move dlls_changed initialization on attach into targets Markus Metzger
2026-08-12 13:27 ` [PATCH v4 14/44] gdbserver: adjust pid after the target attaches Markus Metzger
2026-08-12 13:27 ` [PATCH v4 15/44] gdbserver: check process when we need a process Markus Metzger
2026-08-12 13:27 ` [PATCH v4 16/44] gdb: use process in xfer_partial if inferior_ptid is null_ptid Markus Metzger
2026-08-12 13:27 ` [PATCH v4 17/44] gdb: allow inferiors without threads in all_matching_threads_iterator Markus Metzger
2026-08-12 13:27 ` [PATCH v4 18/44] gdbserver: improve threads debug output for process general thread Markus Metzger
2026-08-12 13:27 ` [PATCH v4 19/44] gdb, gdbserver: allow setting null_ptid as " Markus Metzger
2026-08-12 13:27 ` [PATCH v4 20/44] gdbserver: allow inferiors without threads Markus Metzger
2026-08-12 13:27 ` [PATCH v4 21/44] gdb: allow creating and attaching to " Markus Metzger
2026-08-12 13:27 ` [PATCH v4 22/44] gdb, remote: don't create an inferior on attach Markus Metzger
2026-08-12 13:27 ` [PATCH v4 23/44] gdb: allow switching to an inferior without threads Markus Metzger
2026-08-12 13:27 ` [PATCH v4 24/44] gdb: allow resuming an inferior with no threads Markus Metzger
2026-08-12 13:27 ` [PATCH v4 25/44] gdb: allow continuing an inferior without threads Markus Metzger
2026-08-12 13:27 ` [PATCH v4 26/44] gdb: partially fix C-c not working Markus Metzger
2026-08-12 13:27 ` [PATCH v4 27/44] gdb, linux-nat: use current_inferior()->pid in mourn_inferior() Markus Metzger
2026-08-12 13:27 ` [PATCH v4 28/44] gdb: inferior events Markus Metzger
2026-08-12 13:27 ` Markus Metzger [this message]
2026-08-12 13:27 ` [PATCH v4 30/44] gdb: keep target registered in inferior_event_handler() Markus Metzger
2026-08-12 13:27 ` [PATCH v4 31/44] gdb, dwarf, ze: add DW_OP_INTEL_regval_bits Markus Metzger
2026-08-12 13:27 ` [PATCH v4 32/44] gdbserver: add a pointer to the owner thread in regcache Markus Metzger
2026-08-12 13:27 ` [PATCH v4 33/44] gdb, gdbserver, ze: in-memory libraries Markus Metzger
2026-08-12 13:27 ` [PATCH v4 34/44] gdb, gdbserver: library notifications Markus Metzger
2026-08-12 13:27 ` [PATCH v4 35/44] gdbserver, ze, intelgt: introduce ze-low and intelgt-ze-low targets Markus Metzger
2026-08-12 13:27 ` [PATCH v4 36/44] testsuite, sycl: add SYCL support Markus Metzger
2026-08-12 13:27 ` [PATCH v4 37/44] testsuite, sycl: add test for backtracing inside a kernel Markus Metzger
2026-08-12 13:27 ` [PATCH v4 38/44] testsuite, sycl: add test for 'info locals' and 'info args' Markus Metzger
2026-08-12 13:27 ` [PATCH v4 39/44] testsuite, sycl: add tests for stepping Markus Metzger
2026-08-12 13:28 ` [PATCH v4 40/44] testsuite, sycl: add test for 1-D and 2-D parallel_for kernels Markus Metzger
2026-08-12 13:28 ` [PATCH v4 41/44] testsuite, sycl: add test for scheduler-locking Markus Metzger
2026-08-12 13:28 ` [PATCH v4 42/44] testsuite, arch, intelgt: add a disassembly test Markus Metzger
2026-08-12 13:28 ` [PATCH v4 43/44] testsuite, arch, intelgt: add intelgt-program-bp.exp Markus Metzger
2026-08-12 13:28 ` [PATCH v4 44/44] testsuite, intelgt: add a test for interrupting an exited thread Markus Metzger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260812132805.380163-30-markus.t.metzger@intel.com \
    --to=markus.t.metzger@intel.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox