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

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