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

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