old-cross-binutils/gdb/testsuite/boards/native-extended-gdbserver.exp
Pedro Alves 5b80f00d51 gdb_load: Fix latent bugs
In a test I was writting, I needed a procedure that would connect to
the target, and do "load", or equivalent.

Years ago, boards would override gdb_load to implement that.  Then
gdb_reload was added, and gdb_load was relaxed to allow boards avoid
the spawing and connecting to the target.  This sped up gdbserver
testing.  See
https://www.sourceware.org/ml/gdb-patches/2007-02/msg00318.html.

To actually spawn the target and load the executable on the target
side, gdb_reload was born:

 # gdb_reload -- load a file into the target.  Called before "running",
 # either the first time or after already starting the program once,
 # for remote targets.  Most files that override gdb_load should now
 # override this instead.

 proc gdb_reload { } {
     # For the benefit of existing configurations, default to gdb_load.
     # Specifying no file defaults to the executable currently being
     # debugged.
     return [gdb_load ""]
 }

Note the comment about specifying no file.  Indeed looking at
config/sid.exp, or config/monitor.exp, we see examples of that.

However, the default gdb_load itself doesn't handle the case of no
file specified.  When passed no file, it just calls gdb_file_cmd with
no file either, which ends up invocing the "file" command with no
argument, which means unloading the file and its symbols...  That
means calling gdb_reload when testing against native targets is
broken.  We don't see that today because the only call to gdb_reload
that exists today is guarded by target_info exists
gdb,do_reload_on_run.

The native-extended-gdbserver.exp board is likewise broken here.  When
[gdb_load ""] is called, the board sets the remote exec-file to "" ...

Tested on x86_64 Fedora 17, native, remote gdbserver and
extended-remote gdbserver.

testsuite/
2014-05-01  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (gdb_load): Extend comment.  Skip calling
	gdb_file_cmd if no file is specified.
	* boards/native-extended-gdbserver.exp (gdb_load): Use the
	last_loaded_file to set the remote exec-file.
2014-05-02 00:59:31 +01:00

121 lines
3.4 KiB
Text

# Copyright 2011-2014 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 a dejagnu "board file" and is used to run the testsuite
# natively with gdbserver, in extended-remote mode.
#
# To use this file:
# bash$ cd ${build_dir}/gdb
# bash$ make check RUNTESTFLAGS="--target_board=native-extended-gdbserver"
load_generic_config "extended-gdbserver"
load_board_description "gdbserver-base"
# By default, dejagnu makes the board remote unless the board name
# matches localhost. Force it to be NOT remote.
global board
global board_info
set board_info($board,isremote) 0
set_board_info sockethost "localhost:"
# We will be using the extended GDB remote protocol.
set_board_info gdb_protocol "extended-remote"
send_user "configuring for gdbserver local testing (extended-remote)\n"
# We must load this explicitly here, and rename the procedures we want
# to override. If we didn't do this, given that mi-support.exp is
# loaded later in the test files, the procedures loaded then would
# override our definitions.
load_lib mi-support.exp
# Overriden in order to start a "gdbserver --multi" instance whenever
# GDB is started. Note nothing is needed for gdb_exit, since
# gdbserver is started with --once, causing it to exit once GDB
# disconnects.
proc gdb_start { } {
# Spawn GDB.
default_gdb_start
# And then GDBserver, ready for extended-remote mode.
gdbserver_start_multi
return 0
}
# Likewise, for MI.
#
if { [info procs extended_gdbserver_mi_gdb_start] == "" } {
rename mi_gdb_start extended_gdbserver_mi_gdb_start
}
proc mi_gdb_start { args } {
# Spawn GDB.
set res [extended_gdbserver_mi_gdb_start $args]
if { $res } {
return $res
}
# And then GDBserver, ready for extended-remote mode.
mi_gdbserver_start_multi
return 0
}
# Overriden in order to set the remote exec-file whenever a file is
# loaded to gdb.
#
proc gdb_load { arg } {
global gdb_prompt
global last_loaded_file
if { $arg != "" } {
if [gdb_file_cmd $arg] then { return -1 }
}
send_gdb "set remote exec-file $last_loaded_file\n"
gdb_expect {
-re "$gdb_prompt $" {}
timeout {
perror "couldn't set the remote exec-file (timed out)."
return -1
}
}
return 0
}
# Likewise, for MI.
#
if { [info procs extended_gdbserver_mi_gdb_load] == "" } {
rename mi_gdb_load extended_gdbserver_mi_gdb_load
}
proc mi_gdb_load { arg } {
global mi_gdb_prompt
set res [extended_gdbserver_mi_gdb_load $arg]
if { $res } then { return -1 }
send_gdb "100-gdb-set remote exec-file $arg\n"
gdb_expect 10 {
-re ".*100-gdb-set remote exec-file $arg\r\n100\\\^done\r\n$mi_gdb_prompt$" {
verbose "set the remote exec-file to $arg."
}
timeout {
perror "couldn't set the remote exec-file (timed out)."
}
}
return 0
}