1 # Copyright 1997, 1999, 2002, 2003, 2004 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 escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
49 set cleanupfile ${objdir}/${subdir}/${testfile}.awk
51 #execute_anywhere "rm -f ${binfile} ${binfile2}"
52 remote_exec build "rm -f ${binfile} ${binfile2}"
53 # For debugging this test
57 # Clean out any old files from past runs.
59 remote_exec build "${cleanupfile}"
61 # build the first test case
63 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
64 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
67 # Build the in-system-call test
69 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
70 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
73 if [get_compiler_info ${binfile}] {
77 proc do_attach_tests {} {
87 # Start the program running and then wait for a bit, to be sure
88 # that it can be attached to.
90 set testpid [eval exec $binfile &]
92 if { [istarget "*-*-cygwin*"] } {
93 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
94 # different due to the way fork/exec works.
95 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
98 # Verify that we cannot attach to nonsense.
100 send_gdb "attach abc\n"
102 -re ".*Illegal process-id: abc.*$gdb_prompt $"\
103 {pass "attach to nonsense is prohibited"}
104 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
106 # Response expected from /proc-based systems.
107 pass "attach to nonsense is prohibited"
109 -re ".*Can't attach to process..*$gdb_prompt $"\
111 # Response expected on Cygwin
112 pass "attach to nonsense is prohibited"
114 -re "Attaching to.*$gdb_prompt $"\
115 {fail "attach to nonsense is prohibited (bogus pid allowed)"}
116 -re "$gdb_prompt $" {fail "attach to nonsense is prohibited"}
117 timeout {fail "(timeout) attach to nonsense is prohibited"}
120 # Verify that we cannot attach to what appears to be a valid
121 # process ID, but is a process that doesn't exist. Traditionally,
122 # most systems didn't have a process with ID 0, so we take that as
123 # the default. However, there are a few exceptions.
126 if { [istarget "*-*-*bsd*"] } {
127 # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
128 # (which should have the desired effect on any version of
129 # FreeBSD, and probably other *BSD's too).
132 send_gdb "attach $boguspid\n"
134 -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $"\
136 # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
137 pass "attach to nonexistent process is prohibited"
139 -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $"\
141 # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
142 pass "attach to nonexistent process is prohibited"
144 -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $"\
145 {pass "attach to nonexistent process is prohibited"}
146 -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $"\
147 {pass "attach to nonexistent process is prohibited"}
148 -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
150 # Response expected from /proc-based systems.
151 pass "attach to nonexistent process is prohibited"
153 -re ".*Can't attach to process..*$gdb_prompt $"\
155 # Response expected on Cygwin
156 pass "attach to nonexistent process is prohibited"
158 -re "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
160 fail "(timeout) attach to nonexistent process is prohibited"
164 # Verify that we can attach to the process by first giving its
165 # executable name via the file command, and using attach with
168 # (Actually, the test system appears to do this automatically
169 # for us. So, we must also be prepared to be asked if we want
170 # to discard an existing set of symbols.)
172 send_gdb "file $binfile\n"
174 -re "Load new symbol table from.*y or n.*$" {
177 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
178 {pass "(re)set file, before attach1"}
179 -re "$gdb_prompt $" {fail "(re)set file, before attach1"}
180 timeout {fail "(timeout) (re)set file, before attach1"}
183 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
184 {pass "set file, before attach1"}
185 -re "$gdb_prompt $" {fail "set file, before attach1"}
186 timeout {fail "(timeout) set file, before attach1"}
189 send_gdb "attach $testpid\n"
191 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
192 {pass "attach1, after setting file"}
193 -re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $"\
195 # Response expected on Cygwin
196 pass "attach1, after setting file"
198 -re "$gdb_prompt $" {fail "attach1, after setting file"}
199 timeout {fail "(timeout) attach1, after setting file"}
202 # Verify that we can "see" the variable "should_exit" in the
203 # program, and that it is zero.
205 send_gdb "print should_exit\n"
207 -re ".* = 0.*$gdb_prompt $"\
208 {pass "after attach1, print should_exit"}
209 -re "$gdb_prompt $" {fail "after attach1, print should_exit"}
210 timeout {fail "(timeout) after attach1, print should_exit"}
213 # Detach the process.
217 -re "Detaching from program: .*$escapedbinfile.*$gdb_prompt $"\
218 {pass "attach1 detach"}
219 -re "$gdb_prompt $" {fail "attach1 detach"}
220 timeout {fail "(timeout) attach1 detach"}
223 # Wait a bit for gdb to finish detaching
227 # Purge the symbols from gdb's brain. (We want to be certain
228 # the next attach, which won't be preceded by a "file" command,
229 # is really getting the executable file without our help.)
231 set old_timeout $timeout
235 -re ".*gdb internal error.*$" {
236 fail "Internal error, prob. Memory corruption"
238 -re "No executable file now.*Discard symbol table.*y or n.*$" {
241 -re "No symbol file now.*$gdb_prompt $"\
242 {pass "attach1, purging symbols after detach"}
243 -re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
244 timeout {fail "(timeout) attach1, purging symbols after detach"}
247 -re "$gdb_prompt $" {fail "attach1, purging file after detach"}
249 fail "(timeout) attach1, purging file after detach"
252 set timeout $old_timeout
254 # Verify that we can attach to the process just by giving the
257 send_gdb "attach $testpid\n"
259 -re "Attaching to process $testpid.*Load new symbol table from \"$escapedbinfile\.exe\".*y or n.*$" {
260 # On Cygwin, the DLL's symbol tables are loaded prior to the
261 # executable's symbol table. This in turn always results in
262 # asking the user for actually loading the symbol table of the
266 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
267 {pass "(re)set file, before attach2"}
269 {fail "(re)set file, before attach2"}
270 timeout {fail "(timeout) (re)set file, before attach2"}
273 -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
275 -re "$gdb_prompt $" {fail "attach2"}
276 timeout {fail "(timeout) attach2"}
279 # Verify that we can modify the variable "should_exit" in the
282 send_gdb "set should_exit=1\n"
284 -re "$gdb_prompt $" {pass "after attach2, set should_exit"}
285 timeout {fail "(timeout) after attach2, set should_exit"}
288 # Verify that the modification really happened.
290 send_gdb "tbreak 19\n"
292 -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
293 {pass "after attach2, set tbreak postloop"}
294 -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
295 timeout {fail "(timeout) after attach2, set tbreak postloop"}
297 send_gdb "continue\n"
299 -re "main.*at.*$srcfile:19.*$gdb_prompt $"\
300 {pass "after attach2, reach tbreak postloop"}
301 -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"}
302 timeout {fail "(timeout) after attach2, reach tbreak postloop"}
305 # Allow the test process to exit, to cleanup after ourselves.
307 send_gdb "continue\n"
309 -re "Program exited normally.*$gdb_prompt $"\
310 {pass "after attach2, exit"}
311 -re "$gdb_prompt $" {fail "after attach2, exit"}
312 timeout {fail "(timeout) after attach2, exit"}
315 # Make sure we don't leave a process around to confuse
316 # the next test run (and prevent the compile by keeping
317 # the text file busy), in case the "set should_exit" didn't
320 remote_exec build "kill -9 ${testpid}"
321 # Start the program running and then wait for a bit, to be sure
322 # that it can be attached to.
324 set testpid [eval exec $binfile &]
326 if { [istarget "*-*-cygwin*"] } {
327 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
328 # different due to the way fork/exec works.
329 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
332 # Verify that we can attach to the process, and find its a.out
333 # when we're cd'd to some directory that doesn't contain the
334 # a.out. (We use the source path set by the "dir" command.)
336 send_gdb "dir ${objdir}/${subdir}\n"
338 -re ".*Source directories searched: .*$gdb_prompt $"\
339 {pass "set source path"}
340 -re "$gdb_prompt $" {fail "set source path"}
341 timeout {fail "(timeout) set source path"}
346 -re ".*Working directory /tmp.*$gdb_prompt $"\
347 {pass "cd away from process' a.out"}
348 -re "$gdb_prompt $" {fail "cd away from process' a.out"}
349 timeout {fail "(timeout) cd away from process' a.out"}
352 # Explicitly flush out any knowledge of the previous attachment.
355 -re ".*Discard symbol table from.*y or n. $"\
358 -re ".*No symbol file now.*$gdb_prompt $"\
359 {pass "before attach3, flush symbols"}
360 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
361 timeout {fail "(timeout) before attach3, flush symbols"}
364 -re ".*No symbol file now.*$gdb_prompt $"\
365 {pass "before attach3, flush symbols"}
366 -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
367 timeout {fail "(timeout) before attach3, flush symbols"}
371 -re ".*No executable file now.*$gdb_prompt $"\
372 {pass "before attach3, flush exec"}
373 -re "$gdb_prompt $" {fail "before attach3, flush exec"}
374 timeout {fail "(timeout) before attach3, flush exec"}
377 send_gdb "attach $testpid\n"
379 -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
380 {pass "attach when process' a.out not in cwd"}
381 -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
382 timeout {fail "(timeout) attach when process' a.out not in cwd"}
387 -re ".*Kill the program being debugged.*y or n. $"\
390 -re "$gdb_prompt $" {pass "after attach3, exit"}
391 timeout {fail "(timeout) after attach3, exit"}
394 -re "$gdb_prompt $" {fail "after attach3, exit"}
395 timeout {fail "(timeout) after attach3, exit"}
398 # Another "don't leave a process around"
399 remote_exec build "kill -9 ${testpid}"
402 proc do_call_attach_tests {} {
406 # Start the program running and then wait for a bit, to be sure
407 # that it can be attached to.
409 set testpid [eval exec $binfile2 &]
411 if { [istarget "*-*-cygwin*"] } {
412 # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
413 # different due to the way fork/exec works.
414 set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
419 gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
420 send_gdb "attach $testpid\n"
422 -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
423 fail "attach call, read register 3 error"
425 -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
428 -re "Attaching to.*process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
431 -re "$gdb_prompt $" {fail "attach call"}
432 timeout {fail "(timeout) attach call"}
435 # See if other registers are problems
439 -re ".*warning: reading register.*$gdb_prompt $" {
440 pass "CHFts23490: known bug"
442 -re ".*r3.*$gdb_prompt $" {
443 pass "Bug fixed, Yayyy!"
445 timeout { fail "timeout on info reg" }
448 # Get rid of the process
450 gdb_test "p should_exit = 1" ".*"
451 gdb_test "c" ".*Program exited normally.*"
455 remote_exec build "kill -9 ${testpid}"
460 # Start with a fresh gdb
464 gdb_reinitialize_dir $srcdir/$subdir
467 # This is a test of gdb's ability to attach to a running process.
471 # Test attaching when the target is inside a system call
476 gdb_reinitialize_dir $srcdir/$subdir