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

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