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

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