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

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