1 2005-07-21 Jeff Johnston <jjohnstn@redhat.com>
3 * gdb.base/attach-32.exp: New test for attaching in 32-bit
4 mode on 64-bit systems.
5 * gdb.base/attach-32.c: Ditto.
6 * gdb.base/attach-32b.c: Ditto.
8 2007-12-26 Jan Kratochvil <jan.kratochvil@redhat.com>
10 * gdb.base/attach-32.exp: Fix forgotten $GDBFLAGS as set.
12 Index: gdb-6.8.50.20081128/gdb/testsuite/gdb.base/attach-32.c
13 ===================================================================
14 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
15 +++ gdb-6.8.50.20081128/gdb/testsuite/gdb.base/attach-32.c 2008-12-07 10:06:03.000000000 +0100
17 +/* This program is intended to be started outside of gdb, and then
18 + attached to by gdb. Thus, it simply spins in a loop. The loop
19 + is exited when & if the variable 'should_exit' is non-zero. (It
20 + is initialized to zero in this program, so the loop will never
21 + exit unless/until gdb sets the variable to non-zero.)
31 + while (! should_exit)
37 Index: gdb-6.8.50.20081128/gdb/testsuite/gdb.base/attach-32.exp
38 ===================================================================
39 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
40 +++ gdb-6.8.50.20081128/gdb/testsuite/gdb.base/attach-32.exp 2008-12-07 10:08:52.000000000 +0100
42 +# Copyright 2005 Free Software Foundation, Inc.
44 +# This program is free software; you can redistribute it and/or modify
45 +# it under the terms of the GNU General Public License as published by
46 +# the Free Software Foundation; either version 2 of the License, or
47 +# (at your option) any later version.
49 +# This program is distributed in the hope that it will be useful,
50 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
51 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52 +# GNU General Public License for more details.
54 +# You should have received a copy of the GNU General Public License
55 +# along with this program; if not, write to the Free Software
56 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
58 +# This test was based on attach.exp and modified for 32/64 bit Linux systems. */
60 +if $tracelevel then {
67 +# On HP-UX 11.0, this test is causing a process running the program
68 +# "attach" to be left around spinning. Until we figure out why, I am
69 +# commenting out the test to avoid polluting tiamat (our 11.0 nightly
70 +# test machine) with these processes. RT
72 +# Setting the magic bit in the target app should work. I added a
73 +# "kill", and also a test for the R3 register warning. JB
74 +if { ![istarget "x86_64*-*linux*"]
75 + && ![istarget "powerpc64*-*linux*"]} {
79 +# are we on a target board
80 +if [is_remote target] then {
84 +set testfile "attach-32"
85 +set srcfile ${testfile}.c
86 +set srcfile2 ${testfile}b.c
87 +set binfile ${objdir}/${subdir}/${testfile}
88 +set binfile2 ${objdir}/${subdir}/${testfile}b
89 +set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
91 +#execute_anywhere "rm -f ${binfile} ${binfile2}"
92 +remote_exec build "rm -f ${binfile} ${binfile2}"
93 +# For debugging this test
97 +# build the first test case
99 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "additional_flags=-m32"]] != "" } {
100 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
103 +# Build the in-system-call test
105 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable [list debug "additional_flags=-m32"]] != "" } {
106 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
109 +if [get_compiler_info ${binfile}] {
113 +proc do_attach_tests {} {
116 + global escapedbinfile
124 + # Verify that we can "see" the variable "should_exit" in the
125 + # program, and that it is zero.
127 + gdb_test "print should_exit" " = 0" "after attach-32, print should_exit"
129 + # Verify that we can modify the variable "should_exit" in the
132 + gdb_test "set should_exit=1" "" "after attach-32, set should_exit"
134 + # Verify that the modification really happened.
136 + send_gdb "tbreak 19\n"
138 + -re "reakpoint .*at.*$srcfile, line 19.*$gdb_prompt $" {
139 + pass "after attach-32, set tbreak postloop"
141 + -re "$gdb_prompt $" {
142 + fail "after attach-32, set tbreak postloop"
145 + fail "(timeout) after attach-32, set tbreak postloop"
148 + send_gdb "continue\n"
150 + -re "main.*at.*$srcfile:19.*$gdb_prompt $" {
151 + pass "after attach-32, reach tbreak postloop"
153 + -re "$gdb_prompt $" {
154 + fail "after attach-32, reach tbreak postloop"
157 + fail "(timeout) after attach-32, reach tbreak postloop"
161 + # Allow the test process to exit, to cleanup after ourselves.
163 + gdb_test "continue" "Program exited normally." "after attach-32, exit"
165 + # Make sure we don't leave a process around to confuse
166 + # the next test run (and prevent the compile by keeping
167 + # the text file busy), in case the "set should_exit" didn't
170 + remote_exec build "kill -9 ${testpid}"
172 + # Start the program running and then wait for a bit, to be sure
173 + # that it can be attached to.
175 + set testpid [eval exec $binfile &]
177 + if { [istarget "*-*-cygwin*"] } {
178 + # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
179 + # different due to the way fork/exec works.
180 + set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
183 + # Verify that we can attach to the process, and find its a.out
184 + # when we're cd'd to some directory that doesn't contain the
185 + # a.out. (We use the source path set by the "dir" command.)
187 + gdb_test "dir ${objdir}/${subdir}" "Source directories searched: .*" \
190 + gdb_test "cd /tmp" "Working directory /tmp." \
191 + "cd away from process working directory"
193 + # Explicitly flush out any knowledge of the previous attachment.
195 + set test "before attach-32-3, flush symbols"
196 + gdb_test_multiple "symbol" "$test" {
197 + -re "Discard symbol table from.*y or n. $" {
198 + gdb_test "y" "No symbol file now." \
201 + -re "No symbol file now.*$gdb_prompt $" {
206 + gdb_test "exec" "No executable file now." \
207 + "before attach-32-3, flush exec"
209 + gdb_test "attach $testpid" \
210 + "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*" \
211 + "attach-32 when process' a.out not in cwd"
213 + set test "after attach-32-3, exit"
214 + gdb_test_multiple "kill" "$test" {
215 + -re "Kill the program being debugged.*y or n. $" {
216 + gdb_test "y" "" "$test"
220 + # Another "don't leave a process around"
221 + remote_exec build "kill -9 ${testpid}"
224 +proc do_call_attach_tests {} {
229 + # See if other registers are problems
231 + set test "info other register"
232 + gdb_test_multiple "i r r3" "$test" {
233 + -re "warning: reading register.*$gdb_prompt $" {
236 + -re "r3.*$gdb_prompt $" {
241 + # Get rid of the process
243 + gdb_test "p should_exit = 1"
244 + gdb_test "c" "Program exited normally."
248 + remote_exec build "kill -9 ${testpid}"
252 +# Start with a fresh gdb
255 +set testpid [eval exec $binfile &]
257 +if { [istarget "*-*-cygwin*"] } {
258 + # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
259 + # different due to the way fork/exec works.
260 + set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
263 +set GDBFLAGS_orig $GDBFLAGS
264 +set GDBFLAGS "--pid=$testpid"
266 +set GDBFLAGS $GDBFLAGS_orig
268 +gdb_reinitialize_dir $srcdir/$subdir
270 +# This is a test of gdb's ability to attach to a running process.
274 +# Test attaching when the target is inside a system call
277 +set testpid [eval exec $binfile2 &]
279 +if { [istarget "*-*-cygwin*"] } {
280 + # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
281 + # different due to the way fork/exec works.
282 + set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
285 +set GDBFLAGS_orig $GDBFLAGS
286 +set GDBFLAGS "--pid=$testpid"
288 +set GDBFLAGS $GDBFLAGS_orig
290 +gdb_reinitialize_dir $srcdir/$subdir
291 +do_call_attach_tests
294 Index: gdb-6.8.50.20081128/gdb/testsuite/gdb.base/attach-32b.c
295 ===================================================================
296 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
297 +++ gdb-6.8.50.20081128/gdb/testsuite/gdb.base/attach-32b.c 2008-12-07 10:06:03.000000000 +0100
299 +/* This program is intended to be started outside of gdb, and then
300 + attached to by gdb. Thus, it simply spins in a loop. The loop
301 + is exited when & if the variable 'should_exit' is non-zero. (It
302 + is initialized to zero in this program, so the loop will never
303 + exit unless/until gdb sets the variable to non-zero.)
309 +int should_exit = 0;
315 + sleep( 10 ); /* System call causes register fetch to fail */
316 + /* This is a known HPUX "feature" */
317 + while (! should_exit)