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 # Because we can't attach over nfs, copy binfile to /tmp/${binfile}.${pid}
67 # and replace binfile with a symbolic link
70 exec /bin/cp -f ${binfile} /tmp/attach1.${pid}
72 set binfile /tmp/attach1.${pid}
73 # exec ln -s /tmp/attach1.${pid} ${binfile}
75 # Build the in-system-call test
77 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
78 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
81 # Because we can't attach over nfs, copy binfile2 to /tmp/${binfile2}.${pid}
82 # and replace binfile2 with a symbolic link
85 exec cp -f ${binfile2} /tmp/attach2.${pid}
86 exec rm -f ${binfile2}
87 set binfile2 /tmp/attach2.${pid}
88 # exec ln -s /tmp/attach2.${pid} ${binfile2}
91 if [get_compiler_info ${binfile}] {
95 proc do_attach_tests {} {
104 # Start the program running and then wait for a bit, to be sure
105 # that it can be attached to.
107 set testpid [eval exec $binfile &]
110 # Verify that we cannot attach to nonsense.
112 send_gdb "attach abc\n"
114 -re ".*Illegal process-id: abc.*$gdb_prompt $"\
115 {pass "attach to nonsense is prohibited"}
116 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
118 # Response expected from /proc-based systems.
119 pass "attach to nonsense is prohibited"
121 -re "Attaching to.*$gdb_prompt $"\
122 {fail "attach to nonsense is prohibited (bogus pid allowed)"}
123 -re "$gdb_prompt $" {fail "attach to nonsense is prohibited"}
124 timeout {fail "(timeout) attach to nonsense is prohibited"}
127 # Verify that we cannot attach to what appears to be a valid
128 # process ID, but is a process that doesn't exist. (I don't
129 # believe any process is ever assigned #0, at least on HPUX.)
131 send_gdb "attach 0\n"
133 -re "Attaching to.*, process 0.*No such process.*$gdb_prompt $"\
135 # Response expected on HP-UX 10.20 (i.e., ptrace-based).
136 pass "attach to nonexistent process is prohibited"
138 -re "Attaching to.*, process 0 failed.*Hint.*$gdb_prompt $"\
140 # Response expected on HP-UX 11.0 (i.e., ttrace-based).
141 pass "attach to nonexistent process is prohibited"
143 -re "Attaching to.*, process 0.*denied.*$gdb_prompt $"\
144 {pass "attach to nonexistent process is prohibited"}
145 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
147 # Response expected from /proc-based systems.
148 pass "attach to nonexistent process is prohibited"
150 -re "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
151 timeout {fail "(timeout) attach to nonexistent process is prohibited"}
154 # Verify that we can attach to the process by first giving its
155 # executable name via the file command, and using attach with
158 # (Actually, the test system appears to do this automatically
159 # for us. So, we must also be prepared to be asked if we want
160 # to discard an existing set of symbols.)
162 send_gdb "file $binfile\n"
164 -re "Load new symbol table from.*y or n.*$" {
167 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
168 {pass "(re)set file, before attach1"}
169 -re "$gdb_prompt $" {fail "(re)set file, before attach1"}
170 timeout {fail "(timeout) (re)set file, before attach1"}
173 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
174 {pass "set file, before attach1"}
175 -re "$gdb_prompt $" {fail "set file, before attach1"}
176 timeout {fail "(timeout) set file, before attach1"}
179 send_gdb "attach $testpid\n"
181 -re "Attaching to program.*`?$binfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
182 {pass "attach1, after setting file"}
183 -re "$gdb_prompt $" {fail "attach1, after setting file"}
184 timeout {fail "(timeout) attach1, after setting file"}
187 # Verify that we can "see" the variable "should_exit" in the
188 # program, and that it is zero.
190 send_gdb "print should_exit\n"
192 -re ".* = 0.*$gdb_prompt $"\
193 {pass "after attach1, print should_exit"}
194 -re "$gdb_prompt $" {fail "after attach1, print should_exit"}
195 timeout {fail "(timeout) after attach1, print should_exit"}
198 # Detach the process.
202 -re "Detaching from program: .*$binfile.*$gdb_prompt $"\
203 {pass "attach1 detach"}
204 -re "$gdb_prompt $" {fail "attach1 detach"}
205 timeout {fail "(timeout) attach1 detach"}
208 # Wait a bit for gdb to finish detaching
212 # Purge the symbols from gdb's brain. (We want to be certain
213 # the next attach, which won't be preceded by a "file" command,
214 # is really getting the executable file without our help.)
216 set old_timeout $timeout
220 -re ".*gdb internal error.*$" {
221 fail "Internal error, prob. Memory corruption"
223 -re "No executable file now.*Discard symbol table.*y or n.*$" {
226 -re "No symbol file now.*$gdb_prompt $"\
227 {pass "attach1, purging symbols after detach"}
228 -re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
229 timeout {fail "(timeout) attach1, purging symbols after detach"}
232 -re "$gdb_prompt $" {fail "attach1, purging file after detach"}
234 fail "(timeout) attach1, purging file after detach"
237 set timeout $old_timeout
239 # Verify that we can attach to the process just by giving the
242 send_gdb "attach $testpid\n"
244 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
246 -re "$gdb_prompt $" {fail "attach2"}
247 timeout {fail "(timeout) attach2"}
250 # Verify that we can modify the variable "should_exit" in the
253 send_gdb "set should_exit=1\n"
255 -re "$gdb_prompt $" {pass "after attach2, set should_exit"}
256 timeout {fail "(timeout) after attach2, set should_exit"}
259 # Verify that the modification really happened.
261 send_gdb "tbreak 19\n"
263 -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
264 {pass "after attach2, set tbreak postloop"}
265 -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
266 timeout {fail "(timeout) after attach2, set tbreak postloop"}
268 send_gdb "continue\n"
270 -re "main.*at.*$srcfile:19.*$gdb_prompt $"\
271 {pass "after attach2, reach tbreak postloop"}
272 -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"}
273 timeout {fail "(timeout) after attach2, reach tbreak postloop"}
276 # Allow the test process to exit, to cleanup after ourselves.
278 send_gdb "continue\n"
280 -re "Program exited normally.*$gdb_prompt $"\
281 {pass "after attach2, exit"}
282 -re "$gdb_prompt $" {fail "after attach2, exit"}
283 timeout {fail "(timeout) after attach2, exit"}
286 # Make sure we don't leave a process around to confuse
287 # the next test run (and prevent the compile by keeping
288 # the text file busy), in case the "set should_exit" didn't
291 remote_exec build "kill -9 ${testpid}"
292 # Start the program running and then wait for a bit, to be sure
293 # that it can be attached to.
295 set testpid [eval exec $binfile &]
298 # Verify that we can attach to the process, and find its a.out
299 # when we're cd'd to some directory that doesn't contain the
300 # a.out. (We use the source path set by the "dir" command.)
302 send_gdb "dir ${objdir}/${subdir}\n"
304 -re ".*Source directories searched: .*$gdb_prompt $"\
305 {pass "set source path"}
306 -re "$gdb_prompt $" {fail "set source path"}
307 timeout {fail "(timeout) set source path"}
312 -re ".*Working directory /tmp.*$gdb_prompt $"\
313 {pass "cd away from process' a.out"}
314 -re "$gdb_prompt $" {fail "cd away from process' a.out"}
315 timeout {fail "(timeout) cd away from process' a.out"}
318 # Explicitly flush out any knowledge of the previous attachment.
321 -re ".*Discard symbol table from.*y or n. $"\
324 -re ".*No symbol file now.*$gdb_prompt $"\
325 {pass "before attach3, flush symbols"}
326 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
327 timeout {fail "(timeout) before attach3, flush symbols"}
330 -re ".*No symbol file now.*$gdb_prompt $"\
331 {pass "before attach3, flush symbols"}
332 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
333 timeout {fail "(timeout) before attach3, flush symbols"}
337 -re ".*No executable file now.*$gdb_prompt $"\
338 {pass "before attach3, flush exec"}
339 -re "$gdb_prompt $" {fail "before attach3, flush exec"}
340 timeout {fail "(timeout) before attach3, flush exec"}
343 send_gdb "attach $testpid\n"
345 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
346 {pass "attach when process' a.out not in cwd"}
347 -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
348 timeout {fail "(timeout) attach when process' a.out not in cwd"}
353 -re ".*Kill the program being debugged.*y or n. $"\
356 -re "$gdb_prompt $" {pass "after attach3, exit"}
357 timeout {fail "(timeout) after attach3, exit"}
360 -re "$gdb_prompt $" {fail "after attach3, exit"}
361 timeout {fail "(timeout) after attach3, exit"}
365 proc do_call_attach_tests {} {
369 # Start the program running and then wait for a bit, to be sure
370 # that it can be attached to.
372 set testpid [eval exec $binfile2 &]
377 gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
378 send_gdb "attach $testpid\n"
380 -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
381 fail "attach call, read register 3 error"
383 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
386 -re "$gdb_prompt $" {fail "attach call"}
387 timeout {fail "(timeout) attach call"}
390 # See if other registers are problems
394 -re ".*warning: reading register.*$gdb_prompt $" {
395 pass "CHFts23490: known bug"
397 -re ".*r3.*$gdb_prompt $" {
398 pass "Bug fixed, Yayyy!"
400 timeout { fail "timeout on info reg" }
403 # Get rid of the process
405 gdb_test "p should_exit = 1" ".*"
406 gdb_test "c" ".*Program exited normally.*"
410 remote_exec build "kill -9 ${testpid}"
415 # Start with a fresh gdb
419 gdb_reinitialize_dir $srcdir/$subdir
422 # This is a test of gdb's ability to attach to a running process.
426 # Test attaching when the target is inside a system call
431 # this seems not necessary. - guo
433 # # Since we have moved the executable to /tmp, it will be hard for gdb
434 # # to find the object file/executable to read the symbols. This is
435 # # a known limitation. We try and get the name of the executable the
436 # # process is running from a variety of methods, but none is foolproof.
437 # # Using "dir" will get us the symbols.
439 # gdb_test "dir ./gdb.base" ".*" "set up directory before attach"
440 gdb_reinitialize_dir $srcdir/$subdir
443 # Cleanup the files placed in /tmp and the symlinks
444 remote_exec build "rm -f ${binfile} ${binfile2} /tmp/attach1.${pid} /tmp/attach2.${pid}"