public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Adjust/fix gdb.thread/pthreads.exp for Cygwin
@ 2023-09-20 17:59 Pedro Alves
  2023-09-20 17:59 ` [PATCH 1/5] gdb.threads/pthreads.c, K&R -> ANSI function style Pedro Alves
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Pedro Alves @ 2023-09-20 17:59 UTC (permalink / raw)
  To: gdb-patches

This set of patches improves gdb.thread/pthreads.exp when testing
against Cygwin.  The test still won't pass cleanly [1] without some GDB
fixes (which I plan on submitting later at some point), but if you run
it against the GDB distributed with Cygwin, at least, it passes (they
have some local GDB patches missing upstream).

[1] - it fails with:

 FAIL: gdb.threads/pthreads.exp: Stopped with a ^C (timeout)
 WARNING: Could not stop child with ^C; skipping rest of tests.

Pedro Alves (5):
  gdb.threads/pthreads.c, K&R -> ANSI function style
  Fix gdb.threads/pthreads.c formatting
  Fix gdb.threads/pthreads.exp error handling/printing
  In gdb.threads/pthreads.c, handle pthread_attr_setscope ENOTSUP
  Adjust gdb.thread/pthreads.exp for Cygwin

 gdb/testsuite/gdb.threads/pthreads.c   | 86 ++++++++++++++++----------
 gdb/testsuite/gdb.threads/pthreads.exp | 14 ++---
 2 files changed, 60 insertions(+), 40 deletions(-)


base-commit: 093da43d2adb4497dfec8afbb4eeaf2425668fdd
-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] gdb.threads/pthreads.c, K&R -> ANSI function style
  2023-09-20 17:59 [PATCH 0/5] Adjust/fix gdb.thread/pthreads.exp for Cygwin Pedro Alves
@ 2023-09-20 17:59 ` Pedro Alves
  2023-09-20 17:59 ` [PATCH 2/5] Fix gdb.threads/pthreads.c formatting Pedro Alves
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2023-09-20 17:59 UTC (permalink / raw)
  To: gdb-patches

gdb.threads/pthreads.c is declaring functions with old K&R style.
This commit converts them to ANSI style.

Change-Id: I1ce007c67bb4ab1e49248c014c7881e46634f8f8
---
 gdb/testsuite/gdb.threads/pthreads.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/gdb/testsuite/gdb.threads/pthreads.c b/gdb/testsuite/gdb.threads/pthreads.c
index fe1f89d0a23..7ec5604676f 100644
--- a/gdb/testsuite/gdb.threads/pthreads.c
+++ b/gdb/testsuite/gdb.threads/pthreads.c
@@ -27,8 +27,7 @@
 static int verbose = 0;
 
 static void
-common_routine (arg)
-     int arg;
+common_routine (int arg)
 {
   static int from_thread1;
   static int from_thread2;
@@ -90,8 +89,7 @@ thread2 (void * arg)
 }
 
 void
-foo (a, b, c)
-     int a, b, c;
+foo (int a, int b, int c)
 {
   int d, e, f;
 
@@ -99,9 +97,7 @@ foo (a, b, c)
 }
 
 int
-main(argc, argv)
-     int argc;
-     char **argv;
+main (int argc, char **argv)
 {
   pthread_t tid1, tid2;
   int j;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/5] Fix gdb.threads/pthreads.c formatting
  2023-09-20 17:59 [PATCH 0/5] Adjust/fix gdb.thread/pthreads.exp for Cygwin Pedro Alves
  2023-09-20 17:59 ` [PATCH 1/5] gdb.threads/pthreads.c, K&R -> ANSI function style Pedro Alves
@ 2023-09-20 17:59 ` Pedro Alves
  2023-09-20 17:59 ` [PATCH 3/5] Fix gdb.threads/pthreads.exp error handling/printing Pedro Alves
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2023-09-20 17:59 UTC (permalink / raw)
  To: gdb-patches

Just some GNU formatting fixes throughout.

