c499105
Test various forms of threads tracking across exec(2).
c499105
Jan Kratochvil 22d1e60
Index: gdb-7.10.90.20160211/gdb/testsuite/gdb.threads/threaded-exec.c
Jan Kratochvil 22d1e60
===================================================================
Jan Kratochvil 22d1e60
--- gdb-7.10.90.20160211.orig/gdb/testsuite/gdb.threads/threaded-exec.c	2016-02-16 09:54:45.157163049 +0100
Jan Kratochvil 22d1e60
+++ gdb-7.10.90.20160211/gdb/testsuite/gdb.threads/threaded-exec.c	2016-02-16 09:54:46.210170175 +0100
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
 
Jan Kratochvil 22d1e60
@@ -40,7 +114,34 @@
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
 }
Jan Kratochvil 22d1e60
Index: gdb-7.10.90.20160211/gdb/testsuite/gdb.threads/threaded-exec.exp
Jan Kratochvil 22d1e60
===================================================================
Jan Kratochvil 22d1e60
--- gdb-7.10.90.20160211.orig/gdb/testsuite/gdb.threads/threaded-exec.exp	2016-02-16 09:54:45.157163049 +0100
Jan Kratochvil 22d1e60
+++ gdb-7.10.90.20160211/gdb/testsuite/gdb.threads/threaded-exec.exp	2016-02-16 09:55:27.397448879 +0100
c499105
@@ -20,9 +20,14 @@
c499105
 
c499105
 set testfile threaded-exec
c499105
 set srcfile ${testfile}.c
Jan Kratochvil 22d1e60
-set binfile [standard_output_file ${testfile}]
Jan Kratochvil 22d1e60
+set binfile_nothreads [standard_output_file ${testfile}N]
Jan Kratochvil 22d1e60
+set binfile_threads [standard_output_file ${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
 
Jan Kratochvil 22d1e60
@@ -30,9 +35,9 @@
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" {
Jan Kratochvil 48cf710
    -re "\r\n\\\[Inferior .* exited normally\\\]\r\n$gdb_prompt $" {