1 # Copyright 1997, 1999, 2002, 2003, 2004, 2007, 2008, 2009
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 # On HP-UX 11.0, this test is causing a process running the program
25 # "attach" to be left around spinning. Until we figure out why, I am
26 # commenting out the test to avoid polluting tiamat (our 11.0 nightly
27 # test machine) with these processes. RT
29 # Setting the magic bit in the target app should work. I added a
30 # "kill", and also a test for the R3 register warning. JB
31 if { [istarget "hppa*-*-hpux*"] } {
35 # On SPU, this test currently fails because "sleep" is not supported.
36 if { [istarget "spu*-*-*"] } {
40 # are we on a target board
41 if [is_remote target] then {
46 set srcfile ${testfile}.c
47 set srcfile2 ${testfile}2.c
48 set binfile ${objdir}/${subdir}/${testfile}
49 set binfile2 ${objdir}/${subdir}/${testfile}2
50 set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
52 #execute_anywhere "rm -f ${binfile} ${binfile2}"
53 remote_exec build "rm -f ${binfile} ${binfile2}"
54 # For debugging this test
58 # build the first test case
60 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
65 # Build the in-system-call test
67 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
72 if [get_compiler_info ${binfile}] {
76 proc do_attach_tests {} {
86 # Start the program running and then wait for a bit, to be sure
87 # that it can be attached to.
89 set testpid [eval exec $binfile &]
91 if { [istarget "*-*-cygwin*"] } {
92 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
93 # different due to the way fork/exec works.
94 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
97 # Verify that we cannot attach to nonsense.
99 set test "attach to nonsense is prohibited"
100 gdb_test_multiple "attach abc" "$test" {
101 -re "Illegal process-id: abc.*$gdb_prompt $" {
104 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
105 # Response expected from /proc-based systems.
108 -re "Can't attach to process..*$gdb_prompt $" {
109 # Response expected on Cygwin
112 -re "Attaching to.*$gdb_prompt $" {
113 fail "$test (bogus pid allowed)"
117 # Verify that we cannot attach to what appears to be a valid
118 # process ID, but is a process that doesn't exist. Traditionally,
119 # most systems didn't have a process with ID 0, so we take that as
120 # the default. However, there are a few exceptions.
123 if { [istarget "*-*-*bsd*"] } {
124 # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
125 # (which should have the desired effect on any version of
126 # FreeBSD, and probably other *BSD's too).
129 set test "attach to nonexistent process is prohibited"
130 gdb_test_multiple "attach $boguspid" "$test" {
131 -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $" {
132 # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
135 -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $" {
136 # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
139 -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $" {
142 -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $" {
145 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
146 # Response expected from /proc-based systems.
149 -re "Can't attach to process..*$gdb_prompt $" {
150 # Response expected on Cygwin
155 # Verify that we can attach to the process by first giving its
156 # executable name via the file command, and using attach with the
159 # (Actually, the test system appears to do this automatically for
160 # us. So, we must also be prepared to be asked if we want to
161 # discard an existing set of symbols.)
163 set test "set file, before attach1"
164 gdb_test_multiple "file $binfile" "$test" {
165 -re "Load new symbol table from.*y or n. $" {
166 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
169 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
174 set test "attach1, after setting file"
175 gdb_test_multiple "attach $testpid" "$test" {
176 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $" {
179 -re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
180 # Response expected on Cygwin
185 # Verify that we can "see" the variable "should_exit" in the
186 # program, and that it is zero.
188 gdb_test "print should_exit" " = 0" "after attach1, print should_exit"
190 # Detach the process.
193 "Detaching from program: .*$escapedbinfile, process $testpid" \
196 # Wait a bit for gdb to finish detaching
200 # Purge the symbols from gdb's brain. (We want to be certain the
201 # next attach, which won't be preceded by a "file" command, is
202 # really getting the executable file without our help.)
204 set old_timeout $timeout
206 set test "attach1, purging symbols after detach"
207 gdb_test_multiple "file" "$test" {
208 -re "No executable file now.*Discard symbol table.*y or n. $" {
209 gdb_test "y" "No symbol file now." "$test"
212 set timeout $old_timeout
214 # Verify that we can attach to the process just by giving the
217 set test "set file, before attach2"
218 gdb_test_multiple "attach $testpid" "$test" {
219 -re "Attaching to process $testpid.*Load new symbol table from \"$escapedbinfile\.exe\".*y or n. $" {
220 # On Cygwin, the DLL's symbol tables are loaded prior to the
221 # executable's symbol table. This in turn always results in
222 # asking the user for actually loading the symbol table of the
224 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
227 -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $" {
232 # Verify that we can modify the variable "should_exit" in the
235 gdb_test "set should_exit=1" "" "after attach2, set should_exit"
237 # Verify that the modification really happened.
239 send_gdb "tbreak 19\n"
241 -re "Temporary breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $" {
242 pass "after attach2, set tbreak postloop"
244 -re "$gdb_prompt $" {
245 fail "after attach2, set tbreak postloop"
248 fail "(timeout) after attach2, set tbreak postloop"
251 send_gdb "continue\n"
253 -re "main.*at.*$srcfile:19.*$gdb_prompt $" {
254 pass "after attach2, reach tbreak postloop"
256 -re "$gdb_prompt $" {
257 fail "after attach2, reach tbreak postloop"
260 fail "(timeout) after attach2, reach tbreak postloop"
264 # Allow the test process to exit, to cleanup after ourselves.
266 gdb_test "continue" "Program exited normally." "after attach2, exit"
268 # Make sure we don't leave a process around to confuse
269 # the next test run (and prevent the compile by keeping
270 # the text file busy), in case the "set should_exit" didn't
273 remote_exec build "kill -9 ${testpid}"
275 # Start the program running and then wait for a bit, to be sure
276 # that it can be attached to.
278 set testpid [eval exec $binfile &]
280 if { [istarget "*-*-cygwin*"] } {
281 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
282 # different due to the way fork/exec works.
283 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
286 # Verify that we can attach to the process, and find its a.out
287 # when we're cd'd to some directory that doesn't contain the
288 # a.out. (We use the source path set by the "dir" command.)
290 gdb_test "dir ${objdir}/${subdir}" "Source directories searched: .*" \
293 gdb_test "cd /tmp" "Working directory /tmp." \
294 "cd away from process working directory"
296 # Explicitly flush out any knowledge of the previous attachment.
298 set test "before attach3, flush symbols"
299 gdb_test_multiple "symbol" "$test" {
300 -re "Discard symbol table from.*y or n. $" {
301 gdb_test "y" "No symbol file now." \
304 -re "No symbol file now.*$gdb_prompt $" {
309 gdb_test "exec" "No executable file now." \
310 "before attach3, flush exec"
312 gdb_test "attach $testpid" \
313 "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*" \
314 "attach when process' a.out not in cwd"
316 set test "after attach3, exit"
317 gdb_test_multiple "kill" "$test" {
318 -re "Kill the program being debugged.*y or n. $" {
319 gdb_test "y" "" "$test"
323 # Another "don't leave a process around"
324 remote_exec build "kill -9 ${testpid}"
327 proc do_call_attach_tests {} {
331 # Start the program running and then wait for a bit, to be sure
332 # that it can be attached to.
334 set testpid [eval exec $binfile2 &]
336 if { [istarget "*-*-cygwin*"] } {
337 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
338 # different due to the way fork/exec works.
339 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
344 gdb_test "file $binfile2" "" "force switch to gdb64, if necessary"
345 set test "attach call"
346 gdb_test_multiple "attach $testpid" "$test" {
347 -re "warning: reading register.*I.*O error.*$gdb_prompt $" {
348 fail "$test (read register error)"
350 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
353 -re "Attaching to.*process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
358 # See if other registers are problems
360 set test "info other register"
361 gdb_test_multiple "i r r3" "$test" {
362 -re "warning: reading register.*$gdb_prompt $" {
365 -re "r3.*$gdb_prompt $" {
370 # Get rid of the process
372 gdb_test "p should_exit = 1"
373 gdb_test "c" "Program exited normally."
377 remote_exec build "kill -9 ${testpid}"
381 # Start with a fresh gdb
385 gdb_reinitialize_dir $srcdir/$subdir
388 # This is a test of gdb's ability to attach to a running process.
392 # Test attaching when the target is inside a system call
397 gdb_reinitialize_dir $srcdir/$subdir