-# Copyright 2000-2018 Free Software Foundation, Inc.
+# Copyright 2000-2019 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
+# Send gdb the "target" command. Returns 0 on success, 1 on failure.
+# 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 } {
+proc gdb_target_cmd { 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 "Remote MIPS debugging.*$gdb_prompt" {
+ -re "Remote MIPS debugging.*$additional_text.*$gdb_prompt" {
verbose "Set target to $targetname"
return 0
}
- -re "Remote debugging using .*$serialport_re.*$gdb_prompt $" {
+ -re "Remote debugging using .*$serialport_re.*$additional_text.*$gdb_prompt $" {
verbose "Set target to $targetname"
return 0
}
- -re "Remote debugging using stdio.*$gdb_prompt $" {
+ -re "Remote debugging using stdio.*$additional_text.*$gdb_prompt $" {
verbose "Set target to $targetname"
return 0
}
- -re "Remote target $targetname connected to.*$gdb_prompt $" {
+ -re "Remote target $targetname connected to.*$additional_text.*$gdb_prompt $" {
verbose "Set target to $targetname"
return 0
}
- -re "Connected to.*$gdb_prompt $" {
+ -re "Connected to.*$additional_text.*$gdb_prompt $" {
verbose "Set target to $targetname"
return 0
}
# If gdbserver_reconnect will be called $gdbserver_reconnect_p must be
# set to true already during gdbserver_start.
global gdbserver_reconnect_p
+ global srcdir
+ global subdir
if {![info exists gdbserver_reconnect_p] || !$gdbserver_reconnect_p} {
# GDB client could accidentally connect to a stale server.
- # append gdbserver_command " --debug --once"
append gdbserver_command " --once"
}
+ # 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"
+ }
+ }
+
if { $options != "" } {
append gdbserver_command " $options"
}
-timeout 120
-notransfer
-re "Listening on" { }
- -re "Can't bind address: Address already in use\\.\r\n" {
+ -re "Can't (bind address|listen on socket): 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.
continue
}
}
- -re ".*: cannot resolve name: Name or service not known\r\n" {
+ -re ".*: cannot resolve name: .*\r\n" {
error "gdbserver cannot resolve name."
}
timeout {
return [mi_gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport]
}
+
+# Check if debugging is enabled for gdbserver.
+
+proc gdbserver_debug_enabled { } {
+ global gdbserverdebug
+
+ # If not already read, get the debug setting from environment or board setting.
+ if ![info exists gdbserverdebug] {
+ global env
+ if [info exists env(GDBSERVER_DEBUG)] {
+ set gdbserverdebug $env(GDBSERVER_DEBUG)
+ } elseif [target_info exists gdbserver,debug] {
+ set gdbserverdebug [target_info gdbserver,debug]
+ } else {
+ return 0
+ }
+ }
+
+ # Only return success on valid values.
+ return [expr { $gdbserverdebug == "debug" || $gdbserverdebug == "remote"
+ || $gdbserverdebug == "all" }]
+}