Commit | Line | Data |
---|---|---|
da6012e5 | 1 | # Copyright 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc. |
fb40c209 AC |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 2 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program; if not, write to the Free Software | |
15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
16 | ||
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@prep.ai.mit.edu | |
19 | ||
20 | # This file was based on a file written by Fred Fish. (fnf@cygnus.com) | |
21 | ||
22 | # Test setup routines that work with the MI interpreter. | |
23 | ||
24 | # The variable mi_gdb_prompt is a regexp which matches the gdb mi prompt. | |
25 | # Set it if it is not already set. | |
26 | global mi_gdb_prompt | |
27 | if ![info exists mi_gdb_prompt] then { | |
28 | set mi_gdb_prompt "\[(\]gdb\[)\] \r\n" | |
29 | } | |
30 | ||
31 | set MIFLAGS "-i=mi" | |
32 | ||
33 | # | |
34 | # mi_gdb_exit -- exit the GDB, killing the target program if necessary | |
35 | # | |
36 | proc mi_gdb_exit {} { | |
37 | catch mi_uncatched_gdb_exit | |
38 | } | |
39 | ||
40 | proc mi_uncatched_gdb_exit {} { | |
41 | global GDB | |
42 | global GDBFLAGS | |
43 | global verbose | |
44 | global gdb_spawn_id; | |
45 | global gdb_prompt | |
46 | global mi_gdb_prompt | |
47 | global MIFLAGS | |
48 | ||
49 | gdb_stop_suppressing_tests; | |
50 | ||
51 | if { [info procs sid_exit] != "" } { | |
52 | sid_exit | |
53 | } | |
54 | ||
55 | if ![info exists gdb_spawn_id] { | |
56 | return; | |
57 | } | |
58 | ||
59 | verbose "Quitting $GDB $GDBFLAGS $MIFLAGS" | |
60 | ||
61 | if { [is_remote host] && [board_info host exists fileid] } { | |
62 | send_gdb "999-gdb-exit\n"; | |
63 | gdb_expect 10 { | |
64 | -re "y or n" { | |
65 | send_gdb "y\n"; | |
66 | exp_continue; | |
67 | } | |
68 | -re "Undefined command.*$gdb_prompt $" { | |
69 | send_gdb "quit\n" | |
70 | exp_continue; | |
71 | } | |
72 | -re "DOSEXIT code" { } | |
73 | default { } | |
74 | } | |
75 | } | |
76 | ||
77 | if ![is_remote host] { | |
78 | remote_close host; | |
79 | } | |
80 | unset gdb_spawn_id | |
81 | } | |
82 | ||
83 | # | |
84 | # start gdb -- start gdb running, default procedure | |
85 | # | |
86 | # When running over NFS, particularly if running many simultaneous | |
87 | # tests on different hosts all using the same server, things can | |
88 | # get really slow. Give gdb at least 3 minutes to start up. | |
89 | # | |
90 | proc mi_gdb_start { } { | |
91 | global verbose | |
92 | global GDB | |
93 | global GDBFLAGS | |
94 | global gdb_prompt | |
95 | global mi_gdb_prompt | |
96 | global timeout | |
97 | global gdb_spawn_id; | |
98 | global MIFLAGS | |
99 | ||
100 | gdb_stop_suppressing_tests; | |
101 | ||
1759b3c3 AC |
102 | # Start SID. |
103 | if { [info procs sid_start] != "" } { | |
104 | verbose "Spawning SID" | |
105 | sid_start | |
106 | } | |
107 | ||
fb40c209 AC |
108 | verbose "Spawning $GDB -nw $GDBFLAGS $MIFLAGS" |
109 | ||
110 | if [info exists gdb_spawn_id] { | |
111 | return 0; | |
112 | } | |
113 | ||
114 | if ![is_remote host] { | |
115 | if { [which $GDB] == 0 } then { | |
116 | perror "$GDB does not exist." | |
117 | exit 1 | |
118 | } | |
119 | } | |
120 | set res [remote_spawn host "$GDB -nw $GDBFLAGS $MIFLAGS [host_info gdb_opts]"]; | |
121 | if { $res < 0 || $res == "" } { | |
122 | perror "Spawning $GDB failed." | |
123 | return 1; | |
124 | } | |
125 | gdb_expect { | |
1f312e79 JJ |
126 | -re "~\"GNU.*\r\n~\".*$mi_gdb_prompt$" { |
127 | # We have a new format mi startup prompt. If we are | |
128 | # running mi1, then this is an error as we should be | |
129 | # using the old-style prompt. | |
130 | if { $MIFLAGS == "-i=mi1" } { | |
131 | perror "(mi startup) Got unexpected new mi prompt." | |
132 | remote_close host; | |
133 | return -1; | |
134 | } | |
135 | verbose "GDB initialized." | |
136 | } | |
137 | -re "\[^~\].*$mi_gdb_prompt$" { | |
138 | # We have an old format mi startup prompt. If we are | |
139 | # not running mi1, then this is an error as we should be | |
140 | # using the new-style prompt. | |
141 | if { $MIFLAGS != "-i=mi1" } { | |
142 | perror "(mi startup) Got unexpected old mi prompt." | |
143 | remote_close host; | |
144 | return -1; | |
145 | } | |
d20bf2e8 | 146 | verbose "GDB initialized." |
fb40c209 AC |
147 | } |
148 | -re ".*$gdb_prompt $" { | |
149 | untested "Skip mi tests (got non-mi prompt)." | |
150 | remote_close host; | |
151 | return -1; | |
152 | } | |
76c520e0 AC |
153 | -re ".*unrecognized option.*for a complete list of options." { |
154 | untested "Skip mi tests (not compiled with mi support)." | |
155 | remote_close host; | |
156 | return -1; | |
157 | } | |
7d76bd60 MK |
158 | -re ".*Interpreter `mi' unrecognized." { |
159 | untested "Skip mi tests (not compiled with mi support)." | |
160 | remote_close host; | |
161 | return -1; | |
162 | } | |
fb40c209 AC |
163 | timeout { |
164 | perror "(timeout) GDB never initialized after 10 seconds." | |
165 | remote_close host; | |
166 | return -1 | |
167 | } | |
168 | } | |
169 | set gdb_spawn_id -1; | |
170 | ||
171 | # FIXME: mi output does not go through pagers, so these can be removed. | |
172 | # force the height to "unlimited", so no pagers get used | |
173 | send_gdb "100-gdb-set height 0\n" | |
174 | gdb_expect 10 { | |
175 | -re ".*100-gdb-set height 0\r\n100\\\^done\r\n$mi_gdb_prompt$" { | |
176 | verbose "Setting height to 0." 2 | |
177 | } | |
178 | timeout { | |
179 | warning "Couldn't set the height to 0" | |
180 | } | |
181 | } | |
182 | # force the width to "unlimited", so no wraparound occurs | |
183 | send_gdb "101-gdb-set width 0\n" | |
184 | gdb_expect 10 { | |
185 | -re ".*101-gdb-set width 0\r\n101\\\^done\r\n$mi_gdb_prompt$" { | |
186 | verbose "Setting width to 0." 2 | |
187 | } | |
188 | timeout { | |
189 | warning "Couldn't set the width to 0." | |
190 | } | |
191 | } | |
192 | ||
fb40c209 AC |
193 | return 0; |
194 | } | |
195 | ||
196 | # Many of the tests depend on setting breakpoints at various places and | |
197 | # running until that breakpoint is reached. At times, we want to start | |
198 | # with a clean-slate with respect to breakpoints, so this utility proc | |
199 | # lets us do this without duplicating this code everywhere. | |
200 | # | |
201 | ||
202 | proc mi_delete_breakpoints {} { | |
203 | global mi_gdb_prompt | |
204 | ||
205 | # FIXME: The mi operation won't accept a prompt back and will use the 'all' arg | |
206 | send_gdb "102-break-delete\n" | |
207 | gdb_expect 30 { | |
208 | -re "Delete all breakpoints.*y or n.*$" { | |
209 | send_gdb "y\n"; | |
210 | exp_continue | |
211 | } | |
212 | -re ".*102-break-delete\r\n102\\\^done\r\n$mi_gdb_prompt$" { | |
213 | # This happens if there were no breakpoints | |
214 | } | |
f1c8a949 | 215 | timeout { perror "Delete all breakpoints in mi_delete_breakpoints (timeout)" ; return } |
fb40c209 AC |
216 | } |
217 | ||
218 | # The correct output is not "No breakpoints or watchpoints." but an | |
219 | # empty BreakpointTable. Also, a query is not acceptable with mi. | |
220 | send_gdb "103-break-list\n" | |
221 | gdb_expect 30 { | |
222 | -re "103-break-list\r\n103\\\^done,BreakpointTable=\{\}\r\n$mi_gdb_prompt$" {} | |
cff22675 | 223 | -re "103-break-list\r\n103\\\^done,BreakpointTable=\{nr_rows=\".\",nr_cols=\".\",hdr=\\\[\{width=\".*\",alignment=\".*\",col_name=\"number\",colhdr=\"Num\"\}.*colhdr=\"Type\".*colhdr=\"Disp\".*colhdr=\"Enb\".*colhdr=\"Address\".*colhdr=\"What\".*\\\],body=\\\[\\\]\}" {} |
fb40c209 AC |
224 | -re "103-break-list\r\n103\\\^doneNo breakpoints or watchpoints.\r\n\r\n$mi_gdb_prompt$" {warning "Unexpected console text received"} |
225 | -re "$mi_gdb_prompt$" { perror "Breakpoints not deleted" ; return } | |
226 | -re "Delete all breakpoints.*or n.*$" { | |
227 | warning "Unexpected prompt for breakpoints deletion"; | |
228 | send_gdb "y\n"; | |
229 | exp_continue | |
230 | } | |
231 | timeout { perror "-break-list (timeout)" ; return } | |
232 | } | |
233 | } | |
234 | ||
235 | proc mi_gdb_reinitialize_dir { subdir } { | |
236 | global mi_gdb_prompt | |
da81390b | 237 | global MIFLAGS |
fb40c209 AC |
238 | |
239 | global suppress_flag | |
240 | if { $suppress_flag } { | |
241 | return | |
242 | } | |
243 | ||
244 | if [is_remote host] { | |
245 | return ""; | |
246 | } | |
247 | ||
da81390b JJ |
248 | if { $MIFLAGS == "-i=mi1" } { |
249 | send_gdb "104-environment-directory\n" | |
250 | gdb_expect 60 { | |
fb40c209 AC |
251 | -re ".*Reinitialize source path to empty.*y or n. " { |
252 | warning "Got confirmation prompt for dir reinitialization." | |
253 | send_gdb "y\n" | |
254 | gdb_expect 60 { | |
255 | -re "$mi_gdb_prompt$" {} | |
256 | timeout {error "Dir reinitialization failed (timeout)"} | |
257 | } | |
258 | } | |
259 | -re "$mi_gdb_prompt$" {} | |
260 | timeout {error "Dir reinitialization failed (timeout)"} | |
da81390b JJ |
261 | } |
262 | } else { | |
263 | send_gdb "104-environment-directory -r\n" | |
264 | gdb_expect 60 { | |
265 | -re "104\\\^done,source-path=.*\r\n$mi_gdb_prompt$" {} | |
266 | -re "$mi_gdb_prompt$" {} | |
267 | timeout {error "Dir reinitialization failed (timeout)"} | |
268 | } | |
fb40c209 AC |
269 | } |
270 | ||
271 | send_gdb "105-environment-directory $subdir\n" | |
272 | gdb_expect 60 { | |
273 | -re "Source directories searched.*$mi_gdb_prompt$" { | |
274 | verbose "Dir set to $subdir" | |
275 | } | |
da81390b | 276 | -re "105\\\^done.*\r\n$mi_gdb_prompt$" { |
fb40c209 AC |
277 | # FIXME: We return just the prompt for now. |
278 | verbose "Dir set to $subdir" | |
279 | # perror "Dir \"$subdir\" failed." | |
280 | } | |
281 | } | |
282 | } | |
283 | ||
da6012e5 DJ |
284 | # Send GDB the "target" command. |
285 | # FIXME: Some of these patterns are not appropriate for MI. Based on | |
286 | # config/monitor.exp:gdb_target_command. | |
287 | proc mi_gdb_target_cmd { targetname serialport } { | |
288 | global mi_gdb_prompt | |
289 | ||
290 | for {set i 1} {$i <= 3} {incr i} { | |
291 | send_gdb "47-target-select $targetname $serialport\n" | |
292 | gdb_expect 60 { | |
293 | -re "47\\^connected.*$mi_gdb_prompt$" { | |
294 | verbose "Set target to $targetname"; | |
295 | return 0; | |
296 | } | |
297 | -re "Couldn't establish connection to remote.*$mi_gdb_prompt$" { | |
298 | verbose "Connection failed"; | |
299 | } | |
300 | -re "Remote MIPS debugging.*$mi_gdb_prompt$" { | |
301 | verbose "Set target to $targetname"; | |
302 | return 0; | |
303 | } | |
304 | -re "Remote debugging using .*$serialport.*$mi_gdb_prompt$" { | |
305 | verbose "Set target to $targetname"; | |
306 | return 0; | |
307 | } | |
308 | -re "Remote target $targetname connected to.*$mi_gdb_prompt$" { | |
309 | verbose "Set target to $targetname"; | |
310 | return 0; | |
311 | } | |
312 | -re "Connected to.*$mi_gdb_prompt$" { | |
313 | verbose "Set target to $targetname"; | |
314 | return 0; | |
315 | } | |
316 | -re "Ending remote.*$mi_gdb_prompt$" { } | |
317 | -re "Connection refused.*$mi_gdb_prompt$" { | |
318 | verbose "Connection refused by remote target. Pausing, and trying again." | |
319 | sleep 5 | |
320 | continue | |
321 | } | |
322 | -re "Timeout reading from remote system.*$mi_gdb_prompt$" { | |
323 | verbose "Got timeout error from gdb."; | |
324 | } | |
325 | timeout { | |
326 | send_gdb "\ 3"; | |
327 | break | |
328 | } | |
329 | } | |
330 | } | |
331 | return 1 | |
332 | } | |
333 | ||
fb40c209 | 334 | # |
da6012e5 | 335 | # load a file into the debugger (file command only). |
fb40c209 AC |
336 | # return a -1 if anything goes wrong. |
337 | # | |
da6012e5 | 338 | proc mi_gdb_file_cmd { arg } { |
fb40c209 AC |
339 | global verbose |
340 | global loadpath | |
341 | global loadfile | |
342 | global GDB | |
343 | global mi_gdb_prompt | |
b53f9b27 | 344 | global last_mi_gdb_file |
da6012e5 | 345 | global last_mi_remote_file |
fb40c209 AC |
346 | upvar timeout timeout |
347 | ||
b53f9b27 MS |
348 | if { $arg == "" } { |
349 | set arg $last_mi_gdb_file; | |
da6012e5 DJ |
350 | } else { |
351 | set last_mi_gdb_file $arg | |
352 | if { [ info exists last_mi_remote_file ] } { | |
353 | unset last_mi_remote_file | |
354 | } | |
b53f9b27 MS |
355 | } |
356 | ||
da6012e5 DJ |
357 | if [is_remote host] { |
358 | set arg [remote_download host $arg]; | |
359 | if { $arg == "" } { | |
360 | error "download failed" | |
361 | return -1; | |
362 | } | |
363 | } | |
fb40c209 | 364 | |
fb40c209 AC |
365 | # FIXME: Several of these patterns are only acceptable for console |
366 | # output. Queries are an error for mi. | |
367 | send_gdb "105-file-exec-and-symbols $arg\n" | |
368 | gdb_expect 120 { | |
369 | -re "Reading symbols from.*done.*$mi_gdb_prompt$" { | |
370 | verbose "\t\tLoaded $arg into the $GDB" | |
da6012e5 | 371 | return 0 |
fb40c209 AC |
372 | } |
373 | -re "has no symbol-table.*$mi_gdb_prompt$" { | |
374 | perror "$arg wasn't compiled with \"-g\"" | |
375 | return -1 | |
376 | } | |
377 | -re "A program is being debugged already.*Kill it.*y or n. $" { | |
378 | send_gdb "y\n" | |
379 | verbose "\t\tKilling previous program being debugged" | |
380 | exp_continue | |
381 | } | |
382 | -re "Load new symbol table from \".*\".*y or n. $" { | |
383 | send_gdb "y\n" | |
384 | gdb_expect 120 { | |
385 | -re "Reading symbols from.*done.*$mi_gdb_prompt$" { | |
386 | verbose "\t\tLoaded $arg with new symbol table into $GDB" | |
387 | # All OK | |
388 | } | |
389 | timeout { | |
390 | perror "(timeout) Couldn't load $arg, other program already loaded." | |
391 | return -1 | |
392 | } | |
393 | } | |
394 | } | |
395 | -re "No such file or directory.*$mi_gdb_prompt$" { | |
396 | perror "($arg) No such file or directory\n" | |
397 | return -1 | |
398 | } | |
399 | -re "105-file-exec-and-symbols .*\r\n105\\\^done\r\n$mi_gdb_prompt$" { | |
da6012e5 DJ |
400 | # We (MI) are just giving the prompt back for now, instead of giving |
401 | # some acknowledgement. | |
402 | return 0 | |
403 | } | |
fb40c209 AC |
404 | timeout { |
405 | perror "couldn't load $arg into $GDB (timed out)." | |
406 | return -1 | |
407 | } | |
da6012e5 | 408 | eof { |
fb40c209 AC |
409 | # This is an attempt to detect a core dump, but seems not to |
410 | # work. Perhaps we need to match .* followed by eof, in which | |
411 | # gdb_expect does not seem to have a way to do that. | |
412 | perror "couldn't load $arg into $GDB (end of file)." | |
413 | return -1 | |
414 | } | |
415 | } | |
da6012e5 DJ |
416 | } |
417 | ||
418 | # | |
419 | # load a file into the debugger. | |
420 | # return a -1 if anything goes wrong. | |
421 | # | |
422 | proc mi_gdb_load { arg } { | |
423 | global verbose | |
424 | global loadpath | |
425 | global loadfile | |
426 | global GDB | |
427 | global mi_gdb_prompt | |
428 | upvar timeout timeout | |
429 | ||
430 | # ``gdb_unload'' | |
431 | if { $arg != "" } { | |
432 | mi_gdb_file_cmd $arg | |
433 | } | |
434 | ||
fb40c209 | 435 | # ``load'' |
da6012e5 DJ |
436 | if { [info procs gdbserver_gdb_load] != "" } { |
437 | global last_mi_gdb_file | |
438 | global last_mi_remote_file | |
439 | ||
440 | if { ! [info exists last_mi_remote_file] } { | |
441 | if [is_remote target] { | |
442 | set last_mi_remote_file [remote_download target $arg] | |
443 | } else { | |
444 | set last_mi_remote_file $last_mi_gdb_file | |
445 | } | |
446 | } | |
447 | ||
448 | set res [gdbserver_gdb_load $last_mi_remote_file] | |
449 | set protocol [lindex $res 0] | |
450 | set gdbport [lindex $res 1] | |
451 | ||
452 | if { [mi_gdb_target_cmd $protocol $gdbport] != 0 } { | |
453 | return -1 | |
454 | } | |
455 | } elseif { [info procs send_target_sid] != "" } { | |
fb40c209 AC |
456 | # For SID, things get complex |
457 | send_target_sid | |
458 | gdb_expect 60 { | |
459 | -re "\\^done,.*$mi_gdb_prompt$" { | |
460 | } | |
461 | timeout { | |
462 | perror "Unable to connect to SID target" | |
463 | return -1 | |
464 | } | |
465 | } | |
466 | send_gdb "48-target-download\n" | |
467 | gdb_expect 10 { | |
468 | -re "48\\^done.*$mi_gdb_prompt$" { | |
469 | } | |
470 | timeout { | |
471 | perror "Unable to download to SID target" | |
472 | return -1 | |
473 | } | |
474 | } | |
475 | } elseif { [target_info protocol] == "sim" } { | |
476 | # For the simulator, just connect to it directly. | |
477 | send_gdb "47-target-select sim\n" | |
478 | gdb_expect 10 { | |
479 | -re "47\\^connected.*$mi_gdb_prompt$" { | |
480 | } | |
481 | timeout { | |
482 | perror "Unable to select sim target" | |
483 | return -1 | |
484 | } | |
485 | } | |
486 | send_gdb "48-target-download\n" | |
487 | gdb_expect 10 { | |
488 | -re "48\\^done.*$mi_gdb_prompt$" { | |
489 | } | |
490 | timeout { | |
491 | perror "Unable to download to sim target" | |
492 | return -1 | |
493 | } | |
494 | } | |
b53f9b27 MS |
495 | } elseif { [target_info gdb_protocol] == "remote" } { |
496 | # remote targets | |
8e3049aa PB |
497 | if { [mi_gdb_target_cmd "remote" [target_info netport]] != 0 } { |
498 | perror "Unable to connect to remote target" | |
499 | return -1 | |
b53f9b27 MS |
500 | } |
501 | send_gdb "48-target-download\n" | |
502 | gdb_expect 10 { | |
503 | -re "48\\^done.*$mi_gdb_prompt$" { | |
504 | } | |
505 | timeout { | |
506 | perror "Unable to download to remote target" | |
507 | return -1 | |
508 | } | |
509 | } | |
fb40c209 AC |
510 | } |
511 | return 0 | |
512 | } | |
513 | ||
514 | # mi_gdb_test COMMAND PATTERN MESSAGE -- send a command to gdb; test the result. | |
515 | # | |
516 | # COMMAND is the command to execute, send to GDB with send_gdb. If | |
517 | # this is the null string no command is sent. | |
518 | # PATTERN is the pattern to match for a PASS, and must NOT include | |
519 | # the \r\n sequence immediately before the gdb prompt. | |
520 | # MESSAGE is an optional message to be printed. If this is | |
521 | # omitted, then the pass/fail messages use the command string as the | |
522 | # message. (If this is the empty string, then sometimes we don't | |
523 | # call pass or fail at all; I don't understand this at all.) | |
524 | # | |
525 | # Returns: | |
526 | # 1 if the test failed, | |
527 | # 0 if the test passes, | |
528 | # -1 if there was an internal error. | |
529 | # | |
530 | proc mi_gdb_test { args } { | |
531 | global verbose | |
532 | global mi_gdb_prompt | |
07c98896 | 533 | global GDB expect_out |
fb40c209 AC |
534 | upvar timeout timeout |
535 | ||
536 | if [llength $args]>2 then { | |
537 | set message [lindex $args 2] | |
538 | } else { | |
539 | set message [lindex $args 0] | |
540 | } | |
541 | set command [lindex $args 0] | |
542 | set pattern [lindex $args 1] | |
543 | ||
544 | if [llength $args]==5 { | |
545 | set question_string [lindex $args 3]; | |
546 | set response_string [lindex $args 4]; | |
547 | } else { | |
548 | set question_string "^FOOBAR$" | |
549 | } | |
550 | ||
551 | if $verbose>2 then { | |
552 | send_user "Sending \"$command\" to gdb\n" | |
553 | send_user "Looking to match \"$pattern\"\n" | |
554 | send_user "Message is \"$message\"\n" | |
555 | } | |
556 | ||
557 | set result -1 | |
558 | set string "${command}\n"; | |
559 | if { $command != "" } { | |
560 | while { "$string" != "" } { | |
561 | set foo [string first "\n" "$string"]; | |
562 | set len [string length "$string"]; | |
563 | if { $foo < [expr $len - 1] } { | |
564 | set str [string range "$string" 0 $foo]; | |
565 | if { [send_gdb "$str"] != "" } { | |
566 | global suppress_flag; | |
567 | ||
568 | if { ! $suppress_flag } { | |
569 | perror "Couldn't send $command to GDB."; | |
570 | } | |
571 | fail "$message"; | |
572 | return $result; | |
573 | } | |
574 | gdb_expect 2 { | |
575 | -re "\[\r\n\]" { } | |
576 | timeout { } | |
577 | } | |
578 | set string [string range "$string" [expr $foo + 1] end]; | |
579 | } else { | |
580 | break; | |
581 | } | |
582 | } | |
583 | if { "$string" != "" } { | |
584 | if { [send_gdb "$string"] != "" } { | |
585 | global suppress_flag; | |
586 | ||
587 | if { ! $suppress_flag } { | |
588 | perror "Couldn't send $command to GDB."; | |
589 | } | |
590 | fail "$message"; | |
591 | return $result; | |
592 | } | |
593 | } | |
594 | } | |
595 | ||
596 | if [info exists timeout] { | |
597 | set tmt $timeout; | |
598 | } else { | |
599 | global timeout; | |
600 | if [info exists timeout] { | |
601 | set tmt $timeout; | |
602 | } else { | |
603 | set tmt 60; | |
604 | } | |
605 | } | |
606 | gdb_expect $tmt { | |
607 | -re "\\*\\*\\* DOSEXIT code.*" { | |
608 | if { $message != "" } { | |
609 | fail "$message"; | |
610 | } | |
611 | gdb_suppress_entire_file "GDB died"; | |
612 | return -1; | |
613 | } | |
614 | -re "Ending remote debugging.*$mi_gdb_prompt\[ \]*$" { | |
615 | if ![isnative] then { | |
616 | warning "Can`t communicate to remote target." | |
617 | } | |
618 | gdb_exit | |
619 | gdb_start | |
620 | set result -1 | |
7ddebc7e KS |
621 | } |
622 | -re "\[\r\n\]*($pattern)\[\r\n\]+$mi_gdb_prompt\[ \]*$" { | |
623 | if ![string match "" $message] then { | |
624 | pass "$message" | |
625 | } | |
626 | set result 0 | |
fb40c209 AC |
627 | } |
628 | -re "(${question_string})$" { | |
629 | send_gdb "$response_string\n"; | |
630 | exp_continue; | |
631 | } | |
632 | -re "Undefined.* command:.*$mi_gdb_prompt\[ \]*$" { | |
633 | perror "Undefined command \"$command\"." | |
634 | fail "$message" | |
635 | set result 1 | |
636 | } | |
637 | -re "Ambiguous command.*$mi_gdb_prompt\[ \]*$" { | |
638 | perror "\"$command\" is not a unique command name." | |
639 | fail "$message" | |
640 | set result 1 | |
fb40c209 AC |
641 | } |
642 | -re "Program exited with code \[0-9\]+.*$mi_gdb_prompt\[ \]*$" { | |
643 | if ![string match "" $message] then { | |
ed4c619a | 644 | set errmsg "$message (the program exited)" |
fb40c209 | 645 | } else { |
ed4c619a | 646 | set errmsg "$command (the program exited)" |
fb40c209 AC |
647 | } |
648 | fail "$errmsg" | |
649 | return -1 | |
650 | } | |
651 | -re "The program is not being run.*$mi_gdb_prompt\[ \]*$" { | |
652 | if ![string match "" $message] then { | |
ed4c619a | 653 | set errmsg "$message (the program is no longer running)" |
fb40c209 | 654 | } else { |
ed4c619a | 655 | set errmsg "$command (the program is no longer running)" |
fb40c209 AC |
656 | } |
657 | fail "$errmsg" | |
658 | return -1 | |
659 | } | |
660 | -re ".*$mi_gdb_prompt\[ \]*$" { | |
661 | if ![string match "" $message] then { | |
662 | fail "$message" | |
663 | } | |
664 | set result 1 | |
665 | } | |
666 | "<return>" { | |
667 | send_gdb "\n" | |
668 | perror "Window too small." | |
669 | fail "$message" | |
670 | } | |
671 | -re "\\(y or n\\) " { | |
672 | send_gdb "n\n" | |
673 | perror "Got interactive prompt." | |
674 | fail "$message" | |
675 | } | |
676 | eof { | |
677 | perror "Process no longer exists" | |
678 | if { $message != "" } { | |
679 | fail "$message" | |
680 | } | |
681 | return -1 | |
682 | } | |
683 | full_buffer { | |
684 | perror "internal buffer is full." | |
685 | fail "$message" | |
686 | } | |
687 | timeout { | |
688 | if ![string match "" $message] then { | |
689 | fail "$message (timeout)" | |
690 | } | |
691 | set result 1 | |
692 | } | |
693 | } | |
694 | return $result | |
695 | } | |
696 | ||
697 | # | |
698 | # MI run command. (A modified version of gdb_run_cmd) | |
699 | # | |
700 | ||
701 | # In patterns, the newline sequence ``\r\n'' is matched explicitly as | |
702 | # ``.*$'' could swallow up output that we attempt to match elsewhere. | |
703 | ||
704 | proc mi_run_cmd {args} { | |
705 | global suppress_flag | |
706 | if { $suppress_flag } { | |
707 | return -1 | |
708 | } | |
709 | global mi_gdb_prompt | |
710 | ||
711 | if [target_info exists gdb_init_command] { | |
712 | send_gdb "[target_info gdb_init_command]\n"; | |
713 | gdb_expect 30 { | |
714 | -re "$mi_gdb_prompt$" { } | |
715 | default { | |
716 | perror "gdb_init_command for target failed"; | |
717 | return; | |
718 | } | |
719 | } | |
720 | } | |
721 | ||
722 | if [target_info exists use_gdb_stub] { | |
723 | if [target_info exists gdb,do_reload_on_run] { | |
724 | # Specifying no file, defaults to the executable | |
725 | # currently being debugged. | |
726 | if { [mi_gdb_load ""] < 0 } { | |
727 | return; | |
728 | } | |
729 | send_gdb "000-exec-continue\n"; | |
730 | gdb_expect 60 { | |
1df0c130 | 731 | -re "000\\^running\[\r\n\]+$mi_gdb_prompt$" {} |
fb40c209 AC |
732 | default {} |
733 | } | |
734 | return; | |
735 | } | |
6a90e1d0 AC |
736 | |
737 | if [target_info exists gdb,start_symbol] { | |
738 | set start [target_info gdb,start_symbol]; | |
739 | } else { | |
740 | set start "start"; | |
741 | } | |
742 | ||
743 | # HACK: Should either use 000-jump or fix the target code | |
744 | # to better handle RUN. | |
745 | send_gdb "jump *$start\n" | |
746 | warning "Using CLI jump command, expect run-to-main FAIL" | |
747 | return | |
fb40c209 AC |
748 | } |
749 | ||
750 | send_gdb "000-exec-run $args\n" | |
751 | gdb_expect { | |
752 | -re "000\\^running\r\n${mi_gdb_prompt}" { | |
753 | } | |
754 | timeout { | |
755 | perror "Unable to start target" | |
756 | return | |
757 | } | |
758 | } | |
759 | # NOTE: Shortly after this there will be a ``000*stopping,...(gdb)'' | |
760 | } | |
761 | ||
762 | # | |
763 | # Just like run-to-main but works with the MI interface | |
764 | # | |
765 | ||
766 | proc mi_run_to_main { } { | |
767 | global suppress_flag | |
768 | if { $suppress_flag } { | |
769 | return -1 | |
770 | } | |
771 | ||
fb40c209 AC |
772 | global srcdir |
773 | global subdir | |
774 | global binfile | |
775 | global srcfile | |
776 | ||
fb40c209 AC |
777 | mi_delete_breakpoints |
778 | mi_gdb_reinitialize_dir $srcdir/$subdir | |
779 | mi_gdb_load ${binfile} | |
780 | ||
08b468e0 KS |
781 | mi_runto main |
782 | } | |
fb40c209 | 783 | |
08b468e0 KS |
784 | |
785 | # Just like gdb's "runto" proc, it will run the target to a given | |
786 | # function. The big difference here between mi_runto and mi_execute_to | |
787 | # is that mi_execute_to must have the inferior running already. This | |
788 | # proc will (like gdb's runto) (re)start the inferior, too. | |
789 | # | |
790 | # FUNC is the linespec of the place to stop (it inserts a breakpoint here). | |
791 | # It returns: | |
792 | # -1 if test suppressed, failed, timedout | |
793 | # 0 if test passed | |
794 | ||
795 | proc mi_runto {func} { | |
796 | global suppress_flag | |
797 | if { $suppress_flag } { | |
798 | return -1 | |
799 | } | |
800 | ||
801 | global mi_gdb_prompt expect_out | |
802 | global hex decimal | |
803 | ||
804 | set test "mi runto $func" | |
805 | mi_gdb_test "200-break-insert $func" \ | |
806 | "200\\^done,bkpt=\{number=\"\[0-9\]+\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"$func\",file=\".*\",line=\"\[0-9\]*\",times=\"0\"\}" \ | |
807 | "breakpoint at $func" | |
808 | ||
809 | if {![regexp {number="[0-9]+"} $expect_out(buffer) str] | |
810 | || ![scan $str {number="%d"} bkptno]} { | |
811 | set bkptno {[0-9]+} | |
812 | } | |
813 | ||
814 | mi_run_cmd | |
815 | gdb_expect { | |
816 | -re ".*000\\*stopped,reason=\"breakpoint-hit\",bkptno=\"$bkptno\",thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\"$func\",args=\(\\\[.*\\\]\|\{.*\}\),file=\".*\",line=\"\[0-9\]*\"\}\r\n$mi_gdb_prompt$" { | |
817 | pass "$test" | |
818 | return 0 | |
819 | } | |
820 | -re ".*$mi_gdb_prompt$" { | |
821 | fail "$test (2)" | |
822 | } | |
823 | timeout { | |
824 | fail "$test (timeout)" | |
825 | return -1 | |
826 | } | |
827 | } | |
fb40c209 AC |
828 | } |
829 | ||
830 | ||
831 | # Next to the next statement | |
08b468e0 | 832 | # For return values, see mi_execute_to_helper |
fb40c209 AC |
833 | |
834 | proc mi_next { test } { | |
dc360f58 | 835 | return [mi_next_to {.*} {.*} {.*} {.*} $test] |
fb40c209 AC |
836 | } |
837 | ||
838 | ||
839 | # Step to the next statement | |
08b468e0 | 840 | # For return values, see mi_execute_to_helper |
fb40c209 AC |
841 | |
842 | proc mi_step { test } { | |
dc360f58 | 843 | return [mi_step_to {.*} {.*} {.*} {.*} $test] |
fb40c209 | 844 | } |
dcf95b47 DJ |
845 | |
846 | # cmd should not include the number or newline (i.e. "exec-step 3", not | |
847 | # "220-exec-step 3\n" | |
848 | ||
1902c51f DJ |
849 | # Can not match -re ".*\r\n${mi_gdb_prompt}", because of false positives |
850 | # after the first prompt is printed. | |
851 | ||
08b468e0 | 852 | proc mi_execute_to_helper { cmd reason func args file line extra test } { |
dcf95b47 DJ |
853 | global suppress_flag |
854 | if { $suppress_flag } { | |
855 | return -1 | |
856 | } | |
857 | global mi_gdb_prompt | |
858 | global hex | |
859 | global decimal | |
860 | send_gdb "220-$cmd\n" | |
861 | gdb_expect { | |
dc360f58 | 862 | -re ".*220\\^running\r\n${mi_gdb_prompt}.*220\\*stopped,reason=\"$reason\",thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\"$func\",args=$args,file=\".*$file\",line=\"$line\"\}$extra\r\n$mi_gdb_prompt$" { |
dcf95b47 DJ |
863 | pass "$test" |
864 | return 0 | |
865 | } | |
dc360f58 | 866 | -re ".*220\\^running\r\n${mi_gdb_prompt}.*220\\*stopped,reason=\"$reason\",thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\".*\",args=\[\\\[\{\].*\[\\\]\}\],file=\".*\",line=\"\[0-9\]*\"\}.*\r\n$mi_gdb_prompt$" { |
dcf95b47 DJ |
867 | fail "$test (stopped at wrong place)" |
868 | return -1 | |
869 | } | |
870 | -re "220\\^running\r\n${mi_gdb_prompt}.*\r\n${mi_gdb_prompt}$" { | |
871 | fail "$test (unknown output after running)" | |
872 | return -1 | |
873 | } | |
dcf95b47 DJ |
874 | timeout { |
875 | fail "$test (timeout)" | |
876 | return -1 | |
877 | } | |
878 | } | |
879 | } | |
880 | ||
08b468e0 KS |
881 | proc mi_execute_to { cmd reason func args file line extra test } { |
882 | mi_execute_to_helper "$cmd" "$reason" "$func" "\\\[$args\\\]" \ | |
dcf95b47 DJ |
883 | "$file" "$line" "$extra" "$test" |
884 | } | |
885 | ||
886 | proc mi_next_to { func args file line test } { | |
08b468e0 | 887 | mi_execute_to "exec-next" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
888 | "$file" "$line" "" "$test" |
889 | } | |
890 | ||
891 | proc mi_step_to { func args file line test } { | |
08b468e0 | 892 | mi_execute_to "exec-step" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
893 | "$file" "$line" "" "$test" |
894 | } | |
895 | ||
896 | proc mi_finish_to { func args file line result ret test } { | |
08b468e0 | 897 | mi_execute_to "exec-finish" "function-finished" "$func" "$args" \ |
dcf95b47 DJ |
898 | "$file" "$line" \ |
899 | ",gdb-result-var=\"$result\",return-value=\"$ret\"" \ | |
900 | "$test" | |
901 | } | |
902 | ||
903 | proc mi_continue_to { bkptno func args file line test } { | |
08b468e0 | 904 | mi_execute_to "exec-continue" "breakpoint-hit\",bkptno=\"$bkptno" \ |
dcf95b47 DJ |
905 | "$func" "$args" "$file" "$line" "" "$test" |
906 | } | |
907 | ||
08b468e0 KS |
908 | proc mi0_execute_to { cmd reason func args file line extra test } { |
909 | mi_execute_to_helper "$cmd" "$reason" "$func" "\{$args\}" \ | |
dcf95b47 DJ |
910 | "$file" "$line" "$extra" "$test" |
911 | } | |
912 | ||
913 | proc mi0_next_to { func args file line test } { | |
08b468e0 | 914 | mi0_execute_to "exec-next" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
915 | "$file" "$line" "" "$test" |
916 | } | |
917 | ||
918 | proc mi0_step_to { func args file line test } { | |
08b468e0 | 919 | mi0_execute_to "exec-step" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
920 | "$file" "$line" "" "$test" |
921 | } | |
922 | ||
923 | proc mi0_finish_to { func args file line result ret test } { | |
08b468e0 | 924 | mi0_execute_to "exec-finish" "function-finished" "$func" "$args" \ |
dcf95b47 DJ |
925 | "$file" "$line" \ |
926 | ",gdb-result-var=\"$result\",return-value=\"$ret\"" \ | |
927 | "$test" | |
928 | } | |
929 | ||
930 | proc mi0_continue_to { bkptno func args file line test } { | |
08b468e0 | 931 | mi0_execute_to "exec-continue" "breakpoint-hit\",bkptno=\"$bkptno" \ |
dcf95b47 DJ |
932 | "$func" "$args" "$file" "$line" "" "$test" |
933 | } |