]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/interrupt.exp
Copyright year update in most files of the GDB Project.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / interrupt.exp
1 # Copyright 1994-2000, 2007-2012 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 if [target_info exists gdb,nointerrupts] {
17 verbose "Skipping interrupt.exp because of nointerrupts."
18 continue
19 }
20
21 if [target_info exists gdb,noinferiorio] {
22 verbose "Skipping interrupt.exp because of noinferiorio."
23 return
24 }
25
26 if $tracelevel then {
27 strace $tracelevel
28 }
29
30
31 set testfile interrupt
32 set srcfile ${testfile}.c
33 set binfile ${objdir}/${subdir}/${testfile}
34
35 set options { debug }
36 if { ! [target_info exists gdb,nosignals] } {
37 lappend options "additional_flags=-DSIGNALS"
38 }
39
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $options] != "" } {
41 untested interrupt.exp
42 return -1
43 }
44
45 gdb_start
46
47
48 if ![file exists $binfile] then {
49 perror "$binfile does not exist."
50 return 0
51 } else {
52 gdb_reinitialize_dir $srcdir/$subdir
53 gdb_load $binfile
54 # Hope this is unix :-)
55 gdb_test "shell stty intr '^C'" ".*" \
56 "set interrupt character in interrupt.exp"
57 if [runto_main] then {
58 send_gdb "continue\n"
59 gdb_expect {
60 -re "\r\ntalk to me baby\r\n$" {
61 pass "child process is alive"
62 }
63 timeout { fail "run (timeout)" }
64 eof { fail "run (eof)" }
65 }
66 # This should appear twice, once for the echo and once for the
67 # program's output. Under dejagnu (but not interactively) for
68 # SunOS4, it only appears once. Don't worry about it, I imagine
69 # dejagnu has just done something to the tty modes.
70 send_gdb "a\n"
71 gdb_expect {
72 -re "^a\r\n(|a\r\n)$" {
73 pass "child process ate our char"
74 }
75 timeout { fail "echo a (timeout)" }
76 eof { fail "echo a (eof)" }
77 }
78 # Wait until the program is in the read system call again.
79 sleep 2
80
81 # Cntrl-c may fail for simulator targets running on a BSD host.
82 # This is the result of a combination of the read syscall
83 # being restarted and gdb capturing the cntrl-c signal.
84
85 # Cntrl-c may fail for simulator targets on slow hosts.
86 # This is because there is a race condition between entering
87 # the read and delivering the cntrl-c.
88
89 send_gdb "\003"
90 gdb_expect {
91 -re "Program received signal SIGINT.*$gdb_prompt $" {
92 pass "send_gdb control C"
93 }
94 -re ".*$gdb_prompt $" { fail "send_gdb control C" }
95 timeout { fail "send_gdb control C (timeout)" }
96 eof { fail "send_gdb control C (eof)" }
97 }
98
99 send_gdb "p func1 ()\n"
100 gdb_expect {
101 -re " = 4.*$gdb_prompt $" { pass "call function when asleep" }
102 -re ".*Program received signal SIG(SEGV|ILL).*$gdb_prompt $" {
103 setup_xfail "i*86-pc-linux*-gnu*"
104 fail "child died when we called func1, skipped rest of tests"
105 return
106 }
107 -re "$gdb_prompt $" {
108 # On HPUX-11.0 'send "p func1 ()"' above
109 # terminates the program. A defect is pending on this
110 # issue [defect #DTS CHFts24203]. Hence calling setup_xfail
111 # below.
112 setup_xfail "hppa*-*-*11*" CHFts24203
113 fail "call function when asleep (wrong output)"
114 }
115 default {
116
117 # This fail probably happens whenever we use /proc (we
118 # don't use PRSABORT), but apparently also happens on
119 # other machines as well.
120
121 setup_xfail "sparc*-*-solaris2*"
122 setup_xfail "mips-*-ultrix*"
123 setup_xfail "i*86-*-solaris2*"
124 setup_xfail "*-*-sysv4*"
125 setup_xfail "vax-*-*"
126 setup_xfail "alpha-*-*"
127 setup_xfail "*-*-*bsd*"
128 setup_xfail "*-*-irix*"
129 setup_xfail "*-*-hpux*"
130 setup_xfail "*-*-*lynx*"
131 fail "call function when asleep (stays asleep)"
132 # Send_Gdb a newline to wake it up
133 send_gdb "\n"
134 gdb_test "" " = 4" "call function after waking it"
135 }
136 # eof { fail "call function when asleep (eof)" }
137 }
138
139 # Now try calling the function again.
140 gdb_test "p func1 ()" " = 4" "call function a second time"
141
142 # And the program should still be doing the same thing.
143 # The optional trailing \r\n is in case we sent a newline above
144 # to wake the program, in which case the program now sends it
145 # back. We check for it either here or in the next gdb_expect
146 # command, because which one it ends up in is timing dependent.
147 send_gdb "continue\n"
148 # For some reason, i386-*-sysv4 gdb fails to issue the Continuing
149 # message, but otherwise appears normal (FIXME).
150 gdb_expect {
151 -re "^continue\r\nContinuing.\r\n(\r\n|)$" { pass "continue" }
152 -re "^continue\r\n\r\n" { fail "continue (missing Continuing.)" }
153 -re "$gdb_prompt $" { fail "continue" }
154 timeout { fail "continue (timeout)" }
155 eof { fail "continue (eof)" }
156 }
157
158 send_gdb "data\n"
159 # The optional leading \r\n is in case we sent a newline above
160 # to wake the program, in which case the program now sends it
161 # back.
162 # FIXME: The pattern below leads to an expected success on HPUX-11.0
163 # but the success is spurious. Need to provide the right reg.expr.
164 # here.
165 gdb_expect {
166 -re "^(\r\n|)data\r\n(|data\r\n)$" { pass "echo data" }
167 -re "Undefined command.*$gdb_prompt " { fail "echo data" }
168 timeout { fail "echo data (timeout)" }
169 eof { fail "echo data (eof)" }
170 }
171
172 if { ! [target_info exists gdb,nosignals] } {
173 # Wait until the program is in the read system call again.
174 sleep 2
175
176 # Stop the program for another test.
177 set msg "Send Control-C, second time"
178 send_gdb "\003"
179 gdb_test_multiple "" "$msg" {
180 -re "Program received signal SIGINT.*$gdb_prompt $" {
181 pass "$msg"
182 }
183 }
184
185 # The "signal" command should deliver the correct signal and
186 # return to the loop.
187 set msg "signal SIGINT"
188 gdb_test_multiple "signal SIGINT" "$msg" {
189 -re "^signal SIGINT\r\nContinuing with signal SIGINT.\r\n(\r\n|)$" { pass "$msg" }
190 }
191
192 # We should be back in the loop.
193 send_gdb "more data\n"
194 gdb_expect {
195 -re "^(\r\n|)more data\r\n(|more data\r\n)$" { pass "echo more data" }
196 timeout { fail "echo more data (timeout)" }
197 eof { fail "echo more data (eof)" }
198 }
199 }
200
201 send_gdb "\004"
202 gdb_expect {
203 -re "end of file.*$inferior_exited_re normally.*$gdb_prompt $" {
204 pass "send end of file"
205 }
206 -re "$gdb_prompt $" { fail "send end of file" }
207 timeout { fail "send end of file (timeout)" }
208 eof { fail "send end of file (eof)" }
209 }
210 }
211 }
212 return 0