Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>,
	Tankut Baris Aktemur <Tankut.Aktemur@amd.com>
Subject: [PATCH 4/7] gdb/testsuite: fix step-over-thread-exit.exp with native-gdbserver
Date: Wed,  6 May 2026 16:27:52 -0400	[thread overview]
Message-ID: <20260506202804.1681886-5-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260506202804.1681886-1-simon.marchi@polymtl.ca>

From: Simon Marchi <simon.marchi@polymtl.ca>

This test uses "set args N" to control how many threads the inferior
spawns: 1 in some cases and 100 in others.  However, "set args" doesn't
work with the native-gdbserver board.  As a result, with that board, the
inferior always uses its default of 100 threads.  It sometimes causes
failures like:

    p $_thread == 2
    $1 = 1
    (gdb) [New Thread 2790806.2790823 (id 3)]

    Thread 3 "step-over-threa" hit Breakpoint 2, 0x00005555555552ab in my_exit_syscall () at /.../testsuite/lib/my-syscalls.S:85
    85      SYSCALL (my_exit, __NR_exit)
    FAIL: gdb.threads/step-over-thread-exit.exp: step_over_mode=inline: non-stop=on: target-non-stop=on: schedlock=off: cmd=next: ns_stop_all=0: selected thread didn't change (timeout)

Here, GDB steps over thread 2's exit.  As soon as thread 2 exits, the
main thread spawns a new thread (thread 3), which hits the breakpoint
placed over the exit syscall, and that event gets reported
asynchronously, confusing the testsuite.  The point of setting n_threads
to 1 is exactly to avoid things like that.

Fix it by passing the args via the new -inferior-args option, which
works correctly with the native-gdbserver board.

Change the test program to requiring the number of threads to be passed
as an argument, which would have caught this problem.

Change-Id: Ifc8856aa582706fd7207d0035d35dee749eb83a5
Reported-By: Tankut Baris Aktemur <Tankut.Aktemur@amd.com>
---
 gdb/testsuite/gdb.threads/step-over-thread-exit.c | 15 ++++++++++-----
 .../gdb.threads/step-over-thread-exit.exp         |  8 ++------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/gdb/testsuite/gdb.threads/step-over-thread-exit.c b/gdb/testsuite/gdb.threads/step-over-thread-exit.c
index 6cda1a4f1b0b..e52de2910a7a 100644
--- a/gdb/testsuite/gdb.threads/step-over-thread-exit.c
+++ b/gdb/testsuite/gdb.threads/step-over-thread-exit.c
@@ -31,16 +31,21 @@ thread_func (void *arg)
   abort ();
 }
 
-/* Number of threads we'll create.  */
-int n_threads = 100;
-
 int
 main (int argc, char **argv)
 {
   int i;
 
-  if (argc > 1)
-    n_threads = atoi (argv[1]);
+  /* Number of threads we'll create.  Set from argv[1].  */
+  int n_threads;
+
+  if (argc != 2)
+    {
+      fprintf (stderr, "Usage: %s N_THREADS\n", argv[0]);
+      return 1;
+    }
+
+  n_threads = atoi (argv[1]);
 
   /* Spawn and join a thread, N_THREADS times.  */
   for (i = 0; i < n_threads; i++)
diff --git a/gdb/testsuite/gdb.threads/step-over-thread-exit.exp b/gdb/testsuite/gdb.threads/step-over-thread-exit.exp
index f398538058d4..aeca985dec0d 100644
--- a/gdb/testsuite/gdb.threads/step-over-thread-exit.exp
+++ b/gdb/testsuite/gdb.threads/step-over-thread-exit.exp
@@ -71,9 +71,7 @@ proc test {step_over_mode non-stop target-non-stop schedlock cmd ns_stop_all} {
     if {$schedlock
 	|| (${non-stop} == "on" && $ns_stop_all)} {
 
-	gdb_test_no_output "set args 1"
-
-	if { ![runto my_exit_syscall] } {
+	if { ![runto my_exit_syscall -inferior-args 1] } {
 	    return
 	}
 
@@ -148,9 +146,7 @@ proc test {step_over_mode non-stop target-non-stop schedlock cmd ns_stop_all} {
 	    set n_threads 100
 	}
 
-	gdb_test_no_output "set args $n_threads"
-
-	if { ![runto_main] } {
+	if { ![runto_main -inferior-args $n_threads] } {
 	    return
 	}
 
-- 
2.54.0


  parent reply	other threads:[~2026-05-06 20:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06 20:27 [PATCH 0/7] gdb/testsuite: allow passing inferior arguments with native-gdbserver board simon.marchi
2026-05-06 20:27 ` [PATCH 1/7] gdb/testsuite: remove unused arguments to gdb_breakpoint simon.marchi
2026-05-06 20:27 ` [PATCH 2/7] gdb/testsuite: make gdb_breakpoint, runto and runto_main use parse_args simon.marchi
2026-05-06 20:27 ` [PATCH 3/7] gdb/testsuite: add -inferior-args option to runto simon.marchi
2026-05-12 13:02   ` Aktemur, Baris
2026-06-19 19:29     ` Simon Marchi
2026-06-19 19:54       ` Simon Marchi
2026-05-06 20:27 ` simon.marchi [this message]
2026-05-12 13:06   ` [PATCH 4/7] gdb/testsuite: fix step-over-thread-exit.exp with native-gdbserver Aktemur, Baris
2026-06-19 19:31     ` Simon Marchi
2026-05-06 20:27 ` [PATCH 5/7] gdb/testsuite: make pie-execl.exp work " simon.marchi
2026-05-06 20:27 ` [PATCH 6/7] gdb/testsuite: use -inferior-args in gdb.base/gcore-buffer-overflow.exp simon.marchi
2026-05-06 20:27 ` [PATCH 7/7] gdb/testsuite: fix gdb.rocm/code-object-load-while-breakpoint-hit.exp with native-gdbserver simon.marchi
2026-05-12 13:18 ` [PATCH 0/7] gdb/testsuite: allow passing inferior arguments with native-gdbserver board Aktemur, Baris
2026-06-15  9:54   ` Aktemur, Baris
2026-06-19 20:09     ` Simon Marchi

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=20260506202804.1681886-5-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=Tankut.Aktemur@amd.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