-# Copyright 2000-2013 Free Software Foundation, Inc.
+# Copyright 2000-2018 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
return 1
}
+ # 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
}
global gdbserver_server_exec
global last_loaded_file
+ 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.
if { $reuse == 0 } {
set gdbserver_host_exec $host_exec
set gdbserver_host_mtime [file mtime $host_exec]
- if [is_remote target] {
- set gdbserver_server_exec [gdb_download $host_exec]
- } else {
- set gdbserver_server_exec $host_exec
- }
+ set gdbserver_server_exec [gdb_remote_download target $host_exec]
}
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"
+}
+
# Start a gdbserver process with initial OPTIONS and trailing ARGUMENTS.
# The port will be filled in between them automatically.
#
proc gdbserver_start { options arguments } {
global portnum
+ global GDB_TEST_SOCKETHOST
# Port id -- either specified in baseboard file, or managed here.
if [target_info exists gdb,socketport] {
}
# Extract the local and remote host ids from the target board struct.
- if [target_info exists sockethost] {
+ if { [info exists GDB_TEST_SOCKETHOST] } {
+ # The user is not supposed to provide a port number, just a
+ # hostname/address, therefore we add the trailing ":" here.
+ set debughost "${GDB_TEST_SOCKETHOST}:"
+ # Escape open and close square brackets.
+ set debughost_tmp [string map { [ \\[ ] \\] } $debughost]
+ # We need a "gdbserver" version of the debughost, which will
+ # have the possible connection prefix stripped. This is
+ # because gdbserver currently doesn't recognize the prefixes.
+ regsub -all "^\(tcp:|udp:|tcp4:|udp4:|tcp6:|udp6:\)" $debughost_tmp "" debughost_gdbserver
+ } elseif [target_info exists sockethost] {
set debughost [target_info sockethost]
+ set debughost_gdbserver $debughost
} else {
set debughost "localhost:"
+ set debughost_gdbserver $debughost
}
# Some boards use a different value for the port that is passed to
} 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] {
if { $options != "" } {
append gdbserver_command " $options"
}
+ if { $debughost_gdbserver != "" } {
+ append gdbserver_command " $debughost_gdbserver"
+ }
if { $portnum != "" } {
- append gdbserver_command " :$portnum"
+ if { $debughost_gdbserver == "" } {
+ append gdbserver_command " "
+ }
+ 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]
+ # 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
+ -timeout 120
-notransfer
-re "Listening on" { }
-re "Can't bind address: Address already in use\\.\r\n" {
continue
}
}
+ -re ".*: cannot resolve name: .*\r\n" {
+ error "gdbserver cannot resolve name."
+ }
+ timeout {
+ error "Timeout waiting for gdbserver response."
+ }
}
break
}
- # 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.
- expect_background {
- -i $server_spawn_id
- full_buffer { }
- eof {
- # The spawn ID is already closed now (but not yet waited for).
- wait -i $expect_out(spawn_id)
- }
- }
-
return [list $protocol [$get_remote_address $debughost $portnum]]
}
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. We must load this
+# explicitly here, and rename the procedures we want to override.
+load_lib mi-support.exp
+
+if { [info procs gdbserver_orig_gdb_exit] == "" } {
+ rename gdb_exit gdbserver_orig_gdb_exit
+ rename mi_gdb_exit gdbserver_orig_mi_gdb_exit
+}
+
+proc gdbserver_gdb_exit { is_mi } {
+ 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} {
+ if { $is_mi } {
+ gdbserver_orig_mi_gdb_exit
+ } else {
+ 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 {
+ if { $is_mi } {
+ set monitor_exit "-interpreter-exec console \"monitor exit\""
+ } else {
+ set monitor_exit "monitor exit"
+ }
+ 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
+
+ if { $is_mi } {
+ gdbserver_orig_mi_gdb_exit
+ } else {
+ gdbserver_orig_gdb_exit
+ }
+}
+
+proc gdb_exit {} {
+ gdbserver_gdb_exit 0
+}
+
+proc mi_gdb_exit {} {
+ gdbserver_gdb_exit 1
+}
+
# Start a gdbserver process running HOST_EXEC and pass CHILD_ARGS
-# to it. Return 0 on success, or non-zero on failure.
+# 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
}
}
- set res [gdbserver_spawn $child_args]
+ 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]
}
-# Start and connect to a gdbserver in extended mode. Note this frobs
-# $gdbserver_protocol, so should be used only from a board that
-# usually connects in target remote mode.
-proc gdbserver_start_extended { } {
+# 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 res [gdbserver_start "--multi" ""]
+ set gdbserver_options "--multi"
+
+ if { $options != "" } {
+ append gdbserver_options " $options"
+ }
+
+ if { [catch { gdbserver_start $gdbserver_options "" } res] == 1 } {
+ perror $res
+ return 2
+ }
set gdbserver_protocol [lindex $res 0]
if { [string first "extended-" $gdbserver_protocol] != 0} {
set gdbserver_protocol "extended-$gdbserver_protocol"
global gdbserver_protocol
global gdbserver_gdbport
- set res [gdbserver_start "--multi" ""]
+ if { [catch { gdbserver_start "--multi" "" } res] == 1 } {
+ perror $res
+ return 2
+ }
set gdbserver_protocol [lindex $res 0]
set gdbserver_gdbport [lindex $res 1]
global gdbserver_protocol
global gdbserver_gdbport
- set res [gdbserver_start "--multi" ""]
+ if { [catch { gdbserver_start "--multi" "" } res] == 1 } {
+ perror $res
+ return 2
+ }
set gdbserver_protocol [lindex $res 0]
set gdbserver_gdbport [lindex $res 1]