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

b94e32
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
b94e32
From: Fedora GDB patches <invalid@email.com>
b94e32
Date: Fri, 27 Oct 2017 21:07:50 +0200
b94e32
Subject: gdb-6.8-bz442765-threaded-exec-test.patch
b94e32
b94e32
;; Test various forms of threads tracking across exec() (BZ 442765).
b94e32
;;=fedoratest
b94e32
b94e32
Test various forms of threads tracking across exec(2).
b94e32
b94e32
diff --git a/gdb/testsuite/gdb.threads/threaded-exec.c b/gdb/testsuite/gdb.threads/threaded-exec.c
b94e32
--- a/gdb/testsuite/gdb.threads/threaded-exec.c
b94e32
+++ b/gdb/testsuite/gdb.threads/threaded-exec.c
b94e32
@@ -18,21 +18,95 @@
b94e32
    Boston, MA 02111-1307, USA.  */
b94e32
 
b94e32
 #include <stddef.h>
b94e32
-#include <pthread.h>
b94e32
 #include <assert.h>
b94e32
 #include <stdlib.h>
b94e32
 #include <unistd.h>
b94e32
+#include <stdio.h>
b94e32
 
b94e32
+#ifdef THREADS
b94e32
+
b94e32
+# include <pthread.h>
b94e32
 
b94e32
 static void *
b94e32
 threader (void *arg)
b94e32
 {
b94e32
-	return NULL;
b94e32
+  return NULL;
b94e32
 }
b94e32
 
b94e32
+#endif
b94e32
+
b94e32
 int
b94e32
-main (void)
b94e32
+main (int argc, char **argv)
b94e32
 {
b94e32
+  char *exec_nothreads, *exec_threads, *cmd;
b94e32
+  int phase;
b94e32
+  char phase_s[8];
b94e32
+
b94e32
+  setbuf (stdout, NULL);
b94e32
+
b94e32
+  if (argc != 4)
b94e32
+    {
b94e32
+      fprintf (stderr, "%s <non-threaded> <threaded> <phase>\n", argv[0]);
b94e32
+      return 1;
b94e32
+    }
b94e32
+
b94e32
+#ifdef THREADS
b94e32
+  puts ("THREADS: Y");
b94e32
+#else
b94e32
+  puts ("THREADS: N");
b94e32
+#endif
b94e32
+  exec_nothreads = argv[1];
b94e32
+  printf ("exec_nothreads: %s\n", exec_nothreads);
b94e32
+  exec_threads = argv[2];
b94e32
+  printf ("exec_threads: %s\n", exec_threads);
b94e32
+  phase = atoi (argv[3]);
b94e32
+  printf ("phase: %d\n", phase);
b94e32
+
b94e32
+  /* Phases: threading
b94e32
+     0: N -> N
b94e32
+     1: N -> Y
b94e32
+     2: Y -> Y
b94e32
+     3: Y -> N
b94e32
+     4: N -> exit  */
b94e32
+
b94e32
+  cmd = NULL;
b94e32
+
b94e32
+#ifndef THREADS
b94e32
+  switch (phase)
b94e32
+    {
b94e32
+    case 0:
b94e32
+      cmd = exec_nothreads;
b94e32
+      break;
b94e32
+    case 1:
b94e32
+      cmd = exec_threads;
b94e32
+      break;
b94e32
+    case 2:
b94e32
+      fprintf (stderr, "%s: We should have threads for phase %d!\n", argv[0],
b94e32
+	       phase);
b94e32
+      return 1;
b94e32
+    case 3:
b94e32
+      fprintf (stderr, "%s: We should have threads for phase %d!\n", argv[0],
b94e32
+	       phase);
b94e32
+      return 1;
b94e32
+    case 4:
b94e32
+      return 0;
b94e32
+    default:
b94e32
+      assert (0);
b94e32
+    }
b94e32
+#else	/* THREADS */
b94e32
+  switch (phase)
b94e32
+    {
b94e32
+    case 0:
b94e32
+      fprintf (stderr, "%s: We should not have threads for phase %d!\n",
b94e32
+	       argv[0], phase);
b94e32
+      return 1;
b94e32
+    case 1:
b94e32
+      fprintf (stderr, "%s: We should not have threads for phase %d!\n",
b94e32
+	       argv[0], phase);
b94e32
+      return 1;
b94e32
+    case 2:
b94e32
+      cmd = exec_threads;
b94e32
+      {
b94e32
 	pthread_t t1;
b94e32
 	int i;
b94e32
 
b94e32
@@ -40,7 +114,34 @@ main (void)
b94e32
 	assert (i == 0);
b94e32
 	i = pthread_join (t1, NULL);
b94e32
 	assert (i == 0);
b94e32
+      }
b94e32
+      break;
b94e32
+    case 3:
b94e32
+      cmd = exec_nothreads;
b94e32
+      {
b94e32
+	pthread_t t1;
b94e32
+	int i;
b94e32
+
b94e32
+	i = pthread_create (&t1, NULL, threader, (void *) NULL);
b94e32
+	assert (i == 0);
b94e32
+	i = pthread_join (t1, NULL);
b94e32
+	assert (i == 0);
b94e32
+      }
b94e32
+      break;
b94e32
+    case 4:
b94e32
+      fprintf (stderr, "%s: We should not have threads for phase %d!\n",
b94e32
+	       argv[0], phase);
b94e32
+      return 1;
b94e32
+    default:
b94e32
+      assert (0);
b94e32
+    }
b94e32
+#endif	/* THREADS */
b94e32
+
b94e32
+  assert (cmd != NULL);
b94e32
+
b94e32
+  phase++;
b94e32
+  snprintf (phase_s, sizeof phase_s, "%d", phase);
b94e32
 
b94e32
-	execl ("/bin/true", "/bin/true", NULL);
b94e32
-	abort ();
b94e32
+  execl (cmd, cmd, exec_nothreads, exec_threads, phase_s, NULL);
b94e32
+  assert (0);
b94e32
 }
