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