Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / testsuite / lib / mi-support.exp
blobfa99c53f255ce16969e9543a748328cfb4dc7ca7
1 # Copyright 1999, 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was based on a file written by Fred Fish. (fnf@cygnus.com)
22 # Test setup routines that work with the MI interpreter.
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"
31 global mi_inferior_spawn_id
32 global mi_inferior_tty_name
34 set MIFLAGS "-i=mi"
37 # mi_gdb_exit -- exit the GDB, killing the target program if necessary
39 proc mi_gdb_exit {} {
40 catch mi_uncatched_gdb_exit
43 proc mi_uncatched_gdb_exit {} {
44 global GDB
45 global GDBFLAGS
46 global verbose
47 global gdb_spawn_id;
48 global gdb_prompt
49 global mi_gdb_prompt
50 global MIFLAGS
52 gdb_stop_suppressing_tests;
54 if { [info procs sid_exit] != "" } {
55 sid_exit
58 if ![info exists gdb_spawn_id] {
59 return;
62 verbose "Quitting $GDB $GDBFLAGS $MIFLAGS"
64 if { [is_remote host] && [board_info host exists fileid] } {
65 send_gdb "999-gdb-exit\n";
66 gdb_expect 10 {
67 -re "y or n" {
68 send_gdb "y\n";
69 exp_continue;
71 -re "Undefined command.*$gdb_prompt $" {
72 send_gdb "quit\n"
73 exp_continue;
75 -re "DOSEXIT code" { }
76 default { }
80 if ![is_remote host] {
81 remote_close host;
83 unset gdb_spawn_id
87 # mi_gdb_start [INFERIOR_PTY] -- start gdb running, default procedure
89 # INFERIOR_PTY should be set to separate-inferior-tty to have the inferior work
90 # with it's own PTY. If set to same-inferior-tty, the inferior shares GDB's PTY.
91 # The default value is same-inferior-tty.
93 # When running over NFS, particularly if running many simultaneous
94 # tests on different hosts all using the same server, things can
95 # get really slow. Give gdb at least 3 minutes to start up.
97 proc mi_gdb_start { args } {
98 global verbose
99 global GDB
100 global GDBFLAGS
101 global gdb_prompt
102 global mi_gdb_prompt
103 global timeout
104 global gdb_spawn_id;
105 global MIFLAGS
107 gdb_stop_suppressing_tests;
108 set inferior_pty no-tty
110 if { [llength $args] == 1} {
111 set inferior_pty [lindex $args 0]
114 set separate_inferior_pty [string match $inferior_pty separate-inferior-tty]
116 # Start SID.
117 if { [info procs sid_start] != "" } {
118 verbose "Spawning SID"
119 sid_start
122 verbose "Spawning $GDB -nw $GDBFLAGS $MIFLAGS"
124 if [info exists gdb_spawn_id] {
125 return 0;
128 if ![is_remote host] {
129 if { [which $GDB] == 0 } then {
130 perror "$GDB does not exist."
131 exit 1
135 # Create the new PTY for the inferior process.
136 if { $separate_inferior_pty } {
137 spawn -pty
138 global mi_inferior_spawn_id
139 global mi_inferior_tty_name
140 set mi_inferior_spawn_id $spawn_id
141 set mi_inferior_tty_name $spawn_out(slave,name)
144 set res [remote_spawn host "$GDB -nw $GDBFLAGS $MIFLAGS [host_info gdb_opts]"];
145 if { $res < 0 || $res == "" } {
146 perror "Spawning $GDB failed."
147 return 1;
149 gdb_expect {
150 -re "~\"GNU.*\r\n~\".*$mi_gdb_prompt$" {
151 # We have a new format mi startup prompt. If we are
152 # running mi1, then this is an error as we should be
153 # using the old-style prompt.
154 if { $MIFLAGS == "-i=mi1" } {
155 perror "(mi startup) Got unexpected new mi prompt."
156 remote_close host;
157 return -1;
159 verbose "GDB initialized."
161 -re "\[^~\].*$mi_gdb_prompt$" {
162 # We have an old format mi startup prompt. If we are
163 # not running mi1, then this is an error as we should be
164 # using the new-style prompt.
165 if { $MIFLAGS != "-i=mi1" } {
166 perror "(mi startup) Got unexpected old mi prompt."
167 remote_close host;
168 return -1;
170 verbose "GDB initialized."
172 -re ".*$gdb_prompt $" {
173 untested "Skip mi tests (got non-mi prompt)."
174 remote_close host;
175 return -1;
177 -re ".*unrecognized option.*for a complete list of options." {
178 untested "Skip mi tests (not compiled with mi support)."
179 remote_close host;
180 return -1;
182 -re ".*Interpreter `mi' unrecognized." {
183 untested "Skip mi tests (not compiled with mi support)."
184 remote_close host;
185 return -1;
187 timeout {
188 perror "(timeout) GDB never initialized after 10 seconds."
189 remote_close host;
190 return -1
193 set gdb_spawn_id -1;
195 # FIXME: mi output does not go through pagers, so these can be removed.
196 # force the height to "unlimited", so no pagers get used
197 send_gdb "100-gdb-set height 0\n"
198 gdb_expect 10 {
199 -re ".*100-gdb-set height 0\r\n100\\\^done\r\n$mi_gdb_prompt$" {
200 verbose "Setting height to 0." 2
202 timeout {
203 warning "Couldn't set the height to 0"
206 # force the width to "unlimited", so no wraparound occurs
207 send_gdb "101-gdb-set width 0\n"
208 gdb_expect 10 {
209 -re ".*101-gdb-set width 0\r\n101\\\^done\r\n$mi_gdb_prompt$" {
210 verbose "Setting width to 0." 2
212 timeout {
213 warning "Couldn't set the width to 0."
216 # If allowing the inferior to have its own PTY then assign the inferior
217 # its own terminal device here.
218 if { $separate_inferior_pty } {
219 send_gdb "102-inferior-tty-set $mi_inferior_tty_name\n"
220 gdb_expect 10 {
221 -re ".*102\\\^done\r\n$mi_gdb_prompt$" {
222 verbose "redirect inferior output to new terminal device."
224 timeout {
225 warning "Couldn't redirect inferior output." 2
230 return 0;
233 # Many of the tests depend on setting breakpoints at various places and
234 # running until that breakpoint is reached. At times, we want to start
235 # with a clean-slate with respect to breakpoints, so this utility proc
236 # lets us do this without duplicating this code everywhere.
239 proc mi_delete_breakpoints {} {
240 global mi_gdb_prompt
242 # FIXME: The mi operation won't accept a prompt back and will use the 'all' arg
243 send_gdb "102-break-delete\n"
244 gdb_expect 30 {
245 -re "Delete all breakpoints.*y or n.*$" {
246 send_gdb "y\n";
247 exp_continue
249 -re "102-break-delete\r\n102\\\^done\r\n$mi_gdb_prompt$" {
250 # This happens if there were no breakpoints
252 timeout { perror "Delete all breakpoints in mi_delete_breakpoints (timeout)" ; return }
255 # The correct output is not "No breakpoints or watchpoints." but an
256 # empty BreakpointTable. Also, a query is not acceptable with mi.
257 send_gdb "103-break-list\n"
258 gdb_expect 30 {
259 -re "103-break-list\r\n103\\\^done,BreakpointTable=\{\}\r\n$mi_gdb_prompt$" {}
260 -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=\\\[\\\]\}" {}
261 -re "103-break-list\r\n103\\\^doneNo breakpoints or watchpoints.\r\n\r\n$mi_gdb_prompt$" {warning "Unexpected console text received"}
262 -re "$mi_gdb_prompt$" { perror "Breakpoints not deleted" ; return }
263 -re "Delete all breakpoints.*or n.*$" {
264 warning "Unexpected prompt for breakpoints deletion";
265 send_gdb "y\n";
266 exp_continue
268 timeout { perror "-break-list (timeout)" ; return }
272 proc mi_gdb_reinitialize_dir { subdir } {
273 global mi_gdb_prompt
274 global MIFLAGS
276 global suppress_flag
277 if { $suppress_flag } {
278 return
281 if [is_remote host] {
282 return "";
285 if { $MIFLAGS == "-i=mi1" } {
286 send_gdb "104-environment-directory\n"
287 gdb_expect 60 {
288 -re ".*Reinitialize source path to empty.*y or n. " {
289 warning "Got confirmation prompt for dir reinitialization."
290 send_gdb "y\n"
291 gdb_expect 60 {
292 -re "$mi_gdb_prompt$" {}
293 timeout {error "Dir reinitialization failed (timeout)"}
296 -re "$mi_gdb_prompt$" {}
297 timeout {error "Dir reinitialization failed (timeout)"}
299 } else {
300 send_gdb "104-environment-directory -r\n"
301 gdb_expect 60 {
302 -re "104\\\^done,source-path=.*\r\n$mi_gdb_prompt$" {}
303 -re "$mi_gdb_prompt$" {}
304 timeout {error "Dir reinitialization failed (timeout)"}
308 send_gdb "105-environment-directory $subdir\n"
309 gdb_expect 60 {
310 -re "Source directories searched.*$mi_gdb_prompt$" {
311 verbose "Dir set to $subdir"
313 -re "105\\\^done.*\r\n$mi_gdb_prompt$" {
314 # FIXME: We return just the prompt for now.
315 verbose "Dir set to $subdir"
316 # perror "Dir \"$subdir\" failed."
321 # Send GDB the "target" command.
322 # FIXME: Some of these patterns are not appropriate for MI. Based on
323 # config/monitor.exp:gdb_target_command.
324 proc mi_gdb_target_cmd { targetname serialport } {
325 global mi_gdb_prompt
327 for {set i 1} {$i <= 3} {incr i} {
328 send_gdb "47-target-select $targetname $serialport\n"
329 gdb_expect 60 {
330 -re "47\\^connected.*$mi_gdb_prompt$" {
331 verbose "Set target to $targetname";
332 return 0;
334 -re "Couldn't establish connection to remote.*$mi_gdb_prompt$" {
335 verbose "Connection failed";
337 -re "Remote MIPS debugging.*$mi_gdb_prompt$" {
338 verbose "Set target to $targetname";
339 return 0;
341 -re "Remote debugging using .*$serialport.*$mi_gdb_prompt$" {
342 verbose "Set target to $targetname";
343 return 0;
345 -re "Remote target $targetname connected to.*$mi_gdb_prompt$" {
346 verbose "Set target to $targetname";
347 return 0;
349 -re "Connected to.*$mi_gdb_prompt$" {
350 verbose "Set target to $targetname";
351 return 0;
353 -re "Ending remote.*$mi_gdb_prompt$" { }
354 -re "Connection refused.*$mi_gdb_prompt$" {
355 verbose "Connection refused by remote target. Pausing, and trying again."
356 sleep 5
357 continue
359 -re "Timeout reading from remote system.*$mi_gdb_prompt$" {
360 verbose "Got timeout error from gdb.";
362 timeout {
363 send_gdb "\x03";
364 break
368 return 1
372 # load a file into the debugger (file command only).
373 # return a -1 if anything goes wrong.
375 proc mi_gdb_file_cmd { arg } {
376 global verbose
377 global loadpath
378 global loadfile
379 global GDB
380 global mi_gdb_prompt
381 global last_mi_gdb_file
382 global last_mi_remote_file
383 upvar timeout timeout
385 if { $arg == "" } {
386 set arg $last_mi_gdb_file;
387 } else {
388 set last_mi_gdb_file $arg
389 if { [ info exists last_mi_remote_file ] } {
390 unset last_mi_remote_file
394 if [is_remote host] {
395 set arg [remote_download host $arg];
396 if { $arg == "" } {
397 error "download failed"
398 return -1;
402 # FIXME: Several of these patterns are only acceptable for console
403 # output. Queries are an error for mi.
404 send_gdb "105-file-exec-and-symbols $arg\n"
405 gdb_expect 120 {
406 -re "Reading symbols from.*done.*$mi_gdb_prompt$" {
407 verbose "\t\tLoaded $arg into the $GDB"
408 return 0
410 -re "has no symbol-table.*$mi_gdb_prompt$" {
411 perror "$arg wasn't compiled with \"-g\""
412 return -1
414 -re "A program is being debugged already.*Kill it.*y or n. $" {
415 send_gdb "y\n"
416 verbose "\t\tKilling previous program being debugged"
417 exp_continue
419 -re "Load new symbol table from \".*\".*y or n. $" {
420 send_gdb "y\n"
421 gdb_expect 120 {
422 -re "Reading symbols from.*done.*$mi_gdb_prompt$" {
423 verbose "\t\tLoaded $arg with new symbol table into $GDB"
424 # All OK
426 timeout {
427 perror "(timeout) Couldn't load $arg, other program already loaded."
428 return -1
432 -re "No such file or directory.*$mi_gdb_prompt$" {
433 perror "($arg) No such file or directory\n"
434 return -1
436 -re "105-file-exec-and-symbols .*\r\n105\\\^done\r\n$mi_gdb_prompt$" {
437 # We (MI) are just giving the prompt back for now, instead of giving
438 # some acknowledgement.
439 return 0
441 timeout {
442 perror "couldn't load $arg into $GDB (timed out)."
443 return -1
445 eof {
446 # This is an attempt to detect a core dump, but seems not to
447 # work. Perhaps we need to match .* followed by eof, in which
448 # gdb_expect does not seem to have a way to do that.
449 perror "couldn't load $arg into $GDB (end of file)."
450 return -1
456 # load a file into the debugger.
457 # return a -1 if anything goes wrong.
459 proc mi_gdb_load { arg } {
460 global verbose
461 global loadpath
462 global loadfile
463 global GDB
464 global mi_gdb_prompt
465 upvar timeout timeout
467 # ``gdb_unload''
468 if { $arg != "" } {
469 mi_gdb_file_cmd $arg
472 # ``load''
473 if { [info procs gdbserver_gdb_load] != "" } {
474 global last_mi_gdb_file
475 global last_mi_remote_file
477 if { ! [info exists last_mi_remote_file] } {
478 if [is_remote target] {
479 set last_mi_remote_file [remote_download target $arg /tmp/[file tail $arg].[pid]]
480 } else {
481 set last_mi_remote_file $last_mi_gdb_file
485 set res [gdbserver_gdb_load $last_mi_remote_file]
486 set protocol [lindex $res 0]
487 set gdbport [lindex $res 1]
489 if { [mi_gdb_target_cmd $protocol $gdbport] != 0 } {
490 return -1
492 } elseif { [info procs send_target_sid] != "" } {
493 # For SID, things get complex
494 send_target_sid
495 gdb_expect 60 {
496 -re "\\^done.*$mi_gdb_prompt$" {
498 timeout {
499 perror "Unable to connect to SID target"
500 return -1
503 send_gdb "48-target-download\n"
504 gdb_expect 10 {
505 -re "48\\^done.*$mi_gdb_prompt$" {
507 timeout {
508 perror "Unable to download to SID target"
509 return -1
512 } elseif { [target_info protocol] == "sim" } {
513 # For the simulator, just connect to it directly.
514 send_gdb "47-target-select sim\n"
515 gdb_expect 10 {
516 -re "47\\^connected.*$mi_gdb_prompt$" {
518 timeout {
519 perror "Unable to select sim target"
520 return -1
523 send_gdb "48-target-download\n"
524 gdb_expect 10 {
525 -re "48\\^done.*$mi_gdb_prompt$" {
527 timeout {
528 perror "Unable to download to sim target"
529 return -1
532 } elseif { [target_info gdb_protocol] == "remote" } {
533 # remote targets
534 if { [mi_gdb_target_cmd "remote" [target_info netport]] != 0 } {
535 perror "Unable to connect to remote target"
536 return -1
538 send_gdb "48-target-download\n"
539 gdb_expect 10 {
540 -re "48\\^done.*$mi_gdb_prompt$" {
542 timeout {
543 perror "Unable to download to remote target"
544 return -1
548 return 0
551 # mi_gdb_test COMMAND PATTERN MESSAGE [IPATTERN] -- send a command to gdb;
552 # test the result.
554 # COMMAND is the command to execute, send to GDB with send_gdb. If
555 # this is the null string no command is sent.
556 # PATTERN is the pattern to match for a PASS, and must NOT include
557 # the \r\n sequence immediately before the gdb prompt.
558 # MESSAGE is the message to be printed. (If this is the empty string,
559 # then sometimes we don't call pass or fail at all; I don't
560 # understand this at all.)
561 # IPATTERN is the pattern to match for the inferior's output. This parameter
562 # is optional. If present, it will produce a PASS if the match is
563 # successful, and a FAIL if unsuccessful.
565 # Returns:
566 # 1 if the test failed,
567 # 0 if the test passes,
568 # -1 if there was an internal error.
570 proc mi_gdb_test { args } {
571 global verbose
572 global mi_gdb_prompt
573 global GDB expect_out
574 upvar timeout timeout
576 set command [lindex $args 0]
577 set pattern [lindex $args 1]
578 set message [lindex $args 2]
580 if [llength $args]==4 {
581 set ipattern [lindex $args 3]
584 if [llength $args]==5 {
585 set question_string [lindex $args 3];
586 set response_string [lindex $args 4];
587 } else {
588 set question_string "^FOOBAR$"
591 if $verbose>2 then {
592 send_user "Sending \"$command\" to gdb\n"
593 send_user "Looking to match \"$pattern\"\n"
594 send_user "Message is \"$message\"\n"
597 set result -1
598 set string "${command}\n";
599 set string_regex [string_to_regexp $command]
601 if { $command != "" } {
602 while { "$string" != "" } {
603 set foo [string first "\n" "$string"];
604 set len [string length "$string"];
605 if { $foo < [expr $len - 1] } {
606 set str [string range "$string" 0 $foo];
607 if { [send_gdb "$str"] != "" } {
608 global suppress_flag;
610 if { ! $suppress_flag } {
611 perror "Couldn't send $command to GDB.";
613 fail "$message";
614 return $result;
616 gdb_expect 2 {
617 -re "\[\r\n\]" { }
618 timeout { }
620 set string [string range "$string" [expr $foo + 1] end];
621 } else {
622 break;
625 if { "$string" != "" } {
626 if { [send_gdb "$string"] != "" } {
627 global suppress_flag;
629 if { ! $suppress_flag } {
630 perror "Couldn't send $command to GDB.";
632 fail "$message";
633 return $result;
638 if [info exists timeout] {
639 set tmt $timeout;
640 } else {
641 global timeout;
642 if [info exists timeout] {
643 set tmt $timeout;
644 } else {
645 set tmt 60;
648 gdb_expect $tmt {
649 -re "\\*\\*\\* DOSEXIT code.*" {
650 if { $message != "" } {
651 fail "$message";
653 gdb_suppress_entire_file "GDB died";
654 return -1;
656 -re "Ending remote debugging.*$mi_gdb_prompt\[ \]*$" {
657 if ![isnative] then {
658 warning "Can`t communicate to remote target."
660 gdb_exit
661 gdb_start
662 set result -1
664 -re "^($string_regex\[\r\n\]+)?($pattern\[\r\n\]+$mi_gdb_prompt\[ \]*)" {
665 # At this point, $expect_out(1,string) is the MI input command.
666 # and $expect_out(2,string) is the MI output command.
667 # If $expect_out(1,string) is "", then there was no MI input command here.
669 # NOTE, there is no trailing anchor because with GDB/MI,
670 # asynchronous responses can happen at any point, causing more
671 # data to be available. Normally an anchor is used to make
672 # sure the end of the output is matched, however, $mi_gdb_prompt
673 # is just as good of an anchor since mi_gdb_test is meant to
674 # match a single mi output command. If a second GDB/MI output
675 # response is sent, it will be in the buffer for the next
676 # time mi_gdb_test is called.
677 if ![string match "" $message] then {
678 pass "$message"
680 set result 0
682 -re "(${question_string})$" {
683 send_gdb "$response_string\n";
684 exp_continue;
686 -re "Undefined.* command:.*$mi_gdb_prompt\[ \]*$" {
687 perror "Undefined command \"$command\"."
688 fail "$message"
689 set result 1
691 -re "Ambiguous command.*$mi_gdb_prompt\[ \]*$" {
692 perror "\"$command\" is not a unique command name."
693 fail "$message"
694 set result 1
696 -re "Program exited with code \[0-9\]+.*$mi_gdb_prompt\[ \]*$" {
697 if ![string match "" $message] then {
698 set errmsg "$message (the program exited)"
699 } else {
700 set errmsg "$command (the program exited)"
702 fail "$errmsg"
703 return -1
705 -re "The program is not being run.*$mi_gdb_prompt\[ \]*$" {
706 if ![string match "" $message] then {
707 set errmsg "$message (the program is no longer running)"
708 } else {
709 set errmsg "$command (the program is no longer running)"
711 fail "$errmsg"
712 return -1
714 -re ".*$mi_gdb_prompt\[ \]*$" {
715 if ![string match "" $message] then {
716 fail "$message"
718 set result 1
720 "<return>" {
721 send_gdb "\n"
722 perror "Window too small."
723 fail "$message"
725 -re "\\(y or n\\) " {
726 send_gdb "n\n"
727 perror "Got interactive prompt."
728 fail "$message"
730 eof {
731 perror "Process no longer exists"
732 if { $message != "" } {
733 fail "$message"
735 return -1
737 full_buffer {
738 perror "internal buffer is full."
739 fail "$message"
741 timeout {
742 if ![string match "" $message] then {
743 fail "$message (timeout)"
745 set result 1
749 # If the GDB output matched, compare the inferior output.
750 if { $result == 0 } {
751 if [ info exists ipattern ] {
752 global mi_inferior_spawn_id
753 expect {
754 -i $mi_inferior_spawn_id -re "$ipattern" {
755 pass "inferior_output:$message"
757 timeout {
758 fail "inferior output timeout"
759 set result 1
765 return $result
769 # MI run command. (A modified version of gdb_run_cmd)
772 # In patterns, the newline sequence ``\r\n'' is matched explicitly as
773 # ``.*$'' could swallow up output that we attempt to match elsewhere.
775 proc mi_run_cmd {args} {
776 global suppress_flag
777 if { $suppress_flag } {
778 return -1
780 global mi_gdb_prompt
782 if [target_info exists gdb_init_command] {
783 send_gdb "[target_info gdb_init_command]\n";
784 gdb_expect 30 {
785 -re "$mi_gdb_prompt$" { }
786 default {
787 perror "gdb_init_command for target failed";
788 return;
793 if [target_info exists use_gdb_stub] {
794 if [target_info exists gdb,do_reload_on_run] {
795 # Specifying no file, defaults to the executable
796 # currently being debugged.
797 if { [mi_gdb_load ""] < 0 } {
798 return;
800 send_gdb "000-exec-continue\n";
801 gdb_expect 60 {
802 -re "000\\^running\[\r\n\]+$mi_gdb_prompt$" {}
803 default {}
805 return;
808 if [target_info exists gdb,start_symbol] {
809 set start [target_info gdb,start_symbol];
810 } else {
811 set start "start";
814 # HACK: Should either use 000-jump or fix the target code
815 # to better handle RUN.
816 send_gdb "jump *$start\n"
817 warning "Using CLI jump command, expect run-to-main FAIL"
818 return
821 send_gdb "000-exec-run $args\n"
822 gdb_expect {
823 -re "000\\^running\r\n${mi_gdb_prompt}" {
825 timeout {
826 perror "Unable to start target"
827 return
830 # NOTE: Shortly after this there will be a ``000*stopping,...(gdb)''
834 # Just like run-to-main but works with the MI interface
837 proc mi_run_to_main { } {
838 global suppress_flag
839 if { $suppress_flag } {
840 return -1
843 global srcdir
844 global subdir
845 global binfile
846 global srcfile
848 mi_delete_breakpoints
849 mi_gdb_reinitialize_dir $srcdir/$subdir
850 mi_gdb_load ${binfile}
852 mi_runto main
856 # Just like gdb's "runto" proc, it will run the target to a given
857 # function. The big difference here between mi_runto and mi_execute_to
858 # is that mi_execute_to must have the inferior running already. This
859 # proc will (like gdb's runto) (re)start the inferior, too.
861 # FUNC is the linespec of the place to stop (it inserts a breakpoint here).
862 # It returns:
863 # -1 if test suppressed, failed, timedout
864 # 0 if test passed
866 proc mi_runto {func} {
867 global suppress_flag
868 if { $suppress_flag } {
869 return -1
872 global mi_gdb_prompt expect_out
873 global hex decimal fullname_syntax
875 set test "mi runto $func"
876 mi_gdb_test "200-break-insert $func" \
877 "200\\^done,bkpt=\{number=\"\[0-9\]+\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"$func\",file=\".*\",line=\"\[0-9\]*\",times=\"0\"\}" \
878 "breakpoint at $func"
880 if {![regexp {number="[0-9]+"} $expect_out(buffer) str]
881 || ![scan $str {number="%d"} bkptno]} {
882 set bkptno {[0-9]+}
885 mi_run_cmd
886 gdb_expect {
887 -re ".*000\\*stopped,reason=\"breakpoint-hit\",bkptno=\"$bkptno\",thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\"$func\",args=\(\\\[.*\\\]\|\{.*\}\),file=\".*\",fullname=\"${fullname_syntax}.*\",line=\"\[0-9\]*\"\}\r\n$mi_gdb_prompt$" {
888 pass "$test"
889 return 0
891 -re ".*$mi_gdb_prompt$" {
892 fail "$test (2)"
894 timeout {
895 fail "$test (timeout)"
896 return -1
902 # Next to the next statement
903 # For return values, see mi_execute_to_helper
905 proc mi_next { test } {
906 return [mi_next_to {.*} {.*} {.*} {.*} $test]
910 # Step to the next statement
911 # For return values, see mi_execute_to_helper
913 proc mi_step { test } {
914 return [mi_step_to {.*} {.*} {.*} {.*} $test]
917 # cmd should not include the number or newline (i.e. "exec-step 3", not
918 # "220-exec-step 3\n"
920 # Can not match -re ".*\r\n${mi_gdb_prompt}", because of false positives
921 # after the first prompt is printed.
923 proc mi_execute_to_helper { cmd reason func args file line extra test } {
924 global suppress_flag
925 if { $suppress_flag } {
926 return -1
928 global mi_gdb_prompt
929 global hex
930 global decimal
931 global fullname_syntax
932 send_gdb "220-$cmd\n"
933 gdb_expect {
934 -re "220\\^running\r\n${mi_gdb_prompt}.*220\\*stopped,reason=\"$reason\",thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\"$func\",args=$args,file=\".*$file\",fullname=\"${fullname_syntax}$file\",line=\"$line\"\}$extra\r\n$mi_gdb_prompt$" {
935 pass "$test"
936 return 0
938 -re "220\\^running\r\n${mi_gdb_prompt}.*220\\*stopped,reason=\"$reason\",thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\".*\",args=\[\\\[\{\].*\[\\\]\}\],file=\".*\",fullname=\"${fullname_syntax}.*\",line=\"\[0-9\]*\"\}.*\r\n$mi_gdb_prompt$" {
939 fail "$test (stopped at wrong place)"
940 return -1
942 -re "220\\^running\r\n${mi_gdb_prompt}.*\r\n${mi_gdb_prompt}$" {
943 fail "$test (unknown output after running)"
944 return -1
946 timeout {
947 fail "$test (timeout)"
948 return -1
953 proc mi_execute_to { cmd reason func args file line extra test } {
954 mi_execute_to_helper "$cmd" "$reason" "$func" "\\\[$args\\\]" \
955 "$file" "$line" "$extra" "$test"
958 proc mi_next_to { func args file line test } {
959 mi_execute_to "exec-next" "end-stepping-range" "$func" "$args" \
960 "$file" "$line" "" "$test"
963 proc mi_step_to { func args file line test } {
964 mi_execute_to "exec-step" "end-stepping-range" "$func" "$args" \
965 "$file" "$line" "" "$test"
968 proc mi_finish_to { func args file line result ret test } {
969 mi_execute_to "exec-finish" "function-finished" "$func" "$args" \
970 "$file" "$line" \
971 ",gdb-result-var=\"$result\",return-value=\"$ret\"" \
972 "$test"
975 proc mi_continue_to { bkptno func args file line test } {
976 mi_execute_to "exec-continue" "breakpoint-hit\",bkptno=\"$bkptno" \
977 "$func" "$args" "$file" "$line" "" "$test"
980 proc mi0_execute_to { cmd reason func args file line extra test } {
981 mi_execute_to_helper "$cmd" "$reason" "$func" "\{$args\}" \
982 "$file" "$line" "$extra" "$test"
985 proc mi0_next_to { func args file line test } {
986 mi0_execute_to "exec-next" "end-stepping-range" "$func" "$args" \
987 "$file" "$line" "" "$test"
990 proc mi0_step_to { func args file line test } {
991 mi0_execute_to "exec-step" "end-stepping-range" "$func" "$args" \
992 "$file" "$line" "" "$test"
995 proc mi0_finish_to { func args file line result ret test } {
996 mi0_execute_to "exec-finish" "function-finished" "$func" "$args" \
997 "$file" "$line" \
998 ",gdb-result-var=\"$result\",return-value=\"$ret\"" \
999 "$test"
1002 proc mi0_continue_to { bkptno func args file line test } {
1003 mi0_execute_to "exec-continue" "breakpoint-hit\",bkptno=\"$bkptno" \
1004 "$func" "$args" "$file" "$line" "" "$test"