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