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

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