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

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