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. (I don't
110 # believe any process is ever assigned #0, at least on HPUX.)
112 send_gdb "attach 0\n"
114 -re "Attaching to.*, process 0.*No such process.*$gdb_prompt $"\
116 # Response expected on HP-UX 10.20 (i.e., ptrace-based).
117 pass "attach to nonexistent process is prohibited"
119 -re "Attaching to.*, process 0 failed.*Hint.*$gdb_prompt $"\
121 # Response expected on HP-UX 11.0 (i.e., ttrace-based).
122 pass "attach to nonexistent process is prohibited"
124 -re "Attaching to.*, process 0.*denied.*$gdb_prompt $"\
125 {pass "attach to nonexistent process is prohibited"}
126 -re "Attaching to.*, process 0.*Operation not permitted.*$gdb_prompt $"\
127 {pass "attach to nonexistent process is prohibited"}
128 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
130 # Response expected from /proc-based systems.
131 pass "attach to nonexistent process is prohibited"
133 -re "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
134 timeout {fail "(timeout) attach to nonexistent process is prohibited"}
137 # Verify that we can attach to the process by first giving its
138 # executable name via the file command, and using attach with
141 # (Actually, the test system appears to do this automatically
142 # for us. So, we must also be prepared to be asked if we want
143 # to discard an existing set of symbols.)
145 send_gdb "file $binfile\n"
147 -re "Load new symbol table from.*y or n.*$" {
150 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
151 {pass "(re)set file, before attach1"}
152 -re "$gdb_prompt $" {fail "(re)set file, before attach1"}
153 timeout {fail "(timeout) (re)set file, before attach1"}
156 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
157 {pass "set file, before attach1"}
158 -re "$gdb_prompt $" {fail "set file, before attach1"}
159 timeout {fail "(timeout) set file, before attach1"}
162 send_gdb "attach $testpid\n"
164 -re "Attaching to program.*`?$binfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
165 {pass "attach1, after setting file"}
166 -re "$gdb_prompt $" {fail "attach1, after setting file"}
167 timeout {fail "(timeout) attach1, after setting file"}
170 # Verify that we can "see" the variable "should_exit" in the
171 # program, and that it is zero.
173 send_gdb "print should_exit\n"
175 -re ".* = 0.*$gdb_prompt $"\
176 {pass "after attach1, print should_exit"}
177 -re "$gdb_prompt $" {fail "after attach1, print should_exit"}
178 timeout {fail "(timeout) after attach1, print should_exit"}
181 # Detach the process.
185 -re "Detaching from program: .*$binfile.*$gdb_prompt $"\
186 {pass "attach1 detach"}
187 -re "$gdb_prompt $" {fail "attach1 detach"}
188 timeout {fail "(timeout) attach1 detach"}
191 # Wait a bit for gdb to finish detaching
195 # Purge the symbols from gdb's brain. (We want to be certain
196 # the next attach, which won't be preceded by a "file" command,
197 # is really getting the executable file without our help.)
199 set old_timeout $timeout
203 -re ".*gdb internal error.*$" {
204 fail "Internal error, prob. Memory corruption"
206 -re "No executable file now.*Discard symbol table.*y or n.*$" {
209 -re "No symbol file now.*$gdb_prompt $"\
210 {pass "attach1, purging symbols after detach"}
211 -re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
212 timeout {fail "(timeout) attach1, purging symbols after detach"}
215 -re "$gdb_prompt $" {fail "attach1, purging file after detach"}
217 fail "(timeout) attach1, purging file after detach"
220 set timeout $old_timeout
222 # Verify that we can attach to the process just by giving the
225 send_gdb "attach $testpid\n"
227 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
229 -re "$gdb_prompt $" {fail "attach2"}
230 timeout {fail "(timeout) attach2"}
233 # Verify that we can modify the variable "should_exit" in the
236 send_gdb "set should_exit=1\n"
238 -re "$gdb_prompt $" {pass "after attach2, set should_exit"}
239 timeout {fail "(timeout) after attach2, set should_exit"}
242 # Verify that the modification really happened.
244 send_gdb "tbreak 19\n"
246 -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
247 {pass "after attach2, set tbreak postloop"}
248 -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
249 timeout {fail "(timeout) after attach2, set tbreak postloop"}
251 send_gdb "continue\n"
253 -re "main.*at.*$srcfile:19.*$gdb_prompt $"\
254 {pass "after attach2, reach tbreak postloop"}
255 -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"}
256 timeout {fail "(timeout) after attach2, reach tbreak postloop"}
259 # Allow the test process to exit, to cleanup after ourselves.
261 send_gdb "continue\n"
263 -re "Program exited normally.*$gdb_prompt $"\
264 {pass "after attach2, exit"}
265 -re "$gdb_prompt $" {fail "after attach2, exit"}
266 timeout {fail "(timeout) after attach2, exit"}
269 # Make sure we don't leave a process around to confuse
270 # the next test run (and prevent the compile by keeping
271 # the text file busy), in case the "set should_exit" didn't
274 remote_exec build "kill -9 ${testpid}"
275 # Start the program running and then wait for a bit, to be sure
276 # that it can be attached to.
278 set testpid [eval exec $binfile &]
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 send_gdb "dir ${objdir}/${subdir}\n"
287 -re ".*Source directories searched: .*$gdb_prompt $"\
288 {pass "set source path"}
289 -re "$gdb_prompt $" {fail "set source path"}
290 timeout {fail "(timeout) set source path"}
295 -re ".*Working directory /tmp.*$gdb_prompt $"\
296 {pass "cd away from process' a.out"}
297 -re "$gdb_prompt $" {fail "cd away from process' a.out"}
298 timeout {fail "(timeout) cd away from process' a.out"}
301 # Explicitly flush out any knowledge of the previous attachment.
304 -re ".*Discard symbol table from.*y or n. $"\
307 -re ".*No symbol file now.*$gdb_prompt $"\
308 {pass "before attach3, flush symbols"}
309 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
310 timeout {fail "(timeout) before attach3, flush symbols"}
313 -re ".*No symbol file now.*$gdb_prompt $"\
314 {pass "before attach3, flush symbols"}
315 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
316 timeout {fail "(timeout) before attach3, flush symbols"}
320 -re ".*No executable file now.*$gdb_prompt $"\
321 {pass "before attach3, flush exec"}
322 -re "$gdb_prompt $" {fail "before attach3, flush exec"}
323 timeout {fail "(timeout) before attach3, flush exec"}
326 send_gdb "attach $testpid\n"
328 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
329 {pass "attach when process' a.out not in cwd"}
330 -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
331 timeout {fail "(timeout) attach when process' a.out not in cwd"}
336 -re ".*Kill the program being debugged.*y or n. $"\
339 -re "$gdb_prompt $" {pass "after attach3, exit"}
340 timeout {fail "(timeout) after attach3, exit"}
343 -re "$gdb_prompt $" {fail "after attach3, exit"}
344 timeout {fail "(timeout) after attach3, exit"}
348 proc do_call_attach_tests {} {
352 # Start the program running and then wait for a bit, to be sure
353 # that it can be attached to.
355 set testpid [eval exec $binfile2 &]
360 gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
361 send_gdb "attach $testpid\n"
363 -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
364 fail "attach call, read register 3 error"
366 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
369 -re "$gdb_prompt $" {fail "attach call"}
370 timeout {fail "(timeout) attach call"}
373 # See if other registers are problems
377 -re ".*warning: reading register.*$gdb_prompt $" {
378 pass "CHFts23490: known bug"
380 -re ".*r3.*$gdb_prompt $" {
381 pass "Bug fixed, Yayyy!"
383 timeout { fail "timeout on info reg" }
386 # Get rid of the process
388 gdb_test "p should_exit = 1" ".*"
389 gdb_test "c" ".*Program exited normally.*"
393 remote_exec build "kill -9 ${testpid}"
398 # Start with a fresh gdb
402 gdb_reinitialize_dir $srcdir/$subdir
405 # This is a test of gdb's ability to attach to a running process.
409 # Test attaching when the target is inside a system call
414 gdb_reinitialize_dir $srcdir/$subdir