1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2013-2023 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 require allow_gdbserver_tests
27 if { [build_executable "failed to prepare" ${testfile}] } {
31 # Global control variable used by the proc prepare. Should be set to
32 # either 'inferior' or 'server'.
34 # In the proc prepare we start gdbserver and extract a pid, which will
35 # later be killed by calling the proc kill_server.
37 # When KILL_PID_OF is set to 'inferior' then the pid we kill is that
38 # of the inferior running under gdbserver, when this process dies
39 # gdbserver itself will exit.
41 # When KILL_PID_OF is set to 'server' then the pid we kill is that of
42 # the gdbserver itself, this is a much more aggressive strategy and
43 # exposes different bugs within GDB.
44 set kill_pid_of "inferior"
46 # Spawn GDBserver, run to main, extract GDBserver's PID and save it in
47 # the SERVER_PID global.
50 global binfile gdb_prompt srcfile decimal
54 save_vars { GDBFLAGS } {
55 # If GDB and GDBserver are both running locally, set the sysroot to avoid
56 # reading files via the remote protocol.
57 if { ![is_remote host] && ![is_remote target] } {
58 set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
61 clean_restart $binfile
64 # Make sure we're disconnected, in case we're testing with an
65 # extended-remote board, therefore already connected.
66 gdb_test "disconnect" ".*"
70 # Continue past server_pid assignment. We do this for both scenarios,
71 # to avoid doing a backtrace from _start, which may not trigger remote
73 gdb_breakpoint ${srcfile}:[gdb_get_line_number "i = 0;"]
74 gdb_continue_to_breakpoint "after server_pid assignment"
76 if { $::kill_pid_of == "inferior" } {
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.
118 "set remote trace-status-packet on" \
119 "Support for the 'qTStatus' packet on the current remote target is set to \"on\"."
121 # Force GDB to talk with GDBserver, so that we can get the
122 # "connection closed" error.
123 gdb_test "tstatus" {Remote connection closed|Remote communication error\. Target disconnected\.: Connection reset by peer\.}
126 # Test unwinding with no debug/unwind info, right after the connection
129 proc_with_prefix test_unwind_nosyms {} {
134 # Remove symbols, so that we try to unwind with one of the
135 # heuristic unwinders, and read memory from within its sniffer.
140 gdb_test "bt" "(Target disconnected|Remote connection closed|Remote communication error).*"
143 # Test unwinding with debug/unwind info, right after the connection is
146 proc_with_prefix test_unwind_syms {} {
153 gdb_test "bt" "(Target disconnected|Remote connection closed|Remote communication error).*"
156 # Test performing a stepi right after the connection is dropped.
158 proc_with_prefix test_stepi {} {
165 gdb_test "stepi" "(Target disconnected|Remote connection closed|Remote communication error).*"
168 # Run each test twice, see the description of KILL_PID_OF earlier in
169 # this file for more details.
171 foreach_with_prefix kill_pid_of { "inferior" "server" } {