2000-10-19 23:46:42 +02:00
|
|
|
# Test framework for GDB (remote protocol) using a "gdbserver",
|
|
|
|
# ie. a debug agent running as a native process on the same or
|
|
|
|
# a different host.
|
|
|
|
|
2002-07-19 21:40:28 +02:00
|
|
|
# Copyright 2000, 2002 Free Software Foundation, Inc.
|
2000-10-19 23:46:42 +02:00
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
# 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 2 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, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
2000-10-19 23:46:42 +02:00
|
|
|
|
|
|
|
# Please email any bugs, comments, and/or additions to this file to:
|
|
|
|
# bug-gdb@prep.ai.mit.edu
|
|
|
|
|
|
|
|
# This file was written by Michael Snyder. (msnyder@redhat.com)
|
|
|
|
|
|
|
|
#
|
|
|
|
# This module to be used for testing gdb with a "gdbserver"
|
|
|
|
# built either from libremote or from gdb/gdbserver.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Load the basic testing library, and the remote stuff.
|
|
|
|
load_lib ../config/monitor.exp
|
|
|
|
|
|
|
|
#
|
|
|
|
# To be addressed or set in your baseboard config file:
|
1999-04-16 03:35:26 +02:00
|
|
|
#
|
2000-10-19 23:46:42 +02:00
|
|
|
# set_board_info gdb_protocol "remote"
|
|
|
|
# Unles you have a gdbserver that uses a different protocol...
|
1999-04-16 03:35:26 +02:00
|
|
|
#
|
2000-10-19 23:46:42 +02:00
|
|
|
# set_board_info use_gdb_stub 1
|
|
|
|
# This tells the rest of the test suite not to do things
|
|
|
|
# like "run" which don't work well on remote targets.
|
1999-04-16 03:35:26 +02:00
|
|
|
#
|
2000-10-19 23:46:42 +02:00
|
|
|
# set_board_info gdb,do_reload_on_run 1
|
|
|
|
# Unles you have a gdbserver that can handle multiple sessions.
|
1999-04-16 03:35:26 +02:00
|
|
|
#
|
2000-10-19 23:46:42 +02:00
|
|
|
# set_board_info noargs 1
|
|
|
|
# At present there is no provision in the remote protocol
|
|
|
|
# for passing arguments. This test framework does not
|
|
|
|
# address the issue, so it's best to set this variable
|
|
|
|
# in your baseboard configuration file.
|
|
|
|
# FIXME: there's no reason why the test harness couldn't
|
|
|
|
# pass commandline args when it spawns gdbserver.
|
|
|
|
#
|
|
|
|
# set_board_info gdb,noinferiorio 1
|
|
|
|
# Neither the traditional gdbserver nor the one in libremote
|
|
|
|
# can presently capture stdout and relay it to GDB via the
|
|
|
|
# 'O' packet. This means that tests involving printf will
|
|
|
|
# fail unles you set this varibale in your baseboard
|
|
|
|
# configuration file.
|
|
|
|
#
|
|
|
|
# set_board_info gdb,no_hardware_watchpoints 1
|
|
|
|
# Unles you have a gdbserver that supports hardware watchpoints.
|
|
|
|
# FIXME: gdb should detect if the target doesn't support them,
|
|
|
|
# and fall back to using software watchpoints.
|
|
|
|
#
|
|
|
|
# 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 socketport
|
|
|
|
# Port id to use for socket connection. If not set explicitly,
|
|
|
|
# it will start at "2345" and increment for each use.
|
|
|
|
#
|
|
|
|
|
1999-04-16 03:35:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# gdb_load -- load a file into the debugger.
|
|
|
|
# return a -1 if anything goes wrong.
|
|
|
|
#
|
2000-10-19 23:46:42 +02:00
|
|
|
|
|
|
|
global server_exec;
|
|
|
|
global portnum;
|
|
|
|
set portnum "2345";
|
|
|
|
|
2002-07-19 21:40:28 +02:00
|
|
|
proc gdb_load { arg } {
|
|
|
|
global host_exec;
|
2000-10-19 23:46:42 +02:00
|
|
|
global server_exec;
|
|
|
|
global portnum;
|
2001-05-10 21:35:14 +02:00
|
|
|
global verbose;
|
|
|
|
global gdb_prompt;
|
2000-10-19 23:46:42 +02:00
|
|
|
|
|
|
|
# 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] {
|
|
|
|
set debughost [target_info sockethost];
|
|
|
|
} else {
|
|
|
|
set debughost "localhost:";
|
|
|
|
}
|
|
|
|
# Extract the protocol
|
|
|
|
if [target_info exists gdb_protocol] {
|
|
|
|
set protocol [target_info gdb_protocol];
|
|
|
|
} else {
|
|
|
|
set protocol "remote";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Extract the name of the gdbserver, if known (default 'gdbserver').
|
1999-04-16 03:35:26 +02:00
|
|
|
if [target_info exists gdb_server_prog] {
|
|
|
|
set gdbserver [target_info gdb_server_prog];
|
|
|
|
} else {
|
|
|
|
set gdbserver "gdbserver";
|
|
|
|
}
|
2000-10-19 23:46:42 +02:00
|
|
|
# Extract the socket hostname
|
|
|
|
if [target_info exists sockethost] {
|
|
|
|
set sockethost [target_info sockethost];
|
|
|
|
} else {
|
|
|
|
set sockethost ""
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
|
|
|
|
2000-10-19 23:46:42 +02:00
|
|
|
# Export the host:port pair.
|
|
|
|
set gdbport $debughost$portnum;
|
1999-04-16 03:35:26 +02:00
|
|
|
|
2002-07-19 21:40:28 +02:00
|
|
|
# Remember new exec file.
|
|
|
|
if { $arg == "" } {
|
|
|
|
if { ! [info exists host_exec] } {
|
2000-10-19 23:46:42 +02:00
|
|
|
send_gdb "info files\n";
|
|
|
|
gdb_expect 30 {
|
|
|
|
-re "Symbols from \"(\[^\"\]+)\"" {
|
2002-07-19 21:40:28 +02:00
|
|
|
set host_exec $expect_out(1,string);
|
2000-10-19 23:46:42 +02:00
|
|
|
exp_continue;
|
|
|
|
}
|
|
|
|
-re "Local exec file:\[\r\n\]+\[ \t\]*`(\[^'\]+)'," {
|
2002-07-19 21:40:28 +02:00
|
|
|
set host_exec $expect_out(1,string);
|
2000-10-19 23:46:42 +02:00
|
|
|
exp_continue;
|
|
|
|
}
|
|
|
|
-re "$gdb_prompt $" { }
|
|
|
|
}
|
|
|
|
}
|
2002-07-19 21:40:28 +02:00
|
|
|
} else {
|
|
|
|
set host_exec $arg
|
|
|
|
if [info exists server_exec] { unset server_exec }
|
2000-10-19 23:46:42 +02:00
|
|
|
}
|
|
|
|
|
2002-07-19 21:40:28 +02:00
|
|
|
if { ! [info exists server_exec] } {
|
|
|
|
if [is_remote target] {
|
|
|
|
set server_exec [remote_download target $host_exec]
|
|
|
|
} else {
|
|
|
|
set server_exec $host_exec
|
|
|
|
}
|
|
|
|
}
|
2000-10-19 23:46:42 +02:00
|
|
|
|
|
|
|
# Fire off the debug agent
|
2001-05-10 21:35:14 +02:00
|
|
|
if [target_info exists gdb_server_args] {
|
|
|
|
# This flavour of gdbserver takes as arguments those specified
|
|
|
|
# in the board configuration file
|
|
|
|
set custom_args [target_info gdb_server_args];
|
2002-07-19 21:40:28 +02:00
|
|
|
set server_spawn_id [remote_spawn target \
|
|
|
|
"$gdbserver $custom_args"]
|
2001-05-10 21:35:14 +02:00
|
|
|
} else {
|
|
|
|
# This flavour of gdbserver takes as arguments the port information
|
|
|
|
# and the name of the executable file to be debugged.
|
2002-07-19 21:40:28 +02:00
|
|
|
set server_spawn_id [remote_spawn target \
|
|
|
|
"$gdbserver $sockethost$portnum $server_exec"]
|
2001-05-10 21:35:14 +02:00
|
|
|
}
|
2002-07-19 21:40:28 +02:00
|
|
|
|
|
|
|
# We can't call close, because if gdbserver is local then that means
|
|
|
|
# that it will get a SIGHUP.
|
|
|
|
## close -i $server_spawn_id
|
|
|
|
wait -nowait -i $server_spawn_id
|
|
|
|
|
2000-10-19 23:46:42 +02:00
|
|
|
# Give it a little time to establish
|
2002-07-19 21:40:28 +02:00
|
|
|
sleep 1
|
2000-10-19 23:46:42 +02:00
|
|
|
|
|
|
|
# tell gdb what file we are debugging
|
2002-07-19 21:40:28 +02:00
|
|
|
if { $arg != "" } {
|
|
|
|
if [gdb_file_cmd $arg] {
|
|
|
|
return -1;
|
|
|
|
}
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|
2000-10-19 23:46:42 +02:00
|
|
|
|
|
|
|
# attach to the "serial port"
|
|
|
|
gdb_target_cmd $protocol $gdbport;
|
|
|
|
|
2001-05-10 21:35:14 +02:00
|
|
|
# do the real load if needed
|
|
|
|
if [target_info exists gdb_server_do_load] {
|
|
|
|
send_gdb "load\n"
|
|
|
|
set timeout 2400
|
|
|
|
verbose "Timeout is now $timeout seconds" 2
|
|
|
|
gdb_expect {
|
|
|
|
-re ".*$gdb_prompt $" {
|
|
|
|
if $verbose>1 then {
|
|
|
|
send_user "Loaded $arg into $GDB\n"
|
|
|
|
}
|
|
|
|
set timeout 30
|
|
|
|
verbose "Timeout is now $timeout seconds" 2
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
-re "$gdb_prompt $" {
|
|
|
|
if $verbose>1 then {
|
|
|
|
perror "GDB couldn't load."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
timeout {
|
|
|
|
if $verbose>1 then {
|
|
|
|
perror "Timed out trying to load $arg."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-19 23:46:42 +02:00
|
|
|
return 0;
|
1999-04-16 03:35:26 +02:00
|
|
|
}
|