]>
Commit | Line | Data |
---|---|---|
3a58abaf AM |
1 | 2007-04-22 Jan Kratochvil <jan.kratochvil@redhat.com> |
2 | ||
3 | * gdb_gcore.sh: Redirect GDB from `</dev/null'. | |
4 | ||
5 | 2007-04-22 Jan Kratochvil <jan.kratochvil@redhat.com> | |
6 | ||
7 | * gdb.base/gcorebg.exp, gdb.base/gcorebg.c: New files. | |
8 | ||
9 | ||
10 | --- gdb-6.6-orig/gdb/gdb_gcore.sh 2005-12-17 17:33:59.000000000 -0500 | |
11 | +++ gdb-6.6/gdb/gdb_gcore.sh 2007-04-22 05:42:50.000000000 -0400 | |
12 | @@ -71,7 +71,9 @@ | |
13 | quit | |
14 | EOF | |
15 | ||
16 | - gdb -x $tmpfile -batch | |
17 | + # `</dev/null' to avoid touching interactive terminal if it is | |
18 | + # available but not accessible (SIGTTIN risk) | |
19 | + gdb -x $tmpfile -batch </dev/null | |
20 | ||
21 | if [ -r $name.$pid ] ; then | |
22 | rc=0 | |
23 | --- /dev/null 1 Jan 1970 00:00:00 -0000 | |
24 | +++ ./gdb/testsuite/gdb.base/gcorebg.c 25 Feb 2007 12:21:20 -0000 | |
25 | @@ -0,0 +1,43 @@ | |
26 | +#include <stdio.h> | |
27 | +#include <sys/types.h> | |
28 | +#include <unistd.h> | |
29 | +#include <stdlib.h> | |
30 | +#include <signal.h> | |
31 | + | |
32 | +int main (int argc, char **argv) | |
33 | +{ | |
34 | + pid_t pid = 0; | |
35 | + pid_t ppid; | |
36 | + char buf[256]; | |
37 | + | |
38 | + if (argc != 4) | |
39 | + { | |
40 | + fprintf (stderr, "Syntax: %s {standard|detached} <gcore command> <core output file>\n", | |
41 | + argv[0]); | |
42 | + exit (1); | |
43 | + } | |
44 | + | |
45 | + pid = fork (); | |
46 | + | |
47 | + switch (pid) | |
48 | + { | |
49 | + case 0: | |
50 | + if (strcmp (argv[1], "detached") == 0) | |
51 | + setpgrp (); | |
52 | + ppid = getppid (); | |
53 | + sprintf (buf, "sh %s -o %s %d", argv[2], argv[3], (int) ppid); | |
54 | + system (buf); | |
55 | + kill (ppid, SIGTERM); | |
56 | + break; | |
57 | + | |
58 | + case -1: | |
59 | + perror ("fork err\n"); | |
60 | + exit (1); | |
61 | + break; | |
62 | + | |
63 | + default: | |
64 | + sleep (60); | |
65 | + } | |
66 | + | |
67 | + return 0; | |
68 | +} | |
69 | --- /dev/null 1 Jan 1970 00:00:00 -0000 | |
70 | +++ ./gdb/testsuite/gdb.base/gcorebg.exp 25 Feb 2007 12:21:20 -0000 | |
71 | @@ -0,0 +1,120 @@ | |
72 | +# Copyright 2007 Free Software Foundation, Inc. | |
73 | + | |
74 | +# This program is free software; you can redistribute it and/or modify | |
75 | +# it under the terms of the GNU General Public License as published by | |
76 | +# the Free Software Foundation; either version 2 of the License, or | |
77 | +# (at your option) any later version. | |
78 | +# | |
79 | +# This program is distributed in the hope that it will be useful, | |
80 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
81 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
82 | +# GNU General Public License for more details. | |
83 | +# | |
84 | +# You should have received a copy of the GNU General Public License | |
85 | +# along with this program; if not, write to the Free Software | |
86 | +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
87 | + | |
88 | +# Please email any bugs, comments, and/or additions to this file to: | |
89 | +# bug-gdb@prep.ai.mit.edu | |
90 | + | |
91 | +# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>. | |
92 | +# This is a test for `gdb_gcore.sh' functionality. | |
93 | +# It also tests a regression with `gdb_gcore.sh' being run without its | |
94 | +# accessible terminal. | |
95 | + | |
96 | +if $tracelevel then { | |
97 | + strace $tracelevel | |
98 | +} | |
99 | + | |
100 | +set prms_id 0 | |
101 | +set bug_id 0 | |
102 | + | |
103 | +if ![info exists GCORE] { | |
104 | + set GCORE "${srcdir}/../gdb_gcore.sh" | |
105 | +} | |
106 | +verbose "using GCORE = $GCORE" 2 | |
107 | + | |
108 | +set testfile "gcorebg" | |
109 | +set srcfile ${testfile}.c | |
110 | +set binfile ${objdir}/${subdir}/${testfile} | |
111 | +set corefile ${objdir}/${subdir}/${testfile}.test | |
112 | + | |
113 | +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
114 | + untested gcorebg.exp | |
115 | + return -1 | |
116 | +} | |
117 | + | |
118 | +# Cleanup. | |
119 | + | |
120 | +proc core_clean {} { | |
121 | + global corefile | |
122 | + | |
123 | + foreach file [glob -nocomplain [join [list $corefile *] ""]] { | |
124 | + verbose "Delete file $file" 1 | |
125 | + remote_file target delete $file | |
126 | + } | |
127 | +} | |
128 | +core_clean | |
129 | +remote_file target delete "./gdb" | |
130 | + | |
131 | +# Generate the core file. | |
132 | + | |
133 | +# Provide `./gdb' for `gdb_gcore.sh' running it as a bare `gdb' command. | |
134 | +# Setup also `$PATH' appropriately. | |
135 | +# If GDB was not found let `gdb_gcore.sh' to find the system GDB by `$PATH'. | |
136 | +if {$GDB != "gdb"} { | |
137 | + file link ./gdb $GDB | |
138 | +} | |
139 | +global env | |
140 | +set oldpath $env(PATH) | |
141 | +set env(PATH) [join [list . $env(PATH)] ":"] | |
142 | +verbose "PATH = $env(PATH)" 2 | |
143 | + | |
144 | +# Test file body. | |
145 | +# $detached == "standard" || $detached == "detached" | |
146 | + | |
147 | +proc test_body { detached } { | |
148 | + global binfile | |
149 | + global GCORE | |
150 | + global corefile | |
151 | + | |
152 | + set res [remote_spawn target "$binfile $detached $GCORE $corefile"] | |
153 | + if { $res < 0 || $res == "" } { | |
154 | + fail "Spawning $detached gcore" | |
155 | + return 1 | |
156 | + } | |
157 | + pass "Spawning $detached gcore" | |
158 | + remote_expect target 20 { | |
159 | + timeout { | |
160 | + fail "Spawned $detached gcore finished" | |
161 | + remote_exec target "kill -9 -[exp_pid -i $res]" | |
162 | + return 1 | |
163 | + } | |
164 | + eof { | |
165 | + pass "Spawned $detached gcore finished" | |
166 | + remote_wait target 20 | |
167 | + } | |
168 | + } | |
169 | + | |
170 | + if {1 == [llength [glob -nocomplain [join [list $corefile *] ""]]]} { | |
171 | + pass "Core file generated by $detached gcore" | |
172 | + } else { | |
173 | + fail "Core file generated by $detached gcore" | |
174 | + } | |
175 | + core_clean | |
176 | +} | |
177 | + | |
178 | +# First a general `gdb_gcore.sh' spawn with its controlling terminal available. | |
179 | + | |
180 | +test_body standard | |
181 | + | |
182 | +# And now `gdb_gcore.sh' spawn without its controlling terminal available. | |
183 | +# It is spawned through `gcorebg.c' using setpgrp (). | |
184 | + | |
185 | +test_body detached | |
186 | + | |
187 | + | |
188 | +# Cleanup. | |
189 | + | |
190 | +set env(PATH) $oldpath | |
191 | +remote_file target delete "./gdb" |