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

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