b94e32
diff --git a/gdb/testsuite/gdb.threads/threaded-exec.exp b/gdb/testsuite/gdb.threads/threaded-exec.exp
b94e32
--- a/gdb/testsuite/gdb.threads/threaded-exec.exp
b94e32
+++ b/gdb/testsuite/gdb.threads/threaded-exec.exp
b94e32
@@ -20,9 +20,14 @@
b94e32
 
b94e32
 set testfile threaded-exec
b94e32
 set srcfile ${testfile}.c
b94e32
-set binfile [standard_output_file ${testfile}]
b94e32
+set binfile_nothreads [standard_output_file ${testfile}N]
b94e32
+set binfile_threads [standard_output_file ${testfile}Y]
b94e32
 
b94e32
-if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } {
b94e32
+if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile_nothreads}" executable {additional_flags=-UTHREADS}] != "" } {
b94e32
+    return -1
b94e32
+}
b94e32
+
b94e32
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile_threads}" executable {additional_flags=-DTHREADS}] != "" } {
b94e32
     return -1
b94e32
 }
b94e32
 
b94e32
@@ -30,9 +35,9 @@ gdb_exit
b94e32
 gdb_start
b94e32
 gdb_reinitialize_dir $srcdir/$subdir
b94e32
 
b94e32
-gdb_load ${binfile}
b94e32
+gdb_load ${binfile_nothreads}
b94e32
 
b94e32
-gdb_run_cmd
b94e32
+gdb_run_cmd [list ${binfile_nothreads} ${binfile_threads} 0]
b94e32
 
b94e32
 gdb_test_multiple {} "Program exited" {
b94e32
    -re "\r\n\\\[Inferior .* exited normally\\\]\r\n$gdb_prompt $" {