1995-05-11 01:03:50 +00:00
|
|
|
|
# Test Framework Driver for GDB driving a ROM monitor (via monitor.c).
|
1997-03-06 22:32:25 +00:00
|
|
|
|
# Copyright 1995, 1997 Free Software Foundation, Inc.
|
1995-05-11 01:03:50 +00: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
|
1997-03-06 22:32:25 +00:00
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1995-05-11 01:03:50 +00:00
|
|
|
|
|
|
|
|
|
load_lib gdb.exp
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# gdb_target_monitor
|
|
|
|
|
# Set gdb to target the monitor
|
|
|
|
|
#
|
1997-06-04 00:04:43 +00:00
|
|
|
|
proc gdb_target_monitor { exec_file } {
|
1997-02-02 07:59:25 +00:00
|
|
|
|
global gdb_prompt
|
1995-05-11 01:03:50 +00:00
|
|
|
|
global exit_status
|
1997-01-29 09:40:31 +00:00
|
|
|
|
global timeout
|
1995-05-11 01:03:50 +00:00
|
|
|
|
|
|
|
|
|
set timeout 60
|
1997-01-29 09:40:31 +00:00
|
|
|
|
|
|
|
|
|
verbose "Timeout is now $timeout seconds" 2
|
|
|
|
|
if [target_info exists gdb_protocol] {
|
|
|
|
|
set targetname "[target_info gdb_protocol]"
|
|
|
|
|
} else {
|
|
|
|
|
perror "No protocol specified for [target_info name].";
|
|
|
|
|
return -1;
|
1996-05-08 04:04:25 +00:00
|
|
|
|
}
|
1997-01-29 09:40:31 +00:00
|
|
|
|
if [target_info exists baud] {
|
1997-03-01 04:50:01 +00:00
|
|
|
|
gdb_test "set remotebaud [target_info baud]" "" ""
|
1996-05-08 04:04:25 +00:00
|
|
|
|
}
|
1997-05-23 21:49:12 +00:00
|
|
|
|
if [target_info exists gdb_serial] {
|
|
|
|
|
set serialport "[target_info gdb_serial]";
|
|
|
|
|
} elseif [target_info exists netport] {
|
1997-01-29 09:40:31 +00:00
|
|
|
|
set serialport "[target_info netport]"
|
|
|
|
|
} else {
|
|
|
|
|
set serialport "[target_info serial]"
|
1996-05-08 04:04:25 +00:00
|
|
|
|
}
|
1997-01-29 09:40:31 +00:00
|
|
|
|
|
|
|
|
|
for {set j 1} {$j <= 2} {incr j} {
|
1997-06-04 00:04:43 +00:00
|
|
|
|
if [gdb_file_cmd $exec_file] { return -1; }
|
|
|
|
|
|
1997-01-29 09:40:31 +00:00
|
|
|
|
for {set i 1} {$i <= 3} {incr i} {
|
1997-06-04 00:04:43 +00:00
|
|
|
|
send_gdb "target $targetname $serialport\n"
|
1997-03-01 04:50:01 +00:00
|
|
|
|
gdb_expect {
|
|
|
|
|
-re "A program is being debugged already.*ill it.*y or n. $" {
|
|
|
|
|
send_gdb "y\n";
|
|
|
|
|
exp_continue;
|
|
|
|
|
}
|
1997-06-14 16:25:14 +00:00
|
|
|
|
-re "Couldn't establish connection to remote.*$gdb_prompt" {
|
1997-06-04 00:04:43 +00:00
|
|
|
|
verbose "Connection failed";
|
1997-03-01 04:50:01 +00:00
|
|
|
|
}
|
|
|
|
|
-re "Remote MIPS debugging.*$gdb_prompt" {
|
1997-06-04 00:04:43 +00:00
|
|
|
|
verbose "Set target to $targetname";
|
|
|
|
|
return 0;
|
1997-01-29 09:40:31 +00:00
|
|
|
|
}
|
1997-03-01 04:50:01 +00:00
|
|
|
|
-re "Remote debugging using $serialport.*$gdb_prompt" {
|
1997-06-04 00:04:43 +00:00
|
|
|
|
verbose "Set target to $targetname";
|
|
|
|
|
return 0;
|
1997-01-29 09:40:31 +00:00
|
|
|
|
}
|
1997-03-01 04:50:01 +00:00
|
|
|
|
-re "Remote target $targetname connected to.*$gdb_prompt" {
|
1997-06-04 00:04:43 +00:00
|
|
|
|
verbose "Set target to $targetname";
|
|
|
|
|
return 0;
|
1995-05-11 01:03:50 +00:00
|
|
|
|
}
|
1997-03-06 05:30:54 +00:00
|
|
|
|
-re "Ending remote.*$gdb_prompt" { }
|
1997-03-01 04:50:01 +00:00
|
|
|
|
-re "Connection refused.*$gdb_prompt" {
|
1995-05-11 01:03:50 +00:00
|
|
|
|
verbose "Connection refused by remote target. Pausing, and trying again."
|
|
|
|
|
sleep 30
|
|
|
|
|
continue
|
|
|
|
|
}
|
1997-03-01 04:50:01 +00:00
|
|
|
|
timeout {
|
|
|
|
|
send_gdb "";
|
1996-05-08 04:04:25 +00:00
|
|
|
|
break
|
1995-05-11 01:03:50 +00:00
|
|
|
|
}
|
1997-01-29 09:40:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1997-06-04 00:04:43 +00:00
|
|
|
|
|
|
|
|
|
gdb_target_exec;
|
|
|
|
|
|
1997-01-29 09:40:31 +00:00
|
|
|
|
if { $j == 1 && ![reboot_target] } {
|
|
|
|
|
break;
|
1995-05-11 01:03:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1996-05-08 04:04:25 +00:00
|
|
|
|
|
1997-06-04 00:04:43 +00:00
|
|
|
|
perror "Couldn't set target for $targetname, port is $serialport.";
|
1997-03-01 04:50:01 +00:00
|
|
|
|
return -1;
|
1995-05-11 01:03:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-05-23 21:49:12 +00:00
|
|
|
|
proc gdb_target_exec { } {
|
|
|
|
|
gdb_test "target exec" "No exec file now." "" ".*Kill it.*y or n.*" "y"
|
|
|
|
|
|
|
|
|
|
}
|
1995-05-11 01:03:50 +00:00
|
|
|
|
#
|
|
|
|
|
# gdb_load -- load a file into the debugger.
|
|
|
|
|
# return a -1 if anything goes wrong.
|
|
|
|
|
#
|
|
|
|
|
proc gdb_load { arg } {
|
|
|
|
|
global verbose
|
|
|
|
|
global loadpath
|
|
|
|
|
global loadfile
|
|
|
|
|
global GDB
|
1997-02-02 07:59:25 +00:00
|
|
|
|
global gdb_prompt
|
1997-01-29 09:40:31 +00:00
|
|
|
|
global timeout
|
1995-05-11 01:03:50 +00:00
|
|
|
|
|
1997-06-04 00:04:43 +00:00
|
|
|
|
if { $arg == "" } {
|
|
|
|
|
send_gdb "info files\n";
|
|
|
|
|
gdb_expect {
|
1997-06-14 16:25:14 +00:00
|
|
|
|
-re "Symbols from \"(\[^\"\]+)\"" {
|
1997-06-04 00:04:43 +00:00
|
|
|
|
set arg $expect_out(1,string);
|
|
|
|
|
exp_continue;
|
|
|
|
|
}
|
|
|
|
|
-re "Local exec file:\[\r\n\]+\[ \t\]*`(\[^'\]+)'," {
|
|
|
|
|
set arg $expect_out(1,string);
|
|
|
|
|
exp_continue;
|
|
|
|
|
}
|
|
|
|
|
-re "$gdb_prompt $" { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1997-03-06 05:30:54 +00:00
|
|
|
|
for { set j 1; } { $j <= 2 } {incr j; } {
|
1997-03-07 22:00:02 +00:00
|
|
|
|
if [target_info exists gdb,use_standard_load] {
|
1997-05-23 21:49:12 +00:00
|
|
|
|
gdb_target_exec;
|
1997-03-07 22:00:02 +00:00
|
|
|
|
remote_push_conn host;
|
|
|
|
|
set state [remote_ld target $arg];
|
|
|
|
|
remote_close target;
|
|
|
|
|
remote_pop_conn host;
|
1997-05-23 21:49:12 +00:00
|
|
|
|
if { $state == "pass" } {
|
1997-06-04 00:04:43 +00:00
|
|
|
|
if [gdb_target_monitor $arg] { return -1; }
|
1997-05-23 21:49:12 +00:00
|
|
|
|
gdb_test "list main" ".*" ""
|
|
|
|
|
verbose "Loaded $arg into $GDB\n";
|
1997-06-04 00:04:43 +00:00
|
|
|
|
return 0;
|
1997-03-07 22:00:02 +00:00
|
|
|
|
}
|
1997-05-23 21:49:12 +00:00
|
|
|
|
} else {
|
1997-03-06 05:30:54 +00:00
|
|
|
|
|
1997-06-04 00:04:43 +00:00
|
|
|
|
if [gdb_target_monitor $arg] { return -1 }
|
|
|
|
|
|
1997-06-14 16:25:14 +00:00
|
|
|
|
if [is_remote host] {
|
|
|
|
|
# FIXME: Multiple downloads. bleah.
|
|
|
|
|
set farg [remote_download host $arg];
|
|
|
|
|
} else {
|
|
|
|
|
set farg $arg;
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-04 00:04:43 +00:00
|
|
|
|
if { $arg != "" && [target_info exists gdb_sect_offset] } {
|
1997-05-23 21:49:12 +00:00
|
|
|
|
set textoff [target_info gdb_sect_offset];
|
|
|
|
|
send_gdb "sect .text $textoff\n";
|
|
|
|
|
gdb_expect {
|
|
|
|
|
-re "(0x\[0-9a-z]+) - 0x\[0-9a-z\]+ is \\.data" {
|
|
|
|
|
set dataoff $expect_out(1,string);
|
|
|
|
|
exp_continue;
|
|
|
|
|
}
|
|
|
|
|
-re "(0x\[0-9a-z\]+) - 0x\[0-9a-z\]+ is \\.bss" {
|
|
|
|
|
set bssoff $expect_out(1,string);
|
|
|
|
|
exp_continue;
|
|
|
|
|
}
|
|
|
|
|
-re "$gdb_prompt" { }
|
|
|
|
|
}
|
|
|
|
|
set dataoff [format 0x%x [expr $dataoff + $textoff]];
|
|
|
|
|
set bssoff [format 0x%x [expr $bssoff + $textoff]];
|
|
|
|
|
send_gdb "sect .data $dataoff\n";
|
|
|
|
|
gdb_expect {
|
|
|
|
|
-re "$gdb_prompt" { }
|
|
|
|
|
}
|
|
|
|
|
send_gdb "sect .bss $bssoff\n";
|
|
|
|
|
gdb_expect {
|
|
|
|
|
-re "$gdb_prompt" { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-14 16:25:14 +00:00
|
|
|
|
verbose "Loading $farg"
|
1997-05-23 21:49:12 +00:00
|
|
|
|
if [target_info exists gdb_load_offset] {
|
1997-06-14 16:25:14 +00:00
|
|
|
|
set command "load $farg [target_info gdb_load_offset]\n";
|
1997-05-23 21:49:12 +00:00
|
|
|
|
} else {
|
1997-06-14 16:25:14 +00:00
|
|
|
|
set command "load $farg\n";
|
1997-03-06 05:30:54 +00:00
|
|
|
|
}
|
1997-05-23 21:49:12 +00:00
|
|
|
|
send_gdb $command;
|
1997-06-14 16:25:14 +00:00
|
|
|
|
set timeout 1200
|
1997-05-23 21:49:12 +00:00
|
|
|
|
verbose "Timeout is now $timeout seconds" 2
|
|
|
|
|
gdb_expect {
|
1997-06-04 00:04:43 +00:00
|
|
|
|
-re "\[Ff\]ailed.*$gdb_prompt $" {
|
1997-05-23 21:49:12 +00:00
|
|
|
|
verbose "load failed";
|
|
|
|
|
}
|
1997-06-14 16:25:14 +00:00
|
|
|
|
-re "Timeout reading from remote.*$gdb_prompt" {
|
|
|
|
|
}
|
1997-06-04 00:04:43 +00:00
|
|
|
|
-re "$gdb_prompt $" {
|
1997-06-14 16:25:14 +00:00
|
|
|
|
verbose "Loaded $farg into $GDB\n"
|
1997-06-04 00:04:43 +00:00
|
|
|
|
return 0;
|
1997-05-23 21:49:12 +00:00
|
|
|
|
}
|
|
|
|
|
timeout {
|
|
|
|
|
if { $verbose > 1 } {
|
1997-06-14 16:25:14 +00:00
|
|
|
|
perror "Timed out trying to load $farg."
|
1997-05-23 21:49:12 +00:00
|
|
|
|
}
|
1997-03-06 05:30:54 +00:00
|
|
|
|
}
|
1995-05-11 01:03:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1997-03-06 05:30:54 +00:00
|
|
|
|
|
1997-06-04 00:04:43 +00:00
|
|
|
|
# Make sure we don't have an open connection to the target.
|
1997-05-23 21:49:12 +00:00
|
|
|
|
gdb_target_exec;
|
|
|
|
|
|
|
|
|
|
if { $j == 1 } {
|
|
|
|
|
if { ![reboot_target] } {
|
|
|
|
|
break;
|
|
|
|
|
}
|
1997-03-06 05:30:54 +00:00
|
|
|
|
}
|
1995-05-11 01:03:50 +00:00
|
|
|
|
}
|
1997-03-06 05:30:54 +00:00
|
|
|
|
perror "Couldn't load file into GDB.";
|
|
|
|
|
return -1;
|
1995-05-11 01:03:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
proc gdb_start { } {
|
1997-05-23 21:49:12 +00:00
|
|
|
|
global gdb_prompt;
|
1995-05-11 01:03:50 +00:00
|
|
|
|
|
1997-05-23 21:49:12 +00:00
|
|
|
|
if [board_info target exists gdb_prompt] {
|
|
|
|
|
set gdb_prompt [board_info target gdb_prompt];
|
|
|
|
|
}
|
|
|
|
|
|
1997-01-29 09:40:31 +00:00
|
|
|
|
catch default_gdb_start;
|
|
|
|
|
}
|