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