2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This test was created by modifying gdb.threads/attachstop.
18 # This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
19 # Regression for: https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=197584
21 # This test only works on Linux
22 if { ![isnative] || [is_remote host] || ![istarget *-linux*] } {
26 set testfile "attachstop-mt"
27 set srcfile ${testfile}.c
28 set binfile ${objdir}/${subdir}/${testfile}
29 set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
31 #execute_anywhere "rm -f ${binfile}"
32 remote_exec build "rm -f ${binfile}"
33 # For debugging this test
39 if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
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.
50 set testpid [eval exec $binfile &]
55 # Do not: set testpid2 [expr $testpid + 1]
56 # as it will not exist on Red Hat 2.6.9-34.0.2.ELsmp
57 set testpid2 [expr $testpid + 2]
59 set status2 /proc/${testpid}/task/${testpid2}/status
60 if {[expr ! [file exists $status2]]} {
62 set status2 /proc/${testpid2}/status
65 # Initial sanity test it is normally sleeping
66 set fileid0 [open $status2 r];
71 set test "attach0, initial sanity check of the sleeping state"
72 if {[string match "*(sleeping)*" $line2]} {
78 # Sttach and detach to test it will not become stopped
80 gdb_reinitialize_dir $srcdir/$subdir
83 set test "attach0 to sleeping"
84 gdb_test_multiple "attach $testpid" "$test" {
85 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
90 gdb_test "gcore /dev/null" ".*aved corefile.*" "attach0 to sleeping gcore invocation"
92 gdb_test "thread 2" ".*witching to thread 2 .*" "attach0 to sleeping switch thread"
94 gdb_test "bt" ".*sleep.*func.*" "attach0 to sleeping bt"
96 # Exit and detach the process.
103 # Check it did not get stopped by our gdb
104 set fileid1 [open $status2 r];
109 set test "attach1, post-gdb sanity check of the sleeping state - Red Hat BZ 197584"
110 if {[string match "*(sleeping)*" $line2]} {
117 remote_exec build "kill -s STOP ${testpid}"
122 # Check it really got stopped by kill(1)
123 set fileid2 [open $status2 r];
128 set test "attach2, initial sanity check of the stopped state"
129 if {[string match "*(stopped)*" $line2]} {
135 # Start with clean gdb
137 gdb_reinitialize_dir $srcdir/$subdir
140 # Verify that we can attach to the process by first giving its
141 # executable name via the file command, and using attach with the
144 set test "set file, before attach3 to stopped process"
145 gdb_test_multiple "file $binfile" "$test" {
146 -re "Load new symbol table from.*y or n. $" {
147 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
150 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
155 set test "attach3 to stopped, after setting file"
156 gdb_test_multiple "attach $testpid" "$test" {
157 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
162 # We may be already after the threads phase.
163 # `thread 2' command is important for the test to switch the current thread to
164 # a non-primary one for the detach process.
166 gdb_test "thread 2" ".*(witching to thread 2 |hread ID 2 not known).*" "attach3 to stopped switch thread"
167 gdb_test "bt" ".*sleep.*(func|main).*" "attach3 to stopped bt"
169 # Exit and detach the process.
173 remote_exec build "kill -s STOP ${testpid}"
178 # Continue the test as we would hit another expected bug regarding
179 # Program received signal SIGSTOP, Stopped (signal).
180 # across NPTL threads.
183 gdb_reinitialize_dir $srcdir/$subdir
186 # Verify that we can attach to the process just by giving the
189 set test "attach4 to stopped, after setting file"
190 gdb_test_multiple "attach $testpid" "$test" {
191 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
196 # We may be already after the threads phase.
197 # `thread 2' command is important for the test to switch the current thread to
198 # a non-primary one for the detach process.
200 gdb_test "thread 2" ".*(witching to thread 2 |hread ID 2 not known).*" "attach4 to stopped switch thread"
201 gdb_test "bt" ".*sleep.*(func|main).*" "attach4 to stopped bt"
203 # RHEL3U8 kernel-2.4.21-47.EL will not return SIGINT but only shorten the sleep.
204 gdb_breakpoint [gdb_get_line_number "Ridiculous time"]
205 gdb_breakpoint [gdb_get_line_number "cut the sleep time"]
206 set test "attach4 continue"
207 send_gdb "continue\n"
210 { pass "continue ($test)" }
212 { fail "continue ($test) (timeout)" }
215 # For this to work we must be sure to consume the "Continuing."
216 # message first, or GDB's signal handler may not be in place.
217 after 1000 {send_gdb "\003"}
218 set test "attach4 stop by interrupt"
220 -re "Program received signal SIGINT.*$gdb_prompt $"
224 -re "Breakpoint \[0-9\].*$srcfile.*$gdb_prompt $"
230 fail "$test (timeout)"
239 # At this point, the process should be sleeping
241 set fileid4 [open $status2 r];
246 set test "attach4, exit leaves process sleeping"
247 if {[string match "*(sleeping)*" $line2]} {
253 # Make sure we don't leave a process around to confuse
254 # the next test run (and prevent the compile by keeping
255 # the text file busy), in case the "set should_exit" didn't
258 remote_exec build "kill -9 ${testpid}"