Change-Id: Ie851e3815b839e57898263896db0ba8ddfefe09e
---
 gdb/testsuite/gdb.threads/pthreads.c | 45 +++++++++++++++++-----------
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/gdb/testsuite/gdb.threads/pthreads.c b/gdb/testsuite/gdb.threads/pthreads.c
index 7ec5604676f..e1593e980ea 100644
--- a/gdb/testsuite/gdb.threads/pthreads.c
+++ b/gdb/testsuite/gdb.threads/pthreads.c
@@ -35,7 +35,8 @@ common_routine (int arg)
   static int hits;
   static int full_coverage;
 
-  if (verbose) printf("common_routine (%d)\n", arg);
+  if (verbose)
+    printf ("common_routine (%d)\n", arg);
   hits++;
   switch (arg)
     {
@@ -59,13 +60,15 @@ thread1 (void *arg)
   int i;
   int z = 0;
 
-  if (verbose) printf ("thread1 (%0lx) ; pid = %d\n", (long) arg, getpid ());
-  for (i=1; i <= 10000000; i++)
+  if (verbose)
+    printf ("thread1 (%0lx) ; pid = %d\n", (long) arg, getpid ());
+  for (i = 1; i <= 10000000; i++)
     {
-      if (verbose) printf("thread1 %ld\n", (long) pthread_self ());
+      if (verbose)
+	printf ("thread1 %ld\n", (long) pthread_self ());
       z += i;
       common_routine (1);
-      sleep(1);
+      sleep (1);
     }
   return (void *) 0;
 }
@@ -76,15 +79,17 @@ thread2 (void * arg)
   int i;
   int k = 0;
 
-  if (verbose) printf ("thread2 (%0lx) ; pid = %d\n", (long) arg, getpid ());
-  for (i=1; i <= 10000000; i++)
+  if (verbose)
+    printf ("thread2 (%0lx) ; pid = %d\n", (long) arg, getpid ());
+  for (i = 1; i <= 10000000; i++)
     {
-      if (verbose) printf("thread2 %ld\n", (long) pthread_self ());
+      if (verbose)
+	printf ("thread2 %ld\n", (long) pthread_self ());
       k += i;
       common_routine (2);
-      sleep(1);
+      sleep (1);
     }
-  sleep(100);
+  sleep (100);
   return (void *) 0;
 }
 
@@ -93,7 +98,8 @@ foo (int a, int b, int c)
 {
   int d, e, f;
 
-  if (verbose) printf("a=%d\n", a);
+  if (verbose)
+    printf ("a=%d\n", a);
 }
 
 int
@@ -105,7 +111,8 @@ main (int argc, char **argv)
   void (*xxx) ();
   pthread_attr_t attr;
 
-  if (verbose) printf ("pid = %d\n", getpid());
+  if (verbose)
+    printf ("pid = %d\n", getpid ());
 
   foo (1, 2, 3);
 
@@ -128,7 +135,8 @@ main (int argc, char **argv)
       perror ("pthread_create 1");
       exit (1);
     }
-  if (verbose) printf ("Made thread %ld\n", (long) tid1);
+  if (verbose)
+    printf ("Made thread %ld\n", (long) tid1);
   sleep (1);
 
   if (pthread_create (&tid2, NULL, thread2, (void *) 0xdeadbeef))
@@ -136,18 +144,19 @@ main (int argc, char **argv)
       perror ("pthread_create 2");
       exit (1);
     }
-  if (verbose) printf("Made thread %ld\n", (long) tid2);
+  if (verbose)
+    printf ("Made thread %ld\n", (long) tid2);
 
   sleep (1);
 
   for (j = 1; j <= 10000000; j++)
     {
-      if (verbose) printf("top %ld\n", (long) pthread_self ());
+      if (verbose)
+	printf ("top %ld\n", (long) pthread_self ());
       common_routine (0);
-      sleep(1);
+      sleep (1);
       t += j;
     }
   
-  exit(0);
+  exit (0);
 }
