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

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