1 # Copyright 1997-2013 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 {
34 set srcfile ${testfile}.c
35 set srcfile2 ${testfile}2.c
36 set binfile ${objdir}/${subdir}/${testfile}
37 set binfile2 ${objdir}/${subdir}/${testfile}2
38 set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
40 #execute_anywhere "rm -f ${binfile} ${binfile2}"
41 remote_exec build "rm -f ${binfile} ${binfile2}"
42 # For debugging this test
46 # build the first test case
48 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
53 # Build the in-system-call test
55 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
60 if [get_compiler_info] {
64 proc do_attach_tests {} {
74 # Start the program running and then wait for a bit, to be sure
75 # that it can be attached to.
77 set testpid [eval exec $binfile &]
79 if { [istarget "*-*-cygwin*"] } {
80 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
81 # different due to the way fork/exec works.
82 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
85 # Verify that we cannot attach to nonsense.
87 set test "attach to nonsense is prohibited"
88 gdb_test_multiple "attach abc" "$test" {
89 -re "Illegal process-id: abc\\.\r\n$gdb_prompt $" {
92 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
93 # Response expected from /proc-based systems.
96 -re "Can't attach to process..*$gdb_prompt $" {
97 # Response expected on Cygwin
100 -re "Attaching to.*$gdb_prompt $" {
101 fail "$test (bogus pid allowed)"
105 # Verify that we cannot attach to nonsense even if its initial part is
108 set test "attach to digits-starting nonsense is prohibited"
109 gdb_test_multiple "attach ${testpid}x" "$test" {
110 -re "Illegal process-id: ${testpid}x\\.\r\n$gdb_prompt $" {
113 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
114 # Response expected from /proc-based systems.
117 -re "Can't attach to process..*$gdb_prompt $" {
118 # Response expected on Cygwin
121 -re "Attaching to.*$gdb_prompt $" {
122 fail "$test (bogus pid allowed)"
126 # Verify that we cannot attach to what appears to be a valid
127 # process ID, but is a process that doesn't exist. Traditionally,
128 # most systems didn't have a process with ID 0, so we take that as
129 # the default. However, there are a few exceptions.
132 if { [istarget "*-*-*bsd*"] } {
133 # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
134 # (which should have the desired effect on any version of
135 # FreeBSD, and probably other *BSD's too).
138 set test "attach to nonexistent process is prohibited"
139 gdb_test_multiple "attach $boguspid" "$test" {
140 -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $" {
141 # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
144 -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $" {
145 # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
148 -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $" {
151 -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $" {
154 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
155 # Response expected from /proc-based systems.
158 -re "Can't attach to process..*$gdb_prompt $" {
159 # Response expected on Cygwin
162 -re "Attaching to.*, process $boguspid.*failed.*$gdb_prompt $" {
163 # Response expected on the extended-remote target.
168 # Verify that we can attach to the process by first giving its
169 # executable name via the file command, and using attach with the
172 # (Actually, the test system appears to do this automatically for
173 # us. So, we must also be prepared to be asked if we want to
174 # discard an existing set of symbols.)
176 set test "set file, before attach1"
177 gdb_test_multiple "file $binfile" "$test" {
178 -re "Load new symbol table from.*y or n. $" {
179 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
182 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
187 set test "attach1, after setting file"
188 gdb_test_multiple "attach $testpid" "$test" {
189 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $" {
192 -re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
193 # Response expected on Cygwin
198 # Verify that we can "see" the variable "should_exit" in the
199 # program, and that it is zero.
201 gdb_test "print should_exit" " = 0" "after attach1, print should_exit"
203 # Detach the process.
206 "Detaching from program: .*$escapedbinfile, process $testpid" \
209 # Wait a bit for gdb to finish detaching
213 # Purge the symbols from gdb's brain. (We want to be certain the
214 # next attach, which won't be preceded by a "file" command, is
215 # really getting the executable file without our help.)
217 set old_timeout $timeout
219 set test "attach1, purging symbols after detach"
220 gdb_test_multiple "file" "$test" {
221 -re "No executable file now.*Discard symbol table.*y or n. $" {
222 gdb_test "y" "No symbol file now." "$test"
225 set timeout $old_timeout
227 # Verify that we can attach to the process just by giving the
230 set test "attach2, with no file"
231 set found_exec_file 0
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 set found_exec_file 1
243 -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $" {
245 set found_exec_file 1
249 if {$found_exec_file == 0} {
250 set test "load file manually, after attach2"
251 gdb_test_multiple "file $binfile" "$test" {
252 -re "A program is being debugged already..*Are you sure you want to change the file.*y or n. $" {
253 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
256 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
262 # Verify that we can modify the variable "should_exit" in the
265 gdb_test_no_output "set should_exit=1" "after attach2, set should_exit"
267 # Verify that the modification really happened.
269 gdb_test "tbreak 19" "Temporary breakpoint .*at.*$srcfile, line 19.*" \
270 "after attach2, set tbreak postloop"
272 gdb_test "continue" "main.*at.*$srcfile:19.*" \
273 "after attach2, reach tbreak postloop"
275 # Allow the test process to exit, to cleanup after ourselves.
277 gdb_continue_to_end "after attach2, exit"
279 # Make sure we don't leave a process around to confuse
280 # the next test run (and prevent the compile by keeping
281 # the text file busy), in case the "set should_exit" didn't
284 remote_exec build "kill -9 ${testpid}"
286 # Start the program running and then wait for a bit, to be sure
287 # that it can be attached to.
289 set testpid [eval exec $binfile &]
291 if { [istarget "*-*-cygwin*"] } {
292 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
293 # different due to the way fork/exec works.
294 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
297 # Verify that we can attach to the process, and find its a.out
298 # when we're cd'd to some directory that doesn't contain the
299 # a.out. (We use the source path set by the "dir" command.)
301 gdb_test "dir ${objdir}/${subdir}" "Source directories searched: .*" \
304 gdb_test "cd /tmp" "Working directory /tmp." \
305 "cd away from process working directory"
307 # Explicitly flush out any knowledge of the previous attachment.
309 set test "before attach3, flush symbols"
310 gdb_test_multiple "symbol-file" "$test" {
311 -re "Discard symbol table from.*y or n. $" {
312 gdb_test "y" "No symbol file now." \
315 -re "No symbol file now.*$gdb_prompt $" {
320 gdb_test "exec" "No executable file now." \
321 "before attach3, flush exec"
323 gdb_test "attach $testpid" \
324 "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*" \
325 "attach when process' a.out not in cwd"
327 set test "after attach3, exit"
331 "Kill the program being debugged.*y or n. $" \
334 # Another "don't leave a process around"
335 remote_exec build "kill -9 ${testpid}"
338 proc do_call_attach_tests {} {
342 # Start the program running and then wait for a bit, to be sure
343 # that it can be attached to.
345 set testpid [eval exec $binfile2 &]
347 if { [istarget "*-*-cygwin*"] } {
348 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
349 # different due to the way fork/exec works.
350 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
355 gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
356 set test "attach call"
357 gdb_test_multiple "attach $testpid" "$test" {
358 -re "warning: reading register.*I.*O error.*$gdb_prompt $" {
359 fail "$test (read register error)"
361 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
364 -re "Attaching to.*process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
369 # See if other registers are problems
371 set test "info other register"
372 gdb_test_multiple "i r r3" "$test" {
373 -re "warning: reading register.*$gdb_prompt $" {
376 -re "r3.*$gdb_prompt $" {
381 # Get rid of the process
383 gdb_test "p should_exit = 1"
388 remote_exec build "kill -9 ${testpid}"
392 # Start with a fresh gdb
396 gdb_reinitialize_dir $srcdir/$subdir
399 # This is a test of gdb's ability to attach to a running process.
403 # Test attaching when the target is inside a system call
408 gdb_reinitialize_dir $srcdir/$subdir