1 # Copyright 1999-2023 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 3 of the License, or
6 # (at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
16 # This file was based on a file written by Fred Fish. (fnf@cygnus.com)
18 # Test setup routines that work with the MI interpreter.
20 load_lib gdb-utils.exp
22 # The variable mi_gdb_prompt is a regexp which matches the gdb mi prompt.
23 # Set it if it is not already set.
25 if {![info exists mi_gdb_prompt]} {
26 set mi_gdb_prompt "\[(\]gdb\[)\] \r\n"
29 global mi_inferior_tty_name
31 # Always points to GDB's main UI spawn ID, even when testing with MI
32 # running on a secondary UI.
33 global gdb_main_spawn_id
35 # Points to the spawn id of the MI channel. When testing with MI
36 # running as the primary/main UI, this is the same as
37 # gdb_main_spawn_id, but will be different when testing with MI
38 # running on a secondary UI.
43 set thread_selected_re "=thread-selected,id=\"\[0-9\]+\"\r\n"
44 set gdbindex_warning_re "&\"warning: Skipping \[^\r\n\]+ \.gdb_index section in \[^\r\n\]+\"\r\n(?:&\"\\\\n\"\r\n)?"
45 set library_loaded_re "=library-loaded\[^\n\]+\"\r\n(?:$gdbindex_warning_re)?"
46 set breakpoint_re "=(?:breakpoint-created|breakpoint-deleted)\[^\n\]+\"\r\n"
49 # mi_gdb_exit -- exit the GDB, killing the target program if necessary
52 catch mi_uncatched_gdb_exit
55 proc mi_uncatched_gdb_exit {} {
57 global INTERNAL_GDBFLAGS GDBFLAGS
58 global gdb_spawn_id gdb_main_spawn_id
59 global mi_spawn_id inferior_spawn_id
64 if { [info procs sid_exit] != "" } {
68 if ![info exists gdb_spawn_id] {
72 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $MIFLAGS"
74 if { [is_remote host] && [board_info host exists fileid] } {
75 send_gdb "999-gdb-exit\n"
81 -re "Undefined command.*$gdb_prompt $" {
85 -re "DOSEXIT code" { }
86 -re "\r\n999\\^exit\r\n" { }
90 # Switch back to the main spawn id, so that remote_close below
91 # closes it, and not a secondary channel. Closing a secondary
92 # channel does not make GDB exit.
93 if {$gdb_spawn_id != $gdb_main_spawn_id} {
94 switch_gdb_spawn_id $gdb_main_spawn_id
97 # Close secondary MI channel, if there's one.
98 if {$mi_spawn_id != $gdb_main_spawn_id} {
102 if ![is_remote host] {
106 unset gdb_main_spawn_id
108 unset inferior_spawn_id
111 # Create the PTY for the inferior process and tell GDB about it.
113 proc mi_create_inferior_pty {} {
115 global inferior_spawn_id
116 global mi_inferior_tty_name
119 set inferior_spawn_id $spawn_id
120 set tty_name $spawn_out(slave,name)
121 set mi_inferior_tty_name $tty_name
123 send_gdb "102-inferior-tty-set $tty_name\n"
125 -re ".*102\\\^done\r\n$mi_gdb_prompt$" {
126 verbose "redirect inferior output to new terminal device."
129 warning "Couldn't redirect inferior output." 2
135 # Like default_mi_gdb_start below, but the MI is created as a separate
136 # ui in a new tty. The global MI_SPAWN_ID is updated to point at the
137 # new tty created for the MI interface. The global GDB_MAIN_SPAWN_ID
138 # is updated to the current value of the global GDB_SPAWN_ID.
140 proc mi_gdb_start_separate_mi_tty { { flags {} } } {
141 global gdb_prompt mi_gdb_prompt
143 global gdb_spawn_id gdb_main_spawn_id mi_spawn_id
144 global inferior_spawn_id
146 set separate_inferior_pty 0
148 foreach flag $flags {
149 if {$flag == "separate-inferior-tty"} {
150 set separate_inferior_pty 1
156 # Create the new PTY for the MI UI.
158 set mi_spawn_id $spawn_id
159 set mi_tty_name $spawn_out(slave,name)
160 gdb_test_multiple "new-ui mi $mi_tty_name" "new-ui" {
161 -re "New UI allocated\r\n$gdb_prompt $" {
165 # Switch to the MI channel.
166 set gdb_main_spawn_id $gdb_spawn_id
167 switch_gdb_spawn_id $mi_spawn_id
169 # Consume pending output and MI prompt.
171 -re "$mi_gdb_prompt$" {
174 perror "MI channel failed"
180 if {$separate_inferior_pty} {
181 mi_create_inferior_pty
190 # default_mi_gdb_start [FLAGS] -- start gdb running, default procedure
192 # FLAGS is a list of flags, each flag is a string.
194 # If "separate-inferior-tty" is specified, the inferior works with
197 # If "separate-mi-tty" is specified, the gdb starts in CLI mode, with
198 # MI running on a secondary UI, on its own tty.
200 # When running over NFS, particularly if running many simultaneous
201 # tests on different hosts all using the same server, things can
202 # get really slow. Give gdb at least 3 minutes to start up.
204 proc default_mi_gdb_start { { flags {} } } {
207 global INTERNAL_GDBFLAGS GDBFLAGS
211 global gdb_spawn_id gdb_main_spawn_id inferior_spawn_id mi_spawn_id
213 global FORCE_SEPARATE_MI_TTY
215 # Keep track of the number of times GDB has been launched.
221 if {[info exists FORCE_SEPARATE_MI_TTY]} {
222 set separate_mi_pty $FORCE_SEPARATE_MI_TTY
224 set separate_mi_pty 0
227 set separate_inferior_pty 0
229 foreach flag $flags {
230 if {$flag == "separate-mi-tty"} {
231 set separate_mi_pty 1
232 } elseif {$flag == "separate-inferior-tty"} {
233 set separate_inferior_pty 1
237 if {$separate_mi_pty} {
238 return [mi_gdb_start_separate_mi_tty $flags]
241 # Set the default value, it may be overriden later by specific testfile.
242 set use_gdb_stub [target_info exists use_gdb_stub]
245 if { [info procs sid_start] != "" } {
246 verbose "Spawning SID"
250 if [info exists gdb_spawn_id] {
254 save_vars { GDBFLAGS } {
255 append GDBFLAGS " $MIFLAGS"
264 -re "~\"GNU.*\r\n~\".*$mi_gdb_prompt$" {
265 # We have a new format mi startup prompt.
266 verbose "GDB initialized."
268 -re ".*unrecognized option.*for a complete list of options." {
269 untested "skip mi tests (not compiled with mi support)."
274 -re ".*Interpreter `mi' unrecognized." {
275 untested "skip mi tests (not compiled with mi support)."
281 perror "(timeout) GDB never initialized after 10 seconds."
287 set gdb_main_spawn_id $gdb_spawn_id
288 set mi_spawn_id $gdb_spawn_id
290 # FIXME: mi output does not go through pagers, so these can be removed.
291 # force the height to "unlimited", so no pagers get used
292 send_gdb "100-gdb-set height 0\n"
294 -re ".*100-gdb-set height 0\r\n100\\\^done\r\n$mi_gdb_prompt$" {
295 verbose "Setting height to 0." 2
298 warning "Couldn't set the height to 0"
301 # force the width to "unlimited", so no wraparound occurs
302 send_gdb "101-gdb-set width 0\n"
304 -re ".*101-gdb-set width 0\r\n101\\\^done\r\n$mi_gdb_prompt$" {
305 verbose "Setting width to 0." 2
308 warning "Couldn't set the width to 0."
312 if { $separate_inferior_pty } {
313 mi_create_inferior_pty
316 if {![info exists inferior_spawn_id]} {
317 set inferior_spawn_id $gdb_spawn_id
326 # Overridable function. You can override this function in your
329 proc mi_gdb_start { args } {
330 return [eval default_mi_gdb_start $args]
333 # Many of the tests depend on setting breakpoints at various places and
334 # running until that breakpoint is reached. At times, we want to start
335 # with a clean-slate with respect to breakpoints, so this utility proc
336 # lets us do this without duplicating this code everywhere.
339 proc mi_delete_breakpoints {} {
342 # FIXME: The mi operation won't accept a prompt back and will use the 'all' arg
343 send_gdb "102-break-delete\n"
345 -re "Delete all breakpoints.*y or n.*$" {
349 -re "102-break-delete\r\n102\\\^done\r\n$mi_gdb_prompt$" {
350 # This happens if there were no breakpoints
352 timeout { perror "Delete all breakpoints in mi_delete_breakpoints (timeout)" ; return }
355 # The correct output is not "No breakpoints or watchpoints." but an
356 # empty BreakpointTable. Also, a query is not acceptable with mi.
357 send_gdb "103-break-list\n"
359 -re "103-break-list\r\n103\\\^done,BreakpointTable=\{\}\r\n$mi_gdb_prompt$" {}
360 -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=\\\[\\\]\}\r\n$mi_gdb_prompt$" {}
361 -re "103-break-list\r\n103\\\^doneNo breakpoints or watchpoints.\r\n\r\n$mi_gdb_prompt$" {warning "Unexpected console text received"}
362 -re "$mi_gdb_prompt$" { perror "Breakpoints not deleted" ; return }
363 -re "Delete all breakpoints.*or n.*$" {
364 warning "Unexpected prompt for breakpoints deletion"
368 timeout { perror "-break-list (timeout)" ; return }
372 proc mi_gdb_reinitialize_dir { subdir } {
376 if [is_remote host] {
380 send_gdb "104-environment-directory -r\n"
382 -re "104\\\^done,source-path=.*\r\n$mi_gdb_prompt$" {}
383 -re "$mi_gdb_prompt$" {}
384 timeout {error "Dir reinitialization failed (timeout)"}
387 send_gdb "105-environment-directory $subdir\n"
389 -re "Source directories searched.*$mi_gdb_prompt$" {
390 verbose "Dir set to $subdir"
392 -re "105\\\^done.*\r\n$mi_gdb_prompt$" {
393 # FIXME: We return just the prompt for now.
394 verbose "Dir set to $subdir"
395 # perror "Dir \"$subdir\" failed."
400 # Send GDB the "target" command.
401 # FIXME: Some of these patterns are not appropriate for MI. Based on
402 # config/monitor.exp:gdb_target_command.
403 proc mi_gdb_target_cmd { targetname serialport } {
406 set serialport_re [string_to_regexp $serialport]
407 for {set i 1} {$i <= 3} {incr i} {
408 send_gdb "47-target-select $targetname $serialport\n"
410 -re "47\\^connected.*$mi_gdb_prompt" {
411 verbose "Set target to $targetname"
414 -re "unknown host.*$mi_gdb_prompt" {
415 verbose "Couldn't look up $serialport"
417 -re "Couldn't establish connection to remote.*$mi_gdb_prompt$" {
418 verbose "Connection failed"
420 -re "Remote MIPS debugging.*$mi_gdb_prompt$" {
421 verbose "Set target to $targetname"
424 -re "Remote debugging using .*$serialport_re.*$mi_gdb_prompt$" {
425 verbose "Set target to $targetname"
428 -re "Remote target $targetname connected to.*$mi_gdb_prompt$" {
429 verbose "Set target to $targetname"
432 -re "Connected to.*$mi_gdb_prompt$" {
433 verbose "Set target to $targetname"
436 -re "Ending remote.*$mi_gdb_prompt$" { }
437 -re "Connection refused.*$mi_gdb_prompt$" {
438 verbose "Connection refused by remote target. Pausing, and trying again."
442 -re "Non-stop mode requested, but remote does not support non-stop.*$mi_gdb_prompt" {
443 unsupported "non-stop mode not supported"
446 -re "Timeout reading from remote system.*$mi_gdb_prompt$" {
447 verbose "Got timeout error from gdb."
459 # load a file into the debugger (file command only).
460 # return a -1 if anything goes wrong.
462 proc mi_gdb_file_cmd { arg } {
467 global last_loaded_file
468 upvar timeout timeout
470 # GCC for Windows target may create foo.exe given "-o foo".
471 if { ![file exists $arg] && [file exists "$arg.exe"] } {
475 set last_loaded_file $arg
477 if [is_remote host] {
478 set arg [remote_download host $arg]
480 error "download failed"
485 # FIXME: Several of these patterns are only acceptable for console
486 # output. Queries are an error for mi.
487 send_gdb "105-file-exec-and-symbols $arg\n"
489 -re "Reading symbols from.*$mi_gdb_prompt$" {
490 verbose "\t\tLoaded $arg into the $GDB"
493 -re "has no symbol-table.*$mi_gdb_prompt$" {
494 perror "$arg wasn't compiled with \"-g\""
497 -re "Load new symbol table from \".*\".*y or n. $" {
500 -re "Reading symbols from.*$mi_gdb_prompt$" {
501 verbose "\t\tLoaded $arg with new symbol table into $GDB"
505 perror "(timeout) Couldn't load $arg, other program already loaded."
510 -re "No such file or directory.*$mi_gdb_prompt$" {
511 perror "($arg) No such file or directory\n"
514 -re "105-file-exec-and-symbols .*\r\n105\\\^done\r\n$mi_gdb_prompt$" {
515 # We (MI) are just giving the prompt back for now, instead of giving
516 # some acknowledgement.
520 perror "couldn't load $arg into $GDB (timed out)."
524 # This is an attempt to detect a core dump, but seems not to
525 # work. Perhaps we need to match .* followed by eof, in which
526 # gdb_expect does not seem to have a way to do that.
527 perror "couldn't load $arg into $GDB (end of file)."
534 # connect to the target and download a file, if necessary.
535 # return a -1 if anything goes wrong.
537 proc mi_gdb_target_load { } {
543 if [target_info exists gdb_load_timeout] {
544 set loadtimeout [target_info gdb_load_timeout]
549 if { [info procs gdbserver_gdb_load] != "" } {
550 mi_gdb_test "kill" ".*" ""
551 if { [catch gdbserver_gdb_load res] == 1 } {
555 set protocol [lindex $res 0]
556 set gdbport [lindex $res 1]
558 if { [mi_gdb_target_cmd $protocol $gdbport] != 0 } {
561 } elseif { [info procs send_target_sid] != "" } {
562 # For SID, things get complex
565 -re ".*$mi_gdb_prompt$"
568 gdb_expect $loadtimeout {
569 -re "\\^done.*$mi_gdb_prompt$" {
572 perror "Unable to connect to SID target (timeout)"
576 send_gdb "48-target-download\n"
577 gdb_expect $loadtimeout {
578 -re "48\\^done.*$mi_gdb_prompt$" {
581 perror "Unable to download to SID target (timeout)"
585 } elseif { [target_info protocol] == "sim" } {
586 set target_sim_options "[board_info target gdb,target_sim_options]"
587 # For the simulator, just connect to it directly.
588 send_gdb "47-target-select sim $target_sim_options\n"
589 gdb_expect $loadtimeout {
590 -re "47\\^connected.*$mi_gdb_prompt$" {
593 perror "Unable to select sim target (timeout)"
597 send_gdb "48-target-download\n"
598 gdb_expect $loadtimeout {
599 -re "48\\^done.*$mi_gdb_prompt$" {
602 perror "Unable to download to sim target (timeout)"
606 } elseif { [target_info gdb_protocol] == "remote" } {
608 if { [mi_gdb_target_cmd "remote" [target_info netport]] != 0 } {
609 perror "Unable to connect to remote target"
612 send_gdb "48-target-download\n"
613 gdb_expect $loadtimeout {
614 -re "48\\^done.*$mi_gdb_prompt$" {
617 perror "Unable to download to remote target (timeout)"
626 # load a file into the debugger.
627 # return a -1 if anything goes wrong.
629 proc mi_gdb_load { arg } {
631 return [mi_gdb_file_cmd $arg]
636 # Return true if symbols were read in using -readnow. Otherwise,
639 proc mi_readnow { args } {
640 # Just defer to gdb.exp.
644 # mi_gdb_test COMMAND [PATTERN [MESSAGE [IPATTERN]]] -- send a command to gdb;
647 # COMMAND is the command to execute, send to GDB with send_gdb. If
648 # this is the null string no command is sent.
649 # PATTERN is the pattern to match for a PASS, and must NOT include
650 # the \r\n sequence immediately before the gdb prompt.
651 # If not specified, .* is used.
652 # MESSAGE is the message to be printed. (If this is the empty string,
653 # then sometimes we don't call pass or fail at all; I don't
654 # understand this at all.)
655 # If not specified, COMMAND is used.
656 # IPATTERN is the pattern to match for the inferior's output. This parameter
657 # is optional. If present, it will produce a PASS if the match is
658 # successful, and a FAIL if unsuccessful.
661 # 1 if the test failed,
662 # 0 if the test passes,
663 # -1 if there was an internal error.
665 proc mi_gdb_test { args } {
668 global GDB expect_out
669 global inferior_exited_re async
670 upvar timeout timeout
672 if {[llength $args] >= 1} {
673 set command [lindex $args 0]
675 error "Not enough arguments in mi_gdb_test"
678 if {[llength $args] >= 2} {
679 set pattern [lindex $args 1]
684 if {[llength $args] >= 3} {
685 set message [lindex $args 2]
690 if [llength $args]==4 {
691 set ipattern [lindex $args 3]
694 if [llength $args]==5 {
695 set question_string [lindex $args 3]
696 set response_string [lindex $args 4]
698 set question_string "^FOOBAR$"
701 if { [llength $args] >= 6 } {
702 error "Too many arguments in mi_gdb_test"
706 send_user "Sending \"$command\" to gdb\n"
707 send_user "Looking to match \"$pattern\"\n"
708 send_user "Message is \"$message\"\n"
712 set string "${command}\n"
713 set string_regex [string_to_regexp $command]
715 if { $command != "" } {
716 while { "$string" != "" } {
717 set foo [string first "\n" "$string"]
718 set len [string length "$string"]
719 if { $foo < [expr $len - 1] } {
720 set str [string range "$string" 0 $foo]
721 if { [send_gdb "$str"] != "" } {
722 perror "Couldn't send $command to GDB."
728 set string [string range "$string" [expr $foo + 1] end]
733 if { "$string" != "" } {
734 if { [send_gdb "$string"] != "" } {
735 perror "Couldn't send $command to GDB."
740 if [info exists timeout] {
744 if [info exists timeout] {
751 # With $prompt_re "" there may come arbitrary asynchronous response
752 # from the previous command, before or after $string_regex.
753 set string_regex ".*"
755 verbose -log "Expecting: ^($string_regex\[\r\n\]+)?($pattern\[\r\n\]+$mi_gdb_prompt\[ \]*)"
757 -re "\\*\\*\\* DOSEXIT code.*" {
758 if { $message != "" } {
763 -re "Ending remote debugging.*$mi_gdb_prompt\[ \]*$" {
765 warning "Can`t communicate to remote target."
771 -re "^($string_regex\[\r\n\]+)?($pattern\[\r\n\]+$mi_gdb_prompt\[ \]*)" {
772 # At this point, $expect_out(1,string) is the MI input command.
773 # and $expect_out(2,string) is the MI output command.
774 # If $expect_out(1,string) is "", then there was no MI input command here.
776 # NOTE, there is no trailing anchor because with GDB/MI,
777 # asynchronous responses can happen at any point, causing more
778 # data to be available. Normally an anchor is used to make
779 # sure the end of the output is matched, however, $mi_gdb_prompt
780 # is just as good of an anchor since mi_gdb_test is meant to
781 # match a single mi output command. If a second GDB/MI output
782 # response is sent, it will be in the buffer for the next
783 # time mi_gdb_test is called.
784 if {![string match "" $message]} {
789 -re "(${question_string})$" {
790 send_gdb "$response_string\n"
793 -re "Undefined.* command:.*$mi_gdb_prompt\[ \]*$" {
794 perror "Undefined command \"$command\"."
798 -re "Ambiguous command.*$mi_gdb_prompt\[ \]*$" {
799 perror "\"$command\" is not a unique command name."
803 -re "$inferior_exited_re with code \[0-9\]+.*$mi_gdb_prompt\[ \]*$" {
804 if {![string match "" $message]} {
805 set errmsg "$message (the program exited)"
807 set errmsg "$command (the program exited)"
812 -re "The program is not being run.*$mi_gdb_prompt\[ \]*$" {
813 if {![string match "" $message]} {
814 set errmsg "$message (the program is no longer running)"
816 set errmsg "$command (the program is no longer running)"
821 -re ".*$mi_gdb_prompt\[ \]*$" {
822 if {![string match "" $message]} {
823 fail "$message (unexpected output)"
829 perror "Window too small."
833 perror "Process no longer exists"
834 if { $message != "" } {
840 perror "internal buffer is full."
844 if {![string match "" $message]} {
845 fail "$message (timeout)"
851 # If the GDB output matched, compare the inferior output.
852 if { $result == 0 } {
853 if [ info exists ipattern ] {
854 if { ![target_info exists gdb,noinferiorio] } {
855 global gdb_spawn_id inferior_spawn_id
857 set sid "$inferior_spawn_id $gdb_spawn_id"
859 -i "$sid" -re "$ipattern" {
860 pass "$message inferior output"
863 fail "$message inferior output (timeout)"
868 unsupported "$message inferior output"
876 # Collect output sent to the console output stream until UNTIL is
877 # seen. UNTIL is a regular expression. MESSAGE is the message to be
878 # printed in case of timeout.
880 proc mi_gdb_expect_cli_output {until message} {
884 -re "~\"(\[^\r\n\]+)\"\r\n" {
885 append output $expect_out(1,string)
888 -notransfer -re "$until" {
892 fail "$message (timeout)"
901 # MI run command. (A modified version of gdb_run_cmd)
904 # In patterns, the newline sequence ``\r\n'' is matched explicitly as
905 # ``.*$'' could swallow up output that we attempt to match elsewhere.
907 # Send the command to run the test program.
909 # If USE_MI_COMMAND is true, the "-exec-run" command is used.
910 # Otherwise, the "run" (CLI) command is used. If the global USE_GDB_STUB is
911 # true, -exec-continue and continue are used instead of their run counterparts.
913 # ARGS is passed as argument to the command used to run the test program.
914 # Beware that arguments to "-exec-run" do not have the same semantics as
915 # arguments to the "run" command, so USE_MI_COMMAND influences the meaning
916 # of ARGS. If USE_MI_COMMAND is true, they are arguments to -exec-run.
917 # If USE_MI_COMMAND is false, they are effectively arguments passed
918 # to the test program. If the global USE_GDB_STUB is true, ARGS is not used.
919 proc mi_run_cmd_full {use_mi_command args} {
920 global mi_gdb_prompt use_gdb_stub
921 global thread_selected_re
922 global library_loaded_re
924 if {$use_mi_command} {
925 set run_prefix "220-exec-"
932 foreach command [gdb_init_commands] {
933 send_gdb "$command\n"
935 -re "$mi_gdb_prompt$" { }
937 unresolved "gdb_init_command for target failed"
943 if { [mi_gdb_target_load] < 0 } {
948 if [target_info exists gdb,do_reload_on_run] {
949 send_gdb "${run_prefix}continue\n"
951 -re "${run_match}\\^running\[\r\n\]+\\*running,thread-id=\"\[^\"\]+\"\r\n$mi_gdb_prompt" {}
952 -re "${run_match}\\^error.*$mi_gdb_prompt" {return -1}
958 if [target_info exists gdb,start_symbol] {
959 set start [target_info gdb,start_symbol]
964 # HACK: Should either use 000-jump or fix the target code
965 # to better handle RUN.
966 send_gdb "jump *$start\n"
967 warning "Using CLI jump command, expect run-to-main FAIL"
969 -re "&\"jump \\*${start}\\\\n\"\[\r\n\]+~\"Continuing at 0x\[0-9A-Fa-f\]+\.\\\\n\"\[\r\n\]+\\^running\[\r\n\]+\\*running,thread-id=\"\[^\"\]+\"\[\r\n\]+${mi_gdb_prompt}" {}
971 unresolved "unable to start target"
978 send_gdb "${run_prefix}run $args\n"
980 -re "${run_match}\\^running\r\n(\\*running,thread-id=\"\[^\"\]+\"\r\n|=thread-created,id=\"1\",group-id=\"\[0-9\]+\"\r\n)*(${library_loaded_re})*(${thread_selected_re})?${mi_gdb_prompt}" {
982 -re "\\^error,msg=\"The target does not support running in non-stop mode.\"" {
983 unsupported "non-stop mode not supported"
987 unresolved "unable to start target"
991 # NOTE: Shortly after this there will be a ``000*stopped,...(gdb)''
996 # A wrapper for mi_run_cmd_full which uses -exec-run and
997 # -exec-continue, as appropriate. ARGS are passed verbatim to
999 proc mi_run_cmd {args} {
1000 return [eval mi_run_cmd_full 1 $args]
1003 # A wrapper for mi_run_cmd_full which uses the CLI commands 'run' and
1004 # 'continue', as appropriate. ARGS are passed verbatim to
1006 proc mi_run_with_cli {args} {
1007 return [eval mi_run_cmd_full 0 $args]
1010 # Starts fresh GDB binary and loads an optional executable into GDB.
1011 # Usage: mi_clean_restart [EXECUTABLE]
1012 # EXECUTABLE is the basename of the binary.
1013 # Return -1 if starting gdb or loading the executable failed.
1015 proc mi_clean_restart {{executable ""} {flags {}}} {
1023 # This is a clean restart, so reset error and warning count.
1027 if {[mi_gdb_start $flags]} {
1031 mi_gdb_reinitialize_dir $srcdir/$subdir
1033 if {$executable != ""} {
1034 set binfile [standard_output_file ${executable}]
1035 return [mi_gdb_load ${binfile}]
1041 # Just like gdb's "runto" proc, it will run the target to a given
1042 # function. The big difference here between mi_runto and mi_execute_to
1043 # is that mi_execute_to must have the inferior running already. This
1044 # proc will (like gdb's runto) (re)start the inferior, too.
1046 # FUNC is the linespec of the place to stop (it inserts a breakpoint here).
1048 # -1 if failed, timedout
1051 # Supported options:
1053 # -qualified -- pass --qualified to -break-insert
1054 # -pending -- pass -f to -break-insert to create a pending
1057 proc mi_runto_helper {func run_or_continue args} {
1058 global mi_gdb_prompt expect_out
1059 global hex decimal fullname_syntax
1061 parse_args {{qualified} {pending}}
1063 set test "mi runto $func"
1065 set bp [mi_make_breakpoint_pending -type breakpoint -disp del]
1067 set bp [mi_make_breakpoint -type breakpoint -disp del \
1068 -func $func\(\\\(.*\\\)\)?]
1073 lappend extra_opts "--qualified"
1076 lappend extra_opts "-f"
1077 # MI prints "Function FUNC not defined", "No line NNN in current
1078 # file.", etc. to the CLI stream.
1079 set extra_output "&\"\[^\r\n\]+\"\r\n"
1081 mi_gdb_test "200-break-insert [join $extra_opts " "] -t $func" "${extra_output}200\\^done,$bp" \
1082 "breakpoint at $func"
1084 if {$run_or_continue == "run"} {
1085 if { [mi_run_cmd] < 0 } {
1089 mi_send_resuming_command "exec-continue" "$test"
1092 mi_expect_stop "breakpoint-hit" $func ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } $test
1095 proc mi_runto {func args} {
1096 return [mi_runto_helper $func "run" {*}$args]
1099 # Just like runto_main but works with the MI interface.
1101 proc mi_runto_main {} {
1102 return [mi_runto_helper "main" "run" -qualified]
1105 # Next to the next statement
1106 # For return values, see mi_execute_to_helper
1108 proc mi_next { test } {
1109 return [mi_next_to {.*} {.*} {.*} {.*} $test]
1113 # Step to the next statement
1114 # For return values, see mi_execute_to_helper
1116 proc mi_step { test } {
1117 return [mi_step_to {.*} {.*} {.*} {.*} $test]
1122 proc mi_detect_async {} {
1124 global mi_gdb_prompt
1126 send_gdb "show mi-async\n"
1129 -re "asynchronous mode is on...*$mi_gdb_prompt$" {
1132 -re ".*$mi_gdb_prompt$" {
1142 # Wait for MI *stopped notification to appear.
1143 # The REASON, FUNC, ARGS, FILE and LINE are regular expressions
1144 # to match against whatever is output in *stopped. FILE may also match
1145 # filename of a file without debug info. ARGS should not include [] the
1146 # list of argument is enclosed in, and other regular expressions should
1147 # not include quotes.
1148 # EXTRA can be a list of one, two or three elements.
1149 # The first element is the regular expression
1150 # for output expected right after *stopped, and before GDB prompt.
1151 # The third element is the regular expression for the locno
1152 # right after bkptno field. The locno regex should not include
1153 # the comma separating it from the following fields.
1155 # When we fail to match output at all, -1 is returned. If FILE does
1156 # match and the target system has no debug info for FILE return 0.
1157 # Otherwise, the line at which we stop is returned. This is useful when
1158 # exact line is not possible to specify for some reason -- one can pass
1159 # the .* or "\[0-9\]*" regexps for line, and then check the line
1162 # Do not pass .* for any argument if you are expecting more than one stop.
1163 proc mi_expect_stop { reason func args file line extra test } {
1165 global mi_gdb_prompt
1168 global fullname_syntax
1170 global thread_selected_re
1171 global breakpoint_re
1175 set after_stopped ""
1178 if { [llength $extra] == 3 } {
1179 set after_stopped [lindex $extra 0]
1180 set after_reason [lindex $extra 1]
1181 set after_reason "${after_reason},"
1182 set locno [lindex $extra 2]
1183 set locno "${locno},"
1184 } elseif { [llength $extra] == 2 } {
1185 set after_stopped [lindex $extra 0]
1186 set after_reason [lindex $extra 1]
1187 set after_reason "${after_reason},"
1188 } elseif { [llength $extra] == 1 } {
1189 set after_stopped [lindex $extra 0]
1195 set prompt_re "$mi_gdb_prompt$"
1198 if { $reason == "really-no-reason" } {
1200 -re "\\*stopped\r\n$prompt_re" {
1204 fail "$test (timeout)"
1210 if { $reason == "exited-normally" } {
1213 -re "\\*stopped,reason=\"exited-normally\"\r\n$prompt_re" {
1216 -re ".*$mi_gdb_prompt$" {fail "continue to end (2)"}
1218 fail "$test (timeout)"
1223 if { $reason == "exited" } {
1225 -re "\\*stopped,reason=\"exited\",exit-code=\"\[0-7\]+\"\r\n$prompt_re" {
1228 -re ".*$mi_gdb_prompt$" {
1229 fail "$test (inferior not stopped)"
1232 fail "$test (timeout)"
1238 if { $reason == "solib-event" } {
1239 set pattern "\\*stopped,reason=\"solib-event\",thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re"
1240 verbose -log "mi_expect_stop: expecting: $pattern"
1246 fail "$test (timeout)"
1252 set args "\\\[$args\\\]"
1256 if { $reason == "breakpoint-hit" } {
1257 set bn {bkptno="[0-9]+",}
1258 set bn "${bn}${locno}"
1259 } elseif { $reason == "solib-event" } {
1261 } elseif { $reason == "exception-caught" } {
1262 set ebn {bkptno="[0-9]+",}
1263 set ebn "${ebn}${locno}"
1265 set reason "breakpoint-hit"
1269 if { $reason != "" } {
1270 if { [regexp {"} $reason] } {
1271 set r "reason=$reason,"
1273 set r "reason=\"$reason\","
1280 verbose -log "mi_expect_stop: expecting: \\*stopped,${ebn}${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$func\",args=$args,(?:file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"$line\",arch=\"$any\"|from=\"$file\")\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re"
1283 -re "\\*stopped,${ebn}${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$func\",args=$args,(?:file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"($line)\",arch=\"$any\"|from=\"$file\")\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re" {
1285 if {[array names expect_out "2,string"] != ""} {
1286 return $expect_out(2,string)
1288 # No debug info available but $file does match.
1291 -re "\\*stopped,${ebn}${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$any\",args=\[\\\[\{\]$any\[\\\]\}\],file=\"$any\",fullname=\"${fullname_syntax}$any\",line=\"\[0-9\]*\",arch=\"$any\"\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re" {
1292 verbose -log "got $expect_out(buffer)"
1293 fail "$test (stopped at wrong place)"
1296 -re ".*\r\n$mi_gdb_prompt$" {
1297 verbose -log "got $expect_out(buffer)"
1298 fail "$test (unknown output after running)"
1302 fail "$test (timeout)"
1308 # Wait for MI *stopped notification related to an interrupt request to
1310 proc mi_expect_interrupt { test } {
1311 global mi_gdb_prompt
1318 set prompt_re "$mi_gdb_prompt"
1321 set r_nonstop "reason=\"signal-received\",signal-name=\"0\",signal-meaning=\"Signal 0\""
1322 set r_allstop "reason=\"signal-received\",signal-name=\"SIGINT\",signal-meaning=\"Interrupt\""
1323 set r "(${r_nonstop}|${r_allstop})"
1326 # A signal can land anywhere, just ignore the location
1327 verbose -log "mi_expect_interrupt: expecting: \\*stopped,${r}$any\r\n$prompt_re"
1329 -re "\\*stopped,${r}$any\r\n$prompt_re" {
1333 -re ".*\r\n$mi_gdb_prompt" {
1334 verbose -log "got $expect_out(buffer)"
1335 fail "$test (unknown output after running)"
1339 fail "$test (timeout)"
1345 # cmd should not include the number or newline (i.e. "exec-step 3", not
1346 # "220-exec-step 3\n"
1348 # Can not match -re ".*\r\n${mi_gdb_prompt}", because of false positives
1349 # after the first prompt is printed.
1351 proc mi_execute_to { cmd reason func args file line extra test } {
1352 mi_send_resuming_command "$cmd" "$test"
1353 set r [mi_expect_stop $reason $func $args $file $line $extra $test]
1357 proc mi_next_to { func args file line test } {
1358 mi_execute_to "exec-next" "end-stepping-range" "$func" "$args" \
1359 "$file" "$line" "" "$test"
1362 proc mi_step_to { func args file line test } {
1363 mi_execute_to "exec-step" "end-stepping-range" "$func" "$args" \
1364 "$file" "$line" "" "$test"
1367 proc mi_finish_to { func args file line result ret test } {
1368 mi_execute_to "exec-finish" "function-finished" "$func" "$args" \
1370 ",gdb-result-var=\"$result\",return-value=\"$ret\"" \
1374 proc mi_continue_to {func} {
1375 mi_runto_helper $func "continue"
1378 # Creates a breakpoint and checks the reported fields are as expected.
1379 # This procedure takes the same options as mi_make_breakpoint and
1380 # returns the breakpoint regexp from that procedure.
1382 proc mi_create_breakpoint {location test args} {
1383 set bp [eval mi_make_breakpoint $args]
1384 mi_gdb_test "222-break-insert $location" "222\\^done,$bp" $test
1388 # Like mi_create_breakpoint, but creates a breakpoint with multiple
1389 # locations using mi_make_breakpoint_multi instead.
1391 proc mi_create_breakpoint_multi {location test args} {
1392 set bp [eval mi_make_breakpoint_multi $args]
1393 mi_gdb_test "222-break-insert $location" "222\\^done,$bp" $test
1397 # Like mi_create_breakpoint, but creates a pending breakpoint.
1399 proc mi_create_breakpoint_pending {location test args} {
1400 set bp [eval mi_make_breakpoint_pending $args]
1401 mi_gdb_test "222-break-insert $location" ".*\r\n222\\^done,$bp" $test
1405 # Creates varobj named NAME for EXPRESSION.
1406 # Name cannot be "-".
1407 proc mi_create_varobj { name expression testname } {
1408 mi_gdb_test "-var-create $name * $expression" \
1409 "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=.*,has_more=\"0\"" \
1413 proc mi_create_floating_varobj { name expression testname } {
1414 mi_gdb_test "-var-create $name @ $expression" \
1415 "\\^done,name=\"$name\",numchild=\"\(-1\|\[0-9\]+\)\",value=\".*\",type=.*" \
1420 # Same as mi_create_varobj, but also checks the reported type
1422 proc mi_create_varobj_checked { name expression type testname } {
1423 mi_gdb_test "-var-create $name * $expression" \
1424 "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=\"$type\".*" \
1428 # Same as mi_create_floating_varobj, but assumes the test is creating
1429 # a dynamic varobj that has children. The "value" and "has_more"
1430 # attributes are checked.
1431 proc mi_create_dynamic_varobj {name expression value has_more testname} {
1432 mi_gdb_test "-var-create $name @ $expression" \
1433 "\\^done,name=\"$name\",numchild=\"0\",value=\"$value\",type=.*,has_more=\"${has_more}\"" \
1437 # Deletes the specified NAME.
1438 proc mi_delete_varobj { name testname } {
1439 mi_gdb_test "-var-delete $name" \
1440 "\\^done,ndeleted=.*" \
1444 # Updates varobj named NAME and checks that all varobjs in EXPECTED
1445 # are reported as updated, and no other varobj is updated.
1446 # Assumes that no varobj is out of scope and that no varobj changes
1448 proc mi_varobj_update { name expected testname } {
1449 set er "\\^done,changelist=\\\["
1451 foreach item $expected {
1452 set v "{name=\"$item\",in_scope=\"true\",type_changed=\"false\",has_more=\".\"}"
1462 verbose -log "Expecting: $er" 2
1463 mi_gdb_test "-var-update $name" $er $testname
1466 proc mi_varobj_update_with_child_type_change { name child_name new_type new_children testname } {
1467 set v "{name=\"$child_name\",in_scope=\"true\",type_changed=\"true\",new_type=\"$new_type\",new_num_children=\"$new_children\",has_more=\".\"}"
1468 set er "\\^done,changelist=\\\[$v\\\]"
1469 verbose -log "Expecting: $er"
1470 mi_gdb_test "-var-update $name" $er $testname
1473 proc mi_varobj_update_with_type_change { name new_type new_children testname } {
1474 mi_varobj_update_with_child_type_change $name $name $new_type $new_children $testname
1477 # A helper that turns a key/value list into a regular expression
1478 # matching some MI output.
1479 proc mi_varobj_update_kv_helper {list} {
1482 foreach {key value} $list {
1487 if {$key == "new_children"} {
1488 append rx "$key=\\\[$value\\\]"
1490 append rx "$key=\"$value\""
1496 # A helper for mi_varobj_update_dynamic that computes a match
1497 # expression given a child list.
1498 proc mi_varobj_update_dynamic_helper {children} {
1502 foreach child $children {
1508 append crx [mi_varobj_update_kv_helper $child]
1515 # Update a dynamic varobj named NAME. CHILDREN is a list of children
1516 # that have been updated; NEW_CHILDREN is a list of children that were
1517 # added to the primary varobj. Each child is a list of key/value
1518 # pairs that are expected. SELF is a key/value list holding
1519 # information about the varobj itself. TESTNAME is the name of the
1521 proc mi_varobj_update_dynamic {name testname self children new_children} {
1522 if {[llength $new_children]} {
1523 set newrx [mi_varobj_update_dynamic_helper $new_children]
1524 lappend self new_children $newrx
1526 set selfrx [mi_varobj_update_kv_helper $self]
1527 set crx [mi_varobj_update_dynamic_helper $children]
1529 set er "\\^done,changelist=\\\[\{name=\"$name\",in_scope=\"true\""
1530 append er ",$selfrx\}"
1536 verbose -log "Expecting: $er"
1537 mi_gdb_test "-var-update $name" $er $testname
1540 proc mi_check_varobj_value { name value testname } {
1542 mi_gdb_test "-var-evaluate-expression $name" \
1543 "\\^done,value=\"$value\"" \
1547 # Helper proc which constructs a child regexp for
1548 # mi_list_varobj_children and mi_varobj_update_dynamic.
1549 proc mi_child_regexp {children add_child} {
1558 foreach item $children {
1560 set name [lindex $item 0]
1561 set exp [lindex $item 1]
1562 set numchild [lindex $item 2]
1563 if {[llength $item] == 5} {
1564 set type [lindex $item 3]
1565 set value [lindex $item 4]
1567 lappend children_exp\
1568 "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",value=\"$value\",type=\"$type\"(,thread-id=\"\[0-9\]+\")?}"
1569 } elseif {[llength $item] == 4} {
1570 set type [lindex $item 3]
1572 lappend children_exp\
1573 "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",type=\"$type\"(,thread-id=\"\[0-9\]+\")?}"
1575 lappend children_exp\
1576 "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\"(,thread-id=\"\[0-9\]+\")?}"
1579 return [join $children_exp ","]
1582 # Check the results of the:
1584 # -var-list-children VARNAME
1586 # command. The CHILDREN parement should be a list of lists.
1587 # Each inner list can have either 3 or 4 elements, describing
1588 # fields that gdb is expected to report for child variable object,
1589 # in the following order
1593 # - Number of children
1596 # If inner list has 3 elements, the gdb is expected to output no
1597 # type for a child and no value.
1599 # If the inner list has 4 elements, gdb output is expected to
1602 proc mi_list_varobj_children { varname children testname } {
1603 mi_list_varobj_children_range $varname "" "" [llength $children] $children \
1607 # Like mi_list_varobj_children, but sets a subrange. NUMCHILDREN is
1608 # the total number of children.
1609 proc mi_list_varobj_children_range {varname from to numchildren children testname} {
1611 if {[llength $varname] == 2} {
1612 set options [lindex $varname 1]
1613 set varname [lindex $varname 0]
1616 set children_exp_j [mi_child_regexp $children 1]
1618 set expected "\\^done,numchild=\".*\",children=\\\[$children_exp_j.*\\\]"
1620 set expected "\\^done,numchild=\"0\""
1624 append expected ",has_more=\"0\""
1625 } elseif {$to >= 0 && $numchildren > $to} {
1626 append expected ",has_more=\"1\""
1628 append expected ",has_more=\"0\""
1631 verbose -log "Expecting: $expected"
1633 mi_gdb_test "-var-list-children $options $varname $from $to" \
1637 # Verifies that variable object VARNAME has NUMBER children,
1638 # where each one is named $VARNAME.<index-of-child> and has type TYPE.
1639 proc mi_list_array_varobj_children { varname number type testname } {
1640 mi_list_array_varobj_children_with_index $varname $number 0 $type $testname
1643 # Same as mi_list_array_varobj_children, but allowing to pass a start index
1645 proc mi_list_array_varobj_children_with_index { varname number start_index \
1648 set index $start_index
1649 for {set i 0} {$i < $number} {incr i} {
1650 lappend t [list $varname.$index $index 0 $type]
1653 mi_list_varobj_children $varname $t $testname
1656 # A list of two-element lists. First element of each list is
1657 # a Tcl statement, and the second element is the line
1658 # number of source C file where the statement originates.
1659 set mi_autotest_data ""
1660 # The name of the source file for autotesting.
1661 set mi_autotest_source ""
1663 # Prepares for running inline tests in FILENAME.
1664 # See comments for mi_run_inline_test for detailed
1665 # explanation of the idea and syntax.
1666 proc mi_prepare_inline_tests { filename } {
1670 global mi_autotest_source
1671 global mi_autotest_data
1673 set mi_autotest_data {}
1675 set mi_autotest_source $filename
1677 if {![regexp "^/" "$filename"]} {
1678 set filename "$srcdir/$subdir/$filename"
1681 set chan [open $filename]
1682 set content [read $chan]
1685 set start [string first "/*:" $content]
1687 set end [string first ":*/" $content]
1689 error "Unterminated special comment in $filename"
1692 set prefix [string range $content 0 $start]
1693 set prefix_newlines [count_newlines $prefix]
1695 set line_number [expr $line_number+$prefix_newlines]
1696 set comment_line $line_number
1698 set comment [string range $content [expr $start+3] [expr $end-1]]
1700 set comment_newlines [count_newlines $comment]
1701 set line_number [expr $line_number+$comment_newlines]
1703 set comment [string trim $comment]
1704 set content [string range $content [expr $end+3] \
1705 [string length $content]]
1706 lappend mi_autotest_data [list $comment $comment_line]
1714 # Helper to mi_run_inline_test below.
1715 # Return the list of all (statement,line_number) lists
1716 # that comprise TESTCASE. The begin and end markers
1718 proc mi_get_inline_test {testcase} {
1720 global mi_gdb_prompt
1721 global mi_autotest_data
1722 global mi_autotest_source
1728 foreach l $mi_autotest_data {
1730 set comment [lindex $l 0]
1732 if {$comment == "BEGIN: $testcase"} {
1734 } elseif {$comment == "END: $testcase"} {
1737 } elseif {$seen_begin==1} {
1742 if {$seen_begin == 0} {
1743 error "Autotest $testcase not found"
1746 if {$seen_begin == 1 && $seen_end == 0} {
1747 error "Missing end marker for test $testcase"
1753 # Sets temporary breakpoint at LOCATION.
1754 proc mi_tbreak {location test} {
1756 global mi_gdb_prompt
1758 mi_gdb_test "-break-insert -t $location" \
1763 # Send COMMAND that must be a command that resumes
1764 # the inferior (run/continue/next/etc) and consumes
1765 # the "^running" output from it.
1766 proc mi_send_resuming_command_raw {command test} {
1768 global mi_gdb_prompt
1769 global thread_selected_re
1770 global library_loaded_re
1772 send_gdb "$command\n"
1774 -re "\\^running\r\n\\*running,thread-id=\"\[^\"\]+\"\r\n($library_loaded_re)*($thread_selected_re)?${mi_gdb_prompt}" {
1775 # Note that lack of 'pass' call here -- this works around limitation
1776 # in DejaGNU xfail mechanism. mi-until.exp has this:
1778 # setup_kfail gdb/2104 "*-*-*"
1781 # and mi_execute_to uses mi_send_resuming_command. If we use 'pass' here,
1782 # it will reset kfail, so when the actual test fails, it will be flagged
1786 -re "\\^error,msg=\"Displaced stepping is only supported in ARM mode\".*" {
1787 unsupported "$test (Thumb mode)"
1790 -re "\\^error,msg=.*" {
1791 fail "$test (MI error)"
1794 -re ".*${mi_gdb_prompt}" {
1795 fail "$test (failed to resume)"
1805 proc mi_send_resuming_command {command test} {
1806 mi_send_resuming_command_raw -$command $test
1809 # Helper to mi_run_inline_test below.
1810 # Sets a temporary breakpoint at LOCATION and runs
1811 # the program using COMMAND. When the program is stopped
1812 # returns the line at which it. Returns -1 if line cannot
1814 # Does not check that the line is the same as requested.
1815 # The caller can check itself if required.
1816 proc_with_prefix mi_continue_to_line {location test} {
1817 with_test_prefix $test {
1818 mi_tbreak $location "set temporary breakpoint"
1819 mi_send_resuming_command "exec-continue" "continue to breakpoint"
1820 return [mi_get_stop_line]
1824 # Wait until gdb prints the current line.
1825 proc mi_get_stop_line {} {
1827 global mi_gdb_prompt
1833 set prompt_re "$mi_gdb_prompt$"
1837 -re ".*line=\"(\[0-9\]*)\".*\r\n$prompt_re" {
1838 return $expect_out(1,string)
1840 -re ".*$mi_gdb_prompt" {
1841 fail "wait for stop (unexpected output)"
1844 fail "wait for stop (timeout)"
1849 # Run a MI test embedded in comments in a C file.
1850 # The C file should contain special comments in the following
1853 # /*: BEGIN: testname :*/
1854 # /*: <Tcl statements> :*/
1855 # /*: END: testname :*/
1857 # This procedure find the begin and end marker for the requested
1858 # test. Then, a temporary breakpoint is set at the begin
1859 # marker and the program is run (from start).
1861 # After that, for each special comment between the begin and end
1862 # marker, the Tcl statements are executed. It is assumed that
1863 # for each comment, the immediately preceding line is executable
1864 # C statement. Then, gdb will be single-stepped until that
1865 # preceding C statement is executed, and after that the
1866 # Tcl statements in the comment will be executed.
1870 # /*: BEGIN: assignment-test :*/
1872 # /*: <Tcl code to check that 'v' is indeed 10 :*/
1873 # /*: END: assignment-test :*/
1875 # The mi_prepare_inline_tests function should be called before
1876 # calling this function. A given C file can contain several
1877 # inline tests. The names of the tests must be unique within one
1880 proc mi_run_inline_test { testcase } {
1882 global mi_gdb_prompt
1885 global fullname_syntax
1886 global mi_autotest_source
1888 set commands [mi_get_inline_test $testcase]
1893 foreach c $commands {
1894 set statements [lindex $c 0]
1895 set line [lindex $c 1]
1896 set line [expr $line-1]
1898 # We want gdb to be stopped at the expression immediately
1899 # before the comment. If this is the first comment, the
1900 # program is either not started yet or is in some random place,
1901 # so we run it. For further comments, we might be already
1902 # standing at the right line. If not continue till the
1906 # Start the program afresh.
1907 mi_tbreak "$mi_autotest_source:$line" "set temporary breakpoint"
1908 if { [mi_run_cmd] < 0 } {
1911 set line_now [mi_get_stop_line]
1913 } elseif {$line_now!=$line} {
1914 set line_now [mi_continue_to_line "$mi_autotest_source:$line" "continue to $line"]
1917 if {$line_now!=$line} {
1918 fail "$testcase: go to line $line"
1921 # We're not at the statement right above the comment.
1922 # Execute that statement so that the comment can test
1923 # the state after the statement is executed.
1925 # Single-step past the line.
1926 if { [mi_send_resuming_command "exec-next" "$testcase: step over $line"] != 0 } {
1929 set line_now [mi_get_stop_line]
1931 # We probably want to use 'uplevel' so that statements
1932 # have direct access to global variables that the
1933 # main 'exp' file has set up. But it's not yet clear,
1934 # will need more experience to be sure.
1941 proc get_mi_thread_list {name} {
1944 # MI will return a list of thread ids:
1947 # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
1949 mi_gdb_test "-thread-list-ids" \
1950 {.*\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \
1951 "-thread_list_ids ($name)"
1954 if {[info exists expect_out(buffer)]} {
1955 set output $expect_out(buffer)
1959 if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} {
1960 fail "finding threads in MI output ($name)"
1962 pass "finding threads in MI output ($name)"
1964 # Make list of console threads
1965 set start [expr {[string first \{ $threads] + 1}]
1966 set end [expr {[string first \} $threads] - 1}]
1967 set threads [string range $threads $start $end]
1968 foreach thread [split $threads ,] {
1969 if {[scan $thread {thread-id="%d"} num]} {
1970 lappend thread_list $num
1978 # Check that MI and the console know of the same threads.
1979 # Appends NAME to all test names.
1980 proc check_mi_and_console_threads {name} {
1983 mi_gdb_test "-thread-list-ids" \
1984 {.*\^done,thread-ids={(thread-id="[0-9]+"(,)*)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \
1985 "-thread-list-ids ($name)"
1987 if {[info exists expect_out(buffer)]} {
1988 set mi_output $expect_out(buffer)
1991 # GDB will return a list of thread ids and some more info:
1994 # -interpreter-exec console "info threads"
1995 # ~" 4 Thread 2051 (LWP 7734) 0x401166b1 in __libc_nanosleep () at __libc_nanosleep:-1"
1996 # ~" 3 Thread 1026 (LWP 7733) () at __libc_nanosleep:-1"
1997 # ~" 2 Thread 2049 (LWP 7732) 0x401411f8 in __poll (fds=0x804bb24, nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63"
1998 # ~"* 1 Thread 1024 (LWP 7731) main (argc=1, argv=0xbfffdd94) at ../../../src/gdb/testsuite/gdb.mi/pthreads.c:160"
1999 # FIXME: kseitz/2002-09-05: Don't use the hack-cli method.
2000 mi_gdb_test "info threads" \
2001 {.*(~".*"[\r\n]*)+.*} \
2002 "info threads ($name)"
2003 set console_output {}
2004 if {[info exists expect_out(buffer)]} {
2005 set console_output $expect_out(buffer)
2008 # Make a list of all known threads to console (gdb's thread IDs)
2009 set console_thread_list {}
2010 foreach line [split $console_output \n] {
2011 if {[string index $line 0] == "~"} {
2012 # This is a line from the console; trim off "~", " ", "*", and "\""
2013 set line [string trim $line ~\ \"\*]
2014 if {[scan $line "%d" id] == 1} {
2015 lappend console_thread_list $id
2020 # Now find the result string from MI
2022 foreach line [split $mi_output \n] {
2023 if {[string range $line 0 4] == "^done"} {
2027 if {$mi_result == ""} {
2028 fail "finding MI result string ($name)"
2030 pass "finding MI result string ($name)"
2033 # Finally, extract the thread ids and compare them to the console
2034 set num_mi_threads_str ""
2035 if {![regexp {number-of-threads="[0-9]+"} $mi_result num_mi_threads_str]} {
2036 fail "finding number of threads in MI output ($name)"
2038 pass "finding number of threads in MI output ($name)"
2040 # Extract the number of threads from the MI result
2041 if {![scan $num_mi_threads_str {number-of-threads="%d"} num_mi_threads]} {
2042 fail "got number of threads from MI ($name)"
2044 pass "got number of threads from MI ($name)"
2046 # Check if MI and console have same number of threads
2047 if {$num_mi_threads != [llength $console_thread_list]} {
2048 fail "console and MI have same number of threads ($name)"
2050 pass "console and MI have same number of threads ($name)"
2052 # Get MI thread list
2053 set mi_thread_list [get_mi_thread_list $name]
2055 # Check if MI and console have the same threads
2057 foreach ct [lsort $console_thread_list] mt [lsort $mi_thread_list] {
2063 fail "MI and console have same threads ($name)"
2065 # Send a list of failures to the log
2066 send_log "Console has thread ids: $console_thread_list\n"
2067 send_log "MI has thread ids: $mi_thread_list\n"
2069 pass "MI and console have same threads ($name)"
2076 # Set solib-search-path to allow gdb to locate shlib FILE.
2077 proc mi_locate_shlib { file } {
2080 if ![info exists mi_spawn_id] {
2081 perror "mi_locate_shlib: GDB is not running"
2084 # If the target is remote, we need to tell gdb where to find the
2086 if { ![is_remote target] } {
2090 # We could set this even when not testing remotely, but a user
2091 # generally won't set it unless necessary. In order to make the tests
2092 # more like the real-life scenarios, we don't set it for local testing.
2093 mi_gdb_test "set solib-search-path [file dirname $file]" "\^done" ""
2096 # Copy shlib FILE to the target and set solib-search-path to allow gdb to
2098 proc mi_load_shlib { file } {
2099 set dest [gdb_download_shlib $file]
2100 mi_locate_shlib $file
2104 # Download shared libraries to the target.
2105 proc mi_load_shlibs { args } {
2106 foreach file $args {
2111 proc mi_check_thread_states { states test } {
2113 set pattern ".*\\^done,threads=\\\["
2115 set pattern "${pattern}(.*)state=\"$s\""
2117 set pattern "${pattern}(,core=\"\[0-9\]*\")?\\\}\\\].*"
2119 verbose -log "expecting: $pattern"
2120 mi_gdb_test "-thread-info" $pattern $test
2123 # Return a list of MI features supported by this gdb.
2124 proc mi_get_features {} {
2125 global expect_out mi_gdb_prompt
2127 send_gdb "-list-features\n"
2130 -re "\\^done,features=\\\[(.*)\\\]\r\n$mi_gdb_prompt$" {
2131 regsub -all -- \" $expect_out(1,string) "" features
2132 return [split $features ,]
2134 -re ".*\r\n$mi_gdb_prompt$" {
2135 verbose -log "got $expect_out(buffer)"
2139 verbose -log "timeout in mi_gdb_prompt"
2145 # Variable Object Trees
2147 # Yet another way to check varobjs. Pass mi_walk_varobj_tree a "list" of
2148 # variables (not unlike the actual source code definition), and it will
2149 # automagically test the children for you (by default).
2171 # foo *f = new foo (); <-- break here
2173 # We want to check all the children of "f".
2175 # Translate the above structures into the following tree:
2181 # anonymous struct {
2192 # {const int *} iPtr {
2193 # {const int} {*iPtr} {}
2203 # mi_walk_varobj_tree c++ $tree
2205 # If you'd prefer to walk the tree using your own callback,
2206 # simply pass the name of the callback to mi_walk_varobj_tree.
2208 # This callback should take one argument, the name of the variable
2209 # to process. This name is the name of a global array holding the
2210 # variable's properties (object name, type, etc).
2212 # An example callback:
2214 # proc my_callback {var} {
2215 # upvar #0 $var varobj
2217 # puts "my_callback: called on varobj $varobj(obj_name)"
2220 # The arrays created for each variable object contain the following
2223 # obj_name - the object name for accessing this variable via MI
2224 # display_name - the display name for this variable (exp="display_name" in
2225 # the output of -var-list-children)
2226 # type - the type of this variable (type="type" in the output
2227 # of -var-list-children, or the special tag "anonymous"
2228 # path_expr - the "-var-info-path-expression" for this variable
2229 # NOTE: This member cannot be used reliably with typedefs.
2231 # See notes inside get_path_expr for more.
2232 # parent - the variable name of the parent varobj
2233 # children - a list of children variable names (which are the
2234 # names Tcl arrays, not object names)
2236 # For each variable object, an array containing the above fields will
2237 # be created under the root node (conveniently called, "root"). For example,
2238 # a variable object with handle "OBJ.public.0_anonymous.a" will have
2239 # a corresponding global Tcl variable named "root.OBJ.public.0_anonymous.a".
2241 # Note that right now, this mechanism cannot be used for recursive data
2242 # structures like linked lists.
2244 namespace eval ::varobj_tree {
2245 # An index which is appended to root varobjs to ensure uniqueness.
2246 variable _root_idx 0
2248 # A procedure to help with debuggging varobj trees.
2249 # VARIABLE_NAME is the name of the variable to dump.
2250 # CMD, if present, is the name of the callback to output the contstructed
2251 # strings. By default, it uses expect's "send_log" command.
2252 # TERM, if present, is a terminating character. By default it is the newline.
2254 # To output to the terminal (not the expect log), use
2255 # mi_varobj_tree_dump_variable my_variable puts ""
2257 proc mi_varobj_tree_dump_variable {variable_name {cmd send_log} {term "\n"}} {
2258 upvar #0 $variable_name varobj
2260 eval "$cmd \"VAR = $variable_name$term\""
2262 # Explicitly encode the array indices, since outputting them
2263 # in some logical order is better than what "array names" might
2265 foreach idx {obj_name parent display_name type path_expr} {
2266 eval "$cmd \"\t$idx = $varobj($idx)$term\""
2270 set num [llength $varobj(children)]
2271 eval "$cmd \"\tnum_children = $num$term\""
2273 eval "$cmd \"\tchildren = $varobj(children)$term\""
2277 # The default callback used by mi_walk_varobj_tree. This callback
2278 # simply checks all of VAR's children. It specifically does not test
2279 # path expressions, since that is very problematic.
2281 # This procedure may be used in custom callbacks.
2282 proc test_children_callback {variable_name} {
2283 upvar #0 $variable_name varobj
2285 if {[llength $varobj(children)] > 0} {
2286 # Construct the list of children the way mi_list_varobj_children
2287 # expects to get it:
2288 # { {obj_name display_name num_children type} ... }
2289 set children_list {}
2290 foreach child $varobj(children) {
2292 set clist [list [string_to_regexp $c(obj_name)] \
2293 [string_to_regexp $c(display_name)] \
2294 [llength $c(children)]]
2295 if {[string length $c(type)] > 0} {
2296 lappend clist [string_to_regexp $c(type)]
2298 lappend children_list $clist
2301 mi_list_varobj_children $varobj(obj_name) $children_list \
2302 "VT: list children of $varobj(obj_name)"
2306 # Set the properties of the varobj represented by
2307 # PARENT_VARIABLE - the name of the parent's variable
2308 # OBJNAME - the MI object name of this variable
2309 # DISP_NAME - the display name of this variable
2310 # TYPE - the type of this variable
2311 # PATH - the path expression for this variable
2312 # CHILDREN - a list of the variable's children
2313 proc create_varobj {parent_variable objname disp_name \
2314 type path children} {
2315 upvar #0 $parent_variable parent
2317 set var_name "root.$objname"
2319 array set $var_name [list obj_name $objname]
2320 array set $var_name [list display_name $disp_name]
2321 array set $var_name [list type $type]
2322 array set $var_name [list path_expr $path]
2323 array set $var_name [list parent "$parent_variable"]
2324 array set $var_name [list children \
2325 [get_tree_children $var_name $children]]
2329 # Should VARIABLE be used in path expressions? The CPLUS_FAKE_CHILD
2330 # varobjs and anonymous structs/unions are not used for path expressions.
2331 proc is_path_expr_parent {variable} {
2332 upvar #0 $variable varobj
2334 # If the varobj's type is "", it is a CPLUS_FAKE_CHILD.
2335 # If the tail of the varobj's object name is "%d_anonymous",
2336 # then it represents an anonymous struct or union.
2337 if {[string length $varobj(type)] == 0 \
2338 || [regexp {[0-9]+_anonymous$} $varobj(obj_name)]} {
2345 # Return the path expression for the variable named NAME in
2346 # parent varobj whose variable name is given by PARENT_VARIABLE.
2347 proc get_path_expr {parent_variable name type} {
2348 upvar #0 $parent_variable parent
2349 upvar #0 $parent_variable path_parent
2351 # If TYPE is "", this is one of the CPLUS_FAKE_CHILD varobjs,
2352 # which has no path expression. Likewsise for anonymous structs
2354 if {[string length $type] == 0 \
2355 || [string compare $type "anonymous"] == 0} {
2359 # Find the path parent variable.
2360 while {![is_path_expr_parent $parent_variable]} {
2361 set parent_variable $path_parent(parent)
2362 upvar #0 $parent_variable path_parent
2365 # This is where things get difficult. We do not actually know
2366 # the real type for variables defined via typedefs, so we don't actually
2367 # know whether the parent is a structure/union or not.
2369 # So we assume everything that isn't a simple type is a compound type.
2371 regexp {\*+} $parent(type) stars
2373 if {[string index $name 0] == "*"} {
2377 if {[string index $parent(type) end] == "\]"} {
2378 # Parent is an array.
2379 return "($path_parent(path_expr))\[$name\]"
2380 } elseif {$is_compound} {
2381 # Parent is a structure or union or a pointer to one.
2382 if {[string length $stars]} {
2390 # To make matters even more hideous, varobj.c has slightly different
2391 # path expressions for C and C++.
2392 set path_expr "($path_parent(path_expr))$join$name"
2393 if {[string compare -nocase $root(language) "c"] == 0} {
2396 return "($path_expr)"
2399 # Parent is a pointer.
2400 return "*($path_parent(path_expr))"
2404 # Process the CHILDREN (a list of varobj_tree elements) of the variable
2405 # given by PARENT_VARIABLE. Returns a list of children variables.
2406 proc get_tree_children {parent_variable children} {
2407 upvar #0 $parent_variable parent
2410 set children_list {}
2411 foreach {type name children} $children {
2412 if {[string compare $parent_variable "root"] == 0} {
2416 set objname "$name$_root_idx"
2417 set disp_name "$name"
2418 set path_expr "$name"
2419 } elseif {[string compare $type "anonymous"] == 0} {
2420 # Special case: anonymous types. In this case, NAME will either be
2421 # "struct" or "union".
2422 set objname "$parent(obj_name).${field_idx}_anonymous"
2423 set disp_name "<anonymous $name>"
2425 set type "$name {...}"
2427 set objname "$parent(obj_name).$name"
2429 set path_expr [get_path_expr $parent_variable $name $type]
2432 lappend children_list [create_varobj $parent_variable $objname \
2433 $disp_name $type $path_expr $children]
2437 return $children_list
2440 # The main procedure to call the given CALLBACK on the elements of the
2441 # given varobj TREE. See detailed explanation above.
2442 proc walk_tree {language tree callback} {
2446 if {[llength $tree] < 3} {
2447 error "tree does not contain enough elements"
2452 # Create root node and process the tree.
2453 array set root [list language $language]
2454 array set root [list obj_name "root"]
2455 array set root [list display_name "root"]
2456 array set root [list type "root"]
2457 array set root [list path_expr "root"]
2458 array set root [list parent "root"]
2459 array set root [list children [get_tree_children root $tree]]
2462 set all_nodes $root(children); # a stack of nodes
2463 while {[llength $all_nodes] > 0} {
2464 # "Pop" the name of the global variable containing this varobj's
2465 # information from the stack of nodes.
2466 set var_name [lindex $all_nodes 0]
2467 set all_nodes [lreplace $all_nodes 0 0]
2469 # Bring the global named in VAR_NAME into scope as the local variable
2471 upvar #0 $var_name varobj
2473 # Append any children of VAROBJ to the list of nodes to walk.
2474 if {[llength $varobj(children)] > 0} {
2475 set all_nodes [concat $all_nodes $varobj(children)]
2478 # If this is a root variable, create the variable object for it.
2479 if {[string compare $varobj(parent) "root"] == 0} {
2480 mi_create_varobj $varobj(obj_name) $varobj(display_name) \
2481 "VT: create root varobj for $varobj(display_name)"
2484 # Now call the callback for VAROBJ.
2485 uplevel #0 $callback $var_name
2490 # The default varobj tree callback, which simply tests -var-list-children.
2491 proc mi_varobj_tree_test_children_callback {variable} {
2492 ::varobj_tree::test_children_callback $variable
2495 # Walk the variable object tree given by TREE, calling the specified
2496 # CALLBACK. By default this uses mi_varobj_tree_test_children_callback.
2497 proc mi_walk_varobj_tree {language tree \
2499 mi_varobj_tree_test_children_callback}} {
2500 ::varobj_tree::walk_tree $language $tree $callback
2503 # Build a list of key-value pairs given by the list ATTR_LIST. Flatten
2504 # this list using the optional JOINER, a comma by default.
2506 # The list must contain an even number of elements, which are the key-value
2507 # pairs. Each value will be surrounded by quotes, according to the grammar,
2508 # except if the value starts with \[ or \{, when the quotes will be omitted.
2510 # Example: mi_build_kv_pairs {a b c d e f g \[.*\]}
2511 # returns a=\"b\",c=\"d\",e=\"f\",g=\[.*\]
2512 proc mi_build_kv_pairs {attr_list {joiner ,}} {
2514 foreach {var value} $attr_list {
2515 if {[string range $value 0 1] == "\\\["
2516 || [string range $value 0 1] == "\\\{"} {
2517 lappend l "$var=$value"
2519 lappend l "$var=\"$value\""
2522 return "[join $l $joiner]"
2525 # Construct a breakpoint location regexp. This may be used along with
2526 # mi_make_breakpoint_multi to test the output of -break-insert,
2527 # -dprintf-insert, or -break-info with breapoints with multiple
2530 # All arguments for the breakpoint location may be specified using the
2531 # options: number, enabled, addr, func, file, fullname, line,
2532 # thread-groups, and thread.
2534 # For the option -thread the corresponding output field is only added
2535 # if the option is present and not set to the empty string.
2537 # Example: mi_make_breakpoint_loc -number 2.1 -file ".*/myfile.c" -line 3
2538 # will return the breakpoint location:
2539 # {number="2.1",enabled=".*",addr=".*",func=".*",
2540 # file=".*/myfile.c",fullname=".*",line="3",thread-groups=\[.*\]}
2542 proc mi_make_breakpoint_loc {args} {
2543 parse_args {{number .*} {enabled .*} {addr .*}
2544 {func .*} {file .*} {fullname .*} {line .*}
2545 {thread-groups \\\[.*\\\]} {thread ""}}
2548 foreach attr [list number enabled addr func file \
2549 fullname line thread-groups] {
2550 lappend attr_list $attr [set $attr]
2553 set result [mi_build_kv_pairs $attr_list]
2555 if {[string length $thread] > 0} {
2557 append result [mi_build_kv_pairs [list "thread" $thread]]
2563 # Bits shared between mi_make_breakpoint and mi_make_breakpoint_multi.
2565 proc mi_make_breakpoint_1 {attr_list thread cond evaluated-by times \
2566 ignore script original-location} {
2567 set result "bkpt=\\\{[mi_build_kv_pairs $attr_list]"
2569 # There are always exceptions.
2571 # If THREAD is not present, do not output it.
2572 if {[string length $thread] > 0} {
2574 append result [mi_build_kv_pairs [list "thread" $thread]]
2577 # If COND is not present, do not output it.
2578 if {[string length $cond] > 0} {
2580 append result [mi_build_kv_pairs [list "cond" $cond]]
2582 # When running on a remote, GDB may output who is evaluating
2583 # breakpoint conditions.
2584 if {[string length ${evaluated-by}] > 0} {
2585 append result [mi_build_kv_pairs \
2586 [list "evaluated-by" ${evaluated-by}]]
2588 append result {(,evaluated-by=".*")?}
2593 append result [mi_build_kv_pairs [list "times" $times]]
2595 # If SCRIPT and IGNORE are not present, do not output them.
2598 append result [mi_build_kv_pairs [list "ignore" $ignore]]
2601 if {[string length $script] > 0} {
2603 append result [mi_build_kv_pairs [list "script" $script]]
2606 # Allow anything up until the next "official"/required attribute.
2607 # This pattern skips over script/ignore if matches on those
2608 # were not specifically required by the caller.
2611 append result [mi_build_kv_pairs \
2612 [list "original-location" ${original-location}]]
2618 # Construct a breakpoint regexp, for a breakpoint with multiple
2619 # locations. This may be used to test the output of -break-insert,
2620 # -dprintf-insert, or -break-info with breakpoints with multiple
2623 # All arguments for the breakpoint may be specified using the options:
2624 # number, type, disp, enabled, times, ignore, script,
2625 # original-location, cond, evaluated-by, locations, and thread.
2627 # Only if -script and -ignore are given will they appear in the output.
2628 # Otherwise, this procedure will skip them using ".*".
2630 # For the options -thread and -cond the corresponding output fields
2631 # are only added if the options are present and not set to the empty
2634 # Example: mi_make_breakpoint_multi -number 2 -locations "$loc"
2635 # will return the breakpoint:
2636 # bkpt={number="2",type=".*",disp=".*",enabled=".*",addr="<MULTIPLE>",
2637 # times="0".*original-location=".*",locations=$loc}
2639 # You can construct the list of locations with mi_make_breakpoint_loc.
2641 proc mi_make_breakpoint_multi {args} {
2642 parse_args {{number .*} {type .*} {disp .*} {enabled .*}
2643 {times .*} {ignore 0}
2644 {script ""} {original-location .*} {cond ""} {evaluated-by ""}
2645 {locations .*} {thread ""}}
2648 foreach attr [list number type disp enabled] {
2649 lappend attr_list $attr [set $attr]
2652 lappend attr_list "addr" "<MULTIPLE>"
2654 set result [mi_make_breakpoint_1 \
2655 $attr_list $thread $cond ${evaluated-by} $times \
2656 $ignore $script ${original-location}]
2659 append result [mi_build_kv_pairs [list "locations" $locations]]
2661 append result "\\\}"
2665 # Construct a breakpoint regexp, for a pending breakpoint. This may
2666 # be used to test the output of -break-insert, -dprintf-insert, or
2667 # -break-info for pending breakpoints.
2669 # Arguments for the breakpoint may be specified using the options:
2670 # number, type, disp, enabled, pending, original-location, thread, and
2673 # For the options -thread and -cond the corresponding output fields
2674 # are only included if the options are present and not the empty
2677 # Example: mi_make_breakpoint_pending -number 2 -pending func
2678 # will return the breakpoint:
2679 # bkpt={number="2",type=".*",disp=".*",enabled=".*",addr="<PENDING>",
2680 # pending="func", times="0".*original-location=".*"}
2682 proc mi_make_breakpoint_pending {args} {
2683 parse_args {{number .*} {type .*} {disp .*} {enabled .*}
2684 {pending .*} {original-location .*} {thread ""} {cond ""}}
2687 foreach attr [list number type disp enabled] {
2688 lappend attr_list $attr [set $attr]
2691 lappend attr_list "addr" "<PENDING>"
2693 foreach attr [list pending] {
2694 lappend attr_list $attr [set $attr]
2702 set result [mi_make_breakpoint_1 \
2703 $attr_list $thread $cond ${evaluated-by} $times \
2704 $ignore $script ${original-location}]
2706 append result "\\\}"
2710 # Construct a breakpoint regexp. This may be used to test the output of
2711 # -break-insert, -dprintf-insert, or -break-info.
2713 # All arguments for the breakpoint may be specified using the options
2714 # number, type, disp, enabled, addr, func, file, fullanme, line,
2715 # thread-groups, cond, evaluated-by, times, ignore, script,
2716 # and original-location.
2718 # Only if -script and -ignore are given will they appear in the output.
2719 # Otherwise, this procedure will skip them using ".*".
2721 # Example: mi_make_breakpoint -number 2 -file ".*/myfile.c" -line 3
2722 # will return the breakpoint:
2723 # bkpt={number="2",type=".*",disp=".*",enabled=".*",addr=".*",func=".*",
2724 # file=".*/myfile.c",fullname=".*",line="3",thread-groups=\[.*\],
2725 # times="0".*original-location=".*"}
2727 proc mi_make_breakpoint {args} {
2728 parse_args {{number .*} {type .*} {disp .*} {enabled .*} {addr .*}
2729 {func .*} {file .*} {fullname .*} {line .*}
2730 {thread-groups \\\[.*\\\]} {times .*} {ignore 0}
2731 {script ""} {original-location .*} {cond ""} {evaluated-by ""}
2735 foreach attr [list number type disp enabled addr func file \
2736 fullname line thread-groups] {
2737 lappend attr_list $attr [set $attr]
2740 set result [mi_make_breakpoint_1 \
2741 $attr_list $thread $cond ${evaluated-by} $times \
2742 $ignore $script ${original-location}]
2744 append result "\\\}"
2748 # Build a breakpoint table regexp given the list of breakpoints in `bp_list',
2749 # constructed by mi_make_breakpoint.
2751 # Example: Construct a breakpoint table where the only attributes we
2752 # test for are the existence of three breakpoints numbered 1, 2, and 3.
2755 # lappend bps [mi_make_breakpoint -number 1]
2756 # lappend bps [mi_make_breakpoint -number 2]
2757 # lappned bps [mi_make_breakpoint -number 3]
2758 # mi_make_breakpoint_table $bps
2759 # will return (abbreviated for clarity):
2760 # BreakpointTable={nr_rows="3",nr_cols="6",hdr=[{width=".*",...} ...],
2761 # body=[bkpt={number="1",...},bkpt={number="2",...},bkpt={number="3",...}]}
2763 proc mi_make_breakpoint_table {bp_list} {
2764 # Build header -- assume a standard header for all breakpoint tables.
2766 foreach {nm hdr} [list number Num type Type disp Disp enabled Enb \
2767 addr Address what What] {
2768 # The elements here are the MI table headers, which have the
2770 # {width="7",alignment="-1",col_name="number",colhdr="Num"}
2771 lappend hl "{[mi_build_kv_pairs [list width .* alignment .* \
2772 col_name $nm colhdr $hdr]]}"
2774 set header "hdr=\\\[[join $hl ,]\\\]"
2776 # The caller has implicitly supplied the number of columns and rows.
2777 set nc [llength $hl]
2778 set nr [llength $bp_list]
2780 # Build body -- mi_make_breakpoint has done most of the work.
2781 set body "body=\\\[[join $bp_list ,]\\\]"
2783 # Assemble the final regexp.
2784 return "BreakpointTable={nr_rows=\"$nr\",nr_cols=\"$nc\",$header,$body}"
2787 # As skip_libstdcxx_probe_tests_prompt, with mi_gdb_prompt.
2789 proc mi_skip_libstdcxx_probe_tests {} {
2790 global mi_gdb_prompt
2791 return [skip_libstdcxx_probe_tests_prompt "$mi_gdb_prompt$"]
2794 # Check whether we're testing with the remote or extended-remote
2797 proc mi_is_target_remote {} {
2798 global mi_gdb_prompt
2800 return [gdb_is_target_remote_prompt "$mi_gdb_prompt"]
2803 # Retrieve the value of EXP in the inferior, represented in format
2804 # specified in FMT (using "printFMT"). DEFAULT is used as fallback if
2805 # print fails. TEST is the test message to use. It can be omitted,
2806 # in which case a test message is built from EXP.
2808 # This is an MI version of gdb_valueof.
2810 proc mi_get_valueof { fmt exp default {test ""} } {
2811 global mi_gdb_prompt
2814 set test "get valueof \"${exp}\""
2818 gdb_test_multiple "print${fmt} ${exp}" "$test" -prompt "$::mi_gdb_prompt$" {
2819 -re "~\"\\$\[0-9\]* = (\[^\r\n\]*)\\\\n\"\r\n\\^done\r\n$mi_gdb_prompt$" {
2820 set val $expect_out(1,string)
2824 fail "$test (timeout)"
2830 # Some MI tests should be run in the normal way, on the main UI, while
2831 # other tests should be run twice, once when the MI is on the main UI,
2832 # and once with the MI on a secondary UI, this proc facilitates that.
2836 # foreach_mi_ui_mode mode {
2840 # The BODY will then be run once with MODE set to 'main' and once with
2841 # MODE set to 'separate'.
2843 # However, there are times when we know using the 'separate' UI will
2844 # not work. This proc handles figuring that out, if the 'separate' UI
2845 # is known not to work then the 'separate' mode will be skipped and
2846 # BODY will be run just once with MODE set to 'main'.
2848 proc foreach_mi_ui_mode { var_name body } {
2849 upvar 1 $var_name var
2851 if [gdb_debug_enabled] {
2852 # gdb debug doesn't work for separate-mi-tty.
2855 set modes {"main" "separate"}
2858 foreach var $modes {
2859 with_test_prefix "$var_name=$var" {
2860 set code [catch {uplevel 1 $body} result]
2864 global errorInfo errorCode
2865 return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
2866 } elseif {$code == 3} {
2868 } elseif {$code == 2} {
2869 return -code $code $result