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

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