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

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