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 | |
6b8ce727 | 42 | global INTERNAL_GDBFLAGS GDBFLAGS |
fb40c209 AC |
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 | ||
6b8ce727 | 59 | verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $MIFLAGS" |
fb40c209 AC |
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 | |
6b8ce727 | 97 | global INTERNAL_GDBFLAGS GDBFLAGS |
fb40c209 AC |
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 | ||
6b8ce727 | 119 | verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $MIFLAGS" |
fb40c209 AC |
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 | ||
6b8ce727 | 141 | set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS $MIFLAGS [host_info gdb_opts]"]; |
fb40c209 AC |
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 { |
d0b76dc6 | 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 { |
3d043ef6 | 819 | -re "220\\^running\r\n(\\*running,thread-id=\"\[^\"\]+\"\r\n|=thread-created,id=\"1\",group-id=\"\[0-9\]+\"\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 | ||
c6ebd6cf | 915 | send_gdb "show target-async\n" |
f7f9a841 | 916 | |
a2840c35 | 917 | gdb_expect { |
c6ebd6cf | 918 | -re ".*Controlling the inferior in asynchronous mode is on...*$mi_gdb_prompt$" { |
a2840c35 VP |
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 | |
d0b76dc6 DJ |
946 | # the .* or "\[0-9\]*" regexps for line, and then check the line |
947 | # programmatically. | |
948 | # | |
949 | # Do not pass .* for any argument if you are expecting more than one stop. | |
bb378428 | 950 | proc mi_expect_stop { reason func args file line extra test } { |
1902c51f | 951 | |
dcf95b47 DJ |
952 | global mi_gdb_prompt |
953 | global hex | |
954 | global decimal | |
76ff342d | 955 | global fullname_syntax |
f7f9a841 | 956 | global async |
bb378428 VP |
957 | |
958 | set after_stopped "" | |
959 | set after_reason "" | |
960 | if { [llength $extra] == 2 } { | |
961 | set after_stopped [lindex $extra 0] | |
962 | set after_reason [lindex $extra 1] | |
963 | set after_reason "${after_reason}," | |
964 | } elseif { [llength $extra] == 1 } { | |
965 | set after_stopped [lindex $extra 0] | |
966 | } | |
967 | ||
f7f9a841 VP |
968 | if {$async} { |
969 | set prompt_re "" | |
970 | } else { | |
d0b76dc6 | 971 | set prompt_re "$mi_gdb_prompt$" |
f7f9a841 VP |
972 | } |
973 | ||
974 | if { $reason == "really-no-reason" } { | |
975 | gdb_expect { | |
d0b76dc6 | 976 | -re "\\*stopped\r\n$prompt_re" { |
f7f9a841 VP |
977 | pass "$test" |
978 | } | |
979 | timeout { | |
980 | fail "$test (unknown output after running)" | |
981 | } | |
982 | } | |
983 | return | |
984 | } | |
985 | ||
bb378428 VP |
986 | if { $reason == "exited-normally" } { |
987 | ||
988 | gdb_expect { | |
d0b76dc6 | 989 | -re "\\*stopped,reason=\"exited-normally\"\r\n$prompt_re" { |
bb378428 VP |
990 | pass "$test" |
991 | } | |
992 | -re ".*$mi_gdb_prompt$" {fail "continue to end (2)"} | |
993 | timeout { | |
994 | fail "$test (unknown output after running)" | |
995 | } | |
996 | } | |
997 | return | |
998 | } | |
999 | ||
1000 | set args "\\\[$args\\\]" | |
1001 | ||
1002 | set bn "" | |
1003 | if { $reason == "breakpoint-hit" } { | |
1004 | set bn {bkptno="[0-9]+",} | |
1005 | } | |
1006 | ||
1007 | set r "" | |
1008 | if { $reason != "" } { | |
1009 | set r "reason=\"$reason\"," | |
1010 | } | |
1011 | ||
18ac113b AR |
1012 | |
1013 | set a $after_reason | |
1014 | ||
d0b76dc6 DJ |
1015 | set any "\[^\n\]*" |
1016 | ||
1017 | verbose -log "mi_expect_stop: expecting: \\*stopped,${r}${a}${bn}thread-id=\"$decimal\",stopped-threads=$any,frame=\{addr=\"$hex\",func=\"$func\",args=$args,file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"$line\"\}\r\n$after_stopped$prompt_re" | |
dcf95b47 | 1018 | gdb_expect { |
d0b76dc6 | 1019 | -re "\\*stopped,${r}${a}${bn}thread-id=\"$decimal\",stopped-threads=$any,frame=\{addr=\"$hex\",func=\"$func\",args=$args,file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"($line)\"\}$after_stopped\r\n$prompt_re" { |
dcf95b47 | 1020 | pass "$test" |
bb378428 | 1021 | return $expect_out(2,string) |
dcf95b47 | 1022 | } |
d0b76dc6 | 1023 | -re "\\*stopped,${r}${a}${bn}thread-id=\"$decimal\",stopped-threads=$any,frame=\{addr=\"$hex\",func=\"$any\",args=\[\\\[\{\]$any\[\\\]\}\],file=\"$any\",fullname=\"${fullname_syntax}$any\",line=\"\[0-9\]*\"\}$any\r\n$prompt_re" { |
8cf6e61a | 1024 | verbose -log "got $expect_out(buffer)" |
dcf95b47 DJ |
1025 | fail "$test (stopped at wrong place)" |
1026 | return -1 | |
1027 | } | |
f7f9a841 | 1028 | -re ".*\r\n$mi_gdb_prompt$" { |
8cf6e61a | 1029 | verbose -log "got $expect_out(buffer)" |
dcf95b47 DJ |
1030 | fail "$test (unknown output after running)" |
1031 | return -1 | |
1032 | } | |
dcf95b47 DJ |
1033 | timeout { |
1034 | fail "$test (timeout)" | |
1035 | return -1 | |
1036 | } | |
bb378428 | 1037 | } |
dcf95b47 DJ |
1038 | } |
1039 | ||
1ad15515 PA |
1040 | # Wait for MI *stopped notification related to an interrupt request to |
1041 | # appear. | |
1042 | proc mi_expect_interrupt { test } { | |
1043 | global mi_gdb_prompt | |
1044 | global decimal | |
1045 | global async | |
1046 | ||
1047 | if {$async} { | |
1048 | set prompt_re "" | |
1049 | } else { | |
1050 | set prompt_re "$mi_gdb_prompt$" | |
1051 | } | |
1052 | ||
252fbfc8 | 1053 | set r "reason=\"signal-received\",signal-name=\"0\",signal-meaning=\"Signal 0\"" |
1ad15515 PA |
1054 | |
1055 | set any "\[^\n\]*" | |
1056 | ||
1057 | # A signal can land anywhere, just ignore the location | |
1058 | verbose -log "mi_expect_interrupt: expecting: \\*stopped,${r},thread-id=\"$decimal\",stopped-threads=$any\r\n$prompt_re" | |
1059 | gdb_expect { | |
1060 | -re "\\*stopped,${r},thread-id=\"$decimal\",stopped-threads=$any\r\n$prompt_re" { | |
1061 | pass "$test" | |
1062 | return 0; | |
1063 | } | |
1064 | -re ".*\r\n$mi_gdb_prompt$" { | |
1065 | verbose -log "got $expect_out(buffer)" | |
1066 | fail "$test (unknown output after running)" | |
1067 | return -1 | |
1068 | } | |
1069 | timeout { | |
1070 | fail "$test (timeout)" | |
1071 | return -1 | |
1072 | } | |
1073 | } | |
1074 | } | |
1075 | ||
bb378428 VP |
1076 | # cmd should not include the number or newline (i.e. "exec-step 3", not |
1077 | # "220-exec-step 3\n" | |
1078 | ||
1079 | # Can not match -re ".*\r\n${mi_gdb_prompt}", because of false positives | |
1080 | # after the first prompt is printed. | |
1081 | ||
08b468e0 | 1082 | proc mi_execute_to { cmd reason func args file line extra test } { |
bb378428 VP |
1083 | global suppress_flag |
1084 | if { $suppress_flag } { | |
1085 | return -1 | |
1086 | } | |
1087 | ||
1088 | mi_send_resuming_command "$cmd" "$test" | |
1089 | set r [mi_expect_stop $reason $func $args $file $line $extra $test] | |
1090 | return $r | |
dcf95b47 DJ |
1091 | } |
1092 | ||
1093 | proc mi_next_to { func args file line test } { | |
08b468e0 | 1094 | mi_execute_to "exec-next" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
1095 | "$file" "$line" "" "$test" |
1096 | } | |
1097 | ||
1098 | proc mi_step_to { func args file line test } { | |
08b468e0 | 1099 | mi_execute_to "exec-step" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
1100 | "$file" "$line" "" "$test" |
1101 | } | |
1102 | ||
1103 | proc mi_finish_to { func args file line result ret test } { | |
08b468e0 | 1104 | mi_execute_to "exec-finish" "function-finished" "$func" "$args" \ |
dcf95b47 DJ |
1105 | "$file" "$line" \ |
1106 | ",gdb-result-var=\"$result\",return-value=\"$ret\"" \ | |
1107 | "$test" | |
1108 | } | |
1109 | ||
f7e97bb3 VP |
1110 | proc mi_continue_to {func} { |
1111 | mi_runto_helper $func "continue" | |
dcf95b47 DJ |
1112 | } |
1113 | ||
08b468e0 KS |
1114 | proc mi0_execute_to { cmd reason func args file line extra test } { |
1115 | mi_execute_to_helper "$cmd" "$reason" "$func" "\{$args\}" \ | |
dcf95b47 DJ |
1116 | "$file" "$line" "$extra" "$test" |
1117 | } | |
1118 | ||
1119 | proc mi0_next_to { func args file line test } { | |
08b468e0 | 1120 | mi0_execute_to "exec-next" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
1121 | "$file" "$line" "" "$test" |
1122 | } | |
1123 | ||
1124 | proc mi0_step_to { func args file line test } { | |
08b468e0 | 1125 | mi0_execute_to "exec-step" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
1126 | "$file" "$line" "" "$test" |
1127 | } | |
1128 | ||
1129 | proc mi0_finish_to { func args file line result ret test } { | |
08b468e0 | 1130 | mi0_execute_to "exec-finish" "function-finished" "$func" "$args" \ |
dcf95b47 DJ |
1131 | "$file" "$line" \ |
1132 | ",gdb-result-var=\"$result\",return-value=\"$ret\"" \ | |
1133 | "$test" | |
1134 | } | |
1135 | ||
1136 | proc mi0_continue_to { bkptno func args file line test } { | |
08b468e0 | 1137 | mi0_execute_to "exec-continue" "breakpoint-hit\",bkptno=\"$bkptno" \ |
dcf95b47 DJ |
1138 | "$func" "$args" "$file" "$line" "" "$test" |
1139 | } | |
b26ed50d | 1140 | |
d24317b4 VP |
1141 | # Creates a breakpoint and checks the reported fields are as expected |
1142 | proc mi_create_breakpoint { location number disp func file line address test } { | |
1143 | 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=\".*\"\}" | |
1144 | mi_gdb_test "222-break-insert $location" \ | |
1145 | "222\\^done,bkpt=\{number=\"$number\",type=\"breakpoint\",disp=\"$disp\",enabled=\"y\",addr=\"$address\",func=\"$func\",file=\"$file\",fullname=\".*\",line=\"$line\",times=\"0\",original-location=\".*\"\}" \ | |
1146 | $test | |
1147 | } | |
1148 | ||
1149 | proc mi_list_breakpoints { expected test } { | |
1150 | set fullname ".*" | |
1151 | ||
1152 | set body "" | |
1153 | set first 1 | |
1154 | ||
1155 | foreach item $children { | |
1156 | if {$first == 0} { | |
1157 | set body "$body," | |
1158 | } | |
1159 | set number disp func file line address | |
1160 | set number [lindex $item 0] | |
1161 | set disp [lindex $item 1] | |
1162 | set func [lindex $item 2] | |
1163 | set line [lindex $item 3] | |
1164 | set address [lindex $item 4] | |
1165 | 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=\".*\"\}" | |
1166 | set first 0 | |
1167 | } | |
1168 | ||
1169 | 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\\\]\}" \ | |
1170 | mi_gdb_test "666-break-list" \ | |
1171 | "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\\\]\}" \ | |
1172 | $test | |
1173 | } | |
1174 | ||
b26ed50d VP |
1175 | # Creates varobj named NAME for EXPRESSION. |
1176 | # Name cannot be "-". | |
1177 | proc mi_create_varobj { name expression testname } { | |
1178 | mi_gdb_test "-var-create $name * $expression" \ | |
983c9c8f | 1179 | "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=.*" \ |
b26ed50d VP |
1180 | $testname |
1181 | } | |
1182 | ||
fcacd99f VP |
1183 | proc mi_create_floating_varobj { name expression testname } { |
1184 | mi_gdb_test "-var-create $name @ $expression" \ | |
1185 | "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=.*" \ | |
1186 | $testname | |
1187 | } | |
1188 | ||
1189 | ||
9e8e3afe VP |
1190 | # Same as mi_create_varobj, but also checks the reported type |
1191 | # of the varobj. | |
1192 | proc mi_create_varobj_checked { name expression type testname } { | |
1193 | mi_gdb_test "-var-create $name * $expression" \ | |
1194 | "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=\"$type\".*" \ | |
1195 | $testname | |
1196 | } | |
1197 | ||
6e2a9270 VP |
1198 | # Deletes the specified NAME. |
1199 | proc mi_delete_varobj { name testname } { | |
1200 | mi_gdb_test "-var-delete $name" \ | |
1201 | "\\^done,ndeleted=.*" \ | |
1202 | $testname | |
1203 | } | |
1204 | ||
b26ed50d VP |
1205 | # Updates varobj named NAME and checks that all varobjs in EXPECTED |
1206 | # are reported as updated, and no other varobj is updated. | |
1207 | # Assumes that no varobj is out of scope and that no varobj changes | |
1208 | # types. | |
1209 | proc mi_varobj_update { name expected testname } { | |
1210 | set er "\\^done,changelist=\\\[" | |
1211 | set first 1 | |
1212 | foreach item $expected { | |
1213 | set v "{name=\"$item\",in_scope=\"true\",type_changed=\"false\"}" | |
25d5ea92 | 1214 | if {$first == 1} { |
b26ed50d | 1215 | set er "$er$v" |
25d5ea92 | 1216 | set first 0 |
b26ed50d VP |
1217 | } else { |
1218 | set er "$er,$v" | |
1219 | } | |
1220 | } | |
1221 | set er "$er\\\]" | |
1222 | ||
1223 | verbose -log "Expecting: $er" 2 | |
1224 | mi_gdb_test "-var-update $name" $er $testname | |
1225 | } | |
1226 | ||
fcacd99f VP |
1227 | proc mi_varobj_update_with_type_change { name new_type new_children testname } { |
1228 | set v "{name=\"$name\",in_scope=\"true\",type_changed=\"true\",new_type=\"$new_type\",new_num_children=\"$new_children\"}" | |
1229 | set er "\\^done,changelist=\\\[$v\\\]" | |
1230 | verbose -log "Expecting: $er" | |
1231 | mi_gdb_test "-var-update $name" $er $testname | |
1232 | } | |
1233 | ||
b26ed50d VP |
1234 | proc mi_check_varobj_value { name value testname } { |
1235 | ||
1236 | mi_gdb_test "-var-evaluate-expression $name" \ | |
1237 | "\\^done,value=\"$value\"" \ | |
1238 | $testname | |
1239 | } | |
038224f6 VP |
1240 | |
1241 | # Check the results of the: | |
1242 | # | |
1243 | # -var-list-children VARNAME | |
1244 | # | |
1245 | # command. The CHILDREN parement should be a list of lists. | |
1246 | # Each inner list can have either 3 or 4 elements, describing | |
1247 | # fields that gdb is expected to report for child variable object, | |
1248 | # in the following order | |
1249 | # | |
1250 | # - Name | |
1251 | # - Expression | |
1252 | # - Number of children | |
1253 | # - Type | |
1254 | # | |
1255 | # If inner list has 3 elements, the gdb is expected to output no | |
9e8e3afe VP |
1256 | # type for a child and no value. |
1257 | # | |
1258 | # If the inner list has 4 elements, gdb output is expected to | |
1259 | # have no value. | |
038224f6 VP |
1260 | # |
1261 | proc mi_list_varobj_children { varname children testname } { | |
1262 | ||
9e8e3afe VP |
1263 | set options "" |
1264 | if {[llength $varname] == 2} { | |
1265 | set options [lindex $varname 1] | |
1266 | set varname [lindex $varname 0] | |
1267 | } | |
1268 | ||
038224f6 VP |
1269 | set numchildren [llength $children] |
1270 | set children_exp {} | |
1271 | set whatever "\"\[^\"\]+\"" | |
1272 | ||
1273 | foreach item $children { | |
1274 | ||
1275 | set name [lindex $item 0] | |
1276 | set exp [lindex $item 1] | |
1277 | set numchild [lindex $item 2] | |
9e8e3afe | 1278 | if {[llength $item] == 5} { |
038224f6 | 1279 | set type [lindex $item 3] |
9e8e3afe | 1280 | set value [lindex $item 4] |
038224f6 VP |
1281 | |
1282 | lappend children_exp\ | |
9e8e3afe VP |
1283 | "child={name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",value=\"$value\",type=\"$type\"\(,thread-id=\"\[0-9\]+\")?}" |
1284 | } elseif {[llength $item] == 4} { | |
1285 | set type [lindex $item 3] | |
1286 | ||
1287 | lappend children_exp\ | |
1288 | "child={name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",type=\"$type\"\(,thread-id=\"\[0-9\]+\")?}" | |
038224f6 VP |
1289 | } else { |
1290 | lappend children_exp\ | |
9e8e3afe | 1291 | "child={name=\"$name\",exp=\"$exp\",numchild=\"$numchild\"(,thread-id=\"\[0-9\]+\")?}" |
038224f6 VP |
1292 | } |
1293 | } | |
1294 | set children_exp_j [join $children_exp ","] | |
9e8e3afe VP |
1295 | if {$numchildren} { |
1296 | set expected "\\^done,numchild=\".*\",children=\\\[$children_exp_j.*\\\]" | |
1297 | } { | |
1298 | set expected "\\^done,numchild=\"0\"" | |
1299 | } | |
038224f6 VP |
1300 | |
1301 | verbose -log "Expecting: $expected" | |
1302 | ||
9e8e3afe VP |
1303 | mi_gdb_test "-var-list-children $options $varname" $expected $testname |
1304 | } | |
1305 | ||
1306 | # Verifies that variable object VARNAME has NUMBER children, | |
1307 | # where each one is named $VARNAME.<index-of-child> and has type TYPE. | |
1308 | proc mi_list_array_varobj_children { varname number type testname } { | |
1309 | set t {} | |
1310 | for {set i 0} {$i < $number} {incr i} { | |
1311 | lappend t [list $varname.$i $i 0 $type] | |
1312 | } | |
1313 | mi_list_varobj_children $varname $t $testname | |
038224f6 | 1314 | } |
2d0720d9 VP |
1315 | |
1316 | # A list of two-element lists. First element of each list is | |
1317 | # a Tcl statement, and the second element is the line | |
1318 | # number of source C file where the statement originates. | |
1319 | set mi_autotest_data "" | |
1320 | # The name of the source file for autotesting. | |
1321 | set mi_autotest_source "" | |
1322 | ||
1323 | proc count_newlines { string } { | |
1324 | return [regexp -all "\n" $string] | |
1325 | } | |
1326 | ||
1327 | # Prepares for running inline tests in FILENAME. | |
1328 | # See comments for mi_run_inline_test for detailed | |
1329 | # explanation of the idea and syntax. | |
1330 | proc mi_prepare_inline_tests { filename } { | |
1331 | ||
1332 | global srcdir | |
1333 | global subdir | |
1334 | global mi_autotest_source | |
1335 | global mi_autotest_data | |
1336 | ||
1337 | set mi_autotest_data {} | |
1338 | ||
1339 | set mi_autotest_source $filename | |
1340 | ||
1341 | if { ! [regexp "^/" "$filename"] } then { | |
1342 | set filename "$srcdir/$subdir/$filename" | |
1343 | } | |
1344 | ||
1345 | set chan [open $filename] | |
1346 | set content [read $chan] | |
1347 | set line_number 1 | |
1348 | while {1} { | |
1349 | set start [string first "/*:" $content] | |
1350 | if {$start != -1} { | |
1351 | set end [string first ":*/" $content] | |
1352 | if {$end == -1} { | |
1353 | error "Unterminated special comment in $filename" | |
1354 | } | |
1355 | ||
1356 | set prefix [string range $content 0 $start] | |
1357 | set prefix_newlines [count_newlines $prefix] | |
1358 | ||
1359 | set line_number [expr $line_number+$prefix_newlines] | |
1360 | set comment_line $line_number | |
1361 | ||
1362 | set comment [string range $content [expr $start+3] [expr $end-1]] | |
1363 | ||
1364 | set comment_newlines [count_newlines $comment] | |
1365 | set line_number [expr $line_number+$comment_newlines] | |
1366 | ||
1367 | set comment [string trim $comment] | |
1368 | set content [string range $content [expr $end+3] \ | |
1369 | [string length $content]] | |
1370 | lappend mi_autotest_data [list $comment $comment_line] | |
1371 | } else { | |
1372 | break | |
1373 | } | |
1374 | } | |
1375 | close $chan | |
1376 | } | |
1377 | ||
1378 | # Helper to mi_run_inline_test below. | |
1379 | # Return the list of all (statement,line_number) lists | |
1380 | # that comprise TESTCASE. The begin and end markers | |
1381 | # are not included. | |
1382 | proc mi_get_inline_test {testcase} { | |
1383 | ||
1384 | global mi_gdb_prompt | |
1385 | global mi_autotest_data | |
1386 | global mi_autotest_source | |
1387 | ||
1388 | set result {} | |
1389 | ||
1390 | set seen_begin 0 | |
1391 | set seen_end 0 | |
1392 | foreach l $mi_autotest_data { | |
1393 | ||
1394 | set comment [lindex $l 0] | |
1395 | ||
1396 | if {$comment == "BEGIN: $testcase"} { | |
1397 | set seen_begin 1 | |
1398 | } elseif {$comment == "END: $testcase"} { | |
1399 | set seen_end 1 | |
1400 | break | |
1401 | } elseif {$seen_begin==1} { | |
1402 | lappend result $l | |
1403 | } | |
1404 | } | |
1405 | ||
1406 | if {$seen_begin == 0} { | |
1407 | error "Autotest $testcase not found" | |
1408 | } | |
1409 | ||
1410 | if {$seen_begin == 1 && $seen_end == 0} { | |
1411 | error "Missing end marker for test $testcase" | |
1412 | } | |
1413 | ||
1414 | return $result | |
1415 | } | |
1416 | ||
1417 | # Sets temporary breakpoint at LOCATION. | |
1418 | proc mi_tbreak {location} { | |
1419 | ||
1420 | global mi_gdb_prompt | |
1421 | ||
1422 | mi_gdb_test "-break-insert -t $location" \ | |
1423 | {\^done,bkpt=.*} \ | |
1424 | "run to $location (set breakpoint)" | |
1425 | } | |
1426 | ||
1427 | # Send COMMAND that must be a command that resumes | |
1428 | # the inferiour (run/continue/next/etc) and consumes | |
1429 | # the "^running" output from it. | |
a2840c35 | 1430 | proc mi_send_resuming_command_raw {command test} { |
2d0720d9 VP |
1431 | |
1432 | global mi_gdb_prompt | |
1433 | ||
a2840c35 | 1434 | send_gdb "$command\n" |
2d0720d9 | 1435 | gdb_expect { |
a2840c35 | 1436 | -re "\\^running\r\n\\*running,thread-id=\"\[^\"\]+\"\r\n${mi_gdb_prompt}" { |
7ebd49dc VP |
1437 | # Note that lack of 'pass' call here -- this works around limitation |
1438 | # in DejaGNU xfail mechanism. mi-until.exp has this: | |
1439 | # | |
1440 | # setup_kfail gdb/2104 "*-*-*" | |
1441 | # mi_execute_to ... | |
1442 | # | |
1443 | # and mi_execute_to uses mi_send_resuming_command. If we use 'pass' here, | |
1444 | # it will reset kfail, so when the actual test fails, it will be flagged | |
1445 | # as real failure. | |
d0b76dc6 | 1446 | return 0 |
2d0720d9 | 1447 | } |
bb378428 VP |
1448 | -re ".*${mi_gdb_prompt}" { |
1449 | fail "$test (failed to resume)" | |
d0b76dc6 | 1450 | return -1 |
bb378428 | 1451 | } |
a2840c35 | 1452 | -re "\\^error,msg=.*" { |
bb378428 VP |
1453 | fail "$test (MI error)" |
1454 | return -1 | |
1455 | } | |
2d0720d9 | 1456 | timeout { |
bb378428 VP |
1457 | fail "$test" |
1458 | return -1 | |
2d0720d9 VP |
1459 | } |
1460 | } | |
1461 | } | |
1462 | ||
a2840c35 VP |
1463 | proc mi_send_resuming_command {command test} { |
1464 | mi_send_resuming_command_raw -$command $test | |
1465 | } | |
1466 | ||
2d0720d9 VP |
1467 | # Helper to mi_run_inline_test below. |
1468 | # Sets a temporary breakpoint at LOCATION and runs | |
1469 | # the program using COMMAND. When the program is stopped | |
1470 | # returns the line at which it. Returns -1 if line cannot | |
1471 | # be determined. | |
1472 | # Does not check that the line is the same as requested. | |
1473 | # The caller can check itself if required. | |
a73bafbc | 1474 | proc mi_continue_to_line {location test} { |
2d0720d9 VP |
1475 | |
1476 | mi_tbreak $location | |
1477 | mi_send_resuming_command "exec-continue" "run to $location (exec-continue)" | |
bb378428 | 1478 | return [mi_get_stop_line $test] |
2d0720d9 VP |
1479 | } |
1480 | ||
1481 | # Wait until gdb prints the current line. | |
bb378428 | 1482 | proc mi_get_stop_line {test} { |
2d0720d9 VP |
1483 | |
1484 | global mi_gdb_prompt | |
f7f9a841 VP |
1485 | global async |
1486 | ||
1487 | if {$async} { | |
1488 | set prompt_re "" | |
1489 | } else { | |
d0b76dc6 | 1490 | set prompt_re "$mi_gdb_prompt$" |
f7f9a841 | 1491 | } |
2d0720d9 VP |
1492 | |
1493 | gdb_expect { | |
d0b76dc6 | 1494 | -re ".*line=\"(\[0-9\]*)\".*\r\n$prompt_re" { |
2d0720d9 VP |
1495 | return $expect_out(1,string) |
1496 | } | |
d0b76dc6 | 1497 | -re ".*$mi_gdb_prompt" { |
2d0720d9 VP |
1498 | fail "wait for stop ($test)" |
1499 | } | |
1500 | timeout { | |
1501 | fail "wait for stop ($test)" | |
1502 | } | |
1503 | } | |
1504 | } | |
1505 | ||
1506 | # Run a MI test embedded in comments in a C file. | |
1507 | # The C file should contain special comments in the following | |
1508 | # three forms: | |
1509 | # | |
1510 | # /*: BEGIN: testname :*/ | |
1511 | # /*: <Tcl statements> :*/ | |
1512 | # /*: END: testname :*/ | |
1513 | # | |
1514 | # This procedure find the begin and end marker for the requested | |
1515 | # test. Then, a temporary breakpoint is set at the begin | |
1516 | # marker and the program is run (from start). | |
1517 | # | |
1518 | # After that, for each special comment between the begin and end | |
1519 | # marker, the Tcl statements are executed. It is assumed that | |
1520 | # for each comment, the immediately preceding line is executable | |
1521 | # C statement. Then, gdb will be single-stepped until that | |
1522 | # preceding C statement is executed, and after that the | |
1523 | # Tcl statements in the comment will be executed. | |
1524 | # | |
1525 | # For example: | |
1526 | # | |
1527 | # /*: BEGIN: assignment-test :*/ | |
1528 | # v = 10; | |
1529 | # /*: <Tcl code to check that 'v' is indeed 10 :*/ | |
1530 | # /*: END: assignment-test :*/ | |
1531 | # | |
1532 | # The mi_prepare_inline_tests function should be called before | |
1533 | # calling this function. A given C file can contain several | |
1534 | # inline tests. The names of the tests must be unique within one | |
1535 | # C file. | |
1536 | # | |
1537 | proc mi_run_inline_test { testcase } { | |
1538 | ||
1539 | global mi_gdb_prompt | |
1540 | global hex | |
1541 | global decimal | |
1542 | global fullname_syntax | |
1543 | global mi_autotest_source | |
1544 | ||
1545 | set commands [mi_get_inline_test $testcase] | |
1546 | ||
1547 | set first 1 | |
1548 | set line_now 1 | |
1549 | ||
1550 | foreach c $commands { | |
1551 | set statements [lindex $c 0] | |
1552 | set line [lindex $c 1] | |
1553 | set line [expr $line-1] | |
1554 | ||
1555 | # We want gdb to be stopped at the expression immediately | |
1556 | # before the comment. If this is the first comment, the | |
1557 | # program is either not started yet or is in some random place, | |
1558 | # so we run it. For further comments, we might be already | |
1559 | # standing at the right line. If not continue till the | |
1560 | # right line. | |
1561 | ||
1562 | if {$first==1} { | |
1563 | # Start the program afresh. | |
1564 | mi_tbreak "$mi_autotest_source:$line" | |
1565 | mi_run_cmd | |
bb378428 | 1566 | set line_now [mi_get_stop_line "$testcase: step to $line"] |
2d0720d9 VP |
1567 | set first 0 |
1568 | } elseif {$line_now!=$line} { | |
25d5ea92 | 1569 | set line_now [mi_continue_to_line "$mi_autotest_source:$line" "continue to $line"] |
2d0720d9 VP |
1570 | } |
1571 | ||
1572 | if {$line_now!=$line} { | |
1573 | fail "$testcase: go to line $line" | |
1574 | } | |
1575 | ||
1576 | # We're not at the statement right above the comment. | |
1577 | # Execute that statement so that the comment can test | |
1578 | # the state after the statement is executed. | |
1579 | ||
1580 | # Single-step past the line. | |
d0b76dc6 DJ |
1581 | if { [mi_send_resuming_command "exec-next" "$testcase: step over $line"] != 0 } { |
1582 | return -1 | |
1583 | } | |
1584 | set line_now [mi_get_stop_line "$testcase: step over $line"] | |
2d0720d9 VP |
1585 | |
1586 | # We probably want to use 'uplevel' so that statements | |
1587 | # have direct access to global variables that the | |
1588 | # main 'exp' file has set up. But it's not yet clear, | |
1589 | # will need more experience to be sure. | |
1590 | eval $statements | |
1591 | } | |
1592 | } | |
9d81d21b VP |
1593 | |
1594 | proc get_mi_thread_list {name} { | |
1595 | global expect_out | |
1596 | ||
1597 | # MI will return a list of thread ids: | |
1598 | # | |
1599 | # -thread-list-ids | |
1600 | # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N" | |
1601 | # (gdb) | |
1602 | mi_gdb_test "-thread-list-ids" \ | |
1603 | {.*\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},number-of-threads="[0-9]+"} \ | |
1604 | "-thread_list_ids ($name)" | |
1605 | ||
1606 | set output {} | |
1607 | if {[info exists expect_out(buffer)]} { | |
1608 | set output $expect_out(buffer) | |
1609 | } | |
1610 | ||
1611 | set thread_list {} | |
1612 | if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} { | |
1613 | fail "finding threads in MI output ($name)" | |
1614 | } else { | |
1615 | pass "finding threads in MI output ($name)" | |
1616 | ||
1617 | # Make list of console threads | |
1618 | set start [expr {[string first \{ $threads] + 1}] | |
1619 | set end [expr {[string first \} $threads] - 1}] | |
1620 | set threads [string range $threads $start $end] | |
1621 | foreach thread [split $threads ,] { | |
1622 | if {[scan $thread {thread-id="%d"} num]} { | |
1623 | lappend thread_list $num | |
1624 | } | |
1625 | } | |
1626 | } | |
1627 | ||
1628 | return $thread_list | |
1629 | } | |
1630 | ||
1631 | # Check that MI and the console know of the same threads. | |
1632 | # Appends NAME to all test names. | |
1633 | proc check_mi_and_console_threads {name} { | |
1634 | global expect_out | |
1635 | ||
1636 | mi_gdb_test "-thread-list-ids" \ | |
1637 | {.*\^done,thread-ids={(thread-id="[0-9]+"(,)*)+},number-of-threads="[0-9]+"} \ | |
1638 | "-thread-list-ids ($name)" | |
1639 | set mi_output {} | |
1640 | if {[info exists expect_out(buffer)]} { | |
1641 | set mi_output $expect_out(buffer) | |
1642 | } | |
1643 | ||
1644 | # GDB will return a list of thread ids and some more info: | |
1645 | # | |
1646 | # (gdb) | |
1647 | # -interpreter-exec console "info threads" | |
1648 | # ~" 4 Thread 2051 (LWP 7734) 0x401166b1 in __libc_nanosleep () at __libc_nanosleep:-1" | |
1649 | # ~" 3 Thread 1026 (LWP 7733) () at __libc_nanosleep:-1" | |
1650 | # ~" 2 Thread 2049 (LWP 7732) 0x401411f8 in __poll (fds=0x804bb24, nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63" | |
1651 | # ~"* 1 Thread 1024 (LWP 7731) main (argc=1, argv=0xbfffdd94) at ../../../src/gdb/testsuite/gdb.mi/pthreads.c:160" | |
1652 | # FIXME: kseitz/2002-09-05: Don't use the hack-cli method. | |
1653 | mi_gdb_test "info threads" \ | |
1654 | {.*(~".*"[\r\n]*)+.*} \ | |
1655 | "info threads ($name)" | |
1656 | set console_output {} | |
1657 | if {[info exists expect_out(buffer)]} { | |
1658 | set console_output $expect_out(buffer) | |
1659 | } | |
1660 | ||
1661 | # Make a list of all known threads to console (gdb's thread IDs) | |
1662 | set console_thread_list {} | |
1663 | foreach line [split $console_output \n] { | |
1664 | if {[string index $line 0] == "~"} { | |
1665 | # This is a line from the console; trim off "~", " ", "*", and "\"" | |
1666 | set line [string trim $line ~\ \"\*] | |
1667 | if {[scan $line "%d" id] == 1} { | |
1668 | lappend console_thread_list $id | |
1669 | } | |
1670 | } | |
1671 | } | |
1672 | ||
1673 | # Now find the result string from MI | |
1674 | set mi_result "" | |
1675 | foreach line [split $mi_output \n] { | |
1676 | if {[string range $line 0 4] == "^done"} { | |
1677 | set mi_result $line | |
1678 | } | |
1679 | } | |
1680 | if {$mi_result == ""} { | |
1681 | fail "finding MI result string ($name)" | |
1682 | } else { | |
1683 | pass "finding MI result string ($name)" | |
1684 | } | |
1685 | ||
1686 | # Finally, extract the thread ids and compare them to the console | |
1687 | set num_mi_threads_str "" | |
1688 | if {![regexp {number-of-threads="[0-9]+"} $mi_result num_mi_threads_str]} { | |
1689 | fail "finding number of threads in MI output ($name)" | |
1690 | } else { | |
1691 | pass "finding number of threads in MI output ($name)" | |
1692 | ||
1693 | # Extract the number of threads from the MI result | |
1694 | if {![scan $num_mi_threads_str {number-of-threads="%d"} num_mi_threads]} { | |
1695 | fail "got number of threads from MI ($name)" | |
1696 | } else { | |
1697 | pass "got number of threads from MI ($name)" | |
1698 | ||
1699 | # Check if MI and console have same number of threads | |
1700 | if {$num_mi_threads != [llength $console_thread_list]} { | |
1701 | fail "console and MI have same number of threads ($name)" | |
1702 | } else { | |
1703 | pass "console and MI have same number of threads ($name)" | |
1704 | ||
1705 | # Get MI thread list | |
1706 | set mi_thread_list [get_mi_thread_list $name] | |
1707 | ||
1708 | # Check if MI and console have the same threads | |
1709 | set fails 0 | |
1710 | foreach ct [lsort $console_thread_list] mt [lsort $mi_thread_list] { | |
1711 | if {$ct != $mt} { | |
1712 | incr fails | |
1713 | } | |
1714 | } | |
1715 | if {$fails > 0} { | |
1716 | fail "MI and console have same threads ($name)" | |
1717 | ||
1718 | # Send a list of failures to the log | |
1719 | send_log "Console has thread ids: $console_thread_list\n" | |
1720 | send_log "MI has thread ids: $mi_thread_list\n" | |
1721 | } else { | |
1722 | pass "MI and console have same threads ($name)" | |
1723 | } | |
1724 | } | |
1725 | } | |
1726 | } | |
1727 | } | |
5e06a3d1 VP |
1728 | |
1729 | proc mi_load_shlibs { args } { | |
1730 | if {![is_remote target]} { | |
1731 | return | |
1732 | } | |
1733 | ||
1734 | foreach file $args { | |
1735 | gdb_download $file | |
1736 | } | |
1737 | ||
1738 | # Even if the target supplies full paths for shared libraries, | |
1739 | # they may not be paths for this system. | |
1740 | mi_gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "\^done" "" | |
1741 | } | |
1742 | ||
1ad15515 PA |
1743 | proc mi_reverse_list { list } { |
1744 | if { [llength $list] <= 1 } { | |
1745 | return $list | |
1746 | } | |
1747 | set tail [lrange $list 1 [llength $list]] | |
1748 | set rtail [mi_reverse_list $tail] | |
1749 | lappend rtail [lindex $list 0] | |
1750 | return $rtail | |
1751 | } | |
1752 | ||
1753 | proc mi_check_thread_states { xstates test } { | |
1754 | global expect_out | |
1755 | set states [mi_reverse_list $xstates] | |
1756 | set pattern "\\^done,threads=\\\[" | |
1757 | foreach s $states { | |
1758 | set pattern "${pattern}(.*)state=\"$s\"" | |
1759 | } | |
1760 | set pattern "$pattern\\\}\\\].*" | |
1761 | ||
1762 | verbose -log "expecting: $pattern" | |
1763 | mi_gdb_test "-thread-info" $pattern $test | |
1764 | } |