1 # Copyright 1994-2022 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 if [target_info exists gdb,nointerrupts] {
17 verbose "Skipping interrupt.exp because of nointerrupts."
21 if [target_info exists gdb,noinferiorio] {
22 verbose "Skipping interrupt.exp because of noinferiorio."
29 if { ! [target_info exists gdb,nosignals] } {
30 lappend options "additional_flags=-DSIGNALS"
33 if {[build_executable $testfile.exp $testfile $srcfile $options] == -1} {
34 untested "failed to compile"
41 if {![file exists $binfile]} {
44 gdb_reinitialize_dir $srcdir/$subdir
46 # Hope this is unix :-)
47 gdb_test "shell stty intr '^C'" ".*" \
48 "set interrupt character"
50 global inferior_spawn_id gdb_spawn_id
52 set msg "process is alive"
53 gdb_test_multiple "continue" $msg {
54 -i "$inferior_spawn_id" -re "talk to me baby\r\n" {
59 # This should appear twice, once for the echo and once for the
62 set msg "child process ate our char"
64 gdb_test_multiple "" $msg {
65 -i "$inferior_spawn_id" -re "^a\r\na\r\n$" {
70 # Wait until the program is in the read system call again.
73 # Cntrl-c may fail for simulator targets running on a BSD host.
74 # This is the result of a combination of the read syscall
75 # being restarted and gdb capturing the cntrl-c signal.
77 # Cntrl-c may fail for simulator targets on slow hosts.
78 # This is because there is a race condition between entering
79 # the read and delivering the cntrl-c.
82 set msg "send_gdb control C"
83 gdb_test_multiple "" $msg {
84 -re "Program received signal SIGINT.*$gdb_prompt $" {
89 set msg "call function when asleep"
90 send_gdb "p func1 ()\n"
91 gdb_test_multiple "" $msg {
92 -re " = 4.*$gdb_prompt $" {
95 -re ".*Program received signal SIG(SEGV|ILL).*$gdb_prompt $" {
96 setup_xfail "i*86-pc-linux*-gnu*"
97 fail "child died when we called func1, skipped rest of tests"
100 -re "$gdb_prompt $" {
101 fail "call function when asleep (wrong output)"
105 # This fail probably happens whenever we use /proc (we
106 # don't use PRSABORT), but apparently also happens on
107 # other machines as well.
109 setup_xfail "sparc*-*-solaris2*"
110 setup_xfail "i*86-*-solaris2*"
111 setup_xfail "*-*-sysv4*"
112 setup_xfail "vax-*-*"
113 setup_xfail "alpha-*-*"
114 setup_xfail "*-*-*bsd*"
115 setup_xfail "*-*-*lynx*"
116 fail "$msg (stays asleep)"
117 # Send the inferior a newline to wake it up.
119 gdb_test "" " = 4" "call function after waking it"
123 # Now try calling the function again.
124 gdb_test "p func1 ()" " = 4" "call function a second time"
126 # And the program should still be doing the same thing.
127 # The optional trailing \r\n is in case we sent a newline above
128 # to wake the program, in which case the program now sends it
129 # back. We check for it either here or in the next gdb_expect
130 # command, because which one it ends up in is timing dependent.
131 send_gdb "continue\n"
132 # For some reason, i386-*-sysv4 gdb fails to issue the Continuing
133 # message, but otherwise appears normal (FIXME).
136 gdb_test_multiple "" "$msg" {
137 -re "^continue\r\nContinuing.\r\n(\r\n|)$" {
140 -re "^continue\r\n\r\n" {
141 fail "$msg (missing Continuing.)"
145 send_inferior "data\n"
146 # The optional leading \r\n is in case we sent a newline above
147 # to wake the program, in which case the program now sends it
151 gdb_test_multiple "" $msg {
152 -i "$inferior_spawn_id" -re "^(\r\n|)data\r\ndata\r\n$" {
155 -i "$gdb_spawn_id" -re "Undefined command.*$gdb_prompt " {
160 if { ! [target_info exists gdb,nosignals] } {
161 # Wait until the program is in the read system call again.
164 # Stop the program for another test.
165 set msg "Send Control-C, second time"
167 gdb_test_multiple "" "$msg" {
168 -re "Program received signal SIGINT.*$gdb_prompt $" {
173 # The "signal" command should deliver the correct signal and
174 # return to the loop.
175 set msg "signal SIGINT"
176 gdb_test_multiple "signal SIGINT" "$msg" {
177 -re "^signal SIGINT\r\nContinuing with signal SIGINT.\r\n(\r\n|)$" {
182 # We should be back in the loop.
183 send_inferior "more data\n"
185 set msg "echo more data"
186 gdb_test_multiple "" $msg {
187 -i "$inferior_spawn_id" -re "^(\r\n|)more data\r\nmore data\r\n$" {
193 set saw_end_of_file 0
194 set saw_inferior_exit 0
196 set msg "send end of file"
199 set spawn_list "$inferior_spawn_id"
201 gdb_test_multiple "" $msg {
202 -i spawn_list -re "end of file" {
203 set saw_end_of_file 1
204 verbose -log "saw \"end of file\""
205 if {!$saw_inferior_exit} {
206 # When $inferior_spawn_id != $gdb_spawn_id, such
207 # as when testing with gdbserver, we may see the
208 # eof (the process exit, not the string just
209 # matched) for $inferior_spawn_id before the
210 # expected gdb output. Clear this so we no longer
211 # expect anything out of $inferior_spawn_id.
216 -i "$gdb_spawn_id" -re "$inferior_exited_re normally.*$gdb_prompt " {
217 set saw_inferior_exit 1
218 verbose -log "saw inferior exit"
219 if {!$saw_end_of_file} {
225 gdb_assert { $saw_end_of_file && $saw_inferior_exit } $msg