]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.threads/attach-into-signal.exp
277a9d06574f85a7f4f4704a53c0de9822e3defa
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / attach-into-signal.exp
1 # Copyright 2008-2014 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # This test was created by modifying attach-stopped.exp.
17 # This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
18
19 # This test only works on Linux
20 if { ![isnative] || [is_remote host] || [target_info exists use_gdb_stub]
21 || ![istarget *-linux*] } {
22 continue
23 }
24
25 standard_testfile
26 set executable_nothr ${testfile}-nothr
27 set executable_thr ${testfile}-thr
28
29 proc corefunc { threadtype executable } {
30 global srcfile
31 global srcdir
32 global subdir
33 global gdb_prompt
34
35 with_test_prefix "$threadtype" {
36 clean_restart ${executable}
37
38 set binfile [standard_output_file $executable]
39 set escapedbinfile [string_to_regexp ${binfile}]
40
41 if [get_compiler_info] {
42 return -1
43 }
44
45 gdb_test "handle SIGALRM stop print pass" "Yes.*Yes.*Yes.*"
46
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.
50
51 set testpid [eval exec $binfile &]
52 exec sleep 2
53
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.
57
58 # linux-2.6.20.4.x86_64 had maximal attempt # 20 in 4 test runs.
59 set attempts 100
60 set attempt 1
61 set passes 1
62 while { $passes < 3 && $attempt <= $attempts } {
63 set stoppedtry 0
64 while { $stoppedtry < 10 } {
65 if [catch {open /proc/${testpid}/status r} fileid] {
66 set stoppedtry 10
67 break
68 }
69 gets $fileid line1
70 gets $fileid line2
71 close $fileid
72
73 if {![string match "*(stopped)*" $line2]} {
74 # No PASS message as we may be looping in multiple
75 # attempts.
76 break
77 }
78 sleep 1
79 set stoppedtry [expr $stoppedtry + 1]
80 }
81 if { $stoppedtry >= 10 } {
82 verbose -log $line2
83 set test "process is still running on the attempt # $attempt of $attempts"
84 break
85 }
86
87 # Main test:
88 set test "attach (pass $passes), pending signal catch"
89 if {[gdb_test_multiple "attach $testpid" $test {
90 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*Program received signal SIGALRM.*$gdb_prompt $" {
91 # nonthreaded:
92 pass $test
93 verbose -log "$test succeeded on the attempt # $attempt of $attempts"
94 set passes [expr $passes + 1]
95 }
96 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
97 set ok 0
98
99 if { $threadtype == "threaded" } {
100 # In the threaded case, the signal is left
101 # pending on the second thread. Check for
102 # that by peeking at the thread's siginfo.
103 # SIGALRM is 14, SIGSTOP is 19.
104
105 set test2 "thread apply 2 print \$_siginfo.si_signo"
106 gdb_test_multiple $test2 $test2 {
107 -re " = 14\r\n$gdb_prompt $" {
108 set ok 1
109 }
110 -re " = 19\r\n$gdb_prompt $" {
111 }
112 }
113 } else {
114 # In the nonthreaded case, GDB should tell the
115 # user about having seen a signal.
116 }
117
118 if { $ok == 0} {
119 # We just lack the luck, we should try it again.
120 set attempt [expr $attempt + 1]
121 } else {
122 pass $test
123 verbose -log "$test succeeded on the attempt # $attempt of $attempts"
124 set passes [expr $passes + 1]
125 }
126 }
127 }] != 0 } {
128 break
129 }
130
131 gdb_test "detach" "Detaching from.*" ""
132 }
133 if {$passes < 3} {
134 if {$attempt > $attempts} {
135 unresolved $test
136 } else {
137 fail $test
138 }
139 }
140
141 # Exit and detach the process.
142
143 gdb_exit
144
145 # Make sure we don't leave a process around to confuse the
146 # next test run (and prevent the compile by keeping the text
147 # file busy), in case the "set should_exit" didn't work.
148
149 # Continue the program - some Linux kernels need it before -9 if the
150 # process is stopped.
151 remote_exec build "kill -s CONT ${testpid}"
152
153 remote_exec build "kill -9 ${testpid}"
154
155 }
156 }
157
158 # build the test case first without threads
159 #
160 if {[build_executable $testfile $executable_nothr $srcfile] == -1} {
161 untested "attach-into-signal.exp (nonthreaded)"
162 return -1
163 }
164
165 corefunc nonthreaded ${executable_nothr}
166
167 # build the test case also with threads
168 #
169 if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" [standard_output_file ${executable_thr}] executable {debug additional_flags=-DUSE_THREADS}] != "" } {
170 untested "attach-into-signal.exp (threaded)"
171 return -1
172 }
173
174 corefunc threaded ${executable_thr}