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

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