Fix and improve comment in gdb_remote_download
[deliverable/binutils-gdb.git] / gdb / testsuite / lib / mi-support.exp
CommitLineData
618f726f 1# Copyright 1999-2016 Free Software Foundation, Inc.
fb40c209
AC
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
fb40c209 6# (at your option) any later version.
e22f8b7c 7#
fb40c209
AC
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.
e22f8b7c 12#
fb40c209 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
fb40c209 15
fb40c209
AC
16# This file was based on a file written by Fred Fish. (fnf@cygnus.com)
17
18# Test setup routines that work with the MI interpreter.
19
a25eb028
MR
20load_lib gdb-utils.exp
21
fb40c209
AC
22# The variable mi_gdb_prompt is a regexp which matches the gdb mi prompt.
23# Set it if it is not already set.
24global mi_gdb_prompt
25if ![info exists mi_gdb_prompt] then {
26 set mi_gdb_prompt "\[(\]gdb\[)\] \r\n"
27}
28
ecd3fd0f
BR
29global mi_inferior_tty_name
30
fb40c209
AC
31set MIFLAGS "-i=mi"
32
84a02e58 33set thread_selected_re "=thread-selected,id=\"\[0-9\]+\"\r\n"
bbec57e4 34set gdbindex_warning_re "&\"warning: Skipping \[^\r\n\]+ \.gdb_index section in \[^\r\n\]+\"\r\n(?:&\"\\\\n\"\r\n)?"
481860b3 35set library_loaded_re "=library-loaded\[^\n\]+\"\r\n(?:$gdbindex_warning_re)?"
ca539be8 36set breakpoint_re "=(?:breakpoint-created|breakpoint-deleted)\[^\n\]+\"\r\n"
66bb093b 37
fb40c209
AC
38#
39# mi_gdb_exit -- exit the GDB, killing the target program if necessary
40#
41proc mi_gdb_exit {} {
42 catch mi_uncatched_gdb_exit
43}
44
45proc mi_uncatched_gdb_exit {} {
46 global GDB
6b8ce727 47 global INTERNAL_GDBFLAGS GDBFLAGS
fb40c209 48 global verbose
4ec70201 49 global gdb_spawn_id
fb40c209
AC
50 global gdb_prompt
51 global mi_gdb_prompt
52 global MIFLAGS
53
4ec70201 54 gdb_stop_suppressing_tests
fb40c209
AC
55
56 if { [info procs sid_exit] != "" } {
57 sid_exit
58 }
59
60 if ![info exists gdb_spawn_id] {
4ec70201 61 return
fb40c209
AC
62 }
63
6b8ce727 64 verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $MIFLAGS"
fb40c209
AC
65
66 if { [is_remote host] && [board_info host exists fileid] } {
4ec70201 67 send_gdb "999-gdb-exit\n"
fb40c209
AC
68 gdb_expect 10 {
69 -re "y or n" {
4ec70201
PA
70 send_gdb "y\n"
71 exp_continue
fb40c209 72 }
4392c534
YQ
73 -re "Undefined command.*$gdb_prompt $" {
74 send_gdb "quit\n"
4ec70201 75 exp_continue
4392c534 76 }
fb40c209
AC
77 -re "DOSEXIT code" { }
78 default { }
79 }
80 }
81
82 if ![is_remote host] {
4ec70201 83 remote_close host
fb40c209
AC
84 }
85 unset gdb_spawn_id
86}
87
88#
79732189 89# default_mi_gdb_start [INFERIOR_PTY] -- start gdb running, default procedure
ecd3fd0f
BR
90#
91# INFERIOR_PTY should be set to separate-inferior-tty to have the inferior work
92# with it's own PTY. If set to same-inferior-tty, the inferior shares GDB's PTY.
93# The default value is same-inferior-tty.
fb40c209
AC
94#
95# When running over NFS, particularly if running many simultaneous
96# tests on different hosts all using the same server, things can
97# get really slow. Give gdb at least 3 minutes to start up.
98#
79732189 99proc default_mi_gdb_start { args } {
e11ac3a3 100 global verbose use_gdb_stub
fb40c209 101 global GDB
6b8ce727 102 global INTERNAL_GDBFLAGS GDBFLAGS
fb40c209
AC
103 global gdb_prompt
104 global mi_gdb_prompt
105 global timeout
e8376742 106 global gdb_spawn_id inferior_spawn_id
fb40c209
AC
107 global MIFLAGS
108
4ec70201 109 gdb_stop_suppressing_tests
ecd3fd0f
BR
110 set inferior_pty no-tty
111
e11ac3a3
JK
112 # Set the default value, it may be overriden later by specific testfile.
113 set use_gdb_stub [target_info exists use_gdb_stub]
114
ecd3fd0f
BR
115 if { [llength $args] == 1} {
116 set inferior_pty [lindex $args 0]
117 }
118
119 set separate_inferior_pty [string match $inferior_pty separate-inferior-tty]
fb40c209 120
1759b3c3
AC
121 # Start SID.
122 if { [info procs sid_start] != "" } {
123 verbose "Spawning SID"
124 sid_start
125 }
126
6b8ce727 127 verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $MIFLAGS"
fb40c209
AC
128
129 if [info exists gdb_spawn_id] {
ae59b1da 130 return 0
fb40c209
AC
131 }
132
133 if ![is_remote host] {
134 if { [which $GDB] == 0 } then {
135 perror "$GDB does not exist."
136 exit 1
137 }
138 }
ecd3fd0f 139
4ec70201 140 set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS $MIFLAGS [host_info gdb_opts]"]
fb40c209
AC
141 if { $res < 0 || $res == "" } {
142 perror "Spawning $GDB failed."
ae59b1da 143 return 1
fb40c209
AC
144 }
145 gdb_expect {
1f312e79
JJ
146 -re "~\"GNU.*\r\n~\".*$mi_gdb_prompt$" {
147 # We have a new format mi startup prompt. If we are
148 # running mi1, then this is an error as we should be
149 # using the old-style prompt.
150 if { $MIFLAGS == "-i=mi1" } {
4392c534
YQ
151 perror "(mi startup) Got unexpected new mi prompt."
152 remote_close host
153 return -1
1f312e79
JJ
154 }
155 verbose "GDB initialized."
156 }
157 -re "\[^~\].*$mi_gdb_prompt$" {
158 # We have an old format mi startup prompt. If we are
159 # not running mi1, then this is an error as we should be
160 # using the new-style prompt.
161 if { $MIFLAGS != "-i=mi1" } {
4392c534
YQ
162 perror "(mi startup) Got unexpected old mi prompt."
163 remote_close host
164 return -1
1f312e79 165 }
d20bf2e8 166 verbose "GDB initialized."
fb40c209 167 }
76c520e0
AC
168 -re ".*unrecognized option.*for a complete list of options." {
169 untested "Skip mi tests (not compiled with mi support)."
4ec70201 170 remote_close host
ae59b1da 171 return -1
76c520e0 172 }
7d76bd60
MK
173 -re ".*Interpreter `mi' unrecognized." {
174 untested "Skip mi tests (not compiled with mi support)."
4ec70201 175 remote_close host
ae59b1da 176 return -1
7d76bd60 177 }
fb40c209
AC
178 timeout {
179 perror "(timeout) GDB never initialized after 10 seconds."
4ec70201 180 remote_close host
fb40c209
AC
181 return -1
182 }
183 }
717cf30c 184 set gdb_spawn_id $res
fb40c209
AC
185
186 # FIXME: mi output does not go through pagers, so these can be removed.
187 # force the height to "unlimited", so no pagers get used
188 send_gdb "100-gdb-set height 0\n"
189 gdb_expect 10 {
4392c534 190 -re ".*100-gdb-set height 0\r\n100\\\^done\r\n$mi_gdb_prompt$" {
fb40c209
AC
191 verbose "Setting height to 0." 2
192 }
193 timeout {
194 warning "Couldn't set the height to 0"
195 }
196 }
197 # force the width to "unlimited", so no wraparound occurs
198 send_gdb "101-gdb-set width 0\n"
199 gdb_expect 10 {
200 -re ".*101-gdb-set width 0\r\n101\\\^done\r\n$mi_gdb_prompt$" {
201 verbose "Setting width to 0." 2
202 }
203 timeout {
204 warning "Couldn't set the width to 0."
205 }
206 }
e8376742
PA
207
208 # Create the new PTY for the inferior process.
ecd3fd0f 209 if { $separate_inferior_pty } {
e8376742
PA
210 spawn -pty
211 global mi_inferior_tty_name
212 set inferior_spawn_id $spawn_id
213 set mi_inferior_tty_name $spawn_out(slave,name)
214
ecd3fd0f
BR
215 send_gdb "102-inferior-tty-set $mi_inferior_tty_name\n"
216 gdb_expect 10 {
217 -re ".*102\\\^done\r\n$mi_gdb_prompt$" {
218 verbose "redirect inferior output to new terminal device."
219 }
220 timeout {
4392c534 221 warning "Couldn't redirect inferior output." 2
ecd3fd0f 222 }
4392c534 223 }
ecd3fd0f 224 }
fb40c209 225
e8376742
PA
226 if {![info exists inferior_spawn_id]} {
227 set inferior_spawn_id $gdb_spawn_id
228 }
229
fcdfa280 230 mi_detect_async
f7f9a841 231
ae59b1da 232 return 0
fb40c209
AC
233}
234
79732189
AR
235#
236# Overridable function. You can override this function in your
237# baseboard file.
4392c534 238#
79732189
AR
239proc mi_gdb_start { args } {
240 return [default_mi_gdb_start $args]
241}
242
fb40c209
AC
243# Many of the tests depend on setting breakpoints at various places and
244# running until that breakpoint is reached. At times, we want to start
245# with a clean-slate with respect to breakpoints, so this utility proc
246# lets us do this without duplicating this code everywhere.
247#
248
249proc mi_delete_breakpoints {} {
250 global mi_gdb_prompt
251
252# FIXME: The mi operation won't accept a prompt back and will use the 'all' arg
253 send_gdb "102-break-delete\n"
254 gdb_expect 30 {
255 -re "Delete all breakpoints.*y or n.*$" {
4ec70201 256 send_gdb "y\n"
fb40c209 257 exp_continue
4392c534 258 }
39fb8e9e 259 -re "102-break-delete\r\n102\\\^done\r\n$mi_gdb_prompt$" {
4392c534 260 # This happens if there were no breakpoints
fb40c209 261 }
f1c8a949 262 timeout { perror "Delete all breakpoints in mi_delete_breakpoints (timeout)" ; return }
fb40c209
AC
263 }
264
265# The correct output is not "No breakpoints or watchpoints." but an
266# empty BreakpointTable. Also, a query is not acceptable with mi.
267 send_gdb "103-break-list\n"
268 gdb_expect 30 {
269 -re "103-break-list\r\n103\\\^done,BreakpointTable=\{\}\r\n$mi_gdb_prompt$" {}
6f3f3097 270 -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$" {}
fb40c209
AC
271 -re "103-break-list\r\n103\\\^doneNo breakpoints or watchpoints.\r\n\r\n$mi_gdb_prompt$" {warning "Unexpected console text received"}
272 -re "$mi_gdb_prompt$" { perror "Breakpoints not deleted" ; return }
273 -re "Delete all breakpoints.*or n.*$" {
4ec70201
PA
274 warning "Unexpected prompt for breakpoints deletion"
275 send_gdb "y\n"
fb40c209
AC
276 exp_continue
277 }
278 timeout { perror "-break-list (timeout)" ; return }
279 }
280}
281
282proc mi_gdb_reinitialize_dir { subdir } {
283 global mi_gdb_prompt
da81390b 284 global MIFLAGS
fb40c209
AC
285
286 global suppress_flag
287 if { $suppress_flag } {
288 return
289 }
290
291 if [is_remote host] {
ae59b1da 292 return ""
fb40c209
AC
293 }
294
da81390b
JJ
295 if { $MIFLAGS == "-i=mi1" } {
296 send_gdb "104-environment-directory\n"
297 gdb_expect 60 {
fb40c209 298 -re ".*Reinitialize source path to empty.*y or n. " {
4392c534 299 warning "Got confirmation prompt for dir reinitialization."
fb40c209
AC
300 send_gdb "y\n"
301 gdb_expect 60 {
302 -re "$mi_gdb_prompt$" {}
4392c534 303 timeout {error "Dir reinitialization failed (timeout)"}
fb40c209
AC
304 }
305 }
306 -re "$mi_gdb_prompt$" {}
4392c534 307 timeout {error "Dir reinitialization failed (timeout)"}
da81390b
JJ
308 }
309 } else {
4392c534
YQ
310 send_gdb "104-environment-directory -r\n"
311 gdb_expect 60 {
312 -re "104\\\^done,source-path=.*\r\n$mi_gdb_prompt$" {}
313 -re "$mi_gdb_prompt$" {}
314 timeout {error "Dir reinitialization failed (timeout)"}
da81390b 315 }
fb40c209
AC
316 }
317
318 send_gdb "105-environment-directory $subdir\n"
319 gdb_expect 60 {
320 -re "Source directories searched.*$mi_gdb_prompt$" {
321 verbose "Dir set to $subdir"
322 }
da81390b 323 -re "105\\\^done.*\r\n$mi_gdb_prompt$" {
4392c534 324 # FIXME: We return just the prompt for now.
fb40c209
AC
325 verbose "Dir set to $subdir"
326 # perror "Dir \"$subdir\" failed."
327 }
328 }
329}
330
da6012e5
DJ
331# Send GDB the "target" command.
332# FIXME: Some of these patterns are not appropriate for MI. Based on
333# config/monitor.exp:gdb_target_command.
334proc mi_gdb_target_cmd { targetname serialport } {
335 global mi_gdb_prompt
336
ef783a7d 337 set serialport_re [string_to_regexp $serialport]
da6012e5
DJ
338 for {set i 1} {$i <= 3} {incr i} {
339 send_gdb "47-target-select $targetname $serialport\n"
340 gdb_expect 60 {
56a8e183 341 -re "47\\^connected.*$mi_gdb_prompt" {
4ec70201 342 verbose "Set target to $targetname"
ae59b1da 343 return 0
da6012e5 344 }
401ea829 345 -re "unknown host.*$mi_gdb_prompt" {
4392c534 346 verbose "Couldn't look up $serialport"
401ea829 347 }
da6012e5 348 -re "Couldn't establish connection to remote.*$mi_gdb_prompt$" {
4ec70201 349 verbose "Connection failed"
da6012e5
DJ
350 }
351 -re "Remote MIPS debugging.*$mi_gdb_prompt$" {
4ec70201 352 verbose "Set target to $targetname"
ae59b1da 353 return 0
da6012e5 354 }
ef783a7d 355 -re "Remote debugging using .*$serialport_re.*$mi_gdb_prompt$" {
4ec70201 356 verbose "Set target to $targetname"
ae59b1da 357 return 0
da6012e5
DJ
358 }
359 -re "Remote target $targetname connected to.*$mi_gdb_prompt$" {
4ec70201 360 verbose "Set target to $targetname"
ae59b1da 361 return 0
da6012e5 362 }
4392c534 363 -re "Connected to.*$mi_gdb_prompt$" {
4ec70201 364 verbose "Set target to $targetname"
ae59b1da 365 return 0
da6012e5
DJ
366 }
367 -re "Ending remote.*$mi_gdb_prompt$" { }
368 -re "Connection refused.*$mi_gdb_prompt$" {
369 verbose "Connection refused by remote target. Pausing, and trying again."
370 sleep 5
371 continue
372 }
56a8e183
PA
373 -re "Non-stop mode requested, but remote does not support non-stop.*$mi_gdb_prompt" {
374 unsupported "Non-stop mode not supported"
375 return 1
376 }
da6012e5 377 -re "Timeout reading from remote system.*$mi_gdb_prompt$" {
4ec70201 378 verbose "Got timeout error from gdb."
da6012e5
DJ
379 }
380 timeout {
4ec70201 381 send_gdb "\ 3"
da6012e5
DJ
382 break
383 }
384 }
385 }
386 return 1
387}
388
fb40c209 389#
da6012e5 390# load a file into the debugger (file command only).
fb40c209
AC
391# return a -1 if anything goes wrong.
392#
da6012e5 393proc mi_gdb_file_cmd { arg } {
fb40c209
AC
394 global verbose
395 global loadpath
396 global loadfile
397 global GDB
398 global mi_gdb_prompt
b741e217 399 global last_loaded_file
fb40c209
AC
400 upvar timeout timeout
401
b741e217 402 set last_loaded_file $arg
b53f9b27 403
da6012e5 404 if [is_remote host] {
4ec70201 405 set arg [remote_download host $arg]
da6012e5
DJ
406 if { $arg == "" } {
407 error "download failed"
ae59b1da 408 return -1
da6012e5
DJ
409 }
410 }
fb40c209 411
fb40c209
AC
412# FIXME: Several of these patterns are only acceptable for console
413# output. Queries are an error for mi.
414 send_gdb "105-file-exec-and-symbols $arg\n"
415 gdb_expect 120 {
4392c534
YQ
416 -re "Reading symbols from.*done.*$mi_gdb_prompt$" {
417 verbose "\t\tLoaded $arg into the $GDB"
418 return 0
419 }
420 -re "has no symbol-table.*$mi_gdb_prompt$" {
421 perror "$arg wasn't compiled with \"-g\""
422 return -1
423 }
424 -re "Load new symbol table from \".*\".*y or n. $" {
425 send_gdb "y\n"
426 gdb_expect 120 {
427 -re "Reading symbols from.*done.*$mi_gdb_prompt$" {
428 verbose "\t\tLoaded $arg with new symbol table into $GDB"
429 # All OK
430 }
431 timeout {
432 perror "(timeout) Couldn't load $arg, other program already loaded."
433 return -1
434 }
435 }
436 }
437 -re "No such file or directory.*$mi_gdb_prompt$" {
438 perror "($arg) No such file or directory\n"
439 return -1
440 }
441 -re "105-file-exec-and-symbols .*\r\n105\\\^done\r\n$mi_gdb_prompt$" {
442 # We (MI) are just giving the prompt back for now, instead of giving
da6012e5
DJ
443 # some acknowledgement.
444 return 0
445 }
4392c534
YQ
446 timeout {
447 perror "couldn't load $arg into $GDB (timed out)."
448 return -1
449 }
da6012e5 450 eof {
4392c534
YQ
451 # This is an attempt to detect a core dump, but seems not to
452 # work. Perhaps we need to match .* followed by eof, in which
453 # gdb_expect does not seem to have a way to do that.
454 perror "couldn't load $arg into $GDB (end of file)."
455 return -1
456 }
fb40c209 457 }
da6012e5
DJ
458}
459
460#
b741e217 461# connect to the target and download a file, if necessary.
da6012e5
DJ
462# return a -1 if anything goes wrong.
463#
b741e217 464proc mi_gdb_target_load { } {
da6012e5
DJ
465 global verbose
466 global loadpath
467 global loadfile
468 global GDB
469 global mi_gdb_prompt
e2d69cb5
JZ
470
471 if [target_info exists gdb_load_timeout] {
472 set loadtimeout [target_info gdb_load_timeout]
473 } else {
474 set loadtimeout 1600
475 }
da6012e5 476
da6012e5 477 if { [info procs gdbserver_gdb_load] != "" } {
2226f861 478 mi_gdb_test "kill" ".*" ""
09635af7
MR
479 if { [catch gdbserver_gdb_load res] == 1 } {
480 perror $res
481 return -1
482 }
da6012e5
DJ
483 set protocol [lindex $res 0]
484 set gdbport [lindex $res 1]
485
486 if { [mi_gdb_target_cmd $protocol $gdbport] != 0 } {
487 return -1
488 }
489 } elseif { [info procs send_target_sid] != "" } {
fb40c209 490 # For SID, things get complex
2b97317d
KB
491 send_gdb "kill\n"
492 gdb_expect 10 {
493 -re ".*$mi_gdb_prompt$"
494 }
fb40c209 495 send_target_sid
e2d69cb5 496 gdb_expect $loadtimeout {
2f168eed 497 -re "\\^done.*$mi_gdb_prompt$" {
fb40c209
AC
498 }
499 timeout {
e2d69cb5 500 perror "Unable to connect to SID target (timeout)"
fb40c209
AC
501 return -1
502 }
503 }
504 send_gdb "48-target-download\n"
e2d69cb5 505 gdb_expect $loadtimeout {
fb40c209
AC
506 -re "48\\^done.*$mi_gdb_prompt$" {
507 }
508 timeout {
e2d69cb5 509 perror "Unable to download to SID target (timeout)"
fb40c209
AC
510 return -1
511 }
512 }
513 } elseif { [target_info protocol] == "sim" } {
514 # For the simulator, just connect to it directly.
515 send_gdb "47-target-select sim\n"
e2d69cb5 516 gdb_expect $loadtimeout {
fb40c209
AC
517 -re "47\\^connected.*$mi_gdb_prompt$" {
518 }
519 timeout {
e2d69cb5 520 perror "Unable to select sim target (timeout)"
fb40c209
AC
521 return -1
522 }
523 }
524 send_gdb "48-target-download\n"
e2d69cb5 525 gdb_expect $loadtimeout {
fb40c209
AC
526 -re "48\\^done.*$mi_gdb_prompt$" {
527 }
528 timeout {
e2d69cb5 529 perror "Unable to download to sim target (timeout)"
fb40c209
AC
530 return -1
531 }
532 }
b53f9b27
MS
533 } elseif { [target_info gdb_protocol] == "remote" } {
534 # remote targets
8e3049aa
PB
535 if { [mi_gdb_target_cmd "remote" [target_info netport]] != 0 } {
536 perror "Unable to connect to remote target"
537 return -1
b53f9b27
MS
538 }
539 send_gdb "48-target-download\n"
e2d69cb5 540 gdb_expect $loadtimeout {
b53f9b27
MS
541 -re "48\\^done.*$mi_gdb_prompt$" {
542 }
543 timeout {
e2d69cb5 544 perror "Unable to download to remote target (timeout)"
b53f9b27
MS
545 return -1
546 }
547 }
fb40c209
AC
548 }
549 return 0
550}
551
b741e217
DJ
552#
553# load a file into the debugger.
554# return a -1 if anything goes wrong.
555#
556proc mi_gdb_load { arg } {
557 if { $arg != "" } {
558 return [mi_gdb_file_cmd $arg]
559 }
560 return 0
561}
562
ecd3fd0f
BR
563# mi_gdb_test COMMAND PATTERN MESSAGE [IPATTERN] -- send a command to gdb;
564# test the result.
fb40c209
AC
565#
566# COMMAND is the command to execute, send to GDB with send_gdb. If
567# this is the null string no command is sent.
568# PATTERN is the pattern to match for a PASS, and must NOT include
569# the \r\n sequence immediately before the gdb prompt.
4392c534
YQ
570# MESSAGE is the message to be printed. (If this is the empty string,
571# then sometimes we don't call pass or fail at all; I don't
f1ea48cb 572# understand this at all.)
ecd3fd0f 573# IPATTERN is the pattern to match for the inferior's output. This parameter
4392c534 574# is optional. If present, it will produce a PASS if the match is
ecd3fd0f 575# successful, and a FAIL if unsuccessful.
fb40c209
AC
576#
577# Returns:
578# 1 if the test failed,
579# 0 if the test passes,
580# -1 if there was an internal error.
4392c534 581#
fb40c209
AC
582proc mi_gdb_test { args } {
583 global verbose
584 global mi_gdb_prompt
07c98896 585 global GDB expect_out
405e54e9 586 global inferior_exited_re async
fb40c209
AC
587 upvar timeout timeout
588
fb40c209
AC
589 set command [lindex $args 0]
590 set pattern [lindex $args 1]
f1ea48cb 591 set message [lindex $args 2]
fb40c209 592
ecd3fd0f
BR
593 if [llength $args]==4 {
594 set ipattern [lindex $args 3]
595 }
596
fb40c209 597 if [llength $args]==5 {
4ec70201
PA
598 set question_string [lindex $args 3]
599 set response_string [lindex $args 4]
fb40c209
AC
600 } else {
601 set question_string "^FOOBAR$"
602 }
603
604 if $verbose>2 then {
605 send_user "Sending \"$command\" to gdb\n"
606 send_user "Looking to match \"$pattern\"\n"
607 send_user "Message is \"$message\"\n"
608 }
609
610 set result -1
4ec70201 611 set string "${command}\n"
39fb8e9e
BR
612 set string_regex [string_to_regexp $command]
613
fb40c209
AC
614 if { $command != "" } {
615 while { "$string" != "" } {
4ec70201
PA
616 set foo [string first "\n" "$string"]
617 set len [string length "$string"]
fb40c209 618 if { $foo < [expr $len - 1] } {
4ec70201 619 set str [string range "$string" 0 $foo]
fb40c209 620 if { [send_gdb "$str"] != "" } {
4ec70201 621 global suppress_flag
fb40c209
AC
622
623 if { ! $suppress_flag } {
4ec70201 624 perror "Couldn't send $command to GDB."
fb40c209 625 }
4ec70201 626 fail "$message"
ae59b1da 627 return $result
fb40c209
AC
628 }
629 gdb_expect 2 {
630 -re "\[\r\n\]" { }
631 timeout { }
632 }
4ec70201 633 set string [string range "$string" [expr $foo + 1] end]
fb40c209 634 } else {
4ec70201 635 break
fb40c209
AC
636 }
637 }
638 if { "$string" != "" } {
639 if { [send_gdb "$string"] != "" } {
4ec70201 640 global suppress_flag
fb40c209
AC
641
642 if { ! $suppress_flag } {
4ec70201 643 perror "Couldn't send $command to GDB."
fb40c209 644 }
4ec70201 645 fail "$message"
ae59b1da 646 return $result
fb40c209
AC
647 }
648 }
649 }
650
651 if [info exists timeout] {
4ec70201 652 set tmt $timeout
fb40c209 653 } else {
4ec70201 654 global timeout
fb40c209 655 if [info exists timeout] {
4ec70201 656 set tmt $timeout
fb40c209 657 } else {
4ec70201 658 set tmt 60
fb40c209
AC
659 }
660 }
405e54e9
JK
661 if {$async} {
662 # With $prompt_re "" there may come arbitrary asynchronous response
663 # from the previous command, before or after $string_regex.
664 set string_regex ".*"
665 }
9d81d21b 666 verbose -log "Expecting: ^($string_regex\[\r\n\]+)?($pattern\[\r\n\]+$mi_gdb_prompt\[ \]*)"
fb40c209
AC
667 gdb_expect $tmt {
668 -re "\\*\\*\\* DOSEXIT code.*" {
669 if { $message != "" } {
4ec70201 670 fail "$message"
fb40c209 671 }
4ec70201 672 gdb_suppress_entire_file "GDB died"
ae59b1da 673 return -1
fb40c209
AC
674 }
675 -re "Ending remote debugging.*$mi_gdb_prompt\[ \]*$" {
676 if ![isnative] then {
677 warning "Can`t communicate to remote target."
678 }
679 gdb_exit
680 gdb_start
681 set result -1
7ddebc7e 682 }
405e54e9 683 -re "^($string_regex\[\r\n\]+)?($pattern\[\r\n\]+$mi_gdb_prompt\[ \]*)" {
39fb8e9e
BR
684 # At this point, $expect_out(1,string) is the MI input command.
685 # and $expect_out(2,string) is the MI output command.
686 # If $expect_out(1,string) is "", then there was no MI input command here.
687
40e55bef
BR
688 # NOTE, there is no trailing anchor because with GDB/MI,
689 # asynchronous responses can happen at any point, causing more
690 # data to be available. Normally an anchor is used to make
691 # sure the end of the output is matched, however, $mi_gdb_prompt
692 # is just as good of an anchor since mi_gdb_test is meant to
693 # match a single mi output command. If a second GDB/MI output
694 # response is sent, it will be in the buffer for the next
695 # time mi_gdb_test is called.
7ddebc7e
KS
696 if ![string match "" $message] then {
697 pass "$message"
698 }
699 set result 0
fb40c209
AC
700 }
701 -re "(${question_string})$" {
4ec70201
PA
702 send_gdb "$response_string\n"
703 exp_continue
fb40c209
AC
704 }
705 -re "Undefined.* command:.*$mi_gdb_prompt\[ \]*$" {
706 perror "Undefined command \"$command\"."
4392c534 707 fail "$message"
fb40c209
AC
708 set result 1
709 }
710 -re "Ambiguous command.*$mi_gdb_prompt\[ \]*$" {
711 perror "\"$command\" is not a unique command name."
4392c534 712 fail "$message"
fb40c209 713 set result 1
fb40c209 714 }
fda326dd 715 -re "$inferior_exited_re with code \[0-9\]+.*$mi_gdb_prompt\[ \]*$" {
fb40c209 716 if ![string match "" $message] then {
ed4c619a 717 set errmsg "$message (the program exited)"
fb40c209 718 } else {
ed4c619a 719 set errmsg "$command (the program exited)"
fb40c209
AC
720 }
721 fail "$errmsg"
722 return -1
723 }
724 -re "The program is not being run.*$mi_gdb_prompt\[ \]*$" {
725 if ![string match "" $message] then {
ed4c619a 726 set errmsg "$message (the program is no longer running)"
fb40c209 727 } else {
ed4c619a 728 set errmsg "$command (the program is no longer running)"
fb40c209
AC
729 }
730 fail "$errmsg"
731 return -1
732 }
733 -re ".*$mi_gdb_prompt\[ \]*$" {
734 if ![string match "" $message] then {
735 fail "$message"
736 }
737 set result 1
738 }
739 "<return>" {
740 send_gdb "\n"
741 perror "Window too small."
4392c534 742 fail "$message"
fb40c209
AC
743 }
744 -re "\\(y or n\\) " {
745 send_gdb "n\n"
746 perror "Got interactive prompt."
4392c534 747 fail "$message"
fb40c209
AC
748 }
749 eof {
750 perror "Process no longer exists"
751 if { $message != "" } {
752 fail "$message"
753 }
754 return -1
755 }
756 full_buffer {
757 perror "internal buffer is full."
4392c534 758 fail "$message"
fb40c209
AC
759 }
760 timeout {
761 if ![string match "" $message] then {
762 fail "$message (timeout)"
763 }
764 set result 1
765 }
766 }
ecd3fd0f
BR
767
768 # If the GDB output matched, compare the inferior output.
769 if { $result == 0 } {
770 if [ info exists ipattern ] {
d084b331 771 if { ![target_info exists gdb,noinferiorio] } {
e8376742
PA
772 global gdb_spawn_id inferior_spawn_id
773
774 set sid "$inferior_spawn_id $gdb_spawn_id"
775 gdb_expect {
776 -i "$sid" -re "$ipattern" {
777 pass "$message inferior output"
d084b331 778 }
e8376742
PA
779 timeout {
780 fail "$message inferior output (timeout)"
781 set result 1
d084b331 782 }
ecd3fd0f 783 }
d084b331
DJ
784 } else {
785 unsupported "$message inferior output"
ecd3fd0f 786 }
6ec41e1e 787 }
ecd3fd0f
BR
788 }
789
fb40c209
AC
790 return $result
791}
792
17b2616c
PA
793# Collect output sent to the console output stream until UNTIL is
794# seen. UNTIL is a regular expression. MESSAGE is the message to be
795# printed in case of timeout.
796
797proc mi_gdb_expect_cli_output {until message} {
798
799 set output ""
800 gdb_expect {
801 -re "~\"(\[^\r\n\]+)\"\r\n" {
802 append output $expect_out(1,string)
803 exp_continue
804 }
805 -notransfer -re "$until" {
806 # Done
807 }
808 timeout {
809 fail "$message (timeout)"
810 return ""
811 }
812 }
813
814 return $output
815}
816
fb40c209
AC
817#
818# MI run command. (A modified version of gdb_run_cmd)
819#
820
821# In patterns, the newline sequence ``\r\n'' is matched explicitly as
822# ``.*$'' could swallow up output that we attempt to match elsewhere.
823
a2199296
SM
824# Send the command to run the test program.
825#
826# If USE_MI_COMMAND is true, the "-exec-run" command is used.
827# Otherwise, the "run" (CLI) command is used. If the global USE_GDB_STUB is
828# true, -exec-continue and continue are used instead of their run counterparts.
829#
830# ARGS is passed as argument to the command used to run the test program.
831# Beware that arguments to "-exec-run" do not have the same semantics as
832# arguments to the "run" command, so USE_MI_COMMAND influences the meaning
833# of ARGS. If USE_MI_COMMAND is true, they are arguments to -exec-run.
834# If USE_MI_COMMAND is false, they are effectively arguments passed
835# to the test program. If the global USE_GDB_STUB is true, ARGS is not used.
36dfb11c 836proc mi_run_cmd_full {use_mi_command args} {
fb40c209
AC
837 global suppress_flag
838 if { $suppress_flag } {
839 return -1
840 }
e11ac3a3 841 global mi_gdb_prompt use_gdb_stub
66bb093b 842 global thread_selected_re
c86cf029 843 global library_loaded_re
fb40c209 844
36dfb11c
TT
845 if {$use_mi_command} {
846 set run_prefix "220-exec-"
847 set run_match "220"
848 } else {
849 set run_prefix ""
850 set run_match ""
851 }
852
a25eb028
MR
853 foreach command [gdb_init_commands] {
854 send_gdb "$command\n"
fb40c209
AC
855 gdb_expect 30 {
856 -re "$mi_gdb_prompt$" { }
857 default {
4ec70201 858 perror "gdb_init_command for target failed"
ae59b1da 859 return -1
fb40c209
AC
860 }
861 }
862 }
863
b741e217 864 if { [mi_gdb_target_load] < 0 } {
56a8e183 865 return -1
b741e217
DJ
866 }
867
e11ac3a3 868 if $use_gdb_stub {
fb40c209 869 if [target_info exists gdb,do_reload_on_run] {
4ec70201 870 send_gdb "${run_prefix}continue\n"
fb40c209 871 gdb_expect 60 {
36dfb11c 872 -re "${run_match}\\^running\[\r\n\]+\\*running,thread-id=\"\[^\"\]+\"\r\n$mi_gdb_prompt" {}
88bbeca9 873 -re "${run_match}\\^error.*$mi_gdb_prompt" {return -1}
fb40c209
AC
874 default {}
875 }
ae59b1da 876 return 0
fb40c209 877 }
6a90e1d0
AC
878
879 if [target_info exists gdb,start_symbol] {
4ec70201 880 set start [target_info gdb,start_symbol]
6a90e1d0 881 } else {
4ec70201 882 set start "start"
6a90e1d0
AC
883 }
884
885 # HACK: Should either use 000-jump or fix the target code
886 # to better handle RUN.
887 send_gdb "jump *$start\n"
888 warning "Using CLI jump command, expect run-to-main FAIL"
6d265cb4
TP
889 gdb_expect {
890 -re "${run_match}&\"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}" {}
891 }
56a8e183 892 return 0
fb40c209
AC
893 }
894
2f25d70f 895 send_gdb "${run_prefix}run $args\n"
fb40c209 896 gdb_expect {
36dfb11c 897 -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}" {
fb40c209 898 }
56a8e183
PA
899 -re "\\^error,msg=\"The target does not support running in non-stop mode.\"" {
900 unsupported "Non-stop mode not supported"
901 return -1
902 }
fb40c209
AC
903 timeout {
904 perror "Unable to start target"
56a8e183 905 return -1
fb40c209
AC
906 }
907 }
2d0720d9 908 # NOTE: Shortly after this there will be a ``000*stopped,...(gdb)''
56a8e183
PA
909
910 return 0
fb40c209
AC
911}
912
36dfb11c
TT
913# A wrapper for mi_run_cmd_full which uses -exec-run and
914# -exec-continue, as appropriate. ARGS are passed verbatim to
915# mi_run_cmd_full.
916proc mi_run_cmd {args} {
917 return [eval mi_run_cmd_full 1 $args]
918}
919
920# A wrapper for mi_run_cmd_full which uses the CLI commands 'run' and
921# 'continue', as appropriate. ARGS are passed verbatim to
922# mi_run_cmd_full.
923proc mi_run_with_cli {args} {
924 return [eval mi_run_cmd_full 0 $args]
925}
926
fb40c209
AC
927#
928# Just like run-to-main but works with the MI interface
929#
930
931proc mi_run_to_main { } {
932 global suppress_flag
933 if { $suppress_flag } {
934 return -1
935 }
936
fb40c209
AC
937 global srcdir
938 global subdir
939 global binfile
940 global srcfile
941
fb40c209
AC
942 mi_delete_breakpoints
943 mi_gdb_reinitialize_dir $srcdir/$subdir
944 mi_gdb_load ${binfile}
945
08b468e0
KS
946 mi_runto main
947}
fb40c209 948
08b468e0
KS
949
950# Just like gdb's "runto" proc, it will run the target to a given
951# function. The big difference here between mi_runto and mi_execute_to
952# is that mi_execute_to must have the inferior running already. This
953# proc will (like gdb's runto) (re)start the inferior, too.
954#
955# FUNC is the linespec of the place to stop (it inserts a breakpoint here).
956# It returns:
957# -1 if test suppressed, failed, timedout
958# 0 if test passed
959
f7e97bb3 960proc mi_runto_helper {func run_or_continue} {
08b468e0
KS
961 global suppress_flag
962 if { $suppress_flag } {
963 return -1
964 }
965
966 global mi_gdb_prompt expect_out
76ff342d 967 global hex decimal fullname_syntax
08b468e0
KS
968
969 set test "mi runto $func"
4b48d439
KS
970 set bp [mi_make_breakpoint -type breakpoint -disp del \
971 -func $func\(\\\(.*\\\)\)?]
972 mi_gdb_test "200-break-insert -t $func" "200\\^done,$bp" \
973 "breakpoint at $func"
08b468e0 974
f7e97bb3 975 if {$run_or_continue == "run"} {
56a8e183
PA
976 if { [mi_run_cmd] < 0 } {
977 return -1
978 }
f7e97bb3 979 } else {
bb378428 980 mi_send_resuming_command "exec-continue" "$test"
f7e97bb3 981 }
74a44383 982
18ac113b 983 mi_expect_stop "breakpoint-hit" $func ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } $test
fb40c209
AC
984}
985
f7e97bb3 986proc mi_runto {func} {
56a8e183 987 return [mi_runto_helper $func "run"]
f7e97bb3 988}
fb40c209
AC
989
990# Next to the next statement
08b468e0 991# For return values, see mi_execute_to_helper
fb40c209
AC
992
993proc mi_next { test } {
dc360f58 994 return [mi_next_to {.*} {.*} {.*} {.*} $test]
fb40c209
AC
995}
996
997
998# Step to the next statement
08b468e0 999# For return values, see mi_execute_to_helper
fb40c209
AC
1000
1001proc mi_step { test } {
dc360f58 1002 return [mi_step_to {.*} {.*} {.*} {.*} $test]
fb40c209 1003}
dcf95b47 1004
f7f9a841
VP
1005set async "unknown"
1006
fcdfa280 1007proc mi_detect_async {} {
f7f9a841
VP
1008 global async
1009 global mi_gdb_prompt
1010
329ea579 1011 send_gdb "show mi-async\n"
4392c534 1012
a2840c35 1013 gdb_expect {
329ea579 1014 -re "asynchronous mode is on...*$mi_gdb_prompt$" {
4392c534
YQ
1015 set async 1
1016 }
1017 -re ".*$mi_gdb_prompt$" {
1018 set async 0
1019 }
1020 timeout {
1021 set async 0
1022 }
f7f9a841
VP
1023 }
1024 return $async
1025}
1026
bb378428
VP
1027# Wait for MI *stopped notification to appear.
1028# The REASON, FUNC, ARGS, FILE and LINE are regular expressions
05acf274
JK
1029# to match against whatever is output in *stopped. FILE may also match
1030# filename of a file without debug info. ARGS should not include [] the
1031# list of argument is enclosed in, and other regular expressions should
1032# not include quotes.
bb378428
VP
1033# If EXTRA is a list of one element, it's the regular expression
1034# for output expected right after *stopped, and before GDB prompt.
1035# If EXTRA is a list of two elements, the first element is for
1036# output right after *stopped, and the second element is output
1037# right after reason field. The regex after reason should not include
1038# the comma separating it from the following fields.
4392c534 1039#
05acf274
JK
1040# When we fail to match output at all, -1 is returned. If FILE does
1041# match and the target system has no debug info for FILE return 0.
1042# Otherwise, the line at which we stop is returned. This is useful when
1043# exact line is not possible to specify for some reason -- one can pass
d0b76dc6
DJ
1044# the .* or "\[0-9\]*" regexps for line, and then check the line
1045# programmatically.
1046#
1047# Do not pass .* for any argument if you are expecting more than one stop.
bb378428 1048proc mi_expect_stop { reason func args file line extra test } {
1902c51f 1049
dcf95b47
DJ
1050 global mi_gdb_prompt
1051 global hex
1052 global decimal
76ff342d 1053 global fullname_syntax
f7f9a841 1054 global async
66bb093b 1055 global thread_selected_re
8d3788bd 1056 global breakpoint_re
bb378428 1057
0c7e1a46
PA
1058 set any "\[^\n\]*"
1059
bb378428
VP
1060 set after_stopped ""
1061 set after_reason ""
1062 if { [llength $extra] == 2 } {
4392c534
YQ
1063 set after_stopped [lindex $extra 0]
1064 set after_reason [lindex $extra 1]
1065 set after_reason "${after_reason},"
bb378428 1066 } elseif { [llength $extra] == 1 } {
4392c534 1067 set after_stopped [lindex $extra 0]
bb378428
VP
1068 }
1069
f7f9a841 1070 if {$async} {
4392c534 1071 set prompt_re ""
f7f9a841 1072 } else {
4392c534 1073 set prompt_re "$mi_gdb_prompt$"
f7f9a841
VP
1074 }
1075
1076 if { $reason == "really-no-reason" } {
4392c534
YQ
1077 gdb_expect {
1078 -re "\\*stopped\r\n$prompt_re" {
1079 pass "$test"
1080 }
1081 timeout {
73eb7709 1082 fail "$test (timeout)"
4392c534
YQ
1083 }
1084 }
1085 return
1086 }
1087
bb378428
VP
1088 if { $reason == "exited-normally" } {
1089
4392c534
YQ
1090 gdb_expect {
1091 -re "\\*stopped,reason=\"exited-normally\"\r\n$prompt_re" {
1092 pass "$test"
1093 }
1094 -re ".*$mi_gdb_prompt$" {fail "continue to end (2)"}
1095 timeout {
73eb7709 1096 fail "$test (timeout)"
4392c534
YQ
1097 }
1098 }
1099 return
bb378428 1100 }
3deb39c6
SM
1101 if { $reason == "exited" } {
1102 gdb_expect {
1103 -re "\\*stopped,reason=\"exited\",exit-code=\"\[0-7\]+\"\r\n$prompt_re" {
1104 pass "$test"
1105 }
1106 -re ".*$mi_gdb_prompt$" {
1107 fail "$test (inferior not stopped)"
1108 }
1109 timeout {
73eb7709 1110 fail "$test (timeout)"
3deb39c6
SM
1111 }
1112 }
1113 return
1114 }
bb378428 1115
0c7e1a46
PA
1116 if { $reason == "solib-event" } {
1117 set pattern "\\*stopped,reason=\"solib-event\",thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re"
1118 verbose -log "mi_expect_stop: expecting: $pattern"
1119 gdb_expect {
1120 -re "$pattern" {
1121 pass "$test"
1122 }
1123 timeout {
73eb7709 1124 fail "$test (timeout)"
0c7e1a46
PA
1125 }
1126 }
1127 return
1128 }
1129
bb378428
VP
1130 set args "\\\[$args\\\]"
1131
1132 set bn ""
1133 if { $reason == "breakpoint-hit" } {
4392c534 1134 set bn {bkptno="[0-9]+",}
edcc5120
TT
1135 } elseif { $reason == "solib-event" } {
1136 set bn ".*"
bb378428
VP
1137 }
1138
1139 set r ""
1140 if { $reason != "" } {
4392c534 1141 set r "reason=\"$reason\","
bb378428
VP
1142 }
1143
18ac113b
AR
1144
1145 set a $after_reason
1146
05acf274 1147 verbose -log "mi_expect_stop: expecting: \\*stopped,${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$func\",args=$args,(?:file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"$line\"|from=\"$file\")\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re"
dcf95b47 1148 gdb_expect {
05acf274 1149 -re "\\*stopped,${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$func\",args=$args,(?:file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"($line)\"|from=\"$file\")\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re" {
dcf95b47 1150 pass "$test"
05acf274
JK
1151 if {[array names expect_out "2,string"] != ""} {
1152 return $expect_out(2,string)
1153 }
1154 # No debug info available but $file does match.
1155 return 0
dcf95b47 1156 }
c7b1f0d9 1157 -re "\\*stopped,${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$any\",args=\[\\\[\{\]$any\[\\\]\}\],file=\"$any\",fullname=\"${fullname_syntax}$any\",line=\"\[0-9\]*\"\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re" {
4392c534 1158 verbose -log "got $expect_out(buffer)"
dcf95b47
DJ
1159 fail "$test (stopped at wrong place)"
1160 return -1
1161 }
f7f9a841 1162 -re ".*\r\n$mi_gdb_prompt$" {
4392c534 1163 verbose -log "got $expect_out(buffer)"
dcf95b47
DJ
1164 fail "$test (unknown output after running)"
1165 return -1
1166 }
dcf95b47
DJ
1167 timeout {
1168 fail "$test (timeout)"
1169 return -1
1170 }
4392c534 1171 }
dcf95b47
DJ
1172}
1173
1ad15515
PA
1174# Wait for MI *stopped notification related to an interrupt request to
1175# appear.
1176proc mi_expect_interrupt { test } {
1177 global mi_gdb_prompt
1178 global decimal
1179 global async
1180
1181 if {$async} {
1182 set prompt_re ""
1183 } else {
1184 set prompt_re "$mi_gdb_prompt$"
1185 }
1186
a8d9763a
SM
1187 set r_nonstop "reason=\"signal-received\",signal-name=\"0\",signal-meaning=\"Signal 0\""
1188 set r_allstop "reason=\"signal-received\",signal-name=\"SIGINT\",signal-meaning=\"Interrupt\""
1189 set r "(${r_nonstop}|${r_allstop})"
1ad15515
PA
1190 set any "\[^\n\]*"
1191
1192 # A signal can land anywhere, just ignore the location
1d33d6ba 1193 verbose -log "mi_expect_interrupt: expecting: \\*stopped,${r}$any\r\n$prompt_re"
1ad15515 1194 gdb_expect {
1d33d6ba 1195 -re "\\*stopped,${r}$any\r\n$prompt_re" {
1ad15515 1196 pass "$test"
ae59b1da 1197 return 0
1ad15515
PA
1198 }
1199 -re ".*\r\n$mi_gdb_prompt$" {
1200 verbose -log "got $expect_out(buffer)"
1201 fail "$test (unknown output after running)"
1202 return -1
1203 }
1204 timeout {
1205 fail "$test (timeout)"
1206 return -1
1207 }
1208 }
1209}
1210
bb378428
VP
1211# cmd should not include the number or newline (i.e. "exec-step 3", not
1212# "220-exec-step 3\n"
1213
1214# Can not match -re ".*\r\n${mi_gdb_prompt}", because of false positives
1215# after the first prompt is printed.
1216
08b468e0 1217proc mi_execute_to { cmd reason func args file line extra test } {
bb378428
VP
1218 global suppress_flag
1219 if { $suppress_flag } {
1220 return -1
1221 }
1222
1223 mi_send_resuming_command "$cmd" "$test"
1224 set r [mi_expect_stop $reason $func $args $file $line $extra $test]
1225 return $r
dcf95b47
DJ
1226}
1227
1228proc mi_next_to { func args file line test } {
08b468e0 1229 mi_execute_to "exec-next" "end-stepping-range" "$func" "$args" \
dcf95b47
DJ
1230 "$file" "$line" "" "$test"
1231}
1232
1233proc mi_step_to { func args file line test } {
08b468e0 1234 mi_execute_to "exec-step" "end-stepping-range" "$func" "$args" \
dcf95b47
DJ
1235 "$file" "$line" "" "$test"
1236}
1237
1238proc mi_finish_to { func args file line result ret test } {
08b468e0 1239 mi_execute_to "exec-finish" "function-finished" "$func" "$args" \
dcf95b47
DJ
1240 "$file" "$line" \
1241 ",gdb-result-var=\"$result\",return-value=\"$ret\"" \
1242 "$test"
1243}
1244
f7e97bb3
VP
1245proc mi_continue_to {func} {
1246 mi_runto_helper $func "continue"
dcf95b47
DJ
1247}
1248
08b468e0
KS
1249proc mi0_execute_to { cmd reason func args file line extra test } {
1250 mi_execute_to_helper "$cmd" "$reason" "$func" "\{$args\}" \
dcf95b47
DJ
1251 "$file" "$line" "$extra" "$test"
1252}
1253
1254proc mi0_next_to { func args file line test } {
08b468e0 1255 mi0_execute_to "exec-next" "end-stepping-range" "$func" "$args" \
dcf95b47
DJ
1256 "$file" "$line" "" "$test"
1257}
1258
1259proc mi0_step_to { func args file line test } {
08b468e0 1260 mi0_execute_to "exec-step" "end-stepping-range" "$func" "$args" \
dcf95b47
DJ
1261 "$file" "$line" "" "$test"
1262}
1263
1264proc mi0_finish_to { func args file line result ret test } {
08b468e0 1265 mi0_execute_to "exec-finish" "function-finished" "$func" "$args" \
dcf95b47
DJ
1266 "$file" "$line" \
1267 ",gdb-result-var=\"$result\",return-value=\"$ret\"" \
1268 "$test"
1269}
1270
1271proc mi0_continue_to { bkptno func args file line test } {
08b468e0 1272 mi0_execute_to "exec-continue" "breakpoint-hit\",bkptno=\"$bkptno" \
dcf95b47
DJ
1273 "$func" "$args" "$file" "$line" "" "$test"
1274}
b26ed50d 1275
4b48d439
KS
1276# Creates a breakpoint and checks the reported fields are as expected.
1277# This procedure takes the same options as mi_make_breakpoint and
1278# returns the breakpoint regexp from that procedure.
d24317b4 1279
4b48d439
KS
1280proc mi_create_breakpoint {location test args} {
1281 set bp [eval mi_make_breakpoint $args]
1282 mi_gdb_test "222-break-insert $location" "222\\^done,$bp" $test
1283 return $bp
d24317b4
VP
1284}
1285
b26ed50d
VP
1286# Creates varobj named NAME for EXPRESSION.
1287# Name cannot be "-".
1288proc mi_create_varobj { name expression testname } {
1289 mi_gdb_test "-var-create $name * $expression" \
4392c534
YQ
1290 "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=.*,has_more=\"0\"" \
1291 $testname
b26ed50d
VP
1292}
1293
fcacd99f
VP
1294proc mi_create_floating_varobj { name expression testname } {
1295 mi_gdb_test "-var-create $name @ $expression" \
4392c534
YQ
1296 "\\^done,name=\"$name\",numchild=\"\(-1\|\[0-9\]+\)\",value=\".*\",type=.*" \
1297 $testname
fcacd99f
VP
1298}
1299
1300
9e8e3afe
VP
1301# Same as mi_create_varobj, but also checks the reported type
1302# of the varobj.
1303proc mi_create_varobj_checked { name expression type testname } {
1304 mi_gdb_test "-var-create $name * $expression" \
4392c534
YQ
1305 "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=\"$type\".*" \
1306 $testname
9e8e3afe
VP
1307}
1308
0cc7d26f
TT
1309# Same as mi_create_floating_varobj, but assumes the test is creating
1310# a dynamic varobj that has children, so the value must be "{...}".
0a1e6121
YQ
1311# The "has_more" attribute is checked.
1312proc mi_create_dynamic_varobj {name expression has_more testname} {
0cc7d26f 1313 mi_gdb_test "-var-create $name @ $expression" \
0a1e6121 1314 "\\^done,name=\"$name\",numchild=\"0\",value=\"{\\.\\.\\.}\",type=.*,has_more=\"${has_more}\"" \
4392c534 1315 $testname
0cc7d26f
TT
1316}
1317
4392c534 1318# Deletes the specified NAME.
6e2a9270
VP
1319proc mi_delete_varobj { name testname } {
1320 mi_gdb_test "-var-delete $name" \
4392c534
YQ
1321 "\\^done,ndeleted=.*" \
1322 $testname
6e2a9270
VP
1323}
1324
b26ed50d
VP
1325# Updates varobj named NAME and checks that all varobjs in EXPECTED
1326# are reported as updated, and no other varobj is updated.
1327# Assumes that no varobj is out of scope and that no varobj changes
1328# types.
1329proc mi_varobj_update { name expected testname } {
1330 set er "\\^done,changelist=\\\["
1331 set first 1
1332 foreach item $expected {
4392c534
YQ
1333 set v "{name=\"$item\",in_scope=\"true\",type_changed=\"false\",has_more=\".\"}"
1334 if {$first == 1} {
1335 set er "$er$v"
1336 set first 0
1337 } else {
1338 set er "$er,$v"
1339 }
b26ed50d
VP
1340 }
1341 set er "$er\\\]"
1342
1343 verbose -log "Expecting: $er" 2
1344 mi_gdb_test "-var-update $name" $er $testname
1345}
1346
8264ba82
AG
1347proc mi_varobj_update_with_child_type_change { name child_name new_type new_children testname } {
1348 set v "{name=\"$child_name\",in_scope=\"true\",type_changed=\"true\",new_type=\"$new_type\",new_num_children=\"$new_children\",has_more=\".\"}"
fcacd99f
VP
1349 set er "\\^done,changelist=\\\[$v\\\]"
1350 verbose -log "Expecting: $er"
1351 mi_gdb_test "-var-update $name" $er $testname
1352}
1353
8264ba82
AG
1354proc mi_varobj_update_with_type_change { name new_type new_children testname } {
1355 mi_varobj_update_with_child_type_change $name $name $new_type $new_children $testname
1356}
1357
0cc7d26f
TT
1358# A helper that turns a key/value list into a regular expression
1359# matching some MI output.
1360proc mi_varobj_update_kv_helper {list} {
1361 set first 1
1362 set rx ""
1363 foreach {key value} $list {
1364 if {!$first} {
1365 append rx ,
1366 }
1367 set first 0
1368 if {$key == "new_children"} {
1369 append rx "$key=\\\[$value\\\]"
1370 } else {
1371 append rx "$key=\"$value\""
1372 }
1373 }
1374 return $rx
1375}
b6313243 1376
0cc7d26f
TT
1377# A helper for mi_varobj_update_dynamic that computes a match
1378# expression given a child list.
1379proc mi_varobj_update_dynamic_helper {children} {
1380 set crx ""
b6313243 1381
0cc7d26f
TT
1382 set first 1
1383 foreach child $children {
1384 if {!$first} {
1385 append crx ,
1386 }
1387 set first 0
1388 append crx "{"
1389 append crx [mi_varobj_update_kv_helper $child]
1390 append crx "}"
1391 }
1392
1393 return $crx
1394}
1395
1396# Update a dynamic varobj named NAME. CHILDREN is a list of children
1397# that have been updated; NEW_CHILDREN is a list of children that were
1398# added to the primary varobj. Each child is a list of key/value
1399# pairs that are expected. SELF is a key/value list holding
1400# information about the varobj itself. TESTNAME is the name of the
1401# test.
1402proc mi_varobj_update_dynamic {name testname self children new_children} {
1403 if {[llength $new_children]} {
1404 set newrx [mi_varobj_update_dynamic_helper $new_children]
1405 lappend self new_children $newrx
1406 }
1407 set selfrx [mi_varobj_update_kv_helper $self]
1408 set crx [mi_varobj_update_dynamic_helper $children]
1409
1410 set er "\\^done,changelist=\\\[\{name=\"$name\",in_scope=\"true\""
1411 append er ",$selfrx\}"
1412 if {"$crx" != ""} {
1413 append er ",$crx"
1414 }
1415 append er "\\\]"
b6313243
TT
1416
1417 verbose -log "Expecting: $er"
1418 mi_gdb_test "-var-update $name" $er $testname
1419}
1420
b26ed50d
VP
1421proc mi_check_varobj_value { name value testname } {
1422
1423 mi_gdb_test "-var-evaluate-expression $name" \
1424 "\\^done,value=\"$value\"" \
1425 $testname
1426}
038224f6 1427
b6313243
TT
1428# Helper proc which constructs a child regexp for
1429# mi_list_varobj_children and mi_varobj_update_dynamic.
1430proc mi_child_regexp {children add_child} {
1431 set children_exp {}
b6313243
TT
1432
1433 if {$add_child} {
1434 set pre "child="
1435 } else {
1436 set pre ""
1437 }
1438
1439 foreach item $children {
1440
4392c534
YQ
1441 set name [lindex $item 0]
1442 set exp [lindex $item 1]
1443 set numchild [lindex $item 2]
1444 if {[llength $item] == 5} {
1445 set type [lindex $item 3]
1446 set value [lindex $item 4]
1447
1448 lappend children_exp\
31b4ab9e 1449 "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",value=\"$value\",type=\"$type\"(,thread-id=\"\[0-9\]+\")?}"
4392c534
YQ
1450 } elseif {[llength $item] == 4} {
1451 set type [lindex $item 3]
1452
1453 lappend children_exp\
31b4ab9e 1454 "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",type=\"$type\"(,thread-id=\"\[0-9\]+\")?}"
4392c534
YQ
1455 } else {
1456 lappend children_exp\
1457 "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\"(,thread-id=\"\[0-9\]+\")?}"
1458 }
b6313243
TT
1459 }
1460 return [join $children_exp ","]
1461}
1462
038224f6
VP
1463# Check the results of the:
1464#
1465# -var-list-children VARNAME
1466#
1467# command. The CHILDREN parement should be a list of lists.
1468# Each inner list can have either 3 or 4 elements, describing
1469# fields that gdb is expected to report for child variable object,
1470# in the following order
1471#
1472# - Name
1473# - Expression
1474# - Number of children
1475# - Type
1476#
1477# If inner list has 3 elements, the gdb is expected to output no
9e8e3afe
VP
1478# type for a child and no value.
1479#
1480# If the inner list has 4 elements, gdb output is expected to
1481# have no value.
038224f6
VP
1482#
1483proc mi_list_varobj_children { varname children testname } {
0cc7d26f 1484 mi_list_varobj_children_range $varname "" "" [llength $children] $children \
b6313243
TT
1485 $testname
1486}
038224f6 1487
0cc7d26f
TT
1488# Like mi_list_varobj_children, but sets a subrange. NUMCHILDREN is
1489# the total number of children.
1490proc mi_list_varobj_children_range {varname from to numchildren children testname} {
9e8e3afe
VP
1491 set options ""
1492 if {[llength $varname] == 2} {
4392c534
YQ
1493 set options [lindex $varname 1]
1494 set varname [lindex $varname 0]
9e8e3afe
VP
1495 }
1496
b6313243 1497 set children_exp_j [mi_child_regexp $children 1]
9e8e3afe 1498 if {$numchildren} {
4392c534 1499 set expected "\\^done,numchild=\".*\",children=\\\[$children_exp_j.*\\\]"
9e8e3afe 1500 } {
4392c534 1501 set expected "\\^done,numchild=\"0\""
9e8e3afe 1502 }
038224f6 1503
0cc7d26f 1504 if {"$to" == ""} {
4392c534 1505 append expected ",has_more=\"0\""
0cc7d26f 1506 } elseif {$to >= 0 && $numchildren > $to} {
4392c534 1507 append expected ",has_more=\"1\""
0cc7d26f 1508 } else {
4392c534 1509 append expected ",has_more=\"0\""
0cc7d26f
TT
1510 }
1511
038224f6
VP
1512 verbose -log "Expecting: $expected"
1513
0cc7d26f
TT
1514 mi_gdb_test "-var-list-children $options $varname $from $to" \
1515 $expected $testname
9e8e3afe
VP
1516}
1517
1518# Verifies that variable object VARNAME has NUMBER children,
1519# where each one is named $VARNAME.<index-of-child> and has type TYPE.
1520proc mi_list_array_varobj_children { varname number type testname } {
f84bc218
KB
1521 mi_list_array_varobj_children_with_index $varname $number 0 $type $testname
1522}
1523
1524# Same as mi_list_array_varobj_children, but allowing to pass a start index
1525# for an array.
1526proc mi_list_array_varobj_children_with_index { varname number start_index \
1527 type testname } {
9e8e3afe 1528 set t {}
f84bc218 1529 set index $start_index
9e8e3afe 1530 for {set i 0} {$i < $number} {incr i} {
f84bc218
KB
1531 lappend t [list $varname.$index $index 0 $type]
1532 incr index
9e8e3afe
VP
1533 }
1534 mi_list_varobj_children $varname $t $testname
038224f6 1535}
2d0720d9
VP
1536
1537# A list of two-element lists. First element of each list is
1538# a Tcl statement, and the second element is the line
1539# number of source C file where the statement originates.
1540set mi_autotest_data ""
1541# The name of the source file for autotesting.
1542set mi_autotest_source ""
1543
1544proc count_newlines { string } {
1545 return [regexp -all "\n" $string]
1546}
1547
1548# Prepares for running inline tests in FILENAME.
1549# See comments for mi_run_inline_test for detailed
1550# explanation of the idea and syntax.
1551proc mi_prepare_inline_tests { filename } {
1552
1553 global srcdir
1554 global subdir
1555 global mi_autotest_source
1556 global mi_autotest_data
1557
1558 set mi_autotest_data {}
1559
1560 set mi_autotest_source $filename
4392c534 1561
2d0720d9
VP
1562 if { ! [regexp "^/" "$filename"] } then {
1563 set filename "$srcdir/$subdir/$filename"
1564 }
1565
1566 set chan [open $filename]
1567 set content [read $chan]
1568 set line_number 1
1569 while {1} {
4392c534
YQ
1570 set start [string first "/*:" $content]
1571 if {$start != -1} {
1572 set end [string first ":*/" $content]
1573 if {$end == -1} {
1574 error "Unterminated special comment in $filename"
1575 }
1576
1577 set prefix [string range $content 0 $start]
1578 set prefix_newlines [count_newlines $prefix]
1579
1580 set line_number [expr $line_number+$prefix_newlines]
1581 set comment_line $line_number
1582
1583 set comment [string range $content [expr $start+3] [expr $end-1]]
1584
1585 set comment_newlines [count_newlines $comment]
1586 set line_number [expr $line_number+$comment_newlines]
1587
1588 set comment [string trim $comment]
1589 set content [string range $content [expr $end+3] \
1590 [string length $content]]
1591 lappend mi_autotest_data [list $comment $comment_line]
1592 } else {
1593 break
1594 }
2d0720d9
VP
1595 }
1596 close $chan
1597}
1598
1599# Helper to mi_run_inline_test below.
1600# Return the list of all (statement,line_number) lists
1601# that comprise TESTCASE. The begin and end markers
1602# are not included.
1603proc mi_get_inline_test {testcase} {
1604
1605 global mi_gdb_prompt
1606 global mi_autotest_data
1607 global mi_autotest_source
1608
1609 set result {}
1610
1611 set seen_begin 0
1612 set seen_end 0
1613 foreach l $mi_autotest_data {
1614
4392c534 1615 set comment [lindex $l 0]
2d0720d9 1616
4392c534
YQ
1617 if {$comment == "BEGIN: $testcase"} {
1618 set seen_begin 1
1619 } elseif {$comment == "END: $testcase"} {
1620 set seen_end 1
1621 break
1622 } elseif {$seen_begin==1} {
1623 lappend result $l
1624 }
2d0720d9
VP
1625 }
1626
1627 if {$seen_begin == 0} {
4392c534 1628 error "Autotest $testcase not found"
2d0720d9
VP
1629 }
1630
1631 if {$seen_begin == 1 && $seen_end == 0} {
4392c534 1632 error "Missing end marker for test $testcase"
2d0720d9
VP
1633 }
1634
1635 return $result
1636}
1637
1638# Sets temporary breakpoint at LOCATION.
1639proc mi_tbreak {location} {
1640
1641 global mi_gdb_prompt
1642
1643 mi_gdb_test "-break-insert -t $location" \
4392c534
YQ
1644 {\^done,bkpt=.*} \
1645 "run to $location (set breakpoint)"
2d0720d9
VP
1646}
1647
1648# Send COMMAND that must be a command that resumes
7bf9deb0 1649# the inferior (run/continue/next/etc) and consumes
2d0720d9 1650# the "^running" output from it.
a2840c35 1651proc mi_send_resuming_command_raw {command test} {
2d0720d9
VP
1652
1653 global mi_gdb_prompt
66bb093b 1654 global thread_selected_re
c86cf029 1655 global library_loaded_re
2d0720d9 1656
a2840c35 1657 send_gdb "$command\n"
2d0720d9 1658 gdb_expect {
4392c534
YQ
1659 -re "\\^running\r\n\\*running,thread-id=\"\[^\"\]+\"\r\n($library_loaded_re)*($thread_selected_re)?${mi_gdb_prompt}" {
1660 # Note that lack of 'pass' call here -- this works around limitation
1661 # in DejaGNU xfail mechanism. mi-until.exp has this:
1662 #
1663 # setup_kfail gdb/2104 "*-*-*"
1664 # mi_execute_to ...
1665 #
1666 # and mi_execute_to uses mi_send_resuming_command. If we use 'pass' here,
1667 # it will reset kfail, so when the actual test fails, it will be flagged
1668 # as real failure.
d0b76dc6 1669 return 0
4392c534
YQ
1670 }
1671 -re "\\^error,msg=\"Displaced stepping is only supported in ARM mode\".*" {
1672 unsupported "$test (Thumb mode)"
1673 return -1
1674 }
1675 -re "\\^error,msg=.*" {
1676 fail "$test (MI error)"
4ea95be9 1677 return -1
4392c534
YQ
1678 }
1679 -re ".*${mi_gdb_prompt}" {
1680 fail "$test (failed to resume)"
1681 return -1
1682 }
1683 timeout {
bb378428
VP
1684 fail "$test"
1685 return -1
4392c534 1686 }
2d0720d9
VP
1687 }
1688}
1689
a2840c35
VP
1690proc mi_send_resuming_command {command test} {
1691 mi_send_resuming_command_raw -$command $test
1692}
1693
2d0720d9
VP
1694# Helper to mi_run_inline_test below.
1695# Sets a temporary breakpoint at LOCATION and runs
1696# the program using COMMAND. When the program is stopped
1697# returns the line at which it. Returns -1 if line cannot
1698# be determined.
1699# Does not check that the line is the same as requested.
1700# The caller can check itself if required.
a73bafbc 1701proc mi_continue_to_line {location test} {
2d0720d9 1702
4392c534 1703 mi_tbreak $location
2d0720d9 1704 mi_send_resuming_command "exec-continue" "run to $location (exec-continue)"
bb378428 1705 return [mi_get_stop_line $test]
2d0720d9
VP
1706}
1707
1708# Wait until gdb prints the current line.
bb378428 1709proc mi_get_stop_line {test} {
2d0720d9
VP
1710
1711 global mi_gdb_prompt
f7f9a841
VP
1712 global async
1713
1714 if {$async} {
1715 set prompt_re ""
1716 } else {
d0b76dc6 1717 set prompt_re "$mi_gdb_prompt$"
f7f9a841 1718 }
2d0720d9
VP
1719
1720 gdb_expect {
d0b76dc6 1721 -re ".*line=\"(\[0-9\]*)\".*\r\n$prompt_re" {
4392c534 1722 return $expect_out(1,string)
2d0720d9 1723 }
d0b76dc6 1724 -re ".*$mi_gdb_prompt" {
4392c534 1725 fail "wait for stop ($test)"
2d0720d9
VP
1726 }
1727 timeout {
4392c534 1728 fail "wait for stop ($test)"
2d0720d9
VP
1729 }
1730 }
1731}
1732
1733# Run a MI test embedded in comments in a C file.
1734# The C file should contain special comments in the following
1735# three forms:
1736#
1737# /*: BEGIN: testname :*/
1738# /*: <Tcl statements> :*/
1739# /*: END: testname :*/
1740#
1741# This procedure find the begin and end marker for the requested
1742# test. Then, a temporary breakpoint is set at the begin
1743# marker and the program is run (from start).
1744#
1745# After that, for each special comment between the begin and end
1746# marker, the Tcl statements are executed. It is assumed that
1747# for each comment, the immediately preceding line is executable
1748# C statement. Then, gdb will be single-stepped until that
1749# preceding C statement is executed, and after that the
1750# Tcl statements in the comment will be executed.
1751#
1752# For example:
1753#
1754# /*: BEGIN: assignment-test :*/
1755# v = 10;
1756# /*: <Tcl code to check that 'v' is indeed 10 :*/
1757# /*: END: assignment-test :*/
1758#
1759# The mi_prepare_inline_tests function should be called before
1760# calling this function. A given C file can contain several
1761# inline tests. The names of the tests must be unique within one
1762# C file.
1763#
1764proc mi_run_inline_test { testcase } {
1765
1766 global mi_gdb_prompt
1767 global hex
1768 global decimal
1769 global fullname_syntax
1770 global mi_autotest_source
1771
1772 set commands [mi_get_inline_test $testcase]
1773
1774 set first 1
1775 set line_now 1
1776
1777 foreach c $commands {
4392c534
YQ
1778 set statements [lindex $c 0]
1779 set line [lindex $c 1]
1780 set line [expr $line-1]
1781
1782 # We want gdb to be stopped at the expression immediately
1783 # before the comment. If this is the first comment, the
1784 # program is either not started yet or is in some random place,
1785 # so we run it. For further comments, we might be already
1786 # standing at the right line. If not continue till the
1787 # right line.
1788
1789 if {$first==1} {
1790 # Start the program afresh.
1791 mi_tbreak "$mi_autotest_source:$line"
1792 mi_run_cmd
1793 set line_now [mi_get_stop_line "$testcase: step to $line"]
1794 set first 0
1795 } elseif {$line_now!=$line} {
1796 set line_now [mi_continue_to_line "$mi_autotest_source:$line" "continue to $line"]
1797 }
1798
1799 if {$line_now!=$line} {
1800 fail "$testcase: go to line $line"
1801 }
1802
1803 # We're not at the statement right above the comment.
1804 # Execute that statement so that the comment can test
1805 # the state after the statement is executed.
1806
1807 # Single-step past the line.
1808 if { [mi_send_resuming_command "exec-next" "$testcase: step over $line"] != 0 } {
d0b76dc6
DJ
1809 return -1
1810 }
1811 set line_now [mi_get_stop_line "$testcase: step over $line"]
2d0720d9 1812
4392c534
YQ
1813 # We probably want to use 'uplevel' so that statements
1814 # have direct access to global variables that the
1815 # main 'exp' file has set up. But it's not yet clear,
1816 # will need more experience to be sure.
1817 eval $statements
2d0720d9
VP
1818 }
1819}
9d81d21b
VP
1820
1821proc get_mi_thread_list {name} {
1822 global expect_out
1823
1824 # MI will return a list of thread ids:
1825 #
1826 # -thread-list-ids
1827 # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
1828 # (gdb)
1829 mi_gdb_test "-thread-list-ids" \
592375cd 1830 {.*\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \
9d81d21b
VP
1831 "-thread_list_ids ($name)"
1832
1833 set output {}
1834 if {[info exists expect_out(buffer)]} {
1835 set output $expect_out(buffer)
1836 }
1837
1838 set thread_list {}
1839 if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} {
1840 fail "finding threads in MI output ($name)"
1841 } else {
1842 pass "finding threads in MI output ($name)"
1843
1844 # Make list of console threads
1845 set start [expr {[string first \{ $threads] + 1}]
1846 set end [expr {[string first \} $threads] - 1}]
1847 set threads [string range $threads $start $end]
1848 foreach thread [split $threads ,] {
1849 if {[scan $thread {thread-id="%d"} num]} {
1850 lappend thread_list $num
1851 }
1852 }
1853 }
1854
1855 return $thread_list
1856}
1857
1858# Check that MI and the console know of the same threads.
1859# Appends NAME to all test names.
1860proc check_mi_and_console_threads {name} {
1861 global expect_out
1862
1863 mi_gdb_test "-thread-list-ids" \
592375cd 1864 {.*\^done,thread-ids={(thread-id="[0-9]+"(,)*)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \
9d81d21b
VP
1865 "-thread-list-ids ($name)"
1866 set mi_output {}
1867 if {[info exists expect_out(buffer)]} {
1868 set mi_output $expect_out(buffer)
1869 }
1870
1871 # GDB will return a list of thread ids and some more info:
1872 #
1873 # (gdb)
1874 # -interpreter-exec console "info threads"
1875 # ~" 4 Thread 2051 (LWP 7734) 0x401166b1 in __libc_nanosleep () at __libc_nanosleep:-1"
1876 # ~" 3 Thread 1026 (LWP 7733) () at __libc_nanosleep:-1"
1877 # ~" 2 Thread 2049 (LWP 7732) 0x401411f8 in __poll (fds=0x804bb24, nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63"
1878 # ~"* 1 Thread 1024 (LWP 7731) main (argc=1, argv=0xbfffdd94) at ../../../src/gdb/testsuite/gdb.mi/pthreads.c:160"
1879 # FIXME: kseitz/2002-09-05: Don't use the hack-cli method.
1880 mi_gdb_test "info threads" \
1881 {.*(~".*"[\r\n]*)+.*} \
1882 "info threads ($name)"
1883 set console_output {}
1884 if {[info exists expect_out(buffer)]} {
1885 set console_output $expect_out(buffer)
1886 }
1887
1888 # Make a list of all known threads to console (gdb's thread IDs)
1889 set console_thread_list {}
1890 foreach line [split $console_output \n] {
1891 if {[string index $line 0] == "~"} {
1892 # This is a line from the console; trim off "~", " ", "*", and "\""
1893 set line [string trim $line ~\ \"\*]
1894 if {[scan $line "%d" id] == 1} {
1895 lappend console_thread_list $id
1896 }
1897 }
1898 }
1899
1900 # Now find the result string from MI
1901 set mi_result ""
1902 foreach line [split $mi_output \n] {
1903 if {[string range $line 0 4] == "^done"} {
1904 set mi_result $line
1905 }
1906 }
1907 if {$mi_result == ""} {
1908 fail "finding MI result string ($name)"
1909 } else {
1910 pass "finding MI result string ($name)"
1911 }
1912
1913 # Finally, extract the thread ids and compare them to the console
1914 set num_mi_threads_str ""
1915 if {![regexp {number-of-threads="[0-9]+"} $mi_result num_mi_threads_str]} {
1916 fail "finding number of threads in MI output ($name)"
1917 } else {
1918 pass "finding number of threads in MI output ($name)"
1919
1920 # Extract the number of threads from the MI result
1921 if {![scan $num_mi_threads_str {number-of-threads="%d"} num_mi_threads]} {
1922 fail "got number of threads from MI ($name)"
1923 } else {
1924 pass "got number of threads from MI ($name)"
1925
1926 # Check if MI and console have same number of threads
1927 if {$num_mi_threads != [llength $console_thread_list]} {
1928 fail "console and MI have same number of threads ($name)"
1929 } else {
1930 pass "console and MI have same number of threads ($name)"
1931
1932 # Get MI thread list
1933 set mi_thread_list [get_mi_thread_list $name]
1934
1935 # Check if MI and console have the same threads
1936 set fails 0
1937 foreach ct [lsort $console_thread_list] mt [lsort $mi_thread_list] {
1938 if {$ct != $mt} {
1939 incr fails
1940 }
1941 }
1942 if {$fails > 0} {
1943 fail "MI and console have same threads ($name)"
1944
1945 # Send a list of failures to the log
1946 send_log "Console has thread ids: $console_thread_list\n"
1947 send_log "MI has thread ids: $mi_thread_list\n"
1948 } else {
1949 pass "MI and console have same threads ($name)"
1950 }
1951 }
1952 }
1953 }
1954}
5e06a3d1 1955
759f0f0b 1956# Download shared libraries to the target.
5e06a3d1 1957proc mi_load_shlibs { args } {
5e06a3d1 1958 foreach file $args {
7817ea46 1959 gdb_remote_download target [shlib_target_file $file]
5e06a3d1
VP
1960 }
1961
6e774b13
SM
1962 if {[is_remote target]} {
1963 # If the target is remote, we need to tell gdb where to find the
1964 # libraries.
1965 #
1966 # We could set this even when not testing remotely, but a user
1967 # generally won't set it unless necessary. In order to make the tests
1968 # more like the real-life scenarios, we don't set it for local testing.
1969 mi_gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "\^done" ""
1970 }
5e06a3d1
VP
1971}
1972
b05b1202 1973proc mi_check_thread_states { states test } {
1ad15515 1974 global expect_out
f4e164aa 1975 set pattern ".*\\^done,threads=\\\["
1ad15515
PA
1976 foreach s $states {
1977 set pattern "${pattern}(.*)state=\"$s\""
1978 }
dc146f7c 1979 set pattern "${pattern}(,core=\"\[0-9\]*\")?\\\}\\\].*"
1ad15515
PA
1980
1981 verbose -log "expecting: $pattern"
1982 mi_gdb_test "-thread-info" $pattern $test
1983}
b6313243
TT
1984
1985# Return a list of MI features supported by this gdb.
1986proc mi_get_features {} {
1987 global expect_out mi_gdb_prompt
1988
1989 send_gdb "-list-features\n"
1990
1991 gdb_expect {
1992 -re "\\^done,features=\\\[(.*)\\\]\r\n$mi_gdb_prompt$" {
1993 regsub -all -- \" $expect_out(1,string) "" features
1994 return [split $features ,]
1995 }
1996 -re ".*\r\n$mi_gdb_prompt$" {
1997 verbose -log "got $expect_out(buffer)"
1998 return ""
1999 }
2000 timeout {
2001 verbose -log "timeout in mi_gdb_prompt"
2002 return ""
2003 }
2004 }
2005}
1eec78bd
KS
2006
2007# Variable Object Trees
2008#
2009# Yet another way to check varobjs. Pass mi_walk_varobj_tree a "list" of
2010# variables (not unlike the actual source code definition), and it will
2011# automagically test the children for you (by default).
2012#
2013# Example:
2014#
2015# source code:
2016# struct bar {
2017# union {
2018# int integer;
2019# void *ptr;
2020# };
2021# const int *iPtr;
2022# };
2023#
2024# class foo {
2025# public:
2026# int a;
2027# struct {
2028# int b;
2029# struct bar *c;
2030# };
2031# };
2032#
2033# foo *f = new foo (); <-- break here
2034#
2035# We want to check all the children of "f".
2036#
2037# Translate the above structures into the following tree:
2038#
2039# set tree {
2040# foo f {
2041# {} public {
2042# int a {}
2043# anonymous struct {
2044# {} public {
2045# int b {}
2046# {bar *} c {
2047# {} public {
2048# anonymous union {
2049# {} public {
2050# int integer {}
2051# {void *} ptr {}
2052# }
2053# }
2054# {const int *} iPtr {
2055# {const int} {*iPtr} {}
2056# }
2057# }
2058# }
2059# }
2060# }
2061# }
2062# }
2063# }
2064#
440e2fca 2065# mi_walk_varobj_tree c++ $tree
1eec78bd
KS
2066#
2067# If you'd prefer to walk the tree using your own callback,
2068# simply pass the name of the callback to mi_walk_varobj_tree.
2069#
2070# This callback should take one argument, the name of the variable
2071# to process. This name is the name of a global array holding the
2072# variable's properties (object name, type, etc).
2073#
2074# An example callback:
2075#
2076# proc my_callback {var} {
2077# upvar #0 $var varobj
2078#
2079# puts "my_callback: called on varobj $varobj(obj_name)"
2080# }
2081#
2082# The arrays created for each variable object contain the following
2083# members:
2084#
2085# obj_name - the object name for accessing this variable via MI
2086# display_name - the display name for this variable (exp="display_name" in
2087# the output of -var-list-children)
2088# type - the type of this variable (type="type" in the output
2089# of -var-list-children, or the special tag "anonymous"
2090# path_expr - the "-var-info-path-expression" for this variable
440e2fca
KS
2091# NOTE: This member cannot be used reliably with typedefs.
2092# Use with caution!
2093# See notes inside get_path_expr for more.
1eec78bd
KS
2094# parent - the variable name of the parent varobj
2095# children - a list of children variable names (which are the
2096# names Tcl arrays, not object names)
2097#
2098# For each variable object, an array containing the above fields will
2099# be created under the root node (conveniently called, "root"). For example,
2100# a variable object with handle "OBJ.public.0_anonymous.a" will have
2101# a corresponding global Tcl variable named "root.OBJ.public.0_anonymous.a".
2102#
2103# Note that right now, this mechanism cannot be used for recursive data
2104# structures like linked lists.
2105
2106namespace eval ::varobj_tree {
2107 # An index which is appended to root varobjs to ensure uniqueness.
2108 variable _root_idx 0
2109
2110 # A procedure to help with debuggging varobj trees.
2111 # VARIABLE_NAME is the name of the variable to dump.
2112 # CMD, if present, is the name of the callback to output the contstructed
2113 # strings. By default, it uses expect's "send_log" command.
2114 # TERM, if present, is a terminating character. By default it is the newline.
2115 #
2116 # To output to the terminal (not the expect log), use
2117 # mi_varobj_tree_dump_variable my_variable puts ""
2118
2119 proc mi_varobj_tree_dump_variable {variable_name {cmd send_log} {term "\n"}} {
2120 upvar #0 $variable_name varobj
2121
2122 eval "$cmd \"VAR = $variable_name$term\""
2123
2124 # Explicitly encode the array indices, since outputting them
2125 # in some logical order is better than what "array names" might
2126 # return.
2127 foreach idx {obj_name parent display_name type path_expr} {
2128 eval "$cmd \"\t$idx = $varobj($idx)$term\""
2129 }
2130
2131 # Output children
2132 set num [llength $varobj(children)]
2133 eval "$cmd \"\tnum_children = $num$term\""
2134 if {$num > 0} {
2135 eval "$cmd \"\tchildren = $varobj(children)$term\""
2136 }
2137 }
2138
2139 # The default callback used by mi_walk_varobj_tree. This callback
440e2fca
KS
2140 # simply checks all of VAR's children. It specifically does not test
2141 # path expressions, since that is very problematic.
1eec78bd
KS
2142 #
2143 # This procedure may be used in custom callbacks.
2144 proc test_children_callback {variable_name} {
2145 upvar #0 $variable_name varobj
2146
2147 if {[llength $varobj(children)] > 0} {
2148 # Construct the list of children the way mi_list_varobj_children
2149 # expects to get it:
2150 # { {obj_name display_name num_children type} ... }
2151 set children_list {}
2152 foreach child $varobj(children) {
2153 upvar #0 $child c
2154 set clist [list [string_to_regexp $c(obj_name)] \
2155 [string_to_regexp $c(display_name)] \
2156 [llength $c(children)]]
2157 if {[string length $c(type)] > 0} {
2158 lappend clist [string_to_regexp $c(type)]
2159 }
2160 lappend children_list $clist
2161 }
2162
2163 mi_list_varobj_children $varobj(obj_name) $children_list \
2164 "VT: list children of $varobj(obj_name)"
2165 }
2166 }
2167
2168 # Set the properties of the varobj represented by
2169 # PARENT_VARIABLE - the name of the parent's variable
2170 # OBJNAME - the MI object name of this variable
2171 # DISP_NAME - the display name of this variable
2172 # TYPE - the type of this variable
2173 # PATH - the path expression for this variable
2174 # CHILDREN - a list of the variable's children
2175 proc create_varobj {parent_variable objname disp_name \
2176 type path children} {
2177 upvar #0 $parent_variable parent
2178
2179 set var_name "root.$objname"
2180 global $var_name
2181 array set $var_name [list obj_name $objname]
2182 array set $var_name [list display_name $disp_name]
2183 array set $var_name [list type $type]
2184 array set $var_name [list path_expr $path]
2185 array set $var_name [list parent "$parent_variable"]
2186 array set $var_name [list children \
2187 [get_tree_children $var_name $children]]
2188 return $var_name
2189 }
2190
2191 # Should VARIABLE be used in path expressions? The CPLUS_FAKE_CHILD
2192 # varobjs and anonymous structs/unions are not used for path expressions.
2193 proc is_path_expr_parent {variable} {
2194 upvar #0 $variable varobj
2195
2196 # If the varobj's type is "", it is a CPLUS_FAKE_CHILD.
2197 # If the tail of the varobj's object name is "%d_anonymous",
2198 # then it represents an anonymous struct or union.
2199 if {[string length $varobj(type)] == 0 \
2200 || [regexp {[0-9]+_anonymous$} $varobj(obj_name)]} {
2201 return false
2202 }
2203
2204 return true
2205 }
2206
2207 # Return the path expression for the variable named NAME in
2208 # parent varobj whose variable name is given by PARENT_VARIABLE.
2209 proc get_path_expr {parent_variable name type} {
2210 upvar #0 $parent_variable parent
440e2fca 2211 upvar #0 $parent_variable path_parent
1eec78bd
KS
2212
2213 # If TYPE is "", this is one of the CPLUS_FAKE_CHILD varobjs,
440e2fca
KS
2214 # which has no path expression. Likewsise for anonymous structs
2215 # and unions.
2216 if {[string length $type] == 0 \
2217 || [string compare $type "anonymous"] == 0} {
1eec78bd
KS
2218 return ""
2219 }
2220
2221 # Find the path parent variable.
2222 while {![is_path_expr_parent $parent_variable]} {
440e2fca
KS
2223 set parent_variable $path_parent(parent)
2224 upvar #0 $parent_variable path_parent
2225 }
2226
2227 # This is where things get difficult. We do not actually know
2228 # the real type for variables defined via typedefs, so we don't actually
2229 # know whether the parent is a structure/union or not.
2230 #
2231 # So we assume everything that isn't a simple type is a compound type.
2232 set stars ""
2233 regexp {\*+} $parent(type) stars
2234 set is_compound 1
2235 if {[string index $name 0] == "*"} {
2236 set is_compound 0
2237 }
2238
2239 if {[string index $parent(type) end] == "\]"} {
2240 # Parent is an array.
2241 return "($path_parent(path_expr))\[$name\]"
2242 } elseif {$is_compound} {
2243 # Parent is a structure or union or a pointer to one.
2244 if {[string length $stars]} {
2245 set join "->"
2246 } else {
2247 set join "."
2248 }
2249
2250 global root
1eec78bd 2251
440e2fca
KS
2252 # To make matters even more hideous, varobj.c has slightly different
2253 # path expressions for C and C++.
2254 set path_expr "($path_parent(path_expr))$join$name"
2255 if {[string compare -nocase $root(language) "c"] == 0} {
2256 return $path_expr
2257 } else {
2258 return "($path_expr)"
2259 }
2260 } else {
2261 # Parent is a pointer.
2262 return "*($path_parent(path_expr))"
2263 }
1eec78bd
KS
2264 }
2265
2266 # Process the CHILDREN (a list of varobj_tree elements) of the variable
2267 # given by PARENT_VARIABLE. Returns a list of children variables.
2268 proc get_tree_children {parent_variable children} {
2269 upvar #0 $parent_variable parent
2270
2271 set field_idx 0
2272 set children_list {}
2273 foreach {type name children} $children {
2274 if {[string compare $parent_variable "root"] == 0} {
2275 # Root variable
2276 variable _root_idx
2277 incr _root_idx
2278 set objname "$name$_root_idx"
2279 set disp_name "$name"
2280 set path_expr "$name"
2281 } elseif {[string compare $type "anonymous"] == 0} {
2282 # Special case: anonymous types. In this case, NAME will either be
2283 # "struct" or "union".
2284 set objname "$parent(obj_name).${field_idx}_anonymous"
2285 set disp_name "<anonymous $name>"
2286 set path_expr ""
2287 set type "$name {...}"
2288 } else {
2289 set objname "$parent(obj_name).$name"
2290 set disp_name $name
2291 set path_expr [get_path_expr $parent_variable $name $type]
2292 }
2293
2294 lappend children_list [create_varobj $parent_variable $objname \
2295 $disp_name $type $path_expr $children]
2296 incr field_idx
2297 }
2298
2299 return $children_list
2300 }
2301
2302 # The main procedure to call the given CALLBACK on the elements of the
2303 # given varobj TREE. See detailed explanation above.
440e2fca 2304 proc walk_tree {language tree callback} {
1eec78bd 2305 global root
f44eeb11 2306 variable _root_idx
1eec78bd
KS
2307
2308 if {[llength $tree] < 3} {
2309 error "tree does not contain enough elements"
2310 }
2311
f44eeb11
TT
2312 set _root_idx 0
2313
1eec78bd 2314 # Create root node and process the tree.
440e2fca 2315 array set root [list language $language]
1eec78bd
KS
2316 array set root [list obj_name "root"]
2317 array set root [list display_name "root"]
2318 array set root [list type "root"]
2319 array set root [list path_expr "root"]
2320 array set root [list parent "root"]
2321 array set root [list children [get_tree_children root $tree]]
2322
2323 # Walk the tree
2324 set all_nodes $root(children); # a stack of nodes
2325 while {[llength $all_nodes] > 0} {
2326 # "Pop" the name of the global variable containing this varobj's
2327 # information from the stack of nodes.
2328 set var_name [lindex $all_nodes 0]
2329 set all_nodes [lreplace $all_nodes 0 0]
2330
2331 # Bring the global named in VAR_NAME into scope as the local variable
2332 # VAROBJ.
2333 upvar #0 $var_name varobj
2334
2335 # Append any children of VAROBJ to the list of nodes to walk.
2336 if {[llength $varobj(children)] > 0} {
2337 set all_nodes [concat $all_nodes $varobj(children)]
2338 }
2339
2340 # If this is a root variable, create the variable object for it.
2341 if {[string compare $varobj(parent) "root"] == 0} {
2342 mi_create_varobj $varobj(obj_name) $varobj(display_name) \
2343 "VT: create root varobj for $varobj(display_name)"
2344 }
2345
2346 # Now call the callback for VAROBJ.
2347 uplevel #0 $callback $var_name
2348 }
2349 }
2350}
2351
2352# The default varobj tree callback, which simply tests -var-list-children.
2353proc mi_varobj_tree_test_children_callback {variable} {
2354 ::varobj_tree::test_children_callback $variable
2355}
2356
2357# Walk the variable object tree given by TREE, calling the specified
2358# CALLBACK. By default this uses mi_varobj_tree_test_children_callback.
440e2fca
KS
2359proc mi_walk_varobj_tree {language tree \
2360 {callback \
2361 mi_varobj_tree_test_children_callback}} {
2362 ::varobj_tree::walk_tree $language $tree $callback
1eec78bd 2363}
4b48d439
KS
2364
2365# Build a list of key-value pairs given by the list ATTR_LIST. Flatten
2366# this list using the optional JOINER, a comma by default.
2367#
2368# The list must contain an even number of elements, which are the key-value
2369# pairs. Each value will be surrounded by quotes, according to the grammar,
2370# except if the value starts with \[ or \{, when the quotes will be omitted.
2371#
2372# Example: mi_build_kv_pairs {a b c d e f g \[.*\]}
2373# returns a=\"b\",c=\"d\",e=\"f\",g=\[.*\]
2374proc mi_build_kv_pairs {attr_list {joiner ,}} {
2375 set l {}
2376 foreach {var value} $attr_list {
2377 if {[string range $value 0 1] == "\\\["
2378 || [string range $value 0 1] == "\\\{"} {
2379 lappend l "$var=$value"
2380 } else {
2381 lappend l "$var=\"$value\""
2382 }
2383 }
2384 return "[join $l $joiner]"
2385}
2386
2387# Construct a breakpoint regexp. This may be used to test the output of
2388# -break-insert, -dprintf-insert, or -break-info.
2389#
2390# All arguments for the breakpoint may be specified using the options
2391# number, type, disp, enabled, addr, func, file, fullanme, line,
6613eb10
KS
2392# thread-groups, cond, evaluated-by, times, ignore, script,
2393# and original-location.
4b48d439
KS
2394#
2395# Only if -script and -ignore are given will they appear in the output.
2396# Otherwise, this procedure will skip them using ".*".
2397#
2398# Example: mi_make_breakpoint -number 2 -file ".*/myfile.c" -line 3
2399# will return the breakpoint:
2400# bkpt={number="2",type=".*",disp=".*",enabled=".*",addr=".*",func=".*",
2401# file=".*/myfile.c",fullname=".*",line="3",thread-groups=\[.*\],
2402# times="0".*original-location=".*"}
2403
2404proc mi_make_breakpoint {args} {
2405 parse_args {{number .*} {type .*} {disp .*} {enabled .*} {addr .*}
2406 {func .*} {file .*} {fullname .*} {line .*}
2407 {thread-groups \\\[.*\\\]} {times .*} {ignore 0}
6613eb10 2408 {script ""} {original-location .*} {cond ""} {evaluated-by ""}}
4b48d439
KS
2409
2410 set attr_list {}
2411 foreach attr [list number type disp enabled addr func file \
eb8c4e2e 2412 fullname line thread-groups] {
4b48d439
KS
2413 lappend attr_list $attr [set $attr]
2414 }
2415
2416 set result "bkpt={[mi_build_kv_pairs $attr_list]"
2417
2418 # There are always exceptions.
eb8c4e2e
KS
2419
2420 # If COND is not preset, do not output it.
2421 if {[string length $cond] > 0} {
2422 append result ","
2423 append result [mi_build_kv_pairs [list "cond" $cond]]
6613eb10
KS
2424
2425 # When running on a remote, GDB may output who is evaluating
2426 # breakpoint conditions.
2427 if {[string length ${evaluated-by}] > 0} {
2428 append result [mi_build_kv_pairs \
2429 [list "evaluated-by" ${evaluated-by}]]
2430 } else {
2431 append result {(,evaluated-by=".*")?}
2432 }
eb8c4e2e
KS
2433 }
2434
2435 append result ","
2436 append result [mi_build_kv_pairs [list "times" $times]]
2437
4b48d439
KS
2438 # If SCRIPT and IGNORE are not present, do not output them.
2439 if {$ignore != 0} {
2440 append result ","
2441 append result [mi_build_kv_pairs [list "ignore" $ignore]]
2442 append result ","
2443 }
2444 if {[string length $script] > 0} {
2445 append result ","
2446 append result [mi_build_kv_pairs [list "script" $script]]
2447 append result ","
2448 } else {
2449 # Allow anything up until the next "official"/required attribute.
2450 # This pattern skips over script/ignore if matches on those
2451 # were not specifically required by the caller.
2452 append result ".*"
2453 }
2454 append result [mi_build_kv_pairs \
2455 [list "original-location" ${original-location}]]
2456 append result "}"
2457 return $result
2458}
2459
2460# Build a breakpoint table regexp given the list of breakpoints in `bp_list',
2461# constructed by mi_make_breakpoint.
2462#
2463# Example: Construct a breakpoint table where the only attributes we
2464# test for are the existence of three breakpoints numbered 1, 2, and 3.
2465#
2466# set bps {}
2467# lappend bps [mi_make_breakpoint -number 1]
2468# lappend bps [mi_make_breakpoint -number 2]
2469# lappned bps [mi_make_breakpoint -number 3]
2470# mi_make_breakpoint_table $bps
2471# will return (abbreviated for clarity):
2472# BreakpointTable={nr_rows="3",nr_cols="6",hdr=[{width=".*",...} ...],
2473# body=[bkpt={number="1",...},bkpt={number="2",...},bkpt={number="3",...}]}
2474
2475proc mi_make_breakpoint_table {bp_list} {
2476 # Build header -- assume a standard header for all breakpoint tables.
2477 set hl {}
2478 foreach {nm hdr} [list number Num type Type disp Disp enabled Enb \
2479 addr Address what What] {
2480 # The elements here are the MI table headers, which have the
2481 # format:
2482 # {width="7",alignment="-1",col_name="number",colhdr="Num"}
2483 lappend hl "{[mi_build_kv_pairs [list width .* alignment .* \
2484 col_name $nm colhdr $hdr]]}"
2485 }
2486 set header "hdr=\\\[[join $hl ,]\\\]"
2487
2488 # The caller has implicitly supplied the number of columns and rows.
2489 set nc [llength $hl]
2490 set nr [llength $bp_list]
2491
2492 # Build body -- mi_make_breakpoint has done most of the work.
2493 set body "body=\\\[[join $bp_list ,]\\\]"
2494
2495 # Assemble the final regexp.
2496 return "BreakpointTable={nr_rows=\"$nr\",nr_cols=\"$nc\",$header,$body}"
2497}
4d6cceb4
DE
2498
2499# Return a 1 for configurations that do not support Python scripting.
2500# Note: This also sets various globals that specify which version of Python
2501# is in use. See skip_python_tests_prompt.
2502
2503proc mi_skip_python_tests {} {
2504 global mi_gdb_prompt
2505 return [skip_python_tests_prompt "$mi_gdb_prompt$"]
2506}
f015c27b
PA
2507
2508# Check whether we're testing with the remote or extended-remote
2509# targets.
2510
2511proc mi_is_target_remote {} {
2512 global mi_gdb_prompt
2513
2514 return [gdb_is_target_remote_prompt "$mi_gdb_prompt"]
2515}
This page took 1.770138 seconds and 4 git commands to generate.