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

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