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

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