1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2013-2024 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 # Spawn GDBserver, run to main, extract GDBserver's PID and save it in
32 # the SERVER_PID global.
35 global binfile gdb_prompt srcfile decimal
39 save_vars { GDBFLAGS } {
40 # If GDB and GDBserver are both running locally, set the sysroot to avoid
41 # reading files via the remote protocol.
42 if { ![is_remote host] && ![is_remote target] } {
43 set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\""
46 clean_restart $binfile
49 # Make sure we're disconnected, in case we're testing with an
50 # extended-remote board, therefore already connected.
51 gdb_test "disconnect" ".*"
55 gdb_breakpoint ${srcfile}:[gdb_get_line_number "i = 0;"]
56 gdb_continue_to_breakpoint "after server_pid assignment"
58 # Get the pid of GDBServer.
60 gdb_test_multiple "p server_pid" "" {
61 -re -wrap " = ($decimal)" {
62 set server_pid $expect_out(1,string)
67 if {$server_pid == 0} {
74 # Kill GDBserver using the PID saved by prepare.
79 remote_exec target "kill -9 $server_pid"
82 # Test issuing "tstatus" right after the connection is dropped.
84 proc_with_prefix test_tstatus {} {
91 # Enable trace status packet which is disabled after the
92 # connection if the remote target doesn't support tracepoint at
93 # all. Otherwise, no RSP packet is sent out.
95 "set remote trace-status-packet on" \
96 "Support for the 'qTStatus' packet on the current remote target is set to \"on\"."
98 # Force GDB to talk with GDBserver, so that we can get the
99 # "connection closed" error.
100 gdb_test "tstatus" {Remote connection closed|Remote communication error\. Target disconnected: Connection reset by peer\.}
103 # Test unwinding with no debug/unwind info, right after the connection
106 proc_with_prefix test_unwind_nosyms {} {
111 # Remove symbols, so that we try to unwind with one of the
112 # heuristic unwinders, and read memory from within its sniffer.
117 gdb_test "bt" "(Target disconnected|Remote connection closed|Remote communication error).*"
120 # Test unwinding with debug/unwind info, right after the connection is
123 proc_with_prefix test_unwind_syms {} {
130 gdb_test "bt" "(Target disconnected|Remote connection closed|Remote communication error).*"
133 # Test performing a stepi right after the connection is dropped.
135 proc_with_prefix test_stepi {} {
140 # Ensure GDB has computed the frame-id for the current frame
141 # before we kill the gdbserver. With the frame-id cached when we
142 # stepi below the first packets we try to send to gdbserver will
143 # be from within the breakpoint insertion process.
144 gdb_test "info frame" "Stack level 0, .*"
148 gdb_test "stepi" "(Target disconnected|Remote connection closed|Remote communication error).*"