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 .*couldn't open /proc file.*$gdb_prompt $"\
128 # Response expected from /proc-based systems.
129 pass "attach to nonexistent process is prohibited"
131 -re "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
132 timeout {fail "(timeout) attach to nonexistent process is prohibited"}
135 # Verify that we can attach to the process by first giving its
136 # executable name via the file command, and using attach with
139 # (Actually, the test system appears to do this automatically
140 # for us. So, we must also be prepared to be asked if we want
141 # to discard an existing set of symbols.)
143 send_gdb "file $binfile\n"
145 -re "Load new symbol table from.*y or n.*$" {
148 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
149 {pass "(re)set file, before attach1"}
150 -re "$gdb_prompt $" {fail "(re)set file, before attach1"}
151 timeout {fail "(timeout) (re)set file, before attach1"}
154 -re "Reading symbols from $binfile\.\.\.*done.*$gdb_prompt $"\
155 {pass "set file, before attach1"}
156 -re "$gdb_prompt $" {fail "set file, before attach1"}
157 timeout {fail "(timeout) set file, before attach1"}
160 send_gdb "attach $testpid\n"
162 -re "Attaching to program.*`?$binfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
163 {pass "attach1, after setting file"}
164 -re "$gdb_prompt $" {fail "attach1, after setting file"}
165 timeout {fail "(timeout) attach1, after setting file"}
168 # Verify that we can "see" the variable "should_exit" in the
169 # program, and that it is zero.
171 send_gdb "print should_exit\n"
173 -re ".* = 0.*$gdb_prompt $"\
174 {pass "after attach1, print should_exit"}
175 -re "$gdb_prompt $" {fail "after attach1, print should_exit"}
176 timeout {fail "(timeout) after attach1, print should_exit"}
179 # Detach the process.
183 -re "Detaching from program: .*$binfile.*$gdb_prompt $"\
184 {pass "attach1 detach"}
185 -re "$gdb_prompt $" {fail "attach1 detach"}
186 timeout {fail "(timeout) attach1 detach"}
189 # Wait a bit for gdb to finish detaching
193 # Purge the symbols from gdb's brain. (We want to be certain
194 # the next attach, which won't be preceded by a "file" command,
195 # is really getting the executable file without our help.)
197 set old_timeout $timeout
201 -re ".*gdb internal error.*$" {
202 fail "Internal error, prob. Memory corruption"
204 -re "No executable file now.*Discard symbol table.*y or n.*$" {
207 -re "No symbol file now.*$gdb_prompt $"\
208 {pass "attach1, purging symbols after detach"}
209 -re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
210 timeout {fail "(timeout) attach1, purging symbols after detach"}
213 -re "$gdb_prompt $" {fail "attach1, purging file after detach"}
215 fail "(timeout) attach1, purging file after detach"
218 set timeout $old_timeout
220 # Verify that we can attach to the process just by giving the
223 send_gdb "attach $testpid\n"
225 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
227 -re "$gdb_prompt $" {fail "attach2"}
228 timeout {fail "(timeout) attach2"}
231 # Verify that we can modify the variable "should_exit" in the
234 send_gdb "set should_exit=1\n"
236 -re "$gdb_prompt $" {pass "after attach2, set should_exit"}
237 timeout {fail "(timeout) after attach2, set should_exit"}
240 # Verify that the modification really happened.
242 send_gdb "tbreak 19\n"
244 -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
245 {pass "after attach2, set tbreak postloop"}
246 -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
247 timeout {fail "(timeout) after attach2, set tbreak postloop"}
249 send_gdb "continue\n"
251 -re "main.*at.*$srcfile:19.*$gdb_prompt $"\
252 {pass "after attach2, reach tbreak postloop"}
253 -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"}
254 timeout {fail "(timeout) after attach2, reach tbreak postloop"}
257 # Allow the test process to exit, to cleanup after ourselves.
259 send_gdb "continue\n"
261 -re "Program exited normally.*$gdb_prompt $"\
262 {pass "after attach2, exit"}
263 -re "$gdb_prompt $" {fail "after attach2, exit"}
264 timeout {fail "(timeout) after attach2, exit"}
267 # Make sure we don't leave a process around to confuse
268 # the next test run (and prevent the compile by keeping
269 # the text file busy), in case the "set should_exit" didn't
272 remote_exec build "kill -9 ${testpid}"
273 # Start the program running and then wait for a bit, to be sure
274 # that it can be attached to.
276 set testpid [eval exec $binfile &]
279 # Verify that we can attach to the process, and find its a.out
280 # when we're cd'd to some directory that doesn't contain the
281 # a.out. (We use the source path set by the "dir" command.)
283 send_gdb "dir ${objdir}/${subdir}\n"
285 -re ".*Source directories searched: .*$gdb_prompt $"\
286 {pass "set source path"}
287 -re "$gdb_prompt $" {fail "set source path"}
288 timeout {fail "(timeout) set source path"}
293 -re ".*Working directory /tmp.*$gdb_prompt $"\
294 {pass "cd away from process' a.out"}
295 -re "$gdb_prompt $" {fail "cd away from process' a.out"}
296 timeout {fail "(timeout) cd away from process' a.out"}
299 # Explicitly flush out any knowledge of the previous attachment.
302 -re ".*Discard symbol table from.*y or n. $"\
305 -re ".*No symbol file now.*$gdb_prompt $"\
306 {pass "before attach3, flush symbols"}
307 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
308 timeout {fail "(timeout) before attach3, flush symbols"}
311 -re ".*No symbol file now.*$gdb_prompt $"\
312 {pass "before attach3, flush symbols"}
313 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
314 timeout {fail "(timeout) before attach3, flush symbols"}
318 -re ".*No executable file now.*$gdb_prompt $"\
319 {pass "before attach3, flush exec"}
320 -re "$gdb_prompt $" {fail "before attach3, flush exec"}
321 timeout {fail "(timeout) before attach3, flush exec"}
324 send_gdb "attach $testpid\n"
326 -re "Attaching to process $testpid.*Reading symbols from $binfile.*main.*at .*$gdb_prompt $"\
327 {pass "attach when process' a.out not in cwd"}
328 -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
329 timeout {fail "(timeout) attach when process' a.out not in cwd"}
334 -re ".*Kill the program being debugged.*y or n. $"\
337 -re "$gdb_prompt $" {pass "after attach3, exit"}
338 timeout {fail "(timeout) after attach3, exit"}
341 -re "$gdb_prompt $" {fail "after attach3, exit"}
342 timeout {fail "(timeout) after attach3, exit"}
346 proc do_call_attach_tests {} {
350 # Start the program running and then wait for a bit, to be sure
351 # that it can be attached to.
353 set testpid [eval exec $binfile2 &]
358 gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
359 send_gdb "attach $testpid\n"
361 -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
362 fail "attach call, read register 3 error"
364 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
367 -re "$gdb_prompt $" {fail "attach call"}
368 timeout {fail "(timeout) attach call"}
371 # See if other registers are problems
375 -re ".*warning: reading register.*$gdb_prompt $" {
376 pass "CHFts23490: known bug"
378 -re ".*r3.*$gdb_prompt $" {
379 pass "Bug fixed, Yayyy!"
381 timeout { fail "timeout on info reg" }
384 # Get rid of the process
386 gdb_test "p should_exit = 1" ".*"
387 gdb_test "c" ".*Program exited normally.*"
391 remote_exec build "kill -9 ${testpid}"
396 # Start with a fresh gdb
400 gdb_reinitialize_dir $srcdir/$subdir
403 # This is a test of gdb's ability to attach to a running process.
407 # Test attaching when the target is inside a system call
412 gdb_reinitialize_dir $srcdir/$subdir