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

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