1 # Copyright 2008-2012 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This test was created by modifying attach-stopped.exp.
17 # This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
19 # This test only works on Linux
20 if { ![isnative] || [is_remote host] || [target_info exists use_gdb_stub]
21 || ![istarget *-linux*] } {
25 set testfile "attach-into-signal"
26 set srcfile ${testfile}.c
27 set binfile ${objdir}/${subdir}/${testfile}
28 set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
30 remote_exec build "rm -f ${binfile}"
31 # For debugging this test
35 proc corefunc { threadtype } {
43 if [get_compiler_info ${binfile}] {
47 # Start the program running and then wait for a bit, to be sure
48 # that it can be attached to.
49 # Statistically there is a better chance without giving process a nice.
51 set testpid [eval exec $binfile &]
54 # Run 2 passes of the test.
55 # The C file inferior stops pending its signals if a single one is lost,
56 # we test successful redelivery of the caught signal by the 2nd pass.
58 # linux-2.6.20.4.x86_64 had maximal attempt # 20 in 4 test runs.
62 while { $passes < 3 && $attempt <= $attempts } {
64 while { $stoppedtry < 10 } {
65 if [catch {open /proc/${testpid}/status r} fileid] {
73 if {![string match "*(stopped)*" $line2]} {
74 # No PASS message as we may be looping in multiple attempts.
78 set stoppedtry [expr $stoppedtry + 1]
80 if { $stoppedtry >= 10 } {
82 set test "$threadtype: process is still running on the attempt # $attempt of $attempts"
87 set test "$threadtype: attach (pass $passes), pending signal catch"
88 if {[gdb_test_multiple "attach $testpid" $test {
89 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*Received Alarm clock.*$gdb_prompt $" {
92 verbose -log "$test succeeded on the attempt # $attempt of $attempts"
93 set passes [expr $passes + 1]
95 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
97 # We just lack the luck, we should try it again.
98 set attempt [expr $attempt + 1]
100 -re "Attaching to process $testpid.*Received Alarm clock.*$gdb_prompt $" {
103 verbose -log "$test succeeded on the attempt # $attempt of $attempts"
104 set passes [expr $passes + 1]
106 -re "Attaching to process $testpid.*$gdb_prompt $" {
108 # We just lack the luck, we should try it again.
109 set attempt [expr $attempt - 1]
115 gdb_test "detach" "Detaching from.*" ""
118 if {$attempt > $attempts} {
125 # Exit and detach the process.
129 # Make sure we don't leave a process around to confuse
130 # the next test run (and prevent the compile by keeping
131 # the text file busy), in case the "set should_exit" didn't
134 # Continue the program - some Linux kernels need it before -9 if the
135 # process is stopped.
136 remote_exec build "kill -s CONT ${testpid}"
138 remote_exec build "kill -9 ${testpid}"
141 # Start with clean gdb
144 # build the test case first without threads
146 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
147 untested "attach-into-signal.exp (unthreaded)"
152 gdb_reinitialize_dir $srcdir/$subdir
154 gdb_test_no_output "set debug lin-lwp 1" ""
158 # build the test case also with threads
160 if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DUSE_THREADS}] != "" } {
161 untested "attach-into-signal.exp (threaded)"
166 gdb_reinitialize_dir $srcdir/$subdir
168 gdb_test_no_output "set debug lin-lwp 1" ""