1 # Copyright 1997-2014 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/>. */
17 # On HP-UX 11.0, this test is causing a process running the program
18 # "attach" to be left around spinning. Until we figure out why, I am
19 # commenting out the test to avoid polluting tiamat (our 11.0 nightly
20 # test machine) with these processes. RT
22 # Setting the magic bit in the target app should work. I added a
23 # "kill", and also a test for the R3 register warning. JB
24 if { [istarget "hppa*-*-hpux*"] } {
28 # are we on a target board
29 if [is_remote target] then {
33 standard_testfile attach.c attach2.c
34 set binfile2 ${binfile}2
35 set escapedbinfile [string_to_regexp $binfile]
37 #execute_anywhere "rm -f ${binfile} ${binfile2}"
38 remote_exec build "rm -f ${binfile} ${binfile2}"
39 # For debugging this test
43 # build the first test case
45 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
50 # Build the in-system-call test
52 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
57 if [get_compiler_info] {
61 proc do_attach_tests {} {
70 # Start the program running and then wait for a bit, to be sure
71 # that it can be attached to.
73 set testpid [eval exec $binfile &]
75 if { [istarget "*-*-cygwin*"] } {
76 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
77 # different due to the way fork/exec works.
78 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
81 # Verify that we cannot attach to nonsense.
83 set test "attach to nonsense is prohibited"
84 gdb_test_multiple "attach abc" "$test" {
85 -re "Illegal process-id: abc\\.\r\n$gdb_prompt $" {
88 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
89 # Response expected from /proc-based systems.
92 -re "Can't attach to process..*$gdb_prompt $" {
93 # Response expected on Cygwin
96 -re "Attaching to.*$gdb_prompt $" {
97 fail "$test (bogus pid allowed)"
101 # Verify that we cannot attach to nonsense even if its initial part is
104 set test "attach to digits-starting nonsense is prohibited"
105 gdb_test_multiple "attach ${testpid}x" "$test" {
106 -re "Illegal process-id: ${testpid}x\\.\r\n$gdb_prompt $" {
109 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
110 # Response expected from /proc-based systems.
113 -re "Can't attach to process..*$gdb_prompt $" {
114 # Response expected on Cygwin
117 -re "Attaching to.*$gdb_prompt $" {
118 fail "$test (bogus pid allowed)"
122 # Verify that we cannot attach to what appears to be a valid
123 # process ID, but is a process that doesn't exist. Traditionally,
124 # most systems didn't have a process with ID 0, so we take that as
125 # the default. However, there are a few exceptions.
128 if { [istarget "*-*-*bsd*"] } {
129 # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
130 # (which should have the desired effect on any version of
131 # FreeBSD, and probably other *BSD's too).
134 set test "attach to nonexistent process is prohibited"
135 gdb_test_multiple "attach $boguspid" "$test" {
136 -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $" {
137 # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
140 -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $" {
141 # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
144 -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $" {
147 -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $" {
150 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
151 # Response expected from /proc-based systems.
154 -re "Can't attach to process..*$gdb_prompt $" {
155 # Response expected on Cygwin
158 -re "Attaching to.*, process $boguspid.*failed.*$gdb_prompt $" {
159 # Response expected on the extended-remote target.
164 # Verify that we can attach to the process by first giving its
165 # executable name via the file command, and using attach with the
168 # (Actually, the test system appears to do this automatically for
169 # us. So, we must also be prepared to be asked if we want to
170 # discard an existing set of symbols.)
172 set test "set file, before attach1"
173 gdb_test_multiple "file $binfile" "$test" {
174 -re "Load new symbol table from.*y or n. $" {
175 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
178 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
183 set test "attach1, after setting file"
184 gdb_test_multiple "attach $testpid" "$test" {
185 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $" {
188 -re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
189 # Response expected on Cygwin
194 # Verify that we can "see" the variable "should_exit" in the
195 # program, and that it is zero.
197 gdb_test "print should_exit" " = 0" "after attach1, print should_exit"
199 # Detach the process.
202 "Detaching from program: .*$escapedbinfile, process $testpid" \
205 # Wait a bit for gdb to finish detaching
209 # Purge the symbols from gdb's brain. (We want to be certain the
210 # next attach, which won't be preceded by a "file" command, is
211 # really getting the executable file without our help.)
213 set old_timeout $timeout
215 set test "attach1, purging symbols after detach"
216 gdb_test_multiple "file" "$test" {
217 -re "No executable file now.*Discard symbol table.*y or n. $" {
218 gdb_test "y" "No symbol file now." "$test"
221 set timeout $old_timeout
223 # Verify that we can attach to the process just by giving the
226 set test "attach2, with no file"
227 set found_exec_file 0
228 gdb_test_multiple "attach $testpid" "$test" {
229 -re "Attaching to process $testpid.*Load new symbol table from \"$escapedbinfile\.exe\".*y or n. $" {
230 # On Cygwin, the DLL's symbol tables are loaded prior to the
231 # executable's symbol table. This in turn always results in
232 # asking the user for actually loading the symbol table of the
234 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
237 set found_exec_file 1
239 -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $" {
241 set found_exec_file 1
245 if {$found_exec_file == 0} {
246 set test "load file manually, after attach2"
247 gdb_test_multiple "file $binfile" "$test" {
248 -re "A program is being debugged already..*Are you sure you want to change the file.*y or n. $" {
249 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
252 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
258 # Verify that we can modify the variable "should_exit" in the
261 gdb_test_no_output "set should_exit=1" "after attach2, set should_exit"
263 # Verify that the modification really happened.
265 gdb_test "tbreak 19" "Temporary breakpoint .*at.*$srcfile, line 19.*" \
266 "after attach2, set tbreak postloop"
268 gdb_test "continue" "main.*at.*$srcfile:19.*" \
269 "after attach2, reach tbreak postloop"
271 # Allow the test process to exit, to cleanup after ourselves.
273 gdb_continue_to_end "after attach2, exit"
275 # Make sure we don't leave a process around to confuse
276 # the next test run (and prevent the compile by keeping
277 # the text file busy), in case the "set should_exit" didn't
280 remote_exec build "kill -9 ${testpid}"
282 # Start the program running and then wait for a bit, to be sure
283 # that it can be attached to.
285 set testpid [eval exec $binfile &]
287 if { [istarget "*-*-cygwin*"] } {
288 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
289 # different due to the way fork/exec works.
290 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
293 # Verify that we can attach to the process, and find its a.out
294 # when we're cd'd to some directory that doesn't contain the
295 # a.out. (We use the source path set by the "dir" command.)
297 gdb_test "dir [standard_output_file {}]" "Source directories searched: .*" \
300 gdb_test "cd /tmp" "Working directory /tmp." \
301 "cd away from process working directory"
303 # Explicitly flush out any knowledge of the previous attachment.
305 set test "before attach3, flush symbols"
306 gdb_test_multiple "symbol-file" "$test" {
307 -re "Discard symbol table from.*y or n. $" {
308 gdb_test "y" "No symbol file now." \
311 -re "No symbol file now.*$gdb_prompt $" {
316 gdb_test "exec" "No executable file now." \
317 "before attach3, flush exec"
319 gdb_test "attach $testpid" \
320 "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*" \
321 "attach when process' a.out not in cwd"
323 set test "after attach3, exit"
327 "Kill the program being debugged.*y or n. $" \
330 # Another "don't leave a process around"
331 remote_exec build "kill -9 ${testpid}"
334 proc do_call_attach_tests {} {
338 # Start the program running and then wait for a bit, to be sure
339 # that it can be attached to.
341 set testpid [eval exec $binfile2 &]
343 if { [istarget "*-*-cygwin*"] } {
344 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
345 # different due to the way fork/exec works.
346 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
351 gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
352 set test "attach call"
353 gdb_test_multiple "attach $testpid" "$test" {
354 -re "warning: reading register.*I.*O error.*$gdb_prompt $" {
355 fail "$test (read register error)"
357 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
360 -re "Attaching to.*process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
365 # See if other registers are problems
367 set test "info other register"
368 gdb_test_multiple "i r r3" "$test" {
369 -re "warning: reading register.*$gdb_prompt $" {
372 -re "r3.*$gdb_prompt $" {
377 # Get rid of the process
379 gdb_test "p should_exit = 1"
384 remote_exec build "kill -9 ${testpid}"
387 proc do_command_attach_tests {} {
392 global INTERNAL_GDBFLAGS
395 if ![isnative] then {
396 unsupported "command attach test"
400 # Start the program running and then wait for a bit, to be sure
401 # that it can be attached to.
403 set testpid [eval exec $binfile &]
405 if { [istarget "*-*-cygwin*"] } {
406 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
407 # different due to the way fork/exec works.
408 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
413 send_user "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS --pid=$testpid\n"
416 eval "spawn $GDB $INTERNAL_GDBFLAGS $GDBFLAGS --pid=$testpid"
417 set test "starting with --pid"
419 -re "Reading symbols from.*$gdb_prompt $" {
423 fail "$test (timeout)"
427 # Get rid of the process
429 remote_exec build "kill -9 ${testpid}"
433 # Start with a fresh gdb
437 gdb_reinitialize_dir $srcdir/$subdir
440 # This is a test of gdb's ability to attach to a running process.
444 # Test attaching when the target is inside a system call
449 gdb_reinitialize_dir $srcdir/$subdir
454 do_command_attach_tests