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

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