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