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}]
47 #execute_anywhere "rm -f ${binfile} ${binfile2}"
48 remote_exec build "rm -f ${binfile} ${binfile2}"
49 # For debugging this test
53 # build the first test case
55 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
56 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
59 # Build the in-system-call test
61 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
62 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
65 if [get_compiler_info ${binfile}] {
69 proc do_attach_tests {} {
79 # Start the program running and then wait for a bit, to be sure
80 # that it can be attached to.
82 set testpid [eval exec $binfile &]
84 if { [istarget "*-*-cygwin*"] } {
85 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
86 # different due to the way fork/exec works.
87 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
90 # Verify that we cannot attach to nonsense.
92 set test "attach to nonsense is prohibited"
93 gdb_test_multiple "attach abc" "$test" {
94 -re "Illegal process-id: abc.*$gdb_prompt $" {
97 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
98 # Response expected from /proc-based systems.
101 -re "Can't attach to process..*$gdb_prompt $" {
102 # Response expected on Cygwin
105 -re "Attaching to.*$gdb_prompt $" {
106 fail "$test (bogus pid allowed)"
110 # Verify that we cannot attach to what appears to be a valid
111 # process ID, but is a process that doesn't exist. Traditionally,
112 # most systems didn't have a process with ID 0, so we take that as
113 # the default. However, there are a few exceptions.
116 if { [istarget "*-*-*bsd*"] } {
117 # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
118 # (which should have the desired effect on any version of
119 # FreeBSD, and probably other *BSD's too).
122 set test "attach to nonexistent process is prohibited"
123 gdb_test_multiple "attach $boguspid" "$test" {
124 -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $" {
125 # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
128 -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $" {
129 # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
132 -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $" {
135 -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $" {
138 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
139 # Response expected from /proc-based systems.
142 -re "Can't attach to process..*$gdb_prompt $" {
143 # Response expected on Cygwin
148 # Verify that we can attach to the process by first giving its
149 # executable name via the file command, and using attach with the
152 # (Actually, the test system appears to do this automatically for
153 # us. So, we must also be prepared to be asked if we want to
154 # discard an existing set of symbols.)
156 set test "set file, before attach1"
157 gdb_test_multiple "file $binfile" "$test" {
158 -re "Load new symbol table from.*y or n. $" {
159 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
162 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
167 set test "attach1, after setting file"
168 gdb_test_multiple "attach $testpid" "$test" {
169 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $" {
172 -re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
173 # Response expected on Cygwin
178 # Verify that we can "see" the variable "should_exit" in the
179 # program, and that it is zero.
181 gdb_test "print should_exit" " = 0" "after attach1, print should_exit"
183 # Detach the process.
186 "Detaching from program: .*$escapedbinfile, process $testpid" \
189 # Wait a bit for gdb to finish detaching
193 # Purge the symbols from gdb's brain. (We want to be certain the
194 # next attach, which won't be preceded by a "file" command, is
195 # really getting the executable file without our help.)
197 set old_timeout $timeout
199 set test "attach1, purging symbols after detach"
200 gdb_test_multiple "file" "$test" {
201 -re "No executable file now.*Discard symbol table.*y or n. $" {
202 gdb_test "y" "No symbol file now." "$test"
205 set timeout $old_timeout
207 # Verify that we can attach to the process just by giving the
210 set test "set file, before attach2"
211 gdb_test_multiple "attach $testpid" "$test" {
212 -re "Attaching to process $testpid.*Load new symbol table from \"$escapedbinfile\.exe\".*y or n. $" {
213 # On Cygwin, the DLL's symbol tables are loaded prior to the
214 # executable's symbol table. This in turn always results in
215 # asking the user for actually loading the symbol table of the
217 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
220 -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $" {
225 # Verify that we can modify the variable "should_exit" in the
228 gdb_test "set should_exit=1" "" "after attach2, set should_exit"
230 # Verify that the modification really happened.
232 send_gdb "tbreak 19\n"
234 -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $" {
235 pass "after attach2, set tbreak postloop"
237 -re "$gdb_prompt $" {
238 fail "after attach2, set tbreak postloop"
241 fail "(timeout) after attach2, set tbreak postloop"
244 send_gdb "continue\n"
246 -re "main.*at.*$srcfile:19.*$gdb_prompt $" {
247 pass "after attach2, reach tbreak postloop"
249 -re "$gdb_prompt $" {
250 fail "after attach2, reach tbreak postloop"
253 fail "(timeout) after attach2, reach tbreak postloop"
257 # Allow the test process to exit, to cleanup after ourselves.
259 gdb_test "continue" "Program exited normally." "after attach2, exit"
261 # Make sure we don't leave a process around to confuse
262 # the next test run (and prevent the compile by keeping
263 # the text file busy), in case the "set should_exit" didn't
266 remote_exec build "kill -9 ${testpid}"
268 # Start the program running and then wait for a bit, to be sure
269 # that it can be attached to.
271 set testpid [eval exec $binfile &]
273 if { [istarget "*-*-cygwin*"] } {
274 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
275 # different due to the way fork/exec works.
276 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
279 # Verify that we can attach to the process, and find its a.out
280 # when we're cd'd to some directory that doesn't contain the
281 # a.out. (We use the source path set by the "dir" command.)
283 gdb_test "dir ${objdir}/${subdir}" "Source directories searched: .*" \
286 gdb_test "cd /tmp" "Working directory /tmp." \
287 "cd away from process working directory"
289 # Explicitly flush out any knowledge of the previous attachment.
291 set test "before attach3, flush symbols"
292 gdb_test_multiple "symbol" "$test" {
293 -re "Discard symbol table from.*y or n. $" {
294 gdb_test "y" "No symbol file now." \
297 -re "No symbol file now.*$gdb_prompt $" {
302 gdb_test "exec" "No executable file now." \
303 "before attach3, flush exec"
305 gdb_test "attach $testpid" \
306 "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*" \
307 "attach when process' a.out not in cwd"
309 set test "after attach3, exit"
310 gdb_test_multiple "kill" "$test" {
311 -re "Kill the program being debugged.*y or n. $" {
312 gdb_test "y" "" "$test"
316 # Another "don't leave a process around"
317 remote_exec build "kill -9 ${testpid}"
320 proc do_call_attach_tests {} {
324 # Start the program running and then wait for a bit, to be sure
325 # that it can be attached to.
327 set testpid [eval exec $binfile2 &]
329 if { [istarget "*-*-cygwin*"] } {
330 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
331 # different due to the way fork/exec works.
332 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
337 gdb_test "file $binfile2" "" "force switch to gdb64, if necessary"
338 set test "attach call"
339 gdb_test_multiple "attach $testpid" "$test" {
340 -re "warning: reading register.*I.*O error.*$gdb_prompt $" {
341 fail "$test (read register error)"
343 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
346 -re "Attaching to.*process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
351 # See if other registers are problems
353 set test "info other register"
354 gdb_test_multiple "i r r3" "$test" {
355 -re "warning: reading register.*$gdb_prompt $" {
358 -re "r3.*$gdb_prompt $" {
363 # Get rid of the process
365 gdb_test "p should_exit = 1"
366 gdb_test "c" "Program exited normally."
370 remote_exec build "kill -9 ${testpid}"
374 # Start with a fresh gdb
378 gdb_reinitialize_dir $srcdir/$subdir
381 # This is a test of gdb's ability to attach to a running process.
385 # Test attaching when the target is inside a system call
390 gdb_reinitialize_dir $srcdir/$subdir