Blame SOURCES/gdb-6.8-bz442765-threaded-exec-test.patch

7a6771
Test various forms of threads tracking across exec(2).
7a6771
7a6771
Index: gdb-7.10.90.20160211/gdb/testsuite/gdb.threads/threaded-exec.c
7a6771
===================================================================
7a6771
--- gdb-7.10.90.20160211.orig/gdb/testsuite/gdb.threads/threaded-exec.c	2016-02-16 09:54:45.157163049 +0100
7a6771
+++ gdb-7.10.90.20160211/gdb/testsuite/gdb.threads/threaded-exec.c	2016-02-16 09:54:46.210170175 +0100
7a6771
@@ -18,21 +18,95 @@
7a6771
    Boston, MA 02111-1307, USA.  */
7a6771
 
7a6771
 #include <stddef.h>
7a6771
-#include <pthread.h>
7a6771
 #include <assert.h>
7a6771
 #include <stdlib.h>
7a6771
 #include <unistd.h>
7a6771
+#include <stdio.h>
7a6771
 
7a6771
+#ifdef THREADS
7a6771
+
7a6771
+# include <pthread.h>
7a6771
 
7a6771
 static void *
7a6771
 threader (void *arg)
7a6771
 {
7a6771
-	return NULL;
7a6771
+  return NULL;
7a6771
 }
7a6771
 
7a6771
+#endif
7a6771
+
7a6771
 int
7a6771
-main (void)
7a6771
+main (int argc, char **argv)
7a6771
 {
7a6771
+  char *exec_nothreads, *exec_threads, *cmd;
7a6771
+  int phase;
7a6771
+  char phase_s[8];
7a6771
+
7a6771
+  setbuf (stdout, NULL);
7a6771
+
7a6771
+  if (argc != 4)
7a6771
+    {
7a6771
+      fprintf (stderr, "%s <non-threaded> <threaded> <phase>\n", argv[0]);
7a6771
+      return 1;
7a6771
+    }
7a6771
+
7a6771
+#ifdef THREADS
7a6771
+  puts ("THREADS: Y");
7a6771
+#else
7a6771
+  puts ("THREADS: N");
7a6771
+#endif
7a6771
+  exec_nothreads = argv[1];
7a6771
+  printf ("exec_nothreads: %s\n", exec_nothreads);
7a6771
+  exec_threads = argv[2];
7a6771
+  printf ("exec_threads: %s\n", exec_threads);
7a6771
+  phase = atoi (argv[3]);
7a6771
+  printf ("phase: %d\n", phase);
7a6771
+
7a6771
+  /* Phases: threading
7a6771
+     0: N -> N
7a6771
+     1: N -> Y
7a6771
+     2: Y -> Y
7a6771
+     3: Y -> N
7a6771
+     4: N -> exit  */
7a6771
+
7a6771
+  cmd = NULL;
7a6771
+
7a6771
+#ifndef THREADS
7a6771
+  switch (phase)
7a6771
+    {
7a6771
+    case 0:
7a6771
+      cmd = exec_nothreads;
7a6771
+      break;
7a6771
+    case 1:
7a6771
+      cmd = exec_threads;
7a6771
+      break;
7a6771
+    case 2:
7a6771
+      fprintf (stderr, "%s: We should have threads for phase %d!\n", argv[0],
7a6771
+	       phase);
7a6771
+      return 1;
7a6771
+    case 3:
7a6771
+      fprintf (stderr, "%s: We should have threads for phase %d!\n", argv[0],
7a6771
+	       phase);
7a6771
+      return 1;
7a6771
+    case 4:
7a6771
+      return 0;
7a6771
+    default:
7a6771
+      assert (0);
7a6771
+    }
7a6771
+#else	/* THREADS */
7a6771
+  switch (phase)
7a6771
+    {
7a6771
+    case 0:
7a6771
+      fprintf (stderr, "%s: We should not have threads for phase %d!\n",
7a6771
+	       argv[0], phase);
7a6771
+      return 1;
7a6771
+    case 1:
7a6771
+      fprintf (stderr, "%s: We should not have threads for phase %d!\n",
7a6771
+	       argv[0], phase);
7a6771
+      return 1;
7a6771
+    case 2:
7a6771
+      cmd = exec_threads;
7a6771
+      {
7a6771
 	pthread_t t1;
7a6771
 	int i;
7a6771
 
7a6771
@@ -40,7 +114,34 @@
7a6771
 	assert (i == 0);
7a6771
 	i = pthread_join (t1, NULL);
7a6771
 	assert (i == 0);
7a6771
+      }
7a6771
+      break;
7a6771
+    case 3:
7a6771
+      cmd = exec_nothreads;
7a6771
+      {
7a6771
+	pthread_t t1;
7a6771
+	int i;
7a6771
+
7a6771
+	i = pthread_create (&t1, NULL, threader, (void *) NULL);
7a6771
+	assert (i == 0);
7a6771
+	i = pthread_join (t1, NULL);
7a6771
+	assert (i == 0);
7a6771
+      }
7a6771
+      break;
7a6771
+    case 4:
7a6771
+      fprintf (stderr, "%s: We should not have threads for phase %d!\n",
7a6771
+	       argv[0], phase);
7a6771
+      return 1;
7a6771
+    default:
7a6771
+      assert (0);
7a6771
+    }
7a6771
+#endif	/* THREADS */
7a6771
+
7a6771
+  assert (cmd != NULL);
7a6771
+
7a6771
+  phase++;
7a6771
+  snprintf (phase_s, sizeof phase_s, "%d", phase);
7a6771
 
7a6771
-	execl ("/bin/true", "/bin/true", NULL);
7a6771
-	abort ();
7a6771
+  execl (cmd, cmd, exec_nothreads, exec_threads, phase_s, NULL);
7a6771
+  assert (0);
7a6771
 }
