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

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