]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.server/server-kill.exp
gdb: Make global feature array a per-remote target array
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.server / server-kill.exp
1 # This testcase is part of GDB, the GNU debugger.
2 #
3 # Copyright 2013-2023 Free Software Foundation, Inc.
4 #
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.
9 #
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.
14 #
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/>.
17
18 # Check that GDB handles GDBserver disconnecting abruptly, in several
19 # scenarios.
20
21 load_lib gdbserver-support.exp
22
23 standard_testfile
24
25 require allow_gdbserver_tests
26
27 if { [build_executable "failed to prepare" ${testfile}] } {
28 return -1
29 }
30
31 # Global control variable used by the proc prepare. Should be set to
32 # either 'inferior' or 'server'.
33 #
34 # In the proc prepare we start gdbserver and extract a pid, which will
35 # later be killed by calling the proc kill_server.
36 #
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.
40 #
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"
45
46 # Spawn GDBserver, run to main, extract GDBserver's PID and save it in
47 # the SERVER_PID global.
48
49 proc prepare {} {
50 global binfile gdb_prompt srcfile decimal
51 global server_pid
52 global GDBFLAGS
53
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\""
59 }
60
61 clean_restart $binfile
62 }
63
64 # Make sure we're disconnected, in case we're testing with an
65 # extended-remote board, therefore already connected.
66 gdb_test "disconnect" ".*"
67
68 gdbserver_run ""
69
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
72 # communication.
73 gdb_breakpoint ${srcfile}:[gdb_get_line_number "i = 0;"]
74 gdb_continue_to_breakpoint "after server_pid assignment"
75
76 if { $::kill_pid_of == "inferior" } {
77 # Get the pid of GDBServer.
78 set test "p server_pid"
79 set server_pid 0
80 gdb_test_multiple $test $test {
81 -re " = ($decimal)\r\n$gdb_prompt $" {
82 set server_pid $expect_out(1,string)
83 pass $test
84 }
85 }
86 } else {
87 set server_pid [exp_pid -i $::server_spawn_id]
88 }
89
90 if {$server_pid == 0} {
91 return 0
92 }
93
94 return 1
95 }
96
97 # Kill GDBserver using the PID saved by prepare.
98
99 proc kill_server {} {
100 global server_pid
101
102 remote_exec target "kill -9 $server_pid"
103 }
104
105 # Test issuing "tstatus" right after the connection is dropped.
106
107 proc_with_prefix test_tstatus {} {
108 if ![prepare] {
109 return
110 }
111
112 kill_server
113
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 \
118 "set remote trace-status-packet on" \
119 "Support for the 'qTStatus' packet on the current remote target is set to \"on\"."
120
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\.}
124 }
125
126 # Test unwinding with no debug/unwind info, right after the connection
127 # is dropped.
128
129 proc_with_prefix test_unwind_nosyms {} {
130 if ![prepare] {
131 return
132 }
133
134 # Remove symbols, so that we try to unwind with one of the
135 # heuristic unwinders, and read memory from within its sniffer.
136 gdb_unload
137
138 kill_server
139
140 gdb_test "bt" "(Target disconnected|Remote connection closed|Remote communication error).*"
141 }
142
143 # Test unwinding with debug/unwind info, right after the connection is
144 # dropped.
145
146 proc_with_prefix test_unwind_syms {} {
147 if ![prepare] {
148 return
149 }
150
151 kill_server
152
153 gdb_test "bt" "(Target disconnected|Remote connection closed|Remote communication error).*"
154 }
155
156 # Test performing a stepi right after the connection is dropped.
157
158 proc_with_prefix test_stepi {} {
159 if ![prepare] {
160 return
161 }
162
163 kill_server
164
165 gdb_test "stepi" "(Target disconnected|Remote connection closed|Remote communication error).*"
166 }
167
168 # Run each test twice, see the description of KILL_PID_OF earlier in
169 # this file for more details.
170
171 foreach_with_prefix kill_pid_of { "inferior" "server" } {
172 test_tstatus
173 test_unwind_nosyms
174 test_unwind_syms
175 test_stepi
176 }