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

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