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

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