1# manythreads.exp -- Expect script to test stopping many threads 2# Copyright (C) 2004-2023 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 set saw_signal 0 67 set order_ok 1 68 gdb_test_multiple "" $message { 69 -re "\r\n\\\[New \[^\r\n\]*(?=\r\n)" { 70 # Note if GDB emits [New Thread ...] output between 71 # "Thread NNN received signal" and the prompt, it's a 72 # regression. 73 # 74 # GDB makes sure to notify about signal stops, end of 75 # stepping ranges, etc., only after updating the thread 76 # list, otherwise that stop info would be easy to miss. 77 # 78 # A BROKEN example would be: 79 # 80 # ... pages of new threads output ... 81 # [New Thread NNN] 82 # ^C 83 # ... more new threads output ... 84 # [New Thread NNN] 85 # [New Thread NNN] 86 # Thread NNN received signal SIGINT, Interrupt. 87 # [New Thread NNN] 88 # [New Thread NNN] 89 # ... pages of new threads output ... 90 # [Switching to Thread NNN] 91 # foo () at foo.c:31 92 # 31 bar (); 93 # 94 if { $saw_signal } { 95 set order_ok 0 96 } 97 exp_continue 98 } 99 -re "\r\n\\\[\[^\r\n]* exited\\\](?=\r\n)" { 100 exp_continue 101 } 102 -re "\r\n\[^\r\n]* received signal SIGINT\[^\r\n\]*(?=\r\n)" { 103 set saw_signal 1 104 exp_continue 105 } 106 -re -wrap "" { 107 gdb_assert {$saw_signal && $order_ok} $gdb_test_name 108 } 109 } 110} 111 112# Send a Ctrl-C and verify that we can do info threads and continue 113interrupt_and_wait "stop threads 1" 114 115set cmd "info threads" 116set ok 0 117gdb_test_multiple $cmd $cmd { 118 -re " 1 *Thread " { 119 set ok 1 120 exp_continue 121 } 122 -re ".*\r\n" { 123 # Eat this line and continue, to prevent the buffer overflowing. 124 exp_continue 125 } 126 -re "$gdb_prompt $" { 127 if { $ok } { 128 pass $cmd 129 } else { 130 fail $cmd 131 } 132 } 133} 134 135gdb_test_no_output "thread name zardoz" "give a name to the thread" 136gdb_test "info threads" ".*zardoz.*" "check thread name" 137 138set message "second continue" 139gdb_test_multiple "continue" "second continue" { 140 -re "error:.*$gdb_prompt $" { 141 fail "$message" 142 } 143 -re "Continuing" { 144 pass "$message" 145 } 146} 147 148# Wait another second. If the program stops on its own, GDB has failed 149# to handle duplicate SIGINTs sent to multiple threads. 150set failed 0 151remote_expect host 1 { 152 -re "\\\[New \[^\]\]*\\\]\r\n" { 153 exp_continue -continue_timer 154 } 155 -re "\\\[\[^\]\]* exited\\\]\r\n" { 156 exp_continue -continue_timer 157 } 158 -re " received signal SIGINT.*$gdb_prompt $" { 159 if { $failed == 0 } { 160 fail "check for duplicate SIGINT" 161 } 162 send_gdb "continue\n" 163 set failed 1 164 exp_continue 165 } 166 timeout { 167 if { $failed == 0 } { 168 pass "check for duplicate SIGINT" 169 } 170 } 171} 172 173# Send another Ctrl-C and verify that we can do info threads and quit 174interrupt_and_wait "stop threads 2" 175 176gdb_test_multiple "quit" "GDB exits after stopping multithreaded program" { 177 -re "Quit anyway\\? \\(y or n\\) $" { 178 send_gdb "y\n" 179 exp_continue 180 } 181 eof { 182 pass "GDB exits after stopping multithreaded program" 183 } 184 timeout { 185 fail "GDB exits after stopping multithreaded program (timeout)" 186 } 187} 188 189