|
|
a8223e |
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
|
|
|
a8223e |
From: Fedora GDB patches <invalid@email.com>
|
|
|
a8223e |
Date: Fri, 27 Oct 2017 21:07:50 +0200
|
|
|
a8223e |
Subject: gdb-6.8-bz442765-threaded-exec-test.patch
|
|
|
a8223e |
|
|
|
a8223e |
;; Test various forms of threads tracking across exec() (BZ 442765).
|
|
|
a8223e |
;;=fedoratest
|
|
|
a8223e |
|
|
|
a8223e |
Test various forms of threads tracking across exec(2).
|
|
|
a8223e |
|
|
|
a8223e |
diff --git a/gdb/testsuite/gdb.threads/threaded-exec.c b/gdb/testsuite/gdb.threads/threaded-exec.c
|
|
|
a8223e |
--- a/gdb/testsuite/gdb.threads/threaded-exec.c
|
|
|
a8223e |
+++ b/gdb/testsuite/gdb.threads/threaded-exec.c
|
|
|
a8223e |
@@ -18,21 +18,95 @@
|
|
|
a8223e |
Boston, MA 02111-1307, USA. */
|
|
|
a8223e |
|
|
|
a8223e |
#include <stddef.h>
|
|
|
a8223e |
-#include <pthread.h>
|
|
|
a8223e |
#include <assert.h>
|
|
|
a8223e |
#include <stdlib.h>
|
|
|
a8223e |
#include <unistd.h>
|
|
|
a8223e |
+#include <stdio.h>
|
|
|
a8223e |
|
|
|
a8223e |
+#ifdef THREADS
|
|
|
a8223e |
+
|
|
|
a8223e |
+# include <pthread.h>
|
|
|
a8223e |
|
|
|
a8223e |
static void *
|
|
|
a8223e |
threader (void *arg)
|
|
|
a8223e |
{
|
|
|
a8223e |
- return NULL;
|
|
|
a8223e |
+ return NULL;
|
|
|
a8223e |
}
|
|
|
a8223e |
|
|
|
a8223e |
+#endif
|
|
|
a8223e |
+
|
|
|
a8223e |
int
|
|
|
a8223e |
-main (void)
|
|
|
a8223e |
+main (int argc, char **argv)
|
|
|
a8223e |
{
|
|
|
a8223e |
+ char *exec_nothreads, *exec_threads, *cmd;
|
|
|
a8223e |
+ int phase;
|
|
|
a8223e |
+ char phase_s[8];
|
|
|
a8223e |
+
|
|
|
a8223e |
+ setbuf (stdout, NULL);
|
|
|
a8223e |
+
|
|
|
a8223e |
+ if (argc != 4)
|
|
|
a8223e |
+ {
|
|
|
a8223e |
+ fprintf (stderr, "%s <non-threaded> <threaded> <phase>\n", argv[0]);
|
|
|
a8223e |
+ return 1;
|
|
|
a8223e |
+ }
|
|
|
a8223e |
+
|
|
|
a8223e |
+#ifdef THREADS
|
|
|
a8223e |
+ puts ("THREADS: Y");
|
|
|
a8223e |
+#else
|
|
|
a8223e |
+ puts ("THREADS: N");
|
|
|
a8223e |
+#endif
|
|
|
a8223e |
+ exec_nothreads = argv[1];
|
|
|
a8223e |
+ printf ("exec_nothreads: %s\n", exec_nothreads);
|
|
|
a8223e |
+ exec_threads = argv[2];
|
|
|
a8223e |
+ printf ("exec_threads: %s\n", exec_threads);
|
|
|
a8223e |
+ phase = atoi (argv[3]);
|
|
|
a8223e |
+ printf ("phase: %d\n", phase);
|
|
|
a8223e |
+
|
|
|
a8223e |
+ /* Phases: threading
|
|
|
a8223e |
+ 0: N -> N
|
|
|
a8223e |
+ 1: N -> Y
|
|
|
a8223e |
+ 2: Y -> Y
|
|
|
a8223e |
+ 3: Y -> N
|
|
|
a8223e |
+ 4: N -> exit */
|
|
|
a8223e |
+
|
|
|
a8223e |
+ cmd = NULL;
|
|
|
a8223e |
+
|
|
|
a8223e |
+#ifndef THREADS
|
|
|
a8223e |
+ switch (phase)
|
|
|
a8223e |
+ {
|
|
|
a8223e |
+ case 0:
|
|
|
a8223e |
+ cmd = exec_nothreads;
|
|
|
a8223e |
+ break;
|
|
|
a8223e |
+ case 1:
|
|
|
a8223e |
+ cmd = exec_threads;
|
|
|
a8223e |
+ break;
|
|
|
a8223e |
+ case 2:
|
|
|
a8223e |
+ fprintf (stderr, "%s: We should have threads for phase %d!\n", argv[0],
|
|
|
a8223e |
+ phase);
|
|
|
a8223e |
+ return 1;
|
|
|
a8223e |
+ case 3:
|
|
|
a8223e |
+ fprintf (stderr, "%s: We should have threads for phase %d!\n", argv[0],
|
|
|
a8223e |
+ phase);
|
|
|
a8223e |
+ return 1;
|
|
|
a8223e |
+ case 4:
|
|
|
a8223e |
+ return 0;
|
|
|
a8223e |
+ default:
|
|
|
a8223e |
+ assert (0);
|
|
|
a8223e |
+ }
|
|
|
a8223e |
+#else /* THREADS */
|
|
|
a8223e |
+ switch (phase)
|
|
|
a8223e |
+ {
|
|
|
a8223e |
+ case 0:
|
|
|
a8223e |
+ fprintf (stderr, "%s: We should not have threads for phase %d!\n",
|
|
|
a8223e |
+ argv[0], phase);
|
|
|
a8223e |
+ return 1;
|
|
|
a8223e |
+ case 1:
|
|
|
a8223e |
+ fprintf (stderr, "%s: We should not have threads for phase %d!\n",
|
|
|
a8223e |
+ argv[0], phase);
|
|
|
a8223e |
+ return 1;
|
|
|
a8223e |
+ case 2:
|
|
|
a8223e |
+ cmd = exec_threads;
|
|
|
a8223e |
+ {
|
|
|
a8223e |
pthread_t t1;
|
|
|
a8223e |
int i;
|
|
|
a8223e |
|
|
|
a8223e |
@@ -40,7 +114,34 @@
|
|
|
a8223e |
assert (i == 0);
|
|
|
a8223e |
i = pthread_join (t1, NULL);
|
|
|
a8223e |
assert (i == 0);
|
|
|
a8223e |
+ }
|
|
|
a8223e |
+ break;
|
|
|
a8223e |
+ case 3:
|
|
|
a8223e |
+ cmd = exec_nothreads;
|
|
|
a8223e |
+ {
|
|
|
a8223e |
+ pthread_t t1;
|
|
|
a8223e |
+ int i;
|
|
|
a8223e |
+
|
|
|
a8223e |
+ i = pthread_create (&t1, NULL, threader, (void *) NULL);
|
|
|
a8223e |
+ assert (i == 0);
|
|
|
a8223e |
+ i = pthread_join (t1, NULL);
|
|
|
a8223e |
+ assert (i == 0);
|
|
|
a8223e |
+ }
|
|
|
a8223e |
+ break;
|
|
|
a8223e |
+ case 4:
|
|
|
a8223e |
+ fprintf (stderr, "%s: We should not have threads for phase %d!\n",
|
|
|
a8223e |
+ argv[0], phase);
|
|
|
a8223e |
+ return 1;
|
|
|
a8223e |
+ default:
|
|
|
a8223e |
+ assert (0);
|
|
|
a8223e |
+ }
|
|
|
a8223e |
+#endif /* THREADS */
|
|
|
a8223e |
+
|
|
|
a8223e |
+ assert (cmd != NULL);
|
|
|
a8223e |
+
|
|
|
a8223e |
+ phase++;
|
|
|
a8223e |
+ snprintf (phase_s, sizeof phase_s, "%d", phase);
|
|
|
a8223e |
|
|
|
a8223e |
- execl ("/bin/true", "/bin/true", NULL);
|
|
|
a8223e |
- abort ();
|
|
|
a8223e |
+ execl (cmd, cmd, exec_nothreads, exec_threads, phase_s, NULL);
|
|
|
a8223e |
+ assert (0);
|
|
|
a8223e |
}
|
|
|
a8223e |
diff --git a/gdb/testsuite/gdb.threads/threaded-exec.exp b/gdb/testsuite/gdb.threads/threaded-exec.exp
|
|
|
a8223e |
--- a/gdb/testsuite/gdb.threads/threaded-exec.exp
|
|
|
a8223e |
+++ b/gdb/testsuite/gdb.threads/threaded-exec.exp
|
|
|
a8223e |
@@ -20,9 +20,14 @@
|
|
|
a8223e |
|
|
|
a8223e |
set testfile threaded-exec
|
|
|
a8223e |
set srcfile ${testfile}.c
|
|
|
a8223e |
-set binfile [standard_output_file ${testfile}]
|
|
|
a8223e |
+set binfile_nothreads [standard_output_file ${testfile}N]
|
|
|
a8223e |
+set binfile_threads [standard_output_file ${testfile}Y]
|
|
|
a8223e |
|
|
|
a8223e |
-if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } {
|
|
|
a8223e |
+if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile_nothreads}" executable {additional_flags=-UTHREADS}] != "" } {
|
|
|
a8223e |
+ return -1
|
|
|
a8223e |
+}
|
|
|
a8223e |
+
|
|
|
a8223e |
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile_threads}" executable {additional_flags=-DTHREADS}] != "" } {
|
|
|
a8223e |
return -1
|
|
|
a8223e |
}
|
|
|
a8223e |
|
|
|
a8223e |
@@ -30,9 +35,9 @@ gdb_exit
|
|
|
a8223e |
gdb_start
|
|
|
a8223e |
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
a8223e |
|
|
|
a8223e |
-gdb_load ${binfile}
|
|
|
a8223e |
+gdb_load ${binfile_nothreads}
|
|
|
a8223e |
|
|
|
a8223e |
-gdb_run_cmd
|
|
|
a8223e |
+gdb_run_cmd [list ${binfile_nothreads} ${binfile_threads} 0]
|
|
|
a8223e |
|
|
|
a8223e |
gdb_test_multiple {} "Program exited" {
|
|
|
a8223e |
-re "\r\n\\\[Inferior .* exited normally\\\]\r\n$gdb_prompt $" {
|