mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-27 04:52:05 +08:00
266 lines
7.0 KiB
Plaintext
266 lines
7.0 KiB
Plaintext
# Copyright 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
|
|
|
# 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
# This test is based on gdb.base/attach.exp with modifications by Jeff Johnston
|
|
# <jjohnstn@redhat.com> and Jan Kratochvil <jan.kratochvil@redhat.com>.
|
|
|
|
# This test only works on Linux
|
|
if { ![isnative] || [is_remote host] || ![istarget *-linux*] } {
|
|
continue
|
|
}
|
|
|
|
set testfile "attachstop-mt"
|
|
set srcfile ${testfile}.c
|
|
set binfile ${objdir}/${subdir}/${testfile}
|
|
set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
|
|
|
|
#execute_anywhere "rm -f ${binfile}"
|
|
remote_exec build "rm -f ${binfile}"
|
|
# For debugging this test
|
|
#
|
|
#log_user 1
|
|
|
|
# build the test case
|
|
#
|
|
if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
|
|
untested attachstop-mt.exp
|
|
return -1
|
|
}
|
|
|
|
if [get_compiler_info ${binfile}] {
|
|
return -1
|
|
}
|
|
|
|
# Start the program running and then wait for a bit, to be sure
|
|
# that it can be attached to.
|
|
|
|
set testpid [eval exec $binfile &]
|
|
|
|
# No race
|
|
sleep 2
|
|
|
|
# The testcase has three threads, find some other thread TID for $testpid2.
|
|
set tids [exec sh -c "echo /proc/$testpid/task/*"]
|
|
regsub -all /proc/$testpid/task/ $tids {} tids
|
|
if {$tids == "*"} {
|
|
unresolved "/proc/PID/task is not supported (kernel-2.4?)"
|
|
remote_exec build "kill -9 ${testpid}"
|
|
return -1
|
|
}
|
|
set tids [lsort -integer [split $tids]]
|
|
if {[llength $tids] != 3 || [lindex $tids 0] != $testpid} {
|
|
verbose -log "Invalid TIDs <$tids> for PID $testpid"
|
|
fail "Invalid TIDs found"
|
|
remote_exec build "kill -9 ${testpid}"
|
|
return -1
|
|
}
|
|
set testpid2 [lindex $tids 2]
|
|
|
|
# Initial sanity test it is normally sleeping
|
|
set status2 /proc/${testpid}/task/${testpid2}/status
|
|
set fileid0 [open $status2 r];
|
|
gets $fileid0 line1;
|
|
gets $fileid0 line2;
|
|
close $fileid0;
|
|
|
|
set test "attach0, initial sanity check of the sleeping state"
|
|
if {[string match "*(sleeping)*" $line2]} {
|
|
pass $test
|
|
} else {
|
|
fail $test
|
|
}
|
|
|
|
# Sttach and detach to test it will not become stopped
|
|
gdb_start
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
gdb_load ${binfile}
|
|
|
|
set test "attach0 to sleeping"
|
|
gdb_test_multiple "attach $testpid" "$test" {
|
|
-re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
|
|
pass "$test"
|
|
}
|
|
}
|
|
|
|
gdb_test "gcore /dev/null" ".*aved corefile.*" "attach0 to sleeping gcore invocation"
|
|
|
|
gdb_test "thread 2" ".*witching to thread 2 .*" "attach0 to sleeping switch thread"
|
|
|
|
gdb_test "bt" ".*sleep.*func.*" "attach0 to sleeping bt"
|
|
|
|
# Exit and detach the process.
|
|
|
|
gdb_exit
|
|
|
|
# No race
|
|
sleep 2
|
|
|
|
# Check it did not get stopped by our gdb
|
|
set fileid1 [open $status2 r];
|
|
gets $fileid1 line1;
|
|
gets $fileid1 line2;
|
|
close $fileid1;
|
|
|
|
set test "attach1, post-gdb sanity check of the sleeping state - Red Hat BZ 197584"
|
|
if {[string match "*(sleeping)*" $line2]} {
|
|
pass $test
|
|
} else {
|
|
fail $test
|
|
}
|
|
|
|
# Stop the program
|
|
remote_exec build "kill -s STOP ${testpid}"
|
|
|
|
# No race
|
|
sleep 2
|
|
|
|
# Check it really got stopped by kill(1)
|
|
set fileid2 [open $status2 r];
|
|
gets $fileid2 line1;
|
|
gets $fileid2 line2;
|
|
close $fileid2;
|
|
|
|
set test "attach2, initial sanity check of the stopped state"
|
|
if {[string match "*(stopped)*" $line2]} {
|
|
pass $test
|
|
} else {
|
|
fail $test
|
|
}
|
|
|
|
# Start with clean gdb
|
|
gdb_start
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
gdb_load ${binfile}
|
|
|
|
# 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.
|
|
|
|
set test "set file, before attach3 to stopped process"
|
|
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)"
|
|
}
|
|
-re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
|
|
pass "$test"
|
|
}
|
|
}
|
|
|
|
set test "attach3 to stopped, after setting file"
|
|
gdb_test_multiple "attach $testpid" "$test" {
|
|
-re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
|
|
pass "$test"
|
|
}
|
|
}
|
|
|
|
# We may be already after the threads phase.
|
|
# `thread 2' command is important for the test to switch the current thread to
|
|
# a non-primary one for the detach process.
|
|
|
|
gdb_test "thread 2" ".*(witching to thread 2 |hread ID 2 not known).*" "attach3 to stopped switch thread"
|
|
gdb_test "bt" ".*sleep.*(func|main).*" "attach3 to stopped bt"
|
|
|
|
# Exit and detach the process.
|
|
gdb_exit
|
|
|
|
# Stop the program
|
|
remote_exec build "kill -s STOP ${testpid}"
|
|
|
|
# No race
|
|
sleep 2
|
|
|
|
# Continue the test as we would hit another expected bug regarding
|
|
# Program received signal SIGSTOP, Stopped (signal).
|
|
# across NPTL threads.
|
|
|
|
gdb_start
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
gdb_load ${binfile}
|
|
|
|
# Verify that we can attach to the process just by giving the
|
|
# process ID.
|
|
|
|
set test "attach4 to stopped, after setting file"
|
|
gdb_test_multiple "attach $testpid" "$test" {
|
|
-re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
|
|
pass "$test"
|
|
}
|
|
}
|
|
|
|
# We may be already after the threads phase.
|
|
# `thread 2' command is important for the test to switch the current thread to
|
|
# a non-primary one for the detach process.
|
|
|
|
gdb_test "thread 2" ".*(witching to thread 2 |hread ID 2 not known).*" "attach4 to stopped switch thread"
|
|
gdb_test "bt" ".*sleep.*(func|main).*" "attach4 to stopped bt"
|
|
|
|
# RHEL3U8 kernel-2.4.21-47.EL will not return SIGINT but only shorten the sleep.
|
|
gdb_breakpoint [gdb_get_line_number "Ridiculous time"]
|
|
gdb_breakpoint [gdb_get_line_number "cut the sleep time"]
|
|
set test "attach4 continue"
|
|
gdb_test_multiple "continue" "continue ($test)" {
|
|
-re "Continuing" {
|
|
pass "continue ($test)"
|
|
}
|
|
}
|
|
|
|
# For this to work we must be sure to consume the "Continuing."
|
|
# message first, or GDB's signal handler may not be in place.
|
|
after 1000 {send_gdb "\003"}
|
|
set test "attach4 stop by interrupt"
|
|
gdb_expect {
|
|
-re "Program received signal SIGINT.*$gdb_prompt $"
|
|
{
|
|
pass $test
|
|
}
|
|
-re "Breakpoint \[0-9\].*$srcfile.*$gdb_prompt $"
|
|
{
|
|
pass $test
|
|
}
|
|
timeout
|
|
{
|
|
fail "$test (timeout)"
|
|
}
|
|
}
|
|
|
|
gdb_exit
|
|
|
|
# No race
|
|
sleep 2
|
|
|
|
# At this point, the process should be sleeping
|
|
|
|
set fileid4 [open $status2 r];
|
|
gets $fileid4 line1;
|
|
gets $fileid4 line2;
|
|
close $fileid4;
|
|
|
|
set test "attach4, exit leaves process sleeping"
|
|
if {[string match "*(sleeping)*" $line2]} {
|
|
pass $test
|
|
} else {
|
|
fail $test
|
|
}
|
|
|
|
# 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}"
|
|
|
|
return 0
|