1 # Copyright (C) 1997 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
20 # On HP-UX 11.0, this test is causing a process running
21 # the program "attach" to be left around spinning.
22 # Until we figure out why, I am commenting out the test
23 # to avoid polluting tiamat (our 11.0 nightly test machine)
24 # with these processes. RT
26 # Setting the magic bit in the target app should work.
27 # I added a "kill", and also a test for the R3 register
38 if { ![istarget "hppa*-*-hpux*"] } {
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 "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
135 timeout {fail "(timeout) attach to nonexistent process is prohibited"}
138 # Verify that we can attach to the process by first giving its
139 # executable name via the file command, and using attach with
142 # (Actually, the test system appears to do this automatically
143 # for us. So, we must also be prepared to be asked if we want
144 # to discard an existing set of symbols.)
146 send_gdb "file $binfile\n"
148 -re "Load new symbol table from.*y or n.*$" {
151 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
152 {pass "(re)set file, before attach1"}
153 -re "$gdb_prompt $" {fail "(re)set file, before attach1"}
154 timeout {fail "(timeout) (re)set file, before attach1"}
157 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
158 {pass "set file, before attach1"}
159 -re "$gdb_prompt $" {fail "set file, before attach1"}
160 timeout {fail "(timeout) set file, before attach1"}
163 send_gdb "attach $testpid\n"
165 -re "Attaching to program.*$binfile, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
166 {pass "attach1, after setting file"}
167 -re "$gdb_prompt $" {fail "attach1, after setting file"}
168 timeout {fail "(timeout) attach1, after setting file"}
171 # Verify that we can "see" the variable "should_exit" in the
172 # program, and that it is zero.
174 send_gdb "print should_exit\n"
176 -re ".* = 0.*$gdb_prompt $"\
177 {pass "after attach1, print should_exit"}
178 -re "$gdb_prompt $" {fail "after attach1, print should_exit"}
179 timeout {fail "(timeout) after attach1, print should_exit"}
182 # Detach the process.
186 -re "Detaching from program: .*$binfile.*$gdb_prompt $"\
187 {pass "attach1 detach"}
188 -re "$gdb_prompt $" {fail "attach1 detach"}
189 timeout {fail "(timeout) attach1 detach"}
192 # Wait a bit for gdb to finish detaching
196 # Purge the symbols from gdb's brain. (We want to be certain
197 # the next attach, which won't be preceded by a "file" command,
198 # is really getting the executable file without our help.)
200 set old_timeout $timeout
204 -re ".*gdb internal error.*$" {
205 fail "Internal error, prob. Memory corruption"
207 -re "No executable file now.*Discard symbol table.*y or n.*$" {
210 -re "No symbol file now.*$gdb_prompt $"\
211 {pass "attach1, purging symbols after detach"}
212 -re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
213 timeout {fail "(timeout) attach1, purging symbols after detach"}
216 -re "$gdb_prompt $" {fail "attach1, purging file after detach"}
218 fail "(timeout) attach1, purging file after detach"
221 set timeout $old_timeout
223 # Verify that we can attach to the process just by giving the
226 send_gdb "attach $testpid\n"
228 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
230 -re "$gdb_prompt $" {fail "attach2"}
231 timeout {fail "(timeout) attach2"}
234 # Verify that we can modify the variable "should_exit" in the
237 send_gdb "set should_exit=1\n"
239 -re "$gdb_prompt $" {pass "after attach2, set should_exit"}
240 timeout {fail "(timeout) after attach2, set should_exit"}
243 # Verify that the modification really happened.
245 send_gdb "tbreak 19\n"
247 -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
248 {pass "after attach2, set tbreak postloop"}
249 -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
250 timeout {fail "(timeout) after attach2, set tbreak postloop"}
252 send_gdb "continue\n"
254 -re "main.*at.*$srcfile:19.*$gdb_prompt $"\
255 {pass "after attach2, reach tbreak postloop"}
256 -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"}
257 timeout {fail "(timeout) after attach2, reach tbreak postloop"}
260 # Allow the test process to exit, to cleanup after ourselves.
262 send_gdb "continue\n"
264 -re "Program exited normally.*$gdb_prompt $"\
265 {pass "after attach2, exit"}
266 -re "$gdb_prompt $" {fail "after attach2, exit"}
267 timeout {fail "(timeout) after attach2, exit"}
270 # Make sure we don't leave a process around to confuse
271 # the next test run (and prevent the compile by keeping
272 # the text file busy), in case the "set should_exit" didn't
275 remote_exec build "kill -9 ${testpid}"
276 # Start the program running and then wait for a bit, to be sure
277 # that it can be attached to.
279 set testpid [eval exec $binfile &]
282 # Verify that we can attach to the process, and find its a.out
283 # when we're cd'd to some directory that doesn't contain the
284 # a.out. (We use the source path set by the "dir" command.)
286 send_gdb "dir ${objdir}/${subdir}\n"
288 -re ".*Source directories searched: .*$gdb_prompt $"\
289 {pass "set source path"}
290 -re "$gdb_prompt $" {fail "set source path"}
291 timeout {fail "(timeout) set source path"}
296 -re ".*Working directory /tmp.*$gdb_prompt $"\
297 {pass "cd away from process' a.out"}
298 -re "$gdb_prompt $" {fail "cd away from process' a.out"}
299 timeout {fail "(timeout) cd away from process' a.out"}
302 # Explicitly flush out any knowledge of the previous attachment.
305 -re ".*Discard symbol table from.*y or n. $"\
308 -re ".*No symbol file now.*$gdb_prompt $"\
309 {pass "before attach3, flush symbols"}
310 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
311 timeout {fail "(timeout) before attach3, flush symbols"}
314 -re ".*No symbol file now.*$gdb_prompt $"\
315 {pass "before attach3, flush symbols"}
316 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
317 timeout {fail "(timeout) before attach3, flush symbols"}
321 -re ".*No executable file now.*$gdb_prompt $"\
322 {pass "before attach3, flush exec"}
323 -re "$gdb_prompt $" {fail "before attach3, flush exec"}
324 timeout {fail "(timeout) before attach3, flush exec"}
327 send_gdb "attach $testpid\n"
329 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
330 {pass "attach when process' a.out not in cwd"}
331 -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
332 timeout {fail "(timeout) attach when process' a.out not in cwd"}
337 -re ".*Kill the program being debugged.*y or n. $"\
340 -re "$gdb_prompt $" {pass "after attach3, exit"}
341 timeout {fail "(timeout) after attach3, exit"}
344 -re "$gdb_prompt $" {fail "after attach3, exit"}
345 timeout {fail "(timeout) after attach3, exit"}
349 proc do_call_attach_tests {} {
353 # Start the program running and then wait for a bit, to be sure
354 # that it can be attached to.
356 set testpid [eval exec $binfile2 &]
361 gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
362 send_gdb "attach $testpid\n"
364 -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
365 fail "attach call, read register 3 error"
367 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
370 -re "$gdb_prompt $" {fail "attach call"}
371 timeout {fail "(timeout) attach call"}
374 # See if other registers are problems
378 -re ".*warning: reading register.*$gdb_prompt $" {
379 pass "CHFts23490: known bug"
381 -re ".*r3.*$gdb_prompt $" {
382 pass "Bug fixed, Yayyy!"
384 timeout { fail "timeout on info reg" }
387 # Get rid of the process
389 gdb_test "p should_exit = 1" ".*"
390 gdb_test "c" ".*Program exited normally.*"
394 remote_exec build "kill -9 ${testpid}"
399 # Start with a fresh gdb
403 gdb_reinitialize_dir $srcdir/$subdir
406 # This is a test of gdb's ability to attach to a running process.
410 # Test attaching when the target is inside a system call
415 # this seems not necessary. - guo
417 # # Since we have moved the executable to /tmp, it will be hard for gdb
418 # # to find the object file/executable to read the symbols. This is
419 # # a known limitation. We try and get the name of the executable the
420 # # process is running from a variety of methods, but none is foolproof.
421 # # Using "dir" will get us the symbols.
423 # gdb_test "dir ./gdb.base" ".*" "set up directory before attach"
424 gdb_reinitialize_dir $srcdir/$subdir
427 # Until "set follow-fork-mode" and "catch fork" are implemented on
430 if ![istarget "hppa*-hp-hpux*"] then {
434 # Cleanup the files placed in /tmp and the symlinks
435 remote_exec build "rm -f ${binfile} ${binfile2} /tmp/attach1.${pid} /tmp/attach2.${pid}"