1 # Copyright 2008, 2009 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.exp.
17 # This file was created by Jeff Johnston <jjohnstn@redhat.com>.
18 # This file was updated by Jan Kratochvil <jan.kratochvil@redhat.com>.
20 # This test only works on Linux
21 if { ![isnative] || [is_remote host] || ![istarget *-linux*] } {
25 set testfile "attach-stopped"
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
36 proc corefunc { threadtype } {
44 if [get_compiler_info ${binfile}] {
48 # Start the program running and then wait for a bit, to be sure
49 # that it can be attached to.
51 set testpid [eval exec $binfile &]
57 remote_exec build "kill -s STOP ${testpid}"
59 # Start with clean gdb
62 gdb_reinitialize_dir $srcdir/$subdir
65 # Verify that we can attach to the stopped process.
67 set test "$threadtype: attach2 to stopped, after setting file"
68 gdb_test_multiple "attach $testpid" "$test" {
69 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
74 # ".*sleep.*clone.*" would fail on s390x as bt stops at START_THREAD there.
75 if {[string equal $threadtype threaded]} {
76 gdb_test "thread apply all bt" ".*sleep.*start_thread.*" "$threadtype: attach2 to stopped bt"
78 gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach2 to stopped bt"
80 # This breakpoint is there for old/non-x86 kernels not restarting syscalls.
81 gdb_breakpoint [gdb_get_line_number "Second sleep"]
82 set test "$threadtype: attach2 continue"
86 { pass "continue ($test)" }
88 { fail "continue ($test) (timeout)" }
91 # For this to work we must be sure to consume the "Continuing."
92 # message first, or GDB's signal handler may not be in place.
93 after 1000 {send_gdb "\003"}
94 set test "$threadtype: attach2 stop interrupt"
96 -re "Program received signal SIGINT.*$gdb_prompt $"
100 -re "Breakpoint \[0-9\].*$srcfile.*$gdb_prompt $"
115 # At this point, the process should be sleeping
117 if [catch {open /proc/${testpid}/status r} fileid2] {
125 set test "$threadtype: attach2, exit leaves process sleeping"
126 if {[string match "*(sleeping)*" $line2]} {
132 # Make sure we don't leave a process around to confuse
133 # the next test run (and prevent the compile by keeping
134 # the text file busy), in case the "set should_exit" didn't
137 remote_exec build "kill -9 ${testpid}"
140 # build the test case first without threads
142 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
143 untested "attach-stopped.exp (unthreaded)"
149 # build the test case first without threads
151 if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DUSE_THREADS}] != "" } {
152 untested "attach-stopped.exp (threaded)"