1 # Copyright 1997, 1999, 2002 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 cleanupfile ${objdir}/${subdir}/${testfile}.awk
50 #execute_anywhere "rm -f ${binfile} ${binfile2}"
51 remote_exec build "rm -f ${binfile} ${binfile2}"
52 # For debugging this test
56 # Clean out any old files from past runs.
58 remote_exec build "${cleanupfile}"
60 # build the first test case
62 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
63 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
66 # Build the in-system-call test
68 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
69 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
72 if [get_compiler_info ${binfile}] {
76 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 &]
91 # Verify that we cannot attach to nonsense.
93 send_gdb "attach abc\n"
95 -re ".*Illegal process-id: abc.*$gdb_prompt $"\
96 {pass "attach to nonsense is prohibited"}
97 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
99 # Response expected from /proc-based systems.
100 pass "attach to nonsense is prohibited"
102 -re "Attaching to.*$gdb_prompt $"\
103 {fail "attach to nonsense is prohibited (bogus pid allowed)"}
104 -re "$gdb_prompt $" {fail "attach to nonsense is prohibited"}
105 timeout {fail "(timeout) attach to nonsense is prohibited"}
108 # Verify that we cannot attach to what appears to be a valid
109 # process ID, but is a process that doesn't exist. Traditionally,
110 # most systems didn't have a process with ID 0, so we take that as
111 # the default. However, there are a few exceptions.
114 if { [istarget "*-*-freebsd*"] } {
115 # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
116 # (which should have the desired effect on any version of FreeBSD).
119 send_gdb "attach $boguspid\n"
121 -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $"\
123 # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
124 pass "attach to nonexistent process is prohibited"
126 -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $"\
128 # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
129 pass "attach to nonexistent process is prohibited"
131 -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $"\
132 {pass "attach to nonexistent process is prohibited"}
133 -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $"\
134 {pass "attach to nonexistent process is prohibited"}
135 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
137 # Response expected from /proc-based systems.
138 pass "attach to nonexistent process is prohibited"
140 -re "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
142 fail "(timeout) attach to nonexistent process is prohibited"
146 # Verify that we can attach to the process by first giving its
147 # executable name via the file command, and using attach with
150 # (Actually, the test system appears to do this automatically
151 # for us. So, we must also be prepared to be asked if we want
152 # to discard an existing set of symbols.)
154 send_gdb "file $binfile\n"
156 -re "Load new symbol table from.*y or n.*$" {
159 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
160 {pass "(re)set file, before attach1"}
161 -re "$gdb_prompt $" {fail "(re)set file, before attach1"}
162 timeout {fail "(timeout) (re)set file, before attach1"}
165 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
166 {pass "set file, before attach1"}
167 -re "$gdb_prompt $" {fail "set file, before attach1"}
168 timeout {fail "(timeout) set file, before attach1"}
171 send_gdb "attach $testpid\n"
173 -re "Attaching to program.*`?$binfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
174 {pass "attach1, after setting file"}
175 -re "$gdb_prompt $" {fail "attach1, after setting file"}
176 timeout {fail "(timeout) attach1, after setting file"}
179 # Verify that we can "see" the variable "should_exit" in the
180 # program, and that it is zero.
182 send_gdb "print should_exit\n"
184 -re ".* = 0.*$gdb_prompt $"\
185 {pass "after attach1, print should_exit"}
186 -re "$gdb_prompt $" {fail "after attach1, print should_exit"}
187 timeout {fail "(timeout) after attach1, print should_exit"}
190 # Detach the process.
194 -re "Detaching from program: .*$binfile.*$gdb_prompt $"\
195 {pass "attach1 detach"}
196 -re "$gdb_prompt $" {fail "attach1 detach"}
197 timeout {fail "(timeout) attach1 detach"}
200 # Wait a bit for gdb to finish detaching
204 # Purge the symbols from gdb's brain. (We want to be certain
205 # the next attach, which won't be preceded by a "file" command,
206 # is really getting the executable file without our help.)
208 set old_timeout $timeout
212 -re ".*gdb internal error.*$" {
213 fail "Internal error, prob. Memory corruption"
215 -re "No executable file now.*Discard symbol table.*y or n.*$" {
218 -re "No symbol file now.*$gdb_prompt $"\
219 {pass "attach1, purging symbols after detach"}
220 -re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
221 timeout {fail "(timeout) attach1, purging symbols after detach"}
224 -re "$gdb_prompt $" {fail "attach1, purging file after detach"}
226 fail "(timeout) attach1, purging file after detach"
229 set timeout $old_timeout
231 # Verify that we can attach to the process just by giving the
234 send_gdb "attach $testpid\n"
236 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
238 -re "$gdb_prompt $" {fail "attach2"}
239 timeout {fail "(timeout) attach2"}
242 # Verify that we can modify the variable "should_exit" in the
245 send_gdb "set should_exit=1\n"
247 -re "$gdb_prompt $" {pass "after attach2, set should_exit"}
248 timeout {fail "(timeout) after attach2, set should_exit"}
251 # Verify that the modification really happened.
253 send_gdb "tbreak 19\n"
255 -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
256 {pass "after attach2, set tbreak postloop"}
257 -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
258 timeout {fail "(timeout) after attach2, set tbreak postloop"}
260 send_gdb "continue\n"
262 -re "main.*at.*$srcfile:19.*$gdb_prompt $"\
263 {pass "after attach2, reach tbreak postloop"}
264 -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"}
265 timeout {fail "(timeout) after attach2, reach tbreak postloop"}
268 # Allow the test process to exit, to cleanup after ourselves.
270 send_gdb "continue\n"
272 -re "Program exited normally.*$gdb_prompt $"\
273 {pass "after attach2, exit"}
274 -re "$gdb_prompt $" {fail "after attach2, exit"}
275 timeout {fail "(timeout) after attach2, exit"}
278 # Make sure we don't leave a process around to confuse
279 # the next test run (and prevent the compile by keeping
280 # the text file busy), in case the "set should_exit" didn't
283 remote_exec build "kill -9 ${testpid}"
284 # Start the program running and then wait for a bit, to be sure
285 # that it can be attached to.
287 set testpid [eval exec $binfile &]
290 # Verify that we can attach to the process, and find its a.out
291 # when we're cd'd to some directory that doesn't contain the
292 # a.out. (We use the source path set by the "dir" command.)
294 send_gdb "dir ${objdir}/${subdir}\n"
296 -re ".*Source directories searched: .*$gdb_prompt $"\
297 {pass "set source path"}
298 -re "$gdb_prompt $" {fail "set source path"}
299 timeout {fail "(timeout) set source path"}
304 -re ".*Working directory /tmp.*$gdb_prompt $"\
305 {pass "cd away from process' a.out"}
306 -re "$gdb_prompt $" {fail "cd away from process' a.out"}
307 timeout {fail "(timeout) cd away from process' a.out"}
310 # Explicitly flush out any knowledge of the previous attachment.
313 -re ".*Discard symbol table from.*y or n. $"\
316 -re ".*No symbol file now.*$gdb_prompt $"\
317 {pass "before attach3, flush symbols"}
318 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
319 timeout {fail "(timeout) before attach3, flush symbols"}
322 -re ".*No symbol file now.*$gdb_prompt $"\
323 {pass "before attach3, flush symbols"}
324 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
325 timeout {fail "(timeout) before attach3, flush symbols"}
329 -re ".*No executable file now.*$gdb_prompt $"\
330 {pass "before attach3, flush exec"}
331 -re "$gdb_prompt $" {fail "before attach3, flush exec"}
332 timeout {fail "(timeout) before attach3, flush exec"}
335 send_gdb "attach $testpid\n"
337 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
338 {pass "attach when process' a.out not in cwd"}
339 -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
340 timeout {fail "(timeout) attach when process' a.out not in cwd"}
345 -re ".*Kill the program being debugged.*y or n. $"\
348 -re "$gdb_prompt $" {pass "after attach3, exit"}
349 timeout {fail "(timeout) after attach3, exit"}
352 -re "$gdb_prompt $" {fail "after attach3, exit"}
353 timeout {fail "(timeout) after attach3, exit"}
357 proc do_call_attach_tests {} {
361 # Start the program running and then wait for a bit, to be sure
362 # that it can be attached to.
364 set testpid [eval exec $binfile2 &]
369 gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
370 send_gdb "attach $testpid\n"
372 -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
373 fail "attach call, read register 3 error"
375 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
378 -re "$gdb_prompt $" {fail "attach call"}
379 timeout {fail "(timeout) attach call"}
382 # See if other registers are problems
386 -re ".*warning: reading register.*$gdb_prompt $" {
387 pass "CHFts23490: known bug"
389 -re ".*r3.*$gdb_prompt $" {
390 pass "Bug fixed, Yayyy!"
392 timeout { fail "timeout on info reg" }
395 # Get rid of the process
397 gdb_test "p should_exit = 1" ".*"
398 gdb_test "c" ".*Program exited normally.*"
402 remote_exec build "kill -9 ${testpid}"
407 # Start with a fresh gdb
411 gdb_reinitialize_dir $srcdir/$subdir
414 # This is a test of gdb's ability to attach to a running process.
418 # Test attaching when the target is inside a system call
423 gdb_reinitialize_dir $srcdir/$subdir