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

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