gdb.dwarf2: Define and use gdb_target_symbol for symbol prefixes
[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_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"
56a8e183 889 return 0
fb40c209
AC
890 }
891
2f25d70f 892 send_gdb "${run_prefix}run $args\n"
fb40c209 893 gdb_expect {
36dfb11c 894 -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 895 }
56a8e183
PA
896 -re "\\^error,msg=\"The target does not support running in non-stop mode.\"" {
897 unsupported "Non-stop mode not supported"
898 return -1
899 }
fb40c209
AC
900 timeout {
901 perror "Unable to start target"
56a8e183 902 return -1
fb40c209
AC
903 }
904 }
2d0720d9 905 # NOTE: Shortly after this there will be a ``000*stopped,...(gdb)''
56a8e183
PA
906
907 return 0
fb40c209
AC
908}
909
36dfb11c
TT
910# A wrapper for mi_run_cmd_full which uses -exec-run and
911# -exec-continue, as appropriate. ARGS are passed verbatim to
912# mi_run_cmd_full.
913proc mi_run_cmd {args} {
914 return [eval mi_run_cmd_full 1 $args]
915}
916
917# A wrapper for mi_run_cmd_full which uses the CLI commands 'run' and
918# 'continue', as appropriate. ARGS are passed verbatim to
919# mi_run_cmd_full.
920proc mi_run_with_cli {args} {
921 return [eval mi_run_cmd_full 0 $args]
922}
923
fb40c209
AC
924#
925# Just like run-to-main but works with the MI interface
926#
927
928proc mi_run_to_main { } {
929 global suppress_flag
930 if { $suppress_flag } {
931 return -1
932 }
933
fb40c209
AC
934 global srcdir
935 global subdir
936 global binfile
937 global srcfile
938
fb40c209
AC
939 mi_delete_breakpoints
940 mi_gdb_reinitialize_dir $srcdir/$subdir
941 mi_gdb_load ${binfile}
942
08b468e0
KS
943 mi_runto main
944}
fb40c209 945
08b468e0
KS
946
947# Just like gdb's "runto" proc, it will run the target to a given
948# function. The big difference here between mi_runto and mi_execute_to
949# is that mi_execute_to must have the inferior running already. This
950# proc will (like gdb's runto) (re)start the inferior, too.
951#
952# FUNC is the linespec of the place to stop (it inserts a breakpoint here).
953# It returns:
954# -1 if test suppressed, failed, timedout
955# 0 if test passed
956
f7e97bb3 957proc mi_runto_helper {func run_or_continue} {
08b468e0
KS
958 global suppress_flag
959 if { $suppress_flag } {
960 return -1
961 }
962
963 global mi_gdb_prompt expect_out
76ff342d 964 global hex decimal fullname_syntax
08b468e0
KS
965
966 set test "mi runto $func"
4b48d439
KS
967 set bp [mi_make_breakpoint -type breakpoint -disp del \
968 -func $func\(\\\(.*\\\)\)?]
969 mi_gdb_test "200-break-insert -t $func" "200\\^done,$bp" \
970 "breakpoint at $func"
08b468e0 971
f7e97bb3 972 if {$run_or_continue == "run"} {
56a8e183
PA
973 if { [mi_run_cmd] < 0 } {
974 return -1
975 }
f7e97bb3 976 } else {
bb378428 977 mi_send_resuming_command "exec-continue" "$test"
f7e97bb3 978 }
74a44383 979
18ac113b 980 mi_expect_stop "breakpoint-hit" $func ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } $test
fb40c209
AC
981}
982
f7e97bb3 983proc mi_runto {func} {
56a8e183 984 return [mi_runto_helper $func "run"]
f7e97bb3 985}
fb40c209
AC
986
987# Next to the next statement
08b468e0 988# For return values, see mi_execute_to_helper
fb40c209
AC
989
990proc mi_next { test } {
dc360f58 991 return [mi_next_to {.*} {.*} {.*} {.*} $test]
fb40c209
AC
992}
993
994
995# Step to the next statement
08b468e0 996# For return values, see mi_execute_to_helper
fb40c209
AC
997
998proc mi_step { test } {
dc360f58 999 return [mi_step_to {.*} {.*} {.*} {.*} $test]
fb40c209 1000}
dcf95b47 1001
f7f9a841
VP
1002set async "unknown"
1003
fcdfa280 1004proc mi_detect_async {} {
f7f9a841
VP
1005 global async
1006 global mi_gdb_prompt
1007
329ea579 1008 send_gdb "show mi-async\n"
4392c534 1009
a2840c35 1010 gdb_expect {
329ea579 1011 -re "asynchronous mode is on...*$mi_gdb_prompt$" {
4392c534
YQ
1012 set async 1
1013 }
1014 -re ".*$mi_gdb_prompt$" {
1015 set async 0
1016 }
1017 timeout {
1018 set async 0
1019 }
f7f9a841
VP
1020 }
1021 return $async
1022}
1023
bb378428
VP
1024# Wait for MI *stopped notification to appear.
1025# The REASON, FUNC, ARGS, FILE and LINE are regular expressions
05acf274
JK
1026# to match against whatever is output in *stopped. FILE may also match
1027# filename of a file without debug info. ARGS should not include [] the
1028# list of argument is enclosed in, and other regular expressions should
1029# not include quotes.
bb378428
VP
1030# If EXTRA is a list of one element, it's the regular expression
1031# for output expected right after *stopped, and before GDB prompt.
1032# If EXTRA is a list of two elements, the first element is for
1033# output right after *stopped, and the second element is output
1034# right after reason field. The regex after reason should not include
1035# the comma separating it from the following fields.
4392c534 1036#
05acf274
JK
1037# When we fail to match output at all, -1 is returned. If FILE does
1038# match and the target system has no debug info for FILE return 0.
1039# Otherwise, the line at which we stop is returned. This is useful when
1040# exact line is not possible to specify for some reason -- one can pass
d0b76dc6
DJ
1041# the .* or "\[0-9\]*" regexps for line, and then check the line
1042# programmatically.
1043#
1044# Do not pass .* for any argument if you are expecting more than one stop.
bb378428 1045proc mi_expect_stop { reason func args file line extra test } {
1902c51f 1046
dcf95b47
DJ
1047 global mi_gdb_prompt
1048 global hex
1049 global decimal
76ff342d 1050 global fullname_syntax
f7f9a841 1051 global async
66bb093b 1052 global thread_selected_re
8d3788bd 1053 global breakpoint_re
bb378428 1054
0c7e1a46
PA
1055 set any "\[^\n\]*"
1056
bb378428
VP
1057 set after_stopped ""
1058 set after_reason ""
1059 if { [llength $extra] == 2 } {
4392c534
YQ
1060 set after_stopped [lindex $extra 0]
1061 set after_reason [lindex $extra 1]
1062 set after_reason "${after_reason},"
bb378428 1063 } elseif { [llength $extra] == 1 } {
4392c534 1064 set after_stopped [lindex $extra 0]
bb378428
VP
1065 }
1066
f7f9a841 1067 if {$async} {
4392c534 1068 set prompt_re ""
f7f9a841 1069 } else {
4392c534 1070 set prompt_re "$mi_gdb_prompt$"
f7f9a841
VP
1071 }
1072
1073 if { $reason == "really-no-reason" } {
4392c534
YQ
1074 gdb_expect {
1075 -re "\\*stopped\r\n$prompt_re" {
1076 pass "$test"
1077 }
1078 timeout {
73eb7709 1079 fail "$test (timeout)"
4392c534
YQ
1080 }
1081 }
1082 return
1083 }
1084
bb378428
VP
1085 if { $reason == "exited-normally" } {
1086
4392c534
YQ
1087 gdb_expect {
1088 -re "\\*stopped,reason=\"exited-normally\"\r\n$prompt_re" {
1089 pass "$test"
1090 }
1091 -re ".*$mi_gdb_prompt$" {fail "continue to end (2)"}
1092 timeout {
73eb7709 1093 fail "$test (timeout)"
4392c534
YQ
1094 }
1095 }
1096 return
bb378428 1097 }
3deb39c6
SM
1098 if { $reason == "exited" } {
1099 gdb_expect {
1100 -re "\\*stopped,reason=\"exited\",exit-code=\"\[0-7\]+\"\r\n$prompt_re" {
1101 pass "$test"
1102 }
1103 -re ".*$mi_gdb_prompt$" {
1104 fail "$test (inferior not stopped)"
1105 }
1106 timeout {
73eb7709 1107 fail "$test (timeout)"
3deb39c6
SM
1108 }
1109 }
1110 return
1111 }
bb378428 1112
0c7e1a46
PA
1113 if { $reason == "solib-event" } {
1114 set pattern "\\*stopped,reason=\"solib-event\",thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re"
1115 verbose -log "mi_expect_stop: expecting: $pattern"
1116 gdb_expect {
1117 -re "$pattern" {
1118 pass "$test"
1119 }
1120 timeout {
73eb7709 1121 fail "$test (timeout)"
0c7e1a46
PA
1122 }
1123 }
1124 return
1125 }
1126
bb378428
VP
1127 set args "\\\[$args\\\]"
1128
1129 set bn ""
1130 if { $reason == "breakpoint-hit" } {
4392c534 1131 set bn {bkptno="[0-9]+",}
edcc5120
TT
1132 } elseif { $reason == "solib-event" } {
1133 set bn ".*"
bb378428
VP
1134 }
1135
1136 set r ""
1137 if { $reason != "" } {
4392c534 1138 set r "reason=\"$reason\","
bb378428
VP
1139 }
1140
18ac113b
AR
1141
1142 set a $after_reason
1143
05acf274 1144 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 1145 gdb_expect {
05acf274 1146 -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 1147 pass "$test"
05acf274
JK
1148 if {[array names expect_out "2,string"] != ""} {
1149 return $expect_out(2,string)
1150 }
1151 # No debug info available but $file does match.
1152 return 0
dcf95b47 1153 }
c7b1f0d9 1154 -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 1155 verbose -log "got $expect_out(buffer)"
dcf95b47
DJ
1156 fail "$test (stopped at wrong place)"
1157 return -1
1158 }
f7f9a841 1159 -re ".*\r\n$mi_gdb_prompt$" {
4392c534 1160 verbose -log "got $expect_out(buffer)"
dcf95b47
DJ
1161 fail "$test (unknown output after running)"
1162 return -1
1163 }
dcf95b47
DJ
1164 timeout {
1165 fail "$test (timeout)"
1166 return -1
1167 }
4392c534 1168 }
dcf95b47
DJ
1169}
1170
1ad15515
PA
1171# Wait for MI *stopped notification related to an interrupt request to
1172# appear.
1173proc mi_expect_interrupt { test } {
1174 global mi_gdb_prompt
1175 global decimal
1176 global async
1177
1178 if {$async} {
1179 set prompt_re ""
1180 } else {
1181 set prompt_re "$mi_gdb_prompt$"
1182 }
1183
a8d9763a
SM
1184 set r_nonstop "reason=\"signal-received\",signal-name=\"0\",signal-meaning=\"Signal 0\""
1185 set r_allstop "reason=\"signal-received\",signal-name=\"SIGINT\",signal-meaning=\"Interrupt\""
1186 set r "(${r_nonstop}|${r_allstop})"
1ad15515
PA
1187 set any "\[^\n\]*"
1188
1189 # A signal can land anywhere, just ignore the location
1d33d6ba 1190 verbose -log "mi_expect_interrupt: expecting: \\*stopped,${r}$any\r\n$prompt_re"
1ad15515 1191 gdb_expect {
1d33d6ba 1192 -re "\\*stopped,${r}$any\r\n$prompt_re" {
1ad15515 1193 pass "$test"
ae59b1da 1194 return 0
1ad15515
PA
1195 }
1196 -re ".*\r\n$mi_gdb_prompt$" {
1197 verbose -log "got $expect_out(buffer)"
1198 fail "$test (unknown output after running)"
1199 return -1
1200 }
1201 timeout {
1202 fail "$test (timeout)"
1203 return -1
1204 }
1205 }
1206}
1207
bb378428
VP
1208# cmd should not include the number or newline (i.e. "exec-step 3", not
1209# "220-exec-step 3\n"
1210
1211# Can not match -re ".*\r\n${mi_gdb_prompt}", because of false positives
1212# after the first prompt is printed.
1213
08b468e0 1214proc mi_execute_to { cmd reason func args file line extra test } {
bb378428
VP
1215 global suppress_flag
1216 if { $suppress_flag } {
1217 return -1
1218 }
1219
1220 mi_send_resuming_command "$cmd" "$test"
1221 set r [mi_expect_stop $reason $func $args $file $line $extra $test]
1222 return $r
dcf95b47
DJ
1223}
1224
1225proc mi_next_to { func args file line test } {
08b468e0 1226 mi_execute_to "exec-next" "end-stepping-range" "$func" "$args" \
dcf95b47
DJ
1227 "$file" "$line" "" "$test"
1228}
1229
1230proc mi_step_to { func args file line test } {
08b468e0 1231 mi_execute_to "exec-step" "end-stepping-range" "$func" "$args" \
dcf95b47
DJ
1232 "$file" "$line" "" "$test"
1233}
1234
1235proc mi_finish_to { func args file line result ret test } {
08b468e0 1236 mi_execute_to "exec-finish" "function-finished" "$func" "$args" \
dcf95b47
DJ
1237 "$file" "$line" \
1238 ",gdb-result-var=\"$result\",return-value=\"$ret\"" \
1239 "$test"
1240}
1241
f7e97bb3
VP
1242proc mi_continue_to {func} {
1243 mi_runto_helper $func "continue"
dcf95b47
DJ
1244}
1245
08b468e0
KS
1246proc mi0_execute_to { cmd reason func args file line extra test } {
1247 mi_execute_to_helper "$cmd" "$reason" "$func" "\{$args\}" \
dcf95b47
DJ
1248 "$file" "$line" "$extra" "$test"
1249}
1250
1251proc mi0_next_to { func args file line test } {
08b468e0 1252 mi0_execute_to "exec-next" "end-stepping-range" "$func" "$args" \
dcf95b47
DJ
1253 "$file" "$line" "" "$test"
1254}
1255
1256proc mi0_step_to { func args file line test } {
08b468e0 1257 mi0_execute_to "exec-step" "end-stepping-range" "$func" "$args" \
dcf95b47
DJ
1258 "$file" "$line" "" "$test"
1259}
1260
1261proc mi0_finish_to { func args file line result ret test } {
08b468e0 1262 mi0_execute_to "exec-finish" "function-finished" "$func" "$args" \
dcf95b47
DJ
1263 "$file" "$line" \
1264 ",gdb-result-var=\"$result\",return-value=\"$ret\"" \
1265 "$test"
1266}
1267
1268proc mi0_continue_to { bkptno func args file line test } {
08b468e0 1269 mi0_execute_to "exec-continue" "breakpoint-hit\",bkptno=\"$bkptno" \
dcf95b47
DJ
1270 "$func" "$args" "$file" "$line" "" "$test"
1271}
b26ed50d 1272
4b48d439
KS
1273# Creates a breakpoint and checks the reported fields are as expected.
1274# This procedure takes the same options as mi_make_breakpoint and
1275# returns the breakpoint regexp from that procedure.
d24317b4 1276
4b48d439
KS
1277proc mi_create_breakpoint {location test args} {
1278 set bp [eval mi_make_breakpoint $args]
1279 mi_gdb_test "222-break-insert $location" "222\\^done,$bp" $test
1280 return $bp
d24317b4
VP
1281}
1282
b26ed50d
VP
1283# Creates varobj named NAME for EXPRESSION.
1284# Name cannot be "-".
1285proc mi_create_varobj { name expression testname } {
1286 mi_gdb_test "-var-create $name * $expression" \
4392c534
YQ
1287 "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=.*,has_more=\"0\"" \
1288 $testname
b26ed50d
VP
1289}
1290
fcacd99f
VP
1291proc mi_create_floating_varobj { name expression testname } {
1292 mi_gdb_test "-var-create $name @ $expression" \
4392c534
YQ
1293 "\\^done,name=\"$name\",numchild=\"\(-1\|\[0-9\]+\)\",value=\".*\",type=.*" \
1294 $testname
fcacd99f
VP
1295}
1296
1297
9e8e3afe
VP
1298# Same as mi_create_varobj, but also checks the reported type
1299# of the varobj.
1300proc mi_create_varobj_checked { name expression type testname } {
1301 mi_gdb_test "-var-create $name * $expression" \
4392c534
YQ
1302 "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=\"$type\".*" \
1303 $testname
9e8e3afe
VP
1304}
1305
0cc7d26f
TT
1306# Same as mi_create_floating_varobj, but assumes the test is creating
1307# a dynamic varobj that has children, so the value must be "{...}".
0a1e6121
YQ
1308# The "has_more" attribute is checked.
1309proc mi_create_dynamic_varobj {name expression has_more testname} {
0cc7d26f 1310 mi_gdb_test "-var-create $name @ $expression" \
0a1e6121 1311 "\\^done,name=\"$name\",numchild=\"0\",value=\"{\\.\\.\\.}\",type=.*,has_more=\"${has_more}\"" \
4392c534 1312 $testname
0cc7d26f
TT
1313}
1314
4392c534 1315# Deletes the specified NAME.
6e2a9270
VP
1316proc mi_delete_varobj { name testname } {
1317 mi_gdb_test "-var-delete $name" \
4392c534
YQ
1318 "\\^done,ndeleted=.*" \
1319 $testname
6e2a9270
VP
1320}
1321
b26ed50d
VP
1322# Updates varobj named NAME and checks that all varobjs in EXPECTED
1323# are reported as updated, and no other varobj is updated.
1324# Assumes that no varobj is out of scope and that no varobj changes
1325# types.
1326proc mi_varobj_update { name expected testname } {
1327 set er "\\^done,changelist=\\\["
1328 set first 1
1329 foreach item $expected {
4392c534
YQ
1330 set v "{name=\"$item\",in_scope=\"true\",type_changed=\"false\",has_more=\".\"}"
1331 if {$first == 1} {
1332 set er "$er$v"
1333 set first 0
1334 } else {
1335 set er "$er,$v"
1336 }
b26ed50d
VP
1337 }
1338 set er "$er\\\]"
1339
1340 verbose -log "Expecting: $er" 2
1341 mi_gdb_test "-var-update $name" $er $testname
1342}
1343
8264ba82
AG
1344proc mi_varobj_update_with_child_type_change { name child_name new_type new_children testname } {
1345 set v "{name=\"$child_name\",in_scope=\"true\",type_changed=\"true\",new_type=\"$new_type\",new_num_children=\"$new_children\",has_more=\".\"}"
fcacd99f
VP
1346 set er "\\^done,changelist=\\\[$v\\\]"
1347 verbose -log "Expecting: $er"
1348 mi_gdb_test "-var-update $name" $er $testname
1349}
1350
8264ba82
AG
1351proc mi_varobj_update_with_type_change { name new_type new_children testname } {
1352 mi_varobj_update_with_child_type_change $name $name $new_type $new_children $testname
1353}
1354
0cc7d26f
TT
1355# A helper that turns a key/value list into a regular expression
1356# matching some MI output.
1357proc mi_varobj_update_kv_helper {list} {
1358 set first 1
1359 set rx ""
1360 foreach {key value} $list {
1361 if {!$first} {
1362 append rx ,
1363 }
1364 set first 0
1365 if {$key == "new_children"} {
1366 append rx "$key=\\\[$value\\\]"
1367 } else {
1368 append rx "$key=\"$value\""
1369 }
1370 }
1371 return $rx
1372}
b6313243 1373
0cc7d26f
TT
1374# A helper for mi_varobj_update_dynamic that computes a match
1375# expression given a child list.
1376proc mi_varobj_update_dynamic_helper {children} {
1377 set crx ""
b6313243 1378
0cc7d26f
TT
1379 set first 1
1380 foreach child $children {
1381 if {!$first} {
1382 append crx ,
1383 }
1384 set first 0
1385 append crx "{"
1386 append crx [mi_varobj_update_kv_helper $child]
1387 append crx "}"
1388 }
1389
1390 return $crx
1391}
1392
1393# Update a dynamic varobj named NAME. CHILDREN is a list of children
1394# that have been updated; NEW_CHILDREN is a list of children that were
1395# added to the primary varobj. Each child is a list of key/value
1396# pairs that are expected. SELF is a key/value list holding
1397# information about the varobj itself. TESTNAME is the name of the
1398# test.
1399proc mi_varobj_update_dynamic {name testname self children new_children} {
1400 if {[llength $new_children]} {
1401 set newrx [mi_varobj_update_dynamic_helper $new_children]
1402 lappend self new_children $newrx
1403 }
1404 set selfrx [mi_varobj_update_kv_helper $self]
1405 set crx [mi_varobj_update_dynamic_helper $children]
1406
1407 set er "\\^done,changelist=\\\[\{name=\"$name\",in_scope=\"true\""
1408 append er ",$selfrx\}"
1409 if {"$crx" != ""} {
1410 append er ",$crx"
1411 }
1412 append er "\\\]"
b6313243
TT
1413
1414 verbose -log "Expecting: $er"
1415 mi_gdb_test "-var-update $name" $er $testname
1416}
1417
b26ed50d
VP
1418proc mi_check_varobj_value { name value testname } {
1419
1420 mi_gdb_test "-var-evaluate-expression $name" \
1421 "\\^done,value=\"$value\"" \
1422 $testname
1423}
038224f6 1424
b6313243
TT
1425# Helper proc which constructs a child regexp for
1426# mi_list_varobj_children and mi_varobj_update_dynamic.
1427proc mi_child_regexp {children add_child} {
1428 set children_exp {}
b6313243
TT
1429
1430 if {$add_child} {
1431 set pre "child="
1432 } else {
1433 set pre ""
1434 }
1435
1436 foreach item $children {
1437
4392c534
YQ
1438 set name [lindex $item 0]
1439 set exp [lindex $item 1]
1440 set numchild [lindex $item 2]
1441 if {[llength $item] == 5} {
1442 set type [lindex $item 3]
1443 set value [lindex $item 4]
1444
1445 lappend children_exp\
31b4ab9e 1446 "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",value=\"$value\",type=\"$type\"(,thread-id=\"\[0-9\]+\")?}"
4392c534
YQ
1447 } elseif {[llength $item] == 4} {
1448 set type [lindex $item 3]
1449
1450 lappend children_exp\
31b4ab9e 1451 "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",type=\"$type\"(,thread-id=\"\[0-9\]+\")?}"
4392c534
YQ
1452 } else {
1453 lappend children_exp\
1454 "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\"(,thread-id=\"\[0-9\]+\")?}"
1455 }
b6313243
TT
1456 }
1457 return [join $children_exp ","]
1458}
1459
038224f6
VP
1460# Check the results of the:
1461#
1462# -var-list-children VARNAME
1463#
1464# command. The CHILDREN parement should be a list of lists.
1465# Each inner list can have either 3 or 4 elements, describing
1466# fields that gdb is expected to report for child variable object,
1467# in the following order
1468#
1469# - Name
1470# - Expression
1471# - Number of children
1472# - Type
1473#
1474# If inner list has 3 elements, the gdb is expected to output no
9e8e3afe
VP
1475# type for a child and no value.
1476#
1477# If the inner list has 4 elements, gdb output is expected to
1478# have no value.
038224f6
VP
1479#
1480proc mi_list_varobj_children { varname children testname } {
0cc7d26f 1481 mi_list_varobj_children_range $varname "" "" [llength $children] $children \
b6313243
TT
1482 $testname
1483}
038224f6 1484
0cc7d26f
TT
1485# Like mi_list_varobj_children, but sets a subrange. NUMCHILDREN is
1486# the total number of children.
1487proc mi_list_varobj_children_range {varname from to numchildren children testname} {
9e8e3afe
VP
1488 set options ""
1489 if {[llength $varname] == 2} {
4392c534
YQ
1490 set options [lindex $varname 1]
1491 set varname [lindex $varname 0]
9e8e3afe
VP
1492 }
1493
b6313243 1494 set children_exp_j [mi_child_regexp $children 1]
9e8e3afe 1495 if {$numchildren} {
4392c534 1496 set expected "\\^done,numchild=\".*\",children=\\\[$children_exp_j.*\\\]"
9e8e3afe 1497 } {
4392c534 1498 set expected "\\^done,numchild=\"0\""
9e8e3afe 1499 }
038224f6 1500
0cc7d26f 1501 if {"$to" == ""} {
4392c534 1502 append expected ",has_more=\"0\""
0cc7d26f 1503 } elseif {$to >= 0 && $numchildren > $to} {
4392c534 1504 append expected ",has_more=\"1\""
0cc7d26f 1505 } else {
4392c534 1506 append expected ",has_more=\"0\""
0cc7d26f
TT
1507 }
1508
038224f6
VP
1509 verbose -log "Expecting: $expected"
1510
0cc7d26f
TT
1511 mi_gdb_test "-var-list-children $options $varname $from $to" \
1512 $expected $testname
9e8e3afe
VP
1513}
1514
1515# Verifies that variable object VARNAME has NUMBER children,
1516# where each one is named $VARNAME.<index-of-child> and has type TYPE.
1517proc mi_list_array_varobj_children { varname number type testname } {
f84bc218
KB
1518 mi_list_array_varobj_children_with_index $varname $number 0 $type $testname
1519}
1520
1521# Same as mi_list_array_varobj_children, but allowing to pass a start index
1522# for an array.
1523proc mi_list_array_varobj_children_with_index { varname number start_index \
1524 type testname } {
9e8e3afe 1525 set t {}
f84bc218 1526 set index $start_index
9e8e3afe 1527 for {set i 0} {$i < $number} {incr i} {
f84bc218
KB
1528 lappend t [list $varname.$index $index 0 $type]
1529 incr index
9e8e3afe
VP
1530 }
1531 mi_list_varobj_children $varname $t $testname
038224f6 1532}
2d0720d9
VP
1533
1534# A list of two-element lists. First element of each list is
1535# a Tcl statement, and the second element is the line
1536# number of source C file where the statement originates.
1537set mi_autotest_data ""
1538# The name of the source file for autotesting.
1539set mi_autotest_source ""
1540
1541proc count_newlines { string } {
1542 return [regexp -all "\n" $string]
1543}
1544
1545# Prepares for running inline tests in FILENAME.
1546# See comments for mi_run_inline_test for detailed
1547# explanation of the idea and syntax.
1548proc mi_prepare_inline_tests { filename } {
1549
1550 global srcdir
1551 global subdir
1552 global mi_autotest_source
1553 global mi_autotest_data
1554
1555 set mi_autotest_data {}
1556
1557 set mi_autotest_source $filename
4392c534 1558
2d0720d9
VP
1559 if { ! [regexp "^/" "$filename"] } then {
1560 set filename "$srcdir/$subdir/$filename"
1561 }
1562
1563 set chan [open $filename]
1564 set content [read $chan]
1565 set line_number 1
1566 while {1} {
4392c534
YQ
1567 set start [string first "/*:" $content]
1568 if {$start != -1} {
1569 set end [string first ":*/" $content]
1570 if {$end == -1} {
1571 error "Unterminated special comment in $filename"
1572 }
1573
1574 set prefix [string range $content 0 $start]
1575 set prefix_newlines [count_newlines $prefix]
1576
1577 set line_number [expr $line_number+$prefix_newlines]
1578 set comment_line $line_number
1579
1580 set comment [string range $content [expr $start+3] [expr $end-1]]
1581
1582 set comment_newlines [count_newlines $comment]
1583 set line_number [expr $line_number+$comment_newlines]
1584
1585 set comment [string trim $comment]
1586 set content [string range $content [expr $end+3] \
1587 [string length $content]]
1588 lappend mi_autotest_data [list $comment $comment_line]
1589 } else {
1590 break
1591 }
2d0720d9
VP
1592 }
1593 close $chan
1594}
1595
1596# Helper to mi_run_inline_test below.
1597# Return the list of all (statement,line_number) lists
1598# that comprise TESTCASE. The begin and end markers
1599# are not included.
1600proc mi_get_inline_test {testcase} {
1601
1602 global mi_gdb_prompt
1603 global mi_autotest_data
1604 global mi_autotest_source
1605
1606 set result {}
1607
1608 set seen_begin 0
1609 set seen_end 0
1610 foreach l $mi_autotest_data {
1611
4392c534 1612 set comment [lindex $l 0]
2d0720d9 1613
4392c534
YQ
1614 if {$comment == "BEGIN: $testcase"} {
1615 set seen_begin 1
1616 } elseif {$comment == "END: $testcase"} {
1617 set seen_end 1
1618 break
1619 } elseif {$seen_begin==1} {
1620 lappend result $l
1621 }
2d0720d9
VP
1622 }
1623
1624 if {$seen_begin == 0} {
4392c534 1625 error "Autotest $testcase not found"
2d0720d9
VP
1626 }
1627
1628 if {$seen_begin == 1 && $seen_end == 0} {
4392c534 1629 error "Missing end marker for test $testcase"
2d0720d9
VP
1630 }
1631
1632 return $result
1633}
1634
1635# Sets temporary breakpoint at LOCATION.
1636proc mi_tbreak {location} {
1637
1638 global mi_gdb_prompt
1639
1640 mi_gdb_test "-break-insert -t $location" \
4392c534
YQ
1641 {\^done,bkpt=.*} \
1642 "run to $location (set breakpoint)"
2d0720d9
VP
1643}
1644
1645# Send COMMAND that must be a command that resumes
7bf9deb0 1646# the inferior (run/continue/next/etc) and consumes
2d0720d9 1647# the "^running" output from it.
a2840c35 1648proc mi_send_resuming_command_raw {command test} {
2d0720d9
VP
1649
1650 global mi_gdb_prompt
66bb093b 1651 global thread_selected_re
c86cf029 1652 global library_loaded_re
2d0720d9 1653
a2840c35 1654 send_gdb "$command\n"
2d0720d9 1655 gdb_expect {
4392c534
YQ
1656 -re "\\^running\r\n\\*running,thread-id=\"\[^\"\]+\"\r\n($library_loaded_re)*($thread_selected_re)?${mi_gdb_prompt}" {
1657 # Note that lack of 'pass' call here -- this works around limitation
1658 # in DejaGNU xfail mechanism. mi-until.exp has this:
1659 #
1660 # setup_kfail gdb/2104 "*-*-*"
1661 # mi_execute_to ...
1662 #
1663 # and mi_execute_to uses mi_send_resuming_command. If we use 'pass' here,
1664 # it will reset kfail, so when the actual test fails, it will be flagged
1665 # as real failure.
d0b76dc6 1666 return 0
4392c534
YQ
1667 }
1668 -re "\\^error,msg=\"Displaced stepping is only supported in ARM mode\".*" {
1669 unsupported "$test (Thumb mode)"
1670 return -1
1671 }
1672 -re "\\^error,msg=.*" {
1673 fail "$test (MI error)"
4ea95be9 1674 return -1
4392c534
YQ
1675 }
1676 -re ".*${mi_gdb_prompt}" {
1677 fail "$test (failed to resume)"
1678 return -1
1679 }
1680 timeout {
bb378428
VP
1681 fail "$test"
1682 return -1
4392c534 1683 }
2d0720d9
VP
1684 }
1685}
1686
a2840c35
VP
1687proc mi_send_resuming_command {command test} {
1688 mi_send_resuming_command_raw -$command $test
1689}
1690
2d0720d9
VP
1691# Helper to mi_run_inline_test below.
1692# Sets a temporary breakpoint at LOCATION and runs
1693# the program using COMMAND. When the program is stopped
1694# returns the line at which it. Returns -1 if line cannot
1695# be determined.
1696# Does not check that the line is the same as requested.
1697# The caller can check itself if required.
a73bafbc 1698proc mi_continue_to_line {location test} {
2d0720d9 1699
4392c534 1700 mi_tbreak $location
2d0720d9 1701 mi_send_resuming_command "exec-continue" "run to $location (exec-continue)"
bb378428 1702 return [mi_get_stop_line $test]
2d0720d9
VP
1703}
1704
1705# Wait until gdb prints the current line.
bb378428 1706proc mi_get_stop_line {test} {
2d0720d9
VP
1707
1708 global mi_gdb_prompt
f7f9a841
VP
1709 global async
1710
1711 if {$async} {
1712 set prompt_re ""
1713 } else {
d0b76dc6 1714 set prompt_re "$mi_gdb_prompt$"
f7f9a841 1715 }
2d0720d9
VP
1716
1717 gdb_expect {
d0b76dc6 1718 -re ".*line=\"(\[0-9\]*)\".*\r\n$prompt_re" {
4392c534 1719 return $expect_out(1,string)
2d0720d9 1720 }
d0b76dc6 1721 -re ".*$mi_gdb_prompt" {
4392c534 1722 fail "wait for stop ($test)"
2d0720d9
VP
1723 }
1724 timeout {
4392c534 1725 fail "wait for stop ($test)"
2d0720d9
VP
1726 }
1727 }
1728}
1729
1730# Run a MI test embedded in comments in a C file.
1731# The C file should contain special comments in the following
1732# three forms:
1733#
1734# /*: BEGIN: testname :*/
1735# /*: <Tcl statements> :*/
1736# /*: END: testname :*/
1737#
1738# This procedure find the begin and end marker for the requested
1739# test. Then, a temporary breakpoint is set at the begin
1740# marker and the program is run (from start).
1741#
1742# After that, for each special comment between the begin and end
1743# marker, the Tcl statements are executed. It is assumed that
1744# for each comment, the immediately preceding line is executable
1745# C statement. Then, gdb will be single-stepped until that
1746# preceding C statement is executed, and after that the
1747# Tcl statements in the comment will be executed.
1748#
1749# For example:
1750#
1751# /*: BEGIN: assignment-test :*/
1752# v = 10;
1753# /*: <Tcl code to check that 'v' is indeed 10 :*/
1754# /*: END: assignment-test :*/
1755#
1756# The mi_prepare_inline_tests function should be called before
1757# calling this function. A given C file can contain several
1758# inline tests. The names of the tests must be unique within one
1759# C file.
1760#
1761proc mi_run_inline_test { testcase } {
1762
1763 global mi_gdb_prompt
1764 global hex
1765 global decimal
1766 global fullname_syntax
1767 global mi_autotest_source
1768
1769 set commands [mi_get_inline_test $testcase]
1770
1771 set first 1
1772 set line_now 1
1773
1774 foreach c $commands {
4392c534
YQ
1775 set statements [lindex $c 0]
1776 set line [lindex $c 1]
1777 set line [expr $line-1]
1778
1779 # We want gdb to be stopped at the expression immediately
1780 # before the comment. If this is the first comment, the
1781 # program is either not started yet or is in some random place,
1782 # so we run it. For further comments, we might be already
1783 # standing at the right line. If not continue till the
1784 # right line.
1785
1786 if {$first==1} {
1787 # Start the program afresh.
1788 mi_tbreak "$mi_autotest_source:$line"
1789 mi_run_cmd
1790 set line_now [mi_get_stop_line "$testcase: step to $line"]
1791 set first 0
1792 } elseif {$line_now!=$line} {
1793 set line_now [mi_continue_to_line "$mi_autotest_source:$line" "continue to $line"]
1794 }
1795
1796 if {$line_now!=$line} {
1797 fail "$testcase: go to line $line"
1798 }
1799
1800 # We're not at the statement right above the comment.
1801 # Execute that statement so that the comment can test
1802 # the state after the statement is executed.
1803
1804 # Single-step past the line.
1805 if { [mi_send_resuming_command "exec-next" "$testcase: step over $line"] != 0 } {
d0b76dc6
DJ
1806 return -1
1807 }
1808 set line_now [mi_get_stop_line "$testcase: step over $line"]
2d0720d9 1809
4392c534
YQ
1810 # We probably want to use 'uplevel' so that statements
1811 # have direct access to global variables that the
1812 # main 'exp' file has set up. But it's not yet clear,
1813 # will need more experience to be sure.
1814 eval $statements
2d0720d9
VP
1815 }
1816}
9d81d21b
VP
1817
1818proc get_mi_thread_list {name} {
1819 global expect_out
1820
1821 # MI will return a list of thread ids:
1822 #
1823 # -thread-list-ids
1824 # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N"
1825 # (gdb)
1826 mi_gdb_test "-thread-list-ids" \
592375cd 1827 {.*\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \
9d81d21b
VP
1828 "-thread_list_ids ($name)"
1829
1830 set output {}
1831 if {[info exists expect_out(buffer)]} {
1832 set output $expect_out(buffer)
1833 }
1834
1835 set thread_list {}
1836 if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} {
1837 fail "finding threads in MI output ($name)"
1838 } else {
1839 pass "finding threads in MI output ($name)"
1840
1841 # Make list of console threads
1842 set start [expr {[string first \{ $threads] + 1}]
1843 set end [expr {[string first \} $threads] - 1}]
1844 set threads [string range $threads $start $end]
1845 foreach thread [split $threads ,] {
1846 if {[scan $thread {thread-id="%d"} num]} {
1847 lappend thread_list $num
1848 }
1849 }
1850 }
1851
1852 return $thread_list
1853}
1854
1855# Check that MI and the console know of the same threads.
1856# Appends NAME to all test names.
1857proc check_mi_and_console_threads {name} {
1858 global expect_out
1859
1860 mi_gdb_test "-thread-list-ids" \
592375cd 1861 {.*\^done,thread-ids={(thread-id="[0-9]+"(,)*)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \
9d81d21b
VP
1862 "-thread-list-ids ($name)"
1863 set mi_output {}
1864 if {[info exists expect_out(buffer)]} {
1865 set mi_output $expect_out(buffer)
1866 }
1867
1868 # GDB will return a list of thread ids and some more info:
1869 #
1870 # (gdb)
1871 # -interpreter-exec console "info threads"
1872 # ~" 4 Thread 2051 (LWP 7734) 0x401166b1 in __libc_nanosleep () at __libc_nanosleep:-1"
1873 # ~" 3 Thread 1026 (LWP 7733) () at __libc_nanosleep:-1"
1874 # ~" 2 Thread 2049 (LWP 7732) 0x401411f8 in __poll (fds=0x804bb24, nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63"
1875 # ~"* 1 Thread 1024 (LWP 7731) main (argc=1, argv=0xbfffdd94) at ../../../src/gdb/testsuite/gdb.mi/pthreads.c:160"
1876 # FIXME: kseitz/2002-09-05: Don't use the hack-cli method.
1877 mi_gdb_test "info threads" \
1878 {.*(~".*"[\r\n]*)+.*} \
1879 "info threads ($name)"
1880 set console_output {}
1881 if {[info exists expect_out(buffer)]} {
1882 set console_output $expect_out(buffer)
1883 }
1884
1885 # Make a list of all known threads to console (gdb's thread IDs)
1886 set console_thread_list {}
1887 foreach line [split $console_output \n] {
1888 if {[string index $line 0] == "~"} {
1889 # This is a line from the console; trim off "~", " ", "*", and "\""
1890 set line [string trim $line ~\ \"\*]
1891 if {[scan $line "%d" id] == 1} {
1892 lappend console_thread_list $id
1893 }
1894 }
1895 }
1896
1897 # Now find the result string from MI
1898 set mi_result ""
1899 foreach line [split $mi_output \n] {
1900 if {[string range $line 0 4] == "^done"} {
1901 set mi_result $line
1902 }
1903 }
1904 if {$mi_result == ""} {
1905 fail "finding MI result string ($name)"
1906 } else {
1907 pass "finding MI result string ($name)"
1908 }
1909
1910 # Finally, extract the thread ids and compare them to the console
1911 set num_mi_threads_str ""
1912 if {![regexp {number-of-threads="[0-9]+"} $mi_result num_mi_threads_str]} {
1913 fail "finding number of threads in MI output ($name)"
1914 } else {
1915 pass "finding number of threads in MI output ($name)"
1916
1917 # Extract the number of threads from the MI result
1918 if {![scan $num_mi_threads_str {number-of-threads="%d"} num_mi_threads]} {
1919 fail "got number of threads from MI ($name)"
1920 } else {
1921 pass "got number of threads from MI ($name)"
1922
1923 # Check if MI and console have same number of threads
1924 if {$num_mi_threads != [llength $console_thread_list]} {
1925 fail "console and MI have same number of threads ($name)"
1926 } else {
1927 pass "console and MI have same number of threads ($name)"
1928
1929 # Get MI thread list
1930 set mi_thread_list [get_mi_thread_list $name]
1931
1932 # Check if MI and console have the same threads
1933 set fails 0
1934 foreach ct [lsort $console_thread_list] mt [lsort $mi_thread_list] {
1935 if {$ct != $mt} {
1936 incr fails
1937 }
1938 }
1939 if {$fails > 0} {
1940 fail "MI and console have same threads ($name)"
1941
1942 # Send a list of failures to the log
1943 send_log "Console has thread ids: $console_thread_list\n"
1944 send_log "MI has thread ids: $mi_thread_list\n"
1945 } else {
1946 pass "MI and console have same threads ($name)"
1947 }
1948 }
1949 }
1950 }
1951}
5e06a3d1 1952
759f0f0b 1953# Download shared libraries to the target.
5e06a3d1
VP
1954proc mi_load_shlibs { args } {
1955 if {![is_remote target]} {
1956 return
1957 }
1958
1959 foreach file $args {
759f0f0b 1960 gdb_download [shlib_target_file $file]
5e06a3d1
VP
1961 }
1962
1963 # Even if the target supplies full paths for shared libraries,
1964 # they may not be paths for this system.
1965 mi_gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "\^done" ""
1966}
1967
1ad15515
PA
1968proc mi_reverse_list { list } {
1969 if { [llength $list] <= 1 } {
1970 return $list
1971 }
1972 set tail [lrange $list 1 [llength $list]]
1973 set rtail [mi_reverse_list $tail]
1974 lappend rtail [lindex $list 0]
1975 return $rtail
1976}
1977
1978proc mi_check_thread_states { xstates test } {
1979 global expect_out
1980 set states [mi_reverse_list $xstates]
f4e164aa 1981 set pattern ".*\\^done,threads=\\\["
1ad15515
PA
1982 foreach s $states {
1983 set pattern "${pattern}(.*)state=\"$s\""
1984 }
dc146f7c 1985 set pattern "${pattern}(,core=\"\[0-9\]*\")?\\\}\\\].*"
1ad15515
PA
1986
1987 verbose -log "expecting: $pattern"
1988 mi_gdb_test "-thread-info" $pattern $test
1989}
b6313243
TT
1990
1991# Return a list of MI features supported by this gdb.
1992proc mi_get_features {} {
1993 global expect_out mi_gdb_prompt
1994
1995 send_gdb "-list-features\n"
1996
1997 gdb_expect {
1998 -re "\\^done,features=\\\[(.*)\\\]\r\n$mi_gdb_prompt$" {
1999 regsub -all -- \" $expect_out(1,string) "" features
2000 return [split $features ,]
2001 }
2002 -re ".*\r\n$mi_gdb_prompt$" {
2003 verbose -log "got $expect_out(buffer)"
2004 return ""
2005 }
2006 timeout {
2007 verbose -log "timeout in mi_gdb_prompt"
2008 return ""
2009 }
2010 }
2011}
1eec78bd
KS
2012
2013# Variable Object Trees
2014#
2015# Yet another way to check varobjs. Pass mi_walk_varobj_tree a "list" of
2016# variables (not unlike the actual source code definition), and it will
2017# automagically test the children for you (by default).
2018#
2019# Example:
2020#
2021# source code:
2022# struct bar {
2023# union {
2024# int integer;
2025# void *ptr;
2026# };
2027# const int *iPtr;
2028# };
2029#
2030# class foo {
2031# public:
2032# int a;
2033# struct {
2034# int b;
2035# struct bar *c;
2036# };
2037# };
2038#
2039# foo *f = new foo (); <-- break here
2040#
2041# We want to check all the children of "f".
2042#
2043# Translate the above structures into the following tree:
2044#
2045# set tree {
2046# foo f {
2047# {} public {
2048# int a {}
2049# anonymous struct {
2050# {} public {
2051# int b {}
2052# {bar *} c {
2053# {} public {
2054# anonymous union {
2055# {} public {
2056# int integer {}
2057# {void *} ptr {}
2058# }
2059# }
2060# {const int *} iPtr {
2061# {const int} {*iPtr} {}
2062# }
2063# }
2064# }
2065# }
2066# }
2067# }
2068# }
2069# }
2070#
440e2fca 2071# mi_walk_varobj_tree c++ $tree
1eec78bd
KS
2072#
2073# If you'd prefer to walk the tree using your own callback,
2074# simply pass the name of the callback to mi_walk_varobj_tree.
2075#
2076# This callback should take one argument, the name of the variable
2077# to process. This name is the name of a global array holding the
2078# variable's properties (object name, type, etc).
2079#
2080# An example callback:
2081#
2082# proc my_callback {var} {
2083# upvar #0 $var varobj
2084#
2085# puts "my_callback: called on varobj $varobj(obj_name)"
2086# }
2087#
2088# The arrays created for each variable object contain the following
2089# members:
2090#
2091# obj_name - the object name for accessing this variable via MI
2092# display_name - the display name for this variable (exp="display_name" in
2093# the output of -var-list-children)
2094# type - the type of this variable (type="type" in the output
2095# of -var-list-children, or the special tag "anonymous"
2096# path_expr - the "-var-info-path-expression" for this variable
440e2fca
KS
2097# NOTE: This member cannot be used reliably with typedefs.
2098# Use with caution!
2099# See notes inside get_path_expr for more.
1eec78bd
KS
2100# parent - the variable name of the parent varobj
2101# children - a list of children variable names (which are the
2102# names Tcl arrays, not object names)
2103#
2104# For each variable object, an array containing the above fields will
2105# be created under the root node (conveniently called, "root"). For example,
2106# a variable object with handle "OBJ.public.0_anonymous.a" will have
2107# a corresponding global Tcl variable named "root.OBJ.public.0_anonymous.a".
2108#
2109# Note that right now, this mechanism cannot be used for recursive data
2110# structures like linked lists.
2111
2112namespace eval ::varobj_tree {
2113 # An index which is appended to root varobjs to ensure uniqueness.
2114 variable _root_idx 0
2115
2116 # A procedure to help with debuggging varobj trees.
2117 # VARIABLE_NAME is the name of the variable to dump.
2118 # CMD, if present, is the name of the callback to output the contstructed
2119 # strings. By default, it uses expect's "send_log" command.
2120 # TERM, if present, is a terminating character. By default it is the newline.
2121 #
2122 # To output to the terminal (not the expect log), use
2123 # mi_varobj_tree_dump_variable my_variable puts ""
2124
2125 proc mi_varobj_tree_dump_variable {variable_name {cmd send_log} {term "\n"}} {
2126 upvar #0 $variable_name varobj
2127
2128 eval "$cmd \"VAR = $variable_name$term\""
2129
2130 # Explicitly encode the array indices, since outputting them
2131 # in some logical order is better than what "array names" might
2132 # return.
2133 foreach idx {obj_name parent display_name type path_expr} {
2134 eval "$cmd \"\t$idx = $varobj($idx)$term\""
2135 }
2136
2137 # Output children
2138 set num [llength $varobj(children)]
2139 eval "$cmd \"\tnum_children = $num$term\""
2140 if {$num > 0} {
2141 eval "$cmd \"\tchildren = $varobj(children)$term\""
2142 }
2143 }
2144
2145 # The default callback used by mi_walk_varobj_tree. This callback
440e2fca
KS
2146 # simply checks all of VAR's children. It specifically does not test
2147 # path expressions, since that is very problematic.
1eec78bd
KS
2148 #
2149 # This procedure may be used in custom callbacks.
2150 proc test_children_callback {variable_name} {
2151 upvar #0 $variable_name varobj
2152
2153 if {[llength $varobj(children)] > 0} {
2154 # Construct the list of children the way mi_list_varobj_children
2155 # expects to get it:
2156 # { {obj_name display_name num_children type} ... }
2157 set children_list {}
2158 foreach child $varobj(children) {
2159 upvar #0 $child c
2160 set clist [list [string_to_regexp $c(obj_name)] \
2161 [string_to_regexp $c(display_name)] \
2162 [llength $c(children)]]
2163 if {[string length $c(type)] > 0} {
2164 lappend clist [string_to_regexp $c(type)]
2165 }
2166 lappend children_list $clist
2167 }
2168
2169 mi_list_varobj_children $varobj(obj_name) $children_list \
2170 "VT: list children of $varobj(obj_name)"
2171 }
2172 }
2173
2174 # Set the properties of the varobj represented by
2175 # PARENT_VARIABLE - the name of the parent's variable
2176 # OBJNAME - the MI object name of this variable
2177 # DISP_NAME - the display name of this variable
2178 # TYPE - the type of this variable
2179 # PATH - the path expression for this variable
2180 # CHILDREN - a list of the variable's children
2181 proc create_varobj {parent_variable objname disp_name \
2182 type path children} {
2183 upvar #0 $parent_variable parent
2184
2185 set var_name "root.$objname"
2186 global $var_name
2187 array set $var_name [list obj_name $objname]
2188 array set $var_name [list display_name $disp_name]
2189 array set $var_name [list type $type]
2190 array set $var_name [list path_expr $path]
2191 array set $var_name [list parent "$parent_variable"]
2192 array set $var_name [list children \
2193 [get_tree_children $var_name $children]]
2194 return $var_name
2195 }
2196
2197 # Should VARIABLE be used in path expressions? The CPLUS_FAKE_CHILD
2198 # varobjs and anonymous structs/unions are not used for path expressions.
2199 proc is_path_expr_parent {variable} {
2200 upvar #0 $variable varobj
2201
2202 # If the varobj's type is "", it is a CPLUS_FAKE_CHILD.
2203 # If the tail of the varobj's object name is "%d_anonymous",
2204 # then it represents an anonymous struct or union.
2205 if {[string length $varobj(type)] == 0 \
2206 || [regexp {[0-9]+_anonymous$} $varobj(obj_name)]} {
2207 return false
2208 }
2209
2210 return true
2211 }
2212
2213 # Return the path expression for the variable named NAME in
2214 # parent varobj whose variable name is given by PARENT_VARIABLE.
2215 proc get_path_expr {parent_variable name type} {
2216 upvar #0 $parent_variable parent
440e2fca 2217 upvar #0 $parent_variable path_parent
1eec78bd
KS
2218
2219 # If TYPE is "", this is one of the CPLUS_FAKE_CHILD varobjs,
440e2fca
KS
2220 # which has no path expression. Likewsise for anonymous structs
2221 # and unions.
2222 if {[string length $type] == 0 \
2223 || [string compare $type "anonymous"] == 0} {
1eec78bd
KS
2224 return ""
2225 }
2226
2227 # Find the path parent variable.
2228 while {![is_path_expr_parent $parent_variable]} {
440e2fca
KS
2229 set parent_variable $path_parent(parent)
2230 upvar #0 $parent_variable path_parent
2231 }
2232
2233 # This is where things get difficult. We do not actually know
2234 # the real type for variables defined via typedefs, so we don't actually
2235 # know whether the parent is a structure/union or not.
2236 #
2237 # So we assume everything that isn't a simple type is a compound type.
2238 set stars ""
2239 regexp {\*+} $parent(type) stars
2240 set is_compound 1
2241 if {[string index $name 0] == "*"} {
2242 set is_compound 0
2243 }
2244
2245 if {[string index $parent(type) end] == "\]"} {
2246 # Parent is an array.
2247 return "($path_parent(path_expr))\[$name\]"
2248 } elseif {$is_compound} {
2249 # Parent is a structure or union or a pointer to one.
2250 if {[string length $stars]} {
2251 set join "->"
2252 } else {
2253 set join "."
2254 }
2255
2256 global root
1eec78bd 2257
440e2fca
KS
2258 # To make matters even more hideous, varobj.c has slightly different
2259 # path expressions for C and C++.
2260 set path_expr "($path_parent(path_expr))$join$name"
2261 if {[string compare -nocase $root(language) "c"] == 0} {
2262 return $path_expr
2263 } else {
2264 return "($path_expr)"
2265 }
2266 } else {
2267 # Parent is a pointer.
2268 return "*($path_parent(path_expr))"
2269 }
1eec78bd
KS
2270 }
2271
2272 # Process the CHILDREN (a list of varobj_tree elements) of the variable
2273 # given by PARENT_VARIABLE. Returns a list of children variables.
2274 proc get_tree_children {parent_variable children} {
2275 upvar #0 $parent_variable parent
2276
2277 set field_idx 0
2278 set children_list {}
2279 foreach {type name children} $children {
2280 if {[string compare $parent_variable "root"] == 0} {
2281 # Root variable
2282 variable _root_idx
2283 incr _root_idx
2284 set objname "$name$_root_idx"
2285 set disp_name "$name"
2286 set path_expr "$name"
2287 } elseif {[string compare $type "anonymous"] == 0} {
2288 # Special case: anonymous types. In this case, NAME will either be
2289 # "struct" or "union".
2290 set objname "$parent(obj_name).${field_idx}_anonymous"
2291 set disp_name "<anonymous $name>"
2292 set path_expr ""
2293 set type "$name {...}"
2294 } else {
2295 set objname "$parent(obj_name).$name"
2296 set disp_name $name
2297 set path_expr [get_path_expr $parent_variable $name $type]
2298 }
2299
2300 lappend children_list [create_varobj $parent_variable $objname \
2301 $disp_name $type $path_expr $children]
2302 incr field_idx
2303 }
2304
2305 return $children_list
2306 }
2307
2308 # The main procedure to call the given CALLBACK on the elements of the
2309 # given varobj TREE. See detailed explanation above.
440e2fca 2310 proc walk_tree {language tree callback} {
1eec78bd 2311 global root
f44eeb11 2312 variable _root_idx
1eec78bd
KS
2313
2314 if {[llength $tree] < 3} {
2315 error "tree does not contain enough elements"
2316 }
2317
f44eeb11
TT
2318 set _root_idx 0
2319
1eec78bd 2320 # Create root node and process the tree.
440e2fca 2321 array set root [list language $language]
1eec78bd
KS
2322 array set root [list obj_name "root"]
2323 array set root [list display_name "root"]
2324 array set root [list type "root"]
2325 array set root [list path_expr "root"]
2326 array set root [list parent "root"]
2327 array set root [list children [get_tree_children root $tree]]
2328
2329 # Walk the tree
2330 set all_nodes $root(children); # a stack of nodes
2331 while {[llength $all_nodes] > 0} {
2332 # "Pop" the name of the global variable containing this varobj's
2333 # information from the stack of nodes.
2334 set var_name [lindex $all_nodes 0]
2335 set all_nodes [lreplace $all_nodes 0 0]
2336
2337 # Bring the global named in VAR_NAME into scope as the local variable
2338 # VAROBJ.
2339 upvar #0 $var_name varobj
2340
2341 # Append any children of VAROBJ to the list of nodes to walk.
2342 if {[llength $varobj(children)] > 0} {
2343 set all_nodes [concat $all_nodes $varobj(children)]
2344 }
2345
2346 # If this is a root variable, create the variable object for it.
2347 if {[string compare $varobj(parent) "root"] == 0} {
2348 mi_create_varobj $varobj(obj_name) $varobj(display_name) \
2349 "VT: create root varobj for $varobj(display_name)"
2350 }
2351
2352 # Now call the callback for VAROBJ.
2353 uplevel #0 $callback $var_name
2354 }
2355 }
2356}
2357
2358# The default varobj tree callback, which simply tests -var-list-children.
2359proc mi_varobj_tree_test_children_callback {variable} {
2360 ::varobj_tree::test_children_callback $variable
2361}
2362
2363# Walk the variable object tree given by TREE, calling the specified
2364# CALLBACK. By default this uses mi_varobj_tree_test_children_callback.
440e2fca
KS
2365proc mi_walk_varobj_tree {language tree \
2366 {callback \
2367 mi_varobj_tree_test_children_callback}} {
2368 ::varobj_tree::walk_tree $language $tree $callback
1eec78bd 2369}
4b48d439
KS
2370
2371# Build a list of key-value pairs given by the list ATTR_LIST. Flatten
2372# this list using the optional JOINER, a comma by default.
2373#
2374# The list must contain an even number of elements, which are the key-value
2375# pairs. Each value will be surrounded by quotes, according to the grammar,
2376# except if the value starts with \[ or \{, when the quotes will be omitted.
2377#
2378# Example: mi_build_kv_pairs {a b c d e f g \[.*\]}
2379# returns a=\"b\",c=\"d\",e=\"f\",g=\[.*\]
2380proc mi_build_kv_pairs {attr_list {joiner ,}} {
2381 set l {}
2382 foreach {var value} $attr_list {
2383 if {[string range $value 0 1] == "\\\["
2384 || [string range $value 0 1] == "\\\{"} {
2385 lappend l "$var=$value"
2386 } else {
2387 lappend l "$var=\"$value\""
2388 }
2389 }
2390 return "[join $l $joiner]"
2391}
2392
2393# Construct a breakpoint regexp. This may be used to test the output of
2394# -break-insert, -dprintf-insert, or -break-info.
2395#
2396# All arguments for the breakpoint may be specified using the options
2397# number, type, disp, enabled, addr, func, file, fullanme, line,
6613eb10
KS
2398# thread-groups, cond, evaluated-by, times, ignore, script,
2399# and original-location.
4b48d439
KS
2400#
2401# Only if -script and -ignore are given will they appear in the output.
2402# Otherwise, this procedure will skip them using ".*".
2403#
2404# Example: mi_make_breakpoint -number 2 -file ".*/myfile.c" -line 3
2405# will return the breakpoint:
2406# bkpt={number="2",type=".*",disp=".*",enabled=".*",addr=".*",func=".*",
2407# file=".*/myfile.c",fullname=".*",line="3",thread-groups=\[.*\],
2408# times="0".*original-location=".*"}
2409
2410proc mi_make_breakpoint {args} {
2411 parse_args {{number .*} {type .*} {disp .*} {enabled .*} {addr .*}
2412 {func .*} {file .*} {fullname .*} {line .*}
2413 {thread-groups \\\[.*\\\]} {times .*} {ignore 0}
6613eb10 2414 {script ""} {original-location .*} {cond ""} {evaluated-by ""}}
4b48d439
KS
2415
2416 set attr_list {}
2417 foreach attr [list number type disp enabled addr func file \
eb8c4e2e 2418 fullname line thread-groups] {
4b48d439
KS
2419 lappend attr_list $attr [set $attr]
2420 }
2421
2422 set result "bkpt={[mi_build_kv_pairs $attr_list]"
2423
2424 # There are always exceptions.
eb8c4e2e
KS
2425
2426 # If COND is not preset, do not output it.
2427 if {[string length $cond] > 0} {
2428 append result ","
2429 append result [mi_build_kv_pairs [list "cond" $cond]]
6613eb10
KS
2430
2431 # When running on a remote, GDB may output who is evaluating
2432 # breakpoint conditions.
2433 if {[string length ${evaluated-by}] > 0} {
2434 append result [mi_build_kv_pairs \
2435 [list "evaluated-by" ${evaluated-by}]]
2436 } else {
2437 append result {(,evaluated-by=".*")?}
2438 }
eb8c4e2e
KS
2439 }
2440
2441 append result ","
2442 append result [mi_build_kv_pairs [list "times" $times]]
2443
4b48d439
KS
2444 # If SCRIPT and IGNORE are not present, do not output them.
2445 if {$ignore != 0} {
2446 append result ","
2447 append result [mi_build_kv_pairs [list "ignore" $ignore]]
2448 append result ","
2449 }
2450 if {[string length $script] > 0} {
2451 append result ","
2452 append result [mi_build_kv_pairs [list "script" $script]]
2453 append result ","
2454 } else {
2455 # Allow anything up until the next "official"/required attribute.
2456 # This pattern skips over script/ignore if matches on those
2457 # were not specifically required by the caller.
2458 append result ".*"
2459 }
2460 append result [mi_build_kv_pairs \
2461 [list "original-location" ${original-location}]]
2462 append result "}"
2463 return $result
2464}
2465
2466# Build a breakpoint table regexp given the list of breakpoints in `bp_list',
2467# constructed by mi_make_breakpoint.
2468#
2469# Example: Construct a breakpoint table where the only attributes we
2470# test for are the existence of three breakpoints numbered 1, 2, and 3.
2471#
2472# set bps {}
2473# lappend bps [mi_make_breakpoint -number 1]
2474# lappend bps [mi_make_breakpoint -number 2]
2475# lappned bps [mi_make_breakpoint -number 3]
2476# mi_make_breakpoint_table $bps
2477# will return (abbreviated for clarity):
2478# BreakpointTable={nr_rows="3",nr_cols="6",hdr=[{width=".*",...} ...],
2479# body=[bkpt={number="1",...},bkpt={number="2",...},bkpt={number="3",...}]}
2480
2481proc mi_make_breakpoint_table {bp_list} {
2482 # Build header -- assume a standard header for all breakpoint tables.
2483 set hl {}
2484 foreach {nm hdr} [list number Num type Type disp Disp enabled Enb \
2485 addr Address what What] {
2486 # The elements here are the MI table headers, which have the
2487 # format:
2488 # {width="7",alignment="-1",col_name="number",colhdr="Num"}
2489 lappend hl "{[mi_build_kv_pairs [list width .* alignment .* \
2490 col_name $nm colhdr $hdr]]}"
2491 }
2492 set header "hdr=\\\[[join $hl ,]\\\]"
2493
2494 # The caller has implicitly supplied the number of columns and rows.
2495 set nc [llength $hl]
2496 set nr [llength $bp_list]
2497
2498 # Build body -- mi_make_breakpoint has done most of the work.
2499 set body "body=\\\[[join $bp_list ,]\\\]"
2500
2501 # Assemble the final regexp.
2502 return "BreakpointTable={nr_rows=\"$nr\",nr_cols=\"$nc\",$header,$body}"
2503}
4d6cceb4
DE
2504
2505# Return a 1 for configurations that do not support Python scripting.
2506# Note: This also sets various globals that specify which version of Python
2507# is in use. See skip_python_tests_prompt.
2508
2509proc mi_skip_python_tests {} {
2510 global mi_gdb_prompt
2511 return [skip_python_tests_prompt "$mi_gdb_prompt$"]
2512}
This page took 1.70041 seconds and 4 git commands to generate.