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

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