36 |
} |
} |
37 |
|
|
38 |
if [board_info $dest exists gdb_prompt] { |
if [board_info $dest exists gdb_prompt] { |
39 |
set gdb_prompt [board_info $dest gdb_prompt]; |
set gdb_prompt [board_info $dest gdb_prompt] |
40 |
} else { |
} else { |
41 |
set gdb_prompt "\\(gdb\\)" |
set gdb_prompt "\\(gdb\\)" |
42 |
} |
} |
43 |
|
|
44 |
return 1; |
return 1 |
45 |
} |
} |
46 |
|
|
47 |
proc gdb_stub_restart { dest } { |
proc gdb_stub_restart { dest } { |
48 |
global gdb_prompt |
global gdb_prompt |
49 |
global GDB |
global GDB |
50 |
|
|
51 |
gdb_stub_init $dest; |
gdb_stub_init $dest |
52 |
|
|
53 |
for {set x 1;} { $x < 4 } {incr x} { |
for {set x 1;} { $x < 4 } {incr x} { |
54 |
remote_close $dest; |
remote_close $dest |
55 |
sleep 2; |
sleep 2 |
56 |
set command "$GDB -nw -nx"; |
set command "$GDB -nw -nx" |
57 |
if [host_info exists gdb_opts] { |
if [host_info exists gdb_opts] { |
58 |
append command " [host_info gdb_opts]"; |
append command " [host_info gdb_opts]" |
59 |
} |
} |
60 |
set spawn_id [remote_spawn host $command]; |
set spawn_id [remote_spawn host $command] |
61 |
remote_expect host 30 { |
remote_expect host 30 { |
62 |
-re "$gdb_prompt" { } |
-re "$gdb_prompt" { } |
63 |
} |
} |
64 |
if { $spawn_id >= 0 } { |
if { $spawn_id >= 0 } { |
65 |
if [board_info $dest exists baud] { |
if [board_info $dest exists baud] { |
66 |
remote_send host "set remotebaud [board_info $dest baud]\n"; |
remote_send host "set remotebaud [board_info $dest baud]\n" |
67 |
remote_expect host 5 { |
remote_expect host 5 { |
68 |
-re "$gdb_prompt" { } |
-re "$gdb_prompt" { } |
69 |
default { |
default { |
70 |
warning "Error setting baud rate." |
warning "Error setting baud rate." |
71 |
return -1; |
return -1 |
72 |
} |
} |
73 |
} |
} |
74 |
} |
} |
75 |
|
|
76 |
|
|
77 |
set value [gdb_stub_startup $dest]; |
set value [gdb_stub_startup $dest] |
78 |
if { $value > 0 } { |
if { $value > 0 } { |
79 |
break; |
break |
80 |
} |
} |
81 |
verbose "got $value from gdb_stub_startup"; |
verbose "got $value from gdb_stub_startup" |
82 |
remote_send host "quit\n"; |
remote_send host "quit\n" |
83 |
} |
} |
84 |
remote_reboot $dest; |
remote_reboot $dest |
85 |
} |
} |
86 |
if { ${x} < 4 } { |
if { ${x} < 4 } { |
87 |
global board_info; |
global board_info |
88 |
set name [board_info $dest name]; |
set name [board_info $dest name] |
89 |
|
|
90 |
set board_info($name,gdb_is_running) 1; |
set board_info($name,gdb_is_running) 1 |
91 |
return 1; |
return 1 |
92 |
} else { |
} else { |
93 |
return 0; |
return 0 |
94 |
} |
} |
95 |
} |
} |
96 |
|
|
98 |
global gdb_prompt |
global gdb_prompt |
99 |
|
|
100 |
if [board_info $dest exists gdb_serial] { |
if [board_info $dest exists gdb_serial] { |
101 |
set serial [board_info $dest gdb_serial]; |
set serial [board_info $dest gdb_serial] |
102 |
} elseif [board_info $dest exists serial] { |
} elseif [board_info $dest exists serial] { |
103 |
set serial [board_info $dest serial]; |
set serial [board_info $dest serial] |
104 |
} else { |
} else { |
105 |
set serial [board_info $dest netport]; |
set serial [board_info $dest netport] |
106 |
} |
} |
107 |
remote_send host "target remote $serial\n"; |
remote_send host "target remote $serial\n" |
108 |
remote_expect host 10 { |
remote_expect host 10 { |
109 |
-re "Couldn't establish connection.*$gdb_prompt" { |
-re "Couldn't establish connection.*$gdb_prompt" { |
110 |
return 0; |
return 0 |
111 |
} |
} |
112 |
-re "Remote debugging.*$gdb_prompt" { |
-re "Remote debugging.*$gdb_prompt" { |
113 |
verbose "stub is already running" |
verbose "stub is already running" |
114 |
return 1; |
return 1 |
115 |
} |
} |
116 |
-re "$gdb_prompt" { |
-re "$gdb_prompt" { |
117 |
return 0; |
return 0 |
118 |
} |
} |
119 |
timeout { |
timeout { |
120 |
remote_send host "\003"; |
remote_send host "\003" |
121 |
remote_expect host 10 { |
remote_expect host 10 { |
122 |
-re "$gdb_prompt" { } |
-re "$gdb_prompt" { } |
123 |
} |
} |
124 |
return 0; |
return 0 |
125 |
} |
} |
126 |
default { |
default { |
127 |
return 0; |
return 0 |
128 |
} |
} |
129 |
} |
} |
130 |
} |
} |
133 |
global gdb_prompt |
global gdb_prompt |
134 |
global GDB |
global GDB |
135 |
|
|
136 |
set is_running_stub 0; |
set is_running_stub 0 |
137 |
|
|
138 |
if [gdb_stub_remote_check $dest] { |
if [gdb_stub_remote_check $dest] { |
139 |
set is_running_stub 1; |
set is_running_stub 1 |
140 |
} |
} |
141 |
|
|
142 |
if [board_info $dest exists serial] { |
if [board_info $dest exists serial] { |
143 |
set serial [board_info $dest serial]; |
set serial [board_info $dest serial] |
144 |
} else { |
} else { |
145 |
set serial [board_info $dest netport]; |
set serial [board_info $dest netport] |
146 |
} |
} |
147 |
|
|
148 |
if { ! $is_running_stub } { |
if { ! $is_running_stub } { |
149 |
set command "target [board_info $dest gdb_protocol] $serial\n"; |
set command "target [board_info $dest gdb_protocol] $serial\n" |
150 |
remote_send host $command; |
remote_send host $command |
151 |
remote_expect host 5 { |
remote_expect host 5 { |
152 |
-re "already.*y or n." { |
-re "already.*y or n." { |
153 |
remote_send host "y\n"; |
remote_send host "y\n" |
154 |
exp_continue; |
exp_continue |
155 |
} |
} |
156 |
-re "appears to be alive.*$gdb_prompt" { } |
-re "appears to be alive.*$gdb_prompt" { } |
157 |
-re "Remote target.*connected to.*$gdb_prompt" { } |
-re "Remote target.*connected to.*$gdb_prompt" { } |
158 |
default { |
default { |
159 |
return -1; |
return -1 |
160 |
} |
} |
161 |
} |
} |
162 |
} |
} |
163 |
if { $is_running_stub == 0 } { |
if { $is_running_stub == 0 } { |
164 |
global libdir |
global libdir |
165 |
|
|
166 |
verbose "building loader"; |
verbose "building loader" |
167 |
set loader "loader"; |
set loader "loader" |
168 |
if ![file exists $loader] { |
if ![file exists $loader] { |
169 |
if [board_info $dest exists gdb_stub_offset] { |
if [board_info $dest exists gdb_stub_offset] { |
170 |
set result [target_compile "${libdir}/stub-loader.c" $loader executable "libs=-Wl,-Ttext,[board_info $dest gdb_stub_offset]"]; |
set result [target_compile "${libdir}/stub-loader.c" $loader executable "libs=-Wl,-Ttext,[board_info $dest gdb_stub_offset]"] |
171 |
} else { |
} else { |
172 |
set result [target_compile "${libdir}/stub-loader.c" $loader executable "ldscript=[board_info $dest gdb_stub_ldscript]"]; |
set result [target_compile "${libdir}/stub-loader.c" $loader executable "ldscript=[board_info $dest gdb_stub_ldscript]"] |
173 |
} |
} |
174 |
verbose "result is $result"; |
verbose "result is $result" |
175 |
if [is_remote host] { |
if [is_remote host] { |
176 |
set loader [remote_download host $loader]; |
set loader [remote_download host $loader] |
177 |
} |
} |
178 |
} |
} |
179 |
remote_send host "file $loader\n"; |
remote_send host "file $loader\n" |
180 |
remote_expect host 20 { |
remote_expect host 20 { |
181 |
-re "A program is being debug.*Kill it.*y or n. $" { |
-re "A program is being debug.*Kill it.*y or n. $" { |
182 |
remote_send host "y\n" |
remote_send host "y\n" |
189 |
-re "Reading symbols from.*done..*$gdb_prompt $" {} |
-re "Reading symbols from.*done..*$gdb_prompt $" {} |
190 |
-re "$gdb_prompt $" { warning "GDB couldn't find loader" } |
-re "$gdb_prompt $" { warning "GDB couldn't find loader" } |
191 |
timeout { |
timeout { |
192 |
warning "(timeout) read symbol file" ; |
warning "(timeout) read symbol file" |
193 |
return -1 |
return -1 |
194 |
} |
} |
195 |
} |
} |
196 |
|
|
197 |
if [board_info $dest exists serial] { |
if [board_info $dest exists serial] { |
198 |
set serial [board_info $dest serial]; |
set serial [board_info $dest serial] |
199 |
} else { |
} else { |
200 |
set serial [board_info $dest netport]; |
set serial [board_info $dest netport] |
201 |
} |
} |
202 |
remote_send host "target [board_info $dest gdb_protocol] $serial\n"; |
remote_send host "target [board_info $dest gdb_protocol] $serial\n" |
203 |
remote_expect host 60 { |
remote_expect host 60 { |
204 |
-re "appears to be alive.*$gdb_prompt" { } |
-re "appears to be alive.*$gdb_prompt" { } |
205 |
-re "Remote target.*connected to.*$gdb_prompt" { } |
-re "Remote target.*connected to.*$gdb_prompt" { } |
206 |
-re "$gdb_prompt" { |
-re "$gdb_prompt" { |
207 |
warning "Error reconnecting to stub."; |
warning "Error reconnecting to stub." |
208 |
return -1; |
return -1 |
209 |
} |
} |
210 |
default { |
default { |
211 |
warning "Error reconnecting to stub."; |
warning "Error reconnecting to stub." |
212 |
return -1; |
return -1 |
213 |
} |
} |
214 |
} |
} |
215 |
|
|
218 |
if [board_info $dest exists gdb_load_offset] { |
if [board_info $dest exists gdb_load_offset] { |
219 |
remote_send host "load $loader [board_info $dest gdb_stub_offset]\n" |
remote_send host "load $loader [board_info $dest gdb_stub_offset]\n" |
220 |
} else { |
} else { |
221 |
remote_send host "load $loader\n"; |
remote_send host "load $loader\n" |
222 |
} |
} |
223 |
verbose "Loading $loader into $GDB" 2 |
verbose "Loading $loader into $GDB" 2 |
224 |
global verbose |
global verbose |
225 |
set no_run_command 0; |
set no_run_command 0 |
226 |
# FIXME: The value 1200 below should be a parameter. |
# FIXME: The value 1200 below should be a parameter. |
227 |
remote_expect host 1200 { |
remote_expect host 1200 { |
228 |
-re "Transfer rate:.*Switching to remote protocol.*Remote debugging" { |
-re "Transfer rate:.*Switching to remote protocol.*Remote debugging" { |
229 |
set no_run_command 1; |
set no_run_command 1 |
230 |
remote_send host ""; |
remote_send host "" |
231 |
sleep 2; |
sleep 2 |
232 |
remote_send host ""; |
remote_send host "" |
233 |
sleep 1; |
sleep 1 |
234 |
} |
} |
235 |
-re "Loading.*Starting.*at.*$gdb_prompt $" { |
-re "Loading.*Starting.*at.*$gdb_prompt $" { |
236 |
verbose "Loaded $loader into $GDB" 1 |
verbose "Loaded $loader into $GDB" 1 |
237 |
set no_run_command 1; |
set no_run_command 1 |
238 |
} |
} |
239 |
-re "Loading.*$gdb_prompt $" { |
-re "Loading.*$gdb_prompt $" { |
240 |
verbose "Loaded $loader into $GDB" 1 |
verbose "Loaded $loader into $GDB" 1 |
252 |
} |
} |
253 |
|
|
254 |
if { ! $no_run_command } { |
if { ! $no_run_command } { |
255 |
remote_send host "run\n"; |
remote_send host "run\n" |
256 |
remote_expect host 60 { |
remote_expect host 60 { |
257 |
-re "A program is being debug.*Kill it.*y or n. $" { |
-re "A program is being debug.*Kill it.*y or n. $" { |
258 |
remote_send host "y\n" |
remote_send host "y\n" |
263 |
exp_continue |
exp_continue |
264 |
} |
} |
265 |
-re "Starting program:.*loader.*$" { |
-re "Starting program:.*loader.*$" { |
266 |
verbose "Starting loader succeeded" |
verbose "Starting loader succeeded" |
267 |
} |
} |
268 |
timeout { |
timeout { |
269 |
warning "(timeout) starting the loader" ; |
warning "(timeout) starting the loader" |
270 |
return -1 |
return -1 |
271 |
} |
} |
272 |
default { |
default { |
273 |
warning "error starting the loader"; |
warning "error starting the loader" |
274 |
} |
} |
275 |
} |
} |
276 |
sleep 2; |
sleep 2 |
277 |
remote_send host "" |
remote_send host "" |
278 |
sleep 1; |
sleep 1 |
279 |
remote_send host "" |
remote_send host "" |
280 |
verbose "Sent ^C^C" |
verbose "Sent ^C^C" |
281 |
remote_expect host 30 { |
remote_expect host 30 { |
284 |
exp_continue |
exp_continue |
285 |
} |
} |
286 |
-re "$gdb_prompt $" { |
-re "$gdb_prompt $" { |
287 |
verbose "Running loader succeeded" |
verbose "Running loader succeeded" |
288 |
} |
} |
289 |
timeout { |
timeout { |
290 |
warning "(timeout) interrupting the loader" ; |
warning "(timeout) interrupting the loader" |
291 |
return -1 |
return -1 |
292 |
} |
} |
293 |
default { |
default { |
294 |
warning "error interrupting the loader"; |
warning "error interrupting the loader" |
295 |
} |
} |
296 |
} |
} |
297 |
} |
} |
298 |
remote_send host "quit\n"; |
remote_send host "quit\n" |
299 |
return [gdb_stub_restart $dest]; |
return [gdb_stub_restart $dest] |
300 |
} |
} |
301 |
return 1; |
return 1 |
302 |
} |
} |
303 |
|
|
304 |
# |
# |
323 |
-re "$gdb_prompt $" { warning "breakpoints not deleted" ; return -1} |
-re "$gdb_prompt $" { warning "breakpoints not deleted" ; return -1} |
324 |
timeout { warning "info breakpoints (timeout)" ; return -1} |
timeout { warning "info breakpoints (timeout)" ; return -1} |
325 |
} |
} |
326 |
return 0; |
return 0 |
327 |
} |
} |
328 |
|
|
329 |
proc gdb_stub_go_idle { dest } { |
proc gdb_stub_go_idle { dest } { |
345 |
} |
} |
346 |
|
|
347 |
proc gdb_stub_start { dest } { |
proc gdb_stub_start { dest } { |
348 |
global gdb_prompt; |
global gdb_prompt |
349 |
|
|
350 |
set exit_brnum [gdb_stub_add_breakpoint _exit]; |
set exit_brnum [gdb_stub_add_breakpoint _exit] |
351 |
if { $exit_brnum == "undef" || [board_info $dest exists always_break_exit] } { |
if { $exit_brnum == "undef" || [board_info $dest exists always_break_exit] } { |
352 |
set exit_brnum [gdb_stub_add_breakpoint exit]; |
set exit_brnum [gdb_stub_add_breakpoint exit] |
353 |
} |
} |
354 |
set abort_brnum [gdb_stub_add_breakpoint abort]; |
set abort_brnum [gdb_stub_add_breakpoint abort] |
355 |
|
|
356 |
upvar #0 gdb_stub_info I |
upvar #0 gdb_stub_info I |
357 |
set I($dest,exit_brnum) $exit_brnum |
set I($dest,exit_brnum) $exit_brnum |
358 |
set I($dest,abort_brnum) $abort_brnum |
set I($dest,abort_brnum) $abort_brnum |
359 |
|
|
360 |
remote_send host "set \$fp=0\n"; |
remote_send host "set \$fp=0\n" |
361 |
remote_expect host 10 { |
remote_expect host 10 { |
362 |
-re "$gdb_prompt" { } |
-re "$gdb_prompt" { } |
363 |
} |
} |
364 |
# This is needed for the SparcLite. Whee. |
# This is needed for the SparcLite. Whee. |
365 |
if [board_info $dest exists gdb,start_symbol] { |
if [board_info $dest exists gdb,start_symbol] { |
366 |
set start_comm "jump *[board_info $dest gdb,start_symbol]\n"; |
set start_comm "jump *[board_info $dest gdb,start_symbol]\n" |
367 |
} else { |
} else { |
368 |
set start_comm "jump *start\n"; |
set start_comm "jump *start\n" |
369 |
} |
} |
370 |
remote_send host "break copyloop\n"; |
remote_send host "break copyloop\n" |
371 |
remote_expect host 10 { |
remote_expect host 10 { |
372 |
-re "Breakpoint.*$gdb_prompt $" { |
-re "Breakpoint.*$gdb_prompt $" { |
373 |
set start_comm "continue\n"; |
set start_comm "continue\n" |
374 |
} |
} |
375 |
-re "Function.*not defined.*$gdb_prompt $" { } |
-re "Function.*not defined.*$gdb_prompt $" { } |
376 |
default { } |
default { } |
377 |
} |
} |
378 |
remote_send host $start_comm; |
remote_send host $start_comm |
379 |
remote_expect host 10 { |
remote_expect host 10 { |
380 |
-re "y or n. $" { |
-re "y or n. $" { |
381 |
remote_send host "y\n" |
remote_send host "y\n" |
382 |
exp_continue; |
exp_continue |
383 |
} |
} |
384 |
-re "Breakpoint.*in copyloop.*$gdb_prompt $" { |
-re "Breakpoint.*in copyloop.*$gdb_prompt $" { |
385 |
remote_send host "jump relocd\n"; |
remote_send host "jump relocd\n" |
386 |
exp_continue; |
exp_continue |
387 |
} |
} |
388 |
-re "Continuing at.*\[\r\n\]" { } |
-re "Continuing at.*\[\r\n\]" { } |
389 |
default { |
default { |
390 |
return { "fail" "" }; |
return { "fail" "" } |
391 |
} |
} |
392 |
} |
} |
393 |
return { "pass" "" }; |
return { "pass" "" } |
394 |
} |
} |
395 |
|
|
396 |
proc gdb_stub_spawn { dest prog args } { |
proc gdb_stub_spawn { dest prog args } { |
397 |
for { set x 0; } { $x < 3 } { incr x } { |
for { set x 0; } { $x < 3 } { incr x } { |
398 |
if { [remote_ld $dest $prog] != 1 } { |
if { [remote_ld $dest $prog] != 1 } { |
399 |
return [list "fail" "remote_ld failed"]; |
return [list "fail" "remote_ld failed"] |
400 |
} |
} |
401 |
|
|
402 |
set result [gdb_stub_start $dest]; |
set result [gdb_stub_start $dest] |
403 |
if { [lindex $result 0] != "pass" } { |
if { [lindex $result 0] != "pass" } { |
404 |
remote_reboot target; |
remote_reboot target |
405 |
} else { |
} else { |
406 |
return 666; # does anyone use this value? |
return 666; # does anyone use this value? |
407 |
} |
} |
408 |
} |
} |
409 |
return -1; |
return -1 |
410 |
} |
} |
411 |
|
|
412 |
proc gdb_stub_wait { dest timeout } { |
proc gdb_stub_wait { dest timeout } { |
420 |
remote_expect host $timeout { |
remote_expect host $timeout { |
421 |
-re "Breakpoint.*exit.*=0.*$gdb_prompt $" { |
-re "Breakpoint.*exit.*=0.*$gdb_prompt $" { |
422 |
gdb_stub_go_idle $dest |
gdb_stub_go_idle $dest |
423 |
return [list 0 ""]; |
return [list 0 ""] |
424 |
} |
} |
425 |
-re "Breakpoint.*exit.*=\[1-9\]\[0-9\]*.*$gdb_prompt $" { |
-re "Breakpoint.*exit.*=\[1-9\]\[0-9\]*.*$gdb_prompt $" { |
426 |
gdb_stub_go_idle $dest |
gdb_stub_go_idle $dest |
427 |
return [list 0 ""]; |
return [list 0 ""] |
428 |
} |
} |
429 |
-re "Breakpoint.*exit.*$gdb_prompt $" { |
-re "Breakpoint.*exit.*$gdb_prompt $" { |
430 |
gdb_stub_go_idle $dest |
gdb_stub_go_idle $dest |
431 |
return [list 0 ""]; |
return [list 0 ""] |
432 |
} |
} |
433 |
-re "Breakpoint.*abort.*$gdb_prompt $" { |
-re "Breakpoint.*abort.*$gdb_prompt $" { |
434 |
gdb_stub_go_idle $dest |
gdb_stub_go_idle $dest |
435 |
return [list 1 ""]; |
return [list 1 ""] |
436 |
} |
} |
437 |
-re " EXIT code 0.*$gdb_prompt $" { |
-re " EXIT code 0.*$gdb_prompt $" { |
438 |
gdb_stub_go_idle $dest; |
gdb_stub_go_idle $dest |
439 |
return [list 0 ""]; |
return [list 0 ""] |
440 |
} |
} |
441 |
-re " EXIT code \[1-9]\[0-9]*.*$gdb_prompt $" { |
-re " EXIT code \[1-9]\[0-9]*.*$gdb_prompt $" { |
442 |
gdb_stub_go_idle $dest; |
gdb_stub_go_idle $dest |
443 |
return [list 0 ""]; |
return [list 0 ""] |
444 |
} |
} |
445 |
-re " EXIT code 4242.*$gdb_prompt $" { |
-re " EXIT code 4242.*$gdb_prompt $" { |
446 |
gdb_stub_go_idle $dest; |
gdb_stub_go_idle $dest |
447 |
return [list 1 ""]; |
return [list 1 ""] |
448 |
} |
} |
449 |
-re "Program received.*$gdb_prompt $" { |
-re "Program received.*$gdb_prompt $" { |
450 |
gdb_stub_go_idle $dest |
gdb_stub_go_idle $dest |
451 |
return [list 1 ""]; |
return [list 1 ""] |
452 |
} |
} |
453 |
-re "Program exited.*$gdb_prompt $" { |
-re "Program exited.*$gdb_prompt $" { |
454 |
gdb_stub_go_idle $dest |
gdb_stub_go_idle $dest |
455 |
return [list 1 ""]; |
return [list 1 ""] |
456 |
} |
} |
457 |
-re "Breakpoint $exit_brnum.*$gdb_prompt $" { |
-re "Breakpoint $exit_brnum.*$gdb_prompt $" { |
458 |
gdb_stub_go_idle $dest; |
gdb_stub_go_idle $dest |
459 |
return [list 0 ""]; |
return [list 0 ""] |
460 |
} |
} |
461 |
-re "Breakpoint $abort_brnum.*$gdb_prompt $" { |
-re "Breakpoint $abort_brnum.*$gdb_prompt $" { |
462 |
gdb_stub_go_idle $dest; |
gdb_stub_go_idle $dest |
463 |
return [list 1 ""]; |
return [list 1 ""] |
464 |
} |
} |
465 |
default { |
default { |
466 |
remote_close $dest; |
remote_close $dest |
467 |
remote_reboot $dest; |
remote_reboot $dest |
468 |
return [list -1 ""]; |
return [list -1 ""] |
469 |
} |
} |
470 |
} |
} |
471 |
return [list -1 ""]; |
return [list -1 ""] |
472 |
} |
} |
473 |
|
|
474 |
proc gdb_stub_load { dest prog args } { |
proc gdb_stub_load { dest prog args } { |
477 |
|
|
478 |
for { set x 0; } { $x < [llength $args] } { incr x } { |
for { set x 0; } { $x < [llength $args] } { incr x } { |
479 |
if { [lindex $args $x] != "" } { |
if { [lindex $args $x] != "" } { |
480 |
return [list "unsupported" "no support for [lindex $argnames $x] on this target"]; |
return [list "unsupported" "no support for [lindex $argnames $x] on this target"] |
481 |
} |
} |
482 |
} |
} |
483 |
|
|
484 |
set result [remote_spawn $dest $prog]; |
set result [remote_spawn $dest $prog] |
485 |
|
|
486 |
if { $result < 0 } { |
if { $result < 0 } { |
487 |
return [list "fail" "remote_spawn failed"]; |
return [list "fail" "remote_spawn failed"] |
488 |
} |
} |
489 |
|
|
490 |
# FIXME: The value 120 should be a parameter. |
# FIXME: The value 120 should be a parameter. |
491 |
set result [remote_wait $dest 120]; |
set result [remote_wait $dest 120] |
492 |
set status [lindex $result 0]; |
set status [lindex $result 0] |
493 |
set output [lindex $result 1]; |
set output [lindex $result 1] |
494 |
|
|
495 |
if { $status == 0 } { |
if { $status == 0 } { |
496 |
return [list "pass" $output]; |
return [list "pass" $output] |
497 |
} else if { $status > 0 } { |
} else if { $status > 0 } { |
498 |
return [list "fail" $output]; |
return [list "fail" $output] |
499 |
} else { |
} else { |
500 |
global gdb_stub_retry; |
global gdb_stub_retry |
501 |
|
|
502 |
if ![info exists gdb_stub_retry] { |
if ![info exists gdb_stub_retry] { |
503 |
set gdb_stub_retry 1; |
set gdb_stub_retry 1 |
504 |
|
|
505 |
set result [eval gdb_stub_load \{$dest\} \{$prog\} $args]; |
set result [eval gdb_stub_load \{$dest\} \{$prog\} $args] |
506 |
unset gdb_stub_retry; |
unset gdb_stub_retry |
507 |
return $result; |
return $result |
508 |
} else { |
} else { |
509 |
return [list "fail" $output]; |
return [list "fail" $output] |
510 |
} |
} |
511 |
} |
} |
512 |
} |
} |
513 |
|
|
514 |
|
|
515 |
# |
# |
516 |
# gdb_stub_ld -- load PROG into the board; |
# gdb_stub_ld -- load PROG into the board |
517 |
# Returns a 0 if there was an error, |
# Returns a 0 if there was an error, |
518 |
# 1 if it loaded successfully. |
# 1 if it loaded successfully. |
519 |
# |
# |
523 |
|
|
524 |
if ![board_info $dest exists gdb_is_running] { |
if ![board_info $dest exists gdb_is_running] { |
525 |
if ![gdb_stub_restart $dest] { |
if ![gdb_stub_restart $dest] { |
526 |
return 0; |
return 0 |
527 |
} |
} |
528 |
} |
} |
529 |
|
|
544 |
-re "$gdb_prompt $" { |
-re "$gdb_prompt $" { |
545 |
# Hmmm...is retrying going to help? I kinda doubt it. |
# Hmmm...is retrying going to help? I kinda doubt it. |
546 |
warning "GDB couldn't read file" |
warning "GDB couldn't read file" |
547 |
return [gdb_stub_retry_ld "$dest" "$prog"]; |
return [gdb_stub_retry_ld "$dest" "$prog"] |
548 |
} |
} |
549 |
timeout { |
timeout { |
550 |
warning "(timeout) read symbol file"; |
warning "(timeout) read symbol file" |
551 |
return [gdb_stub_retry_ld "$dest" "$prog"]; |
return [gdb_stub_retry_ld "$dest" "$prog"] |
552 |
} |
} |
553 |
} |
} |
554 |
|
|
556 |
gdb_stub_delete_breakpoints |
gdb_stub_delete_breakpoints |
557 |
|
|
558 |
if [board_info $dest exists gdb_serial] { |
if [board_info $dest exists gdb_serial] { |
559 |
set serial [board_info $dest gdb_serial]; |
set serial [board_info $dest gdb_serial] |
560 |
} elseif [board_info $dest exists serial] { |
} elseif [board_info $dest exists serial] { |
561 |
set serial [board_info $dest serial]; |
set serial [board_info $dest serial] |
562 |
} else { |
} else { |
563 |
set serial [board_info $dest netport]; |
set serial [board_info $dest netport] |
564 |
} |
} |
565 |
|
|
566 |
remote_send host "target remote $serial\n" |
remote_send host "target remote $serial\n" |
567 |
remote_expect host 60 { |
remote_expect host 60 { |
568 |
-re "Kill it?.*y or n.*" { |
-re "Kill it?.*y or n.*" { |
569 |
remote_send host "y\n"; |
remote_send host "y\n" |
570 |
exp_continue |
exp_continue |
571 |
} |
} |
572 |
-re "$gdb_prompt $" { |
-re "$gdb_prompt $" { |
579 |
} |
} |
580 |
|
|
581 |
if [board_info $dest exists gdb_load_offset] { |
if [board_info $dest exists gdb_load_offset] { |
582 |
set offset "[board_info $dest gdb_load_offset]"; |
set offset "[board_info $dest gdb_load_offset]" |
583 |
} else { |
} else { |
584 |
set offset ""; |
set offset "" |
585 |
} |
} |
586 |
remote_send host "load $prog $offset\n" |
remote_send host "load $prog $offset\n" |
587 |
verbose "Loading $prog into $GDB" 2 |
verbose "Loading $prog into $GDB" 2 |
588 |
global verbose; |
global verbose |
589 |
remote_expect host 1200 { |
remote_expect host 1200 { |
590 |
-re "Loading.*$gdb_prompt $" { |
-re "Loading.*$gdb_prompt $" { |
591 |
verbose "Loaded $prog into $GDB" 1 |
verbose "Loaded $prog into $GDB" 1 |
609 |
# |
# |
610 |
|
|
611 |
proc gdb_stub_retry_ld { dest prog } { |
proc gdb_stub_retry_ld { dest prog } { |
612 |
global gdb_stub_retry_ld; |
global gdb_stub_retry_ld |
613 |
|
|
614 |
remote_reboot $dest; |
remote_reboot $dest |
615 |
if [info exists gdb_stub_retry_ld] { |
if [info exists gdb_stub_retry_ld] { |
616 |
unset gdb_stub_retry_ld; |
unset gdb_stub_retry_ld |
617 |
return 0; |
return 0 |
618 |
} else { |
} else { |
619 |
set gdb_stub_retry_ld 1; |
set gdb_stub_retry_ld 1 |
620 |
} |
} |
621 |
gdb_stub_restart $dest; |
gdb_stub_restart $dest |
622 |
set status [gdb_stub_ld $dest $prog]; |
set status [gdb_stub_ld $dest $prog] |
623 |
if [info exists gdb_stub_retry_ld] { |
if [info exists gdb_stub_retry_ld] { |
624 |
unset gdb_stub_retry_ld; |
unset gdb_stub_retry_ld |
625 |
} |
} |
626 |
return $status; |
return $status |
627 |
} |
} |
628 |
|
|
629 |
proc gdb_stub_close { dest } { |
proc gdb_stub_close { dest } { |
630 |
global board_info |
global board_info |
631 |
set name [board_info $dest name]; |
set name [board_info $dest name] |
632 |
if [info exists board_info($name,gdb_is_running)] { |
if [info exists board_info($name,gdb_is_running)] { |
633 |
unset board_info($name,gdb_is_running); |
unset board_info($name,gdb_is_running) |
634 |
} |
} |
635 |
return [remote_close host]; |
return [remote_close host] |
636 |
} |
} |
637 |
|
|
638 |
set_board_info protocol "gdb_stub" |
set_board_info protocol "gdb_stub" |