Blame SOURCES/gdb-6.6-bz229517-gcore-without-terminal.patch

6240d7
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
6240d7
From: Jan Kratochvil <jan.kratochvil@redhat.com>
6240d7
Date: Fri, 27 Oct 2017 21:07:50 +0200
6240d7
Subject: gdb-6.6-bz229517-gcore-without-terminal.patch
6240d7
6240d7
;; Allow running `/usr/bin/gcore' with provided but inaccessible tty (BZ 229517).
6240d7
;;=fedoratest
6240d7
6240d7
2007-04-22  Jan Kratochvil <jan.kratochvil@redhat.com>
6240d7
6240d7
	* gdb_gcore.sh: Redirect GDB from `
6240d7
6240d7
2007-04-22  Jan Kratochvil <jan.kratochvil@redhat.com>
6240d7
6240d7
	* gdb.base/gcorebg.exp, gdb.base/gcorebg.c: New files.
6240d7
6240d7
diff --git a/gdb/testsuite/gdb.base/gcorebg.c b/gdb/testsuite/gdb.base/gcorebg.c
6240d7
new file mode 100644
6240d7
--- /dev/null
6240d7
+++ b/gdb/testsuite/gdb.base/gcorebg.c
6240d7
@@ -0,0 +1,49 @@
6240d7
+#include <stdio.h>
6240d7
+#include <sys/types.h>
6240d7
+#include <unistd.h>
6240d7
+#include <stdlib.h>
6240d7
+#include <signal.h>
6240d7
+#include <string.h>
6240d7
+#include <assert.h>
6240d7
+
6240d7
+int main (int argc, char **argv)
6240d7
+{
6240d7
+  pid_t pid = 0;
6240d7
+  pid_t ppid;
6240d7
+  char buf[1024*2 + 500];
6240d7
+  int gotint;
6240d7
+
6240d7
+  if (argc != 4)
6240d7
+    {
6240d7
+      fprintf (stderr, "Syntax: %s {standard|detached} <gcore command> <core output file>\n",
6240d7
+	       argv[0]);
6240d7
+      exit (1);
6240d7
+    }
6240d7
+
6240d7
+  pid = fork ();
6240d7
+
6240d7
+  switch (pid)
6240d7
+    {
6240d7
+      case 0:
6240d7
+        if (strcmp (argv[1], "detached") == 0)
6240d7
+	  setpgrp ();
6240d7
+	ppid = getppid ();
6240d7
+	gotint = snprintf (buf, sizeof (buf), "sh %s -o %s %d", argv[2], argv[3], (int) ppid);
6240d7
+	assert (gotint < sizeof (buf));
6240d7
+	system (buf);
6240d7
+	fprintf (stderr, "Killing parent PID %d\n", ppid);
6240d7
+	kill (ppid, SIGTERM);
6240d7
+	break;
6240d7
+
6240d7
+      case -1:
6240d7
+	perror ("fork err\n");
6240d7
+	exit (1);
6240d7
+	break;
6240d7
+
6240d7
+      default:
6240d7
+	fprintf (stderr,"Sleeping as PID %d\n", getpid ());
6240d7
+	sleep (60);
6240d7
+    }
6240d7
+
6240d7
+  return 0;
6240d7
+}
6240d7
diff --git a/gdb/testsuite/gdb.base/gcorebg.exp b/gdb/testsuite/gdb.base/gcorebg.exp
6240d7
new file mode 100644
6240d7
--- /dev/null
6240d7
+++ b/gdb/testsuite/gdb.base/gcorebg.exp
6240d7
@@ -0,0 +1,113 @@
6240d7
+# Copyright 2007 Free Software Foundation, Inc.
6240d7
+
6240d7
+# This program is free software; you can redistribute it and/or modify
6240d7
+# it under the terms of the GNU General Public License as published by
6240d7
+# the Free Software Foundation; either version 2 of the License, or
6240d7
+# (at your option) any later version.
6240d7
+# 
6240d7
+# This program is distributed in the hope that it will be useful,
6240d7
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
6240d7
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6240d7
+# GNU General Public License for more details.
6240d7
+# 
6240d7
+# You should have received a copy of the GNU General Public License
6240d7
+# along with this program; if not, write to the Free Software
6240d7
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
6240d7
+
6240d7
+# Please email any bugs, comments, and/or additions to this file to:
6240d7
+# bug-gdb@prep.ai.mit.edu
6240d7
+
6240d7
+# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
6240d7
+# This is a test for `gdb_gcore.sh' functionality.
6240d7
+# It also tests a regression with `gdb_gcore.sh' being run without its
6240d7
+# accessible terminal.
6240d7
+
6240d7
+if ![info exists GCORE] {
6240d7
+    set GCORE "[standard_output_file ../../../../gcore]"
6240d7
+}
6240d7
+verbose "using GCORE = $GCORE" 2
6240d7
+
6240d7
+set testfile "gcorebg"
6240d7
+set srcfile  ${testfile}.c
6240d7
+set binfile  [standard_output_file ${testfile}]
6240d7
+set corefile [standard_output_file ${testfile}.test]
6240d7
+
6240d7
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
6240d7
+     untested gcorebg.exp
6240d7
+     return -1
6240d7
+}
6240d7
+
6240d7
+# Cleanup.
6240d7
+
6240d7
+proc core_clean {} {
6240d7
+    global corefile
6240d7
+
6240d7
+    foreach file [glob -nocomplain [join [list $corefile *] ""]] {
6240d7
+	verbose "Delete file $file" 1
6240d7
+	remote_file target delete $file
6240d7
+    }
6240d7
+}
6240d7
+core_clean
6240d7
+remote_file target delete "./gdb"
6240d7
+
6240d7
+# Generate the core file.
6240d7
+
6240d7
+# Provide `./gdb' for `gdb_gcore.sh' running it as a bare `gdb' command.
6240d7
+# Setup also `$PATH' appropriately.
6240d7
+# If GDB was not found let `gdb_gcore.sh' to find the system GDB by `$PATH'.
6240d7
+if {$GDB != "gdb"} {
6240d7
+    file link ./gdb $GDB
6240d7
+}
6240d7
+global env
6240d7
+set oldpath $env(PATH)
6240d7
+set env(PATH) [join [list . $env(PATH)] ":"]
6240d7
+verbose "PATH = $env(PATH)" 2
6240d7
+
6240d7
+# Test file body.
6240d7
+# $detached == "standard" || $detached == "detached"
6240d7
+
6240d7
+proc test_body { detached } {
6240d7
+    global binfile
6240d7
+    global GCORE
6240d7
+    global corefile
6240d7
+
6240d7
+    set res [remote_spawn target "$binfile $detached $GCORE $corefile"]
6240d7
+    if { $res < 0 || $res == "" } {
6240d7
+	fail "Spawning $detached gcore"
6240d7
+	return 1
6240d7
+    }
6240d7
+    pass "Spawning $detached gcore"
6240d7
+    remote_expect target 20 {
6240d7
+	timeout {
6240d7
+	    fail "Spawned $detached gcore finished (timeout)"
6240d7
+	    remote_exec target "kill -9 -[exp_pid -i $res]"
6240d7
+	    return 1
6240d7
+	}
6240d7
+	"Saved corefile .*\r\nKilling parent PID " {
6240d7
+	    pass "Spawned $detached gcore finished"
6240d7
+	    remote_wait target 20
6240d7
+	}
6240d7
+    }
6240d7
+
6240d7
+    if {1 == [llength [glob -nocomplain [join [list $corefile *] ""]]]} {
6240d7
+	pass "Core file generated by $detached gcore"
6240d7
+    } else {
6240d7
+	fail "Core file generated by $detached gcore"
6240d7
+    }
6240d7
+    core_clean
6240d7
+}
6240d7
+
6240d7
+# First a general `gdb_gcore.sh' spawn with its controlling terminal available.
6240d7
+
6240d7
+test_body standard
6240d7
+
6240d7
+# And now `gdb_gcore.sh' spawn without its controlling terminal available.
6240d7
+# It is spawned through `gcorebg.c' using setpgrp ().
6240d7
+
6240d7
+test_body detached
6240d7
+
6240d7
+
6240d7
+# Cleanup.
6240d7
+
6240d7
+set env(PATH) $oldpath
6240d7
+remote_file target delete "./gdb"