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