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

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