]>
Commit | Line | Data |
---|---|---|
9b254dd1 | 1 | # Copyright 1999, 2000, 2002, 2003, 2004, 2005, 2007, 2008 |
6aba47ca | 2 | # Free Software Foundation, Inc. |
fb40c209 AC |
3 | |
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
fb40c209 | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
fb40c209 AC |
9 | # This program is distributed in the hope that it will be useful, |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
e22f8b7c | 13 | # |
fb40c209 | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
fb40c209 AC |
16 | |
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@prep.ai.mit.edu | |
19 | ||
20 | # This file was based on a file written by Fred Fish. (fnf@cygnus.com) | |
21 | ||
22 | # Test setup routines that work with the MI interpreter. | |
23 | ||
24 | # The variable mi_gdb_prompt is a regexp which matches the gdb mi prompt. | |
25 | # Set it if it is not already set. | |
26 | global mi_gdb_prompt | |
27 | if ![info exists mi_gdb_prompt] then { | |
28 | set mi_gdb_prompt "\[(\]gdb\[)\] \r\n" | |
29 | } | |
30 | ||
ecd3fd0f BR |
31 | global mi_inferior_spawn_id |
32 | global mi_inferior_tty_name | |
33 | ||
fb40c209 AC |
34 | set MIFLAGS "-i=mi" |
35 | ||
36 | # | |
37 | # mi_gdb_exit -- exit the GDB, killing the target program if necessary | |
38 | # | |
39 | proc mi_gdb_exit {} { | |
40 | catch mi_uncatched_gdb_exit | |
41 | } | |
42 | ||
43 | proc mi_uncatched_gdb_exit {} { | |
44 | global GDB | |
45 | global GDBFLAGS | |
46 | global verbose | |
47 | global gdb_spawn_id; | |
48 | global gdb_prompt | |
49 | global mi_gdb_prompt | |
50 | global MIFLAGS | |
51 | ||
52 | gdb_stop_suppressing_tests; | |
53 | ||
54 | if { [info procs sid_exit] != "" } { | |
55 | sid_exit | |
56 | } | |
57 | ||
58 | if ![info exists gdb_spawn_id] { | |
59 | return; | |
60 | } | |
61 | ||
62 | verbose "Quitting $GDB $GDBFLAGS $MIFLAGS" | |
63 | ||
64 | if { [is_remote host] && [board_info host exists fileid] } { | |
65 | send_gdb "999-gdb-exit\n"; | |
66 | gdb_expect 10 { | |
67 | -re "y or n" { | |
68 | send_gdb "y\n"; | |
69 | exp_continue; | |
70 | } | |
71 | -re "Undefined command.*$gdb_prompt $" { | |
72 | send_gdb "quit\n" | |
73 | exp_continue; | |
74 | } | |
75 | -re "DOSEXIT code" { } | |
76 | default { } | |
77 | } | |
78 | } | |
79 | ||
80 | if ![is_remote host] { | |
81 | remote_close host; | |
82 | } | |
83 | unset gdb_spawn_id | |
84 | } | |
85 | ||
86 | # | |
79732189 | 87 | # default_mi_gdb_start [INFERIOR_PTY] -- start gdb running, default procedure |
ecd3fd0f BR |
88 | # |
89 | # INFERIOR_PTY should be set to separate-inferior-tty to have the inferior work | |
90 | # with it's own PTY. If set to same-inferior-tty, the inferior shares GDB's PTY. | |
91 | # The default value is same-inferior-tty. | |
fb40c209 AC |
92 | # |
93 | # When running over NFS, particularly if running many simultaneous | |
94 | # tests on different hosts all using the same server, things can | |
95 | # get really slow. Give gdb at least 3 minutes to start up. | |
96 | # | |
79732189 | 97 | proc default_mi_gdb_start { args } { |
fb40c209 AC |
98 | global verbose |
99 | global GDB | |
100 | global GDBFLAGS | |
101 | global gdb_prompt | |
102 | global mi_gdb_prompt | |
103 | global timeout | |
104 | global gdb_spawn_id; | |
105 | global MIFLAGS | |
106 | ||
107 | gdb_stop_suppressing_tests; | |
ecd3fd0f BR |
108 | set inferior_pty no-tty |
109 | ||
110 | if { [llength $args] == 1} { | |
111 | set inferior_pty [lindex $args 0] | |
112 | } | |
113 | ||
114 | set separate_inferior_pty [string match $inferior_pty separate-inferior-tty] | |
fb40c209 | 115 | |
1759b3c3 AC |
116 | # Start SID. |
117 | if { [info procs sid_start] != "" } { | |
118 | verbose "Spawning SID" | |
119 | sid_start | |
120 | } | |
121 | ||
fb40c209 AC |
122 | verbose "Spawning $GDB -nw $GDBFLAGS $MIFLAGS" |
123 | ||
124 | if [info exists gdb_spawn_id] { | |
125 | return 0; | |
126 | } | |
127 | ||
128 | if ![is_remote host] { | |
129 | if { [which $GDB] == 0 } then { | |
130 | perror "$GDB does not exist." | |
131 | exit 1 | |
132 | } | |
133 | } | |
ecd3fd0f BR |
134 | |
135 | # Create the new PTY for the inferior process. | |
136 | if { $separate_inferior_pty } { | |
137 | spawn -pty | |
138 | global mi_inferior_spawn_id | |
139 | global mi_inferior_tty_name | |
140 | set mi_inferior_spawn_id $spawn_id | |
141 | set mi_inferior_tty_name $spawn_out(slave,name) | |
142 | } | |
143 | ||
fb40c209 AC |
144 | set res [remote_spawn host "$GDB -nw $GDBFLAGS $MIFLAGS [host_info gdb_opts]"]; |
145 | if { $res < 0 || $res == "" } { | |
146 | perror "Spawning $GDB failed." | |
147 | return 1; | |
148 | } | |
149 | gdb_expect { | |
1f312e79 JJ |
150 | -re "~\"GNU.*\r\n~\".*$mi_gdb_prompt$" { |
151 | # We have a new format mi startup prompt. If we are | |
152 | # running mi1, then this is an error as we should be | |
153 | # using the old-style prompt. | |
154 | if { $MIFLAGS == "-i=mi1" } { | |
155 | perror "(mi startup) Got unexpected new mi prompt." | |
156 | remote_close host; | |
157 | return -1; | |
158 | } | |
159 | verbose "GDB initialized." | |
160 | } | |
161 | -re "\[^~\].*$mi_gdb_prompt$" { | |
162 | # We have an old format mi startup prompt. If we are | |
163 | # not running mi1, then this is an error as we should be | |
164 | # using the new-style prompt. | |
165 | if { $MIFLAGS != "-i=mi1" } { | |
166 | perror "(mi startup) Got unexpected old mi prompt." | |
167 | remote_close host; | |
168 | return -1; | |
169 | } | |
d20bf2e8 | 170 | verbose "GDB initialized." |
fb40c209 AC |
171 | } |
172 | -re ".*$gdb_prompt $" { | |
173 | untested "Skip mi tests (got non-mi prompt)." | |
174 | remote_close host; | |
175 | return -1; | |
176 | } | |
76c520e0 AC |
177 | -re ".*unrecognized option.*for a complete list of options." { |
178 | untested "Skip mi tests (not compiled with mi support)." | |
179 | remote_close host; | |
180 | return -1; | |
181 | } | |
7d76bd60 MK |
182 | -re ".*Interpreter `mi' unrecognized." { |
183 | untested "Skip mi tests (not compiled with mi support)." | |
184 | remote_close host; | |
185 | return -1; | |
186 | } | |
fb40c209 AC |
187 | timeout { |
188 | perror "(timeout) GDB never initialized after 10 seconds." | |
189 | remote_close host; | |
190 | return -1 | |
191 | } | |
192 | } | |
193 | set gdb_spawn_id -1; | |
194 | ||
195 | # FIXME: mi output does not go through pagers, so these can be removed. | |
196 | # force the height to "unlimited", so no pagers get used | |
197 | send_gdb "100-gdb-set height 0\n" | |
198 | gdb_expect 10 { | |
199 | -re ".*100-gdb-set height 0\r\n100\\\^done\r\n$mi_gdb_prompt$" { | |
200 | verbose "Setting height to 0." 2 | |
201 | } | |
202 | timeout { | |
203 | warning "Couldn't set the height to 0" | |
204 | } | |
205 | } | |
206 | # force the width to "unlimited", so no wraparound occurs | |
207 | send_gdb "101-gdb-set width 0\n" | |
208 | gdb_expect 10 { | |
209 | -re ".*101-gdb-set width 0\r\n101\\\^done\r\n$mi_gdb_prompt$" { | |
210 | verbose "Setting width to 0." 2 | |
211 | } | |
212 | timeout { | |
213 | warning "Couldn't set the width to 0." | |
214 | } | |
215 | } | |
ecd3fd0f BR |
216 | # If allowing the inferior to have its own PTY then assign the inferior |
217 | # its own terminal device here. | |
218 | if { $separate_inferior_pty } { | |
219 | send_gdb "102-inferior-tty-set $mi_inferior_tty_name\n" | |
220 | gdb_expect 10 { | |
221 | -re ".*102\\\^done\r\n$mi_gdb_prompt$" { | |
222 | verbose "redirect inferior output to new terminal device." | |
223 | } | |
224 | timeout { | |
225 | warning "Couldn't redirect inferior output." 2 | |
226 | } | |
227 | } | |
228 | } | |
fb40c209 | 229 | |
fb40c209 AC |
230 | return 0; |
231 | } | |
232 | ||
79732189 AR |
233 | # |
234 | # Overridable function. You can override this function in your | |
235 | # baseboard file. | |
236 | # | |
237 | proc mi_gdb_start { args } { | |
238 | return [default_mi_gdb_start $args] | |
239 | } | |
240 | ||
fb40c209 AC |
241 | # Many of the tests depend on setting breakpoints at various places and |
242 | # running until that breakpoint is reached. At times, we want to start | |
243 | # with a clean-slate with respect to breakpoints, so this utility proc | |
244 | # lets us do this without duplicating this code everywhere. | |
245 | # | |
246 | ||
247 | proc mi_delete_breakpoints {} { | |
248 | global mi_gdb_prompt | |
249 | ||
250 | # FIXME: The mi operation won't accept a prompt back and will use the 'all' arg | |
251 | send_gdb "102-break-delete\n" | |
252 | gdb_expect 30 { | |
253 | -re "Delete all breakpoints.*y or n.*$" { | |
254 | send_gdb "y\n"; | |
255 | exp_continue | |
256 | } | |
39fb8e9e | 257 | -re "102-break-delete\r\n102\\\^done\r\n$mi_gdb_prompt$" { |
fb40c209 AC |
258 | # This happens if there were no breakpoints |
259 | } | |
f1c8a949 | 260 | timeout { perror "Delete all breakpoints in mi_delete_breakpoints (timeout)" ; return } |
fb40c209 AC |
261 | } |
262 | ||
263 | # The correct output is not "No breakpoints or watchpoints." but an | |
264 | # empty BreakpointTable. Also, a query is not acceptable with mi. | |
265 | send_gdb "103-break-list\n" | |
266 | gdb_expect 30 { | |
267 | -re "103-break-list\r\n103\\\^done,BreakpointTable=\{\}\r\n$mi_gdb_prompt$" {} | |
cff22675 | 268 | -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=\\\[\\\]\}" {} |
fb40c209 AC |
269 | -re "103-break-list\r\n103\\\^doneNo breakpoints or watchpoints.\r\n\r\n$mi_gdb_prompt$" {warning "Unexpected console text received"} |
270 | -re "$mi_gdb_prompt$" { perror "Breakpoints not deleted" ; return } | |
271 | -re "Delete all breakpoints.*or n.*$" { | |
272 | warning "Unexpected prompt for breakpoints deletion"; | |
273 | send_gdb "y\n"; | |
274 | exp_continue | |
275 | } | |
276 | timeout { perror "-break-list (timeout)" ; return } | |
277 | } | |
278 | } | |
279 | ||
280 | proc mi_gdb_reinitialize_dir { subdir } { | |
281 | global mi_gdb_prompt | |
da81390b | 282 | global MIFLAGS |
fb40c209 AC |
283 | |
284 | global suppress_flag | |
285 | if { $suppress_flag } { | |
286 | return | |
287 | } | |
288 | ||
289 | if [is_remote host] { | |
290 | return ""; | |
291 | } | |
292 | ||
da81390b JJ |
293 | if { $MIFLAGS == "-i=mi1" } { |
294 | send_gdb "104-environment-directory\n" | |
295 | gdb_expect 60 { | |
fb40c209 AC |
296 | -re ".*Reinitialize source path to empty.*y or n. " { |
297 | warning "Got confirmation prompt for dir reinitialization." | |
298 | send_gdb "y\n" | |
299 | gdb_expect 60 { | |
300 | -re "$mi_gdb_prompt$" {} | |
301 | timeout {error "Dir reinitialization failed (timeout)"} | |
302 | } | |
303 | } | |
304 | -re "$mi_gdb_prompt$" {} | |
305 | timeout {error "Dir reinitialization failed (timeout)"} | |
da81390b JJ |
306 | } |
307 | } else { | |
308 | send_gdb "104-environment-directory -r\n" | |
309 | gdb_expect 60 { | |
310 | -re "104\\\^done,source-path=.*\r\n$mi_gdb_prompt$" {} | |
311 | -re "$mi_gdb_prompt$" {} | |
312 | timeout {error "Dir reinitialization failed (timeout)"} | |
313 | } | |
fb40c209 AC |
314 | } |
315 | ||
316 | send_gdb "105-environment-directory $subdir\n" | |
317 | gdb_expect 60 { | |
318 | -re "Source directories searched.*$mi_gdb_prompt$" { | |
319 | verbose "Dir set to $subdir" | |
320 | } | |
da81390b | 321 | -re "105\\\^done.*\r\n$mi_gdb_prompt$" { |
fb40c209 AC |
322 | # FIXME: We return just the prompt for now. |
323 | verbose "Dir set to $subdir" | |
324 | # perror "Dir \"$subdir\" failed." | |
325 | } | |
326 | } | |
327 | } | |
328 | ||
da6012e5 DJ |
329 | # Send GDB the "target" command. |
330 | # FIXME: Some of these patterns are not appropriate for MI. Based on | |
331 | # config/monitor.exp:gdb_target_command. | |
332 | proc mi_gdb_target_cmd { targetname serialport } { | |
333 | global mi_gdb_prompt | |
334 | ||
ef783a7d | 335 | set serialport_re [string_to_regexp $serialport] |
da6012e5 DJ |
336 | for {set i 1} {$i <= 3} {incr i} { |
337 | send_gdb "47-target-select $targetname $serialport\n" | |
338 | gdb_expect 60 { | |
339 | -re "47\\^connected.*$mi_gdb_prompt$" { | |
340 | verbose "Set target to $targetname"; | |
341 | return 0; | |
342 | } | |
401ea829 JB |
343 | -re "unknown host.*$mi_gdb_prompt" { |
344 | verbose "Couldn't look up $serialport" | |
345 | } | |
da6012e5 DJ |
346 | -re "Couldn't establish connection to remote.*$mi_gdb_prompt$" { |
347 | verbose "Connection failed"; | |
348 | } | |
349 | -re "Remote MIPS debugging.*$mi_gdb_prompt$" { | |
350 | verbose "Set target to $targetname"; | |
351 | return 0; | |
352 | } | |
ef783a7d | 353 | -re "Remote debugging using .*$serialport_re.*$mi_gdb_prompt$" { |
da6012e5 DJ |
354 | verbose "Set target to $targetname"; |
355 | return 0; | |
356 | } | |
357 | -re "Remote target $targetname connected to.*$mi_gdb_prompt$" { | |
358 | verbose "Set target to $targetname"; | |
359 | return 0; | |
360 | } | |
361 | -re "Connected to.*$mi_gdb_prompt$" { | |
362 | verbose "Set target to $targetname"; | |
363 | return 0; | |
364 | } | |
365 | -re "Ending remote.*$mi_gdb_prompt$" { } | |
366 | -re "Connection refused.*$mi_gdb_prompt$" { | |
367 | verbose "Connection refused by remote target. Pausing, and trying again." | |
368 | sleep 5 | |
369 | continue | |
370 | } | |
371 | -re "Timeout reading from remote system.*$mi_gdb_prompt$" { | |
372 | verbose "Got timeout error from gdb."; | |
373 | } | |
374 | timeout { | |
375 | send_gdb "\ 3"; | |
376 | break | |
377 | } | |
378 | } | |
379 | } | |
380 | return 1 | |
381 | } | |
382 | ||
fb40c209 | 383 | # |
da6012e5 | 384 | # load a file into the debugger (file command only). |
fb40c209 AC |
385 | # return a -1 if anything goes wrong. |
386 | # | |
da6012e5 | 387 | proc mi_gdb_file_cmd { arg } { |
fb40c209 AC |
388 | global verbose |
389 | global loadpath | |
390 | global loadfile | |
391 | global GDB | |
392 | global mi_gdb_prompt | |
b741e217 | 393 | global last_loaded_file |
fb40c209 AC |
394 | upvar timeout timeout |
395 | ||
b741e217 | 396 | set last_loaded_file $arg |
b53f9b27 | 397 | |
da6012e5 DJ |
398 | if [is_remote host] { |
399 | set arg [remote_download host $arg]; | |
400 | if { $arg == "" } { | |
401 | error "download failed" | |
402 | return -1; | |
403 | } | |
404 | } | |
fb40c209 | 405 | |
fb40c209 AC |
406 | # FIXME: Several of these patterns are only acceptable for console |
407 | # output. Queries are an error for mi. | |
408 | send_gdb "105-file-exec-and-symbols $arg\n" | |
409 | gdb_expect 120 { | |
410 | -re "Reading symbols from.*done.*$mi_gdb_prompt$" { | |
411 | verbose "\t\tLoaded $arg into the $GDB" | |
da6012e5 | 412 | return 0 |
fb40c209 AC |
413 | } |
414 | -re "has no symbol-table.*$mi_gdb_prompt$" { | |
415 | perror "$arg wasn't compiled with \"-g\"" | |
416 | return -1 | |
417 | } | |
fb40c209 AC |
418 | -re "Load new symbol table from \".*\".*y or n. $" { |
419 | send_gdb "y\n" | |
420 | gdb_expect 120 { | |
421 | -re "Reading symbols from.*done.*$mi_gdb_prompt$" { | |
422 | verbose "\t\tLoaded $arg with new symbol table into $GDB" | |
423 | # All OK | |
424 | } | |
425 | timeout { | |
426 | perror "(timeout) Couldn't load $arg, other program already loaded." | |
427 | return -1 | |
428 | } | |
429 | } | |
430 | } | |
431 | -re "No such file or directory.*$mi_gdb_prompt$" { | |
432 | perror "($arg) No such file or directory\n" | |
433 | return -1 | |
434 | } | |
435 | -re "105-file-exec-and-symbols .*\r\n105\\\^done\r\n$mi_gdb_prompt$" { | |
da6012e5 DJ |
436 | # We (MI) are just giving the prompt back for now, instead of giving |
437 | # some acknowledgement. | |
438 | return 0 | |
439 | } | |
fb40c209 AC |
440 | timeout { |
441 | perror "couldn't load $arg into $GDB (timed out)." | |
442 | return -1 | |
443 | } | |
da6012e5 | 444 | eof { |
fb40c209 AC |
445 | # This is an attempt to detect a core dump, but seems not to |
446 | # work. Perhaps we need to match .* followed by eof, in which | |
447 | # gdb_expect does not seem to have a way to do that. | |
448 | perror "couldn't load $arg into $GDB (end of file)." | |
449 | return -1 | |
450 | } | |
451 | } | |
da6012e5 DJ |
452 | } |
453 | ||
454 | # | |
b741e217 | 455 | # connect to the target and download a file, if necessary. |
da6012e5 DJ |
456 | # return a -1 if anything goes wrong. |
457 | # | |
b741e217 | 458 | proc mi_gdb_target_load { } { |
da6012e5 DJ |
459 | global verbose |
460 | global loadpath | |
461 | global loadfile | |
462 | global GDB | |
463 | global mi_gdb_prompt | |
464 | upvar timeout timeout | |
465 | ||
da6012e5 | 466 | if { [info procs gdbserver_gdb_load] != "" } { |
2226f861 | 467 | mi_gdb_test "kill" ".*" "" |
b741e217 | 468 | set res [gdbserver_gdb_load] |
da6012e5 DJ |
469 | set protocol [lindex $res 0] |
470 | set gdbport [lindex $res 1] | |
471 | ||
472 | if { [mi_gdb_target_cmd $protocol $gdbport] != 0 } { | |
473 | return -1 | |
474 | } | |
475 | } elseif { [info procs send_target_sid] != "" } { | |
fb40c209 | 476 | # For SID, things get complex |
2b97317d KB |
477 | send_gdb "kill\n" |
478 | gdb_expect 10 { | |
479 | -re ".*$mi_gdb_prompt$" | |
480 | } | |
fb40c209 AC |
481 | send_target_sid |
482 | gdb_expect 60 { | |
2f168eed | 483 | -re "\\^done.*$mi_gdb_prompt$" { |
fb40c209 AC |
484 | } |
485 | timeout { | |
486 | perror "Unable to connect to SID target" | |
487 | return -1 | |
488 | } | |
489 | } | |
490 | send_gdb "48-target-download\n" | |
491 | gdb_expect 10 { | |
492 | -re "48\\^done.*$mi_gdb_prompt$" { | |
493 | } | |
494 | timeout { | |
495 | perror "Unable to download to SID target" | |
496 | return -1 | |
497 | } | |
498 | } | |
499 | } elseif { [target_info protocol] == "sim" } { | |
500 | # For the simulator, just connect to it directly. | |
501 | send_gdb "47-target-select sim\n" | |
502 | gdb_expect 10 { | |
503 | -re "47\\^connected.*$mi_gdb_prompt$" { | |
504 | } | |
505 | timeout { | |
506 | perror "Unable to select sim target" | |
507 | return -1 | |
508 | } | |
509 | } | |
510 | send_gdb "48-target-download\n" | |
511 | gdb_expect 10 { | |
512 | -re "48\\^done.*$mi_gdb_prompt$" { | |
513 | } | |
514 | timeout { | |
515 | perror "Unable to download to sim target" | |
516 | return -1 | |
517 | } | |
518 | } | |
b53f9b27 MS |
519 | } elseif { [target_info gdb_protocol] == "remote" } { |
520 | # remote targets | |
8e3049aa PB |
521 | if { [mi_gdb_target_cmd "remote" [target_info netport]] != 0 } { |
522 | perror "Unable to connect to remote target" | |
523 | return -1 | |
b53f9b27 MS |
524 | } |
525 | send_gdb "48-target-download\n" | |
526 | gdb_expect 10 { | |
527 | -re "48\\^done.*$mi_gdb_prompt$" { | |
528 | } | |
529 | timeout { | |
530 | perror "Unable to download to remote target" | |
531 | return -1 | |
532 | } | |
533 | } | |
fb40c209 AC |
534 | } |
535 | return 0 | |
536 | } | |
537 | ||
b741e217 DJ |
538 | # |
539 | # load a file into the debugger. | |
540 | # return a -1 if anything goes wrong. | |
541 | # | |
542 | proc mi_gdb_load { arg } { | |
543 | if { $arg != "" } { | |
544 | return [mi_gdb_file_cmd $arg] | |
545 | } | |
546 | return 0 | |
547 | } | |
548 | ||
ecd3fd0f BR |
549 | # mi_gdb_test COMMAND PATTERN MESSAGE [IPATTERN] -- send a command to gdb; |
550 | # test the result. | |
fb40c209 AC |
551 | # |
552 | # COMMAND is the command to execute, send to GDB with send_gdb. If | |
553 | # this is the null string no command is sent. | |
554 | # PATTERN is the pattern to match for a PASS, and must NOT include | |
555 | # the \r\n sequence immediately before the gdb prompt. | |
f1ea48cb BR |
556 | # MESSAGE is the message to be printed. (If this is the empty string, |
557 | # then sometimes we don't call pass or fail at all; I don't | |
558 | # understand this at all.) | |
ecd3fd0f BR |
559 | # IPATTERN is the pattern to match for the inferior's output. This parameter |
560 | # is optional. If present, it will produce a PASS if the match is | |
561 | # successful, and a FAIL if unsuccessful. | |
fb40c209 AC |
562 | # |
563 | # Returns: | |
564 | # 1 if the test failed, | |
565 | # 0 if the test passes, | |
566 | # -1 if there was an internal error. | |
567 | # | |
568 | proc mi_gdb_test { args } { | |
569 | global verbose | |
570 | global mi_gdb_prompt | |
07c98896 | 571 | global GDB expect_out |
fb40c209 AC |
572 | upvar timeout timeout |
573 | ||
fb40c209 AC |
574 | set command [lindex $args 0] |
575 | set pattern [lindex $args 1] | |
f1ea48cb | 576 | set message [lindex $args 2] |
fb40c209 | 577 | |
ecd3fd0f BR |
578 | if [llength $args]==4 { |
579 | set ipattern [lindex $args 3] | |
580 | } | |
581 | ||
fb40c209 AC |
582 | if [llength $args]==5 { |
583 | set question_string [lindex $args 3]; | |
584 | set response_string [lindex $args 4]; | |
585 | } else { | |
586 | set question_string "^FOOBAR$" | |
587 | } | |
588 | ||
589 | if $verbose>2 then { | |
590 | send_user "Sending \"$command\" to gdb\n" | |
591 | send_user "Looking to match \"$pattern\"\n" | |
592 | send_user "Message is \"$message\"\n" | |
593 | } | |
594 | ||
595 | set result -1 | |
596 | set string "${command}\n"; | |
39fb8e9e BR |
597 | set string_regex [string_to_regexp $command] |
598 | ||
fb40c209 AC |
599 | if { $command != "" } { |
600 | while { "$string" != "" } { | |
601 | set foo [string first "\n" "$string"]; | |
602 | set len [string length "$string"]; | |
603 | if { $foo < [expr $len - 1] } { | |
604 | set str [string range "$string" 0 $foo]; | |
605 | if { [send_gdb "$str"] != "" } { | |
606 | global suppress_flag; | |
607 | ||
608 | if { ! $suppress_flag } { | |
609 | perror "Couldn't send $command to GDB."; | |
610 | } | |
611 | fail "$message"; | |
612 | return $result; | |
613 | } | |
614 | gdb_expect 2 { | |
615 | -re "\[\r\n\]" { } | |
616 | timeout { } | |
617 | } | |
618 | set string [string range "$string" [expr $foo + 1] end]; | |
619 | } else { | |
620 | break; | |
621 | } | |
622 | } | |
623 | if { "$string" != "" } { | |
624 | if { [send_gdb "$string"] != "" } { | |
625 | global suppress_flag; | |
626 | ||
627 | if { ! $suppress_flag } { | |
628 | perror "Couldn't send $command to GDB."; | |
629 | } | |
630 | fail "$message"; | |
631 | return $result; | |
632 | } | |
633 | } | |
634 | } | |
635 | ||
636 | if [info exists timeout] { | |
637 | set tmt $timeout; | |
638 | } else { | |
639 | global timeout; | |
640 | if [info exists timeout] { | |
641 | set tmt $timeout; | |
642 | } else { | |
643 | set tmt 60; | |
644 | } | |
645 | } | |
646 | gdb_expect $tmt { | |
647 | -re "\\*\\*\\* DOSEXIT code.*" { | |
648 | if { $message != "" } { | |
649 | fail "$message"; | |
650 | } | |
651 | gdb_suppress_entire_file "GDB died"; | |
652 | return -1; | |
653 | } | |
654 | -re "Ending remote debugging.*$mi_gdb_prompt\[ \]*$" { | |
655 | if ![isnative] then { | |
656 | warning "Can`t communicate to remote target." | |
657 | } | |
658 | gdb_exit | |
659 | gdb_start | |
660 | set result -1 | |
7ddebc7e | 661 | } |
39fb8e9e BR |
662 | -re "^($string_regex\[\r\n\]+)?($pattern\[\r\n\]+$mi_gdb_prompt\[ \]*)" { |
663 | # At this point, $expect_out(1,string) is the MI input command. | |
664 | # and $expect_out(2,string) is the MI output command. | |
665 | # If $expect_out(1,string) is "", then there was no MI input command here. | |
666 | ||
40e55bef BR |
667 | # NOTE, there is no trailing anchor because with GDB/MI, |
668 | # asynchronous responses can happen at any point, causing more | |
669 | # data to be available. Normally an anchor is used to make | |
670 | # sure the end of the output is matched, however, $mi_gdb_prompt | |
671 | # is just as good of an anchor since mi_gdb_test is meant to | |
672 | # match a single mi output command. If a second GDB/MI output | |
673 | # response is sent, it will be in the buffer for the next | |
674 | # time mi_gdb_test is called. | |
7ddebc7e KS |
675 | if ![string match "" $message] then { |
676 | pass "$message" | |
677 | } | |
678 | set result 0 | |
fb40c209 AC |
679 | } |
680 | -re "(${question_string})$" { | |
681 | send_gdb "$response_string\n"; | |
682 | exp_continue; | |
683 | } | |
684 | -re "Undefined.* command:.*$mi_gdb_prompt\[ \]*$" { | |
685 | perror "Undefined command \"$command\"." | |
686 | fail "$message" | |
687 | set result 1 | |
688 | } | |
689 | -re "Ambiguous command.*$mi_gdb_prompt\[ \]*$" { | |
690 | perror "\"$command\" is not a unique command name." | |
691 | fail "$message" | |
692 | set result 1 | |
fb40c209 AC |
693 | } |
694 | -re "Program exited with code \[0-9\]+.*$mi_gdb_prompt\[ \]*$" { | |
695 | if ![string match "" $message] then { | |
ed4c619a | 696 | set errmsg "$message (the program exited)" |
fb40c209 | 697 | } else { |
ed4c619a | 698 | set errmsg "$command (the program exited)" |
fb40c209 AC |
699 | } |
700 | fail "$errmsg" | |
701 | return -1 | |
702 | } | |
703 | -re "The program is not being run.*$mi_gdb_prompt\[ \]*$" { | |
704 | if ![string match "" $message] then { | |
ed4c619a | 705 | set errmsg "$message (the program is no longer running)" |
fb40c209 | 706 | } else { |
ed4c619a | 707 | set errmsg "$command (the program is no longer running)" |
fb40c209 AC |
708 | } |
709 | fail "$errmsg" | |
710 | return -1 | |
711 | } | |
712 | -re ".*$mi_gdb_prompt\[ \]*$" { | |
713 | if ![string match "" $message] then { | |
714 | fail "$message" | |
715 | } | |
716 | set result 1 | |
717 | } | |
718 | "<return>" { | |
719 | send_gdb "\n" | |
720 | perror "Window too small." | |
721 | fail "$message" | |
722 | } | |
723 | -re "\\(y or n\\) " { | |
724 | send_gdb "n\n" | |
725 | perror "Got interactive prompt." | |
726 | fail "$message" | |
727 | } | |
728 | eof { | |
729 | perror "Process no longer exists" | |
730 | if { $message != "" } { | |
731 | fail "$message" | |
732 | } | |
733 | return -1 | |
734 | } | |
735 | full_buffer { | |
736 | perror "internal buffer is full." | |
737 | fail "$message" | |
738 | } | |
739 | timeout { | |
740 | if ![string match "" $message] then { | |
741 | fail "$message (timeout)" | |
742 | } | |
743 | set result 1 | |
744 | } | |
745 | } | |
ecd3fd0f BR |
746 | |
747 | # If the GDB output matched, compare the inferior output. | |
748 | if { $result == 0 } { | |
749 | if [ info exists ipattern ] { | |
d084b331 DJ |
750 | if { ![target_info exists gdb,noinferiorio] } { |
751 | global mi_inferior_spawn_id | |
752 | expect { | |
753 | -i $mi_inferior_spawn_id -re "$ipattern" { | |
754 | pass "$message inferior output" | |
755 | } | |
756 | timeout { | |
757 | fail "$message inferior output (timeout)" | |
758 | set result 1 | |
759 | } | |
ecd3fd0f | 760 | } |
d084b331 DJ |
761 | } else { |
762 | unsupported "$message inferior output" | |
ecd3fd0f BR |
763 | } |
764 | } | |
765 | } | |
766 | ||
fb40c209 AC |
767 | return $result |
768 | } | |
769 | ||
770 | # | |
771 | # MI run command. (A modified version of gdb_run_cmd) | |
772 | # | |
773 | ||
774 | # In patterns, the newline sequence ``\r\n'' is matched explicitly as | |
775 | # ``.*$'' could swallow up output that we attempt to match elsewhere. | |
776 | ||
777 | proc mi_run_cmd {args} { | |
778 | global suppress_flag | |
779 | if { $suppress_flag } { | |
780 | return -1 | |
781 | } | |
782 | global mi_gdb_prompt | |
783 | ||
784 | if [target_info exists gdb_init_command] { | |
785 | send_gdb "[target_info gdb_init_command]\n"; | |
786 | gdb_expect 30 { | |
787 | -re "$mi_gdb_prompt$" { } | |
788 | default { | |
789 | perror "gdb_init_command for target failed"; | |
790 | return; | |
791 | } | |
792 | } | |
793 | } | |
794 | ||
b741e217 DJ |
795 | if { [mi_gdb_target_load] < 0 } { |
796 | return | |
797 | } | |
798 | ||
fb40c209 AC |
799 | if [target_info exists use_gdb_stub] { |
800 | if [target_info exists gdb,do_reload_on_run] { | |
fb40c209 AC |
801 | send_gdb "000-exec-continue\n"; |
802 | gdb_expect 60 { | |
1df0c130 | 803 | -re "000\\^running\[\r\n\]+$mi_gdb_prompt$" {} |
fb40c209 AC |
804 | default {} |
805 | } | |
806 | return; | |
807 | } | |
6a90e1d0 AC |
808 | |
809 | if [target_info exists gdb,start_symbol] { | |
810 | set start [target_info gdb,start_symbol]; | |
811 | } else { | |
812 | set start "start"; | |
813 | } | |
814 | ||
815 | # HACK: Should either use 000-jump or fix the target code | |
816 | # to better handle RUN. | |
817 | send_gdb "jump *$start\n" | |
818 | warning "Using CLI jump command, expect run-to-main FAIL" | |
819 | return | |
fb40c209 AC |
820 | } |
821 | ||
822 | send_gdb "000-exec-run $args\n" | |
823 | gdb_expect { | |
824 | -re "000\\^running\r\n${mi_gdb_prompt}" { | |
825 | } | |
826 | timeout { | |
827 | perror "Unable to start target" | |
828 | return | |
829 | } | |
830 | } | |
2d0720d9 | 831 | # NOTE: Shortly after this there will be a ``000*stopped,...(gdb)'' |
fb40c209 AC |
832 | } |
833 | ||
834 | # | |
835 | # Just like run-to-main but works with the MI interface | |
836 | # | |
837 | ||
838 | proc mi_run_to_main { } { | |
839 | global suppress_flag | |
840 | if { $suppress_flag } { | |
841 | return -1 | |
842 | } | |
843 | ||
fb40c209 AC |
844 | global srcdir |
845 | global subdir | |
846 | global binfile | |
847 | global srcfile | |
848 | ||
fb40c209 AC |
849 | mi_delete_breakpoints |
850 | mi_gdb_reinitialize_dir $srcdir/$subdir | |
851 | mi_gdb_load ${binfile} | |
852 | ||
08b468e0 KS |
853 | mi_runto main |
854 | } | |
fb40c209 | 855 | |
08b468e0 KS |
856 | |
857 | # Just like gdb's "runto" proc, it will run the target to a given | |
858 | # function. The big difference here between mi_runto and mi_execute_to | |
859 | # is that mi_execute_to must have the inferior running already. This | |
860 | # proc will (like gdb's runto) (re)start the inferior, too. | |
861 | # | |
862 | # FUNC is the linespec of the place to stop (it inserts a breakpoint here). | |
863 | # It returns: | |
864 | # -1 if test suppressed, failed, timedout | |
865 | # 0 if test passed | |
866 | ||
f7e97bb3 | 867 | proc mi_runto_helper {func run_or_continue} { |
08b468e0 KS |
868 | global suppress_flag |
869 | if { $suppress_flag } { | |
870 | return -1 | |
871 | } | |
872 | ||
873 | global mi_gdb_prompt expect_out | |
76ff342d | 874 | global hex decimal fullname_syntax |
08b468e0 KS |
875 | |
876 | set test "mi runto $func" | |
038224f6 VP |
877 | mi_gdb_test "200-break-insert -t $func" \ |
878 | "200\\^done,bkpt=\{number=\"\[0-9\]+\",type=\"breakpoint\",disp=\"del\",enabled=\"y\",addr=\"$hex\",func=\"$func\(\\\(.*\\\)\)?\",file=\".*\",line=\"\[0-9\]*\",times=\"0\"\}" \ | |
08b468e0 KS |
879 | "breakpoint at $func" |
880 | ||
881 | if {![regexp {number="[0-9]+"} $expect_out(buffer) str] | |
882 | || ![scan $str {number="%d"} bkptno]} { | |
883 | set bkptno {[0-9]+} | |
884 | } | |
885 | ||
f7e97bb3 VP |
886 | if {$run_or_continue == "run"} { |
887 | mi_run_cmd | |
888 | } else { | |
74a44383 DJ |
889 | send_gdb "000-exec-continue\n" |
890 | gdb_expect { | |
891 | -re "000\\^running\r\n${mi_gdb_prompt}" { | |
892 | } | |
893 | timeout { | |
894 | fail "$test" | |
895 | return -1 | |
896 | } | |
897 | } | |
f7e97bb3 | 898 | } |
74a44383 | 899 | |
08b468e0 | 900 | gdb_expect { |
038224f6 | 901 | -re ".*000\\*stopped,thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\"$func\",args=\(\\\[.*\\\]\|\{.*\}\),file=\".*\",fullname=\"${fullname_syntax}.*\",line=\"\[0-9\]*\"\}\r\n$mi_gdb_prompt$" { |
08b468e0 KS |
902 | pass "$test" |
903 | return 0 | |
904 | } | |
905 | -re ".*$mi_gdb_prompt$" { | |
906 | fail "$test (2)" | |
907 | } | |
908 | timeout { | |
909 | fail "$test (timeout)" | |
910 | return -1 | |
911 | } | |
912 | } | |
fb40c209 AC |
913 | } |
914 | ||
f7e97bb3 VP |
915 | proc mi_runto {func} { |
916 | mi_runto_helper $func "run" | |
917 | } | |
fb40c209 AC |
918 | |
919 | # Next to the next statement | |
08b468e0 | 920 | # For return values, see mi_execute_to_helper |
fb40c209 AC |
921 | |
922 | proc mi_next { test } { | |
dc360f58 | 923 | return [mi_next_to {.*} {.*} {.*} {.*} $test] |
fb40c209 AC |
924 | } |
925 | ||
926 | ||
927 | # Step to the next statement | |
08b468e0 | 928 | # For return values, see mi_execute_to_helper |
fb40c209 AC |
929 | |
930 | proc mi_step { test } { | |
dc360f58 | 931 | return [mi_step_to {.*} {.*} {.*} {.*} $test] |
fb40c209 | 932 | } |
dcf95b47 DJ |
933 | |
934 | # cmd should not include the number or newline (i.e. "exec-step 3", not | |
935 | # "220-exec-step 3\n" | |
936 | ||
1902c51f DJ |
937 | # Can not match -re ".*\r\n${mi_gdb_prompt}", because of false positives |
938 | # after the first prompt is printed. | |
939 | ||
08b468e0 | 940 | proc mi_execute_to_helper { cmd reason func args file line extra test } { |
dcf95b47 DJ |
941 | global suppress_flag |
942 | if { $suppress_flag } { | |
943 | return -1 | |
944 | } | |
945 | global mi_gdb_prompt | |
946 | global hex | |
947 | global decimal | |
76ff342d | 948 | global fullname_syntax |
dcf95b47 DJ |
949 | send_gdb "220-$cmd\n" |
950 | gdb_expect { | |
39fb8e9e | 951 | -re "220\\^running\r\n${mi_gdb_prompt}.*220\\*stopped,reason=\"$reason\",thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\"$func\",args=$args,file=\".*$file\",fullname=\"${fullname_syntax}$file\",line=\"$line\"\}$extra\r\n$mi_gdb_prompt$" { |
dcf95b47 DJ |
952 | pass "$test" |
953 | return 0 | |
954 | } | |
39fb8e9e | 955 | -re "220\\^running\r\n${mi_gdb_prompt}.*220\\*stopped,reason=\"$reason\",thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\".*\",args=\[\\\[\{\].*\[\\\]\}\],file=\".*\",fullname=\"${fullname_syntax}.*\",line=\"\[0-9\]*\"\}.*\r\n$mi_gdb_prompt$" { |
dcf95b47 DJ |
956 | fail "$test (stopped at wrong place)" |
957 | return -1 | |
958 | } | |
959 | -re "220\\^running\r\n${mi_gdb_prompt}.*\r\n${mi_gdb_prompt}$" { | |
960 | fail "$test (unknown output after running)" | |
961 | return -1 | |
962 | } | |
dcf95b47 DJ |
963 | timeout { |
964 | fail "$test (timeout)" | |
965 | return -1 | |
966 | } | |
967 | } | |
968 | } | |
969 | ||
08b468e0 KS |
970 | proc mi_execute_to { cmd reason func args file line extra test } { |
971 | mi_execute_to_helper "$cmd" "$reason" "$func" "\\\[$args\\\]" \ | |
dcf95b47 DJ |
972 | "$file" "$line" "$extra" "$test" |
973 | } | |
974 | ||
975 | proc mi_next_to { func args file line test } { | |
08b468e0 | 976 | mi_execute_to "exec-next" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
977 | "$file" "$line" "" "$test" |
978 | } | |
979 | ||
980 | proc mi_step_to { func args file line test } { | |
08b468e0 | 981 | mi_execute_to "exec-step" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
982 | "$file" "$line" "" "$test" |
983 | } | |
984 | ||
985 | proc mi_finish_to { func args file line result ret test } { | |
08b468e0 | 986 | mi_execute_to "exec-finish" "function-finished" "$func" "$args" \ |
dcf95b47 DJ |
987 | "$file" "$line" \ |
988 | ",gdb-result-var=\"$result\",return-value=\"$ret\"" \ | |
989 | "$test" | |
990 | } | |
991 | ||
f7e97bb3 VP |
992 | proc mi_continue_to {func} { |
993 | mi_runto_helper $func "continue" | |
dcf95b47 DJ |
994 | } |
995 | ||
08b468e0 KS |
996 | proc mi0_execute_to { cmd reason func args file line extra test } { |
997 | mi_execute_to_helper "$cmd" "$reason" "$func" "\{$args\}" \ | |
dcf95b47 DJ |
998 | "$file" "$line" "$extra" "$test" |
999 | } | |
1000 | ||
1001 | proc mi0_next_to { func args file line test } { | |
08b468e0 | 1002 | mi0_execute_to "exec-next" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
1003 | "$file" "$line" "" "$test" |
1004 | } | |
1005 | ||
1006 | proc mi0_step_to { func args file line test } { | |
08b468e0 | 1007 | mi0_execute_to "exec-step" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
1008 | "$file" "$line" "" "$test" |
1009 | } | |
1010 | ||
1011 | proc mi0_finish_to { func args file line result ret test } { | |
08b468e0 | 1012 | mi0_execute_to "exec-finish" "function-finished" "$func" "$args" \ |
dcf95b47 DJ |
1013 | "$file" "$line" \ |
1014 | ",gdb-result-var=\"$result\",return-value=\"$ret\"" \ | |
1015 | "$test" | |
1016 | } | |
1017 | ||
1018 | proc mi0_continue_to { bkptno func args file line test } { | |
08b468e0 | 1019 | mi0_execute_to "exec-continue" "breakpoint-hit\",bkptno=\"$bkptno" \ |
dcf95b47 DJ |
1020 | "$func" "$args" "$file" "$line" "" "$test" |
1021 | } | |
b26ed50d VP |
1022 | |
1023 | # Creates varobj named NAME for EXPRESSION. | |
1024 | # Name cannot be "-". | |
1025 | proc mi_create_varobj { name expression testname } { | |
1026 | mi_gdb_test "-var-create $name * $expression" \ | |
983c9c8f | 1027 | "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=.*" \ |
b26ed50d VP |
1028 | $testname |
1029 | } | |
1030 | ||
9e8e3afe VP |
1031 | # Same as mi_create_varobj, but also checks the reported type |
1032 | # of the varobj. | |
1033 | proc mi_create_varobj_checked { name expression type testname } { | |
1034 | mi_gdb_test "-var-create $name * $expression" \ | |
1035 | "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=\"$type\".*" \ | |
1036 | $testname | |
1037 | } | |
1038 | ||
6e2a9270 VP |
1039 | # Deletes the specified NAME. |
1040 | proc mi_delete_varobj { name testname } { | |
1041 | mi_gdb_test "-var-delete $name" \ | |
1042 | "\\^done,ndeleted=.*" \ | |
1043 | $testname | |
1044 | } | |
1045 | ||
b26ed50d VP |
1046 | # Updates varobj named NAME and checks that all varobjs in EXPECTED |
1047 | # are reported as updated, and no other varobj is updated. | |
1048 | # Assumes that no varobj is out of scope and that no varobj changes | |
1049 | # types. | |
1050 | proc mi_varobj_update { name expected testname } { | |
1051 | set er "\\^done,changelist=\\\[" | |
1052 | set first 1 | |
1053 | foreach item $expected { | |
1054 | set v "{name=\"$item\",in_scope=\"true\",type_changed=\"false\"}" | |
25d5ea92 | 1055 | if {$first == 1} { |
b26ed50d | 1056 | set er "$er$v" |
25d5ea92 | 1057 | set first 0 |
b26ed50d VP |
1058 | } else { |
1059 | set er "$er,$v" | |
1060 | } | |
1061 | } | |
1062 | set er "$er\\\]" | |
1063 | ||
1064 | verbose -log "Expecting: $er" 2 | |
1065 | mi_gdb_test "-var-update $name" $er $testname | |
1066 | } | |
1067 | ||
1068 | proc mi_check_varobj_value { name value testname } { | |
1069 | ||
1070 | mi_gdb_test "-var-evaluate-expression $name" \ | |
1071 | "\\^done,value=\"$value\"" \ | |
1072 | $testname | |
1073 | } | |
038224f6 VP |
1074 | |
1075 | # Check the results of the: | |
1076 | # | |
1077 | # -var-list-children VARNAME | |
1078 | # | |
1079 | # command. The CHILDREN parement should be a list of lists. | |
1080 | # Each inner list can have either 3 or 4 elements, describing | |
1081 | # fields that gdb is expected to report for child variable object, | |
1082 | # in the following order | |
1083 | # | |
1084 | # - Name | |
1085 | # - Expression | |
1086 | # - Number of children | |
1087 | # - Type | |
1088 | # | |
1089 | # If inner list has 3 elements, the gdb is expected to output no | |
9e8e3afe VP |
1090 | # type for a child and no value. |
1091 | # | |
1092 | # If the inner list has 4 elements, gdb output is expected to | |
1093 | # have no value. | |
038224f6 VP |
1094 | # |
1095 | proc mi_list_varobj_children { varname children testname } { | |
1096 | ||
9e8e3afe VP |
1097 | set options "" |
1098 | if {[llength $varname] == 2} { | |
1099 | set options [lindex $varname 1] | |
1100 | set varname [lindex $varname 0] | |
1101 | } | |
1102 | ||
038224f6 VP |
1103 | set numchildren [llength $children] |
1104 | set children_exp {} | |
1105 | set whatever "\"\[^\"\]+\"" | |
1106 | ||
1107 | foreach item $children { | |
1108 | ||
1109 | set name [lindex $item 0] | |
1110 | set exp [lindex $item 1] | |
1111 | set numchild [lindex $item 2] | |
9e8e3afe | 1112 | if {[llength $item] == 5} { |
038224f6 | 1113 | set type [lindex $item 3] |
9e8e3afe | 1114 | set value [lindex $item 4] |
038224f6 VP |
1115 | |
1116 | lappend children_exp\ | |
9e8e3afe VP |
1117 | "child={name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",value=\"$value\",type=\"$type\"\(,thread-id=\"\[0-9\]+\")?}" |
1118 | } elseif {[llength $item] == 4} { | |
1119 | set type [lindex $item 3] | |
1120 | ||
1121 | lappend children_exp\ | |
1122 | "child={name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",type=\"$type\"\(,thread-id=\"\[0-9\]+\")?}" | |
038224f6 VP |
1123 | } else { |
1124 | lappend children_exp\ | |
9e8e3afe | 1125 | "child={name=\"$name\",exp=\"$exp\",numchild=\"$numchild\"(,thread-id=\"\[0-9\]+\")?}" |
038224f6 VP |
1126 | } |
1127 | } | |
1128 | set children_exp_j [join $children_exp ","] | |
9e8e3afe VP |
1129 | if {$numchildren} { |
1130 | set expected "\\^done,numchild=\".*\",children=\\\[$children_exp_j.*\\\]" | |
1131 | } { | |
1132 | set expected "\\^done,numchild=\"0\"" | |
1133 | } | |
038224f6 VP |
1134 | |
1135 | verbose -log "Expecting: $expected" | |
1136 | ||
9e8e3afe VP |
1137 | mi_gdb_test "-var-list-children $options $varname" $expected $testname |
1138 | } | |
1139 | ||
1140 | # Verifies that variable object VARNAME has NUMBER children, | |
1141 | # where each one is named $VARNAME.<index-of-child> and has type TYPE. | |
1142 | proc mi_list_array_varobj_children { varname number type testname } { | |
1143 | set t {} | |
1144 | for {set i 0} {$i < $number} {incr i} { | |
1145 | lappend t [list $varname.$i $i 0 $type] | |
1146 | } | |
1147 | mi_list_varobj_children $varname $t $testname | |
038224f6 | 1148 | } |
2d0720d9 VP |
1149 | |
1150 | # A list of two-element lists. First element of each list is | |
1151 | # a Tcl statement, and the second element is the line | |
1152 | # number of source C file where the statement originates. | |
1153 | set mi_autotest_data "" | |
1154 | # The name of the source file for autotesting. | |
1155 | set mi_autotest_source "" | |
1156 | ||
1157 | proc count_newlines { string } { | |
1158 | return [regexp -all "\n" $string] | |
1159 | } | |
1160 | ||
1161 | # Prepares for running inline tests in FILENAME. | |
1162 | # See comments for mi_run_inline_test for detailed | |
1163 | # explanation of the idea and syntax. | |
1164 | proc mi_prepare_inline_tests { filename } { | |
1165 | ||
1166 | global srcdir | |
1167 | global subdir | |
1168 | global mi_autotest_source | |
1169 | global mi_autotest_data | |
1170 | ||
1171 | set mi_autotest_data {} | |
1172 | ||
1173 | set mi_autotest_source $filename | |
1174 | ||
1175 | if { ! [regexp "^/" "$filename"] } then { | |
1176 | set filename "$srcdir/$subdir/$filename" | |
1177 | } | |
1178 | ||
1179 | set chan [open $filename] | |
1180 | set content [read $chan] | |
1181 | set line_number 1 | |
1182 | while {1} { | |
1183 | set start [string first "/*:" $content] | |
1184 | if {$start != -1} { | |
1185 | set end [string first ":*/" $content] | |
1186 | if {$end == -1} { | |
1187 | error "Unterminated special comment in $filename" | |
1188 | } | |
1189 | ||
1190 | set prefix [string range $content 0 $start] | |
1191 | set prefix_newlines [count_newlines $prefix] | |
1192 | ||
1193 | set line_number [expr $line_number+$prefix_newlines] | |
1194 | set comment_line $line_number | |
1195 | ||
1196 | set comment [string range $content [expr $start+3] [expr $end-1]] | |
1197 | ||
1198 | set comment_newlines [count_newlines $comment] | |
1199 | set line_number [expr $line_number+$comment_newlines] | |
1200 | ||
1201 | set comment [string trim $comment] | |
1202 | set content [string range $content [expr $end+3] \ | |
1203 | [string length $content]] | |
1204 | lappend mi_autotest_data [list $comment $comment_line] | |
1205 | } else { | |
1206 | break | |
1207 | } | |
1208 | } | |
1209 | close $chan | |
1210 | } | |
1211 | ||
1212 | # Helper to mi_run_inline_test below. | |
1213 | # Return the list of all (statement,line_number) lists | |
1214 | # that comprise TESTCASE. The begin and end markers | |
1215 | # are not included. | |
1216 | proc mi_get_inline_test {testcase} { | |
1217 | ||
1218 | global mi_gdb_prompt | |
1219 | global mi_autotest_data | |
1220 | global mi_autotest_source | |
1221 | ||
1222 | set result {} | |
1223 | ||
1224 | set seen_begin 0 | |
1225 | set seen_end 0 | |
1226 | foreach l $mi_autotest_data { | |
1227 | ||
1228 | set comment [lindex $l 0] | |
1229 | ||
1230 | if {$comment == "BEGIN: $testcase"} { | |
1231 | set seen_begin 1 | |
1232 | } elseif {$comment == "END: $testcase"} { | |
1233 | set seen_end 1 | |
1234 | break | |
1235 | } elseif {$seen_begin==1} { | |
1236 | lappend result $l | |
1237 | } | |
1238 | } | |
1239 | ||
1240 | if {$seen_begin == 0} { | |
1241 | error "Autotest $testcase not found" | |
1242 | } | |
1243 | ||
1244 | if {$seen_begin == 1 && $seen_end == 0} { | |
1245 | error "Missing end marker for test $testcase" | |
1246 | } | |
1247 | ||
1248 | return $result | |
1249 | } | |
1250 | ||
1251 | # Sets temporary breakpoint at LOCATION. | |
1252 | proc mi_tbreak {location} { | |
1253 | ||
1254 | global mi_gdb_prompt | |
1255 | ||
1256 | mi_gdb_test "-break-insert -t $location" \ | |
1257 | {\^done,bkpt=.*} \ | |
1258 | "run to $location (set breakpoint)" | |
1259 | } | |
1260 | ||
1261 | # Send COMMAND that must be a command that resumes | |
1262 | # the inferiour (run/continue/next/etc) and consumes | |
1263 | # the "^running" output from it. | |
1264 | proc mi_send_resuming_command {command test} { | |
1265 | ||
1266 | global mi_gdb_prompt | |
1267 | ||
1268 | send_gdb "220-$command\n" | |
1269 | gdb_expect { | |
1270 | -re "220\\^running\r\n${mi_gdb_prompt}" { | |
1271 | } | |
1272 | timeout { | |
1273 | fail $test | |
1274 | } | |
1275 | } | |
1276 | } | |
1277 | ||
1278 | # Helper to mi_run_inline_test below. | |
1279 | # Sets a temporary breakpoint at LOCATION and runs | |
1280 | # the program using COMMAND. When the program is stopped | |
1281 | # returns the line at which it. Returns -1 if line cannot | |
1282 | # be determined. | |
1283 | # Does not check that the line is the same as requested. | |
1284 | # The caller can check itself if required. | |
a73bafbc | 1285 | proc mi_continue_to_line {location test} { |
2d0720d9 VP |
1286 | |
1287 | mi_tbreak $location | |
1288 | mi_send_resuming_command "exec-continue" "run to $location (exec-continue)" | |
a73bafbc | 1289 | return [mi_wait_for_stop $test] |
2d0720d9 VP |
1290 | } |
1291 | ||
1292 | # Wait until gdb prints the current line. | |
1293 | proc mi_wait_for_stop {test} { | |
1294 | ||
1295 | global mi_gdb_prompt | |
1296 | ||
1297 | gdb_expect { | |
1298 | -re ".*line=\"(.*)\".*\r\n$mi_gdb_prompt$" { | |
1299 | return $expect_out(1,string) | |
1300 | } | |
1301 | -re ".*$mi_gdb_prompt$" { | |
1302 | fail "wait for stop ($test)" | |
1303 | } | |
1304 | timeout { | |
1305 | fail "wait for stop ($test)" | |
1306 | } | |
1307 | } | |
1308 | } | |
1309 | ||
1310 | # Run a MI test embedded in comments in a C file. | |
1311 | # The C file should contain special comments in the following | |
1312 | # three forms: | |
1313 | # | |
1314 | # /*: BEGIN: testname :*/ | |
1315 | # /*: <Tcl statements> :*/ | |
1316 | # /*: END: testname :*/ | |
1317 | # | |
1318 | # This procedure find the begin and end marker for the requested | |
1319 | # test. Then, a temporary breakpoint is set at the begin | |
1320 | # marker and the program is run (from start). | |
1321 | # | |
1322 | # After that, for each special comment between the begin and end | |
1323 | # marker, the Tcl statements are executed. It is assumed that | |
1324 | # for each comment, the immediately preceding line is executable | |
1325 | # C statement. Then, gdb will be single-stepped until that | |
1326 | # preceding C statement is executed, and after that the | |
1327 | # Tcl statements in the comment will be executed. | |
1328 | # | |
1329 | # For example: | |
1330 | # | |
1331 | # /*: BEGIN: assignment-test :*/ | |
1332 | # v = 10; | |
1333 | # /*: <Tcl code to check that 'v' is indeed 10 :*/ | |
1334 | # /*: END: assignment-test :*/ | |
1335 | # | |
1336 | # The mi_prepare_inline_tests function should be called before | |
1337 | # calling this function. A given C file can contain several | |
1338 | # inline tests. The names of the tests must be unique within one | |
1339 | # C file. | |
1340 | # | |
1341 | proc mi_run_inline_test { testcase } { | |
1342 | ||
1343 | global mi_gdb_prompt | |
1344 | global hex | |
1345 | global decimal | |
1346 | global fullname_syntax | |
1347 | global mi_autotest_source | |
1348 | ||
1349 | set commands [mi_get_inline_test $testcase] | |
1350 | ||
1351 | set first 1 | |
1352 | set line_now 1 | |
1353 | ||
1354 | foreach c $commands { | |
1355 | set statements [lindex $c 0] | |
1356 | set line [lindex $c 1] | |
1357 | set line [expr $line-1] | |
1358 | ||
1359 | # We want gdb to be stopped at the expression immediately | |
1360 | # before the comment. If this is the first comment, the | |
1361 | # program is either not started yet or is in some random place, | |
1362 | # so we run it. For further comments, we might be already | |
1363 | # standing at the right line. If not continue till the | |
1364 | # right line. | |
1365 | ||
1366 | if {$first==1} { | |
1367 | # Start the program afresh. | |
1368 | mi_tbreak "$mi_autotest_source:$line" | |
1369 | mi_run_cmd | |
1370 | set line_now [mi_wait_for_stop "$testcase: step to $line"] | |
1371 | set first 0 | |
1372 | } elseif {$line_now!=$line} { | |
25d5ea92 | 1373 | set line_now [mi_continue_to_line "$mi_autotest_source:$line" "continue to $line"] |
2d0720d9 VP |
1374 | } |
1375 | ||
1376 | if {$line_now!=$line} { | |
1377 | fail "$testcase: go to line $line" | |
1378 | } | |
1379 | ||
1380 | # We're not at the statement right above the comment. | |
1381 | # Execute that statement so that the comment can test | |
1382 | # the state after the statement is executed. | |
1383 | ||
1384 | # Single-step past the line. | |
1385 | mi_send_resuming_command "exec-next" "$testcase: step over $line" | |
1386 | set line_now [mi_wait_for_stop "$testcase: step over $line"] | |
1387 | ||
1388 | # We probably want to use 'uplevel' so that statements | |
1389 | # have direct access to global variables that the | |
1390 | # main 'exp' file has set up. But it's not yet clear, | |
1391 | # will need more experience to be sure. | |
1392 | eval $statements | |
1393 | } | |
1394 | } |