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