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 is based on gdb.base/attach.exp with modifications by Jeff Johnston
18 # <jjohnstn@redhat.com> and Jan Kratochvil <jan.kratochvil@redhat.com>.
20 # This test only works on Linux
21 if { ![isnative] || [is_remote host] || ![istarget *-linux*] } {
25 set testfile "attachstop-mt"
26 set srcfile ${testfile}.c
27 set binfile ${objdir}/${subdir}/${testfile}
28 set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
30 #execute_anywhere "rm -f ${binfile}"
31 remote_exec build "rm -f ${binfile}"
32 # For debugging this test
38 if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
39 untested attachstop-mt.exp
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 # The testcase has three threads, find some other thread TID for $testpid2.
56 set tids [exec sh -c "echo /proc/$testpid/task/*"]
57 regsub -all /proc/$testpid/task/ $tids {} tids
59 unresolved "/proc/PID/task is not supported (kernel-2.4?)"
60 remote_exec build "kill -9 ${testpid}"
63 set tids [lsort -integer [split $tids]]
64 if {[llength $tids] != 3 || [lindex $tids 0] != $testpid} {
65 verbose -log "Invalid TIDs <$tids> for PID $testpid"
66 fail "Invalid TIDs found"
67 remote_exec build "kill -9 ${testpid}"
70 set testpid2 [lindex $tids 2]
72 # Initial sanity test it is normally sleeping
73 set status2 /proc/${testpid}/task/${testpid2}/status
74 set fileid0 [open $status2 r];
79 set test "attach0, initial sanity check of the sleeping state"
80 if {[string match "*(sleeping)*" $line2]} {
86 # Sttach and detach to test it will not become stopped
88 gdb_reinitialize_dir $srcdir/$subdir
91 set test "attach0 to sleeping"
92 gdb_test_multiple "attach $testpid" "$test" {
93 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
98 gdb_test "gcore /dev/null" ".*aved corefile.*" "attach0 to sleeping gcore invocation"
100 gdb_test "thread 2" ".*witching to thread 2 .*" "attach0 to sleeping switch thread"
102 gdb_test "bt" ".*sleep.*func.*" "attach0 to sleeping bt"
104 # Exit and detach the process.
111 # Check it did not get stopped by our gdb
112 set fileid1 [open $status2 r];
117 set test "attach1, post-gdb sanity check of the sleeping state - Red Hat BZ 197584"
118 if {[string match "*(sleeping)*" $line2]} {
125 remote_exec build "kill -s STOP ${testpid}"
130 # Check it really got stopped by kill(1)
131 set fileid2 [open $status2 r];
136 set test "attach2, initial sanity check of the stopped state"
137 if {[string match "*(stopped)*" $line2]} {
143 # Start with clean gdb
145 gdb_reinitialize_dir $srcdir/$subdir
148 # Verify that we can attach to the process by first giving its
149 # executable name via the file command, and using attach with the
152 set test "set file, before attach3 to stopped process"
153 gdb_test_multiple "file $binfile" "$test" {
154 -re "Load new symbol table from.*y or n. $" {
155 gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
158 -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
163 set test "attach3 to stopped, after setting file"
164 gdb_test_multiple "attach $testpid" "$test" {
165 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
170 # We may be already after the threads phase.
171 # `thread 2' command is important for the test to switch the current thread to
172 # a non-primary one for the detach process.
174 gdb_test "thread 2" ".*(witching to thread 2 |hread ID 2 not known).*" "attach3 to stopped switch thread"
175 gdb_test "bt" ".*sleep.*(func|main).*" "attach3 to stopped bt"
177 # Exit and detach the process.
181 remote_exec build "kill -s STOP ${testpid}"
186 # Continue the test as we would hit another expected bug regarding
187 # Program received signal SIGSTOP, Stopped (signal).
188 # across NPTL threads.
191 gdb_reinitialize_dir $srcdir/$subdir
194 # Verify that we can attach to the process just by giving the
197 set test "attach4 to stopped, after setting file"
198 gdb_test_multiple "attach $testpid" "$test" {
199 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
204 # We may be already after the threads phase.
205 # `thread 2' command is important for the test to switch the current thread to
206 # a non-primary one for the detach process.
208 gdb_test "thread 2" ".*(witching to thread 2 |hread ID 2 not known).*" "attach4 to stopped switch thread"
209 gdb_test "bt" ".*sleep.*(func|main).*" "attach4 to stopped bt"
211 # RHEL3U8 kernel-2.4.21-47.EL will not return SIGINT but only shorten the sleep.
212 gdb_breakpoint [gdb_get_line_number "Ridiculous time"]
213 gdb_breakpoint [gdb_get_line_number "cut the sleep time"]
214 set test "attach4 continue"
215 send_gdb "continue\n"
218 { pass "continue ($test)" }
220 { fail "continue ($test) (timeout)" }
223 # For this to work we must be sure to consume the "Continuing."
224 # message first, or GDB's signal handler may not be in place.
225 after 1000 {send_gdb "\003"}
226 set test "attach4 stop by interrupt"
228 -re "Program received signal SIGINT.*$gdb_prompt $"
232 -re "Breakpoint \[0-9\].*$srcfile.*$gdb_prompt $"
238 fail "$test (timeout)"
247 # At this point, the process should be sleeping
249 set fileid4 [open $status2 r];
254 set test "attach4, exit leaves process sleeping"
255 if {[string match "*(sleeping)*" $line2]} {
261 # Make sure we don't leave a process around to confuse
262 # the next test run (and prevent the compile by keeping
263 # the text file busy), in case the "set should_exit" didn't
266 remote_exec build "kill -9 ${testpid}"