2007-01-09 17:59:20 +00:00
|
|
|
# Copyright 1997, 1999, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
|
1999-06-28 23:04:32 +00:00
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
|
|
|
|
if $tracelevel then {
|
2004-07-08 20:04:47 +00:00
|
|
|
strace $tracelevel
|
|
|
|
}
|
1999-06-28 23:04:32 +00:00
|
|
|
|
|
|
|
set prms_id 0
|
|
|
|
set bug_id 0
|
|
|
|
|
2002-03-26 00:13:22 +00:00
|
|
|
# On HP-UX 11.0, this test is causing a process running the program
|
|
|
|
# "attach" to be left around spinning. Until we figure out why, I am
|
|
|
|
# commenting out the test to avoid polluting tiamat (our 11.0 nightly
|
|
|
|
# test machine) with these processes. RT
|
|
|
|
#
|
|
|
|
# Setting the magic bit in the target app should work. I added a
|
|
|
|
# "kill", and also a test for the R3 register warning. JB
|
|
|
|
if { [istarget "hppa*-*-hpux*"] } {
|
|
|
|
return 0
|
|
|
|
}
|
1999-06-28 23:04:32 +00:00
|
|
|
|
2006-11-22 17:19:52 +00:00
|
|
|
# On SPU, this test currently fails because "sleep" is not supported.
|
|
|
|
if { [istarget "spu*-*-*"] } {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2002-03-26 00:13:22 +00:00
|
|
|
# are we on a target board
|
2002-04-09 20:48:45 +00:00
|
|
|
if [is_remote target] then {
|
1999-06-28 23:04:32 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
set testfile "attach"
|
|
|
|
set srcfile ${testfile}.c
|
|
|
|
set srcfile2 ${testfile}2.c
|
|
|
|
set binfile ${objdir}/${subdir}/${testfile}
|
|
|
|
set binfile2 ${objdir}/${subdir}/${testfile}2
|
2003-08-07 17:55:41 +00:00
|
|
|
set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
|
1999-06-28 23:04:32 +00:00
|
|
|
|
|
|
|
#execute_anywhere "rm -f ${binfile} ${binfile2}"
|
|
|
|
remote_exec build "rm -f ${binfile} ${binfile2}"
|
|
|
|
# For debugging this test
|
|
|
|
#
|
|
|
|
#log_user 1
|
|
|
|
|
|
|
|
# build the first test case
|
|
|
|
#
|
|
|
|
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
|
2006-08-10 05:27:22 +00:00
|
|
|
untested attach.exp
|
|
|
|
return -1
|
1999-06-28 23:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Build the in-system-call test
|
|
|
|
|
|
|
|
if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
|
2006-08-10 05:27:22 +00:00
|
|
|
untested attach.exp
|
|
|
|
return -1
|
1999-06-28 23:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [get_compiler_info ${binfile}] {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
proc do_attach_tests {} {
|
2004-07-08 20:04:47 +00:00
|
|
|
global gdb_prompt
|
|
|
|
global binfile
|
|
|
|
global escapedbinfile
|
|
|
|
global srcfile
|
|
|
|
global testfile
|
|
|
|
global objdir
|
|
|
|
global subdir
|
|
|
|
global timeout
|
|
|
|
|
|
|
|
# Start the program running and then wait for a bit, to be sure
|
|
|
|
# that it can be attached to.
|
|
|
|
|
|
|
|
set testpid [eval exec $binfile &]
|
|
|
|
exec sleep 2
|
|
|
|
if { [istarget "*-*-cygwin*"] } {
|
|
|
|
# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
|
|
|
|
# different due to the way fork/exec works.
|
|
|
|
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify that we cannot attach to nonsense.
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
set test "attach to nonsense is prohibited"
|
|
|
|
gdb_test_multiple "attach abc" "$test" {
|
|
|
|
-re "Illegal process-id: abc.*$gdb_prompt $" {
|
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
-re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
|
|
|
|
# Response expected from /proc-based systems.
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
2004-07-12 14:25:48 +00:00
|
|
|
-re "Can't attach to process..*$gdb_prompt $" {
|
2004-07-08 20:04:47 +00:00
|
|
|
# Response expected on Cygwin
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
-re "Attaching to.*$gdb_prompt $" {
|
2004-07-12 14:25:48 +00:00
|
|
|
fail "$test (bogus pid allowed)"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify that we cannot attach to what appears to be a valid
|
|
|
|
# process ID, but is a process that doesn't exist. Traditionally,
|
|
|
|
# most systems didn't have a process with ID 0, so we take that as
|
|
|
|
# the default. However, there are a few exceptions.
|
|
|
|
|
|
|
|
set boguspid 0
|
|
|
|
if { [istarget "*-*-*bsd*"] } {
|
|
|
|
# In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
|
|
|
|
# (which should have the desired effect on any version of
|
|
|
|
# FreeBSD, and probably other *BSD's too).
|
|
|
|
set boguspid -1
|
|
|
|
}
|
2004-07-12 14:25:48 +00:00
|
|
|
set test "attach to nonexistent process is prohibited"
|
|
|
|
gdb_test_multiple "attach $boguspid" "$test" {
|
2004-07-08 20:04:47 +00:00
|
|
|
-re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $" {
|
|
|
|
# Response expected on ptrace-based systems (i.e. HP-UX 10.20).
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
-re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $" {
|
|
|
|
# Response expected on ttrace-based systems (i.e. HP-UX 11.0).
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
-re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $" {
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
-re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $" {
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
-re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
|
|
|
|
# Response expected from /proc-based systems.
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
2004-07-12 14:25:48 +00:00
|
|
|
-re "Can't attach to process..*$gdb_prompt $" {
|
2004-07-08 20:04:47 +00:00
|
|
|
# Response expected on Cygwin
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify that we can attach to the process by first giving its
|
|
|
|
# executable name via the file command, and using attach with the
|
|
|
|
# process ID.
|
|
|
|
|
|
|
|
# (Actually, the test system appears to do this automatically for
|
|
|
|
# us. So, we must also be prepared to be asked if we want to
|
|
|
|
# discard an existing set of symbols.)
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
set test "set file, before attach1"
|
|
|
|
gdb_test_multiple "file $binfile" "$test" {
|
|
|
|
-re "Load new symbol table from.*y or n. $" {
|
|
|
|
gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
|
|
|
|
"$test (re-read)"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
-re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
set test "attach1, after setting file"
|
|
|
|
gdb_test_multiple "attach $testpid" "$test" {
|
2004-07-08 20:04:47 +00:00
|
|
|
-re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $" {
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
-re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
|
|
|
|
# Response expected on Cygwin
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify that we can "see" the variable "should_exit" in the
|
|
|
|
# program, and that it is zero.
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
gdb_test "print should_exit" " = 0" "after attach1, print should_exit"
|
2004-07-08 20:04:47 +00:00
|
|
|
|
|
|
|
# Detach the process.
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
gdb_test "detach" \
|
|
|
|
"Detaching from program: .*$escapedbinfile, process $testpid" \
|
|
|
|
"attach1 detach"
|
2004-07-08 20:04:47 +00:00
|
|
|
|
|
|
|
# Wait a bit for gdb to finish detaching
|
|
|
|
|
|
|
|
exec sleep 5
|
|
|
|
|
|
|
|
# Purge the symbols from gdb's brain. (We want to be certain the
|
|
|
|
# next attach, which won't be preceded by a "file" command, is
|
|
|
|
# really getting the executable file without our help.)
|
|
|
|
|
|
|
|
set old_timeout $timeout
|
|
|
|
set timeout 15
|
2004-07-12 14:25:48 +00:00
|
|
|
set test "attach1, purging symbols after detach"
|
|
|
|
gdb_test_multiple "file" "$test" {
|
|
|
|
-re "No executable file now.*Discard symbol table.*y or n. $" {
|
|
|
|
gdb_test "y" "No symbol file now." "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
set timeout $old_timeout
|
|
|
|
|
|
|
|
# Verify that we can attach to the process just by giving the
|
|
|
|
# process ID.
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
set test "set file, before attach2"
|
|
|
|
gdb_test_multiple "attach $testpid" "$test" {
|
|
|
|
-re "Attaching to process $testpid.*Load new symbol table from \"$escapedbinfile\.exe\".*y or n. $" {
|
2004-07-08 20:04:47 +00:00
|
|
|
# On Cygwin, the DLL's symbol tables are loaded prior to the
|
|
|
|
# executable's symbol table. This in turn always results in
|
|
|
|
# asking the user for actually loading the symbol table of the
|
|
|
|
# executable.
|
2004-07-12 14:25:48 +00:00
|
|
|
gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
|
|
|
|
"$test (reset file)"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
-re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $" {
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify that we can modify the variable "should_exit" in the
|
|
|
|
# program.
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
gdb_test "set should_exit=1" "" "after attach2, set should_exit"
|
2004-07-08 20:04:47 +00:00
|
|
|
|
|
|
|
# Verify that the modification really happened.
|
|
|
|
|
|
|
|
send_gdb "tbreak 19\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $" {
|
|
|
|
pass "after attach2, set tbreak postloop"
|
|
|
|
}
|
|
|
|
-re "$gdb_prompt $" {
|
|
|
|
fail "after attach2, set tbreak postloop"
|
|
|
|
}
|
|
|
|
timeout {
|
|
|
|
fail "(timeout) after attach2, set tbreak postloop"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
send_gdb "continue\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "main.*at.*$srcfile:19.*$gdb_prompt $" {
|
|
|
|
pass "after attach2, reach tbreak postloop"
|
|
|
|
}
|
|
|
|
-re "$gdb_prompt $" {
|
|
|
|
fail "after attach2, reach tbreak postloop"
|
|
|
|
}
|
|
|
|
timeout {
|
|
|
|
fail "(timeout) after attach2, reach tbreak postloop"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Allow the test process to exit, to cleanup after ourselves.
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
gdb_test "continue" "Program exited normally." "after attach2, exit"
|
2004-07-08 20:04:47 +00:00
|
|
|
|
|
|
|
# Make sure we don't leave a process around to confuse
|
|
|
|
# the next test run (and prevent the compile by keeping
|
|
|
|
# the text file busy), in case the "set should_exit" didn't
|
|
|
|
# work.
|
|
|
|
|
|
|
|
remote_exec build "kill -9 ${testpid}"
|
2004-07-12 14:25:48 +00:00
|
|
|
|
2004-07-08 20:04:47 +00:00
|
|
|
# Start the program running and then wait for a bit, to be sure
|
|
|
|
# that it can be attached to.
|
|
|
|
|
|
|
|
set testpid [eval exec $binfile &]
|
|
|
|
exec sleep 2
|
|
|
|
if { [istarget "*-*-cygwin*"] } {
|
|
|
|
# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
|
|
|
|
# different due to the way fork/exec works.
|
|
|
|
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify that we can attach to the process, and find its a.out
|
|
|
|
# when we're cd'd to some directory that doesn't contain the
|
|
|
|
# a.out. (We use the source path set by the "dir" command.)
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
gdb_test "dir ${objdir}/${subdir}" "Source directories searched: .*" \
|
|
|
|
"set source path"
|
2004-07-08 20:04:47 +00:00
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
gdb_test "cd /tmp" "Working directory /tmp." \
|
|
|
|
"cd away from process working directory"
|
2004-07-08 20:04:47 +00:00
|
|
|
|
|
|
|
# Explicitly flush out any knowledge of the previous attachment.
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
set test "before attach3, flush symbols"
|
|
|
|
gdb_test_multiple "symbol" "$test" {
|
|
|
|
-re "Discard symbol table from.*y or n. $" {
|
|
|
|
gdb_test "y" "No symbol file now." \
|
|
|
|
"$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
2004-07-12 14:25:48 +00:00
|
|
|
-re "No symbol file now.*$gdb_prompt $" {
|
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
gdb_test "exec" "No executable file now." \
|
|
|
|
"before attach3, flush exec"
|
|
|
|
|
|
|
|
gdb_test "attach $testpid" \
|
|
|
|
"Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*" \
|
|
|
|
"attach when process' a.out not in cwd"
|
|
|
|
|
|
|
|
set test "after attach3, exit"
|
|
|
|
gdb_test_multiple "kill" "$test" {
|
|
|
|
-re "Kill the program being debugged.*y or n. $" {
|
|
|
|
gdb_test "y" "" "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Another "don't leave a process around"
|
|
|
|
remote_exec build "kill -9 ${testpid}"
|
1999-06-28 23:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
proc do_call_attach_tests {} {
|
2004-07-08 20:04:47 +00:00
|
|
|
global gdb_prompt
|
|
|
|
global binfile2
|
|
|
|
|
|
|
|
# Start the program running and then wait for a bit, to be sure
|
|
|
|
# that it can be attached to.
|
1999-06-28 23:04:32 +00:00
|
|
|
|
2004-07-08 20:04:47 +00:00
|
|
|
set testpid [eval exec $binfile2 &]
|
|
|
|
exec sleep 2
|
|
|
|
if { [istarget "*-*-cygwin*"] } {
|
|
|
|
# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
|
|
|
|
# different due to the way fork/exec works.
|
|
|
|
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Attach
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
gdb_test "file $binfile2" "" "force switch to gdb64, if necessary"
|
|
|
|
set test "attach call"
|
|
|
|
gdb_test_multiple "attach $testpid" "$test" {
|
|
|
|
-re "warning: reading register.*I.*O error.*$gdb_prompt $" {
|
|
|
|
fail "$test (read register error)"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
-re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
-re "Attaching to.*process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
|
2004-07-12 14:25:48 +00:00
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# See if other registers are problems
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
set test "info other register"
|
|
|
|
gdb_test_multiple "i r r3" "$test" {
|
|
|
|
-re "warning: reading register.*$gdb_prompt $" {
|
|
|
|
fail "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
2004-07-12 14:25:48 +00:00
|
|
|
-re "r3.*$gdb_prompt $" {
|
|
|
|
pass "$test"
|
2004-07-08 20:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
1999-06-28 23:04:32 +00:00
|
|
|
|
2004-07-08 20:04:47 +00:00
|
|
|
# Get rid of the process
|
|
|
|
|
2004-07-12 14:25:48 +00:00
|
|
|
gdb_test "p should_exit = 1"
|
|
|
|
gdb_test "c" "Program exited normally."
|
2004-07-08 20:04:47 +00:00
|
|
|
|
|
|
|
# Be paranoid
|
|
|
|
|
|
|
|
remote_exec build "kill -9 ${testpid}"
|
1999-06-28 23:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Start with a fresh gdb
|
2004-07-08 20:04:47 +00:00
|
|
|
|
1999-06-28 23:04:32 +00:00
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
gdb_load ${binfile}
|
|
|
|
|
|
|
|
# This is a test of gdb's ability to attach to a running process.
|
2004-07-08 20:04:47 +00:00
|
|
|
|
1999-06-28 23:04:32 +00:00
|
|
|
do_attach_tests
|
|
|
|
|
|
|
|
# Test attaching when the target is inside a system call
|
2004-07-08 20:04:47 +00:00
|
|
|
|
1999-06-28 23:04:32 +00:00
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
|
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
do_call_attach_tests
|
|
|
|
|
|
|
|
return 0
|