Commit | Line | Data |
---|---|---|
598d3636 JK |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | # | |
88b9d363 | 3 | # Copyright 2013-2022 Free Software Foundation, Inc. |
598d3636 JK |
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 | ||
e7bc9db8 PA |
18 | # Check that GDB handles GDBserver disconnecting abruptly, in several |
19 | # scenarios. | |
20 | ||
598d3636 JK |
21 | load_lib gdbserver-support.exp |
22 | ||
23 | standard_testfile | |
24 | ||
25 | if {[skip_gdbserver_tests]} { | |
26 | return 0 | |
27 | } | |
28 | ||
e7bc9db8 | 29 | if { [build_executable "failed to prepare" ${testfile}] } { |
598d3636 JK |
30 | return -1 |
31 | } | |
32 | ||
80dc83fd AB |
33 | # Global control variable used by the proc prepare. Should be set to |
34 | # either 'inferior' or 'server'. | |
35 | # | |
36 | # In the proc prepare we start gdbserver and extract a pid, which will | |
37 | # later be killed by calling the proc kill_server. | |
38 | # | |
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. | |
42 | # | |
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" | |
47 | ||
e7bc9db8 PA |
48 | # Spawn GDBserver, run to main, extract GDBserver's PID and save it in |
49 | # the SERVER_PID global. | |
50 | ||
51 | proc prepare {} { | |
52 | global binfile gdb_prompt srcfile decimal | |
53 | global server_pid | |
8dc558a0 | 54 | global GDBFLAGS |
e7bc9db8 | 55 | |
8dc558a0 SM |
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\"" | |
61 | } | |
62 | ||
63 | clean_restart $binfile | |
64 | } | |
e7bc9db8 PA |
65 | |
66 | # Make sure we're disconnected, in case we're testing with an | |
67 | # extended-remote board, therefore already connected. | |
68 | gdb_test "disconnect" ".*" | |
598d3636 | 69 | |
e7bc9db8 | 70 | gdbserver_run "" |
598d3636 | 71 | |
80dc83fd AB |
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" | |
76 | ||
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 | } | |
e7bc9db8 | 85 | } |
80dc83fd AB |
86 | } else { |
87 | set server_pid [exp_pid -i $::server_spawn_id] | |
f90183d7 | 88 | } |
e7bc9db8 PA |
89 | |
90 | if {$server_pid == 0} { | |
91 | return 0 | |
92 | } | |
93 | ||
94 | return 1 | |
f90183d7 YQ |
95 | } |
96 | ||
e7bc9db8 PA |
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_no_output "set remote trace-status-packet on" | |
118 | ||
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\.} | |
122 | } | |
123 | ||
124 | # Test unwinding with no debug/unwind info, right after the connection | |
125 | # is dropped. | |
126 | ||
127 | proc_with_prefix test_unwind_nosyms {} { | |
128 | if ![prepare] { | |
129 | return | |
130 | } | |
131 | ||
132 | # Remove symbols, so that we try to unwind with one of the | |
133 | # heuristic unwinders, and read memory from within its sniffer. | |
134 | gdb_unload | |
135 | ||
136 | kill_server | |
137 | ||
138 | gdb_test "bt" "(Target disconnected|Remote connection closed|Remote communication error).*" | |
f90183d7 YQ |
139 | } |
140 | ||
e7bc9db8 PA |
141 | # Test unwinding with debug/unwind info, right after the connection is |
142 | # dropped. | |
598d3636 | 143 | |
e7bc9db8 PA |
144 | proc_with_prefix test_unwind_syms {} { |
145 | if ![prepare] { | |
146 | return | |
147 | } | |
148 | ||
149 | kill_server | |
150 | ||
151 | gdb_test "bt" "(Target disconnected|Remote connection closed|Remote communication error).*" | |
152 | } | |
754dd2b0 | 153 | |
80dc83fd AB |
154 | # Test performing a stepi right after the connection is dropped. |
155 | ||
156 | proc_with_prefix test_stepi {} { | |
157 | if ![prepare] { | |
158 | return | |
159 | } | |
160 | ||
161 | kill_server | |
162 | ||
163 | gdb_test "stepi" "(Target disconnected|Remote connection closed|Remote communication error).*" | |
164 | } | |
165 | ||
166 | # Run each test twice, see the description of KILL_PID_OF earlier in | |
167 | # this file for more details. | |
168 | ||
169 | foreach_with_prefix kill_pid_of { "inferior" "server" } { | |
170 | test_tstatus | |
171 | test_unwind_nosyms | |
172 | test_unwind_syms | |
173 | test_stepi | |
174 | } |