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

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