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

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