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

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