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
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.*$gdb_prompt $"\
117 {fail "attach to nonsense is prohibited (bogus pid allowed)"}
118 -re "$gdb_prompt $" {fail "attach to nonsense is prohibited"}
119 timeout {fail "(timeout) attach to nonsense is prohibited"}
122 # Verify that we cannot attach to what appears to be a valid
123 # process ID, but is a process that doesn't exist. (I don't
124 # believe any process is ever assigned #0, at least on HPUX.)
126 send_gdb "attach 0\n"
128 # This reponse is expected on HP-UX 10.20 (i.e., ptrace-based).
129 -re "Attaching to.*, process 0.*No such process.*$gdb_prompt $"\
130 {pass "attach to nonexistent process is prohibited"}
131 # This response is expected on HP-UX 11.0 (i.e., ttrace-based).
132 -re "Attaching to.*, process 0 failed.*Hint.*$gdb_prompt $"\
133 {pass "attach to nonexistent process is prohibited"}
134 -re "Attaching to.*, process 0.*denied.*$gdb_prompt $"\
135 {pass "attach to nonexistent process is prohibited"}
136 -re "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
137 timeout {fail "(timeout) attach to nonexistent process is prohibited"}
140 # Verify that we can attach to the process by first giving its
141 # executable name via the file command, and using attach with
144 # (Actually, the test system appears to do this automatically
145 # for us. So, we must also be prepared to be asked if we want
146 # to discard an existing set of symbols.)
148 send_gdb "file $binfile\n"
150 -re "Load new symbol table from.*y or n.*$" {
153 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
154 {pass "(re)set file, before attach1"}
155 -re "$gdb_prompt $" {fail "(re)set file, before attach1"}
156 timeout {fail "(timeout) (re)set file, before attach1"}
159 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
160 {pass "set file, before attach1"}
161 -re "$gdb_prompt $" {fail "set file, before attach1"}
162 timeout {fail "(timeout) set file, before attach1"}
165 send_gdb "attach $testpid\n"
167 -re "Attaching to program.*$binfile, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
168 {pass "attach1, after setting file"}
169 -re "$gdb_prompt $" {fail "attach1, after setting file"}
170 timeout {fail "(timeout) attach1, after setting file"}
173 # Verify that we can "see" the variable "should_exit" in the
174 # program, and that it is zero.
176 send_gdb "print should_exit\n"
178 -re ".* = 0.*$gdb_prompt $"\
179 {pass "after attach1, print should_exit"}
180 -re "$gdb_prompt $" {fail "after attach1, print should_exit"}
181 timeout {fail "(timeout) after attach1, print should_exit"}
184 # Detach the process.
188 -re "Detaching from program: .*$binfile.*$gdb_prompt $"\
189 {pass "attach1 detach"}
190 -re "$gdb_prompt $" {fail "attach1 detach"}
191 timeout {fail "(timeout) attach1 detach"}
194 # Wait a bit for gdb to finish detaching
198 # Purge the symbols from gdb's brain. (We want to be certain
199 # the next attach, which won't be preceded by a "file" command,
200 # is really getting the executable file without our help.)
202 set old_timeout $timeout
206 -re ".*gdb internal error.*$" {
207 fail "Internal error, prob. Memory corruption"
209 -re "No executable file now.*Discard symbol table.*y or n.*$" {
212 -re "No symbol file now.*$gdb_prompt $"\
213 {pass "attach1, purging symbols after detach"}
214 -re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
215 timeout {fail "(timeout) attach1, purging symbols after detach"}
218 -re "$gdb_prompt $" {fail "attach1, purging file after detach"}
220 fail "(timeout) attach1, purging file after detach"
223 set timeout $old_timeout
225 # Verify that we can attach to the process just by giving the
228 send_gdb "attach $testpid\n"
230 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
232 -re "$gdb_prompt $" {fail "attach2"}
233 timeout {fail "(timeout) attach2"}
236 # Verify that we can modify the variable "should_exit" in the
239 send_gdb "set should_exit=1\n"
241 -re "$gdb_prompt $" {pass "after attach2, set should_exit"}
242 timeout {fail "(timeout) after attach2, set should_exit"}
245 # Verify that the modification really happened.
247 send_gdb "tbreak 19\n"
249 -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
250 {pass "after attach2, set tbreak postloop"}
251 -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
252 timeout {fail "(timeout) after attach2, set tbreak postloop"}
254 send_gdb "continue\n"
256 -re "main.*at.*$srcfile:19.*$gdb_prompt $"\
257 {pass "after attach2, reach tbreak postloop"}
258 -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"}
259 timeout {fail "(timeout) after attach2, reach tbreak postloop"}
262 # Allow the test process to exit, to cleanup after ourselves.
264 send_gdb "continue\n"
266 -re "Program exited normally.*$gdb_prompt $"\
267 {pass "after attach2, exit"}
268 -re "$gdb_prompt $" {fail "after attach2, exit"}
269 timeout {fail "(timeout) after attach2, exit"}
272 # Make sure we don't leave a process around to confuse
273 # the next test run (and prevent the compile by keeping
274 # the text file busy), in case the "set should_exit" didn't
277 remote_exec build "kill -9 ${testpid}"
278 # Start the program running and then wait for a bit, to be sure
279 # that it can be attached to.
281 set testpid [eval exec $binfile &]
284 # Verify that we can attach to the process, and find its a.out
285 # when we're cd'd to some directory that doesn't contain the
286 # a.out. (We use the source path set by the "dir" command.)
288 send_gdb "dir ${objdir}/${subdir}\n"
290 -re ".*Source directories searched: .*$gdb_prompt $"\
291 {pass "set source path"}
292 -re "$gdb_prompt $" {fail "set source path"}
293 timeout {fail "(timeout) set source path"}
298 -re ".*Working directory /tmp.*$gdb_prompt $"\
299 {pass "cd away from process' a.out"}
300 -re "$gdb_prompt $" {fail "cd away from process' a.out"}
301 timeout {fail "(timeout) cd away from process' a.out"}
304 # Explicitly flush out any knowledge of the previous attachment.
307 -re ".*Discard symbol table from.*y or n. $"\
310 -re ".*No symbol file now.*$gdb_prompt $"\
311 {pass "before attach3, flush symbols"}
312 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
313 timeout {fail "(timeout) before attach3, flush symbols"}
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"}
323 -re ".*No executable file now.*$gdb_prompt $"\
324 {pass "before attach3, flush exec"}
325 -re "$gdb_prompt $" {fail "before attach3, flush exec"}
326 timeout {fail "(timeout) before attach3, flush exec"}
329 send_gdb "attach $testpid\n"
331 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
332 {pass "attach when process' a.out not in cwd"}
333 -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
334 timeout {fail "(timeout) attach when process' a.out not in cwd"}
339 -re ".*Kill the program being debugged.*y or n. $"\
342 -re "$gdb_prompt $" {pass "after attach3, exit"}
343 timeout {fail "(timeout) after attach3, exit"}
346 -re "$gdb_prompt $" {fail "after attach3, exit"}
347 timeout {fail "(timeout) after attach3, exit"}
351 proc do_call_attach_tests {} {
355 # Start the program running and then wait for a bit, to be sure
356 # that it can be attached to.
358 set testpid [eval exec $binfile2 &]
363 gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
364 send_gdb "attach $testpid\n"
366 -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
367 fail "attach call, read register 3 error"
369 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
372 -re "$gdb_prompt $" {fail "attach call"}
373 timeout {fail "(timeout) attach call"}
376 # See if other registers are problems
380 -re ".*warning: reading register.*$gdb_prompt $" {
381 pass "CHFts23490: known bug"
383 -re ".*r3.*$gdb_prompt $" {
384 pass "Bug fixed, Yayyy!"
386 timeout { fail "timeout on info reg" }
389 # Get rid of the process
391 gdb_test "p should_exit = 1" ".*"
392 gdb_test "c" ".*Program exited normally.*"
396 remote_exec build "kill -9 ${testpid}"
401 # Start with a fresh gdb
405 gdb_reinitialize_dir $srcdir/$subdir
408 # This is a test of gdb's ability to attach to a running process.
412 # Test attaching when the target is inside a system call
417 # this seems not necessary. - guo
419 # # Since we have moved the executable to /tmp, it will be hard for gdb
420 # # to find the object file/executable to read the symbols. This is
421 # # a known limitation. We try and get the name of the executable the
422 # # process is running from a variety of methods, but none is foolproof.
423 # # Using "dir" will get us the symbols.
425 # gdb_test "dir ./gdb.base" ".*" "set up directory before attach"
426 gdb_reinitialize_dir $srcdir/$subdir
429 # Cleanup the files placed in /tmp and the symlinks
430 remote_exec build "rm -f ${binfile} ${binfile2} /tmp/attach1.${pid} /tmp/attach2.${pid}"