1 # Copyright 1997, 1999, 2002, 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. */
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
27 # On HP-UX 11.0, this test is causing a process running the program
28 # "attach" to be left around spinning. Until we figure out why, I am
29 # commenting out the test to avoid polluting tiamat (our 11.0 nightly
30 # test machine) with these processes. RT
32 # Setting the magic bit in the target app should work. I added a
33 # "kill", and also a test for the R3 register warning. JB
34 if { [istarget "hppa*-*-hpux*"] } {
38 # are we on a target board
39 if [is_remote target] then {
44 set srcfile ${testfile}.c
45 set srcfile2 ${testfile}2.c
46 set binfile ${objdir}/${subdir}/${testfile}
47 set binfile2 ${objdir}/${subdir}/${testfile}2
48 set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
49 set cleanupfile ${objdir}/${subdir}/${testfile}.awk
51 #execute_anywhere "rm -f ${binfile} ${binfile2}"
52 remote_exec build "rm -f ${binfile} ${binfile2}"
53 # For debugging this test
57 # Clean out any old files from past runs.
59 remote_exec build "${cleanupfile}"
61 # build the first test case
63 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
64 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
67 # Build the in-system-call test
69 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
70 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
73 if [get_compiler_info ${binfile}] {
77 proc do_attach_tests {} {
87 # Start the program running and then wait for a bit, to be sure
88 # that it can be attached to.
90 set testpid [eval exec $binfile &]
93 # Verify that we cannot attach to nonsense.
95 send_gdb "attach abc\n"
97 -re ".*Illegal process-id: abc.*$gdb_prompt $"\
98 {pass "attach to nonsense is prohibited"}
99 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
101 # Response expected from /proc-based systems.
102 pass "attach to nonsense is prohibited"
104 -re "Attaching to.*$gdb_prompt $"\
105 {fail "attach to nonsense is prohibited (bogus pid allowed)"}
106 -re "$gdb_prompt $" {fail "attach to nonsense is prohibited"}
107 timeout {fail "(timeout) attach to nonsense is prohibited"}
110 # Verify that we cannot attach to what appears to be a valid
111 # process ID, but is a process that doesn't exist. Traditionally,
112 # most systems didn't have a process with ID 0, so we take that as
113 # the default. However, there are a few exceptions.
116 if { [istarget "*-*-*bsd*"] } {
117 # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
118 # (which should have the desired effect on any version of
119 # FreeBSD, and probably other *BSD's too).
122 send_gdb "attach $boguspid\n"
124 -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $"\
126 # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
127 pass "attach to nonexistent process is prohibited"
129 -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $"\
131 # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
132 pass "attach to nonexistent process is prohibited"
134 -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $"\
135 {pass "attach to nonexistent process is prohibited"}
136 -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $"\
137 {pass "attach to nonexistent process is prohibited"}
138 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
140 # Response expected from /proc-based systems.
141 pass "attach to nonexistent process is prohibited"
143 -re "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
145 fail "(timeout) attach to nonexistent process is prohibited"
149 # Verify that we can attach to the process by first giving its
150 # executable name via the file command, and using attach with
153 # (Actually, the test system appears to do this automatically
154 # for us. So, we must also be prepared to be asked if we want
155 # to discard an existing set of symbols.)
157 send_gdb "file $binfile\n"
159 -re "Load new symbol table from.*y or n.*$" {
162 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
163 {pass "(re)set file, before attach1"}
164 -re "$gdb_prompt $" {fail "(re)set file, before attach1"}
165 timeout {fail "(timeout) (re)set file, before attach1"}
168 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
169 {pass "set file, before attach1"}
170 -re "$gdb_prompt $" {fail "set file, before attach1"}
171 timeout {fail "(timeout) set file, before attach1"}
174 send_gdb "attach $testpid\n"
176 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
177 {pass "attach1, after setting file"}
178 -re "$gdb_prompt $" {fail "attach1, after setting file"}
179 timeout {fail "(timeout) attach1, after setting file"}
182 # Verify that we can "see" the variable "should_exit" in the
183 # program, and that it is zero.
185 send_gdb "print should_exit\n"
187 -re ".* = 0.*$gdb_prompt $"\
188 {pass "after attach1, print should_exit"}
189 -re "$gdb_prompt $" {fail "after attach1, print should_exit"}
190 timeout {fail "(timeout) after attach1, print should_exit"}
193 # Detach the process.
197 -re "Detaching from program: .*$escapedbinfile.*$gdb_prompt $"\
198 {pass "attach1 detach"}
199 -re "$gdb_prompt $" {fail "attach1 detach"}
200 timeout {fail "(timeout) attach1 detach"}
203 # Wait a bit for gdb to finish detaching
207 # Purge the symbols from gdb's brain. (We want to be certain
208 # the next attach, which won't be preceded by a "file" command,
209 # is really getting the executable file without our help.)
211 set old_timeout $timeout
215 -re ".*gdb internal error.*$" {
216 fail "Internal error, prob. Memory corruption"
218 -re "No executable file now.*Discard symbol table.*y or n.*$" {
221 -re "No symbol file now.*$gdb_prompt $"\
222 {pass "attach1, purging symbols after detach"}
223 -re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
224 timeout {fail "(timeout) attach1, purging symbols after detach"}
227 -re "$gdb_prompt $" {fail "attach1, purging file after detach"}
229 fail "(timeout) attach1, purging file after detach"
232 set timeout $old_timeout
234 # Verify that we can attach to the process just by giving the
237 send_gdb "attach $testpid\n"
239 -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
241 -re "$gdb_prompt $" {fail "attach2"}
242 timeout {fail "(timeout) attach2"}
245 # Verify that we can modify the variable "should_exit" in the
248 send_gdb "set should_exit=1\n"
250 -re "$gdb_prompt $" {pass "after attach2, set should_exit"}
251 timeout {fail "(timeout) after attach2, set should_exit"}
254 # Verify that the modification really happened.
256 send_gdb "tbreak 19\n"
258 -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
259 {pass "after attach2, set tbreak postloop"}
260 -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
261 timeout {fail "(timeout) after attach2, set tbreak postloop"}
263 send_gdb "continue\n"
265 -re "main.*at.*$srcfile:19.*$gdb_prompt $"\
266 {pass "after attach2, reach tbreak postloop"}
267 -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"}
268 timeout {fail "(timeout) after attach2, reach tbreak postloop"}
271 # Allow the test process to exit, to cleanup after ourselves.
273 send_gdb "continue\n"
275 -re "Program exited normally.*$gdb_prompt $"\
276 {pass "after attach2, exit"}
277 -re "$gdb_prompt $" {fail "after attach2, exit"}
278 timeout {fail "(timeout) after attach2, exit"}
281 # Make sure we don't leave a process around to confuse
282 # the next test run (and prevent the compile by keeping
283 # the text file busy), in case the "set should_exit" didn't
286 remote_exec build "kill -9 ${testpid}"
287 # Start the program running and then wait for a bit, to be sure
288 # that it can be attached to.
290 set testpid [eval exec $binfile &]
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 send_gdb "dir ${objdir}/${subdir}\n"
299 -re ".*Source directories searched: .*$gdb_prompt $"\
300 {pass "set source path"}
301 -re "$gdb_prompt $" {fail "set source path"}
302 timeout {fail "(timeout) set source path"}
307 -re ".*Working directory /tmp.*$gdb_prompt $"\
308 {pass "cd away from process' a.out"}
309 -re "$gdb_prompt $" {fail "cd away from process' a.out"}
310 timeout {fail "(timeout) cd away from process' a.out"}
313 # Explicitly flush out any knowledge of the previous attachment.
316 -re ".*Discard symbol table from.*y or n. $"\
319 -re ".*No symbol file now.*$gdb_prompt $"\
320 {pass "before attach3, flush symbols"}
321 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
322 timeout {fail "(timeout) before attach3, flush symbols"}
325 -re ".*No symbol file now.*$gdb_prompt $"\
326 {pass "before attach3, flush symbols"}
327 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
328 timeout {fail "(timeout) before attach3, flush symbols"}
332 -re ".*No executable file now.*$gdb_prompt $"\
333 {pass "before attach3, flush exec"}
334 -re "$gdb_prompt $" {fail "before attach3, flush exec"}
335 timeout {fail "(timeout) before attach3, flush exec"}
338 send_gdb "attach $testpid\n"
340 -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
341 {pass "attach when process' a.out not in cwd"}
342 -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
343 timeout {fail "(timeout) attach when process' a.out not in cwd"}
348 -re ".*Kill the program being debugged.*y or n. $"\
351 -re "$gdb_prompt $" {pass "after attach3, exit"}
352 timeout {fail "(timeout) after attach3, exit"}
355 -re "$gdb_prompt $" {fail "after attach3, exit"}
356 timeout {fail "(timeout) after attach3, exit"}
359 # Another "don't leave a process around"
360 remote_exec build "kill -9 ${testpid}"
363 proc do_call_attach_tests {} {
367 # Start the program running and then wait for a bit, to be sure
368 # that it can be attached to.
370 set testpid [eval exec $binfile2 &]
375 gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
376 send_gdb "attach $testpid\n"
378 -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
379 fail "attach call, read register 3 error"
381 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
384 -re "$gdb_prompt $" {fail "attach call"}
385 timeout {fail "(timeout) attach call"}
388 # See if other registers are problems
392 -re ".*warning: reading register.*$gdb_prompt $" {
393 pass "CHFts23490: known bug"
395 -re ".*r3.*$gdb_prompt $" {
396 pass "Bug fixed, Yayyy!"
398 timeout { fail "timeout on info reg" }
401 # Get rid of the process
403 gdb_test "p should_exit = 1" ".*"
404 gdb_test "c" ".*Program exited normally.*"
408 remote_exec build "kill -9 ${testpid}"
413 # Start with a fresh gdb
417 gdb_reinitialize_dir $srcdir/$subdir
420 # This is a test of gdb's ability to attach to a running process.
424 # Test attaching when the target is inside a system call
429 gdb_reinitialize_dir $srcdir/$subdir