1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2013-2021 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Check that GDB handles GDBserver disconnecting abruptly, in several
21 load_lib gdbserver-support.exp
25 if {[skip_gdbserver_tests]} {
29 if { [build_executable "failed to prepare" ${testfile}] } {
33 # Global control variable used by the proc prepare. Should be set to
34 # either 'inferior' or 'server'.
36 # In the proc prepare we start gdbserver and extract a pid, which will
37 # later be killed by calling the proc kill_server.
39 # When KILL_PID_OF is set to 'inferior' then the pid we kill is that
40 # of the inferior running under gdbserver, when this process dies
41 # gdbserver itself will exit.
43 # When KILL_PID_OF is set to 'server' then the pid we kill is that of
44 # the gdbserver itself, this is a much more aggressive strategy and
45 # exposes different bugs within GDB.
46 set kill_pid_of "inferior"
48 # Spawn GDBserver, run to main, extract GDBserver's PID and save it in
49 # the SERVER_PID global.
52 global binfile gdb_prompt srcfile decimal
56 save_vars { GDBFLAGS } {
57 # If GDB and GDBserver are both running locally, set the sysroot to avoid
58 # reading files via the remote protocol.
59 if { ![is_remote host] && ![is_remote target] } {
60 set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
63 clean_restart $binfile
66 # Make sure we're disconnected, in case we're testing with an
67 # extended-remote board, therefore already connected.
68 gdb_test "disconnect" ".*"
72 if { $::kill_pid_of == "inferior" } {
73 # Continue past server_pid assignment.
74 gdb_breakpoint ${srcfile}:[gdb_get_line_number "i = 0;"]
75 gdb_continue_to_breakpoint "after server_pid assignment"
77 # Get the pid of GDBServer.
78 set test "p server_pid"
80 gdb_test_multiple $test $test {
81 -re " = ($decimal)\r\n$gdb_prompt $" {
82 set server_pid $expect_out(1,string)
87 set server_pid [exp_pid -i $::server_spawn_id]
90 if {$server_pid == 0} {
97 # Kill GDBserver using the PID saved by prepare.
102 remote_exec target "kill -9 $server_pid"
105 # Test issuing "tstatus" right after the connection is dropped.
107 proc_with_prefix test_tstatus {} {
114 # Enable trace status packet which is disabled after the
115 # connection if the remote target doesn't support tracepoint at
116 # all. Otherwise, no RSP packet is sent out.
117 gdb_test_no_output "set remote trace-status-packet on"
119 # Force GDB to talk with GDBserver, so that we can get the
120 # "connection closed" error.
121 gdb_test "tstatus" {Remote connection closed|Remote communication error\. Target disconnected\.: Connection reset by peer\.}
124 # Test unwinding with no debug/unwind info, right after the connection
127 proc_with_prefix test_unwind_nosyms {} {
132 # Remove symbols, so that we try to unwind with one of the
133 # heuristic unwinders, and read memory from within its sniffer.
138 gdb_test "bt" "(Target disconnected|Remote connection closed|Remote communication error).*"
141 # Test unwinding with debug/unwind info, right after the connection is
144 proc_with_prefix test_unwind_syms {} {
151 gdb_test "bt" "(Target disconnected|Remote connection closed|Remote communication error).*"
154 # Test performing a stepi right after the connection is dropped.
156 proc_with_prefix test_stepi {} {
163 gdb_test "stepi" "(Target disconnected|Remote connection closed|Remote communication error).*"
166 # Run each test twice, see the description of KILL_PID_OF earlier in
167 # this file for more details.
169 foreach_with_prefix kill_pid_of { "inferior" "server" } {