7a6771
Index: gdb-7.10.90.20160211/gdb/testsuite/gdb.threads/threaded-exec.exp
7a6771
===================================================================
7a6771
--- gdb-7.10.90.20160211.orig/gdb/testsuite/gdb.threads/threaded-exec.exp	2016-02-16 09:54:45.157163049 +0100
7a6771
+++ gdb-7.10.90.20160211/gdb/testsuite/gdb.threads/threaded-exec.exp	2016-02-16 09:55:27.397448879 +0100
7a6771
@@ -20,9 +20,14 @@
7a6771
 
7a6771
 set testfile threaded-exec
7a6771
 set srcfile ${testfile}.c
7a6771
-set binfile [standard_output_file ${testfile}]
7a6771
+set binfile_nothreads [standard_output_file ${testfile}N]
7a6771
+set binfile_threads [standard_output_file ${testfile}Y]
7a6771
 
7a6771
-if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } {
7a6771
+if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile_nothreads}" executable {additional_flags=-UTHREADS}] != "" } {
7a6771
+    return -1
7a6771
+}
7a6771
+
7a6771
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile_threads}" executable {additional_flags=-DTHREADS}] != "" } {
7a6771
     return -1
7a6771
 }
7a6771
 
7a6771
@@ -30,9 +35,9 @@
7a6771
 gdb_start
7a6771
 gdb_reinitialize_dir $srcdir/$subdir
7a6771
 
7a6771
-gdb_load ${binfile}
7a6771
+gdb_load ${binfile_nothreads}
7a6771
 
7a6771
-gdb_run_cmd
7a6771
+gdb_run_cmd ${binfile_nothreads} ${binfile_threads} 0
7a6771
 
7a6771
 gdb_test_multiple {} "Program exited" {
7a6771
    -re "\r\n\\\[Inferior .* exited normally\\\]\r\n$gdb_prompt $" {