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