-# Copyright 2000-2019 Free Software Foundation, Inc.
+# Copyright 2000-2020 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
#
#
-# gdb_target_cmd
-# Send gdb the "target" command. Returns 0 on success, 1 on failure.
+# gdb_target_cmd_ext
+# Send gdb the "target" command. Returns 0 on success, 1 on failure, 2 on
+# unsupported.
# If specified, then ADDITIONAL_TEXT must match the text that comes after
# the connection message in order for the procedure to succeed.
#
-proc gdb_target_cmd { targetname serialport {additional_text ""} } {
+proc gdb_target_cmd_ext { targetname serialport {additional_text ""} } {
global gdb_prompt
set serialport_re [string_to_regexp $serialport]
-re "Couldn't establish connection to remote.*$gdb_prompt $" {
verbose "Connection failed"
}
+ -re "Non-stop mode requested, but remote does not support non-stop.*$gdb_prompt $" {
+ verbose "remote does not support non-stop"
+ return 1
+ }
-re "Remote MIPS debugging.*$additional_text.*$gdb_prompt" {
verbose "Set target to $targetname"
return 0
# Leave it there for the test to diagnose.
return 1
}
+ -re ": Network is unreachable.\r\n.*$gdb_prompt $" {
+ return 2
+ }
timeout {
send_gdb "\ 3"
break
return 1
}
+# Like gdb_target_cmd_ext, but returns 0 on success, 1 on failure.
+
+proc gdb_target_cmd { args } {
+ set res [eval gdb_target_cmd_ext $args]
+ return [expr $res == 0 ? 0 : 1]
+}
global portnum
set portnum "2345"
return [target_info gdb_server_prog]
}
- set gdbserver "${GDB}server"
- if { [file isdirectory $gdbserver] } {
- append gdbserver "/gdbserver"
- }
+ set toplevel [file join [file dirname $GDB] .. gdbserver]
+ foreach gdbserver [list "${GDB}server" $toplevel] {
+ if { [file isdirectory $gdbserver] } {
+ append gdbserver "/gdbserver"
+ }
- if { [file executable $gdbserver] } {
- return $gdbserver
+ if { [file executable $gdbserver] } {
+ return $gdbserver
+ }
}
return ""
# Enable debug if set.
if [gdbserver_debug_enabled] {
global gdbserverdebug
- set debugfile [standard_output_file gdbserver.debug]
- if { $gdbserverdebug == "debug" } {
- append gdbserver_command " --debug --debug-file=$debugfile"
- } elseif { $gdbserverdebug == "remote" } {
- append gdbserver_command " --remote-debug --debug-file=$debugfile"
- } elseif { $gdbserverdebug == "all" } {
- append gdbserver_command " --debug --remote-debug --debug-file=$debugfile"
+ set enabled 0
+ foreach entry [split $gdbserverdebug ,] {
+ switch -- $entry {
+ "debug" {
+ append gdbserver_command " --debug"
+ set enabled 1
+ }
+ "remote" {
+ append gdbserver_command " --remote-debug"
+ set enabled 1
+ }
+ }
+ }
+ # Ensure debugfile is only added if something has been enabled
+ if { $enabled } {
+ set debugfile [standard_output_file gdbserver.debug]
+ append gdbserver_command " --debug-file=$debugfile"
}
}
append gdbserver_command " $arguments"
}
+ gdbserver_write_cmd_file $gdbserver_command
+
global server_spawn_id
set server_spawn_id [remote_spawn target $gdbserver_command]
# Kill anything running before we try to start gdbserver, in case
# we are sharing a serial connection.
global gdb_prompt
- send_gdb "kill\n"
+ send_gdb "kill\n" optional
gdb_expect 120 {
-re "Kill the program being debugged. .y or n. $" {
send_gdb "y\n"
}
}
- # Only return success on valid values.
- return [expr { $gdbserverdebug == "debug" || $gdbserverdebug == "remote"
- || $gdbserverdebug == "all" }]
+ # Expand the all option
+ if { $gdbserverdebug == "all" } {
+ set gdbserverdebug "debug,remote,replay"
+ }
+
+ # Ensure it is not empty.
+ return [expr { $gdbserverdebug != "" }]
+}
+
+# Write the command line used to invocate gdbserver to the cmd file.
+
+proc gdbserver_write_cmd_file { cmdline } {
+ set logfile [standard_output_file_with_gdb_instance gdbserver.cmd]
+ set cmd_file [open $logfile w]
+ puts $cmd_file $cmdline
+ catch "close $cmd_file"
+}
+
+# Override gdb_debug_init so that we can set replay logging in GDB if required.
+# Backup the original function so we can call it afterwards
+
+rename gdb_debug_init _gdb_debug_init
+
+proc gdb_debug_init { } {
+ global gdbserverdebug
+ global gdb_prompt
+
+ if [gdbserver_debug_enabled] {
+ foreach entry [split $gdbserverdebug ,] {
+ if { $entry == "replay" } {
+ set replayfile [standard_output_file_with_gdb_instance gdbserver.replay]
+ send_gdb "set remotelogfile $replayfile\n" optional
+ gdb_expect 10 {
+ -re "$gdb_prompt $" {}
+ }
+ }
+ }
+ }
+
+ # Now call the standard debug init function
+ _gdb_debug_init
}