mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-28 15:18:37 +08:00
2004-07-08 Andrew Cagney <cagney@gnu.org>
* gdb.base/attach.exp: Cleanup copyright. Re-indent.
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
2004-07-08 Andrew Cagney <cagney@gnu.org>
|
2004-07-08 Andrew Cagney <cagney@gnu.org>
|
||||||
|
|
||||||
|
* gdb.base/attach.exp: Cleanup copyright. Re-indent.
|
||||||
|
|
||||||
* gdb.base/sigbpt.exp: Make the common part of each test name a
|
* gdb.base/sigbpt.exp: Make the common part of each test name a
|
||||||
prefix instead of suffix.
|
prefix instead of suffix.
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright 1997, 1999, 2002, 2003, 2004 Free Software Foundation, Inc.
|
# Copyright 1997, 1999, 2002, 2003, 2004 Free Software Foundation, Inc.
|
||||||
|
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -14,12 +14,9 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||||
|
|
||||||
# Please email any bugs, comments, and/or additions to this file to:
|
|
||||||
# bug-gdb@prep.ai.mit.edu
|
|
||||||
|
|
||||||
if $tracelevel then {
|
if $tracelevel then {
|
||||||
strace $tracelevel
|
strace $tracelevel
|
||||||
}
|
}
|
||||||
|
|
||||||
set prms_id 0
|
set prms_id 0
|
||||||
set bug_id 0
|
set bug_id 0
|
||||||
@ -61,13 +58,13 @@ remote_exec build "${cleanupfile}"
|
|||||||
# build the first test case
|
# build the first test case
|
||||||
#
|
#
|
||||||
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
|
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
|
||||||
gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
|
gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Build the in-system-call test
|
# Build the in-system-call test
|
||||||
|
|
||||||
if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
|
if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
|
||||||
gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
|
gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
|
||||||
}
|
}
|
||||||
|
|
||||||
if [get_compiler_info ${binfile}] {
|
if [get_compiler_info ${binfile}] {
|
||||||
@ -75,401 +72,505 @@ if [get_compiler_info ${binfile}] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proc do_attach_tests {} {
|
proc do_attach_tests {} {
|
||||||
global gdb_prompt
|
global gdb_prompt
|
||||||
global binfile
|
global binfile
|
||||||
global escapedbinfile
|
global escapedbinfile
|
||||||
global srcfile
|
global srcfile
|
||||||
global testfile
|
global testfile
|
||||||
global objdir
|
global objdir
|
||||||
global subdir
|
global subdir
|
||||||
global timeout
|
global timeout
|
||||||
|
|
||||||
# Start the program running and then wait for a bit, to be sure
|
# Start the program running and then wait for a bit, to be sure
|
||||||
# that it can be attached to.
|
# 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.
|
set testpid [eval exec $binfile &]
|
||||||
#
|
exec sleep 2
|
||||||
send_gdb "attach abc\n"
|
if { [istarget "*-*-cygwin*"] } {
|
||||||
gdb_expect {
|
# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
|
||||||
-re ".*Illegal process-id: abc.*$gdb_prompt $"\
|
# different due to the way fork/exec works.
|
||||||
{pass "attach to nonsense is prohibited"}
|
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
||||||
-re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
|
}
|
||||||
{
|
|
||||||
# Response expected from /proc-based systems.
|
|
||||||
pass "attach to nonsense is prohibited"
|
|
||||||
}
|
|
||||||
-re ".*Can't attach to process..*$gdb_prompt $"\
|
|
||||||
{
|
|
||||||
# Response expected on Cygwin
|
|
||||||
pass "attach to nonsense is prohibited"
|
|
||||||
}
|
|
||||||
-re "Attaching to.*$gdb_prompt $"\
|
|
||||||
{fail "attach to nonsense is prohibited (bogus pid allowed)"}
|
|
||||||
-re "$gdb_prompt $" {fail "attach to nonsense is prohibited"}
|
|
||||||
timeout {fail "(timeout) attach to nonsense is prohibited"}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Verify that we cannot attach to what appears to be a valid
|
# Verify that we cannot attach to nonsense.
|
||||||
# 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
|
|
||||||
}
|
|
||||||
send_gdb "attach $boguspid\n"
|
|
||||||
gdb_expect {
|
|
||||||
-re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $"\
|
|
||||||
{
|
|
||||||
# Response expected on ptrace-based systems (i.e. HP-UX 10.20).
|
|
||||||
pass "attach to nonexistent process is prohibited"
|
|
||||||
}
|
|
||||||
-re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $"\
|
|
||||||
{
|
|
||||||
# Response expected on ttrace-based systems (i.e. HP-UX 11.0).
|
|
||||||
pass "attach to nonexistent process is prohibited"
|
|
||||||
}
|
|
||||||
-re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $"\
|
|
||||||
{pass "attach to nonexistent process is prohibited"}
|
|
||||||
-re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $"\
|
|
||||||
{pass "attach to nonexistent process is prohibited"}
|
|
||||||
-re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
|
|
||||||
{
|
|
||||||
# Response expected from /proc-based systems.
|
|
||||||
pass "attach to nonexistent process is prohibited"
|
|
||||||
}
|
|
||||||
-re ".*Can't attach to process..*$gdb_prompt $"\
|
|
||||||
{
|
|
||||||
# Response expected on Cygwin
|
|
||||||
pass "attach to nonexistent process is prohibited"
|
|
||||||
}
|
|
||||||
-re "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
|
|
||||||
timeout {
|
|
||||||
fail "(timeout) attach to nonexistent process is prohibited"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Verify that we can attach to the process by first giving its
|
send_gdb "attach abc\n"
|
||||||
# executable name via the file command, and using attach with
|
gdb_expect {
|
||||||
# the process ID.
|
-re ".*Illegal process-id: abc.*$gdb_prompt $" {
|
||||||
#
|
pass "attach to nonsense is prohibited"
|
||||||
# (Actually, the test system appears to do this automatically
|
}
|
||||||
# for us. So, we must also be prepared to be asked if we want
|
-re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
|
||||||
# to discard an existing set of symbols.)
|
# Response expected from /proc-based systems.
|
||||||
#
|
pass "attach to nonsense is prohibited"
|
||||||
send_gdb "file $binfile\n"
|
}
|
||||||
gdb_expect {
|
-re ".*Can't attach to process..*$gdb_prompt $" {
|
||||||
-re "Load new symbol table from.*y or n.*$" {
|
# Response expected on Cygwin
|
||||||
send_gdb "y\n"
|
pass "attach to nonsense is prohibited"
|
||||||
gdb_expect {
|
}
|
||||||
-re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
|
-re "Attaching to.*$gdb_prompt $" {
|
||||||
{pass "(re)set file, before attach1"}
|
fail "attach to nonsense is prohibited (bogus pid allowed)"
|
||||||
-re "$gdb_prompt $" {fail "(re)set file, before attach1"}
|
}
|
||||||
timeout {fail "(timeout) (re)set file, before attach1"}
|
-re "$gdb_prompt $" {
|
||||||
}
|
fail "attach to nonsense is prohibited"
|
||||||
}
|
}
|
||||||
-re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
|
timeout {
|
||||||
{pass "set file, before attach1"}
|
fail "(timeout) attach to nonsense is prohibited"
|
||||||
-re "$gdb_prompt $" {fail "set file, before attach1"}
|
}
|
||||||
timeout {fail "(timeout) set file, before attach1"}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
send_gdb "attach $testpid\n"
|
# Verify that we cannot attach to what appears to be a valid
|
||||||
gdb_expect {
|
# process ID, but is a process that doesn't exist. Traditionally,
|
||||||
-re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
|
# most systems didn't have a process with ID 0, so we take that as
|
||||||
{pass "attach1, after setting file"}
|
# the default. However, there are a few exceptions.
|
||||||
-re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $"\
|
|
||||||
{
|
|
||||||
# Response expected on Cygwin
|
|
||||||
pass "attach1, after setting file"
|
|
||||||
}
|
|
||||||
-re "$gdb_prompt $" {fail "attach1, after setting file"}
|
|
||||||
timeout {fail "(timeout) attach1, after setting file"}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Verify that we can "see" the variable "should_exit" in the
|
set boguspid 0
|
||||||
# program, and that it is zero.
|
if { [istarget "*-*-*bsd*"] } {
|
||||||
#
|
# In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
|
||||||
send_gdb "print should_exit\n"
|
# (which should have the desired effect on any version of
|
||||||
gdb_expect {
|
# FreeBSD, and probably other *BSD's too).
|
||||||
-re ".* = 0.*$gdb_prompt $"\
|
set boguspid -1
|
||||||
{pass "after attach1, print should_exit"}
|
}
|
||||||
-re "$gdb_prompt $" {fail "after attach1, print should_exit"}
|
send_gdb "attach $boguspid\n"
|
||||||
timeout {fail "(timeout) after attach1, print should_exit"}
|
gdb_expect {
|
||||||
}
|
-re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $" {
|
||||||
|
# Response expected on ptrace-based systems (i.e. HP-UX 10.20).
|
||||||
|
pass "attach to nonexistent process is prohibited"
|
||||||
|
}
|
||||||
|
-re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $" {
|
||||||
|
# Response expected on ttrace-based systems (i.e. HP-UX 11.0).
|
||||||
|
pass "attach to nonexistent process is prohibited"
|
||||||
|
}
|
||||||
|
-re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $" {
|
||||||
|
pass "attach to nonexistent process is prohibited"
|
||||||
|
}
|
||||||
|
-re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $" {
|
||||||
|
pass "attach to nonexistent process is prohibited"
|
||||||
|
}
|
||||||
|
-re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $" {
|
||||||
|
# Response expected from /proc-based systems.
|
||||||
|
pass "attach to nonexistent process is prohibited"
|
||||||
|
}
|
||||||
|
-re ".*Can't attach to process..*$gdb_prompt $" {
|
||||||
|
# Response expected on Cygwin
|
||||||
|
pass "attach to nonexistent process is prohibited"
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "attach to nonexistent process is prohibited"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) attach to nonexistent process is prohibited"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Detach the process.
|
# Verify that we can attach to the process by first giving its
|
||||||
#
|
# executable name via the file command, and using attach with the
|
||||||
send_gdb "detach\n"
|
# process ID.
|
||||||
gdb_expect {
|
|
||||||
-re "Detaching from program: .*$escapedbinfile.*$gdb_prompt $"\
|
|
||||||
{pass "attach1 detach"}
|
|
||||||
-re "$gdb_prompt $" {fail "attach1 detach"}
|
|
||||||
timeout {fail "(timeout) attach1 detach"}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Wait a bit for gdb to finish detaching
|
# (Actually, the test system appears to do this automatically for
|
||||||
#
|
# us. So, we must also be prepared to be asked if we want to
|
||||||
exec sleep 5
|
# discard an existing set of symbols.)
|
||||||
|
|
||||||
# Purge the symbols from gdb's brain. (We want to be certain
|
send_gdb "file $binfile\n"
|
||||||
# the next attach, which won't be preceded by a "file" command,
|
gdb_expect {
|
||||||
# is really getting the executable file without our help.)
|
-re "Load new symbol table from.*y or n.*$" {
|
||||||
#
|
send_gdb "y\n"
|
||||||
set old_timeout $timeout
|
gdb_expect {
|
||||||
set timeout 15
|
-re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
|
||||||
send_gdb "file\n"
|
pass "(re)set file, before attach1"
|
||||||
gdb_expect {
|
}
|
||||||
-re ".*gdb internal error.*$" {
|
-re "$gdb_prompt $" {
|
||||||
fail "Internal error, prob. Memory corruption"
|
fail "(re)set file, before attach1"
|
||||||
}
|
}
|
||||||
-re "No executable file now.*Discard symbol table.*y or n.*$" {
|
timeout {
|
||||||
send_gdb "y\n"
|
fail "(timeout) (re)set file, before attach1"
|
||||||
gdb_expect {
|
}
|
||||||
-re "No symbol file now.*$gdb_prompt $"\
|
}
|
||||||
{pass "attach1, purging symbols after detach"}
|
}
|
||||||
-re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
|
-re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
|
||||||
timeout {fail "(timeout) attach1, purging symbols after detach"}
|
pass "set file, before attach1"
|
||||||
}
|
}
|
||||||
}
|
-re "$gdb_prompt $" {
|
||||||
-re "$gdb_prompt $" {fail "attach1, purging file after detach"}
|
fail "set file, before attach1"
|
||||||
timeout {
|
}
|
||||||
fail "(timeout) attach1, purging file after detach"
|
timeout {
|
||||||
}
|
fail "(timeout) set file, before attach1"
|
||||||
}
|
}
|
||||||
set timeout $old_timeout
|
}
|
||||||
|
|
||||||
# Verify that we can attach to the process just by giving the
|
send_gdb "attach $testpid\n"
|
||||||
# process ID.
|
gdb_expect {
|
||||||
#
|
-re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $" {
|
||||||
send_gdb "attach $testpid\n"
|
pass "attach1, after setting file"
|
||||||
gdb_expect {
|
}
|
||||||
-re "Attaching to process $testpid.*Load new symbol table from \"$escapedbinfile\.exe\".*y or n.*$" {
|
-re "Attaching to program.*`?$escapedbinfile\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
|
||||||
# On Cygwin, the DLL's symbol tables are loaded prior to the
|
# Response expected on Cygwin
|
||||||
# executable's symbol table. This in turn always results in
|
pass "attach1, after setting file"
|
||||||
# asking the user for actually loading the symbol table of the
|
}
|
||||||
# executable.
|
-re "$gdb_prompt $" {
|
||||||
send_gdb "y\n"
|
fail "attach1, after setting file"
|
||||||
gdb_expect {
|
}
|
||||||
-re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
|
timeout {
|
||||||
{pass "(re)set file, before attach2"}
|
fail "(timeout) attach1, after setting file"
|
||||||
-re "$gdb_prompt $"\
|
}
|
||||||
{fail "(re)set file, before attach2"}
|
}
|
||||||
timeout {fail "(timeout) (re)set file, before attach2"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
|
|
||||||
{pass "attach2"}
|
|
||||||
-re "$gdb_prompt $" {fail "attach2"}
|
|
||||||
timeout {fail "(timeout) attach2"}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Verify that we can modify the variable "should_exit" in the
|
# Verify that we can "see" the variable "should_exit" in the
|
||||||
# program.
|
# program, and that it is zero.
|
||||||
#
|
|
||||||
send_gdb "set should_exit=1\n"
|
|
||||||
gdb_expect {
|
|
||||||
-re "$gdb_prompt $" {pass "after attach2, set should_exit"}
|
|
||||||
timeout {fail "(timeout) after attach2, set should_exit"}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Verify that the modification really happened.
|
send_gdb "print should_exit\n"
|
||||||
#
|
gdb_expect {
|
||||||
send_gdb "tbreak 19\n"
|
-re ".* = 0.*$gdb_prompt $" {
|
||||||
gdb_expect {
|
pass "after attach1, print should_exit"
|
||||||
-re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
|
}
|
||||||
{pass "after attach2, set tbreak postloop"}
|
-re "$gdb_prompt $" {
|
||||||
-re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
|
fail "after attach1, print should_exit"
|
||||||
timeout {fail "(timeout) after attach2, set tbreak postloop"}
|
}
|
||||||
}
|
timeout {
|
||||||
send_gdb "continue\n"
|
fail "(timeout) after attach1, print should_exit"
|
||||||
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.
|
# Detach the process.
|
||||||
#
|
|
||||||
send_gdb "continue\n"
|
|
||||||
gdb_expect {
|
|
||||||
-re "Program exited normally.*$gdb_prompt $"\
|
|
||||||
{pass "after attach2, exit"}
|
|
||||||
-re "$gdb_prompt $" {fail "after attach2, exit"}
|
|
||||||
timeout {fail "(timeout) after attach2, exit"}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Make sure we don't leave a process around to confuse
|
send_gdb "detach\n"
|
||||||
# the next test run (and prevent the compile by keeping
|
gdb_expect {
|
||||||
# the text file busy), in case the "set should_exit" didn't
|
-re "Detaching from program: .*$escapedbinfile.*$gdb_prompt $" {
|
||||||
# work.
|
pass "attach1 detach"
|
||||||
#
|
}
|
||||||
remote_exec build "kill -9 ${testpid}"
|
-re "$gdb_prompt $" {
|
||||||
# Start the program running and then wait for a bit, to be sure
|
fail "attach1 detach"
|
||||||
# that it can be attached to.
|
}
|
||||||
#
|
timeout {
|
||||||
set testpid [eval exec $binfile &]
|
fail "(timeout) attach1 detach"
|
||||||
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
|
# Wait a bit for gdb to finish detaching
|
||||||
# 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.)
|
|
||||||
#
|
|
||||||
send_gdb "dir ${objdir}/${subdir}\n"
|
|
||||||
gdb_expect {
|
|
||||||
-re ".*Source directories searched: .*$gdb_prompt $"\
|
|
||||||
{pass "set source path"}
|
|
||||||
-re "$gdb_prompt $" {fail "set source path"}
|
|
||||||
timeout {fail "(timeout) set source path"}
|
|
||||||
}
|
|
||||||
|
|
||||||
send_gdb "cd /tmp\n"
|
exec sleep 5
|
||||||
gdb_expect {
|
|
||||||
-re ".*Working directory /tmp.*$gdb_prompt $"\
|
|
||||||
{pass "cd away from process' a.out"}
|
|
||||||
-re "$gdb_prompt $" {fail "cd away from process' a.out"}
|
|
||||||
timeout {fail "(timeout) cd away from process' a.out"}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Explicitly flush out any knowledge of the previous attachment.
|
# Purge the symbols from gdb's brain. (We want to be certain the
|
||||||
send_gdb "symbol\n"
|
# next attach, which won't be preceded by a "file" command, is
|
||||||
gdb_expect {
|
# really getting the executable file without our help.)
|
||||||
-re ".*Discard symbol table from.*y or n. $"\
|
|
||||||
{send_gdb "y\n"
|
|
||||||
gdb_expect {
|
|
||||||
-re ".*No symbol file now.*$gdb_prompt $"\
|
|
||||||
{pass "before attach3, flush symbols"}
|
|
||||||
-re "$gdb_prompt $" {fail "before attach3, flush symbols"}
|
|
||||||
timeout {fail "(timeout) before attach3, flush symbols"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-re ".*No symbol file now.*$gdb_prompt $"\
|
|
||||||
{pass "before attach3, flush symbols"}
|
|
||||||
-re "$gdb_prompt $" {fail "before attach3, flush symbols"}
|
|
||||||
timeout {fail "(timeout) before attach3, flush symbols"}
|
|
||||||
}
|
|
||||||
send_gdb "exec\n"
|
|
||||||
gdb_expect {
|
|
||||||
-re ".*No executable file now.*$gdb_prompt $"\
|
|
||||||
{pass "before attach3, flush exec"}
|
|
||||||
-re "$gdb_prompt $" {fail "before attach3, flush exec"}
|
|
||||||
timeout {fail "(timeout) before attach3, flush exec"}
|
|
||||||
}
|
|
||||||
|
|
||||||
send_gdb "attach $testpid\n"
|
set old_timeout $timeout
|
||||||
gdb_expect {
|
set timeout 15
|
||||||
-re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
|
send_gdb "file\n"
|
||||||
{pass "attach when process' a.out not in cwd"}
|
gdb_expect {
|
||||||
-re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
|
-re ".*gdb internal error.*$" {
|
||||||
timeout {fail "(timeout) attach when process' a.out not in cwd"}
|
fail "Internal error, prob. Memory corruption"
|
||||||
}
|
}
|
||||||
|
-re "No executable file now.*Discard symbol table.*y or n.*$" {
|
||||||
|
send_gdb "y\n"
|
||||||
|
gdb_expect {
|
||||||
|
-re "No symbol file now.*$gdb_prompt $" {
|
||||||
|
pass "attach1, purging symbols after detach"
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "attach1, purging symbols after detach"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) attach1, purging symbols after detach"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "attach1, purging file after detach"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) attach1, purging file after detach"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set timeout $old_timeout
|
||||||
|
|
||||||
send_gdb "kill\n"
|
# Verify that we can attach to the process just by giving the
|
||||||
gdb_expect {
|
# process ID.
|
||||||
-re ".*Kill the program being debugged.*y or n. $"\
|
|
||||||
{send_gdb "y\n"
|
|
||||||
gdb_expect {
|
|
||||||
-re "$gdb_prompt $" {pass "after attach3, exit"}
|
|
||||||
timeout {fail "(timeout) after attach3, exit"}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-re "$gdb_prompt $" {fail "after attach3, exit"}
|
|
||||||
timeout {fail "(timeout) after attach3, exit"}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Another "don't leave a process around"
|
send_gdb "attach $testpid\n"
|
||||||
remote_exec build "kill -9 ${testpid}"
|
gdb_expect {
|
||||||
|
-re "Attaching to process $testpid.*Load new symbol table from \"$escapedbinfile\.exe\".*y or n.*$" {
|
||||||
|
# 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.
|
||||||
|
send_gdb "y\n"
|
||||||
|
gdb_expect {
|
||||||
|
-re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
|
||||||
|
pass "(re)set file, before attach2"
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "(re)set file, before attach2"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) (re)set file, before attach2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
-re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $" {
|
||||||
|
pass "attach2"
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "attach2"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) attach2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verify that we can modify the variable "should_exit" in the
|
||||||
|
# program.
|
||||||
|
|
||||||
|
send_gdb "set should_exit=1\n"
|
||||||
|
gdb_expect {
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
pass "after attach2, set should_exit"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) after attach2, set should_exit"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
send_gdb "continue\n"
|
||||||
|
gdb_expect {
|
||||||
|
-re "Program exited normally.*$gdb_prompt $" {
|
||||||
|
pass "after attach2, exit"
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "after attach2, exit"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) after attach2, exit"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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}"
|
||||||
|
# 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.)
|
||||||
|
|
||||||
|
send_gdb "dir ${objdir}/${subdir}\n"
|
||||||
|
gdb_expect {
|
||||||
|
-re ".*Source directories searched: .*$gdb_prompt $" {
|
||||||
|
pass "set source path"
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "set source path"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) set source path"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
send_gdb "cd /tmp\n"
|
||||||
|
gdb_expect {
|
||||||
|
-re ".*Working directory /tmp.*$gdb_prompt $" {
|
||||||
|
pass "cd away from process' a.out"
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "cd away from process' a.out"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) cd away from process' a.out"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Explicitly flush out any knowledge of the previous attachment.
|
||||||
|
send_gdb "symbol\n"
|
||||||
|
gdb_expect {
|
||||||
|
-re ".*Discard symbol table from.*y or n. $" {
|
||||||
|
send_gdb "y\n"
|
||||||
|
gdb_expect {
|
||||||
|
-re ".*No symbol file now.*$gdb_prompt $" {
|
||||||
|
pass "before attach3, flush symbols"
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "before attach3, flush symbols"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) before attach3, flush symbols"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
-re ".*No symbol file now.*$gdb_prompt $" {
|
||||||
|
pass "before attach3, flush symbols"
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "before attach3, flush symbols"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) before attach3, flush symbols"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
send_gdb "exec\n"
|
||||||
|
gdb_expect {
|
||||||
|
-re ".*No executable file now.*$gdb_prompt $" {
|
||||||
|
pass "before attach3, flush exec"
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "before attach3, flush exec"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) before attach3, flush exec"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
send_gdb "attach $testpid\n"
|
||||||
|
gdb_expect {
|
||||||
|
-re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $" {
|
||||||
|
pass "attach when process' a.out not in cwd"
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "attach when process' a.out not in cwd"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) attach when process' a.out not in cwd"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
send_gdb "kill\n"
|
||||||
|
gdb_expect {
|
||||||
|
-re ".*Kill the program being debugged.*y or n. $" {
|
||||||
|
send_gdb "y\n"
|
||||||
|
gdb_expect {
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
pass "after attach3, exit"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) after attach3, exit"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "after attach3, exit"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) after attach3, exit"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Another "don't leave a process around"
|
||||||
|
remote_exec build "kill -9 ${testpid}"
|
||||||
}
|
}
|
||||||
|
|
||||||
proc do_call_attach_tests {} {
|
proc do_call_attach_tests {} {
|
||||||
global gdb_prompt
|
global gdb_prompt
|
||||||
global binfile2
|
global binfile2
|
||||||
|
|
||||||
# Start the program running and then wait for a bit, to be sure
|
# Start the program running and then wait for a bit, to be sure
|
||||||
# that it can be attached to.
|
# that it can be attached to.
|
||||||
#
|
|
||||||
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
|
set testpid [eval exec $binfile2 &]
|
||||||
#
|
exec sleep 2
|
||||||
gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
|
if { [istarget "*-*-cygwin*"] } {
|
||||||
send_gdb "attach $testpid\n"
|
# testpid is the Cygwin PID, GDB uses the Windows PID, which might be
|
||||||
gdb_expect {
|
# different due to the way fork/exec works.
|
||||||
-re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
|
set testpid [ exec ps -e | gawk "{ if (\$1 == $testpid) print \$4; }" ]
|
||||||
fail "attach call, read register 3 error"
|
}
|
||||||
}
|
|
||||||
-re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
|
|
||||||
pass "attach call"
|
|
||||||
}
|
|
||||||
-re "Attaching to.*process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
|
|
||||||
pass "attach call"
|
|
||||||
}
|
|
||||||
-re "$gdb_prompt $" {fail "attach call"}
|
|
||||||
timeout {fail "(timeout) attach call"}
|
|
||||||
}
|
|
||||||
|
|
||||||
# See if other registers are problems
|
# Attach
|
||||||
#
|
|
||||||
send_gdb "i r r3\n"
|
|
||||||
gdb_expect {
|
|
||||||
-re ".*warning: reading register.*$gdb_prompt $" {
|
|
||||||
pass "CHFts23490: known bug"
|
|
||||||
}
|
|
||||||
-re ".*r3.*$gdb_prompt $" {
|
|
||||||
pass "Bug fixed, Yayyy!"
|
|
||||||
}
|
|
||||||
timeout { fail "timeout on info reg" }
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get rid of the process
|
gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
|
||||||
#
|
send_gdb "attach $testpid\n"
|
||||||
gdb_test "p should_exit = 1" ".*"
|
gdb_expect {
|
||||||
gdb_test "c" ".*Program exited normally.*"
|
-re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
|
||||||
|
fail "attach call, read register 3 error"
|
||||||
|
}
|
||||||
|
-re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
|
||||||
|
pass "attach call"
|
||||||
|
}
|
||||||
|
-re "Attaching to.*process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
|
||||||
|
pass "attach call"
|
||||||
|
}
|
||||||
|
-re "$gdb_prompt $" {
|
||||||
|
fail "attach call"
|
||||||
|
}
|
||||||
|
timeout {
|
||||||
|
fail "(timeout) attach call"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# See if other registers are problems
|
||||||
|
|
||||||
|
send_gdb "i r r3\n"
|
||||||
|
gdb_expect {
|
||||||
|
-re ".*warning: reading register.*$gdb_prompt $" {
|
||||||
|
pass "CHFts23490: known bug"
|
||||||
|
}
|
||||||
|
-re ".*r3.*$gdb_prompt $" {
|
||||||
|
pass "Bug fixed, Yayyy!"
|
||||||
|
}
|
||||||
|
timeout { fail "timeout on info reg" }
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get rid of the process
|
||||||
|
|
||||||
|
gdb_test "p should_exit = 1" ".*"
|
||||||
|
gdb_test "c" ".*Program exited normally.*"
|
||||||
|
|
||||||
|
# Be paranoid
|
||||||
|
|
||||||
# Be paranoid
|
|
||||||
#
|
|
||||||
remote_exec build "kill -9 ${testpid}"
|
remote_exec build "kill -9 ${testpid}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Start with a fresh gdb
|
# Start with a fresh gdb
|
||||||
#
|
|
||||||
gdb_exit
|
gdb_exit
|
||||||
gdb_start
|
gdb_start
|
||||||
gdb_reinitialize_dir $srcdir/$subdir
|
gdb_reinitialize_dir $srcdir/$subdir
|
||||||
gdb_load ${binfile}
|
gdb_load ${binfile}
|
||||||
|
|
||||||
# This is a test of gdb's ability to attach to a running process.
|
# This is a test of gdb's ability to attach to a running process.
|
||||||
#
|
|
||||||
do_attach_tests
|
do_attach_tests
|
||||||
|
|
||||||
# Test attaching when the target is inside a system call
|
# Test attaching when the target is inside a system call
|
||||||
#
|
|
||||||
gdb_exit
|
gdb_exit
|
||||||
gdb_start
|
gdb_start
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user