1 # Copyright 1997, 1999, 2002, 2003, 2004 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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 # are we on a target board
36 if [is_remote target] then {
41 set srcfile ${testfile}.c
42 set srcfile2 ${testfile}2.c
43 set binfile ${objdir}/${subdir}/${testfile}
44 set binfile2 ${objdir}/${subdir}/${testfile}2
45 set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
46 set cleanupfile ${objdir}/${subdir}/${testfile}.awk
48 #execute_anywhere "rm -f ${binfile} ${binfile2}"
49 remote_exec build "rm -f ${binfile} ${binfile2}"
50 # For debugging this test
54 # Clean out any old files from past runs.
56 remote_exec build "${cleanupfile}"
58 # build the first test case
60 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
61 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
64 # Build the in-system-call test
66 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
67 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
70 if [get_compiler_info ${binfile}] {
74 proc do_attach_tests {} {
84 # Start the program running and then wait for a bit, to be sure
85 # that it can be attached to.
87 set testpid [eval exec $binfile &]
89 if { [istarget "*-*-cygwin*"] } {
90 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
91 # different due to the way fork/exec works.
92 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
95 # Verify that we cannot attach to nonsense.
97 send_gdb "attach abc\n"
99 -re ".*Illegal process-id: abc.*$gdb_prompt $" {
100 pass "attach to nonsense is prohibited"
102 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
103 # Response expected from /proc-based systems.
104 pass "attach to nonsense is prohibited"
106 -re ".*Can't attach to process..*$gdb_prompt $" {
107 # Response expected on Cygwin
108 pass "attach to nonsense is prohibited"
110 -re "Attaching to.*$gdb_prompt $" {
111 fail "attach to nonsense is prohibited (bogus pid allowed)"
113 -re "$gdb_prompt $" {
114 fail "attach to nonsense is prohibited"
117 fail "(timeout) attach to nonsense is prohibited"
121 # Verify that we cannot attach to what appears to be a valid
122 # process ID, but is a process that doesn't exist. Traditionally,
123 # most systems didn't have a process with ID 0, so we take that as
124 # the default. However, there are a few exceptions.
127 if { [istarget "*-*-*bsd*"] } {
128 # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
129 # (which should have the desired effect on any version of
130 # FreeBSD, and probably other *BSD's too).
133 send_gdb "attach $boguspid\n"
135 -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $" {
136 # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
137 pass "attach to nonexistent process is prohibited"
139 -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $" {
140 # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
141 pass "attach to nonexistent process is prohibited"
143 -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $" {
144 pass "attach to nonexistent process is prohibited"
146 -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $" {
147 pass "attach to nonexistent process is prohibited"
149 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
150 # Response expected from /proc-based systems.
151 pass "attach to nonexistent process is prohibited"
153 -re ".*Can't attach to process..*$gdb_prompt $" {
154 # Response expected on Cygwin
155 pass "attach to nonexistent process is prohibited"
157 -re "$gdb_prompt $" {
158 fail "attach to nonexistent process is prohibited"
161 fail "(timeout) attach to nonexistent process is prohibited"
165 # Verify that we can attach to the process by first giving its
166 # executable name via the file command, and using attach with the
169 # (Actually, the test system appears to do this automatically for
170 # us. So, we must also be prepared to be asked if we want to
171 # discard an existing set of symbols.)
173 send_gdb "file $binfile\n"
175 -re "Load new symbol table from.*y or n.*$" {
178 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
179 pass "(re)set file, before attach1"
181 -re "$gdb_prompt $" {
182 fail "(re)set file, before attach1"
185 fail "(timeout) (re)set file, before attach1"
189 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
190 pass "set file, before attach1"
192 -re "$gdb_prompt $" {
193 fail "set file, before attach1"
196 fail "(timeout) set file, before attach1"
200 send_gdb "attach $testpid\n"
202 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $" {
203 pass "attach1, after setting file"
205 -re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
206 # Response expected on Cygwin
207 pass "attach1, after setting file"
209 -re "$gdb_prompt $" {
210 fail "attach1, after setting file"
213 fail "(timeout) attach1, after setting file"
217 # Verify that we can "see" the variable "should_exit" in the
218 # program, and that it is zero.
220 send_gdb "print should_exit\n"
222 -re ".* = 0.*$gdb_prompt $" {
223 pass "after attach1, print should_exit"
225 -re "$gdb_prompt $" {
226 fail "after attach1, print should_exit"
229 fail "(timeout) after attach1, print should_exit"
233 # Detach the process.
237 -re "Detaching from program: .*$escapedbinfile.*$gdb_prompt $" {
238 pass "attach1 detach"
240 -re "$gdb_prompt $" {
241 fail "attach1 detach"
244 fail "(timeout) attach1 detach"
248 # Wait a bit for gdb to finish detaching
252 # Purge the symbols from gdb's brain. (We want to be certain the
253 # next attach, which won't be preceded by a "file" command, is
254 # really getting the executable file without our help.)
256 set old_timeout $timeout
260 -re ".*gdb internal error.*$" {
261 fail "Internal error, prob. Memory corruption"
263 -re "No executable file now.*Discard symbol table.*y or n.*$" {
266 -re "No symbol file now.*$gdb_prompt $" {
267 pass "attach1, purging symbols after detach"
269 -re "$gdb_prompt $" {
270 fail "attach1, purging symbols after detach"
273 fail "(timeout) attach1, purging symbols after detach"
277 -re "$gdb_prompt $" {
278 fail "attach1, purging file after detach"
281 fail "(timeout) attach1, purging file after detach"
284 set timeout $old_timeout
286 # Verify that we can attach to the process just by giving the
289 send_gdb "attach $testpid\n"
291 -re "Attaching to process $testpid.*Load new symbol table from \"$escapedbinfile\.exe\".*y or n.*$" {
292 # On Cygwin, the DLL's symbol tables are loaded prior to the
293 # executable's symbol table. This in turn always results in
294 # asking the user for actually loading the symbol table of the
298 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
299 pass "(re)set file, before attach2"
301 -re "$gdb_prompt $" {
302 fail "(re)set file, before attach2"
305 fail "(timeout) (re)set file, before attach2"
309 -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $" {
312 -re "$gdb_prompt $" {
316 fail "(timeout) attach2"
320 # Verify that we can modify the variable "should_exit" in the
323 send_gdb "set should_exit=1\n"
325 -re "$gdb_prompt $" {
326 pass "after attach2, set should_exit"
329 fail "(timeout) after attach2, set should_exit"
333 # Verify that the modification really happened.
335 send_gdb "tbreak 19\n"
337 -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $" {
338 pass "after attach2, set tbreak postloop"
340 -re "$gdb_prompt $" {
341 fail "after attach2, set tbreak postloop"
344 fail "(timeout) after attach2, set tbreak postloop"
347 send_gdb "continue\n"
349 -re "main.*at.*$srcfile:19.*$gdb_prompt $" {
350 pass "after attach2, reach tbreak postloop"
352 -re "$gdb_prompt $" {
353 fail "after attach2, reach tbreak postloop"
356 fail "(timeout) after attach2, reach tbreak postloop"
360 # Allow the test process to exit, to cleanup after ourselves.
362 send_gdb "continue\n"
364 -re "Program exited normally.*$gdb_prompt $" {
365 pass "after attach2, exit"
367 -re "$gdb_prompt $" {
368 fail "after attach2, exit"
371 fail "(timeout) after attach2, exit"
375 # Make sure we don't leave a process around to confuse
376 # the next test run (and prevent the compile by keeping
377 # the text file busy), in case the "set should_exit" didn't
380 remote_exec build "kill -9 ${testpid}"
381 # Start the program running and then wait for a bit, to be sure
382 # that it can be attached to.
384 set testpid [eval exec $binfile &]
386 if { [istarget "*-*-cygwin*"] } {
387 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
388 # different due to the way fork/exec works.
389 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
392 # Verify that we can attach to the process, and find its a.out
393 # when we're cd'd to some directory that doesn't contain the
394 # a.out. (We use the source path set by the "dir" command.)
396 send_gdb "dir ${objdir}/${subdir}\n"
398 -re ".*Source directories searched: .*$gdb_prompt $" {
399 pass "set source path"
401 -re "$gdb_prompt $" {
402 fail "set source path"
405 fail "(timeout) set source path"
411 -re ".*Working directory /tmp.*$gdb_prompt $" {
412 pass "cd away from process' a.out"
414 -re "$gdb_prompt $" {
415 fail "cd away from process' a.out"
418 fail "(timeout) cd away from process' a.out"
422 # Explicitly flush out any knowledge of the previous attachment.
425 -re ".*Discard symbol table from.*y or n. $" {
428 -re ".*No symbol file now.*$gdb_prompt $" {
429 pass "before attach3, flush symbols"
431 -re "$gdb_prompt $" {
432 fail "before attach3, flush symbols"
435 fail "(timeout) before attach3, flush symbols"
439 -re ".*No symbol file now.*$gdb_prompt $" {
440 pass "before attach3, flush symbols"
442 -re "$gdb_prompt $" {
443 fail "before attach3, flush symbols"
446 fail "(timeout) before attach3, flush symbols"
451 -re ".*No executable file now.*$gdb_prompt $" {
452 pass "before attach3, flush exec"
454 -re "$gdb_prompt $" {
455 fail "before attach3, flush exec"
458 fail "(timeout) before attach3, flush exec"
462 send_gdb "attach $testpid\n"
464 -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $" {
465 pass "attach when process' a.out not in cwd"
467 -re "$gdb_prompt $" {
468 fail "attach when process' a.out not in cwd"
471 fail "(timeout) attach when process' a.out not in cwd"
477 -re ".*Kill the program being debugged.*y or n. $" {
480 -re "$gdb_prompt $" {
481 pass "after attach3, exit"
484 fail "(timeout) after attach3, exit"
488 -re "$gdb_prompt $" {
489 fail "after attach3, exit"
492 fail "(timeout) after attach3, exit"
496 # Another "don't leave a process around"
497 remote_exec build "kill -9 ${testpid}"
500 proc do_call_attach_tests {} {
504 # Start the program running and then wait for a bit, to be sure
505 # that it can be attached to.
507 set testpid [eval exec $binfile2 &]
509 if { [istarget "*-*-cygwin*"] } {
510 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
511 # different due to the way fork/exec works.
512 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
517 gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
518 send_gdb "attach $testpid\n"
520 -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
521 fail "attach call, read register 3 error"
523 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
526 -re "Attaching to.*process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
529 -re "$gdb_prompt $" {
533 fail "(timeout) attach call"
537 # See if other registers are problems
541 -re ".*warning: reading register.*$gdb_prompt $" {
542 pass "CHFts23490: known bug"
544 -re ".*r3.*$gdb_prompt $" {
545 pass "Bug fixed, Yayyy!"
547 timeout { fail "timeout on info reg" }
550 # Get rid of the process
552 gdb_test "p should_exit = 1" ".*"
553 gdb_test "c" ".*Program exited normally.*"
557 remote_exec build "kill -9 ${testpid}"
561 # Start with a fresh gdb
565 gdb_reinitialize_dir $srcdir/$subdir
568 # This is a test of gdb's ability to attach to a running process.
572 # Test attaching when the target is inside a system call
577 gdb_reinitialize_dir $srcdir/$subdir