-
-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/5] Fix gdb.threads/pthreads.exp error handling/printing
  2023-09-20 17:59 [PATCH 0/5] Adjust/fix gdb.thread/pthreads.exp for Cygwin Pedro Alves
  2023-09-20 17:59 ` [PATCH 1/5] gdb.threads/pthreads.c, K&R -> ANSI function style Pedro Alves
  2023-09-20 17:59 ` [PATCH 2/5] Fix gdb.threads/pthreads.c formatting Pedro Alves
@ 2023-09-20 17:59 ` Pedro Alves
  2023-09-20 17:59 ` [PATCH 4/5] In gdb.threads/pthreads.c, handle pthread_attr_setscope ENOTSUP Pedro Alves
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2023-09-20 17:59 UTC (permalink / raw)
  To: gdb-patches

On Cygwin, I noticed:

 (gdb) PASS: gdb.threads/pthreads.exp: break thread1
 continue
 Continuing.
 pthread_attr_setscope 1: No error
 [Thread 8732.0x28f8 exited with code 1]
 [Thread 8732.0xb50 exited with code 1]
 [Thread 8732.0x17f8 exited with code 1]

 Program terminated with signal SIGHUP, Hangup.
 The program no longer exists.
 (gdb) FAIL: gdb.threads/pthreads.exp: Continue to creation of first thread

Note "No error" in "pthread_attr_setscope 1: No error".  That is a bug
in the test.  It is using perror, but that prints errno, while the
pthread functions return the error directly.  Fix all cases of the
same problem, by adding a new print_error function and using it.

We now get:

  ...
  pthread_attr_setscope 1: Not supported (134)
  ...

Change-Id: I972ebc931b157bc0f9084e6ecd8916a5e39238f5
---
 gdb/testsuite/gdb.threads/pthreads.c | 30 ++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/gdb/testsuite/gdb.threads/pthreads.c b/gdb/testsuite/gdb.threads/pthreads.c
index e1593e980ea..547bf0fe3f0 100644
--- a/gdb/testsuite/gdb.threads/pthreads.c
+++ b/gdb/testsuite/gdb.threads/pthreads.c
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <pthread.h>
 #include <unistd.h>
+#include <string.h>
 
 static int verbose = 0;
 
@@ -102,6 +103,14 @@ foo (int a, int b, int c)
     printf ("a=%d\n", a);
 }
 
+/* Similar to perror, but use ERR instead of errno.  */
+
+static void
+print_error (const char *ctx, int err)
+{
+  fprintf (stderr, "%s: %s (%d)\n", ctx, strerror (err), err);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -110,38 +119,43 @@ main (int argc, char **argv)
   int t = 0;
   void (*xxx) ();
   pthread_attr_t attr;
+  int res;
 
   if (verbose)
     printf ("pid = %d\n", getpid ());
 
   foo (1, 2, 3);
 
-  if (pthread_attr_init (&attr))
+  res = pthread_attr_init (&attr);
+  if (res != 0)
     {
-      perror ("pthread_attr_init 1");
+      print_error ("pthread_attr_init 1", res);
       exit (1);
     }
 
 #ifdef PTHREAD_SCOPE_SYSTEM
-  if (pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM))
+  res = pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
+  if (res != 0)
     {
-      perror ("pthread_attr_setscope 1");
+      print_error ("pthread_attr_setscope 1", res);
       exit (1);
     }
 #endif
 
-  if (pthread_create (&tid1, &attr, thread1, (void *) 0xfeedface))
+  res = pthread_create (&tid1, &attr, thread1, (void *) 0xfeedface);
+  if (res != 0)
     {
-      perror ("pthread_create 1");
+      print_error ("pthread_create 1", res);
       exit (1);
     }
   if (verbose)
     printf ("Made thread %ld\n", (long) tid1);
   sleep (1);
 
