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

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