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

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