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

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