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

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