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

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