1 # Copyright 1997, 1999, 2002, 2003, 2004, 2007, 2008, 2009, 2010
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 # On HP-UX 11.0, this test is causing a process running the program
23 # "attach" to be left around spinning. Until we figure out why, I am
24 # commenting out the test to avoid polluting tiamat (our 11.0 nightly
25 # test machine) with these processes. RT
27 # Setting the magic bit in the target app should work. I added a
28 # "kill", and also a test for the R3 register warning. JB
29 if { [istarget "hppa*-*-hpux*"] } {
33 # are we on a target board
34 if [is_remote target] then {
39 set srcfile ${testfile}.c
40 set srcfile2 ${testfile}2.c
41 set binfile ${objdir}/${subdir}/${testfile}
42 set binfile2 ${objdir}/${subdir}/${testfile}2
43 set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
45 #execute_anywhere "rm -f ${binfile} ${binfile2}"
46 remote_exec build "rm -f ${binfile} ${binfile2}"
47 # For debugging this test
51 # build the first test case
53 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
58 # Build the in-system-call test
60 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
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\\.\r\n$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 nonsense even if its initial part is
113 set test "attach to digits-starting nonsense is prohibited"
114 gdb_test_multiple "attach ${testpid}x" "$test" {
115 -re "Illegal process-id: ${testpid}x\\.\r\n$gdb_prompt $" {
118 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
119 # Response expected from /proc-based systems.
122 -re "Can't attach to process..*$gdb_prompt $" {
123 # Response expected on Cygwin
126 -re "Attaching to.*$gdb_prompt $" {
127 fail "$test (bogus pid allowed)"
131 # Verify that we cannot attach to what appears to be a valid
132 # process ID, but is a process that doesn't exist. Traditionally,
133 # most systems didn't have a process with ID 0, so we take that as
134 # the default. However, there are a few exceptions.
137 if { [istarget "*-*-*bsd*"] } {
138 # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
139 # (which should have the desired effect on any version of
140 # FreeBSD, and probably other *BSD's too).
143 set test "attach to nonexistent process is prohibited"
144 gdb_test_multiple "attach $boguspid" "$test" {
145 -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $" {
146 # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
149 -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $" {
150 # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
153 -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $" {
156 -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $" {
159 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
160 # Response expected from /proc-based systems.
163 -re "Can't attach to process..*$gdb_prompt $" {
164 # Response expected on Cygwin
169 # Verify that we can attach to the process by first giving its
170 # executable name via the file command, and using attach with the
173 # (Actually, the test system appears to do this automatically for
174 # us. So, we must also be prepared to be asked if we want to
175 # discard an existing set of symbols.)
177 set test "set file, before attach1"
178 gdb_test_multiple "file $binfile" "$test" {
179 -re "Load new symbol table from.*y or n. $" {
180 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
183 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
188 set test "attach1, after setting file"
189 gdb_test_multiple "attach $testpid" "$test" {
190 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $" {
193 -re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
194 # Response expected on Cygwin
199 # Verify that we can "see" the variable "should_exit" in the
200 # program, and that it is zero.
202 gdb_test "print should_exit" " = 0" "after attach1, print should_exit"
204 # Detach the process.
207 "Detaching from program: .*$escapedbinfile, process $testpid" \
210 # Wait a bit for gdb to finish detaching
214 # Purge the symbols from gdb's brain. (We want to be certain the
215 # next attach, which won't be preceded by a "file" command, is
216 # really getting the executable file without our help.)
218 set old_timeout $timeout
220 set test "attach1, purging symbols after detach"
221 gdb_test_multiple "file" "$test" {
222 -re "No executable file now.*Discard symbol table.*y or n. $" {
223 gdb_test "y" "No symbol file now." "$test"
226 set timeout $old_timeout
228 # Verify that we can attach to the process just by giving the
231 set test "set file, before attach2"
232 gdb_test_multiple "attach $testpid" "$test" {
233 -re "Attaching to process $testpid.*Load new symbol table from \"$escapedbinfile\.exe\".*y or n. $" {
234 # On Cygwin, the DLL's symbol tables are loaded prior to the
235 # executable's symbol table. This in turn always results in
236 # asking the user for actually loading the symbol table of the
238 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
241 -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $" {
246 # Verify that we can modify the variable "should_exit" in the
249 gdb_test_no_output "set should_exit=1" "after attach2, set should_exit"
251 # Verify that the modification really happened.
253 gdb_test "tbreak 19" "Temporary breakpoint .*at.*$srcfile, line 19.*" \
254 "after attach2, set tbreak postloop"
256 gdb_test "continue" "main.*at.*$srcfile:19.*" \
257 "after attach2, reach tbreak postloop"
259 # Allow the test process to exit, to cleanup after ourselves.
261 gdb_test "continue" "Program exited normally." "after attach2, exit"
263 # Make sure we don't leave a process around to confuse
264 # the next test run (and prevent the compile by keeping
265 # the text file busy), in case the "set should_exit" didn't
268 remote_exec build "kill -9 ${testpid}"
270 # Start the program running and then wait for a bit, to be sure
271 # that it can be attached to.
273 set testpid [eval exec $binfile &]
275 if { [istarget "*-*-cygwin*"] } {
276 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
277 # different due to the way fork/exec works.
278 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
281 # Verify that we can attach to the process, and find its a.out
282 # when we're cd'd to some directory that doesn't contain the
283 # a.out. (We use the source path set by the "dir" command.)
285 gdb_test "dir ${objdir}/${subdir}" "Source directories searched: .*" \
288 gdb_test "cd /tmp" "Working directory /tmp." \
289 "cd away from process working directory"
291 # Explicitly flush out any knowledge of the previous attachment.
293 set test "before attach3, flush symbols"
294 gdb_test_multiple "symbol-file" "$test" {
295 -re "Discard symbol table from.*y or n. $" {
296 gdb_test "y" "No symbol file now." \
299 -re "No symbol file now.*$gdb_prompt $" {
304 gdb_test "exec" "No executable file now." \
305 "before attach3, flush exec"
307 gdb_test "attach $testpid" \
308 "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*" \
309 "attach when process' a.out not in cwd"
311 set test "after attach3, exit"
312 gdb_test_multiple "kill" "$test" {
313 -re "Kill the program being debugged.*y or n. $" {
314 gdb_test "y" "" "$test"
318 # Another "don't leave a process around"
319 remote_exec build "kill -9 ${testpid}"
322 proc do_call_attach_tests {} {
326 # Start the program running and then wait for a bit, to be sure
327 # that it can be attached to.
329 set testpid [eval exec $binfile2 &]
331 if { [istarget "*-*-cygwin*"] } {
332 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
333 # different due to the way fork/exec works.
334 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
339 gdb_test "file $binfile2" "" "force switch to gdb64, if necessary"
340 set test "attach call"
341 gdb_test_multiple "attach $testpid" "$test" {
342 -re "warning: reading register.*I.*O error.*$gdb_prompt $" {
343 fail "$test (read register error)"
345 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
348 -re "Attaching to.*process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
353 # See if other registers are problems
355 set test "info other register"
356 gdb_test_multiple "i r r3" "$test" {
357 -re "warning: reading register.*$gdb_prompt $" {
360 -re "r3.*$gdb_prompt $" {
365 # Get rid of the process
367 gdb_test "p should_exit = 1"
368 gdb_test "c" "Program exited normally."
372 remote_exec build "kill -9 ${testpid}"
376 # Start with a fresh gdb
380 gdb_reinitialize_dir $srcdir/$subdir
383 # This is a test of gdb's ability to attach to a running process.
387 # Test attaching when the target is inside a system call
392 gdb_reinitialize_dir $srcdir/$subdir