1# Copyright 2013-2019 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# Test that disconnecting and reconnecting doesn't lose signals. 17 18set gdbserver_reconnect_p 1 19if { [info proc gdb_reconnect] == "" } { 20 return 0 21} 22 23standard_testfile 24set executable ${testfile} 25 26if { [gdb_compile_pthreads \ 27 "${srcdir}/${subdir}/${srcfile}" \ 28 "${binfile}" \ 29 executable {debug}] != "" } { 30 untested "failed to compile" 31 return -1 32} 33 34clean_restart $executable 35 36if ![runto_main] then { 37 fail "can't run to main" 38 return 0 39} 40 41gdb_test "continue" "signal SIGUSR1.*" "continue to signal" 42 43# Check that it's thread 2 that is selected. 44gdb_test "info threads" "\\* 2 .*" "thread 2 is selected" 45 46set msg "save \$pc after signal" 47set saved_pc "" 48gdb_test_multiple "print/x \$pc" $msg { 49 -re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" { 50 set saved_pc $expect_out(1,string) 51 pass $msg 52 } 53} 54 55# Switch to the other thread. 56gdb_test "thread 1" "thread 1.*" "switch to thread 1" 57 58# Force GDB to select thread 1 on the remote end as well. 59gdb_test "print/x \$pc" 60 61gdb_test "disconnect" "Ending remote debugging\\." "disconnect after signal" 62 63set test "reconnect after signal" 64 65set res [gdb_reconnect] 66if { [lindex $res 0] == 0 } { 67 pass $test 68} else { 69 fail $test 70 return 0 71} 72 73# Check that thread 2 is re-selected. 74gdb_test "info threads" "\\* 2 .*" "thread 2 is selected on reconnect" 75 76# Check that the program is still alive, and stopped in the same spot. 77gdb_test "print/x \$pc" "\\\$$decimal = $saved_pc" "check \$pc after signal" 78 79# Check that we didn't lose the signal. 80gdb_test "info program" "stopped with signal SIGUSR1,.*" 81 82# Nor does the program. 83gdb_test "b handle" "Breakpoint .*" "set breakpoint in signal handler" 84gdb_test "continue" "handle.*" "continue to signal handler" 85