1 # Test Framework Driver for GDB driving a ROM monitor (via monitor.c).
2 # Copyright 1995, 1997 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 # Set gdb to target the monitor
24 proc gdb_target_monitor { exec_file } {
29 if [target_info exists gdb_protocol] {
30 set targetname "[target_info gdb_protocol]"
32 perror "No protocol specified for [target_info name].";
35 if [target_info exists baud] {
36 gdb_test "set remotebaud [target_info baud]" "" ""
38 if [target_info exists gdb_serial] {
39 set serialport "[target_info gdb_serial]";
40 } elseif [target_info exists netport] {
41 set serialport "[target_info netport]"
43 set serialport "[target_info serial]"
46 for {set j 1} {$j <= 2} {incr j} {
47 if [gdb_file_cmd $exec_file] { return -1; }
49 for {set i 1} {$i <= 3} {incr i} {
50 send_gdb "target $targetname $serialport\n"
52 -re "A program is being debugged already.*ill it.*y or n. $" {
56 -re "Couldn't establish connection to remote.*$gdb_prompt" {
57 verbose "Connection failed";
59 -re "Remote MIPS debugging.*$gdb_prompt" {
60 verbose "Set target to $targetname";
63 -re "Remote debugging using $serialport.*$gdb_prompt" {
64 verbose "Set target to $targetname";
67 -re "Remote target $targetname connected to.*$gdb_prompt" {
68 verbose "Set target to $targetname";
71 -re "Ending remote.*$gdb_prompt" { }
72 -re "Connection refused.*$gdb_prompt" {
73 verbose "Connection refused by remote target. Pausing, and trying again."
86 if { $j == 1 && ![reboot_target] } {
91 perror "Couldn't set target for $targetname, port is $serialport.";
95 proc gdb_target_exec { } {
96 gdb_test "target exec" "No exec file now." "" ".*Kill it.*y or n.*" "y"
100 # gdb_load -- load a file into the debugger.
101 # return a -1 if anything goes wrong.
103 proc gdb_load { arg } {
112 send_gdb "info files\n";
114 -re "Symbols from \"(\[^\"\]+)\"" {
115 set arg $expect_out(1,string);
118 -re "Local exec file:\[\r\n\]+\[ \t\]*`(\[^'\]+)'," {
119 set arg $expect_out(1,string);
122 -re "$gdb_prompt $" { }
126 for { set j 1; } { $j <= 2 } {incr j; } {
127 if [target_info exists gdb,use_standard_load] {
129 remote_push_conn host;
130 set state [remote_ld target $arg];
132 remote_pop_conn host;
133 if { $state == "pass" } {
134 if [gdb_target_monitor $arg] { return -1; }
135 gdb_test "list main" ".*" ""
136 verbose "Loaded $arg into $GDB\n";
141 if [gdb_target_monitor $arg] { return -1 }
143 if [is_remote host] {
144 # FIXME: Multiple downloads. bleah.
145 set farg [remote_download host $arg];
150 if { $arg != "" && [target_info exists gdb_sect_offset] } {
151 set textoff [target_info gdb_sect_offset];
152 send_gdb "sect .text $textoff\n";
154 -re "(0x\[0-9a-z]+) - 0x\[0-9a-z\]+ is \\.data" {
155 set dataoff $expect_out(1,string);
158 -re "(0x\[0-9a-z\]+) - 0x\[0-9a-z\]+ is \\.bss" {
159 set bssoff $expect_out(1,string);
162 -re "$gdb_prompt" { }
164 set dataoff [format 0x%x [expr $dataoff + $textoff]];
165 set bssoff [format 0x%x [expr $bssoff + $textoff]];
166 send_gdb "sect .data $dataoff\n";
168 -re "$gdb_prompt" { }
170 send_gdb "sect .bss $bssoff\n";
172 -re "$gdb_prompt" { }
176 verbose "Loading $farg"
177 if [target_info exists gdb_load_offset] {
178 set command "load $farg [target_info gdb_load_offset]\n";
180 set command "load $farg\n";
184 -re "\[Ff\]ailed.*$gdb_prompt $" {
185 verbose "load failed";
187 -re "Timeout reading from remote.*$gdb_prompt" {
189 -re "$gdb_prompt $" {
190 verbose "Loaded $farg into $GDB\n"
194 if { $verbose > 1 } {
195 perror "Timed out trying to load $farg."
201 # Make sure we don't have an open connection to the target.
205 if { ![reboot_target] } {
210 perror "Couldn't load file into GDB.";