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 set test "attach to nonsense is prohibited"
98 gdb_test_multiple "attach abc" "$test" {
99 -re "Illegal process-id: abc.*$gdb_prompt $" {
102 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
103 # Response expected from /proc-based systems.
106 -re "Can't attach to process..*$gdb_prompt $" {
107 # Response expected on Cygwin
110 -re "Attaching to.*$gdb_prompt $" {
111 fail "$test (bogus pid allowed)"
115 # Verify that we cannot attach to what appears to be a valid
116 # process ID, but is a process that doesn't exist. Traditionally,
117 # most systems didn't have a process with ID 0, so we take that as
118 # the default. However, there are a few exceptions.
121 if { [istarget "*-*-*bsd*"] } {
122 # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
123 # (which should have the desired effect on any version of
124 # FreeBSD, and probably other *BSD's too).
127 set test "attach to nonexistent process is prohibited"
128 gdb_test_multiple "attach $boguspid" "$test" {
129 -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $" {
130 # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
133 -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $" {
134 # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
137 -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $" {
140 -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $" {
143 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
144 # Response expected from /proc-based systems.
147 -re "Can't attach to process..*$gdb_prompt $" {
148 # Response expected on Cygwin
153 # Verify that we can attach to the process by first giving its
154 # executable name via the file command, and using attach with the
157 # (Actually, the test system appears to do this automatically for
158 # us. So, we must also be prepared to be asked if we want to
159 # discard an existing set of symbols.)
161 set test "set file, before attach1"
162 gdb_test_multiple "file $binfile" "$test" {
163 -re "Load new symbol table from.*y or n. $" {
164 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
167 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
172 set test "attach1, after setting file"
173 gdb_test_multiple "attach $testpid" "$test" {
174 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $" {
177 -re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
178 # Response expected on Cygwin
183 # Verify that we can "see" the variable "should_exit" in the
184 # program, and that it is zero.
186 gdb_test "print should_exit" " = 0" "after attach1, print should_exit"
188 # Detach the process.
191 "Detaching from program: .*$escapedbinfile, process $testpid" \
194 # Wait a bit for gdb to finish detaching
198 # Purge the symbols from gdb's brain. (We want to be certain the
199 # next attach, which won't be preceded by a "file" command, is
200 # really getting the executable file without our help.)
202 set old_timeout $timeout
204 set test "attach1, purging symbols after detach"
205 gdb_test_multiple "file" "$test" {
206 -re "No executable file now.*Discard symbol table.*y or n. $" {
207 gdb_test "y" "No symbol file now." "$test"
210 set timeout $old_timeout
212 # Verify that we can attach to the process just by giving the
215 set test "set file, before attach2"
216 gdb_test_multiple "attach $testpid" "$test" {
217 -re "Attaching to process $testpid.*Load new symbol table from \"$escapedbinfile\.exe\".*y or n. $" {
218 # On Cygwin, the DLL's symbol tables are loaded prior to the
219 # executable's symbol table. This in turn always results in
220 # asking the user for actually loading the symbol table of the
222 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
225 -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $" {
230 # Verify that we can modify the variable "should_exit" in the
233 gdb_test "set should_exit=1" "" "after attach2, set should_exit"
235 # Verify that the modification really happened.
237 send_gdb "tbreak 19\n"
239 -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $" {
240 pass "after attach2, set tbreak postloop"
242 -re "$gdb_prompt $" {
243 fail "after attach2, set tbreak postloop"
246 fail "(timeout) after attach2, set tbreak postloop"
249 send_gdb "continue\n"
251 -re "main.*at.*$srcfile:19.*$gdb_prompt $" {
252 pass "after attach2, reach tbreak postloop"
254 -re "$gdb_prompt $" {
255 fail "after attach2, reach tbreak postloop"
258 fail "(timeout) after attach2, reach tbreak postloop"
262 # Allow the test process to exit, to cleanup after ourselves.
264 gdb_test "continue" "Program exited normally." "after attach2, exit"
266 # Make sure we don't leave a process around to confuse
267 # the next test run (and prevent the compile by keeping
268 # the text file busy), in case the "set should_exit" didn't
271 remote_exec build "kill -9 ${testpid}"
273 # Start the program running and then wait for a bit, to be sure
274 # that it can be attached to.
276 set testpid [eval exec $binfile &]
278 if { [istarget "*-*-cygwin*"] } {
279 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
280 # different due to the way fork/exec works.
281 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
284 # Verify that we can attach to the process, and find its a.out
285 # when we're cd'd to some directory that doesn't contain the
286 # a.out. (We use the source path set by the "dir" command.)
288 gdb_test "dir ${objdir}/${subdir}" "Source directories searched: .*" \
291 gdb_test "cd /tmp" "Working directory /tmp." \
292 "cd away from process working directory"
294 # Explicitly flush out any knowledge of the previous attachment.
296 set test "before attach3, flush symbols"
297 gdb_test_multiple "symbol" "$test" {
298 -re "Discard symbol table from.*y or n. $" {
299 gdb_test "y" "No symbol file now." \
302 -re "No symbol file now.*$gdb_prompt $" {
307 gdb_test "exec" "No executable file now." \
308 "before attach3, flush exec"
310 gdb_test "attach $testpid" \
311 "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*" \
312 "attach when process' a.out not in cwd"
314 set test "after attach3, exit"
315 gdb_test_multiple "kill" "$test" {
316 -re "Kill the program being debugged.*y or n. $" {
317 gdb_test "y" "" "$test"
321 # Another "don't leave a process around"
322 remote_exec build "kill -9 ${testpid}"
325 proc do_call_attach_tests {} {
329 # Start the program running and then wait for a bit, to be sure
330 # that it can be attached to.
332 set testpid [eval exec $binfile2 &]
334 if { [istarget "*-*-cygwin*"] } {
335 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
336 # different due to the way fork/exec works.
337 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
342 gdb_test "file $binfile2" "" "force switch to gdb64, if necessary"
343 set test "attach call"
344 gdb_test_multiple "attach $testpid" "$test" {
345 -re "warning: reading register.*I.*O error.*$gdb_prompt $" {
346 fail "$test (read register error)"
348 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
351 -re "Attaching to.*process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
356 # See if other registers are problems
358 set test "info other register"
359 gdb_test_multiple "i r r3" "$test" {
360 -re "warning: reading register.*$gdb_prompt $" {
363 -re "r3.*$gdb_prompt $" {
368 # Get rid of the process
370 gdb_test "p should_exit = 1"
371 gdb_test "c" "Program exited normally."
375 remote_exec build "kill -9 ${testpid}"
379 # Start with a fresh gdb
383 gdb_reinitialize_dir $srcdir/$subdir
386 # This is a test of gdb's ability to attach to a running process.
390 # Test attaching when the target is inside a system call
395 gdb_reinitialize_dir $srcdir/$subdir