1 # Copyright 1997, 1999, 2002, 2003, 2004, 2007 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 3 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, see <http://www.gnu.org/licenses/>. */
23 # On HP-UX 11.0, this test is causing a process running the program
24 # "attach" to be left around spinning. Until we figure out why, I am
25 # commenting out the test to avoid polluting tiamat (our 11.0 nightly
26 # test machine) with these processes. RT
28 # Setting the magic bit in the target app should work. I added a
29 # "kill", and also a test for the R3 register warning. JB
30 if { [istarget "hppa*-*-hpux*"] } {
34 # On SPU, this test currently fails because "sleep" is not supported.
35 if { [istarget "spu*-*-*"] } {
39 # are we on a target board
40 if [is_remote target] then {
45 set srcfile ${testfile}.c
46 set srcfile2 ${testfile}2.c
47 set binfile ${objdir}/${subdir}/${testfile}
48 set binfile2 ${objdir}/${subdir}/${testfile}2
49 set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
51 #execute_anywhere "rm -f ${binfile} ${binfile2}"
52 remote_exec build "rm -f ${binfile} ${binfile2}"
53 # For debugging this test
57 # build the first test case
59 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
64 # Build the in-system-call test
66 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
71 if [get_compiler_info ${binfile}] {
75 proc do_attach_tests {} {
85 # Start the program running and then wait for a bit, to be sure
86 # that it can be attached to.
88 set testpid [eval exec $binfile &]
90 if { [istarget "*-*-cygwin*"] } {
91 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
92 # different due to the way fork/exec works.
93 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
96 # Verify that we cannot attach to nonsense.
98 set test "attach to nonsense is prohibited"
99 gdb_test_multiple "attach abc" "$test" {
100 -re "Illegal process-id: abc.*$gdb_prompt $" {
103 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
104 # Response expected from /proc-based systems.
107 -re "Can't attach to process..*$gdb_prompt $" {
108 # Response expected on Cygwin
111 -re "Attaching to.*$gdb_prompt $" {
112 fail "$test (bogus pid allowed)"
116 # Verify that we cannot attach to what appears to be a valid
117 # process ID, but is a process that doesn't exist. Traditionally,
118 # most systems didn't have a process with ID 0, so we take that as
119 # the default. However, there are a few exceptions.
122 if { [istarget "*-*-*bsd*"] } {
123 # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
124 # (which should have the desired effect on any version of
125 # FreeBSD, and probably other *BSD's too).
128 set test "attach to nonexistent process is prohibited"
129 gdb_test_multiple "attach $boguspid" "$test" {
130 -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $" {
131 # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
134 -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $" {
135 # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
138 -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $" {
141 -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $" {
144 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
145 # Response expected from /proc-based systems.
148 -re "Can't attach to process..*$gdb_prompt $" {
149 # Response expected on Cygwin
154 # Verify that we can attach to the process by first giving its
155 # executable name via the file command, and using attach with the
158 # (Actually, the test system appears to do this automatically for
159 # us. So, we must also be prepared to be asked if we want to
160 # discard an existing set of symbols.)
162 set test "set file, before attach1"
163 gdb_test_multiple "file $binfile" "$test" {
164 -re "Load new symbol table from.*y or n. $" {
165 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
168 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
173 set test "attach1, after setting file"
174 gdb_test_multiple "attach $testpid" "$test" {
175 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $" {
178 -re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
179 # Response expected on Cygwin
184 # Verify that we can "see" the variable "should_exit" in the
185 # program, and that it is zero.
187 gdb_test "print should_exit" " = 0" "after attach1, print should_exit"
189 # Detach the process.
192 "Detaching from program: .*$escapedbinfile, process $testpid" \
195 # Wait a bit for gdb to finish detaching
199 # Purge the symbols from gdb's brain. (We want to be certain the
200 # next attach, which won't be preceded by a "file" command, is
201 # really getting the executable file without our help.)
203 set old_timeout $timeout
205 set test "attach1, purging symbols after detach"
206 gdb_test_multiple "file" "$test" {
207 -re "No executable file now.*Discard symbol table.*y or n. $" {
208 gdb_test "y" "No symbol file now." "$test"
211 set timeout $old_timeout
213 # Verify that we can attach to the process just by giving the
216 set test "set file, before attach2"
217 gdb_test_multiple "attach $testpid" "$test" {
218 -re "Attaching to process $testpid.*Load new symbol table from \"$escapedbinfile\.exe\".*y or n. $" {
219 # On Cygwin, the DLL's symbol tables are loaded prior to the
220 # executable's symbol table. This in turn always results in
221 # asking the user for actually loading the symbol table of the
223 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
226 -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $" {
231 # Verify that we can modify the variable "should_exit" in the
234 gdb_test "set should_exit=1" "" "after attach2, set should_exit"
236 # Verify that the modification really happened.
238 send_gdb "tbreak 19\n"
240 -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $" {
241 pass "after attach2, set tbreak postloop"
243 -re "$gdb_prompt $" {
244 fail "after attach2, set tbreak postloop"
247 fail "(timeout) after attach2, set tbreak postloop"
250 send_gdb "continue\n"
252 -re "main.*at.*$srcfile:19.*$gdb_prompt $" {
253 pass "after attach2, reach tbreak postloop"
255 -re "$gdb_prompt $" {
256 fail "after attach2, reach tbreak postloop"
259 fail "(timeout) after attach2, reach tbreak postloop"
263 # Allow the test process to exit, to cleanup after ourselves.
265 gdb_test "continue" "Program exited normally." "after attach2, exit"
267 # Make sure we don't leave a process around to confuse
268 # the next test run (and prevent the compile by keeping
269 # the text file busy), in case the "set should_exit" didn't
272 remote_exec build "kill -9 ${testpid}"
274 # Start the program running and then wait for a bit, to be sure
275 # that it can be attached to.
277 set testpid [eval exec $binfile &]
279 if { [istarget "*-*-cygwin*"] } {
280 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
281 # different due to the way fork/exec works.
282 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
285 # Verify that we can attach to the process, and find its a.out
286 # when we're cd'd to some directory that doesn't contain the
287 # a.out. (We use the source path set by the "dir" command.)
289 gdb_test "dir ${objdir}/${subdir}" "Source directories searched: .*" \
292 gdb_test "cd /tmp" "Working directory /tmp." \
293 "cd away from process working directory"
295 # Explicitly flush out any knowledge of the previous attachment.
297 set test "before attach3, flush symbols"
298 gdb_test_multiple "symbol" "$test" {
299 -re "Discard symbol table from.*y or n. $" {
300 gdb_test "y" "No symbol file now." \
303 -re "No symbol file now.*$gdb_prompt $" {
308 gdb_test "exec" "No executable file now." \
309 "before attach3, flush exec"
311 gdb_test "attach $testpid" \
312 "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*" \
313 "attach when process' a.out not in cwd"
315 set test "after attach3, exit"
316 gdb_test_multiple "kill" "$test" {
317 -re "Kill the program being debugged.*y or n. $" {
318 gdb_test "y" "" "$test"
322 # Another "don't leave a process around"
323 remote_exec build "kill -9 ${testpid}"
326 proc do_call_attach_tests {} {
330 # Start the program running and then wait for a bit, to be sure
331 # that it can be attached to.
333 set testpid [eval exec $binfile2 &]
335 if { [istarget "*-*-cygwin*"] } {
336 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
337 # different due to the way fork/exec works.
338 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
343 gdb_test "file $binfile2" "" "force switch to gdb64, if necessary"
344 set test "attach call"
345 gdb_test_multiple "attach $testpid" "$test" {
346 -re "warning: reading register.*I.*O error.*$gdb_prompt $" {
347 fail "$test (read register error)"
349 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
352 -re "Attaching to.*process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
357 # See if other registers are problems
359 set test "info other register"
360 gdb_test_multiple "i r r3" "$test" {
361 -re "warning: reading register.*$gdb_prompt $" {
364 -re "r3.*$gdb_prompt $" {
369 # Get rid of the process
371 gdb_test "p should_exit = 1"
372 gdb_test "c" "Program exited normally."
376 remote_exec build "kill -9 ${testpid}"
380 # Start with a fresh gdb
384 gdb_reinitialize_dir $srcdir/$subdir
387 # This is a test of gdb's ability to attach to a running process.
391 # Test attaching when the target is inside a system call
396 gdb_reinitialize_dir $srcdir/$subdir