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

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