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

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