]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/attach-stopped.exp
11-10-28 Sterling Augustine <saugustine@google.com>
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / attach-stopped.exp
CommitLineData
7b6bb8da 1# Copyright 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
a0ef4274
DJ
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.exp.
17# This file was created by Jeff Johnston <jjohnstn@redhat.com>.
18# This file was updated by Jan Kratochvil <jan.kratochvil@redhat.com>.
19
20# This test only works on Linux
21if { ![isnative] || [is_remote host] || ![istarget *-linux*] } {
22 continue
23}
24
25set testfile "attach-stopped"
26set srcfile ${testfile}.c
27set binfile ${objdir}/${subdir}/${testfile}
28set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
29
30#execute_anywhere "rm -f ${binfile}"
31remote_exec build "rm -f ${binfile}"
32# For debugging this test
33#
34#log_user 1
35
36proc corefunc { threadtype } {
37 global srcfile
38 global binfile
39 global escapedbinfile
40 global srcdir
41 global subdir
42 global gdb_prompt
43
44 if [get_compiler_info ${binfile}] {
45 return -1
46 }
47
48 # Start the program running and then wait for a bit, to be sure
49 # that it can be attached to.
50
51 set testpid [eval exec $binfile &]
52
53 # Avoid some race:
54 sleep 2
55
56 # Stop the program
57 remote_exec build "kill -s STOP ${testpid}"
58
59 # Start with clean gdb
60 gdb_exit
61 gdb_start
62 gdb_reinitialize_dir $srcdir/$subdir
63 gdb_load ${binfile}
64
65 # Verify that we can attach to the stopped process.
66
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 $" {
70 pass "$test"
71 }
72 }
73
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"
77 } else {
78 gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach2 to stopped bt"
79 }
80 # This breakpoint is there for old/non-x86 kernels not restarting syscalls.
55b1fd0c 81 gdb_breakpoint $srcfile:[gdb_get_line_number "Second sleep"]
a0ef4274 82 set test "$threadtype: attach2 continue"
9db70545
MS
83 gdb_test_multiple "continue" "continue ($test)" {
84 -re "Continuing" {
85 pass "continue ($test)"
86 }
a0ef4274
DJ
87 }
88
89 # For this to work we must be sure to consume the "Continuing."
90 # message first, or GDB's signal handler may not be in place.
91 after 1000 {send_gdb "\003"}
92 set test "$threadtype: attach2 stop interrupt"
93 gdb_expect 10 {
94 -re "Program received signal SIGINT.*$gdb_prompt $"
95 {
96 pass $test
97 }
98 -re "Breakpoint \[0-9\].*$srcfile.*$gdb_prompt $"
99 {
100 pass $test
101 }
102 timeout
103 {
104 fail $test
105 }
106 }
107
108 gdb_exit
109
110 # Avoid some race:
111 sleep 2
112
113 # At this point, the process should be sleeping
114
115 if [catch {open /proc/${testpid}/status r} fileid2] {
116 set line2 "NOTFOUND"
117 } else {
118 gets $fileid2 line1;
119 gets $fileid2 line2;
120 close $fileid2;
121 }
122
123 set test "$threadtype: attach2, exit leaves process sleeping"
124 if {[string match "*(sleeping)*" $line2]} {
125 pass $test
126 } else {
127 fail $test
128 }
129
130 # Make sure we don't leave a process around to confuse
131 # the next test run (and prevent the compile by keeping
132 # the text file busy), in case the "set should_exit" didn't
133 # work.
134
135 remote_exec build "kill -9 ${testpid}"
136}
137
138# build the test case first without threads
139#
140if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
c7a6ca08
PA
141 untested "attach-stopped.exp (unthreaded)"
142 return -1
a0ef4274
DJ
143}
144
145corefunc nonthreaded
146
147# build the test case first without threads
148#
149if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DUSE_THREADS}] != "" } {
c7a6ca08
PA
150 untested "attach-stopped.exp (threaded)"
151 return -1
a0ef4274
DJ
152}
153
154corefunc threaded
155
156return 0