1 # Test Framework Driver for GDB driving a ROM monitor (via monitor.c).
2 # Copyright 1995-2022 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 3 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, see <http://www.gnu.org/licenses/>.
19 # Send gdb the "target" command
21 proc gdb_target_cmd { targetname serialport } {
24 for {set i 1} {$i <= 3} {incr i} {
25 send_gdb "target $targetname $serialport\n"
27 -re "A program is being debugged already.*ill it.*y or n. $" {
31 -re "Couldn't establish connection to remote.*$gdb_prompt" {
32 verbose "Connection failed"
34 -re "Remote MIPS debugging.*$gdb_prompt" {
35 verbose "Set target to $targetname"
38 -re "Remote debugging using .*$serialport.*$gdb_prompt" {
39 verbose "Set target to $targetname"
42 -re "Remote target $targetname connected to.*$gdb_prompt" {
43 verbose "Set target to $targetname"
46 -re "Connected to.*$gdb_prompt" {
47 verbose "Set target to $targetname"
50 -re "Ending remote.*$gdb_prompt" { }
51 -re "Connection refused.*$gdb_prompt" {
52 verbose "Connection refused by remote target. Pausing, and trying again."
56 -re "Timeout reading from remote system.*$gdb_prompt" {
57 verbose "Got timeout error from gdb."
72 # Set gdb to target the monitor
74 proc gdb_target_monitor { exec_file } {
79 if [target_info exists gdb_protocol] {
80 set targetname "[target_info gdb_protocol]"
82 perror "No protocol specified for [target_info name]."
85 if [target_info exists baud] {
86 gdb_test "set serial baud [target_info baud]" "" ""
88 if [target_info exists binarydownload] {
89 gdb_test "set remotebinarydownload [target_info binarydownload]" "" ""
91 if { [ target_info exists disable_x_packet ] } {
92 gdb_test "set remote X-packet disable" ""
94 if { [ target_info exists disable_z_packet ] } {
95 gdb_test "set remote Z-packet disable" ""
97 if [target_info exists gdb_serial] {
98 set serialport "[target_info gdb_serial]"
99 } elseif [target_info exists netport] {
100 set serialport "[target_info netport]"
102 set serialport "[target_info serial]"
105 for {set j 1} {$j <= 2} {incr j} {
106 if [gdb_file_cmd $exec_file] { return -1 }
108 if ![gdb_target_cmd $targetname $serialport] { return 0 }
112 if { $j == 1 && ![reboot_target] } {
117 perror "Couldn't set target for $targetname, port is $serialport."
121 proc gdb_target_exec { } {
122 gdb_test "target exec" "No executable file now." "" ".*Kill it.*y or n.*" "y"
126 # gdb_load -- load a file into the debugger.
127 # return a -1 if anything goes wrong.
129 proc gdb_load { arg } {
139 if [info exists last_gdb_file] {
140 set arg $last_gdb_file
142 send_gdb "info files\n"
144 -re "Symbols from \"(\[^\"\]+)\"" {
145 set arg $expect_out(1,string)
148 -re "Local exec file:\[\r\n\]+\[ \t\]*`(\[^'\]+)'," {
149 set arg $expect_out(1,string)
152 -re "$gdb_prompt $" { }
157 set last_gdb_file $arg
159 for { set j 1 } { $j <= 2 } {incr j } {
160 if [target_info exists gdb,use_standard_load] {
162 if ![target_info exists gdb,no_push_conn] {
163 remote_push_conn host
165 set state [remote_ld target $arg]
166 if ![target_info exists gdb,no_push_conn] {
170 if { $state == "pass" } {
171 if [gdb_target_monitor $arg] { return -1 }
172 gdb_test "list -q main" ".*" ""
173 verbose "Loaded $arg into $GDB\n"
178 if [gdb_target_monitor $arg] { return -1 }
180 if [is_remote host] {
181 # FIXME: Multiple downloads. bleah.
182 set farg [remote_download host $arg]
187 if { $arg != "" && [target_info exists gdb_sect_offset] } {
188 set textoff [target_info gdb_sect_offset]
189 send_gdb "sect .text $textoff\n"
191 -re "(0x\[0-9a-z]+) - 0x\[0-9a-z\]+ is \\.data" {
192 set dataoff $expect_out(1,string)
195 -re "(0x\[0-9a-z\]+) - 0x\[0-9a-z\]+ is \\.bss" {
196 set bssoff $expect_out(1,string)
199 -re "$gdb_prompt" { }
201 set dataoff [format 0x%x [expr $dataoff + $textoff]]
202 set bssoff [format 0x%x [expr $bssoff + $textoff]]
203 send_gdb "sect .data $dataoff\n"
205 -re "$gdb_prompt" { }
207 send_gdb "sect .bss $bssoff\n"
209 -re "$gdb_prompt" { }
213 verbose "Loading $farg"
214 if [target_info exists gdb_load_offset] {
215 set command "load $farg [target_info gdb_load_offset]\n"
217 set command "load $farg\n"
219 if [target_info exists gdb_load_timeout] {
220 set loadtimeout [target_info gdb_load_timeout]
225 if [is_remote target] {
226 set oldremotetimeout [get_remotetimeout]
227 set_remotetimeout $loadtimeout
232 gdb_expect $loadtimeout {
233 -re "\[Ff\]ailed.*$gdb_prompt $" {
234 verbose "load failed"
236 -re "Timeout reading from remote.*$gdb_prompt" {
238 -re "$gdb_prompt $" {
239 verbose "Loaded $farg into $GDB\n"
243 if { $verbose > 1 } {
244 perror "Timed out trying to load $farg."
249 if [is_remote target] {
250 set_remotetimeout $oldremotetimeout
253 if { $load_ok == 1 } {
258 # Make sure we don't have an open connection to the target.
262 if { ![reboot_target] } {
267 perror "Couldn't load file into GDB."