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-7.2.50.20110320/gdb/testsuite/gdb.base/attach-32.c
13 ===================================================================
14 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
15 +++ gdb-7.2.50.20110320/gdb/testsuite/gdb.base/attach-32.c 2011-03-20 20:15:57.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-7.2.50.20110320/gdb/testsuite/gdb.base/attach-32.exp
38 ===================================================================
39 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
40 +++ gdb-7.2.50.20110320/gdb/testsuite/gdb.base/attach-32.exp 2011-03-20 20:20:03.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 +# On HP-UX 11.0, this test is causing a process running the program
61 +# "attach" to be left around spinning. Until we figure out why, I am
62 +# commenting out the test to avoid polluting tiamat (our 11.0 nightly
63 +# test machine) with these processes. RT
65 +# Setting the magic bit in the target app should work. I added a
66 +# "kill", and also a test for the R3 register warning. JB
67 +if { ![istarget "x86_64*-*linux*"]
68 + && ![istarget "powerpc64*-*linux*"]} {
72 +# are we on a target board
73 +if [is_remote target] then {
77 +set testfile "attach-32"
78 +set srcfile ${testfile}.c
79 +set srcfile2 ${testfile}b.c
80 +set binfile ${objdir}/${subdir}/${testfile}
81 +set binfile2 ${objdir}/${subdir}/${testfile}b
82 +set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
84 +#execute_anywhere "rm -f ${binfile} ${binfile2}"
85 +remote_exec build "rm -f ${binfile} ${binfile2}"
86 +# For debugging this test
90 +# build the first test case
92 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "additional_flags=-m32"]] != "" } {
93 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
96 +# Build the in-system-call test
98 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable [list debug "additional_flags=-m32"]] != "" } {
99 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
102 +if [get_compiler_info ${binfile}] {
106 +proc do_attach_tests {} {
109 + global escapedbinfile
117 + # Verify that we can "see" the variable "should_exit" in the
118 + # program, and that it is zero.
120 + gdb_test "print should_exit" " = 0" "after attach-32, print should_exit"
122 + # Verify that we can modify the variable "should_exit" in the
125 + gdb_test "set should_exit=1" "" "after attach-32, set should_exit"
127 + # Verify that the modification really happened.
129 + send_gdb "tbreak 19\n"
131 + -re "reakpoint .*at.*$srcfile, line 19.*$gdb_prompt $" {
132 + pass "after attach-32, set tbreak postloop"
134 + -re "$gdb_prompt $" {
135 + fail "after attach-32, set tbreak postloop"
138 + fail "(timeout) after attach-32, set tbreak postloop"
141 + send_gdb "continue\n"
143 + -re "main.*at.*$srcfile:19.*$gdb_prompt $" {
144 + pass "after attach-32, reach tbreak postloop"
146 + -re "$gdb_prompt $" {
147 + fail "after attach-32, reach tbreak postloop"
150 + fail "(timeout) after attach-32, reach tbreak postloop"
154 + # Allow the test process to exit, to cleanup after ourselves.
156 + gdb_test "continue" {\[Inferior .* exited normally\]} "after attach-32, exit"
158 + # Make sure we don't leave a process around to confuse
159 + # the next test run (and prevent the compile by keeping
160 + # the text file busy), in case the "set should_exit" didn't
163 + remote_exec build "kill -9 ${testpid}"
165 + # Start the program running and then wait for a bit, to be sure
166 + # that it can be attached to.
168 + set testpid [eval exec $binfile &]
170 + if { [istarget "*-*-cygwin*"] } {
171 + # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
172 + # different due to the way fork/exec works.
173 + set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
176 + # Verify that we can attach to the process, and find its a.out
177 + # when we're cd'd to some directory that doesn't contain the
178 + # a.out. (We use the source path set by the "dir" command.)
180 + gdb_test "dir ${objdir}/${subdir}" "Source directories searched: .*" \
183 + gdb_test "cd /tmp" "Working directory /tmp." \
184 + "cd away from process working directory"
186 + # Explicitly flush out any knowledge of the previous attachment.
188 + set test "before attach-32-3, flush symbols"
189 + gdb_test_multiple "symbol" "$test" {
190 + -re "Discard symbol table from.*y or n. $" {
191 + gdb_test "y" "No symbol file now." \
194 + -re "No symbol file now.*$gdb_prompt $" {
199 + gdb_test "exec" "No executable file now." \
200 + "before attach-32-3, flush exec"
202 + gdb_test "attach $testpid" \
203 + "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*" \
204 + "attach-32 when process' a.out not in cwd"
206 + set test "after attach-32-3, exit"
207 + gdb_test_multiple "kill" "$test" {
208 + -re "Kill the program being debugged.*y or n. $" {
209 + gdb_test "y" "" "$test"
213 + # Another "don't leave a process around"
214 + remote_exec build "kill -9 ${testpid}"
217 +proc do_call_attach_tests {} {
222 + # See if other registers are problems
224 + set test "info other register"
225 + gdb_test_multiple "i r r3" "$test" {
226 + -re "warning: reading register.*$gdb_prompt $" {
229 + -re "r3.*$gdb_prompt $" {
234 + # Get rid of the process
236 + gdb_test "p should_exit = 1"
237 + gdb_test "c" {\[Inferior .* exited normally\]}
241 + remote_exec build "kill -9 ${testpid}"
245 +# Start with a fresh gdb
248 +set testpid [eval exec $binfile &]
250 +if { [istarget "*-*-cygwin*"] } {
251 + # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
252 + # different due to the way fork/exec works.
253 + set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
256 +set GDBFLAGS_orig $GDBFLAGS
257 +set GDBFLAGS "--pid=$testpid"
259 +set GDBFLAGS $GDBFLAGS_orig
261 +gdb_reinitialize_dir $srcdir/$subdir
263 +# This is a test of gdb's ability to attach to a running process.
267 +# Test attaching when the target is inside a system call
270 +set testpid [eval exec $binfile2 &]
272 +if { [istarget "*-*-cygwin*"] } {
273 + # testpid is the Cygwin PID, GDB uses the Windows PID, which might be
274 + # different due to the way fork/exec works.
275 + set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
278 +set GDBFLAGS_orig $GDBFLAGS
279 +set GDBFLAGS "--pid=$testpid"
281 +set GDBFLAGS $GDBFLAGS_orig
283 +gdb_reinitialize_dir $srcdir/$subdir
284 +do_call_attach_tests
287 Index: gdb-7.2.50.20110320/gdb/testsuite/gdb.base/attach-32b.c
288 ===================================================================
289 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
290 +++ gdb-7.2.50.20110320/gdb/testsuite/gdb.base/attach-32b.c 2011-03-20 20:15:57.000000000 +0100
292 +/* This program is intended to be started outside of gdb, and then
293 + attached to by gdb. Thus, it simply spins in a loop. The loop
294 + is exited when & if the variable 'should_exit' is non-zero. (It
295 + is initialized to zero in this program, so the loop will never
296 + exit unless/until gdb sets the variable to non-zero.)
302 +int should_exit = 0;
308 + sleep( 10 ); /* System call causes register fetch to fail */
309 + /* This is a known HPUX "feature" */
310 + while (! should_exit)