1 # Copyright 1999-2022 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/>.
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 inferior_pty no-tty
243 # Set the default value, it may be overriden later by specific testfile.
244 set use_gdb_stub [target_info exists use_gdb_stub]
247 if { [info procs sid_start] != "" } {
248 verbose "Spawning SID"
252 if [info exists gdb_spawn_id] {
256 save_vars { GDBFLAGS } {
257 append GDBFLAGS " $MIFLAGS"
266 -re "~\"GNU.*\r\n~\".*$mi_gdb_prompt$" {
267 # We have a new format mi startup prompt. If we are
268 # running mi1, then this is an error as we should be
269 # using the old-style prompt.
270 if { $MIFLAGS == "-i=mi1" } {
271 perror "(mi startup) Got unexpected new mi prompt."
276 verbose "GDB initialized."
278 -re "\[^~\].*$mi_gdb_prompt$" {
279 # We have an old format mi startup prompt. If we are
280 # not running mi1, then this is an error as we should be
281 # using the new-style prompt.
282 if { $MIFLAGS != "-i=mi1" } {
283 perror "(mi startup) Got unexpected old mi prompt."
288 verbose "GDB initialized."
290 -re ".*unrecognized option.*for a complete list of options." {
291 untested "skip mi tests (not compiled with mi support)."
296 -re ".*Interpreter `mi' unrecognized." {
297 untested "skip mi tests (not compiled with mi support)."
303 perror "(timeout) GDB never initialized after 10 seconds."
309 set gdb_main_spawn_id $gdb_spawn_id
310 set mi_spawn_id $gdb_spawn_id
312 # FIXME: mi output does not go through pagers, so these can be removed.
313 # force the height to "unlimited", so no pagers get used
314 send_gdb "100-gdb-set height 0\n"
316 -re ".*100-gdb-set height 0\r\n100\\\^done\r\n$mi_gdb_prompt$" {
317 verbose "Setting height to 0." 2
320 warning "Couldn't set the height to 0"
323 # force the width to "unlimited", so no wraparound occurs
324 send_gdb "101-gdb-set width 0\n"
326 -re ".*101-gdb-set width 0\r\n101\\\^done\r\n$mi_gdb_prompt$" {
327 verbose "Setting width to 0." 2
330 warning "Couldn't set the width to 0."
334 if { $separate_inferior_pty } {
335 mi_create_inferior_pty
338 if {![info exists inferior_spawn_id]} {
339 set inferior_spawn_id $gdb_spawn_id
348 # Overridable function. You can override this function in your
351 proc mi_gdb_start { args } {
352 return [eval default_mi_gdb_start $args]
355 # Many of the tests depend on setting breakpoints at various places and
356 # running until that breakpoint is reached. At times, we want to start
357 # with a clean-slate with respect to breakpoints, so this utility proc
358 # lets us do this without duplicating this code everywhere.
361 proc mi_delete_breakpoints {} {
364 # FIXME: The mi operation won't accept a prompt back and will use the 'all' arg
365 send_gdb "102-break-delete\n"
367 -re "Delete all breakpoints.*y or n.*$" {
371 -re "102-break-delete\r\n102\\\^done\r\n$mi_gdb_prompt$" {
372 # This happens if there were no breakpoints
374 timeout { perror "Delete all breakpoints in mi_delete_breakpoints (timeout)" ; return }
377 # The correct output is not "No breakpoints or watchpoints." but an
378 # empty BreakpointTable. Also, a query is not acceptable with mi.
379 send_gdb "103-break-list\n"
381 -re "103-break-list\r\n103\\\^done,BreakpointTable=\{\}\r\n$mi_gdb_prompt$" {}
382 -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$" {}
383 -re "103-break-list\r\n103\\\^doneNo breakpoints or watchpoints.\r\n\r\n$mi_gdb_prompt$" {warning "Unexpected console text received"}
384 -re "$mi_gdb_prompt$" { perror "Breakpoints not deleted" ; return }
385 -re "Delete all breakpoints.*or n.*$" {
386 warning "Unexpected prompt for breakpoints deletion"
390 timeout { perror "-break-list (timeout)" ; return }
394 proc mi_gdb_reinitialize_dir { subdir } {
398 if [is_remote host] {
402 if { $MIFLAGS == "-i=mi1" } {
403 send_gdb "104-environment-directory\n"
405 -re ".*Reinitialize source path to empty.*y or n. " {
406 warning "Got confirmation prompt for dir reinitialization."
409 -re "$mi_gdb_prompt$" {}
410 timeout {error "Dir reinitialization failed (timeout)"}
413 -re "$mi_gdb_prompt$" {}
414 timeout {error "Dir reinitialization failed (timeout)"}
417 send_gdb "104-environment-directory -r\n"
419 -re "104\\\^done,source-path=.*\r\n$mi_gdb_prompt$" {}
420 -re "$mi_gdb_prompt$" {}
421 timeout {error "Dir reinitialization failed (timeout)"}
425 send_gdb "105-environment-directory $subdir\n"
427 -re "Source directories searched.*$mi_gdb_prompt$" {
428 verbose "Dir set to $subdir"
430 -re "105\\\^done.*\r\n$mi_gdb_prompt$" {
431 # FIXME: We return just the prompt for now.
432 verbose "Dir set to $subdir"
433 # perror "Dir \"$subdir\" failed."
438 # Send GDB the "target" command.
439 # FIXME: Some of these patterns are not appropriate for MI. Based on
440 # config/monitor.exp:gdb_target_command.
441 proc mi_gdb_target_cmd { targetname serialport } {
444 set serialport_re [string_to_regexp $serialport]
445 for {set i 1} {$i <= 3} {incr i} {
446 send_gdb "47-target-select $targetname $serialport\n"
448 -re "47\\^connected.*$mi_gdb_prompt" {
449 verbose "Set target to $targetname"
452 -re "unknown host.*$mi_gdb_prompt" {
453 verbose "Couldn't look up $serialport"
455 -re "Couldn't establish connection to remote.*$mi_gdb_prompt$" {
456 verbose "Connection failed"
458 -re "Remote MIPS debugging.*$mi_gdb_prompt$" {
459 verbose "Set target to $targetname"
462 -re "Remote debugging using .*$serialport_re.*$mi_gdb_prompt$" {
463 verbose "Set target to $targetname"
466 -re "Remote target $targetname connected to.*$mi_gdb_prompt$" {
467 verbose "Set target to $targetname"
470 -re "Connected to.*$mi_gdb_prompt$" {
471 verbose "Set target to $targetname"
474 -re "Ending remote.*$mi_gdb_prompt$" { }
475 -re "Connection refused.*$mi_gdb_prompt$" {
476 verbose "Connection refused by remote target. Pausing, and trying again."
480 -re "Non-stop mode requested, but remote does not support non-stop.*$mi_gdb_prompt" {
481 unsupported "non-stop mode not supported"
484 -re "Timeout reading from remote system.*$mi_gdb_prompt$" {
485 verbose "Got timeout error from gdb."
497 # load a file into the debugger (file command only).
498 # return a -1 if anything goes wrong.
500 proc mi_gdb_file_cmd { arg } {
505 global last_loaded_file
506 upvar timeout timeout
508 # GCC for Windows target may create foo.exe given "-o foo".
509 if { ![file exists $arg] && [file exists "$arg.exe"] } {
513 set last_loaded_file $arg
515 if [is_remote host] {
516 set arg [remote_download host $arg]
518 error "download failed"
523 # FIXME: Several of these patterns are only acceptable for console
524 # output. Queries are an error for mi.
525 send_gdb "105-file-exec-and-symbols $arg\n"
527 -re "Reading symbols from.*$mi_gdb_prompt$" {
528 verbose "\t\tLoaded $arg into the $GDB"
531 -re "has no symbol-table.*$mi_gdb_prompt$" {
532 perror "$arg wasn't compiled with \"-g\""
535 -re "Load new symbol table from \".*\".*y or n. $" {
538 -re "Reading symbols from.*$mi_gdb_prompt$" {
539 verbose "\t\tLoaded $arg with new symbol table into $GDB"
543 perror "(timeout) Couldn't load $arg, other program already loaded."
548 -re "No such file or directory.*$mi_gdb_prompt$" {
549 perror "($arg) No such file or directory\n"
552 -re "105-file-exec-and-symbols .*\r\n105\\\^done\r\n$mi_gdb_prompt$" {
553 # We (MI) are just giving the prompt back for now, instead of giving
554 # some acknowledgement.
558 perror "couldn't load $arg into $GDB (timed out)."
562 # This is an attempt to detect a core dump, but seems not to
563 # work. Perhaps we need to match .* followed by eof, in which
564 # gdb_expect does not seem to have a way to do that.
565 perror "couldn't load $arg into $GDB (end of file)."
572 # connect to the target and download a file, if necessary.
573 # return a -1 if anything goes wrong.
575 proc mi_gdb_target_load { } {
581 if [target_info exists gdb_load_timeout] {
582 set loadtimeout [target_info gdb_load_timeout]
587 if { [info procs gdbserver_gdb_load] != "" } {
588 mi_gdb_test "kill" ".*" ""
589 if { [catch gdbserver_gdb_load res] == 1 } {
593 set protocol [lindex $res 0]
594 set gdbport [lindex $res 1]
596 if { [mi_gdb_target_cmd $protocol $gdbport] != 0 } {
599 } elseif { [info procs send_target_sid] != "" } {
600 # For SID, things get complex
603 -re ".*$mi_gdb_prompt$"
606 gdb_expect $loadtimeout {
607 -re "\\^done.*$mi_gdb_prompt$" {
610 perror "Unable to connect to SID target (timeout)"
614 send_gdb "48-target-download\n"
615 gdb_expect $loadtimeout {
616 -re "48\\^done.*$mi_gdb_prompt$" {
619 perror "Unable to download to SID target (timeout)"
623 } elseif { [target_info protocol] == "sim" } {
624 set target_sim_options "[board_info target gdb,target_sim_options]"
625 # For the simulator, just connect to it directly.
626 send_gdb "47-target-select sim $target_sim_options\n"
627 gdb_expect $loadtimeout {
628 -re "47\\^connected.*$mi_gdb_prompt$" {
631 perror "Unable to select sim target (timeout)"
635 send_gdb "48-target-download\n"
636 gdb_expect $loadtimeout {
637 -re "48\\^done.*$mi_gdb_prompt$" {
640 perror "Unable to download to sim target (timeout)"
644 } elseif { [target_info gdb_protocol] == "remote" } {
646 if { [mi_gdb_target_cmd "remote" [target_info netport]] != 0 } {
647 perror "Unable to connect to remote target"
650 send_gdb "48-target-download\n"
651 gdb_expect $loadtimeout {
652 -re "48\\^done.*$mi_gdb_prompt$" {
655 perror "Unable to download to remote target (timeout)"
664 # load a file into the debugger.
665 # return a -1 if anything goes wrong.
667 proc mi_gdb_load { arg } {
669 return [mi_gdb_file_cmd $arg]
674 # Return 1 if symbols were read in using -readnow. Otherwise, return 0.
675 # Based on readnow from lib/gdb.exp.
677 proc mi_readnow { args } {
680 if { [llength $args] == 1 } {
681 set re [lindex $args 0]
687 set cmd "maint print objfiles $re"
690 -re ".gdb_index: faked for ..readnow.." {
691 # Record that we've seen the above pattern.
695 -re "\\^done\r\n$mi_gdb_prompt$" {
702 # mi_gdb_test COMMAND [PATTERN [MESSAGE [IPATTERN]]] -- send a command to gdb;
705 # COMMAND is the command to execute, send to GDB with send_gdb. If
706 # this is the null string no command is sent.
707 # PATTERN is the pattern to match for a PASS, and must NOT include
708 # the \r\n sequence immediately before the gdb prompt.
709 # If not specified, .* is used.
710 # MESSAGE is the message to be printed. (If this is the empty string,
711 # then sometimes we don't call pass or fail at all; I don't
712 # understand this at all.)
713 # If not specified, COMMAND is used.
714 # IPATTERN is the pattern to match for the inferior's output. This parameter
715 # is optional. If present, it will produce a PASS if the match is
716 # successful, and a FAIL if unsuccessful.
719 # 1 if the test failed,
720 # 0 if the test passes,
721 # -1 if there was an internal error.
723 proc mi_gdb_test { args } {
726 global GDB expect_out
727 global inferior_exited_re async
728 upvar timeout timeout
730 if {[llength $args] >= 1} {
731 set command [lindex $args 0]
733 error "Not enough arguments in mi_gdb_test"
736 if {[llength $args] >= 2} {
737 set pattern [lindex $args 1]
742 if {[llength $args] >= 3} {
743 set message [lindex $args 2]
748 if [llength $args]==4 {
749 set ipattern [lindex $args 3]
752 if [llength $args]==5 {
753 set question_string [lindex $args 3]
754 set response_string [lindex $args 4]
756 set question_string "^FOOBAR$"
759 if { [llength $args] >= 6 } {
760 error "Too many arguments in mi_gdb_test"
764 send_user "Sending \"$command\" to gdb\n"
765 send_user "Looking to match \"$pattern\"\n"
766 send_user "Message is \"$message\"\n"
770 set string "${command}\n"
771 set string_regex [string_to_regexp $command]
773 if { $command != "" } {
774 while { "$string" != "" } {
775 set foo [string first "\n" "$string"]
776 set len [string length "$string"]
777 if { $foo < [expr $len - 1] } {
778 set str [string range "$string" 0 $foo]
779 if { [send_gdb "$str"] != "" } {
780 perror "Couldn't send $command to GDB."
786 set string [string range "$string" [expr $foo + 1] end]
791 if { "$string" != "" } {
792 if { [send_gdb "$string"] != "" } {
793 perror "Couldn't send $command to GDB."
798 if [info exists timeout] {
802 if [info exists timeout] {
809 # With $prompt_re "" there may come arbitrary asynchronous response
810 # from the previous command, before or after $string_regex.
811 set string_regex ".*"
813 verbose -log "Expecting: ^($string_regex\[\r\n\]+)?($pattern\[\r\n\]+$mi_gdb_prompt\[ \]*)"
815 -re "\\*\\*\\* DOSEXIT code.*" {
816 if { $message != "" } {
821 -re "Ending remote debugging.*$mi_gdb_prompt\[ \]*$" {
823 warning "Can`t communicate to remote target."
829 -re "^($string_regex\[\r\n\]+)?($pattern\[\r\n\]+$mi_gdb_prompt\[ \]*)" {
830 # At this point, $expect_out(1,string) is the MI input command.
831 # and $expect_out(2,string) is the MI output command.
832 # If $expect_out(1,string) is "", then there was no MI input command here.
834 # NOTE, there is no trailing anchor because with GDB/MI,
835 # asynchronous responses can happen at any point, causing more
836 # data to be available. Normally an anchor is used to make
837 # sure the end of the output is matched, however, $mi_gdb_prompt
838 # is just as good of an anchor since mi_gdb_test is meant to
839 # match a single mi output command. If a second GDB/MI output
840 # response is sent, it will be in the buffer for the next
841 # time mi_gdb_test is called.
842 if {![string match "" $message]} {
847 -re "(${question_string})$" {
848 send_gdb "$response_string\n"
851 -re "Undefined.* command:.*$mi_gdb_prompt\[ \]*$" {
852 perror "Undefined command \"$command\"."
856 -re "Ambiguous command.*$mi_gdb_prompt\[ \]*$" {
857 perror "\"$command\" is not a unique command name."
861 -re "$inferior_exited_re with code \[0-9\]+.*$mi_gdb_prompt\[ \]*$" {
862 if {![string match "" $message]} {
863 set errmsg "$message (the program exited)"
865 set errmsg "$command (the program exited)"
870 -re "The program is not being run.*$mi_gdb_prompt\[ \]*$" {
871 if {![string match "" $message]} {
872 set errmsg "$message (the program is no longer running)"
874 set errmsg "$command (the program is no longer running)"
879 -re ".*$mi_gdb_prompt\[ \]*$" {
880 if {![string match "" $message]} {
881 fail "$message (unexpected output)"
887 perror "Window too small."
891 perror "Process no longer exists"
892 if { $message != "" } {
898 perror "internal buffer is full."
902 if {![string match "" $message]} {
903 fail "$message (timeout)"
909 # If the GDB output matched, compare the inferior output.
910 if { $result == 0 } {
911 if [ info exists ipattern ] {
912 if { ![target_info exists gdb,noinferiorio] } {
913 global gdb_spawn_id inferior_spawn_id
915 set sid "$inferior_spawn_id $gdb_spawn_id"
917 -i "$sid" -re "$ipattern" {
918 pass "$message inferior output"
921 fail "$message inferior output (timeout)"
926 unsupported "$message inferior output"
934 # Collect output sent to the console output stream until UNTIL is
935 # seen. UNTIL is a regular expression. MESSAGE is the message to be
936 # printed in case of timeout.
938 proc mi_gdb_expect_cli_output {until message} {
942 -re "~\"(\[^\r\n\]+)\"\r\n" {
943 append output $expect_out(1,string)
946 -notransfer -re "$until" {
950 fail "$message (timeout)"
959 # MI run command. (A modified version of gdb_run_cmd)
962 # In patterns, the newline sequence ``\r\n'' is matched explicitly as
963 # ``.*$'' could swallow up output that we attempt to match elsewhere.
965 # Send the command to run the test program.
967 # If USE_MI_COMMAND is true, the "-exec-run" command is used.
968 # Otherwise, the "run" (CLI) command is used. If the global USE_GDB_STUB is
969 # true, -exec-continue and continue are used instead of their run counterparts.
971 # ARGS is passed as argument to the command used to run the test program.
972 # Beware that arguments to "-exec-run" do not have the same semantics as
973 # arguments to the "run" command, so USE_MI_COMMAND influences the meaning
974 # of ARGS. If USE_MI_COMMAND is true, they are arguments to -exec-run.
975 # If USE_MI_COMMAND is false, they are effectively arguments passed
976 # to the test program. If the global USE_GDB_STUB is true, ARGS is not used.
977 proc mi_run_cmd_full {use_mi_command args} {
978 global mi_gdb_prompt use_gdb_stub
979 global thread_selected_re
980 global library_loaded_re
982 if {$use_mi_command} {
983 set run_prefix "220-exec-"
990 foreach command [gdb_init_commands] {
991 send_gdb "$command\n"
993 -re "$mi_gdb_prompt$" { }
995 unresolved "gdb_init_command for target failed"
1001 if { [mi_gdb_target_load] < 0 } {
1006 if [target_info exists gdb,do_reload_on_run] {
1007 send_gdb "${run_prefix}continue\n"
1009 -re "${run_match}\\^running\[\r\n\]+\\*running,thread-id=\"\[^\"\]+\"\r\n$mi_gdb_prompt" {}
1010 -re "${run_match}\\^error.*$mi_gdb_prompt" {return -1}
1016 if [target_info exists gdb,start_symbol] {
1017 set start [target_info gdb,start_symbol]
1022 # HACK: Should either use 000-jump or fix the target code
1023 # to better handle RUN.
1024 send_gdb "jump *$start\n"
1025 warning "Using CLI jump command, expect run-to-main FAIL"
1027 -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}" {}
1029 unresolved "unable to start target"
1036 send_gdb "${run_prefix}run $args\n"
1038 -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}" {
1040 -re "\\^error,msg=\"The target does not support running in non-stop mode.\"" {
1041 unsupported "non-stop mode not supported"
1045 unresolved "unable to start target"
1049 # NOTE: Shortly after this there will be a ``000*stopped,...(gdb)''
1054 # A wrapper for mi_run_cmd_full which uses -exec-run and
1055 # -exec-continue, as appropriate. ARGS are passed verbatim to
1057 proc mi_run_cmd {args} {
1058 return [eval mi_run_cmd_full 1 $args]
1061 # A wrapper for mi_run_cmd_full which uses the CLI commands 'run' and
1062 # 'continue', as appropriate. ARGS are passed verbatim to
1064 proc mi_run_with_cli {args} {
1065 return [eval mi_run_cmd_full 0 $args]
1068 # Starts fresh GDB binary and loads an optional executable into GDB.
1069 # Usage: mi_clean_restart [executable]
1070 # EXECUTABLE is the basename of the binary.
1071 # Return -1 if starting gdb or loading the executable failed.
1073 proc mi_clean_restart { args } {
1079 if { [llength $args] > 1 } {
1080 error "bad number of args: [llength $args]"
1085 # This is a clean restart, so reset error and warning count.
1089 if {[mi_gdb_start]} {
1093 mi_gdb_reinitialize_dir $srcdir/$subdir
1095 if { [llength $args] >= 1 } {
1096 set executable [lindex $args 0]
1097 set binfile [standard_output_file ${executable}]
1098 return [mi_gdb_load ${binfile}]
1104 # Just like gdb's "runto" proc, it will run the target to a given
1105 # function. The big difference here between mi_runto and mi_execute_to
1106 # is that mi_execute_to must have the inferior running already. This
1107 # proc will (like gdb's runto) (re)start the inferior, too.
1109 # FUNC is the linespec of the place to stop (it inserts a breakpoint here).
1111 # -1 if failed, timedout
1114 # Supported options:
1116 # -qualified -- pass --qualified to -break-insert
1117 # -pending -- pass -f to -break-insert to create a pending
1120 proc mi_runto_helper {func run_or_continue args} {
1121 global mi_gdb_prompt expect_out
1122 global hex decimal fullname_syntax
1124 parse_args {{qualified} {pending}}
1126 set test "mi runto $func"
1128 set bp [mi_make_breakpoint_pending -type breakpoint -disp del]
1130 set bp [mi_make_breakpoint -type breakpoint -disp del \
1131 -func $func\(\\\(.*\\\)\)?]
1136 lappend extra_opts "--qualified"
1139 lappend extra_opts "-f"
1140 # MI prints "Function FUNC not defined", "No line NNN in current
1141 # file.", etc. to the CLI stream.
1142 set extra_output "&\"\[^\r\n\]+\"\r\n"
1144 mi_gdb_test "200-break-insert [join $extra_opts " "] -t $func" "${extra_output}200\\^done,$bp" \
1145 "breakpoint at $func"
1147 if {$run_or_continue == "run"} {
1148 if { [mi_run_cmd] < 0 } {
1152 mi_send_resuming_command "exec-continue" "$test"
1155 mi_expect_stop "breakpoint-hit" $func ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } $test
1158 proc mi_runto {func args} {
1159 return [mi_runto_helper $func "run" {*}$args]
1162 # Just like runto_main but works with the MI interface.
1164 proc mi_runto_main {} {
1165 return [mi_runto_helper "main" "run" -qualified]
1168 # Next to the next statement
1169 # For return values, see mi_execute_to_helper
1171 proc mi_next { test } {
1172 return [mi_next_to {.*} {.*} {.*} {.*} $test]
1176 # Step to the next statement
1177 # For return values, see mi_execute_to_helper
1179 proc mi_step { test } {
1180 return [mi_step_to {.*} {.*} {.*} {.*} $test]
1185 proc mi_detect_async {} {
1187 global mi_gdb_prompt
1189 send_gdb "show mi-async\n"
1192 -re "asynchronous mode is on...*$mi_gdb_prompt$" {
1195 -re ".*$mi_gdb_prompt$" {
1205 # Wait for MI *stopped notification to appear.
1206 # The REASON, FUNC, ARGS, FILE and LINE are regular expressions
1207 # to match against whatever is output in *stopped. FILE may also match
1208 # filename of a file without debug info. ARGS should not include [] the
1209 # list of argument is enclosed in, and other regular expressions should
1210 # not include quotes.
1211 # EXTRA can be a list of one, two or three elements.
1212 # The first element is the regular expression
1213 # for output expected right after *stopped, and before GDB prompt.
1214 # The third element is the regular expression for the locno
1215 # right after bkptno field. The locno regex should not include
1216 # the comma separating it from the following fields.
1218 # When we fail to match output at all, -1 is returned. If FILE does
1219 # match and the target system has no debug info for FILE return 0.
1220 # Otherwise, the line at which we stop is returned. This is useful when
1221 # exact line is not possible to specify for some reason -- one can pass
1222 # the .* or "\[0-9\]*" regexps for line, and then check the line
1225 # Do not pass .* for any argument if you are expecting more than one stop.
1226 proc mi_expect_stop { reason func args file line extra test } {
1228 global mi_gdb_prompt
1231 global fullname_syntax
1233 global thread_selected_re
1234 global breakpoint_re
1238 set after_stopped ""
1241 if { [llength $extra] == 3 } {
1242 set after_stopped [lindex $extra 0]
1243 set after_reason [lindex $extra 1]
1244 set after_reason "${after_reason},"
1245 set locno [lindex $extra 2]
1246 set locno "${locno},"
1247 } elseif { [llength $extra] == 2 } {
1248 set after_stopped [lindex $extra 0]
1249 set after_reason [lindex $extra 1]
1250 set after_reason "${after_reason},"
1251 } elseif { [llength $extra] == 1 } {
1252 set after_stopped [lindex $extra 0]
1258 set prompt_re "$mi_gdb_prompt$"
1261 if { $reason == "really-no-reason" } {
1263 -re "\\*stopped\r\n$prompt_re" {
1267 fail "$test (timeout)"
1273 if { $reason == "exited-normally" } {
1276 -re "\\*stopped,reason=\"exited-normally\"\r\n$prompt_re" {
1279 -re ".*$mi_gdb_prompt$" {fail "continue to end (2)"}
1281 fail "$test (timeout)"
1286 if { $reason == "exited" } {
1288 -re "\\*stopped,reason=\"exited\",exit-code=\"\[0-7\]+\"\r\n$prompt_re" {
1291 -re ".*$mi_gdb_prompt$" {
1292 fail "$test (inferior not stopped)"
1295 fail "$test (timeout)"
1301 if { $reason == "solib-event" } {
1302 set pattern "\\*stopped,reason=\"solib-event\",thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re"
1303 verbose -log "mi_expect_stop: expecting: $pattern"
1309 fail "$test (timeout)"
1315 set args "\\\[$args\\\]"
1319 if { $reason == "breakpoint-hit" } {
1320 set bn {bkptno="[0-9]+",}
1321 set bn "${bn}${locno}"
1322 } elseif { $reason == "solib-event" } {
1324 } elseif { $reason == "exception-caught" } {
1325 set ebn {bkptno="[0-9]+",}
1326 set ebn "${ebn}${locno}"
1328 set reason "breakpoint-hit"
1332 if { $reason != "" } {
1333 set r "reason=\"$reason\","
1339 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"
1342 -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" {
1344 if {[array names expect_out "2,string"] != ""} {
1345 return $expect_out(2,string)
1347 # No debug info available but $file does match.
1350 -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" {
1351 verbose -log "got $expect_out(buffer)"
1352 fail "$test (stopped at wrong place)"
1355 -re ".*\r\n$mi_gdb_prompt$" {
1356 verbose -log "got $expect_out(buffer)"
1357 fail "$test (unknown output after running)"
1361 fail "$test (timeout)"
1367 # Wait for MI *stopped notification related to an interrupt request to
1369 proc mi_expect_interrupt { test } {
1370 global mi_gdb_prompt
1377 set prompt_re "$mi_gdb_prompt"
1380 set r_nonstop "reason=\"signal-received\",signal-name=\"0\",signal-meaning=\"Signal 0\""
1381 set r_allstop "reason=\"signal-received\",signal-name=\"SIGINT\",signal-meaning=\"Interrupt\""
1382 set r "(${r_nonstop}|${r_allstop})"
1385 # A signal can land anywhere, just ignore the location
1386 verbose -log "mi_expect_interrupt: expecting: \\*stopped,${r}$any\r\n$prompt_re"
1388 -re "\\*stopped,${r}$any\r\n$prompt_re" {
1392 -re ".*\r\n$mi_gdb_prompt" {
1393 verbose -log "got $expect_out(buffer)"
1394 fail "$test (unknown output after running)"
1398 fail "$test (timeout)"
1404 # cmd should not include the number or newline (i.e. "exec-step 3", not
1405 # "220-exec-step 3\n"
1407 # Can not match -re ".*\r\n${mi_gdb_prompt}", because of false positives
1408 # after the first prompt is printed.
1410 proc mi_execute_to { cmd reason func args file line extra test } {
1411 mi_send_resuming_command "$cmd" "$test"
1412 set r [mi_expect_stop $reason $func $args $file $line $extra $test]
1416 proc mi_next_to { func args file line test } {
1417 mi_execute_to "exec-next" "end-stepping-range" "$func" "$args" \
1418 "$file" "$line" "" "$test"
1421 proc mi_step_to { func args file line test } {
1422 mi_execute_to "exec-step" "end-stepping-range" "$func" "$args" \
1423 "$file" "$line" "" "$test"
1426 proc mi_finish_to { func args file line result ret test } {
1427 mi_execute_to "exec-finish" "function-finished" "$func" "$args" \
1429 ",gdb-result-var=\"$result\",return-value=\"$ret\"" \
1433 proc mi_continue_to {func} {
1434 mi_runto_helper $func "continue"
1437 proc mi0_execute_to { cmd reason func args file line extra test } {
1438 mi_execute_to_helper "$cmd" "$reason" "$func" "\{$args\}" \
1439 "$file" "$line" "$extra" "$test"
1442 proc mi0_next_to { func args file line test } {
1443 mi0_execute_to "exec-next" "end-stepping-range" "$func" "$args" \
1444 "$file" "$line" "" "$test"
1447 proc mi0_step_to { func args file line test } {
1448 mi0_execute_to "exec-step" "end-stepping-range" "$func" "$args" \
1449 "$file" "$line" "" "$test"
1452 proc mi0_finish_to { func args file line result ret test } {
1453 mi0_execute_to "exec-finish" "function-finished" "$func" "$args" \
1455 ",gdb-result-var=\"$result\",return-value=\"$ret\"" \
1459 proc mi0_continue_to { bkptno func args file line test } {
1460 mi0_execute_to "exec-continue" "breakpoint-hit\",bkptno=\"$bkptno" \
1461 "$func" "$args" "$file" "$line" "" "$test"
1464 # Creates a breakpoint and checks the reported fields are as expected.
1465 # This procedure takes the same options as mi_make_breakpoint and
1466 # returns the breakpoint regexp from that procedure.
1468 proc mi_create_breakpoint {location test args} {
1469 set bp [eval mi_make_breakpoint $args]
1470 mi_gdb_test "222-break-insert $location" "222\\^done,$bp" $test
1474 # Like mi_create_breakpoint, but creates a breakpoint with multiple
1475 # locations using mi_make_breakpoint_multi instead.
1477 proc mi_create_breakpoint_multi {location test args} {
1478 set bp [eval mi_make_breakpoint_multi $args]
1479 mi_gdb_test "222-break-insert $location" "222\\^done,$bp" $test
1483 # Creates varobj named NAME for EXPRESSION.
1484 # Name cannot be "-".
1485 proc mi_create_varobj { name expression testname } {
1486 mi_gdb_test "-var-create $name * $expression" \
1487 "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=.*,has_more=\"0\"" \
1491 proc mi_create_floating_varobj { name expression testname } {
1492 mi_gdb_test "-var-create $name @ $expression" \
1493 "\\^done,name=\"$name\",numchild=\"\(-1\|\[0-9\]+\)\",value=\".*\",type=.*" \
1498 # Same as mi_create_varobj, but also checks the reported type
1500 proc mi_create_varobj_checked { name expression type testname } {
1501 mi_gdb_test "-var-create $name * $expression" \
1502 "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=\"$type\".*" \
1506 # Same as mi_create_floating_varobj, but assumes the test is creating
1507 # a dynamic varobj that has children, so the value must be "{...}".
1508 # The "has_more" attribute is checked.
1509 proc mi_create_dynamic_varobj {name expression has_more testname} {
1510 mi_gdb_test "-var-create $name @ $expression" \
1511 "\\^done,name=\"$name\",numchild=\"0\",value=\"{\\.\\.\\.}\",type=.*,has_more=\"${has_more}\"" \
1515 # Deletes the specified NAME.
1516 proc mi_delete_varobj { name testname } {
1517 mi_gdb_test "-var-delete $name" \
1518 "\\^done,ndeleted=.*" \
1522 # Updates varobj named NAME and checks that all varobjs in EXPECTED
1523 # are reported as updated, and no other varobj is updated.
1524 # Assumes that no varobj is out of scope and that no varobj changes
1526 proc mi_varobj_update { name expected testname } {
1527 set er "\\^done,changelist=\\\["
1529 foreach item $expected {
1530 set v "{name=\"$item\",in_scope=\"true\",type_changed=\"false\",has_more=\".\"}"
1540 verbose -log "Expecting: $er" 2
1541 mi_gdb_test "-var-update $name" $er $testname
1544 proc mi_varobj_update_with_child_type_change { name child_name new_type new_children testname } {
1545 set v "{name=\"$child_name\",in_scope=\"true\",type_changed=\"true\",new_type=\"$new_type\",new_num_children=\"$new_children\",has_more=\".\"}"
1546 set er "\\^done,changelist=\\\[$v\\\]"
1547 verbose -log "Expecting: $er"
1548 mi_gdb_test "-var-update $name" $er $testname
1551 proc mi_varobj_update_with_type_change { name new_type new_children testname } {
1552 mi_varobj_update_with_child_type_change $name $name $new_type $new_children $testname
1555 # A helper that turns a key/value list into a regular expression
1556 # matching some MI output.
1557 proc mi_varobj_update_kv_helper {list} {
1560 foreach {key value} $list {
1565 if {$key == "new_children"} {
1566 append rx "$key=\\\[$value\\\]"
1568 append rx "$key=\"$value\""
1574 # A helper for mi_varobj_update_dynamic that computes a match
1575 # expression given a child list.
1576 proc mi_varobj_update_dynamic_helper {children} {
1580 foreach child $children {
1586 append crx [mi_varobj_update_kv_helper $child]
1593 # Update a dynamic varobj named NAME. CHILDREN is a list of children
1594 # that have been updated; NEW_CHILDREN is a list of children that were
1595 # added to the primary varobj. Each child is a list of key/value
1596 # pairs that are expected. SELF is a key/value list holding
1597 # information about the varobj itself. TESTNAME is the name of the
1599 proc mi_varobj_update_dynamic {name testname self children new_children} {
1600 if {[llength $new_children]} {
1601 set newrx [mi_varobj_update_dynamic_helper $new_children]
1602 lappend self new_children $newrx
1604 set selfrx [mi_varobj_update_kv_helper $self]
1605 set crx [mi_varobj_update_dynamic_helper $children]
1607 set er "\\^done,changelist=\\\[\{name=\"$name\",in_scope=\"true\""
1608 append er ",$selfrx\}"
1614 verbose -log "Expecting: $er"
1615 mi_gdb_test "-var-update $name" $er $testname
1618 proc mi_check_varobj_value { name value testname } {
1620 mi_gdb_test "-var-evaluate-expression $name" \
1621 "\\^done,value=\"$value\"" \
1625 # Helper proc which constructs a child regexp for
1626 # mi_list_varobj_children and mi_varobj_update_dynamic.
1627 proc mi_child_regexp {children add_child} {
1636 foreach item $children {
1638 set name [lindex $item 0]
1639 set exp [lindex $item 1]
1640 set numchild [lindex $item 2]
1641 if {[llength $item] == 5} {
1642 set type [lindex $item 3]
1643 set value [lindex $item 4]
1645 lappend children_exp\
1646 "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",value=\"$value\",type=\"$type\"(,thread-id=\"\[0-9\]+\")?}"
1647 } elseif {[llength $item] == 4} {
1648 set type [lindex $item 3]
1650 lappend children_exp\
1651 "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",type=\"$type\"(,thread-id=\"\[0-9\]+\")?}"
1653 lappend children_exp\
1654 "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\"(,thread-id=\"\[0-9\]+\")?}"
1657 return [join $children_exp ","]
1660 # Check the results of the:
1662 # -var-list-children VARNAME
1664 # command. The CHILDREN parement should be a list of lists.
1665 # Each inner list can have either 3 or 4 elements, describing
1666 # fields that gdb is expected to report for child variable object,
1667 # in the following order
1671 # - Number of children
1674 # If inner list has 3 elements, the gdb is expected to output no
1675 # type for a child and no value.
1677 # If the inner list has 4 elements, gdb output is expected to
1680 proc mi_list_varobj_children { varname children testname } {
1681 mi_list_varobj_children_range $varname "" "" [llength $children] $children \
1685 # Like mi_list_varobj_children, but sets a subrange. NUMCHILDREN is
1686 # the total number of children.
1687 proc mi_list_varobj_children_range {varname from to numchildren children testname} {
1689 if {[llength $varname] == 2} {
1690 set options [lindex $varname 1]
1691 set varname [lindex $varname 0]
1694 set children_exp_j [mi_child_regexp $children 1]
1696 set expected "\\^done,numchild=\".*\",children=\\\[$children_exp_j.*\\\]"
1698 set expected "\\^done,numchild=\"0\""
1702 append expected ",has_more=\"0\""
1703 } elseif {$to >= 0 && $numchildren > $to} {
1704 append expected ",has_more=\"1\""
1706 append expected ",has_more=\"0\""
1709 verbose -log "Expecting: $expected"
1711 mi_gdb_test "-var-list-children $options $varname $from $to" \
1715 # Verifies that variable object VARNAME has NUMBER children,
1716 # where each one is named $VARNAME.<index-of-child> and has type TYPE.
1717 proc mi_list_array_varobj_children { varname number type testname } {
1718 mi_list_array_varobj_children_with_index $varname $number 0 $type $testname
1721 # Same as mi_list_array_varobj_children, but allowing to pass a start index
1723 proc mi_list_array_varobj_children_with_index { varname number start_index \
1726 set index $start_index
1727 for {set i 0} {$i < $number} {incr i} {
1728 lappend t [list $varname.$index $index 0 $type]
1731 mi_list_varobj_children $varname $t $testname
1734 # A list of two-element lists. First element of each list is
1735 # a Tcl statement, and the second element is the line
1736 # number of source C file where the statement originates.
1737 set mi_autotest_data ""
1738 # The name of the source file for autotesting.
1739 set mi_autotest_source ""
1741 # Prepares for running inline tests in FILENAME.
1742 # See comments for mi_run_inline_test for detailed
1743 # explanation of the idea and syntax.
1744 proc mi_prepare_inline_tests { filename } {
1748 global mi_autotest_source
1749 global mi_autotest_data
1751 set mi_autotest_data {}
1753 set mi_autotest_source $filename
1755 if {![regexp "^/" "$filename"]} {
1756 set filename "$srcdir/$subdir/$filename"
1759 set chan [open $filename]
1760 set content [read $chan]
1763 set start [string first "/*:" $content]
1765 set end [string first ":*/" $content]
1767 error "Unterminated special comment in $filename"
1770 set prefix [string range $content 0 $start]
1771 set prefix_newlines [count_newlines $prefix]
1773 set line_number [expr $line_number+$prefix_newlines]
1774 set comment_line $line_number
1776 set comment [string range $content [expr $start+3] [expr $end-1]]
1778 set comment_newlines [count_newlines $comment]
1779 set line_number [expr $line_number+$comment_newlines]
1781 set comment [string trim $comment]
1782 set content [string range $content [expr $end+3] \
1783 [string length $content]]
1784 lappend mi_autotest_data [list $comment $comment_line]
1792 # Helper to mi_run_inline_test below.
1793 # Return the list of all (statement,line_number) lists
1794 # that comprise TESTCASE. The begin and end markers
1796 proc mi_get_inline_test {testcase} {
1798 global mi_gdb_prompt
1799 global mi_autotest_data
1800 global mi_autotest_source
1806 foreach l $mi_autotest_data {
1808 set comment [lindex $l 0]
1810 if {$comment == "BEGIN: $testcase"} {
1812 } elseif {$comment == "END: $testcase"} {
1815 } elseif {$seen_begin==1} {
1820 if {$seen_begin == 0} {
1821 error "Autotest $testcase not found"
1824 if {$seen_begin == 1 && $seen_end == 0} {
1825 error "Missing end marker for test $testcase"
1831 # Sets temporary breakpoint at LOCATION.
1832 proc mi_tbreak {location test} {
1834 global mi_gdb_prompt
1836 mi_gdb_test "-break-insert -t $location" \
1841 # Send COMMAND that must be a command that resumes
1842 # the inferior (run/continue/next/etc) and consumes
1843 # the "^running" output from it.
1844 proc mi_send_resuming_command_raw {command test} {
1846 global mi_gdb_prompt
1847 global thread_selected_re
1848 global library_loaded_re
1850 send_gdb "$command\n"
1852 -re "\\^running\r\n\\*running,thread-id=\"\[^\"\]+\"\r\n($library_loaded_re)*($thread_selected_re)?${mi_gdb_prompt}" {
1853 # Note that lack of 'pass' call here -- this works around limitation
1854 # in DejaGNU xfail mechanism. mi-until.exp has this:
1856 # setup_kfail gdb/2104 "*-*-*"
1859 # and mi_execute_to uses mi_send_resuming_command. If we use 'pass' here,
1860 # it will reset kfail, so when the actual test fails, it will be flagged
1864 -re "\\^error,msg=\"Displaced stepping is only supported in ARM mode\".*" {
1865 unsupported "$test (Thumb mode)"
1868 -re "\\^error,msg=.*" {
1869 fail "$test (MI error)"
1872 -re ".*${mi_gdb_prompt}" {
1873 fail "$test (failed to resume)"
1883 proc mi_send_resuming_command {command test} {
1884 mi_send_resuming_command_raw -$command $test
1887 # Helper to mi_run_inline_test below.
1888 # Sets a temporary breakpoint at LOCATION and runs
1889 # the program using COMMAND. When the program is stopped
1890 # returns the line at which it. Returns -1 if line cannot
1892 # Does not check that the line is the same as requested.
1893 # The caller can check itself if required.
1894 proc_with_prefix mi_continue_to_line {location test} {
1895 with_test_prefix $test {
1896 mi_tbreak $location "set temporary breakpoint"
1897 mi_send_resuming_command "exec-continue" "continue to breakpoint"
1898 return [mi_get_stop_line]
1902 # Wait until gdb prints the current line.
1903 proc mi_get_stop_line {} {
1905 global mi_gdb_prompt
1911 set prompt_re "$mi_gdb_prompt$"
1915 -re ".*line=\"(\[0-9\]*)\".*\r\n$prompt_re" {
1916 return $expect_out(1,string)
1918 -re ".*$mi_gdb_prompt" {
1919 fail "wait for stop (unexpected output)"
1922 fail "wait for stop (timeout)"
1927 # Run a MI test embedded in comments in a C file.
1928 # The C file should contain special comments in the following
1931 # /*: BEGIN: testname :*/
1932 # /*: <Tcl statements> :*/
1933 # /*: END: testname :*/
1935 # This procedure find the begin and end marker for the requested
1936 # test. Then, a temporary breakpoint is set at the begin
1937 # marker and the program is run (from start).
1939 # After that, for each special comment between the begin and end
1940 # marker, the Tcl statements are executed. It is assumed that
1941 # for each comment, the immediately preceding line is executable
1942 # C statement. Then, gdb will be single-stepped until that
1943 # preceding C statement is executed, and after that the
1944 # Tcl statements in the comment will be executed.
1948 # /*: BEGIN: assignment-test :*/
1950 # /*: <Tcl code to check that 'v' is indeed 10 :*/
1951 # /*: END: assignment-test :*/
1953 # The mi_prepare_inline_tests function should be called before
1954 # calling this function. A given C file can contain several
1955 # inline tests. The names of the tests must be unique within one
1958 proc mi_run_inline_test { testcase } {
1960 global mi_gdb_prompt
1963 global fullname_syntax
1964 global mi_autotest_source
1966 set commands [mi_get_inline_test $testcase]
1971 foreach c $commands {
1972 set statements [lindex $c 0]
1973 set line [lindex $c 1]
1974 set line [expr $line-1]
1976 # We want gdb to be stopped at the expression immediately
1977 # before the comment. If this is the first comment, the
1978 # program is either not started yet or is in some random place,
1979 # so we run it. For further comments, we might be already
1980 # standing at the right line. If not continue till the
1984 # Start the program afresh.
1985 mi_tbreak "$mi_autotest_source:$line" "set temporary breakpoint"
1986 if { [mi_run_cmd] < 0 } {
1989 set line_now [mi_get_stop_line]
1991 } elseif {$line_now!=$line} {
1992 set line_now [mi_continue_to_line "$mi_autotest_source:$line" "continue to $line"]
1995 if {$line_now!=$line} {
1996 fail "$testcase: go to line $line"
1999 # We're not at the statement right above the comment.
2000 # Execute that statement so that the comment can test
2001 # the state after the statement is executed.
2003 # Single-step past the line.
2004 if { [mi_send_resuming_command "exec-next" "$testcase: step over $line"] != 0 } {
2007 set line_now [mi_get_stop_line]
2009 # We probably want to use 'uplevel' so that statements
2010 # have direct access to global variables that the
2011 # main 'exp' file has set up. But it's not yet clear,
2012 # will need more experience to be sure.
2019 proc get_mi_thread_list {name} {
2022 # MI will return a list of thread ids:
2025 # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
2027 mi_gdb_test "-thread-list-ids" \
2028 {.*\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \
2029 "-thread_list_ids ($name)"
2032 if {[info exists expect_out(buffer)]} {
2033 set output $expect_out(buffer)
2037 if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} {
2038 fail "finding threads in MI output ($name)"
2040 pass "finding threads in MI output ($name)"
2042 # Make list of console threads
2043 set start [expr {[string first \{ $threads] + 1}]
2044 set end [expr {[string first \} $threads] - 1}]
2045 set threads [string range $threads $start $end]
2046 foreach thread [split $threads ,] {
2047 if {[scan $thread {thread-id="%d"} num]} {
2048 lappend thread_list $num
2056 # Check that MI and the console know of the same threads.
2057 # Appends NAME to all test names.
2058 proc check_mi_and_console_threads {name} {
2061 mi_gdb_test "-thread-list-ids" \
2062 {.*\^done,thread-ids={(thread-id="[0-9]+"(,)*)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \
2063 "-thread-list-ids ($name)"
2065 if {[info exists expect_out(buffer)]} {
2066 set mi_output $expect_out(buffer)
2069 # GDB will return a list of thread ids and some more info:
2072 # -interpreter-exec console "info threads"
2073 # ~" 4 Thread 2051 (LWP 7734) 0x401166b1 in __libc_nanosleep () at __libc_nanosleep:-1"
2074 # ~" 3 Thread 1026 (LWP 7733) () at __libc_nanosleep:-1"
2075 # ~" 2 Thread 2049 (LWP 7732) 0x401411f8 in __poll (fds=0x804bb24, nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63"
2076 # ~"* 1 Thread 1024 (LWP 7731) main (argc=1, argv=0xbfffdd94) at ../../../src/gdb/testsuite/gdb.mi/pthreads.c:160"
2077 # FIXME: kseitz/2002-09-05: Don't use the hack-cli method.
2078 mi_gdb_test "info threads" \
2079 {.*(~".*"[\r\n]*)+.*} \
2080 "info threads ($name)"
2081 set console_output {}
2082 if {[info exists expect_out(buffer)]} {
2083 set console_output $expect_out(buffer)
2086 # Make a list of all known threads to console (gdb's thread IDs)
2087 set console_thread_list {}
2088 foreach line [split $console_output \n] {
2089 if {[string index $line 0] == "~"} {
2090 # This is a line from the console; trim off "~", " ", "*", and "\""
2091 set line [string trim $line ~\ \"\*]
2092 if {[scan $line "%d" id] == 1} {
2093 lappend console_thread_list $id
2098 # Now find the result string from MI
2100 foreach line [split $mi_output \n] {
2101 if {[string range $line 0 4] == "^done"} {
2105 if {$mi_result == ""} {
2106 fail "finding MI result string ($name)"
2108 pass "finding MI result string ($name)"
2111 # Finally, extract the thread ids and compare them to the console
2112 set num_mi_threads_str ""
2113 if {![regexp {number-of-threads="[0-9]+"} $mi_result num_mi_threads_str]} {
2114 fail "finding number of threads in MI output ($name)"
2116 pass "finding number of threads in MI output ($name)"
2118 # Extract the number of threads from the MI result
2119 if {![scan $num_mi_threads_str {number-of-threads="%d"} num_mi_threads]} {
2120 fail "got number of threads from MI ($name)"
2122 pass "got number of threads from MI ($name)"
2124 # Check if MI and console have same number of threads
2125 if {$num_mi_threads != [llength $console_thread_list]} {
2126 fail "console and MI have same number of threads ($name)"
2128 pass "console and MI have same number of threads ($name)"
2130 # Get MI thread list
2131 set mi_thread_list [get_mi_thread_list $name]
2133 # Check if MI and console have the same threads
2135 foreach ct [lsort $console_thread_list] mt [lsort $mi_thread_list] {
2141 fail "MI and console have same threads ($name)"
2143 # Send a list of failures to the log
2144 send_log "Console has thread ids: $console_thread_list\n"
2145 send_log "MI has thread ids: $mi_thread_list\n"
2147 pass "MI and console have same threads ($name)"
2154 # Download shared libraries to the target.
2155 proc mi_load_shlibs { args } {
2156 foreach file $args {
2157 gdb_remote_download target [shlib_target_file $file]
2160 if {[is_remote target]} {
2161 # If the target is remote, we need to tell gdb where to find the
2164 # We could set this even when not testing remotely, but a user
2165 # generally won't set it unless necessary. In order to make the tests
2166 # more like the real-life scenarios, we don't set it for local testing.
2167 mi_gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "\^done" ""
2171 proc mi_check_thread_states { states test } {
2173 set pattern ".*\\^done,threads=\\\["
2175 set pattern "${pattern}(.*)state=\"$s\""
2177 set pattern "${pattern}(,core=\"\[0-9\]*\")?\\\}\\\].*"
2179 verbose -log "expecting: $pattern"
2180 mi_gdb_test "-thread-info" $pattern $test
2183 # Return a list of MI features supported by this gdb.
2184 proc mi_get_features {} {
2185 global expect_out mi_gdb_prompt
2187 send_gdb "-list-features\n"
2190 -re "\\^done,features=\\\[(.*)\\\]\r\n$mi_gdb_prompt$" {
2191 regsub -all -- \" $expect_out(1,string) "" features
2192 return [split $features ,]
2194 -re ".*\r\n$mi_gdb_prompt$" {
2195 verbose -log "got $expect_out(buffer)"
2199 verbose -log "timeout in mi_gdb_prompt"
2205 # Variable Object Trees
2207 # Yet another way to check varobjs. Pass mi_walk_varobj_tree a "list" of
2208 # variables (not unlike the actual source code definition), and it will
2209 # automagically test the children for you (by default).
2231 # foo *f = new foo (); <-- break here
2233 # We want to check all the children of "f".
2235 # Translate the above structures into the following tree:
2241 # anonymous struct {
2252 # {const int *} iPtr {
2253 # {const int} {*iPtr} {}
2263 # mi_walk_varobj_tree c++ $tree
2265 # If you'd prefer to walk the tree using your own callback,
2266 # simply pass the name of the callback to mi_walk_varobj_tree.
2268 # This callback should take one argument, the name of the variable
2269 # to process. This name is the name of a global array holding the
2270 # variable's properties (object name, type, etc).
2272 # An example callback:
2274 # proc my_callback {var} {
2275 # upvar #0 $var varobj
2277 # puts "my_callback: called on varobj $varobj(obj_name)"
2280 # The arrays created for each variable object contain the following
2283 # obj_name - the object name for accessing this variable via MI
2284 # display_name - the display name for this variable (exp="display_name" in
2285 # the output of -var-list-children)
2286 # type - the type of this variable (type="type" in the output
2287 # of -var-list-children, or the special tag "anonymous"
2288 # path_expr - the "-var-info-path-expression" for this variable
2289 # NOTE: This member cannot be used reliably with typedefs.
2291 # See notes inside get_path_expr for more.
2292 # parent - the variable name of the parent varobj
2293 # children - a list of children variable names (which are the
2294 # names Tcl arrays, not object names)
2296 # For each variable object, an array containing the above fields will
2297 # be created under the root node (conveniently called, "root"). For example,
2298 # a variable object with handle "OBJ.public.0_anonymous.a" will have
2299 # a corresponding global Tcl variable named "root.OBJ.public.0_anonymous.a".
2301 # Note that right now, this mechanism cannot be used for recursive data
2302 # structures like linked lists.
2304 namespace eval ::varobj_tree {
2305 # An index which is appended to root varobjs to ensure uniqueness.
2306 variable _root_idx 0
2308 # A procedure to help with debuggging varobj trees.
2309 # VARIABLE_NAME is the name of the variable to dump.
2310 # CMD, if present, is the name of the callback to output the contstructed
2311 # strings. By default, it uses expect's "send_log" command.
2312 # TERM, if present, is a terminating character. By default it is the newline.
2314 # To output to the terminal (not the expect log), use
2315 # mi_varobj_tree_dump_variable my_variable puts ""
2317 proc mi_varobj_tree_dump_variable {variable_name {cmd send_log} {term "\n"}} {
2318 upvar #0 $variable_name varobj
2320 eval "$cmd \"VAR = $variable_name$term\""
2322 # Explicitly encode the array indices, since outputting them
2323 # in some logical order is better than what "array names" might
2325 foreach idx {obj_name parent display_name type path_expr} {
2326 eval "$cmd \"\t$idx = $varobj($idx)$term\""
2330 set num [llength $varobj(children)]
2331 eval "$cmd \"\tnum_children = $num$term\""
2333 eval "$cmd \"\tchildren = $varobj(children)$term\""
2337 # The default callback used by mi_walk_varobj_tree. This callback
2338 # simply checks all of VAR's children. It specifically does not test
2339 # path expressions, since that is very problematic.
2341 # This procedure may be used in custom callbacks.
2342 proc test_children_callback {variable_name} {
2343 upvar #0 $variable_name varobj
2345 if {[llength $varobj(children)] > 0} {
2346 # Construct the list of children the way mi_list_varobj_children
2347 # expects to get it:
2348 # { {obj_name display_name num_children type} ... }
2349 set children_list {}
2350 foreach child $varobj(children) {
2352 set clist [list [string_to_regexp $c(obj_name)] \
2353 [string_to_regexp $c(display_name)] \
2354 [llength $c(children)]]
2355 if {[string length $c(type)] > 0} {
2356 lappend clist [string_to_regexp $c(type)]
2358 lappend children_list $clist
2361 mi_list_varobj_children $varobj(obj_name) $children_list \
2362 "VT: list children of $varobj(obj_name)"
2366 # Set the properties of the varobj represented by
2367 # PARENT_VARIABLE - the name of the parent's variable
2368 # OBJNAME - the MI object name of this variable
2369 # DISP_NAME - the display name of this variable
2370 # TYPE - the type of this variable
2371 # PATH - the path expression for this variable
2372 # CHILDREN - a list of the variable's children
2373 proc create_varobj {parent_variable objname disp_name \
2374 type path children} {
2375 upvar #0 $parent_variable parent
2377 set var_name "root.$objname"
2379 array set $var_name [list obj_name $objname]
2380 array set $var_name [list display_name $disp_name]
2381 array set $var_name [list type $type]
2382 array set $var_name [list path_expr $path]
2383 array set $var_name [list parent "$parent_variable"]
2384 array set $var_name [list children \
2385 [get_tree_children $var_name $children]]
2389 # Should VARIABLE be used in path expressions? The CPLUS_FAKE_CHILD
2390 # varobjs and anonymous structs/unions are not used for path expressions.
2391 proc is_path_expr_parent {variable} {
2392 upvar #0 $variable varobj
2394 # If the varobj's type is "", it is a CPLUS_FAKE_CHILD.
2395 # If the tail of the varobj's object name is "%d_anonymous",
2396 # then it represents an anonymous struct or union.
2397 if {[string length $varobj(type)] == 0 \
2398 || [regexp {[0-9]+_anonymous$} $varobj(obj_name)]} {
2405 # Return the path expression for the variable named NAME in
2406 # parent varobj whose variable name is given by PARENT_VARIABLE.
2407 proc get_path_expr {parent_variable name type} {
2408 upvar #0 $parent_variable parent
2409 upvar #0 $parent_variable path_parent
2411 # If TYPE is "", this is one of the CPLUS_FAKE_CHILD varobjs,
2412 # which has no path expression. Likewsise for anonymous structs
2414 if {[string length $type] == 0 \
2415 || [string compare $type "anonymous"] == 0} {
2419 # Find the path parent variable.
2420 while {![is_path_expr_parent $parent_variable]} {
2421 set parent_variable $path_parent(parent)
2422 upvar #0 $parent_variable path_parent
2425 # This is where things get difficult. We do not actually know
2426 # the real type for variables defined via typedefs, so we don't actually
2427 # know whether the parent is a structure/union or not.
2429 # So we assume everything that isn't a simple type is a compound type.
2431 regexp {\*+} $parent(type) stars
2433 if {[string index $name 0] == "*"} {
2437 if {[string index $parent(type) end] == "\]"} {
2438 # Parent is an array.
2439 return "($path_parent(path_expr))\[$name\]"
2440 } elseif {$is_compound} {
2441 # Parent is a structure or union or a pointer to one.
2442 if {[string length $stars]} {
2450 # To make matters even more hideous, varobj.c has slightly different
2451 # path expressions for C and C++.
2452 set path_expr "($path_parent(path_expr))$join$name"
2453 if {[string compare -nocase $root(language) "c"] == 0} {
2456 return "($path_expr)"
2459 # Parent is a pointer.
2460 return "*($path_parent(path_expr))"
2464 # Process the CHILDREN (a list of varobj_tree elements) of the variable
2465 # given by PARENT_VARIABLE. Returns a list of children variables.
2466 proc get_tree_children {parent_variable children} {
2467 upvar #0 $parent_variable parent
2470 set children_list {}
2471 foreach {type name children} $children {
2472 if {[string compare $parent_variable "root"] == 0} {
2476 set objname "$name$_root_idx"
2477 set disp_name "$name"
2478 set path_expr "$name"
2479 } elseif {[string compare $type "anonymous"] == 0} {
2480 # Special case: anonymous types. In this case, NAME will either be
2481 # "struct" or "union".
2482 set objname "$parent(obj_name).${field_idx}_anonymous"
2483 set disp_name "<anonymous $name>"
2485 set type "$name {...}"
2487 set objname "$parent(obj_name).$name"
2489 set path_expr [get_path_expr $parent_variable $name $type]
2492 lappend children_list [create_varobj $parent_variable $objname \
2493 $disp_name $type $path_expr $children]
2497 return $children_list
2500 # The main procedure to call the given CALLBACK on the elements of the
2501 # given varobj TREE. See detailed explanation above.
2502 proc walk_tree {language tree callback} {
2506 if {[llength $tree] < 3} {
2507 error "tree does not contain enough elements"
2512 # Create root node and process the tree.
2513 array set root [list language $language]
2514 array set root [list obj_name "root"]
2515 array set root [list display_name "root"]
2516 array set root [list type "root"]
2517 array set root [list path_expr "root"]
2518 array set root [list parent "root"]
2519 array set root [list children [get_tree_children root $tree]]
2522 set all_nodes $root(children); # a stack of nodes
2523 while {[llength $all_nodes] > 0} {
2524 # "Pop" the name of the global variable containing this varobj's
2525 # information from the stack of nodes.
2526 set var_name [lindex $all_nodes 0]
2527 set all_nodes [lreplace $all_nodes 0 0]
2529 # Bring the global named in VAR_NAME into scope as the local variable
2531 upvar #0 $var_name varobj
2533 # Append any children of VAROBJ to the list of nodes to walk.
2534 if {[llength $varobj(children)] > 0} {
2535 set all_nodes [concat $all_nodes $varobj(children)]
2538 # If this is a root variable, create the variable object for it.
2539 if {[string compare $varobj(parent) "root"] == 0} {
2540 mi_create_varobj $varobj(obj_name) $varobj(display_name) \
2541 "VT: create root varobj for $varobj(display_name)"
2544 # Now call the callback for VAROBJ.
2545 uplevel #0 $callback $var_name
2550 # The default varobj tree callback, which simply tests -var-list-children.
2551 proc mi_varobj_tree_test_children_callback {variable} {
2552 ::varobj_tree::test_children_callback $variable
2555 # Walk the variable object tree given by TREE, calling the specified
2556 # CALLBACK. By default this uses mi_varobj_tree_test_children_callback.
2557 proc mi_walk_varobj_tree {language tree \
2559 mi_varobj_tree_test_children_callback}} {
2560 ::varobj_tree::walk_tree $language $tree $callback
2563 # Build a list of key-value pairs given by the list ATTR_LIST. Flatten
2564 # this list using the optional JOINER, a comma by default.
2566 # The list must contain an even number of elements, which are the key-value
2567 # pairs. Each value will be surrounded by quotes, according to the grammar,
2568 # except if the value starts with \[ or \{, when the quotes will be omitted.
2570 # Example: mi_build_kv_pairs {a b c d e f g \[.*\]}
2571 # returns a=\"b\",c=\"d\",e=\"f\",g=\[.*\]
2572 proc mi_build_kv_pairs {attr_list {joiner ,}} {
2574 foreach {var value} $attr_list {
2575 if {[string range $value 0 1] == "\\\["
2576 || [string range $value 0 1] == "\\\{"} {
2577 lappend l "$var=$value"
2579 lappend l "$var=\"$value\""
2582 return "[join $l $joiner]"
2585 # Construct a breakpoint location regexp. This may be used along with
2586 # mi_make_breakpoint_multi to test the output of -break-insert,
2587 # -dprintf-insert, or -break-info with breapoints with multiple
2590 # All arguments for the breakpoint location may be specified using the
2591 # options number, enabled, addr, func, file, fullname, line and
2594 # Example: mi_make_breakpoint_loc -number 2.1 -file ".*/myfile.c" -line 3
2595 # will return the breakpoint location:
2596 # {number="2.1",enabled=".*",addr=".*",func=".*",
2597 # file=".*/myfile.c",fullname=".*",line="3",thread-groups=\[.*\]}
2599 proc mi_make_breakpoint_loc {args} {
2600 parse_args {{number .*} {enabled .*} {addr .*}
2601 {func .*} {file .*} {fullname .*} {line .*}
2602 {thread-groups \\\[.*\\\]}}
2605 foreach attr [list number enabled addr func file \
2606 fullname line thread-groups] {
2607 lappend attr_list $attr [set $attr]
2610 return "{[mi_build_kv_pairs $attr_list]}"
2613 # Bits shared between mi_make_breakpoint and mi_make_breakpoint_multi.
2615 proc mi_make_breakpoint_1 {attr_list cond evaluated-by times \
2616 ignore script original-location} {
2617 set result "bkpt=\\\{[mi_build_kv_pairs $attr_list]"
2619 # There are always exceptions.
2621 # If COND is not preset, do not output it.
2622 if {[string length $cond] > 0} {
2624 append result [mi_build_kv_pairs [list "cond" $cond]]
2626 # When running on a remote, GDB may output who is evaluating
2627 # breakpoint conditions.
2628 if {[string length ${evaluated-by}] > 0} {
2629 append result [mi_build_kv_pairs \
2630 [list "evaluated-by" ${evaluated-by}]]
2632 append result {(,evaluated-by=".*")?}
2637 append result [mi_build_kv_pairs [list "times" $times]]
2639 # If SCRIPT and IGNORE are not present, do not output them.
2642 append result [mi_build_kv_pairs [list "ignore" $ignore]]
2645 if {[string length $script] > 0} {
2647 append result [mi_build_kv_pairs [list "script" $script]]
2650 # Allow anything up until the next "official"/required attribute.
2651 # This pattern skips over script/ignore if matches on those
2652 # were not specifically required by the caller.
2655 append result [mi_build_kv_pairs \
2656 [list "original-location" ${original-location}]]
2662 # Construct a breakpoint regexp, for a breakpoint with multiple
2663 # locations. This may be used to test the output of -break-insert,
2664 # -dprintf-insert, or -break-info with breakpoints with multiple
2667 # All arguments for the breakpoint may be specified using the options
2668 # number, type, disp, enabled, func, cond, evaluated-by, times,
2669 # ignore, script and locations.
2671 # Only if -script and -ignore are given will they appear in the output.
2672 # Otherwise, this procedure will skip them using ".*".
2674 # Example: mi_make_breakpoint_multi -number 2 -locations "$loc"
2675 # will return the breakpoint:
2676 # bkpt={number="2",type=".*",disp=".*",enabled=".*",addr="<MULTIPLE>",
2677 # times="0".*original-location=".*",locations=$loc}
2679 # You can construct the list of locations with mi_make_breakpoint_loc.
2681 proc mi_make_breakpoint_multi {args} {
2682 parse_args {{number .*} {type .*} {disp .*} {enabled .*}
2683 {times .*} {ignore 0}
2684 {script ""} {original-location .*} {cond ""} {evaluated-by ""}
2688 foreach attr [list number type disp enabled] {
2689 lappend attr_list $attr [set $attr]
2692 lappend attr_list "addr" "<MULTIPLE>"
2694 set result [mi_make_breakpoint_1 \
2695 $attr_list $cond ${evaluated-by} $times \
2696 $ignore $script ${original-location}]
2699 append result [mi_build_kv_pairs [list "locations" $locations]]
2701 append result "\\\}"
2705 # Construct a breakpoint regexp, for a pending breakpoint. This may
2706 # be used to test the output of -break-insert, -dprintf-insert, or
2707 # -break-info for pending breakpoints.
2709 # Arguments for the breakpoint may be specified using the options
2710 # number, type, disp, enabled, pending.
2712 # Example: mi_make_breakpoint_pending -number 2 -pending func
2713 # will return the breakpoint:
2714 # bkpt={number="2",type=".*",disp=".*",enabled=".*",addr="<PENDING>",
2715 # pending="func", times="0".*original-location=".*"}
2717 proc mi_make_breakpoint_pending {args} {
2718 parse_args {{number .*} {type .*} {disp .*} {enabled .*}
2719 {pending .*} {original-location .*}}
2722 foreach attr [list number type disp enabled] {
2723 lappend attr_list $attr [set $attr]
2726 lappend attr_list "addr" "<PENDING>"
2728 foreach attr [list pending] {
2729 lappend attr_list $attr [set $attr]
2738 set result [mi_make_breakpoint_1 \
2739 $attr_list $cond ${evaluated-by} $times \
2740 $ignore $script ${original-location}]
2742 append result "\\\}"
2746 # Construct a breakpoint regexp. This may be used to test the output of
2747 # -break-insert, -dprintf-insert, or -break-info.
2749 # All arguments for the breakpoint may be specified using the options
2750 # number, type, disp, enabled, addr, func, file, fullanme, line,
2751 # thread-groups, cond, evaluated-by, times, ignore, script,
2752 # and original-location.
2754 # Only if -script and -ignore are given will they appear in the output.
2755 # Otherwise, this procedure will skip them using ".*".
2757 # Example: mi_make_breakpoint -number 2 -file ".*/myfile.c" -line 3
2758 # will return the breakpoint:
2759 # bkpt={number="2",type=".*",disp=".*",enabled=".*",addr=".*",func=".*",
2760 # file=".*/myfile.c",fullname=".*",line="3",thread-groups=\[.*\],
2761 # times="0".*original-location=".*"}
2763 proc mi_make_breakpoint {args} {
2764 parse_args {{number .*} {type .*} {disp .*} {enabled .*} {addr .*}
2765 {func .*} {file .*} {fullname .*} {line .*}
2766 {thread-groups \\\[.*\\\]} {times .*} {ignore 0}
2767 {script ""} {original-location .*} {cond ""} {evaluated-by ""}}
2770 foreach attr [list number type disp enabled addr func file \
2771 fullname line thread-groups] {
2772 lappend attr_list $attr [set $attr]
2775 set result [mi_make_breakpoint_1 \
2776 $attr_list $cond ${evaluated-by} $times \
2777 $ignore $script ${original-location}]
2779 append result "\\\}"
2783 # Build a breakpoint table regexp given the list of breakpoints in `bp_list',
2784 # constructed by mi_make_breakpoint.
2786 # Example: Construct a breakpoint table where the only attributes we
2787 # test for are the existence of three breakpoints numbered 1, 2, and 3.
2790 # lappend bps [mi_make_breakpoint -number 1]
2791 # lappend bps [mi_make_breakpoint -number 2]
2792 # lappned bps [mi_make_breakpoint -number 3]
2793 # mi_make_breakpoint_table $bps
2794 # will return (abbreviated for clarity):
2795 # BreakpointTable={nr_rows="3",nr_cols="6",hdr=[{width=".*",...} ...],
2796 # body=[bkpt={number="1",...},bkpt={number="2",...},bkpt={number="3",...}]}
2798 proc mi_make_breakpoint_table {bp_list} {
2799 # Build header -- assume a standard header for all breakpoint tables.
2801 foreach {nm hdr} [list number Num type Type disp Disp enabled Enb \
2802 addr Address what What] {
2803 # The elements here are the MI table headers, which have the
2805 # {width="7",alignment="-1",col_name="number",colhdr="Num"}
2806 lappend hl "{[mi_build_kv_pairs [list width .* alignment .* \
2807 col_name $nm colhdr $hdr]]}"
2809 set header "hdr=\\\[[join $hl ,]\\\]"
2811 # The caller has implicitly supplied the number of columns and rows.
2812 set nc [llength $hl]
2813 set nr [llength $bp_list]
2815 # Build body -- mi_make_breakpoint has done most of the work.
2816 set body "body=\\\[[join $bp_list ,]\\\]"
2818 # Assemble the final regexp.
2819 return "BreakpointTable={nr_rows=\"$nr\",nr_cols=\"$nc\",$header,$body}"
2822 # Return a 1 for configurations that do not support Python scripting.
2823 # Note: This also sets various globals that specify which version of Python
2824 # is in use. See skip_python_tests_prompt.
2826 proc mi_skip_python_tests {} {
2827 global mi_gdb_prompt
2828 return [skip_python_tests_prompt "$mi_gdb_prompt$"]
2831 # As skip_libstdcxx_probe_tests_prompt, with mi_gdb_prompt.
2833 proc mi_skip_libstdcxx_probe_tests {} {
2834 global mi_gdb_prompt
2835 return [skip_libstdcxx_probe_tests_prompt "$mi_gdb_prompt$"]
2838 # Check whether we're testing with the remote or extended-remote
2841 proc mi_is_target_remote {} {
2842 global mi_gdb_prompt
2844 return [gdb_is_target_remote_prompt "$mi_gdb_prompt"]
2847 # Retrieve the value of EXP in the inferior, represented in format
2848 # specified in FMT (using "printFMT"). DEFAULT is used as fallback if
2849 # print fails. TEST is the test message to use. It can be omitted,
2850 # in which case a test message is built from EXP.
2852 # This is an MI version of gdb_valueof.
2854 proc mi_get_valueof { fmt exp default {test ""} } {
2855 global mi_gdb_prompt
2858 set test "get valueof \"${exp}\""
2862 gdb_test_multiple "print${fmt} ${exp}" "$test" -prompt "$::mi_gdb_prompt$" {
2863 -re "~\"\\$\[0-9\]* = (\[^\r\n\]*)\\\\n\"\r\n\\^done\r\n$mi_gdb_prompt$" {
2864 set val $expect_out(1,string)
2868 fail "$test (timeout)"