1# manythreads.exp -- Expect script to test stopping many threads 2# Copyright (C) 2004-2019 Free Software Foundation, Inc. 3 4# This program is free software; you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation; either version 3 of the License, or 7# (at your option) any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17# This file was written by Jeff Johnston. (jjohnstn@redhat.com) 18 19# This test requires sending ^C to interrupt the running target. 20if [target_info exists gdb,nointerrupts] { 21 verbose "Skipping manythreads.exp because of nointerrupts." 22 return 23} 24 25standard_testfile 26 27set opts { debug } 28if [info exists DEBUG] { 29 # make check RUNTESTFLAGS='gdb.threads/manythreads.exp DEBUG=1' 30 lappend opts "additional_flags=-DDEBUG" 31} 32 33if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $opts] != "" } { 34 return -1 35} 36 37clean_restart ${binfile} 38gdb_test_no_output "set print sevenbit-strings" 39runto_main 40 41# We'll need this when we send_gdb a ^C to GDB. Need to do it before we 42# run the program and gdb starts saving and restoring tty states. 43gdb_test "shell stty intr '^C'" ".*" 44 45set message "first continue" 46gdb_test_multiple "continue" "first continue" { 47 -re "error:.*$gdb_prompt $" { 48 fail "$message" 49 } 50 -re "Continuing" { 51 pass "$message" 52 } 53} 54 55# Wait one second. This is better than the TCL "after" command, because 56# we don't lose GDB's output while we do it. 57remote_expect host 1 { timeout { } } 58 59# Send a Ctrl-C and wait for the SIGINT. 60 61proc interrupt_and_wait { message } { 62 global gdb_prompt 63 64 send_gdb "\003" 65 66 gdb_test_multiple "" $message { 67 -re "\\\[New \[^\]\]*\\\]\r\n" { 68 exp_continue 69 } 70 -re "\\\[\[^\]\]* exited\\\]\r\n" { 71 exp_continue 72 } 73 -re " received signal SIGINT.*$gdb_prompt $" { 74 pass "$message" 75 } 76 -re "$gdb_prompt $" { 77 # Note that with this regex order, if GDB emits [New 78 # Thread ...] output between "Thread NNN received signal" 79 # and the prompt, the "received signal" regex won't match. 80 # That's good, as if we see that happening, it's a 81 # regression. 82 # 83 # GDB makes sure to notify about signal stops, end of 84 # stepping ranges, etc., only after updating the thread 85 # list, otherwise that stop info would be easy to miss. 86 # 87 # A BROKEN example would be: 88 # 89 # ... pages of new threads output ... 90 # [New Thread NNN] 91 # ^C 92 # ... more new threads output ... 93 # [New Thread NNN] 94 # [New Thread NNN] 95 # Thread NNN received signal SIGINT, Interrupt. 96 # [New Thread NNN] 97 # [New Thread NNN] 98 # ... pages of new threads output ... 99 # [Switching to Thread NNN] 100 # foo () at foo.c:31 101 # 31 bar (); 102 # 103 fail $message 104 } 105 } 106} 107 108# Send a Ctrl-C and verify that we can do info threads and continue 109interrupt_and_wait "stop threads 1" 110 111set cmd "info threads" 112set ok 0 113gdb_test_multiple $cmd $cmd { 114 -re " 1 *Thread " { 115 set ok 1 116 exp_continue 117 } 118 -re ".*\r\n" { 119 # Eat this line and continue, to prevent the buffer overflowing. 120 exp_continue 121 } 122 -re "$gdb_prompt $" { 123 if { $ok } { 124 pass $cmd 125 } else { 126 fail $cmd 127 } 128 } 129} 130 131gdb_test_no_output "thread name zardoz" "give a name to the thread" 132gdb_test "info threads" ".*zardoz.*" "check thread name" 133 134set message "second continue" 135gdb_test_multiple "continue" "second continue" { 136 -re "error:.*$gdb_prompt $" { 137 fail "$message" 138 } 139 -re "Continuing" { 140 pass "$message" 141 } 142} 143 144# Wait another second. If the program stops on its own, GDB has failed 145# to handle duplicate SIGINTs sent to multiple threads. 146set failed 0 147remote_expect host 1 { 148 -re "\\\[New \[^\]\]*\\\]\r\n" { 149 exp_continue -continue_timer 150 } 151 -re "\\\[\[^\]\]* exited\\\]\r\n" { 152 exp_continue -continue_timer 153 } 154 -re " received signal SIGINT.*$gdb_prompt $" { 155 if { $failed == 0 } { 156 fail "check for duplicate SIGINT" 157 } 158 send_gdb "continue\n" 159 set failed 1 160 exp_continue 161 } 162 timeout { 163 if { $failed == 0 } { 164 pass "check for duplicate SIGINT" 165 } 166 } 167} 168 169# Send another Ctrl-C and verify that we can do info threads and quit 170interrupt_and_wait "stop threads 2" 171 172gdb_test_multiple "quit" "GDB exits after stopping multithreaded program" { 173 -re "Quit anyway\\? \\(y or n\\) $" { 174 send_gdb "y\n" 175 exp_continue 176 } 177 eof { 178 pass "GDB exits after stopping multithreaded program" 179 } 180 timeout { 181 fail "GDB exits after stopping multithreaded program (timeout)" 182 } 183} 184 185