Commit | Line | Data |
---|---|---|
42a4f53d | 1 | # Copyright 2000-2019 Free Software Foundation, Inc. |
6f8eac0e DJ |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
6f8eac0e | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
6f8eac0e DJ |
8 | # This program is distributed in the hope that it will be useful, |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
e22f8b7c | 12 | # |
6f8eac0e | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
6f8eac0e DJ |
15 | |
16 | # This file is based on config/gdbserver.exp, which was written by | |
17 | # Michael Snyder (msnyder@redhat.com). | |
18 | ||
19 | # | |
20 | # To be addressed or set in your baseboard config file: | |
21 | # | |
22 | # set_board_info gdb_protocol "remote" | |
23 | # Unles you have a gdbserver that uses a different protocol... | |
e11ac3a3 JK |
24 | # After GDB starts you should check global $gdbserver_protocol instead as |
25 | # the testfile may force a specific different target protocol itself. | |
6f8eac0e DJ |
26 | # |
27 | # set_board_info gdb_server_prog | |
28 | # This will be the path to the gdbserver program you want to test. | |
29 | # Defaults to "gdbserver". | |
30 | # | |
31 | # set_board_info sockethost | |
32 | # The name of the host computer whose socket is being used. | |
33 | # Defaults to "localhost". Note: old gdbserver requires | |
34 | # that you define this, but libremote/gdbserver does not. | |
35 | # | |
36 | # set_board_info gdb,socketport | |
37 | # Port id to use for socket connection. If not set explicitly, | |
38 | # it will start at "2345" and increment for each use. | |
e11ac3a3 JK |
39 | # After GDB starts you should check global $gdbserver_gdbport for the |
40 | # real port used. It is not useful if $gdbserver_reconnect_p was not set. | |
6f8eac0e DJ |
41 | # |
42 | ||
43 | # | |
44 | # gdb_target_cmd | |
e5a1a79a AH |
45 | # Send gdb the "target" command. Returns 0 on success, 1 on failure. |
46 | # If specified, then ADDITIONAL_TEXT must match the text that comes after | |
47 | # the connection message in order for the procedure to succeed. | |
6f8eac0e | 48 | # |
e5a1a79a | 49 | proc gdb_target_cmd { targetname serialport {additional_text ""} } { |
6f8eac0e DJ |
50 | global gdb_prompt |
51 | ||
ef783a7d | 52 | set serialport_re [string_to_regexp $serialport] |
6f8eac0e DJ |
53 | for {set i 1} {$i <= 3} {incr i} { |
54 | send_gdb "target $targetname $serialport\n" | |
55 | gdb_expect 60 { | |
56 | -re "A program is being debugged already.*ill it.*y or n. $" { | |
57 | send_gdb "y\n" | |
58 | exp_continue | |
59 | } | |
401ea829 JB |
60 | -re "unknown host.*$gdb_prompt" { |
61 | verbose "Couldn't look up $serialport" | |
62 | } | |
2f83a18e | 63 | -re "Couldn't establish connection to remote.*$gdb_prompt $" { |
6f8eac0e DJ |
64 | verbose "Connection failed" |
65 | } | |
e5a1a79a | 66 | -re "Remote MIPS debugging.*$additional_text.*$gdb_prompt" { |
6f8eac0e DJ |
67 | verbose "Set target to $targetname" |
68 | return 0 | |
69 | } | |
e5a1a79a | 70 | -re "Remote debugging using .*$serialport_re.*$additional_text.*$gdb_prompt $" { |
6f8eac0e DJ |
71 | verbose "Set target to $targetname" |
72 | return 0 | |
73 | } | |
e5a1a79a | 74 | -re "Remote debugging using stdio.*$additional_text.*$gdb_prompt $" { |
e0f9f062 DE |
75 | verbose "Set target to $targetname" |
76 | return 0 | |
77 | } | |
e5a1a79a | 78 | -re "Remote target $targetname connected to.*$additional_text.*$gdb_prompt $" { |
6f8eac0e DJ |
79 | verbose "Set target to $targetname" |
80 | return 0 | |
81 | } | |
e5a1a79a | 82 | -re "Connected to.*$additional_text.*$gdb_prompt $" { |
6f8eac0e DJ |
83 | verbose "Set target to $targetname" |
84 | return 0 | |
85 | } | |
2f83a18e DJ |
86 | -re "Ending remote.*$gdb_prompt $" { } |
87 | -re "Connection refused.*$gdb_prompt $" { | |
6f8eac0e DJ |
88 | verbose "Connection refused by remote target. Pausing, and trying again." |
89 | sleep 30 | |
90 | continue | |
91 | } | |
2f83a18e | 92 | -re "Timeout reading from remote system.*$gdb_prompt $" { |
6f8eac0e DJ |
93 | verbose "Got timeout error from gdb." |
94 | } | |
b741e217 DJ |
95 | -notransfer -re "Remote debugging using .*\r\n> $" { |
96 | # We got an unexpected prompt while creating the target. | |
97 | # Leave it there for the test to diagnose. | |
98 | return 1 | |
99 | } | |
6f8eac0e DJ |
100 | timeout { |
101 | send_gdb "\ 3" | |
102 | break | |
103 | } | |
104 | } | |
105 | } | |
106 | return 1 | |
107 | } | |
108 | ||
109 | ||
110 | global portnum | |
111 | set portnum "2345" | |
112 | ||
113 | # Locate the gdbserver binary. Returns "" if gdbserver could not be found. | |
114 | ||
115 | proc find_gdbserver { } { | |
116 | global GDB | |
6fadd07a DE |
117 | global GDBSERVER |
118 | ||
119 | if [info exists GDBSERVER] { | |
120 | return ${GDBSERVER} | |
121 | } | |
6f8eac0e DJ |
122 | |
123 | if [target_info exists gdb_server_prog] { | |
124 | return [target_info gdb_server_prog] | |
125 | } | |
126 | ||
127 | set gdbserver "${GDB}server" | |
128 | if { [file isdirectory $gdbserver] } { | |
129 | append gdbserver "/gdbserver" | |
130 | } | |
131 | ||
132 | if { [file executable $gdbserver] } { | |
133 | return $gdbserver | |
134 | } | |
135 | ||
136 | return "" | |
137 | } | |
138 | ||
139 | # Return non-zero if we should skip gdbserver-specific tests. | |
140 | ||
141 | proc skip_gdbserver_tests { } { | |
142 | if { [find_gdbserver] == "" } { | |
143 | return 1 | |
144 | } | |
145 | ||
bae62ee2 YQ |
146 | # If GDB is lack of XML support, and targets, like arm, have |
147 | # multiple target descriptions, GDB doesn't know which target | |
148 | # description GDBserver uses, and may fail to parse 'g' packet | |
149 | # after connection. | |
150 | if { [gdb_skip_xml_test] | |
151 | && ([istarget "arm*-*-linux*"] | |
152 | || [istarget "mips*-*-linux*"] | |
153 | || [istarget "powerpc*-*-linux*"] | |
154 | || [istarget "s390*-*-linux*"] | |
155 | || [istarget "x86_64-*-linux*"] | |
156 | || [istarget "i\[34567\]86-*-linux*"]) } { | |
157 | return 1 | |
158 | } | |
159 | ||
6f8eac0e DJ |
160 | return 0 |
161 | } | |
162 | ||
2d717e4f DJ |
163 | # Download the currently loaded program to the target if necessary. |
164 | # Return the target system filename. | |
6496a609 DE |
165 | # NOTE: This was named "gdbserver_download", but that collides with the |
166 | # dejagnu "download" API function when using load_generic_config "gdbserver". | |
6f8eac0e | 167 | |
6496a609 | 168 | proc gdbserver_download_current_prog { } { |
b741e217 DJ |
169 | global gdbserver_host_exec |
170 | global gdbserver_host_mtime | |
171 | global gdbserver_server_exec | |
172 | global last_loaded_file | |
173 | ||
096be756 PA |
174 | if { ![info exists last_loaded_file] } { |
175 | return "" | |
176 | } | |
177 | ||
b741e217 DJ |
178 | set host_exec $last_loaded_file |
179 | ||
180 | # If we already downloaded a file to the target, see if we can reuse it. | |
181 | set reuse 0 | |
182 | if { [info exists gdbserver_server_exec] } { | |
183 | set reuse 1 | |
184 | ||
185 | # If the file has changed, we can not. | |
186 | if { $host_exec != $gdbserver_host_exec } { | |
187 | set reuse 0 | |
188 | } | |
189 | ||
190 | # If the mtime has changed, we can not. | |
191 | if { [file mtime $host_exec] != $gdbserver_host_mtime } { | |
192 | set reuse 0 | |
193 | } | |
194 | } | |
195 | ||
196 | if { $reuse == 0 } { | |
197 | set gdbserver_host_exec $host_exec | |
198 | set gdbserver_host_mtime [file mtime $host_exec] | |
7817ea46 | 199 | set gdbserver_server_exec [gdb_remote_download target $host_exec] |
b741e217 | 200 | } |
6f8eac0e | 201 | |
2d717e4f DJ |
202 | return $gdbserver_server_exec |
203 | } | |
204 | ||
e0f9f062 DE |
205 | # Default routine to compute the argument to "target remote". |
206 | ||
207 | proc gdbserver_default_get_remote_address { host port } { | |
ab19de87 DE |
208 | # Historically HOST included the trailing ":". |
209 | # To avoid breaking any board files out there we leave things alone. | |
e0f9f062 DE |
210 | return "$host$port" |
211 | } | |
212 | ||
ab19de87 DE |
213 | # Default routine to compute the "comm" argument for gdbserver. |
214 | ||
215 | proc gdbserver_default_get_comm_port { port } { | |
c7ab0aef | 216 | return "$port" |
ab19de87 DE |
217 | } |
218 | ||
2d717e4f DJ |
219 | # Start a gdbserver process with initial OPTIONS and trailing ARGUMENTS. |
220 | # The port will be filled in between them automatically. | |
221 | # | |
222 | # Returns the target protocol and socket to connect to. | |
223 | ||
224 | proc gdbserver_start { options arguments } { | |
225 | global portnum | |
c7ab0aef | 226 | global GDB_TEST_SOCKETHOST |
2d717e4f | 227 | |
6f8eac0e DJ |
228 | # Port id -- either specified in baseboard file, or managed here. |
229 | if [target_info exists gdb,socketport] { | |
230 | set portnum [target_info gdb,socketport] | |
231 | } else { | |
232 | # Bump the port number to avoid conflicts with hung ports. | |
233 | incr portnum | |
234 | } | |
235 | ||
236 | # Extract the local and remote host ids from the target board struct. | |
c7ab0aef SDJ |
237 | if { [info exists GDB_TEST_SOCKETHOST] } { |
238 | # The user is not supposed to provide a port number, just a | |
239 | # hostname/address, therefore we add the trailing ":" here. | |
240 | set debughost "${GDB_TEST_SOCKETHOST}:" | |
241 | # Escape open and close square brackets. | |
242 | set debughost_tmp [string map { [ \\[ ] \\] } $debughost] | |
243 | # We need a "gdbserver" version of the debughost, which will | |
244 | # have the possible connection prefix stripped. This is | |
245 | # because gdbserver currently doesn't recognize the prefixes. | |
246 | regsub -all "^\(tcp:|udp:|tcp4:|udp4:|tcp6:|udp6:\)" $debughost_tmp "" debughost_gdbserver | |
247 | } elseif [target_info exists sockethost] { | |
2d717e4f | 248 | set debughost [target_info sockethost] |
c7ab0aef | 249 | set debughost_gdbserver $debughost |
6f8eac0e DJ |
250 | } else { |
251 | set debughost "localhost:" | |
c7ab0aef | 252 | set debughost_gdbserver $debughost |
6f8eac0e DJ |
253 | } |
254 | ||
e0f9f062 DE |
255 | # Some boards use a different value for the port that is passed to |
256 | # gdbserver and the port that is passed to the "target remote" command. | |
257 | # One example is the stdio gdbserver support. | |
258 | if [target_info exists gdb,get_remote_address] { | |
259 | set get_remote_address [target_info gdb,get_remote_address] | |
260 | } else { | |
261 | set get_remote_address gdbserver_default_get_remote_address | |
262 | } | |
ab19de87 DE |
263 | if [target_info exists gdbserver,get_comm_port] { |
264 | set get_comm_port [target_info gdbserver,get_comm_port] | |
265 | } else { | |
266 | set get_comm_port gdbserver_default_get_comm_port | |
267 | } | |
e0f9f062 | 268 | |
6f8eac0e DJ |
269 | # Extract the protocol |
270 | if [target_info exists gdb_protocol] { | |
271 | set protocol [target_info gdb_protocol] | |
272 | } else { | |
273 | set protocol "remote" | |
274 | } | |
275 | ||
276 | set gdbserver [find_gdbserver] | |
277 | ||
047427a8 JK |
278 | # Loop till we find a free port. |
279 | while 1 { | |
047427a8 JK |
280 | # Fire off the debug agent. |
281 | set gdbserver_command "$gdbserver" | |
03f2bd59 JK |
282 | |
283 | # If gdbserver_reconnect will be called $gdbserver_reconnect_p must be | |
284 | # set to true already during gdbserver_start. | |
285 | global gdbserver_reconnect_p | |
dd06d4d6 AH |
286 | global srcdir |
287 | global subdir | |
03f2bd59 JK |
288 | if {![info exists gdbserver_reconnect_p] || !$gdbserver_reconnect_p} { |
289 | # GDB client could accidentally connect to a stale server. | |
290 | append gdbserver_command " --once" | |
291 | } | |
292 | ||
dd06d4d6 AH |
293 | # Enable debug if set. |
294 | if [gdbserver_debug_enabled] { | |
295 | global gdbserverdebug | |
b420b89e AH |
296 | set enabled 0 |
297 | foreach entry [split $gdbserverdebug ,] { | |
298 | switch -- $entry { | |
299 | "debug" { | |
300 | append gdbserver_command " --debug" | |
301 | set enabled 1 | |
302 | } | |
303 | "remote" { | |
304 | append gdbserver_command " --remote-debug" | |
305 | set enabled 1 | |
306 | } | |
307 | } | |
308 | } | |
309 | # Ensure debugfile is only added if something has been enabled | |
310 | if { $enabled } { | |
311 | set debugfile [standard_output_file gdbserver.debug] | |
312 | append gdbserver_command " --debug-file=$debugfile" | |
dd06d4d6 AH |
313 | } |
314 | } | |
315 | ||
047427a8 JK |
316 | if { $options != "" } { |
317 | append gdbserver_command " $options" | |
318 | } | |
c7ab0aef SDJ |
319 | if { $debughost_gdbserver != "" } { |
320 | append gdbserver_command " $debughost_gdbserver" | |
321 | } | |
e0f9f062 | 322 | if { $portnum != "" } { |
c7ab0aef SDJ |
323 | if { $debughost_gdbserver == "" } { |
324 | append gdbserver_command " " | |
325 | } | |
326 | append gdbserver_command "[$get_comm_port $portnum]" | |
e0f9f062 | 327 | } |
047427a8 JK |
328 | if { $arguments != "" } { |
329 | append gdbserver_command " $arguments" | |
330 | } | |
6f8eac0e | 331 | |
408e9b8b AH |
332 | gdbserver_write_cmd_file $gdbserver_command |
333 | ||
6423214f | 334 | global server_spawn_id |
047427a8 JK |
335 | set server_spawn_id [remote_spawn target $gdbserver_command] |
336 | ||
f71c18e7 PA |
337 | # GDBserver doesn't do inferior I/O through GDB. But we can |
338 | # talk to the program using GDBserver's tty instead. | |
339 | global inferior_spawn_id | |
340 | set inferior_spawn_id $server_spawn_id | |
341 | ||
047427a8 JK |
342 | # Wait for the server to open its TCP socket, so that GDB can connect. |
343 | expect { | |
344 | -i $server_spawn_id | |
2bdd10b7 | 345 | -timeout 120 |
047427a8 JK |
346 | -notransfer |
347 | -re "Listening on" { } | |
01abb042 | 348 | -re "Can't (bind address|listen on socket): Address already in use\\.\r\n" { |
047427a8 JK |
349 | verbose -log "Port $portnum is already in use." |
350 | if ![target_info exists gdb,socketport] { | |
351 | # Bump the port number to avoid the conflict. | |
352 | wait -i $expect_out(spawn_id) | |
353 | incr portnum | |
354 | continue | |
355 | } | |
356 | } | |
fb66cde8 | 357 | -re ".*: cannot resolve name: .*\r\n" { |
c7ab0aef SDJ |
358 | error "gdbserver cannot resolve name." |
359 | } | |
09635af7 MR |
360 | timeout { |
361 | error "Timeout waiting for gdbserver response." | |
362 | } | |
047427a8 JK |
363 | } |
364 | break | |
6f8eac0e DJ |
365 | } |
366 | ||
e0f9f062 | 367 | return [list $protocol [$get_remote_address $debughost $portnum]] |
6f8eac0e DJ |
368 | } |
369 | ||
2d717e4f DJ |
370 | # Start a gdbserver process running SERVER_EXEC, and connect GDB |
371 | # to it. CHILD_ARGS are passed to the inferior. | |
372 | # | |
373 | # Returns the target protocol and socket to connect to. | |
374 | ||
375 | proc gdbserver_spawn { child_args } { | |
6496a609 | 376 | set target_exec [gdbserver_download_current_prog] |
2d717e4f DJ |
377 | |
378 | # Fire off the debug agent. This flavour of gdbserver takes as | |
379 | # arguments the port information, the name of the executable file to | |
380 | # be debugged, and any arguments. | |
381 | set arguments "$target_exec" | |
382 | if { $child_args != "" } { | |
383 | append arguments " $child_args" | |
384 | } | |
385 | return [gdbserver_start "" $arguments] | |
386 | } | |
387 | ||
6423214f PA |
388 | # Close the GDBserver connection. |
389 | ||
390 | proc close_gdbserver {} { | |
038d4868 | 391 | global server_spawn_id |
6423214f PA |
392 | |
393 | # We can't just call close, because if gdbserver is local then that means | |
394 | # that it will get a SIGHUP. Doing it this way could also allow us to | |
395 | # get at the inferior's input or output if necessary, and means that we | |
396 | # don't need to redirect output. | |
397 | ||
398 | if {![info exists server_spawn_id]} { | |
399 | return | |
400 | } | |
401 | ||
402 | verbose "Quitting GDBserver" | |
403 | ||
404 | catch "close -i $server_spawn_id" | |
405 | catch "wait -i $server_spawn_id" | |
406 | unset server_spawn_id | |
407 | } | |
408 | ||
f73842fc YQ |
409 | # Hook into GDB exit, and close GDBserver. We must load this |
410 | # explicitly here, and rename the procedures we want to override. | |
411 | load_lib mi-support.exp | |
6423214f | 412 | |
9c211fd8 | 413 | if { [info procs gdbserver_orig_gdb_exit] == "" } { |
6423214f | 414 | rename gdb_exit gdbserver_orig_gdb_exit |
f73842fc | 415 | rename mi_gdb_exit gdbserver_orig_mi_gdb_exit |
6423214f | 416 | } |
f73842fc YQ |
417 | |
418 | proc gdbserver_gdb_exit { is_mi } { | |
038d4868 | 419 | global gdb_spawn_id server_spawn_id |
6423214f | 420 | global gdb_prompt |
1ca99c42 PA |
421 | global gdbserver_reconnect_p |
422 | ||
423 | # Leave GDBserver running if we're exiting GDB in order to | |
424 | # reconnect to the same instance of GDBserver again. | |
425 | if {[info exists gdbserver_reconnect_p] && $gdbserver_reconnect_p} { | |
f73842fc YQ |
426 | if { $is_mi } { |
427 | gdbserver_orig_mi_gdb_exit | |
428 | } else { | |
429 | gdbserver_orig_gdb_exit | |
430 | } | |
1ca99c42 PA |
431 | return |
432 | } | |
6423214f PA |
433 | |
434 | if {[info exists gdb_spawn_id] && [info exists server_spawn_id]} { | |
2efe15c4 YQ |
435 | # GDB may be terminated in an expected way or an unexpected way, |
436 | # but DejaGNU doesn't know that, so gdb_spawn_id isn't unset. | |
437 | # Catch the exceptions. | |
438 | catch { | |
f73842fc YQ |
439 | if { $is_mi } { |
440 | set monitor_exit "-interpreter-exec console \"monitor exit\"" | |
441 | } else { | |
442 | set monitor_exit "monitor exit" | |
443 | } | |
444 | send_gdb "$monitor_exit\n"; | |
2efe15c4 YQ |
445 | # We use expect rather than gdb_expect because |
446 | # we want to suppress printing exception messages, otherwise, | |
447 | # remote_expect, invoked by gdb_expect, prints the exceptions. | |
448 | expect { | |
449 | -i "$gdb_spawn_id" -re "$gdb_prompt $" { | |
450 | exp_continue | |
451 | } | |
452 | -i "$server_spawn_id" eof { | |
453 | wait -i $expect_out(spawn_id) | |
454 | unset server_spawn_id | |
2efe15c4 | 455 | } |
6423214f PA |
456 | } |
457 | } | |
458 | } | |
459 | close_gdbserver | |
460 | ||
f73842fc YQ |
461 | if { $is_mi } { |
462 | gdbserver_orig_mi_gdb_exit | |
463 | } else { | |
464 | gdbserver_orig_gdb_exit | |
465 | } | |
466 | } | |
467 | ||
468 | proc gdb_exit {} { | |
469 | gdbserver_gdb_exit 0 | |
470 | } | |
471 | ||
472 | proc mi_gdb_exit {} { | |
473 | gdbserver_gdb_exit 1 | |
6423214f PA |
474 | } |
475 | ||
6f8eac0e | 476 | # Start a gdbserver process running HOST_EXEC and pass CHILD_ARGS |
09635af7 MR |
477 | # to it. Return 0 on success, or non-zero on failure: 2 if gdbserver |
478 | # failed to start or 1 if we couldn't connect to it. | |
6f8eac0e | 479 | |
b741e217 | 480 | proc gdbserver_run { child_args } { |
b0f4b84b DJ |
481 | global gdbserver_protocol |
482 | global gdbserver_gdbport | |
483 | ||
2226f861 DJ |
484 | # Kill anything running before we try to start gdbserver, in case |
485 | # we are sharing a serial connection. | |
486 | global gdb_prompt | |
487 | send_gdb "kill\n" | |
488 | gdb_expect 120 { | |
489 | -re "Kill the program being debugged. .y or n. $" { | |
490 | send_gdb "y\n" | |
491 | verbose "\t\tKilling previous program being debugged" | |
492 | exp_continue | |
493 | } | |
494 | -re "$gdb_prompt $" { | |
495 | # OK. | |
496 | } | |
497 | } | |
498 | ||
09635af7 MR |
499 | if { [catch { gdbserver_spawn $child_args } res] == 1 } { |
500 | perror $res | |
501 | return 2 | |
502 | } | |
b0f4b84b DJ |
503 | set gdbserver_protocol [lindex $res 0] |
504 | set gdbserver_gdbport [lindex $res 1] | |
505 | ||
506 | return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] | |
507 | } | |
508 | ||
509 | # Reconnect to the previous gdbserver session. | |
510 | ||
511 | proc gdbserver_reconnect { } { | |
512 | global gdbserver_protocol | |
513 | global gdbserver_gdbport | |
6f8eac0e | 514 | |
4ec70201 | 515 | global gdbserver_reconnect_p |
03f2bd59 JK |
516 | if {![info exists gdbserver_reconnect_p] || !$gdbserver_reconnect_p} { |
517 | error "gdbserver_reconnect_p is not set before gdbserver_reconnect" | |
518 | return 0 | |
519 | } | |
520 | ||
b0f4b84b | 521 | return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] |
6f8eac0e | 522 | } |
2d717e4f | 523 | |
8cfe207c YQ |
524 | # Start gdbserver in extended mode with OPTIONS and connect to it. Note |
525 | # this frobs $gdbserver_protocol, so should be used only from a board | |
526 | # that usually connects in target remote mode. | |
527 | proc gdbserver_start_extended { {options ""} } { | |
e11ac3a3 JK |
528 | global gdbserver_protocol |
529 | global gdbserver_gdbport | |
530 | global use_gdb_stub | |
531 | ||
8cfe207c YQ |
532 | set gdbserver_options "--multi" |
533 | ||
534 | if { $options != "" } { | |
535 | append gdbserver_options " $options" | |
536 | } | |
537 | ||
538 | if { [catch { gdbserver_start $gdbserver_options "" } res] == 1 } { | |
09635af7 MR |
539 | perror $res |
540 | return 2 | |
541 | } | |
a1999d40 PA |
542 | set gdbserver_protocol [lindex $res 0] |
543 | if { [string first "extended-" $gdbserver_protocol] != 0} { | |
544 | set gdbserver_protocol "extended-$gdbserver_protocol" | |
545 | } | |
2d717e4f DJ |
546 | set gdbserver_gdbport [lindex $res 1] |
547 | ||
e11ac3a3 JK |
548 | # Even if the board file is testing with target remote, our caller |
549 | # wants to test against gdbserver in extended-remote mode. Make sure to | |
550 | # disable stub-like techniques. | |
551 | set use_gdb_stub 0 | |
552 | ||
2d717e4f DJ |
553 | return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] |
554 | } | |
048fe15a PA |
555 | |
556 | # Start and connect to a gdbserver in extended/multi mode. Unlike | |
557 | # gdbserver_start_extended, this does not frob $gdbserver_protocol. | |
558 | ||
559 | proc gdbserver_start_multi { } { | |
560 | global gdbserver_protocol | |
561 | global gdbserver_gdbport | |
562 | ||
09635af7 MR |
563 | if { [catch { gdbserver_start "--multi" "" } res] == 1 } { |
564 | perror $res | |
565 | return 2 | |
566 | } | |
048fe15a PA |
567 | set gdbserver_protocol [lindex $res 0] |
568 | set gdbserver_gdbport [lindex $res 1] | |
569 | ||
570 | return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] | |
571 | } | |
572 | ||
573 | # Start a gdbserver process in multi/extended mode, and have GDB | |
574 | # connect to it (MI version). Return 0 on success, or non-zero on | |
575 | # failure. | |
576 | ||
577 | proc mi_gdbserver_start_multi { } { | |
578 | global gdbserver_protocol | |
579 | global gdbserver_gdbport | |
580 | ||
09635af7 MR |
581 | if { [catch { gdbserver_start "--multi" "" } res] == 1 } { |
582 | perror $res | |
583 | return 2 | |
584 | } | |
048fe15a PA |
585 | set gdbserver_protocol [lindex $res 0] |
586 | set gdbserver_gdbport [lindex $res 1] | |
587 | ||
588 | return [mi_gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] | |
589 | } | |
dd06d4d6 AH |
590 | |
591 | # Check if debugging is enabled for gdbserver. | |
592 | ||
593 | proc gdbserver_debug_enabled { } { | |
594 | global gdbserverdebug | |
595 | ||
596 | # If not already read, get the debug setting from environment or board setting. | |
597 | if ![info exists gdbserverdebug] { | |
598 | global env | |
599 | if [info exists env(GDBSERVER_DEBUG)] { | |
600 | set gdbserverdebug $env(GDBSERVER_DEBUG) | |
601 | } elseif [target_info exists gdbserver,debug] { | |
602 | set gdbserverdebug [target_info gdbserver,debug] | |
603 | } else { | |
604 | return 0 | |
605 | } | |
606 | } | |
607 | ||
b420b89e AH |
608 | # Expand the all option |
609 | if { $gdbserverdebug == "all" } { | |
610 | set gdbserverdebug "debug,remote,replay" | |
611 | } | |
612 | ||
613 | # Ensure it is not empty. | |
614 | return [expr { $gdbserverdebug != "" }] | |
dd06d4d6 | 615 | } |
408e9b8b AH |
616 | |
617 | # Write the command line used to invocate gdbserver to the cmd file. | |
618 | ||
619 | proc gdbserver_write_cmd_file { cmdline } { | |
620 | set logfile [standard_output_file_with_gdb_instance gdbserver.cmd] | |
621 | set cmd_file [open $logfile w] | |
622 | puts $cmd_file $cmdline | |
623 | catch "close $cmd_file" | |
624 | } | |
b420b89e AH |
625 | |
626 | # Override gdb_debug_init so that we can set replay logging in GDB if required. | |
627 | # Backup the original function so we can call it afterwards | |
628 | ||
629 | rename gdb_debug_init _gdb_debug_init | |
630 | ||
631 | proc gdb_debug_init { } { | |
632 | global gdbserverdebug | |
633 | global gdb_prompt | |
634 | ||
635 | if [gdbserver_debug_enabled] { | |
636 | foreach entry [split $gdbserverdebug ,] { | |
637 | if { $entry == "replay" } { | |
638 | set replayfile [standard_output_file_with_gdb_instance gdbserver.replay] | |
639 | send_gdb "set remotelogfile $replayfile\n" optional | |
640 | gdb_expect 10 { | |
641 | -re "$gdb_prompt $" {} | |
642 | } | |
643 | } | |
644 | } | |
645 | } | |
646 | ||
647 | # Now call the standard debug init function | |
648 | _gdb_debug_init | |
649 | } |