-  if (pthread_create (&tid2, NULL, thread2, (void *) 0xdeadbeef))
+  res = pthread_create (&tid2, NULL, thread2, (void *) 0xdeadbeef);
+  if (res != 0)
     {
-      perror ("pthread_create 2");
+      print_error ("pthread_create 2", res);
       exit (1);
     }
   if (verbose)
-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/5] In gdb.threads/pthreads.c, handle pthread_attr_setscope ENOTSUP
  2023-09-20 17:59 [PATCH 0/5] Adjust/fix gdb.thread/pthreads.exp for Cygwin Pedro Alves
                   ` (2 preceding siblings ...)
  2023-09-20 17:59 ` [PATCH 3/5] Fix gdb.threads/pthreads.exp error handling/printing Pedro Alves
@ 2023-09-20 17:59 ` Pedro Alves
  2023-09-20 17:59 ` [PATCH 5/5] Adjust gdb.thread/pthreads.exp for Cygwin Pedro Alves
  2023-09-21 19:21 ` [PATCH 0/5] Adjust/fix " Tom Tromey
  5 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2023-09-20 17:59 UTC (permalink / raw)
  To: gdb-patches

On Cygwin, I see:

 (gdb) PASS: gdb.threads/pthreads.exp: break thread1
 continue
 Continuing.
 pthread_attr_setscope 1: Not supported (134)
 [Thread 3732.0x265c exited with code 1]
 [Thread 3732.0x2834 exited with code 1]
 [Thread 3732.0x2690 exited with code 1]

 Program terminated with signal SIGHUP, Hangup.
 The program no longer exists.
 (gdb) FAIL: gdb.threads/pthreads.exp: Continue to creation of first thread

 ... and then a set of cascading failures.

Fix this by treating ENOTSUP the same way as if PTHREAD_SCOPE_SYSTEM
were not defined.  I.e., ignore ENOTSUP errors, and proceed with
testing.

Change-Id: Iea68ff8b9937570726154f36610c48ef96101871
---
 gdb/testsuite/gdb.threads/pthreads.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.threads/pthreads.c b/gdb/testsuite/gdb.threads/pthreads.c
index 547bf0fe3f0..4b8b283b048 100644
--- a/gdb/testsuite/gdb.threads/pthreads.c
+++ b/gdb/testsuite/gdb.threads/pthreads.c
@@ -24,6 +24,7 @@
 #include <pthread.h>
 #include <unistd.h>
 #include <string.h>
+#include <errno.h>
 
 static int verbose = 0;
 
@@ -135,7 +136,7 @@ main (int argc, char **argv)
 
 #ifdef PTHREAD_SCOPE_SYSTEM
   res = pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
-  if (res != 0)
+  if (res != 0 && res != ENOTSUP)
     {
       print_error ("pthread_attr_setscope 1", res);
       exit (1);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 5/5] Adjust gdb.thread/pthreads.exp for Cygwin
  2023-09-20 17:59 [PATCH 0/5] Adjust/fix gdb.thread/pthreads.exp for Cygwin Pedro Alves
                   ` (3 preceding siblings ...)
  2023-09-20 17:59 ` [PATCH 4/5] In gdb.threads/pthreads.c, handle pthread_attr_setscope ENOTSUP Pedro Alves
@ 2023-09-20 17:59 ` Pedro Alves
  2023-09-21 19:21 ` [PATCH 0/5] Adjust/fix " Tom Tromey
  5 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2023-09-20 17:59 UTC (permalink / raw)
  To: gdb-patches

The Cygwin runtime spawns a few extra threads, so using hardcoded
thread numbers in tests rarely works correctly.  Thankfully, this
testcase already records the ids of the important threads in globals.
It just so happens that they are not used in a few tests.  This commit
fixes that.

With this, the test passes cleanly on Cygwin.  Still passes cleanly on
x86-64 GNU/Linux.

Change-Id: I01bf71fcb44ceddea8bd16b933b10b964749a6af
---
 gdb/testsuite/gdb.threads/pthreads.exp | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/gdb/testsuite/gdb.threads/pthreads.exp b/gdb/testsuite/gdb.threads/pthreads.exp
index 41a7cb3800f..122172a052b 100644
--- a/gdb/testsuite/gdb.threads/pthreads.exp
+++ b/gdb/testsuite/gdb.threads/pthreads.exp
@@ -274,21 +274,21 @@ proc check_qcs {} {
     set number "\[0-9]\+"
 
     # Check -c (continue) and -s (silently continue) flags.
-    gdb_test "thread apply 2-3 p notfound" \
+    gdb_test "thread apply $::thread1_id $::thread2_id p notfound" \
 	[multi_line \
 	     "" \
-	     "Thread 2 ${any}" \
+	     "Thread $::thread1_id ${any}" \
 	     "No symbol \\\"notfound\\\" in current context." \
 	    ] \
 	"run a failing command that aborts thread apply"
 
-    gdb_test "thread apply 2-3 -c p notfound" \
+    gdb_test "thread apply $::thread1_id $::thread2_id -c p notfound" \
 	[multi_line \
 	     "" \
-	     "Thread 2 ${any}" \
+	     "Thread $::thread1_id ${any}" \
 	     "No symbol \\\"notfound\\\" in current context." \
 	     "" \
-	     "Thread 3 ${any}" \
+	     "Thread $::thread2_id ${any}" \
 	     "No symbol \\\"notfound\\\" in current context." \
 	    ] \
 	"run a failing command, -c to continue"
@@ -302,11 +302,11 @@ proc check_qcs {} {
 		gdb_test $cmd \
 		    [multi_line \
 			 "" \
-			 "Thread 3 ${any}" \
+			 "Thread $::thread2_id ${any}" \
 			 "#${number}${ws}${any} in thread2 ${any}" \
 			 "\\\$\[0-9]+ = ${number}${any}" \
 			 "" \
-			 "Thread 2 ${any}" \
+			 "Thread $::thread1_id ${any}" \
 			 "#${number}${ws}${any} in thread1 ${any}" \
 			 "\\\$\[0-9]+ = ${number}${any}" \
 			] \
-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/5] Adjust/fix gdb.thread/pthreads.exp for Cygwin
  2023-09-20 17:59 [PATCH 0/5] Adjust/fix gdb.thread/pthreads.exp for Cygwin Pedro Alves
                   ` (4 preceding siblings ...)
  2023-09-20 17:59 ` [PATCH 5/5] Adjust gdb.thread/pthreads.exp for Cygwin Pedro Alves
@ 2023-09-21 19:21 ` Tom Tromey
  5 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2023-09-21 19:21 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:

