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

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