]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/config/monitor.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / config / monitor.exp
CommitLineData
c906108c 1# Test Framework Driver for GDB driving a ROM monitor (via monitor.c).
3666a048 2# Copyright 1995-2021 Free Software Foundation, Inc.
c906108c
SS
3#
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
08e706b1
MS
17#
18# gdb_target_cmd
19# Send gdb the "target" command
20#
21proc gdb_target_cmd { targetname serialport } {
22 global gdb_prompt
23
24 for {set i 1} {$i <= 3} {incr i} {
25 send_gdb "target $targetname $serialport\n"
26 gdb_expect 60 {
27 -re "A program is being debugged already.*ill it.*y or n. $" {
4ec70201
PA
28 send_gdb "y\n"
29 exp_continue
08e706b1
MS
30 }
31 -re "Couldn't establish connection to remote.*$gdb_prompt" {
4ec70201 32 verbose "Connection failed"
08e706b1
MS
33 }
34 -re "Remote MIPS debugging.*$gdb_prompt" {
4ec70201 35 verbose "Set target to $targetname"
ae59b1da 36 return 0
08e706b1
MS
37 }
38 -re "Remote debugging using .*$serialport.*$gdb_prompt" {
4ec70201 39 verbose "Set target to $targetname"
ae59b1da 40 return 0
08e706b1
MS
41 }
42 -re "Remote target $targetname connected to.*$gdb_prompt" {
4ec70201 43 verbose "Set target to $targetname"
ae59b1da 44 return 0
08e706b1
MS
45 }
46 -re "Connected to.*$gdb_prompt" {
4ec70201 47 verbose "Set target to $targetname"
ae59b1da 48 return 0
08e706b1
MS
49 }
50 -re "Ending remote.*$gdb_prompt" { }
51 -re "Connection refused.*$gdb_prompt" {
52 verbose "Connection refused by remote target. Pausing, and trying again."
53 sleep 30
54 continue
55 }
56 -re "Timeout reading from remote system.*$gdb_prompt" {
4ec70201 57 verbose "Got timeout error from gdb."
08e706b1
MS
58 }
59 timeout {
4ec70201 60 send_gdb "\ 3"
08e706b1
MS
61 break
62 }
63 }
64 }
269a569e 65 return 1
08e706b1
MS
66}
67
68
69
c906108c
SS
70#
71# gdb_target_monitor
72# Set gdb to target the monitor
73#
74proc gdb_target_monitor { exec_file } {
75 global gdb_prompt
76 global exit_status
77 global timeout
78
79 if [target_info exists gdb_protocol] {
80 set targetname "[target_info gdb_protocol]"
81 } else {
4ec70201 82 perror "No protocol specified for [target_info name]."
ae59b1da 83 return -1
c906108c
SS
84 }
85 if [target_info exists baud] {
7f3c0343 86 gdb_test "set serial baud [target_info baud]" "" ""
c906108c 87 }
7a292a7a
SS
88 if [target_info exists binarydownload] {
89 gdb_test "set remotebinarydownload [target_info binarydownload]" "" ""
90 }
c2c6d25f
JM
91 if { [ target_info exists disable_x_packet ] } {
92 gdb_test "set remote X-packet disable" ""
93 }
94 if { [ target_info exists disable_z_packet ] } {
95 gdb_test "set remote Z-packet disable" ""
96 }
c906108c 97 if [target_info exists gdb_serial] {
4ec70201 98 set serialport "[target_info gdb_serial]"
c906108c
SS
99 } elseif [target_info exists netport] {
100 set serialport "[target_info netport]"
101 } else {
102 set serialport "[target_info serial]"
103 }
104
105 for {set j 1} {$j <= 2} {incr j} {
ae59b1da 106 if [gdb_file_cmd $exec_file] { return -1 }
c906108c 107
ae59b1da 108 if ![gdb_target_cmd $targetname $serialport] { return 0 }
c906108c 109
4ec70201 110 gdb_target_exec
c906108c
SS
111
112 if { $j == 1 && ![reboot_target] } {
4ec70201 113 break
c906108c
SS
114 }
115 }
116
4ec70201 117 perror "Couldn't set target for $targetname, port is $serialport."
ae59b1da 118 return -1
c906108c
SS
119}
120
121proc gdb_target_exec { } {
122 gdb_test "target exec" "No executable file now." "" ".*Kill it.*y or n.*" "y"
123
124}
125#
126# gdb_load -- load a file into the debugger.
127# return a -1 if anything goes wrong.
128#
129proc gdb_load { arg } {
130 global verbose
131 global loadpath
132 global loadfile
133 global GDB
134 global gdb_prompt
135 global timeout
4ec70201 136 global last_gdb_file
c906108c
SS
137
138 if { $arg == "" } {
139 if [info exists last_gdb_file] {
4ec70201 140 set arg $last_gdb_file
c906108c 141 } else {
4ec70201 142 send_gdb "info files\n"
c906108c
SS
143 gdb_expect 30 {
144 -re "Symbols from \"(\[^\"\]+)\"" {
4ec70201
PA
145 set arg $expect_out(1,string)
146 exp_continue
c906108c
SS
147 }
148 -re "Local exec file:\[\r\n\]+\[ \t\]*`(\[^'\]+)'," {
4ec70201
PA
149 set arg $expect_out(1,string)
150 exp_continue
c906108c
SS
151 }
152 -re "$gdb_prompt $" { }
153 }
154 }
155 }
156
4ec70201 157 set last_gdb_file $arg
c906108c 158
13e4e967 159 for { set j 1 } { $j <= 2 } {incr j } {
c906108c 160 if [target_info exists gdb,use_standard_load] {
4ec70201 161 gdb_target_exec
c906108c 162 if ![target_info exists gdb,no_push_conn] {
4ec70201 163 remote_push_conn host
c906108c 164 }
4ec70201 165 set state [remote_ld target $arg]
c906108c 166 if ![target_info exists gdb,no_push_conn] {
4ec70201
PA
167 remote_close target
168 remote_pop_conn host
c906108c
SS
169 }
170 if { $state == "pass" } {
ae59b1da 171 if [gdb_target_monitor $arg] { return -1 }
e777225b 172 gdb_test "list -q main" ".*" ""
4ec70201 173 verbose "Loaded $arg into $GDB\n"
ae59b1da 174 return 0
c906108c
SS
175 }
176 } else {
177
178 if [gdb_target_monitor $arg] { return -1 }
179
180 if [is_remote host] {
181 # FIXME: Multiple downloads. bleah.
4ec70201 182 set farg [remote_download host $arg]
c906108c 183 } else {
4ec70201 184 set farg $arg
c906108c
SS
185 }
186
187 if { $arg != "" && [target_info exists gdb_sect_offset] } {
4ec70201
PA
188 set textoff [target_info gdb_sect_offset]
189 send_gdb "sect .text $textoff\n"
c906108c
SS
190 gdb_expect 30 {
191 -re "(0x\[0-9a-z]+) - 0x\[0-9a-z\]+ is \\.data" {
4ec70201
PA
192 set dataoff $expect_out(1,string)
193 exp_continue
c906108c
SS
194 }
195 -re "(0x\[0-9a-z\]+) - 0x\[0-9a-z\]+ is \\.bss" {
4ec70201
PA
196 set bssoff $expect_out(1,string)
197 exp_continue
c906108c
SS
198 }
199 -re "$gdb_prompt" { }
200 }
4ec70201
PA
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"
c906108c
SS
204 gdb_expect 30 {
205 -re "$gdb_prompt" { }
206 }
4ec70201 207 send_gdb "sect .bss $bssoff\n"
c906108c
SS
208 gdb_expect 30 {
209 -re "$gdb_prompt" { }
210 }
211 }
212
213 verbose "Loading $farg"
214 if [target_info exists gdb_load_offset] {
4ec70201 215 set command "load $farg [target_info gdb_load_offset]\n"
c906108c 216 } else {
4ec70201 217 set command "load $farg\n"
c906108c 218 }
f949823c
MS
219 if [target_info exists gdb_load_timeout] {
220 set loadtimeout [target_info gdb_load_timeout]
221 } else {
222 set loadtimeout 1600
223 }
224
db863c42
MF
225 if [is_remote target] {
226 set oldremotetimeout [get_remotetimeout]
227 set_remotetimeout $loadtimeout
228 }
229
230 set load_ok 0
4ec70201 231 send_gdb $command
f949823c 232 gdb_expect $loadtimeout {
c906108c 233 -re "\[Ff\]ailed.*$gdb_prompt $" {
4ec70201 234 verbose "load failed"
c906108c
SS
235 }
236 -re "Timeout reading from remote.*$gdb_prompt" {
237 }
238 -re "$gdb_prompt $" {
239 verbose "Loaded $farg into $GDB\n"
db863c42 240 set load_ok 1
c906108c
SS
241 }
242 timeout {
243 if { $verbose > 1 } {
244 perror "Timed out trying to load $farg."
245 }
246 }
247 }
db863c42
MF
248
249 if [is_remote target] {
250 set_remotetimeout $oldremotetimeout
251 }
252
253 if { $load_ok == 1 } {
ae59b1da 254 return 0
db863c42 255 }
c906108c
SS
256 }
257
258 # Make sure we don't have an open connection to the target.
4ec70201 259 gdb_target_exec
c906108c
SS
260
261 if { $j == 1 } {
262 if { ![reboot_target] } {
4ec70201 263 break
c906108c
SS
264 }
265 }
266 }
4ec70201 267 perror "Couldn't load file into GDB."
ae59b1da 268 return -1
c906108c 269}