Pedro> This set of patches improves gdb.thread/pthreads.exp when testing
Pedro> against Cygwin.  The test still won't pass cleanly [1] without some GDB
Pedro> fixes (which I plan on submitting later at some point), but if you run
Pedro> it against the GDB distributed with Cygwin, at least, it passes (they
Pedro> have some local GDB patches missing upstream).

This all seems fine to me.  Thank you.
Approved-By: Tom Tromey <tom@tromey.com>

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-09-21 19:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-20 17:59 [PATCH 0/5] Adjust/fix gdb.thread/pthreads.exp for Cygwin Pedro Alves
2023-09-20 17:59 ` [PATCH 1/5] gdb.threads/pthreads.c, K&R -> ANSI function style Pedro Alves
2023-09-20 17:59 ` [PATCH 2/5] Fix gdb.threads/pthreads.c formatting Pedro Alves
2023-09-20 17:59 ` [PATCH 3/5] Fix gdb.threads/pthreads.exp error handling/printing Pedro Alves
2023-09-20 17:59 ` [PATCH 4/5] In gdb.threads/pthreads.c, handle pthread_attr_setscope ENOTSUP Pedro Alves
2023-09-20 17:59 ` [PATCH 5/5] Adjust gdb.thread/pthreads.exp for Cygwin Pedro Alves
2023-09-21 19:21 ` [PATCH 0/5] Adjust/fix " Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).