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

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