old-cross-binutils/gdb/testsuite/lib/gdbserver-support.exp

515 lines
14 KiB
Text
Raw Permalink Normal View History

# Copyright 2000-2016 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file is based on config/gdbserver.exp, which was written by
# Michael Snyder (msnyder@redhat.com).
#
# To be addressed or set in your baseboard config file:
#
# set_board_info gdb_protocol "remote"
# Unles you have a gdbserver that uses a different protocol...
# After GDB starts you should check global $gdbserver_protocol instead as
# the testfile may force a specific different target protocol itself.
#
# set_board_info gdb_server_prog
# This will be the path to the gdbserver program you want to test.
# Defaults to "gdbserver".
#
# set_board_info sockethost
# The name of the host computer whose socket is being used.
# Defaults to "localhost". Note: old gdbserver requires
# that you define this, but libremote/gdbserver does not.
#
# set_board_info gdb,socketport
# Port id to use for socket connection. If not set explicitly,
# it will start at "2345" and increment for each use.
# After GDB starts you should check global $gdbserver_gdbport for the
# real port used. It is not useful if $gdbserver_reconnect_p was not set.
#
#
# gdb_target_cmd
# Send gdb the "target" command
#
proc gdb_target_cmd { targetname serialport } {
global gdb_prompt
set serialport_re [string_to_regexp $serialport]
for {set i 1} {$i <= 3} {incr i} {
send_gdb "target $targetname $serialport\n"
gdb_expect 60 {
-re "A program is being debugged already.*ill it.*y or n. $" {
send_gdb "y\n"
exp_continue
}
-re "unknown host.*$gdb_prompt" {
verbose "Couldn't look up $serialport"
}
-re "Couldn't establish connection to remote.*$gdb_prompt $" {
verbose "Connection failed"
}
-re "Remote MIPS debugging.*$gdb_prompt" {
verbose "Set target to $targetname"
return 0
}
-re "Remote debugging using .*$serialport_re.*$gdb_prompt $" {
verbose "Set target to $targetname"
return 0
}
-re "Remote debugging using stdio.*$gdb_prompt $" {
verbose "Set target to $targetname"
return 0
}
-re "Remote target $targetname connected to.*$gdb_prompt $" {
verbose "Set target to $targetname"
return 0
}
-re "Connected to.*$gdb_prompt $" {
verbose "Set target to $targetname"
return 0
}
-re "Ending remote.*$gdb_prompt $" { }
-re "Connection refused.*$gdb_prompt $" {
verbose "Connection refused by remote target. Pausing, and trying again."
sleep 30
continue
}
-re "Timeout reading from remote system.*$gdb_prompt $" {
verbose "Got timeout error from gdb."
}
-notransfer -re "Remote debugging using .*\r\n> $" {
# We got an unexpected prompt while creating the target.
# Leave it there for the test to diagnose.
return 1
}
timeout {
send_gdb ""
break
}
}
}
return 1
}
global portnum
set portnum "2345"
# Locate the gdbserver binary. Returns "" if gdbserver could not be found.
proc find_gdbserver { } {
global GDB
global GDBSERVER
if [info exists GDBSERVER] {
return ${GDBSERVER}
}
if [target_info exists gdb_server_prog] {
return [target_info gdb_server_prog]
}
set gdbserver "${GDB}server"
if { [file isdirectory $gdbserver] } {
append gdbserver "/gdbserver"
}
if { [file executable $gdbserver] } {
return $gdbserver
}
return ""
}
# Return non-zero if we should skip gdbserver-specific tests.
proc skip_gdbserver_tests { } {
if { [find_gdbserver] == "" } {
return 1
}
Skip gdb.server/ tests if lack of XML support I recently see some gdb.server/*.exp fails in my native gdb testing, in which libexpat isn't available, so GDB isn't able to parse xml file. It causes gdb.server/ tests fails because GDB can't get registers correctly from GDBserver. (gdb) PASS: gdb.server/connect-without-multi-process.exp: multiprocess=off: break main target remote localhost:2352^M Remote debugging using localhost:2352^M warning: Can not parse XML target description; XML support was disabled at compile time^M Reading /lib/ld-linux-armhf.so.3 from remote target...^M warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.^M Reading /lib/ld-linux-armhf.so.3 from remote target...^M Reading symbols from target:/lib/ld-linux-armhf.so.3...Reading /lib/ld-2.17.so.debug from remote target...^M Reading /lib/.debug/ld-2.17.so.debug from remote target...^M (no debugging symbols found)...done.^M Remote 'g' packet reply is too long: 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000efffbe00000000808d0f4d100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000^ 0x4d0f8d80 in _start () from target:/lib/ld-linux-armhf.so.3^M Without XML support in GDB, it can't parse xml sent by GDBserver, and has to fall back to the oldest arch. However, GDBserver doesn't know this (IMO, this is a defect in RSP), and still choose the right target description to create regcache and 'g' packet. If the port only has one target description or coincidentally two sides choose the same target description, there is no such issue. Otherwise, GDB is broken on read registers. This patch is to skip gdbserver tests if XML is not support and the target has multiple target descriptions. gdb/testsuite: 2016-07-21 Yao Qi <yao.qi@linaro.org> * lib/gdbserver-support.exp (skip_gdbserver_tests): Return 1 if gdb_skip_xml_test is true on some targets.
2016-07-21 08:22:29 +00:00
# If GDB is lack of XML support, and targets, like arm, have
# multiple target descriptions, GDB doesn't know which target
# description GDBserver uses, and may fail to parse 'g' packet
# after connection.
if { [gdb_skip_xml_test]
&& ([istarget "arm*-*-linux*"]
|| [istarget "mips*-*-linux*"]
|| [istarget "powerpc*-*-linux*"]
|| [istarget "s390*-*-linux*"]
|| [istarget "x86_64-*-linux*"]
|| [istarget "i\[34567\]86-*-linux*"]) } {
return 1
}
return 0
}
* linux-low.c (linux_attach_lwp): Do not _exit after errors. (linux_kill, linux_detach): Clean up the process list. * remote-utils.c (remote_open): Improve port number parsing. (putpkt_binary, input_interrupt): Only send interrupts if the target is running. * server.c (extended_protocol): Make static. (attached): Define earlier. (exit_requested, response_needed, program_argv): New variables. (target_running): New. (start_inferior): Clear attached here. (attach_inferior): Set attached here. (require_running): Define. (handle_query): Use require_running and target_running. Implement "monitor exit". (handle_v_attach, handle_v_run): New. (handle_v_requests): Use require_running. Handle vAttach and vRun. (gdbserver_usage): Update. (main): Redo argument parsing. Handle --debug and --multi. Handle --attach along with other options or after the port. Save program_argv. Support no initial program. Resynchronize communication with GDB after an error. Handle "monitor exit". Use require_running and target_running. Always allow the extended protocol. Do not error out for Hc0 or Hc-1. Do not automatically restart in extended mode. * README: Refer to the GDB manual. Update --attach usage. * remote.c (struct remote_state): Add cached_wait_status. (remote_exec_file): New variable. (PACKET_vAttach, PACKET_vRun): New constants. (extended_remote_restart): Do not query for status. (struct start_remote_args): New. (remote_start_remote): Take it as a second argument. Check whether the target is running. Issue an error for non-running non-extended targets. Cache the wait status. Set inferior_ptid here. (remote_open_1): Prompt to disconnect non-running targets. Make sure the target is marked running. Do not set inferior_ptid here. Update call to remote_start_remote. Do not call remote_check_symbols if the target is not running. (remote_detach_1): Rename from remote_detach. Take an EXTENDED argument. Handle a non-running target. (remote_detach): Use it. (extended_remote_detach): New. (remote_disconnect): Fix typo. Use remoute_mourn_1. (extended_remote_attach_1, extended_remote_attach) (extended_async_remote_attach): New. (remote_vcont_resume): Remove unused variable. (remote_wait, remote_async_wait): Use any cached wait status. (putpkt_binary, getpkt): Clear any cached wait status. (extended_remoute_mourn_1): New. (extended_remote_mourn): Use it. (extended_async_remote_mourn, extended_remote_run): New. (extended_remote_create_inferior_1): New. (extended_remote_create_inferior): Use it. (extended_remote_async_create_inferior): Likewise. (remote_xfer_partial): Skip for non-executing targets. (init_extended_remote_ops): Set to_detach and to_attach. (init_extended_async_remote_ops): Likewise. Use extended_async_remote_mourn. (_initialize_remote): Register vAttach, vRun, and set remote exec-file. * NEWS: Mention vAttach, vRun, and gdbserver extended-remote support. * gdb.server/ext-attach.c, gdb.server/ext-attach.exp, gdb.server/ext-run.exp: New files. * lib/gdbserver-support.exp (gdbserver_download): New. (gdbserver_start): New. Update gdbserver expected output. (gdbserver_spawn): Use them. (gdbserver_start_extended): New. * gdb.texinfo (Using the `gdbserver' Program): Add security warning. Rearrange into subsections and subsubsections. Document --multi and --debug. Correct --with-sysroot typo. Update --attach usage. Make load reference clearer. Document monitor exit. (Remote Configuration): Document set remote exec-file, attach-packet, and run-packet. (Packets): Document vAttach and vRun.
2008-01-30 00:51:50 +00:00
# Download the currently loaded program to the target if necessary.
# Return the target system filename.
# NOTE: This was named "gdbserver_download", but that collides with the
# dejagnu "download" API function when using load_generic_config "gdbserver".
proc gdbserver_download_current_prog { } {
global gdbserver_host_exec
global gdbserver_host_mtime
global gdbserver_server_exec
global last_loaded_file
Fix gdb.server/solib-list.exp regression Commit 7817ea46148d (Improve gdb_remote_download, remove gdb_download) caused: FAIL: gdb.server/solib-list.exp: non-stop 0: target extended-remote (timeout) FAIL: gdb.server/solib-list.exp: non-stop 0: continue (the program is no longer running) FAIL: gdb.server/solib-list.exp: non-stop 0: p libvar FAIL: gdb.server/solib-list.exp: non-stop 1: target extended-remote (timeout) FAIL: gdb.server/solib-list.exp: non-stop 1: continue (the program is no longer running) FAIL: gdb.server/solib-list.exp: non-stop 1: p libvar gdb.log shows: system interpreter is: /lib64/ld-linux-x86-64.so.2 ... spawn ../gdbserver/gdbserver --once :2347 /home/pedro/brno/pedro/gdb/mygit/build/gdb/testsuite/outputs/gdb.server/solib-list/ld-linux-x86-64.so.2 /home/pedro/brno/pedro/gdb/mygit/build/gdb/testsuite/outputs/gdb.server/solib-list/solib-list Process /home/pedro/brno/pedro/gdb/mygit/build/gdb/testsuite/outputs/gdb.server/solib-list/ld-linux-x86-64.so.2 created; pid = 18637 Cannot exec /home/pedro/brno/pedro/gdb/mygit/build/gdb/testsuite/outputs/gdb.server/solib-list/ld-linux-x86-64.so.2: No such file or directory. ... The test copied the interpreter to the outputs directory, however ld-linux-x86-64.so.2 is a relative symlink that when copied points nowhere: $ ls -l testsuite/outputs/gdb.server/solib-list/ total 52 -rwxrwxr-x. 1 pedro pedro 13450 Apr 7 10:52 gdb.log -rw-rw-r--. 1 pedro pedro 1512 Apr 7 10:52 gdb.sum lrwxrwxrwx. 1 pedro pedro 10 Apr 7 11:39 ld-linux-x86-64.so.2 -> ld-2.22.so -rwxrwxr-x. 1 pedro pedro 9464 Apr 7 11:39 solib-list -rw-rw-r--. 1 pedro pedro 3472 Apr 7 11:39 solib-list-lib.c.o -rw-rw-r--. 1 pedro pedro 2760 Apr 7 11:39 solib-list.o -rwxrwxr-x. 1 pedro pedro 9232 Apr 7 11:39 solib-list.so The copying comes from gdbserver_spawn -> gdbserver_download_current_prog -> gdb_remote_download. There's actually no need to download the interpreter to the target - it's part of the target system/environment. So fix this by making the test just not use gdb_load (and gdb_file_cmd as consequence) at all, and instead pass the interpreter filename to gdbserver as an argument. gdb/testsuite/ChangeLog: 2016-04-08 Pedro Alves <palves@redhat.com> * gdb.server/solib-list.exp: Don't use gdb_load. Instead pass the interpreter filename as argument to gdbserver_spawn. * lib/gdbserver-support.exp (gdbserver_download_current_prog): Return empty if $last_loaded_file does not exist.
2016-04-07 22:36:50 +00:00
if { ![info exists last_loaded_file] } {
return ""
}
set host_exec $last_loaded_file
# If we already downloaded a file to the target, see if we can reuse it.
set reuse 0
if { [info exists gdbserver_server_exec] } {
set reuse 1
# If the file has changed, we can not.
if { $host_exec != $gdbserver_host_exec } {
set reuse 0
}
# If the mtime has changed, we can not.
if { [file mtime $host_exec] != $gdbserver_host_mtime } {
set reuse 0
}
}
if { $reuse == 0 } {
set gdbserver_host_exec $host_exec
set gdbserver_host_mtime [file mtime $host_exec]
Improve gdb_remote_download, remove gdb_download This patch removes gdb_download in favor of gdb_remote_download, since they are very close in functionality. Also, in preparation for the following patch about shared library handling during tests, it improves gdb_remote_download so that it uses standard_output_file for any destination board that is local, not only host. If the destination board is remote, gdb_remote_download will use the standard remote_download from DejaGnu, resulting in the file being transferred on the remote system. If the destination is local, gdb_remote_download will copy the file to the standard test directory (found using standard_output_file). Tcl's file copy seems to handle gracefully cases where the source file is the same as the destination, so I don't think it's necessary to check for that case ourselves, as a previous version of the patch did. I'd prefer to keep the name gdb_download instead of gdb_remote_download, since I don't like the fact that gdb_remote_download implies that the destination is remote, when it's not always the case. However, gdb_remote_download is used at many more places than gdb_download, so it's easier to reuse that. Also, since it's a wrapper around DejaGnu's remote_download, it might be better to keep that name. I don't know. I ran the testsuite native, with native-gdbserver and with a remote gdbserver, and didn't see any related failure. gdb/testsuite/ChangeLog: * gdb.base/jit-so.exp: Use gdb_remote_download instead of gdb_download. Use it even if the target is not remote. * gdb.base/jit.exp (compile_jit_test): Likewise. * lib/gdb.exp (gdb_remote_download): Copy files to the standard output directory if the destination board is local, otherwise use the standard remote_download from DejaGnu. (gdb_download): Remove. (gdb_load_shlibs): Use gdb_remote_download instead of gdb_download. * lib/gdbserver-support.exp (gdbserver_download_current_prog): Use gdb_remote_download instead of gdb_download. Use it even if the target is not remote. * lib/mi-support.exp (mi_load_shlibs): Use gdb_remote_download instead of gdb_download.
2016-04-05 17:59:49 +00:00
set gdbserver_server_exec [gdb_remote_download target $host_exec]
}
* linux-low.c (linux_attach_lwp): Do not _exit after errors. (linux_kill, linux_detach): Clean up the process list. * remote-utils.c (remote_open): Improve port number parsing. (putpkt_binary, input_interrupt): Only send interrupts if the target is running. * server.c (extended_protocol): Make static. (attached): Define earlier. (exit_requested, response_needed, program_argv): New variables. (target_running): New. (start_inferior): Clear attached here. (attach_inferior): Set attached here. (require_running): Define. (handle_query): Use require_running and target_running. Implement "monitor exit". (handle_v_attach, handle_v_run): New. (handle_v_requests): Use require_running. Handle vAttach and vRun. (gdbserver_usage): Update. (main): Redo argument parsing. Handle --debug and --multi. Handle --attach along with other options or after the port. Save program_argv. Support no initial program. Resynchronize communication with GDB after an error. Handle "monitor exit". Use require_running and target_running. Always allow the extended protocol. Do not error out for Hc0 or Hc-1. Do not automatically restart in extended mode. * README: Refer to the GDB manual. Update --attach usage. * remote.c (struct remote_state): Add cached_wait_status. (remote_exec_file): New variable. (PACKET_vAttach, PACKET_vRun): New constants. (extended_remote_restart): Do not query for status. (struct start_remote_args): New. (remote_start_remote): Take it as a second argument. Check whether the target is running. Issue an error for non-running non-extended targets. Cache the wait status. Set inferior_ptid here. (remote_open_1): Prompt to disconnect non-running targets. Make sure the target is marked running. Do not set inferior_ptid here. Update call to remote_start_remote. Do not call remote_check_symbols if the target is not running. (remote_detach_1): Rename from remote_detach. Take an EXTENDED argument. Handle a non-running target. (remote_detach): Use it. (extended_remote_detach): New. (remote_disconnect): Fix typo. Use remoute_mourn_1. (extended_remote_attach_1, extended_remote_attach) (extended_async_remote_attach): New. (remote_vcont_resume): Remove unused variable. (remote_wait, remote_async_wait): Use any cached wait status. (putpkt_binary, getpkt): Clear any cached wait status. (extended_remoute_mourn_1): New. (extended_remote_mourn): Use it. (extended_async_remote_mourn, extended_remote_run): New. (extended_remote_create_inferior_1): New. (extended_remote_create_inferior): Use it. (extended_remote_async_create_inferior): Likewise. (remote_xfer_partial): Skip for non-executing targets. (init_extended_remote_ops): Set to_detach and to_attach. (init_extended_async_remote_ops): Likewise. Use extended_async_remote_mourn. (_initialize_remote): Register vAttach, vRun, and set remote exec-file. * NEWS: Mention vAttach, vRun, and gdbserver extended-remote support. * gdb.server/ext-attach.c, gdb.server/ext-attach.exp, gdb.server/ext-run.exp: New files. * lib/gdbserver-support.exp (gdbserver_download): New. (gdbserver_start): New. Update gdbserver expected output. (gdbserver_spawn): Use them. (gdbserver_start_extended): New. * gdb.texinfo (Using the `gdbserver' Program): Add security warning. Rearrange into subsections and subsubsections. Document --multi and --debug. Correct --with-sysroot typo. Update --attach usage. Make load reference clearer. Document monitor exit. (Remote Configuration): Document set remote exec-file, attach-packet, and run-packet. (Packets): Document vAttach and vRun.
2008-01-30 00:51:50 +00:00
return $gdbserver_server_exec
}
# Default routine to compute the argument to "target remote".
proc gdbserver_default_get_remote_address { host port } {
# Historically HOST included the trailing ":".
# To avoid breaking any board files out there we leave things alone.
return "$host$port"
}
# Default routine to compute the "comm" argument for gdbserver.
proc gdbserver_default_get_comm_port { port } {
return ":$port"
}
* linux-low.c (linux_attach_lwp): Do not _exit after errors. (linux_kill, linux_detach): Clean up the process list. * remote-utils.c (remote_open): Improve port number parsing. (putpkt_binary, input_interrupt): Only send interrupts if the target is running. * server.c (extended_protocol): Make static. (attached): Define earlier. (exit_requested, response_needed, program_argv): New variables. (target_running): New. (start_inferior): Clear attached here. (attach_inferior): Set attached here. (require_running): Define. (handle_query): Use require_running and target_running. Implement "monitor exit". (handle_v_attach, handle_v_run): New. (handle_v_requests): Use require_running. Handle vAttach and vRun. (gdbserver_usage): Update. (main): Redo argument parsing. Handle --debug and --multi. Handle --attach along with other options or after the port. Save program_argv. Support no initial program. Resynchronize communication with GDB after an error. Handle "monitor exit". Use require_running and target_running. Always allow the extended protocol. Do not error out for Hc0 or Hc-1. Do not automatically restart in extended mode. * README: Refer to the GDB manual. Update --attach usage. * remote.c (struct remote_state): Add cached_wait_status. (remote_exec_file): New variable. (PACKET_vAttach, PACKET_vRun): New constants. (extended_remote_restart): Do not query for status. (struct start_remote_args): New. (remote_start_remote): Take it as a second argument. Check whether the target is running. Issue an error for non-running non-extended targets. Cache the wait status. Set inferior_ptid here. (remote_open_1): Prompt to disconnect non-running targets. Make sure the target is marked running. Do not set inferior_ptid here. Update call to remote_start_remote. Do not call remote_check_symbols if the target is not running. (remote_detach_1): Rename from remote_detach. Take an EXTENDED argument. Handle a non-running target. (remote_detach): Use it. (extended_remote_detach): New. (remote_disconnect): Fix typo. Use remoute_mourn_1. (extended_remote_attach_1, extended_remote_attach) (extended_async_remote_attach): New. (remote_vcont_resume): Remove unused variable. (remote_wait, remote_async_wait): Use any cached wait status. (putpkt_binary, getpkt): Clear any cached wait status. (extended_remoute_mourn_1): New. (extended_remote_mourn): Use it. (extended_async_remote_mourn, extended_remote_run): New. (extended_remote_create_inferior_1): New. (extended_remote_create_inferior): Use it. (extended_remote_async_create_inferior): Likewise. (remote_xfer_partial): Skip for non-executing targets. (init_extended_remote_ops): Set to_detach and to_attach. (init_extended_async_remote_ops): Likewise. Use extended_async_remote_mourn. (_initialize_remote): Register vAttach, vRun, and set remote exec-file. * NEWS: Mention vAttach, vRun, and gdbserver extended-remote support. * gdb.server/ext-attach.c, gdb.server/ext-attach.exp, gdb.server/ext-run.exp: New files. * lib/gdbserver-support.exp (gdbserver_download): New. (gdbserver_start): New. Update gdbserver expected output. (gdbserver_spawn): Use them. (gdbserver_start_extended): New. * gdb.texinfo (Using the `gdbserver' Program): Add security warning. Rearrange into subsections and subsubsections. Document --multi and --debug. Correct --with-sysroot typo. Update --attach usage. Make load reference clearer. Document monitor exit. (Remote Configuration): Document set remote exec-file, attach-packet, and run-packet. (Packets): Document vAttach and vRun.
2008-01-30 00:51:50 +00:00
# Start a gdbserver process with initial OPTIONS and trailing ARGUMENTS.
# The port will be filled in between them automatically.
#
# Returns the target protocol and socket to connect to.
proc gdbserver_start { options arguments } {
global portnum
# Port id -- either specified in baseboard file, or managed here.
if [target_info exists gdb,socketport] {
set portnum [target_info gdb,socketport]
} else {
# Bump the port number to avoid conflicts with hung ports.
incr portnum
}
# Extract the local and remote host ids from the target board struct.
if [target_info exists sockethost] {
* linux-low.c (linux_attach_lwp): Do not _exit after errors. (linux_kill, linux_detach): Clean up the process list. * remote-utils.c (remote_open): Improve port number parsing. (putpkt_binary, input_interrupt): Only send interrupts if the target is running. * server.c (extended_protocol): Make static. (attached): Define earlier. (exit_requested, response_needed, program_argv): New variables. (target_running): New. (start_inferior): Clear attached here. (attach_inferior): Set attached here. (require_running): Define. (handle_query): Use require_running and target_running. Implement "monitor exit". (handle_v_attach, handle_v_run): New. (handle_v_requests): Use require_running. Handle vAttach and vRun. (gdbserver_usage): Update. (main): Redo argument parsing. Handle --debug and --multi. Handle --attach along with other options or after the port. Save program_argv. Support no initial program. Resynchronize communication with GDB after an error. Handle "monitor exit". Use require_running and target_running. Always allow the extended protocol. Do not error out for Hc0 or Hc-1. Do not automatically restart in extended mode. * README: Refer to the GDB manual. Update --attach usage. * remote.c (struct remote_state): Add cached_wait_status. (remote_exec_file): New variable. (PACKET_vAttach, PACKET_vRun): New constants. (extended_remote_restart): Do not query for status. (struct start_remote_args): New. (remote_start_remote): Take it as a second argument. Check whether the target is running. Issue an error for non-running non-extended targets. Cache the wait status. Set inferior_ptid here. (remote_open_1): Prompt to disconnect non-running targets. Make sure the target is marked running. Do not set inferior_ptid here. Update call to remote_start_remote. Do not call remote_check_symbols if the target is not running. (remote_detach_1): Rename from remote_detach. Take an EXTENDED argument. Handle a non-running target. (remote_detach): Use it. (extended_remote_detach): New. (remote_disconnect): Fix typo. Use remoute_mourn_1. (extended_remote_attach_1, extended_remote_attach) (extended_async_remote_attach): New. (remote_vcont_resume): Remove unused variable. (remote_wait, remote_async_wait): Use any cached wait status. (putpkt_binary, getpkt): Clear any cached wait status. (extended_remoute_mourn_1): New. (extended_remote_mourn): Use it. (extended_async_remote_mourn, extended_remote_run): New. (extended_remote_create_inferior_1): New. (extended_remote_create_inferior): Use it. (extended_remote_async_create_inferior): Likewise. (remote_xfer_partial): Skip for non-executing targets. (init_extended_remote_ops): Set to_detach and to_attach. (init_extended_async_remote_ops): Likewise. Use extended_async_remote_mourn. (_initialize_remote): Register vAttach, vRun, and set remote exec-file. * NEWS: Mention vAttach, vRun, and gdbserver extended-remote support. * gdb.server/ext-attach.c, gdb.server/ext-attach.exp, gdb.server/ext-run.exp: New files. * lib/gdbserver-support.exp (gdbserver_download): New. (gdbserver_start): New. Update gdbserver expected output. (gdbserver_spawn): Use them. (gdbserver_start_extended): New. * gdb.texinfo (Using the `gdbserver' Program): Add security warning. Rearrange into subsections and subsubsections. Document --multi and --debug. Correct --with-sysroot typo. Update --attach usage. Make load reference clearer. Document monitor exit. (Remote Configuration): Document set remote exec-file, attach-packet, and run-packet. (Packets): Document vAttach and vRun.
2008-01-30 00:51:50 +00:00
set debughost [target_info sockethost]
} else {
set debughost "localhost:"
}
# Some boards use a different value for the port that is passed to
# gdbserver and the port that is passed to the "target remote" command.
# One example is the stdio gdbserver support.
if [target_info exists gdb,get_remote_address] {
set get_remote_address [target_info gdb,get_remote_address]
} else {
set get_remote_address gdbserver_default_get_remote_address
}
if [target_info exists gdbserver,get_comm_port] {
set get_comm_port [target_info gdbserver,get_comm_port]
} else {
set get_comm_port gdbserver_default_get_comm_port
}
# Extract the protocol
if [target_info exists gdb_protocol] {
set protocol [target_info gdb_protocol]
} else {
set protocol "remote"
}
set gdbserver [find_gdbserver]
# Loop till we find a free port.
while 1 {
# Fire off the debug agent.
set gdbserver_command "$gdbserver"
# If gdbserver_reconnect will be called $gdbserver_reconnect_p must be
# set to true already during gdbserver_start.
global gdbserver_reconnect_p
if {![info exists gdbserver_reconnect_p] || !$gdbserver_reconnect_p} {
# GDB client could accidentally connect to a stale server.
* NEWS: Mention tracepoint additions. * breakpoint.h (struct tracepoint): New field traceframe_usage. * breakpoint.c (print_one_breakpoint_location): Identify tracepoints as such when reporting hit counts, report trace buffer usage. (create_tracepoint_from_upload): Copy status info. * tracepoint.h (struct trace_status): Rename error_desc to stop_desc, add fields user_name, notes, start_time, stop_time. (struct uploaded_tp): Add fields hit_count, traceframe_usage. * tracepoint.c (trace_user): New global. (trace_notes): New global. (trace_stop_notes): New global. (start_tracing): Add argument and trace note handling. (stop_tracing): Ditto. (trace_start_command): Add notes argument. (trace_stop_command): Ditto. (trace_status_command): Report additional status info. (trace_status_mi): Similarly. (trace_save): Update, record tracepoint status. (set_disconnected_tracing): Call target method directly. (send_disconnected_tracing_value): Remove. (set_trace_user): New function. (set_trace_notes): New function. (set_trace_stop_notes): New function. (parse_trace_status): Handle additional status. (parse_tracepoint_status): New function. (parse_tracepoint_definition): Call it. (tfile_get_tracepoint_status): New function. (init_tfile_ops): Use it. (_initialize_tracepoint): Add new setshows. * target.h (struct target_ops): New methods to_get_tracepoint_status and to_set_trace_notes. (target_get_tracepoint_status): New macro. (target_set_trace_notes): New macro. * target.c (update_current_target): Add new methods. * remote.c (remote_get_tracepoint_status): New function. (remote_set_trace_notes): New function. (init_remote_ops): Add them. * mi/mi-main.c (mi_cmd_trace_start): Add argument to call. (mi_cmd_trace_stop): Ditto. * tracepoint.c (struct tracepoint): New field traceframe_usage. (tracing_start_time): New global. (tracing_stop_time): New global. (tracing_user_name): New global. (tracing_notes): New global. (tracing_stop_note): New global. (cmd_qtstart): Set traceframe_usage, start_time. (stop_tracing): Set stop_time. (cmd_qtstatus): Report additional status. (cmd_qtp): New function. (handle_tracepoint_query): Call it. (cmd_qtnotes): New function. (handle_tracepoint_general_set): Call it. (get_timestamp): Rename from tsv_get_timestamp. * gdb.texinfo (Starting and Stopping Trace Experiments): Document note-related options and variables. (Tracepoint Packets): Document packet changes. * gdb.trace/tstatus.exp: New. * gdb.trace/actions.c: Include string.h.
2011-11-20 23:59:49 +00:00
# append gdbserver_command " --debug --once"
append gdbserver_command " --once"
}
if { $options != "" } {
append gdbserver_command " $options"
}
if { $portnum != "" } {
append gdbserver_command " [$get_comm_port $portnum]"
}
if { $arguments != "" } {
append gdbserver_command " $arguments"
}
global server_spawn_id
set server_spawn_id [remote_spawn target $gdbserver_command]
testsuite: Introduce $inferior_spawn_id Some important tests, like gdb.base/interrupt.exp end up skipped against gdbserver, because they depend on inferior I/O, which gdbserver doesn't do. This patch adds a mechanism that makes it possible to make them work. It adds a new "inferior_spawn_id" global that is the spawn ID used for I/O interaction with the inferior. By default, for native targets, or remote targets that can do I/O through GDB (semi-hosting) this will be the same as the gdb/host spawn ID. Otherwise, the board may set this to some other spawn ID. When debugging with GDBserver, this will be set to GDBserver's spawn ID. Then tests can use send_inferior instead of send_gdb to send input to the inferior, and use expect's "-i" switch to select which spawn ID to use for matching input/output. That is, something like this will now work: send_inferior "echo me\n" gdb_test_multiple "continue" "test msg" { -i "$inferior_spawn_id" -re "echo me\r\necho\r\n" { ... } } Or even: gdb_test_multiple "continue" "test msg" { -i "$inferior_spawn_id" -re "hello world" { ... } -i "$gdb_spawn_id" -re "error.*$gdb_prompt $" { ... } } Of course, by default, gdb_test_multiple still matches with $gdb_spawn_id. gdb/testsuite/ChangeLog: 2015-04-07 Pedro Alves <palves@redhat.com> * lib/gdb.exp (inferior_spawn_id): New global. (gdb_test_multiple): Handle "-i". Reset the spawn id to GDB's spawn id after processing the user code. (default_gdb_start): Set inferior_spawn_id. (send_inferior): New procedure. * lib/gdbserver-support.exp (gdbserver_start): Set inferior_spawn_id. (close_gdbserver, gdb_exit): Unset inferior_spawn_id.
2015-04-07 17:19:30 +00:00
# GDBserver doesn't do inferior I/O through GDB. But we can
# talk to the program using GDBserver's tty instead.
global inferior_spawn_id
set inferior_spawn_id $server_spawn_id
# Wait for the server to open its TCP socket, so that GDB can connect.
expect {
-i $server_spawn_id
GDB/testsuite: Extend the time gdbserver is waited for Gdbserver support code uses the global timeout value to determine when to stop waiting for a gdbserver process being started to respond before continuing anyway. This timeout is usually as low as 10s and may not be enough in this context, for example on the first run where the filesystem cache is cold, even if it is elsewhere. E.g. I observe this reliably with gdbserver started the first time in QEMU running in the system emulation mode: (gdb) file .../gdb.base/advance Reading symbols from .../gdb.base/advance...done. (gdb) delete breakpoints (gdb) info breakpoints No breakpoints or watchpoints. (gdb) break main Breakpoint 1 at 0x87f8: file .../gdb.base/advance.c, line 41. (gdb) set remotetimeout 15 (gdb) kill The program is not being run. (gdb) [...] .../bin/gdbserver --once :6014 advance target remote localhost:6014 Remote debugging using localhost:6014 Remote communication error. Target disconnected.: Connection reset by peer. (gdb) continue The program is not being run. (gdb) Process advance created; pid = 999 Listening on port 6014 FAIL: gdb.base/advance.exp: Can't run to main -- notice how the test harness proceeded with the `target remote ...' command even though gdbserver hasn't completed its startup yet. A while later when it's finally ready it's too late already. I checked the timing here and it takes gdbserver roughly 25 seconds to start in this scenario. Subsequent gdbserver starts in the same test run take less time and usually complete within 10 seconds although occasionally `target remote ...' precedes the corresponding `Listening on port...' message again. Therefore I have fixed this problem by setting an explicit timeout to 120s on the expect call in question. If this turns out too arbitrary sometime, then perhaps a separate `gdbserver_timeout' setting might be due. * lib/gdbserver-support.exp (gdbserver_start): Set timeout to 120 on waiting for the TCP socket to open.
2014-09-09 15:06:15 +00:00
-timeout 120
-notransfer
-re "Listening on" { }
-re "Can't bind address: Address already in use\\.\r\n" {
verbose -log "Port $portnum is already in use."
if ![target_info exists gdb,socketport] {
# Bump the port number to avoid the conflict.
wait -i $expect_out(spawn_id)
incr portnum
continue
}
}
gdbserver-support: Handle gdbserver start failures As it happens we have a board that fails a gdb.base/gcore-relro.exp test case reproducibly and moreover the case appears to trigger a kernel bug making the it less than usable. Specifically the board remains responsive to some extent, however processes do not appear to be able to successfully complete termination anymore and perhaps more importantly further gdbserver processes can be started, but they never reach the stage of listening on the RSP socket. This change handles timeouts in gdbserver start properly, by throwing a TCL error exception when gdbserver does not report listening on the RSP socket in time. This is then caught at the outer level and reported, and 2 rather than 1 is returned so that the caller may tell the failure to start gdbserver and other issues apart and act accordingly (or do nothing). I thought letting the exception unwind further on might be a good idea for any test harnesses out there to break outright where a gdbserver start error is silently ignored right now, however I figured out the calls to gdbserver-support.exp are buried down too deep in the GDB test suite for such a change to be made easily. I think returning a distinct return value is good enough (the API says "non-zero", so 2 is as good as 1) and we can always make the error harder in a later step if required. With config/gdbserver.exp being used this change remains transparent to the target board, the return value is passed up by gdb_reload and the error exception unwinds through gdbserver_gdb_load and is caught and handled by mi_gdb_target_load. A call to perror is still made, reporting the timeout, and in the case of mi_gdb_target_load the procedure returns a value denoting unsuccessful completion. An unsuccessful completion of gdb_reload is already handled elsewhere. An alternative gdbserver board configuration can interpret the return value in its gdb_reload implementation and catch the error in gdbserver_gdb_load in an attempt to recover a target board that has gone astray, for example by rebooting the board somehow. This has proved effective with our failing board, that now completes the remaining test cases with no further hiccups. * lib/gdbserver-support.exp (gdbserver_start): Throw an error exception on timeout. (gdbserver_run): Catch any `gdbserver_spawn' error exceptions. (gdbserver_start_extended): Catch any `gdbserver_start' error exceptions. (gdbserver_start_multi, mi_gdbserver_start_multi): Likewise. * lib/mi-support.exp (mi_gdb_target_load): Catch any `gdbserver_gdb_load' error exceptions.
2014-09-09 15:17:38 +00:00
timeout {
error "Timeout waiting for gdbserver response."
}
}
break
}
return [list $protocol [$get_remote_address $debughost $portnum]]
}
* linux-low.c (linux_attach_lwp): Do not _exit after errors. (linux_kill, linux_detach): Clean up the process list. * remote-utils.c (remote_open): Improve port number parsing. (putpkt_binary, input_interrupt): Only send interrupts if the target is running. * server.c (extended_protocol): Make static. (attached): Define earlier. (exit_requested, response_needed, program_argv): New variables. (target_running): New. (start_inferior): Clear attached here. (attach_inferior): Set attached here. (require_running): Define. (handle_query): Use require_running and target_running. Implement "monitor exit". (handle_v_attach, handle_v_run): New. (handle_v_requests): Use require_running. Handle vAttach and vRun. (gdbserver_usage): Update. (main): Redo argument parsing. Handle --debug and --multi. Handle --attach along with other options or after the port. Save program_argv. Support no initial program. Resynchronize communication with GDB after an error. Handle "monitor exit". Use require_running and target_running. Always allow the extended protocol. Do not error out for Hc0 or Hc-1. Do not automatically restart in extended mode. * README: Refer to the GDB manual. Update --attach usage. * remote.c (struct remote_state): Add cached_wait_status. (remote_exec_file): New variable. (PACKET_vAttach, PACKET_vRun): New constants. (extended_remote_restart): Do not query for status. (struct start_remote_args): New. (remote_start_remote): Take it as a second argument. Check whether the target is running. Issue an error for non-running non-extended targets. Cache the wait status. Set inferior_ptid here. (remote_open_1): Prompt to disconnect non-running targets. Make sure the target is marked running. Do not set inferior_ptid here. Update call to remote_start_remote. Do not call remote_check_symbols if the target is not running. (remote_detach_1): Rename from remote_detach. Take an EXTENDED argument. Handle a non-running target. (remote_detach): Use it. (extended_remote_detach): New. (remote_disconnect): Fix typo. Use remoute_mourn_1. (extended_remote_attach_1, extended_remote_attach) (extended_async_remote_attach): New. (remote_vcont_resume): Remove unused variable. (remote_wait, remote_async_wait): Use any cached wait status. (putpkt_binary, getpkt): Clear any cached wait status. (extended_remoute_mourn_1): New. (extended_remote_mourn): Use it. (extended_async_remote_mourn, extended_remote_run): New. (extended_remote_create_inferior_1): New. (extended_remote_create_inferior): Use it. (extended_remote_async_create_inferior): Likewise. (remote_xfer_partial): Skip for non-executing targets. (init_extended_remote_ops): Set to_detach and to_attach. (init_extended_async_remote_ops): Likewise. Use extended_async_remote_mourn. (_initialize_remote): Register vAttach, vRun, and set remote exec-file. * NEWS: Mention vAttach, vRun, and gdbserver extended-remote support. * gdb.server/ext-attach.c, gdb.server/ext-attach.exp, gdb.server/ext-run.exp: New files. * lib/gdbserver-support.exp (gdbserver_download): New. (gdbserver_start): New. Update gdbserver expected output. (gdbserver_spawn): Use them. (gdbserver_start_extended): New. * gdb.texinfo (Using the `gdbserver' Program): Add security warning. Rearrange into subsections and subsubsections. Document --multi and --debug. Correct --with-sysroot typo. Update --attach usage. Make load reference clearer. Document monitor exit. (Remote Configuration): Document set remote exec-file, attach-packet, and run-packet. (Packets): Document vAttach and vRun.
2008-01-30 00:51:50 +00:00
# Start a gdbserver process running SERVER_EXEC, and connect GDB
# to it. CHILD_ARGS are passed to the inferior.
#
# Returns the target protocol and socket to connect to.
proc gdbserver_spawn { child_args } {
set target_exec [gdbserver_download_current_prog]
* linux-low.c (linux_attach_lwp): Do not _exit after errors. (linux_kill, linux_detach): Clean up the process list. * remote-utils.c (remote_open): Improve port number parsing. (putpkt_binary, input_interrupt): Only send interrupts if the target is running. * server.c (extended_protocol): Make static. (attached): Define earlier. (exit_requested, response_needed, program_argv): New variables. (target_running): New. (start_inferior): Clear attached here. (attach_inferior): Set attached here. (require_running): Define. (handle_query): Use require_running and target_running. Implement "monitor exit". (handle_v_attach, handle_v_run): New. (handle_v_requests): Use require_running. Handle vAttach and vRun. (gdbserver_usage): Update. (main): Redo argument parsing. Handle --debug and --multi. Handle --attach along with other options or after the port. Save program_argv. Support no initial program. Resynchronize communication with GDB after an error. Handle "monitor exit". Use require_running and target_running. Always allow the extended protocol. Do not error out for Hc0 or Hc-1. Do not automatically restart in extended mode. * README: Refer to the GDB manual. Update --attach usage. * remote.c (struct remote_state): Add cached_wait_status. (remote_exec_file): New variable. (PACKET_vAttach, PACKET_vRun): New constants. (extended_remote_restart): Do not query for status. (struct start_remote_args): New. (remote_start_remote): Take it as a second argument. Check whether the target is running. Issue an error for non-running non-extended targets. Cache the wait status. Set inferior_ptid here. (remote_open_1): Prompt to disconnect non-running targets. Make sure the target is marked running. Do not set inferior_ptid here. Update call to remote_start_remote. Do not call remote_check_symbols if the target is not running. (remote_detach_1): Rename from remote_detach. Take an EXTENDED argument. Handle a non-running target. (remote_detach): Use it. (extended_remote_detach): New. (remote_disconnect): Fix typo. Use remoute_mourn_1. (extended_remote_attach_1, extended_remote_attach) (extended_async_remote_attach): New. (remote_vcont_resume): Remove unused variable. (remote_wait, remote_async_wait): Use any cached wait status. (putpkt_binary, getpkt): Clear any cached wait status. (extended_remoute_mourn_1): New. (extended_remote_mourn): Use it. (extended_async_remote_mourn, extended_remote_run): New. (extended_remote_create_inferior_1): New. (extended_remote_create_inferior): Use it. (extended_remote_async_create_inferior): Likewise. (remote_xfer_partial): Skip for non-executing targets. (init_extended_remote_ops): Set to_detach and to_attach. (init_extended_async_remote_ops): Likewise. Use extended_async_remote_mourn. (_initialize_remote): Register vAttach, vRun, and set remote exec-file. * NEWS: Mention vAttach, vRun, and gdbserver extended-remote support. * gdb.server/ext-attach.c, gdb.server/ext-attach.exp, gdb.server/ext-run.exp: New files. * lib/gdbserver-support.exp (gdbserver_download): New. (gdbserver_start): New. Update gdbserver expected output. (gdbserver_spawn): Use them. (gdbserver_start_extended): New. * gdb.texinfo (Using the `gdbserver' Program): Add security warning. Rearrange into subsections and subsubsections. Document --multi and --debug. Correct --with-sysroot typo. Update --attach usage. Make load reference clearer. Document monitor exit. (Remote Configuration): Document set remote exec-file, attach-packet, and run-packet. (Packets): Document vAttach and vRun.
2008-01-30 00:51:50 +00:00
# Fire off the debug agent. This flavour of gdbserver takes as
# arguments the port information, the name of the executable file to
# be debugged, and any arguments.
set arguments "$target_exec"
if { $child_args != "" } {
append arguments " $child_args"
}
return [gdbserver_start "" $arguments]
}
# Close the GDBserver connection.
proc close_gdbserver {} {
global server_spawn_id
# We can't just call close, because if gdbserver is local then that means
# that it will get a SIGHUP. Doing it this way could also allow us to
# get at the inferior's input or output if necessary, and means that we
# don't need to redirect output.
if {![info exists server_spawn_id]} {
return
}
verbose "Quitting GDBserver"
catch "close -i $server_spawn_id"
catch "wait -i $server_spawn_id"
unset server_spawn_id
}
# Hook into GDB exit, and close GDBserver.
if { [info procs gdbserver_gdb_exit] == "" } {
rename gdb_exit gdbserver_orig_gdb_exit
}
proc gdb_exit {} {
global gdb_spawn_id server_spawn_id
global gdb_prompt
global gdbserver_reconnect_p
# Leave GDBserver running if we're exiting GDB in order to
# reconnect to the same instance of GDBserver again.
if {[info exists gdbserver_reconnect_p] && $gdbserver_reconnect_p} {
gdbserver_orig_gdb_exit
return
}
if {[info exists gdb_spawn_id] && [info exists server_spawn_id]} {
# GDB may be terminated in an expected way or an unexpected way,
# but DejaGNU doesn't know that, so gdb_spawn_id isn't unset.
# Catch the exceptions.
catch {
send_gdb "monitor exit\n";
# We use expect rather than gdb_expect because
# we want to suppress printing exception messages, otherwise,
# remote_expect, invoked by gdb_expect, prints the exceptions.
expect {
-i "$gdb_spawn_id" -re "$gdb_prompt $" {
exp_continue
}
-i "$server_spawn_id" eof {
wait -i $expect_out(spawn_id)
unset server_spawn_id
}
}
}
}
close_gdbserver
gdbserver_orig_gdb_exit
}
# Start a gdbserver process running HOST_EXEC and pass CHILD_ARGS
gdbserver-support: Handle gdbserver start failures As it happens we have a board that fails a gdb.base/gcore-relro.exp test case reproducibly and moreover the case appears to trigger a kernel bug making the it less than usable. Specifically the board remains responsive to some extent, however processes do not appear to be able to successfully complete termination anymore and perhaps more importantly further gdbserver processes can be started, but they never reach the stage of listening on the RSP socket. This change handles timeouts in gdbserver start properly, by throwing a TCL error exception when gdbserver does not report listening on the RSP socket in time. This is then caught at the outer level and reported, and 2 rather than 1 is returned so that the caller may tell the failure to start gdbserver and other issues apart and act accordingly (or do nothing). I thought letting the exception unwind further on might be a good idea for any test harnesses out there to break outright where a gdbserver start error is silently ignored right now, however I figured out the calls to gdbserver-support.exp are buried down too deep in the GDB test suite for such a change to be made easily. I think returning a distinct return value is good enough (the API says "non-zero", so 2 is as good as 1) and we can always make the error harder in a later step if required. With config/gdbserver.exp being used this change remains transparent to the target board, the return value is passed up by gdb_reload and the error exception unwinds through gdbserver_gdb_load and is caught and handled by mi_gdb_target_load. A call to perror is still made, reporting the timeout, and in the case of mi_gdb_target_load the procedure returns a value denoting unsuccessful completion. An unsuccessful completion of gdb_reload is already handled elsewhere. An alternative gdbserver board configuration can interpret the return value in its gdb_reload implementation and catch the error in gdbserver_gdb_load in an attempt to recover a target board that has gone astray, for example by rebooting the board somehow. This has proved effective with our failing board, that now completes the remaining test cases with no further hiccups. * lib/gdbserver-support.exp (gdbserver_start): Throw an error exception on timeout. (gdbserver_run): Catch any `gdbserver_spawn' error exceptions. (gdbserver_start_extended): Catch any `gdbserver_start' error exceptions. (gdbserver_start_multi, mi_gdbserver_start_multi): Likewise. * lib/mi-support.exp (mi_gdb_target_load): Catch any `gdbserver_gdb_load' error exceptions.
2014-09-09 15:17:38 +00:00
# to it. Return 0 on success, or non-zero on failure: 2 if gdbserver
# failed to start or 1 if we couldn't connect to it.
proc gdbserver_run { child_args } {
global gdbserver_protocol
global gdbserver_gdbport
# Kill anything running before we try to start gdbserver, in case
# we are sharing a serial connection.
global gdb_prompt
send_gdb "kill\n"
gdb_expect 120 {
-re "Kill the program being debugged. .y or n. $" {
send_gdb "y\n"
verbose "\t\tKilling previous program being debugged"
exp_continue
}
-re "$gdb_prompt $" {
# OK.
}
}
gdbserver-support: Handle gdbserver start failures As it happens we have a board that fails a gdb.base/gcore-relro.exp test case reproducibly and moreover the case appears to trigger a kernel bug making the it less than usable. Specifically the board remains responsive to some extent, however processes do not appear to be able to successfully complete termination anymore and perhaps more importantly further gdbserver processes can be started, but they never reach the stage of listening on the RSP socket. This change handles timeouts in gdbserver start properly, by throwing a TCL error exception when gdbserver does not report listening on the RSP socket in time. This is then caught at the outer level and reported, and 2 rather than 1 is returned so that the caller may tell the failure to start gdbserver and other issues apart and act accordingly (or do nothing). I thought letting the exception unwind further on might be a good idea for any test harnesses out there to break outright where a gdbserver start error is silently ignored right now, however I figured out the calls to gdbserver-support.exp are buried down too deep in the GDB test suite for such a change to be made easily. I think returning a distinct return value is good enough (the API says "non-zero", so 2 is as good as 1) and we can always make the error harder in a later step if required. With config/gdbserver.exp being used this change remains transparent to the target board, the return value is passed up by gdb_reload and the error exception unwinds through gdbserver_gdb_load and is caught and handled by mi_gdb_target_load. A call to perror is still made, reporting the timeout, and in the case of mi_gdb_target_load the procedure returns a value denoting unsuccessful completion. An unsuccessful completion of gdb_reload is already handled elsewhere. An alternative gdbserver board configuration can interpret the return value in its gdb_reload implementation and catch the error in gdbserver_gdb_load in an attempt to recover a target board that has gone astray, for example by rebooting the board somehow. This has proved effective with our failing board, that now completes the remaining test cases with no further hiccups. * lib/gdbserver-support.exp (gdbserver_start): Throw an error exception on timeout. (gdbserver_run): Catch any `gdbserver_spawn' error exceptions. (gdbserver_start_extended): Catch any `gdbserver_start' error exceptions. (gdbserver_start_multi, mi_gdbserver_start_multi): Likewise. * lib/mi-support.exp (mi_gdb_target_load): Catch any `gdbserver_gdb_load' error exceptions.
2014-09-09 15:17:38 +00:00
if { [catch { gdbserver_spawn $child_args } res] == 1 } {
perror $res
return 2
}
set gdbserver_protocol [lindex $res 0]
set gdbserver_gdbport [lindex $res 1]
return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
}
# Reconnect to the previous gdbserver session.
proc gdbserver_reconnect { } {
global gdbserver_protocol
global gdbserver_gdbport
Remove superfluous semicolons from testsuite throughout. A few months ago semicolons after "return" were removed throughout the testsuite. However, as I pointed out in review, they're unnecessary not just after "return", but pretty much after any tcl command. ';' is the command separator, and you only need it if there's another command on the same line afterwards. This patch was written by running: $ find . -name "*.exp" | xargs grep -l ";\s*$" | xargs sed -i 's/\([^#][^\s*;]*\)\s*;\s*$/\1/' and then undoing changes to comments, and lib/future.exp. Tested on x86_64 Fedora 17. gdb/testsuite/ 2013-06-07 Pedro Alves <palves@redhat.com> * boards/native-extended-gdbserver.exp: Remove semicolon. * config/arm-ice.exp: Likewise. * config/bfin.exp: Likewise. * config/cygmon.exp: Likewise. * config/h8300.exp: Likewise. * config/monitor.exp: Likewise. * config/sid.exp: Likewise. * config/sim.exp: Likewise. * config/slite.exp: Likewise. * config/vx.exp: Likewise. * gdb.arch/i386-bp_permanent.exp: Likewise. * gdb.asm/asm-source.exp: Likewise. * gdb.base/args.exp: Likewise. * gdb.base/attach-pie-misread.exp: Likewise. * gdb.base/auxv.exp: Likewise. * gdb.base/bigcore.exp: Likewise. * gdb.base/bitfields2.exp: Likewise. * gdb.base/bitfields.exp: Likewise. * gdb.base/break.exp: Likewise. * gdb.base/break-interp.exp: Likewise. * gdb.base/callfuncs.exp: Likewise. * gdb.base/call-sc.exp: Likewise. * gdb.base/commands.exp: Likewise. * gdb.base/corefile.exp: Likewise. * gdb.base/dbx.exp: Likewise. * gdb.base/ending-run.exp: Likewise. * gdb.base/exprs.exp: Likewise. * gdb.base/funcargs.exp: Likewise. * gdb.base/hbreak2.exp: Likewise. * gdb.base/huge.exp: Likewise. * gdb.base/list.exp: Likewise. * gdb.base/memattr.exp: Likewise. * gdb.base/overlays.exp: Likewise. * gdb.base/printcmds.exp: Likewise. * gdb.base/recurse.exp: Likewise. * gdb.base/remotetimeout.exp: Likewise. * gdb.base/reread.exp: Likewise. * gdb.base/savedregs.exp: Likewise. * gdb.base/scope.exp: Likewise. * gdb.base/sepdebug.exp: Likewise. * gdb.base/setshow.exp: Likewise. * gdb.base/setvar.exp: Likewise. * gdb.base/sigaltstack.exp: Likewise. * gdb.base/siginfo-addr.exp: Likewise. * gdb.base/siginfo.exp: Likewise. * gdb.base/siginfo-obj.exp: Likewise. * gdb.base/sigrepeat.exp: Likewise. * gdb.base/sigstep.exp: Likewise. * gdb.base/structs.exp: Likewise. * gdb.base/testenv.exp: Likewise. * gdb.base/twice.exp: Likewise. * gdb.base/valgrind-db-attach.exp: Likewise. * gdb.base/valgrind-infcall.exp: Likewise. * gdb.base/varargs.exp: Likewise. * gdb.base/watchpoint.exp: Likewise. * gdb.cp/gdb1355.exp: Likewise. * gdb.cp/misc.exp: Likewise. * gdb.disasm/hppa.exp: Likewise. * gdb.disasm/t01_mov.exp: Likewise. * gdb.disasm/t02_mova.exp: Likewise. * gdb.disasm/t03_add.exp: Likewise. * gdb.disasm/t04_sub.exp: Likewise. * gdb.disasm/t05_cmp.exp: Likewise. * gdb.disasm/t06_ari2.exp: Likewise. * gdb.disasm/t07_ari3.exp: Likewise. * gdb.disasm/t08_or.exp: Likewise. * gdb.disasm/t09_xor.exp: Likewise. * gdb.disasm/t10_and.exp: Likewise. * gdb.disasm/t11_logs.exp: Likewise. * gdb.disasm/t12_bit.exp: Likewise. * gdb.disasm/t13_otr.exp: Likewise. * gdb.gdb/selftest.exp: Likewise. * gdb.hp/gdb.base-hp/callfwmall.exp: Likewise. * gdb.mi/mi-reverse.exp: Likewise. * gdb.pascal/floats.exp: Likewise. * gdb.python/py-inferior.exp: Likewise. * gdb.threads/attach-into-signal.exp: Likewise. * gdb.threads/pthreads.exp: Likewise. * gdb.threads/thread_events.exp: Likewise. * gdb.threads/watchthreads.exp: Likewise. * gdb.trace/actions-changed.exp: Likewise. * gdb.trace/actions.exp: Likewise. * gdb.trace/ax.exp: Likewise. * gdb.trace/backtrace.exp: Likewise. * gdb.trace/change-loc.exp: Likewise. * gdb.trace/deltrace.exp: Likewise. * gdb.trace/disconnected-tracing.exp: Likewise. * gdb.trace/ftrace.exp: Likewise. * gdb.trace/infotrace.exp: Likewise. * gdb.trace/passc-dyn.exp: Likewise. * gdb.trace/passcount.exp: Likewise. * gdb.trace/pending.exp: Likewise. * gdb.trace/qtro.exp: Likewise. * gdb.trace/range-stepping.exp: Likewise. * gdb.trace/report.exp: Likewise. * gdb.trace/save-trace.exp: Likewise. * gdb.trace/status-stop.exp: Likewise. * gdb.trace/strace.exp: Likewise. * gdb.trace/tfile.exp: Likewise. * gdb.trace/tfind.exp: Likewise. * gdb.trace/trace-break.exp: Likewise. * gdb.trace/tracecmd.exp: Likewise. * gdb.trace/trace-mt.exp: Likewise. * gdb.trace/tspeed.exp: Likewise. * gdb.trace/tsv.exp: Likewise. * gdb.trace/while-stepping.exp: Likewise. * lib/gdb.exp: Likewise. * lib/gdbserver-support.exp: Likewise. * lib/java.exp: Likewise. * lib/mi-support.exp: Likewise. * lib/pascal.exp: Likewise. * lib/prompt.exp: Likewise. * lib/trace-support.exp: Likewise.
2013-06-07 17:31:09 +00:00
global gdbserver_reconnect_p
if {![info exists gdbserver_reconnect_p] || !$gdbserver_reconnect_p} {
error "gdbserver_reconnect_p is not set before gdbserver_reconnect"
return 0
}
return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
}
* linux-low.c (linux_attach_lwp): Do not _exit after errors. (linux_kill, linux_detach): Clean up the process list. * remote-utils.c (remote_open): Improve port number parsing. (putpkt_binary, input_interrupt): Only send interrupts if the target is running. * server.c (extended_protocol): Make static. (attached): Define earlier. (exit_requested, response_needed, program_argv): New variables. (target_running): New. (start_inferior): Clear attached here. (attach_inferior): Set attached here. (require_running): Define. (handle_query): Use require_running and target_running. Implement "monitor exit". (handle_v_attach, handle_v_run): New. (handle_v_requests): Use require_running. Handle vAttach and vRun. (gdbserver_usage): Update. (main): Redo argument parsing. Handle --debug and --multi. Handle --attach along with other options or after the port. Save program_argv. Support no initial program. Resynchronize communication with GDB after an error. Handle "monitor exit". Use require_running and target_running. Always allow the extended protocol. Do not error out for Hc0 or Hc-1. Do not automatically restart in extended mode. * README: Refer to the GDB manual. Update --attach usage. * remote.c (struct remote_state): Add cached_wait_status. (remote_exec_file): New variable. (PACKET_vAttach, PACKET_vRun): New constants. (extended_remote_restart): Do not query for status. (struct start_remote_args): New. (remote_start_remote): Take it as a second argument. Check whether the target is running. Issue an error for non-running non-extended targets. Cache the wait status. Set inferior_ptid here. (remote_open_1): Prompt to disconnect non-running targets. Make sure the target is marked running. Do not set inferior_ptid here. Update call to remote_start_remote. Do not call remote_check_symbols if the target is not running. (remote_detach_1): Rename from remote_detach. Take an EXTENDED argument. Handle a non-running target. (remote_detach): Use it. (extended_remote_detach): New. (remote_disconnect): Fix typo. Use remoute_mourn_1. (extended_remote_attach_1, extended_remote_attach) (extended_async_remote_attach): New. (remote_vcont_resume): Remove unused variable. (remote_wait, remote_async_wait): Use any cached wait status. (putpkt_binary, getpkt): Clear any cached wait status. (extended_remoute_mourn_1): New. (extended_remote_mourn): Use it. (extended_async_remote_mourn, extended_remote_run): New. (extended_remote_create_inferior_1): New. (extended_remote_create_inferior): Use it. (extended_remote_async_create_inferior): Likewise. (remote_xfer_partial): Skip for non-executing targets. (init_extended_remote_ops): Set to_detach and to_attach. (init_extended_async_remote_ops): Likewise. Use extended_async_remote_mourn. (_initialize_remote): Register vAttach, vRun, and set remote exec-file. * NEWS: Mention vAttach, vRun, and gdbserver extended-remote support. * gdb.server/ext-attach.c, gdb.server/ext-attach.exp, gdb.server/ext-run.exp: New files. * lib/gdbserver-support.exp (gdbserver_download): New. (gdbserver_start): New. Update gdbserver expected output. (gdbserver_spawn): Use them. (gdbserver_start_extended): New. * gdb.texinfo (Using the `gdbserver' Program): Add security warning. Rearrange into subsections and subsubsections. Document --multi and --debug. Correct --with-sysroot typo. Update --attach usage. Make load reference clearer. Document monitor exit. (Remote Configuration): Document set remote exec-file, attach-packet, and run-packet. (Packets): Document vAttach and vRun.
2008-01-30 00:51:50 +00:00
# Start gdbserver in extended mode with OPTIONS and connect to it. Note
# this frobs $gdbserver_protocol, so should be used only from a board
# that usually connects in target remote mode.
proc gdbserver_start_extended { {options ""} } {
global gdbserver_protocol
global gdbserver_gdbport
global use_gdb_stub
set gdbserver_options "--multi"
if { $options != "" } {
append gdbserver_options " $options"
}
if { [catch { gdbserver_start $gdbserver_options "" } res] == 1 } {
gdbserver-support: Handle gdbserver start failures As it happens we have a board that fails a gdb.base/gcore-relro.exp test case reproducibly and moreover the case appears to trigger a kernel bug making the it less than usable. Specifically the board remains responsive to some extent, however processes do not appear to be able to successfully complete termination anymore and perhaps more importantly further gdbserver processes can be started, but they never reach the stage of listening on the RSP socket. This change handles timeouts in gdbserver start properly, by throwing a TCL error exception when gdbserver does not report listening on the RSP socket in time. This is then caught at the outer level and reported, and 2 rather than 1 is returned so that the caller may tell the failure to start gdbserver and other issues apart and act accordingly (or do nothing). I thought letting the exception unwind further on might be a good idea for any test harnesses out there to break outright where a gdbserver start error is silently ignored right now, however I figured out the calls to gdbserver-support.exp are buried down too deep in the GDB test suite for such a change to be made easily. I think returning a distinct return value is good enough (the API says "non-zero", so 2 is as good as 1) and we can always make the error harder in a later step if required. With config/gdbserver.exp being used this change remains transparent to the target board, the return value is passed up by gdb_reload and the error exception unwinds through gdbserver_gdb_load and is caught and handled by mi_gdb_target_load. A call to perror is still made, reporting the timeout, and in the case of mi_gdb_target_load the procedure returns a value denoting unsuccessful completion. An unsuccessful completion of gdb_reload is already handled elsewhere. An alternative gdbserver board configuration can interpret the return value in its gdb_reload implementation and catch the error in gdbserver_gdb_load in an attempt to recover a target board that has gone astray, for example by rebooting the board somehow. This has proved effective with our failing board, that now completes the remaining test cases with no further hiccups. * lib/gdbserver-support.exp (gdbserver_start): Throw an error exception on timeout. (gdbserver_run): Catch any `gdbserver_spawn' error exceptions. (gdbserver_start_extended): Catch any `gdbserver_start' error exceptions. (gdbserver_start_multi, mi_gdbserver_start_multi): Likewise. * lib/mi-support.exp (mi_gdb_target_load): Catch any `gdbserver_gdb_load' error exceptions.
2014-09-09 15:17:38 +00:00
perror $res
return 2
}
set gdbserver_protocol [lindex $res 0]
if { [string first "extended-" $gdbserver_protocol] != 0} {
set gdbserver_protocol "extended-$gdbserver_protocol"
}
* linux-low.c (linux_attach_lwp): Do not _exit after errors. (linux_kill, linux_detach): Clean up the process list. * remote-utils.c (remote_open): Improve port number parsing. (putpkt_binary, input_interrupt): Only send interrupts if the target is running. * server.c (extended_protocol): Make static. (attached): Define earlier. (exit_requested, response_needed, program_argv): New variables. (target_running): New. (start_inferior): Clear attached here. (attach_inferior): Set attached here. (require_running): Define. (handle_query): Use require_running and target_running. Implement "monitor exit". (handle_v_attach, handle_v_run): New. (handle_v_requests): Use require_running. Handle vAttach and vRun. (gdbserver_usage): Update. (main): Redo argument parsing. Handle --debug and --multi. Handle --attach along with other options or after the port. Save program_argv. Support no initial program. Resynchronize communication with GDB after an error. Handle "monitor exit". Use require_running and target_running. Always allow the extended protocol. Do not error out for Hc0 or Hc-1. Do not automatically restart in extended mode. * README: Refer to the GDB manual. Update --attach usage. * remote.c (struct remote_state): Add cached_wait_status. (remote_exec_file): New variable. (PACKET_vAttach, PACKET_vRun): New constants. (extended_remote_restart): Do not query for status. (struct start_remote_args): New. (remote_start_remote): Take it as a second argument. Check whether the target is running. Issue an error for non-running non-extended targets. Cache the wait status. Set inferior_ptid here. (remote_open_1): Prompt to disconnect non-running targets. Make sure the target is marked running. Do not set inferior_ptid here. Update call to remote_start_remote. Do not call remote_check_symbols if the target is not running. (remote_detach_1): Rename from remote_detach. Take an EXTENDED argument. Handle a non-running target. (remote_detach): Use it. (extended_remote_detach): New. (remote_disconnect): Fix typo. Use remoute_mourn_1. (extended_remote_attach_1, extended_remote_attach) (extended_async_remote_attach): New. (remote_vcont_resume): Remove unused variable. (remote_wait, remote_async_wait): Use any cached wait status. (putpkt_binary, getpkt): Clear any cached wait status. (extended_remoute_mourn_1): New. (extended_remote_mourn): Use it. (extended_async_remote_mourn, extended_remote_run): New. (extended_remote_create_inferior_1): New. (extended_remote_create_inferior): Use it. (extended_remote_async_create_inferior): Likewise. (remote_xfer_partial): Skip for non-executing targets. (init_extended_remote_ops): Set to_detach and to_attach. (init_extended_async_remote_ops): Likewise. Use extended_async_remote_mourn. (_initialize_remote): Register vAttach, vRun, and set remote exec-file. * NEWS: Mention vAttach, vRun, and gdbserver extended-remote support. * gdb.server/ext-attach.c, gdb.server/ext-attach.exp, gdb.server/ext-run.exp: New files. * lib/gdbserver-support.exp (gdbserver_download): New. (gdbserver_start): New. Update gdbserver expected output. (gdbserver_spawn): Use them. (gdbserver_start_extended): New. * gdb.texinfo (Using the `gdbserver' Program): Add security warning. Rearrange into subsections and subsubsections. Document --multi and --debug. Correct --with-sysroot typo. Update --attach usage. Make load reference clearer. Document monitor exit. (Remote Configuration): Document set remote exec-file, attach-packet, and run-packet. (Packets): Document vAttach and vRun.
2008-01-30 00:51:50 +00:00
set gdbserver_gdbport [lindex $res 1]
# Even if the board file is testing with target remote, our caller
# wants to test against gdbserver in extended-remote mode. Make sure to
# disable stub-like techniques.
set use_gdb_stub 0
* linux-low.c (linux_attach_lwp): Do not _exit after errors. (linux_kill, linux_detach): Clean up the process list. * remote-utils.c (remote_open): Improve port number parsing. (putpkt_binary, input_interrupt): Only send interrupts if the target is running. * server.c (extended_protocol): Make static. (attached): Define earlier. (exit_requested, response_needed, program_argv): New variables. (target_running): New. (start_inferior): Clear attached here. (attach_inferior): Set attached here. (require_running): Define. (handle_query): Use require_running and target_running. Implement "monitor exit". (handle_v_attach, handle_v_run): New. (handle_v_requests): Use require_running. Handle vAttach and vRun. (gdbserver_usage): Update. (main): Redo argument parsing. Handle --debug and --multi. Handle --attach along with other options or after the port. Save program_argv. Support no initial program. Resynchronize communication with GDB after an error. Handle "monitor exit". Use require_running and target_running. Always allow the extended protocol. Do not error out for Hc0 or Hc-1. Do not automatically restart in extended mode. * README: Refer to the GDB manual. Update --attach usage. * remote.c (struct remote_state): Add cached_wait_status. (remote_exec_file): New variable. (PACKET_vAttach, PACKET_vRun): New constants. (extended_remote_restart): Do not query for status. (struct start_remote_args): New. (remote_start_remote): Take it as a second argument. Check whether the target is running. Issue an error for non-running non-extended targets. Cache the wait status. Set inferior_ptid here. (remote_open_1): Prompt to disconnect non-running targets. Make sure the target is marked running. Do not set inferior_ptid here. Update call to remote_start_remote. Do not call remote_check_symbols if the target is not running. (remote_detach_1): Rename from remote_detach. Take an EXTENDED argument. Handle a non-running target. (remote_detach): Use it. (extended_remote_detach): New. (remote_disconnect): Fix typo. Use remoute_mourn_1. (extended_remote_attach_1, extended_remote_attach) (extended_async_remote_attach): New. (remote_vcont_resume): Remove unused variable. (remote_wait, remote_async_wait): Use any cached wait status. (putpkt_binary, getpkt): Clear any cached wait status. (extended_remoute_mourn_1): New. (extended_remote_mourn): Use it. (extended_async_remote_mourn, extended_remote_run): New. (extended_remote_create_inferior_1): New. (extended_remote_create_inferior): Use it. (extended_remote_async_create_inferior): Likewise. (remote_xfer_partial): Skip for non-executing targets. (init_extended_remote_ops): Set to_detach and to_attach. (init_extended_async_remote_ops): Likewise. Use extended_async_remote_mourn. (_initialize_remote): Register vAttach, vRun, and set remote exec-file. * NEWS: Mention vAttach, vRun, and gdbserver extended-remote support. * gdb.server/ext-attach.c, gdb.server/ext-attach.exp, gdb.server/ext-run.exp: New files. * lib/gdbserver-support.exp (gdbserver_download): New. (gdbserver_start): New. Update gdbserver expected output. (gdbserver_spawn): Use them. (gdbserver_start_extended): New. * gdb.texinfo (Using the `gdbserver' Program): Add security warning. Rearrange into subsections and subsubsections. Document --multi and --debug. Correct --with-sysroot typo. Update --attach usage. Make load reference clearer. Document monitor exit. (Remote Configuration): Document set remote exec-file, attach-packet, and run-packet. (Packets): Document vAttach and vRun.
2008-01-30 00:51:50 +00:00
return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
}
# Start and connect to a gdbserver in extended/multi mode. Unlike
# gdbserver_start_extended, this does not frob $gdbserver_protocol.
proc gdbserver_start_multi { } {
global gdbserver_protocol
global gdbserver_gdbport
gdbserver-support: Handle gdbserver start failures As it happens we have a board that fails a gdb.base/gcore-relro.exp test case reproducibly and moreover the case appears to trigger a kernel bug making the it less than usable. Specifically the board remains responsive to some extent, however processes do not appear to be able to successfully complete termination anymore and perhaps more importantly further gdbserver processes can be started, but they never reach the stage of listening on the RSP socket. This change handles timeouts in gdbserver start properly, by throwing a TCL error exception when gdbserver does not report listening on the RSP socket in time. This is then caught at the outer level and reported, and 2 rather than 1 is returned so that the caller may tell the failure to start gdbserver and other issues apart and act accordingly (or do nothing). I thought letting the exception unwind further on might be a good idea for any test harnesses out there to break outright where a gdbserver start error is silently ignored right now, however I figured out the calls to gdbserver-support.exp are buried down too deep in the GDB test suite for such a change to be made easily. I think returning a distinct return value is good enough (the API says "non-zero", so 2 is as good as 1) and we can always make the error harder in a later step if required. With config/gdbserver.exp being used this change remains transparent to the target board, the return value is passed up by gdb_reload and the error exception unwinds through gdbserver_gdb_load and is caught and handled by mi_gdb_target_load. A call to perror is still made, reporting the timeout, and in the case of mi_gdb_target_load the procedure returns a value denoting unsuccessful completion. An unsuccessful completion of gdb_reload is already handled elsewhere. An alternative gdbserver board configuration can interpret the return value in its gdb_reload implementation and catch the error in gdbserver_gdb_load in an attempt to recover a target board that has gone astray, for example by rebooting the board somehow. This has proved effective with our failing board, that now completes the remaining test cases with no further hiccups. * lib/gdbserver-support.exp (gdbserver_start): Throw an error exception on timeout. (gdbserver_run): Catch any `gdbserver_spawn' error exceptions. (gdbserver_start_extended): Catch any `gdbserver_start' error exceptions. (gdbserver_start_multi, mi_gdbserver_start_multi): Likewise. * lib/mi-support.exp (mi_gdb_target_load): Catch any `gdbserver_gdb_load' error exceptions.
2014-09-09 15:17:38 +00:00
if { [catch { gdbserver_start "--multi" "" } res] == 1 } {
perror $res
return 2
}
set gdbserver_protocol [lindex $res 0]
set gdbserver_gdbport [lindex $res 1]
return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
}
# Start a gdbserver process in multi/extended mode, and have GDB
# connect to it (MI version). Return 0 on success, or non-zero on
# failure.
proc mi_gdbserver_start_multi { } {
global gdbserver_protocol
global gdbserver_gdbport
gdbserver-support: Handle gdbserver start failures As it happens we have a board that fails a gdb.base/gcore-relro.exp test case reproducibly and moreover the case appears to trigger a kernel bug making the it less than usable. Specifically the board remains responsive to some extent, however processes do not appear to be able to successfully complete termination anymore and perhaps more importantly further gdbserver processes can be started, but they never reach the stage of listening on the RSP socket. This change handles timeouts in gdbserver start properly, by throwing a TCL error exception when gdbserver does not report listening on the RSP socket in time. This is then caught at the outer level and reported, and 2 rather than 1 is returned so that the caller may tell the failure to start gdbserver and other issues apart and act accordingly (or do nothing). I thought letting the exception unwind further on might be a good idea for any test harnesses out there to break outright where a gdbserver start error is silently ignored right now, however I figured out the calls to gdbserver-support.exp are buried down too deep in the GDB test suite for such a change to be made easily. I think returning a distinct return value is good enough (the API says "non-zero", so 2 is as good as 1) and we can always make the error harder in a later step if required. With config/gdbserver.exp being used this change remains transparent to the target board, the return value is passed up by gdb_reload and the error exception unwinds through gdbserver_gdb_load and is caught and handled by mi_gdb_target_load. A call to perror is still made, reporting the timeout, and in the case of mi_gdb_target_load the procedure returns a value denoting unsuccessful completion. An unsuccessful completion of gdb_reload is already handled elsewhere. An alternative gdbserver board configuration can interpret the return value in its gdb_reload implementation and catch the error in gdbserver_gdb_load in an attempt to recover a target board that has gone astray, for example by rebooting the board somehow. This has proved effective with our failing board, that now completes the remaining test cases with no further hiccups. * lib/gdbserver-support.exp (gdbserver_start): Throw an error exception on timeout. (gdbserver_run): Catch any `gdbserver_spawn' error exceptions. (gdbserver_start_extended): Catch any `gdbserver_start' error exceptions. (gdbserver_start_multi, mi_gdbserver_start_multi): Likewise. * lib/mi-support.exp (mi_gdb_target_load): Catch any `gdbserver_gdb_load' error exceptions.
2014-09-09 15:17:38 +00:00
if { [catch { gdbserver_start "--multi" "" } res] == 1 } {
perror $res
return 2
}
set gdbserver_protocol [lindex $res 0]
set gdbserver_gdbport [lindex $res 1]
return [mi_gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
}