xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.threads/reconnect-signal.exp (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1# Copyright 2013-2023 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]} {
37    return 0
38}
39
40gdb_test "continue" "signal SIGUSR1.*" "continue to signal"
41
42# Check that it's thread 2 that is selected.
43gdb_test "info threads" "\\* 2 .*" "thread 2 is selected"
44
45set msg "save \$pc after signal"
46set saved_pc ""
47gdb_test_multiple "print/x \$pc" $msg {
48    -re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" {
49	set saved_pc $expect_out(1,string)
50	pass $msg
51    }
52}
53
54# Switch to the other thread.
55gdb_test "thread 1" "thread 1.*" "switch to thread 1"
56
57# Force GDB to select thread 1 on the remote end as well.
58gdb_test "print/x \$pc"
59
60gdb_test "disconnect" "Ending remote debugging\\." "disconnect after signal"
61
62set test "reconnect after signal"
63
64set res [gdb_reconnect]
65if { [lindex $res 0] == 0 } {
66    pass $test
67} else {
68    fail $test
69    return 0
70}
71
72# Check that thread 2 is re-selected.
73gdb_test "info threads" "\\* 2 .*" "thread 2 is selected on reconnect"
74
75# Check that the program is still alive, and stopped in the same spot.
76gdb_test "print/x \$pc" "\\\$$decimal = $saved_pc" "check \$pc after signal"
77
78# Check that we didn't lose the signal.
79gdb_test "info program" "stopped with signal SIGUSR1,.*"
80
81# Nor does the program.
82gdb_test "b handle" "Breakpoint .*" "set breakpoint in signal handler"
83gdb_test "continue" "handle.*" "continue to signal handler"
84