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

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