Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright 1999-2022 Free Software Foundation, Inc. |
fb40c209 AC |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
fb40c209 | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
fb40c209 AC |
8 | # This program is distributed in the hope that it will be useful, |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
e22f8b7c | 12 | # |
fb40c209 | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
fb40c209 | 15 | |
fb40c209 AC |
16 | # This file was based on a file written by Fred Fish. (fnf@cygnus.com) |
17 | ||
18 | # Test setup routines that work with the MI interpreter. | |
19 | ||
a25eb028 MR |
20 | load_lib gdb-utils.exp |
21 | ||
fb40c209 AC |
22 | # The variable mi_gdb_prompt is a regexp which matches the gdb mi prompt. |
23 | # Set it if it is not already set. | |
24 | global mi_gdb_prompt | |
25 | if ![info exists mi_gdb_prompt] then { | |
26 | set mi_gdb_prompt "\[(\]gdb\[)\] \r\n" | |
27 | } | |
28 | ||
ecd3fd0f BR |
29 | global mi_inferior_tty_name |
30 | ||
51f77c37 PA |
31 | # Always points to GDB's main UI spawn ID, even when testing with MI |
32 | # running on a secondary UI. | |
33 | global gdb_main_spawn_id | |
34 | ||
35 | # Points to the spawn id of the MI channel. When testing with MI | |
36 | # running as the primary/main UI, this is the same as | |
37 | # gdb_main_spawn_id, but will be different when testing with MI | |
38 | # running on a secondary UI. | |
39 | global mi_spawn_id | |
40 | ||
fb40c209 AC |
41 | set MIFLAGS "-i=mi" |
42 | ||
84a02e58 | 43 | set thread_selected_re "=thread-selected,id=\"\[0-9\]+\"\r\n" |
bbec57e4 | 44 | set gdbindex_warning_re "&\"warning: Skipping \[^\r\n\]+ \.gdb_index section in \[^\r\n\]+\"\r\n(?:&\"\\\\n\"\r\n)?" |
481860b3 | 45 | set library_loaded_re "=library-loaded\[^\n\]+\"\r\n(?:$gdbindex_warning_re)?" |
ca539be8 | 46 | set breakpoint_re "=(?:breakpoint-created|breakpoint-deleted)\[^\n\]+\"\r\n" |
66bb093b | 47 | |
fb40c209 AC |
48 | # |
49 | # mi_gdb_exit -- exit the GDB, killing the target program if necessary | |
50 | # | |
51 | proc mi_gdb_exit {} { | |
52 | catch mi_uncatched_gdb_exit | |
53 | } | |
54 | ||
55 | proc mi_uncatched_gdb_exit {} { | |
56 | global GDB | |
6b8ce727 | 57 | global INTERNAL_GDBFLAGS GDBFLAGS |
51f77c37 PA |
58 | global gdb_spawn_id gdb_main_spawn_id |
59 | global mi_spawn_id inferior_spawn_id | |
fb40c209 AC |
60 | global gdb_prompt |
61 | global mi_gdb_prompt | |
62 | global MIFLAGS | |
63 | ||
fb40c209 AC |
64 | if { [info procs sid_exit] != "" } { |
65 | sid_exit | |
66 | } | |
67 | ||
68 | if ![info exists gdb_spawn_id] { | |
4ec70201 | 69 | return |
fb40c209 AC |
70 | } |
71 | ||
6b8ce727 | 72 | verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS $MIFLAGS" |
fb40c209 AC |
73 | |
74 | if { [is_remote host] && [board_info host exists fileid] } { | |
4ec70201 | 75 | send_gdb "999-gdb-exit\n" |
fb40c209 AC |
76 | gdb_expect 10 { |
77 | -re "y or n" { | |
4ec70201 PA |
78 | send_gdb "y\n" |
79 | exp_continue | |
fb40c209 | 80 | } |
4392c534 YQ |
81 | -re "Undefined command.*$gdb_prompt $" { |
82 | send_gdb "quit\n" | |
4ec70201 | 83 | exp_continue |
4392c534 | 84 | } |
fb40c209 AC |
85 | -re "DOSEXIT code" { } |
86 | default { } | |
87 | } | |
88 | } | |
89 | ||
b167e53f PA |
90 | # Switch back to the main spawn id, so that remote_close below |
91 | # closes it, and not a secondary channel. Closing a secondary | |
92 | # channel does not make GDB exit. | |
93 | if {$gdb_spawn_id != $gdb_main_spawn_id} { | |
94 | switch_gdb_spawn_id $gdb_main_spawn_id | |
95 | } | |
96 | ||
97 | # Close secondary MI channel, if there's one. | |
98 | if {$mi_spawn_id != $gdb_main_spawn_id} { | |
99 | close -i $mi_spawn_id | |
100 | } | |
101 | ||
fb40c209 | 102 | if ![is_remote host] { |
4ec70201 | 103 | remote_close host |
fb40c209 AC |
104 | } |
105 | unset gdb_spawn_id | |
51f77c37 PA |
106 | unset gdb_main_spawn_id |
107 | unset mi_spawn_id | |
108 | unset inferior_spawn_id | |
109 | } | |
110 | ||
111 | # Create the PTY for the inferior process and tell GDB about it. | |
112 | ||
113 | proc mi_create_inferior_pty {} { | |
114 | global mi_gdb_prompt | |
115 | global inferior_spawn_id | |
116 | global mi_inferior_tty_name | |
117 | ||
118 | spawn -pty | |
119 | set inferior_spawn_id $spawn_id | |
120 | set tty_name $spawn_out(slave,name) | |
121 | set mi_inferior_tty_name $tty_name | |
122 | ||
123 | send_gdb "102-inferior-tty-set $tty_name\n" | |
124 | gdb_expect 10 { | |
125 | -re ".*102\\\^done\r\n$mi_gdb_prompt$" { | |
126 | verbose "redirect inferior output to new terminal device." | |
127 | } | |
128 | timeout { | |
129 | warning "Couldn't redirect inferior output." 2 | |
130 | } | |
131 | } | |
fb40c209 AC |
132 | } |
133 | ||
51f77c37 PA |
134 | proc mi_gdb_start_separate_mi_tty { args } { |
135 | global gdb_prompt mi_gdb_prompt | |
136 | global timeout | |
137 | global gdb_spawn_id gdb_main_spawn_id mi_spawn_id | |
138 | global inferior_spawn_id | |
139 | ||
140 | set separate_inferior_pty 0 | |
141 | ||
142 | foreach arg $args { | |
143 | if {$arg == "separate-inferior-tty"} { | |
144 | set separate_inferior_pty 1 | |
145 | } | |
146 | } | |
147 | ||
148 | gdb_start | |
149 | ||
150 | # Create the new PTY for the MI UI. | |
151 | spawn -pty | |
152 | set mi_spawn_id $spawn_id | |
153 | set mi_tty_name $spawn_out(slave,name) | |
154 | gdb_test_multiple "new-ui mi $mi_tty_name" "new-ui" { | |
155 | -re "New UI allocated\r\n$gdb_prompt $" { | |
156 | } | |
157 | } | |
158 | ||
159 | # Switch to the MI channel. | |
160 | set gdb_main_spawn_id $gdb_spawn_id | |
161 | switch_gdb_spawn_id $mi_spawn_id | |
162 | ||
163 | # Consume pending output and MI prompt. | |
164 | gdb_expect { | |
165 | -re "$mi_gdb_prompt$" { | |
166 | } | |
167 | default { | |
168 | perror "MI channel failed" | |
169 | remote_close host | |
170 | return -1 | |
171 | } | |
172 | } | |
173 | ||
174 | if {$separate_inferior_pty} { | |
175 | mi_create_inferior_pty | |
176 | } | |
177 | ||
178 | mi_detect_async | |
179 | ||
180 | return 0 | |
181 | } | |
182 | ||
183 | # | |
184 | # default_mi_gdb_start [FLAGS] -- start gdb running, default procedure | |
fb40c209 | 185 | # |
51f77c37 PA |
186 | # If "separate-inferior-tty" is specified, the inferior works with |
187 | # it's own PTY. | |
ecd3fd0f | 188 | # |
51f77c37 PA |
189 | # If "separate-mi-tty" is specified, the gdb starts in CLI mode, with |
190 | # MI running on a secondary UI, on its own tty. | |
fb40c209 AC |
191 | # |
192 | # When running over NFS, particularly if running many simultaneous | |
193 | # tests on different hosts all using the same server, things can | |
194 | # get really slow. Give gdb at least 3 minutes to start up. | |
195 | # | |
79732189 | 196 | proc default_mi_gdb_start { args } { |
3608f86c | 197 | global use_gdb_stub |
fb40c209 | 198 | global GDB |
6b8ce727 | 199 | global INTERNAL_GDBFLAGS GDBFLAGS |
fb40c209 AC |
200 | global gdb_prompt |
201 | global mi_gdb_prompt | |
202 | global timeout | |
51f77c37 | 203 | global gdb_spawn_id gdb_main_spawn_id inferior_spawn_id mi_spawn_id |
fb40c209 | 204 | global MIFLAGS |
994e9c83 | 205 | global FORCE_SEPARATE_MI_TTY |
51f77c37 | 206 | |
b3247276 TT |
207 | # Keep track of the number of times GDB has been launched. |
208 | global gdb_instances | |
209 | incr gdb_instances | |
210 | ||
211 | gdb_stdin_log_init | |
212 | ||
51f77c37 PA |
213 | if {[info exists FORCE_SEPARATE_MI_TTY]} { |
214 | set separate_mi_pty $FORCE_SEPARATE_MI_TTY | |
215 | } else { | |
216 | set separate_mi_pty 0 | |
217 | } | |
218 | ||
219 | set separate_inferior_pty 0 | |
220 | ||
221 | foreach arg $args { | |
222 | if {$arg == "separate-mi-tty"} { | |
223 | set separate_mi_pty 1 | |
224 | } elseif {$arg == "separate-inferior-tty"} { | |
225 | set separate_inferior_pty 1 | |
226 | } | |
227 | } | |
228 | ||
229 | if {$separate_mi_pty} { | |
230 | return [eval mi_gdb_start_separate_mi_tty $args] | |
231 | } | |
fb40c209 | 232 | |
ecd3fd0f BR |
233 | set inferior_pty no-tty |
234 | ||
e11ac3a3 JK |
235 | # Set the default value, it may be overriden later by specific testfile. |
236 | set use_gdb_stub [target_info exists use_gdb_stub] | |
237 | ||
1759b3c3 AC |
238 | # Start SID. |
239 | if { [info procs sid_start] != "" } { | |
240 | verbose "Spawning SID" | |
241 | sid_start | |
242 | } | |
243 | ||
fb40c209 | 244 | if [info exists gdb_spawn_id] { |
ae59b1da | 245 | return 0 |
fb40c209 AC |
246 | } |
247 | ||
2f4b83cd PA |
248 | save_vars { GDBFLAGS } { |
249 | append GDBFLAGS " $MIFLAGS" | |
250 | ||
251 | set res [gdb_spawn] | |
252 | if { $res != 0} { | |
253 | return $res | |
fb40c209 AC |
254 | } |
255 | } | |
ecd3fd0f | 256 | |
fb40c209 | 257 | gdb_expect { |
1f312e79 JJ |
258 | -re "~\"GNU.*\r\n~\".*$mi_gdb_prompt$" { |
259 | # We have a new format mi startup prompt. If we are | |
260 | # running mi1, then this is an error as we should be | |
261 | # using the old-style prompt. | |
262 | if { $MIFLAGS == "-i=mi1" } { | |
4392c534 YQ |
263 | perror "(mi startup) Got unexpected new mi prompt." |
264 | remote_close host | |
2f4b83cd | 265 | unset gdb_spawn_id |
4392c534 | 266 | return -1 |
1f312e79 JJ |
267 | } |
268 | verbose "GDB initialized." | |
269 | } | |
270 | -re "\[^~\].*$mi_gdb_prompt$" { | |
271 | # We have an old format mi startup prompt. If we are | |
272 | # not running mi1, then this is an error as we should be | |
273 | # using the new-style prompt. | |
274 | if { $MIFLAGS != "-i=mi1" } { | |
4392c534 YQ |
275 | perror "(mi startup) Got unexpected old mi prompt." |
276 | remote_close host | |
2f4b83cd | 277 | unset gdb_spawn_id |
4392c534 | 278 | return -1 |
1f312e79 | 279 | } |
d20bf2e8 | 280 | verbose "GDB initialized." |
fb40c209 | 281 | } |
76c520e0 | 282 | -re ".*unrecognized option.*for a complete list of options." { |
bc6c7af4 | 283 | untested "skip mi tests (not compiled with mi support)." |
4ec70201 | 284 | remote_close host |
2f4b83cd | 285 | unset gdb_spawn_id |
ae59b1da | 286 | return -1 |
76c520e0 | 287 | } |
7d76bd60 | 288 | -re ".*Interpreter `mi' unrecognized." { |
bc6c7af4 | 289 | untested "skip mi tests (not compiled with mi support)." |
4ec70201 | 290 | remote_close host |
2f4b83cd | 291 | unset gdb_spawn_id |
ae59b1da | 292 | return -1 |
7d76bd60 | 293 | } |
fb40c209 AC |
294 | timeout { |
295 | perror "(timeout) GDB never initialized after 10 seconds." | |
4ec70201 | 296 | remote_close host |
2f4b83cd | 297 | unset gdb_spawn_id |
fb40c209 AC |
298 | return -1 |
299 | } | |
300 | } | |
2f4b83cd PA |
301 | set gdb_main_spawn_id $gdb_spawn_id |
302 | set mi_spawn_id $gdb_spawn_id | |
fb40c209 AC |
303 | |
304 | # FIXME: mi output does not go through pagers, so these can be removed. | |
305 | # force the height to "unlimited", so no pagers get used | |
306 | send_gdb "100-gdb-set height 0\n" | |
307 | gdb_expect 10 { | |
4392c534 | 308 | -re ".*100-gdb-set height 0\r\n100\\\^done\r\n$mi_gdb_prompt$" { |
fb40c209 AC |
309 | verbose "Setting height to 0." 2 |
310 | } | |
311 | timeout { | |
312 | warning "Couldn't set the height to 0" | |
313 | } | |
314 | } | |
315 | # force the width to "unlimited", so no wraparound occurs | |
316 | send_gdb "101-gdb-set width 0\n" | |
317 | gdb_expect 10 { | |
318 | -re ".*101-gdb-set width 0\r\n101\\\^done\r\n$mi_gdb_prompt$" { | |
319 | verbose "Setting width to 0." 2 | |
320 | } | |
321 | timeout { | |
322 | warning "Couldn't set the width to 0." | |
323 | } | |
324 | } | |
e8376742 | 325 | |
ecd3fd0f | 326 | if { $separate_inferior_pty } { |
51f77c37 | 327 | mi_create_inferior_pty |
ecd3fd0f | 328 | } |
fb40c209 | 329 | |
e8376742 PA |
330 | if {![info exists inferior_spawn_id]} { |
331 | set inferior_spawn_id $gdb_spawn_id | |
332 | } | |
333 | ||
fcdfa280 | 334 | mi_detect_async |
f7f9a841 | 335 | |
ae59b1da | 336 | return 0 |
fb40c209 AC |
337 | } |
338 | ||
79732189 AR |
339 | # |
340 | # Overridable function. You can override this function in your | |
341 | # baseboard file. | |
4392c534 | 342 | # |
79732189 | 343 | proc mi_gdb_start { args } { |
51f77c37 | 344 | return [eval default_mi_gdb_start $args] |
79732189 AR |
345 | } |
346 | ||
fb40c209 AC |
347 | # Many of the tests depend on setting breakpoints at various places and |
348 | # running until that breakpoint is reached. At times, we want to start | |
349 | # with a clean-slate with respect to breakpoints, so this utility proc | |
350 | # lets us do this without duplicating this code everywhere. | |
351 | # | |
352 | ||
353 | proc mi_delete_breakpoints {} { | |
354 | global mi_gdb_prompt | |
355 | ||
356 | # FIXME: The mi operation won't accept a prompt back and will use the 'all' arg | |
357 | send_gdb "102-break-delete\n" | |
358 | gdb_expect 30 { | |
359 | -re "Delete all breakpoints.*y or n.*$" { | |
4ec70201 | 360 | send_gdb "y\n" |
fb40c209 | 361 | exp_continue |
4392c534 | 362 | } |
39fb8e9e | 363 | -re "102-break-delete\r\n102\\\^done\r\n$mi_gdb_prompt$" { |
4392c534 | 364 | # This happens if there were no breakpoints |
fb40c209 | 365 | } |
f1c8a949 | 366 | timeout { perror "Delete all breakpoints in mi_delete_breakpoints (timeout)" ; return } |
fb40c209 AC |
367 | } |
368 | ||
369 | # The correct output is not "No breakpoints or watchpoints." but an | |
370 | # empty BreakpointTable. Also, a query is not acceptable with mi. | |
371 | send_gdb "103-break-list\n" | |
372 | gdb_expect 30 { | |
373 | -re "103-break-list\r\n103\\\^done,BreakpointTable=\{\}\r\n$mi_gdb_prompt$" {} | |
6f3f3097 | 374 | -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 |
375 | -re "103-break-list\r\n103\\\^doneNo breakpoints or watchpoints.\r\n\r\n$mi_gdb_prompt$" {warning "Unexpected console text received"} |
376 | -re "$mi_gdb_prompt$" { perror "Breakpoints not deleted" ; return } | |
377 | -re "Delete all breakpoints.*or n.*$" { | |
4ec70201 PA |
378 | warning "Unexpected prompt for breakpoints deletion" |
379 | send_gdb "y\n" | |
fb40c209 AC |
380 | exp_continue |
381 | } | |
382 | timeout { perror "-break-list (timeout)" ; return } | |
383 | } | |
384 | } | |
385 | ||
386 | proc mi_gdb_reinitialize_dir { subdir } { | |
387 | global mi_gdb_prompt | |
da81390b | 388 | global MIFLAGS |
fb40c209 | 389 | |
fb40c209 | 390 | if [is_remote host] { |
ae59b1da | 391 | return "" |
fb40c209 AC |
392 | } |
393 | ||
da81390b JJ |
394 | if { $MIFLAGS == "-i=mi1" } { |
395 | send_gdb "104-environment-directory\n" | |
396 | gdb_expect 60 { | |
fb40c209 | 397 | -re ".*Reinitialize source path to empty.*y or n. " { |
4392c534 | 398 | warning "Got confirmation prompt for dir reinitialization." |
fb40c209 AC |
399 | send_gdb "y\n" |
400 | gdb_expect 60 { | |
401 | -re "$mi_gdb_prompt$" {} | |
4392c534 | 402 | timeout {error "Dir reinitialization failed (timeout)"} |
fb40c209 AC |
403 | } |
404 | } | |
405 | -re "$mi_gdb_prompt$" {} | |
4392c534 | 406 | timeout {error "Dir reinitialization failed (timeout)"} |
da81390b JJ |
407 | } |
408 | } else { | |
4392c534 YQ |
409 | send_gdb "104-environment-directory -r\n" |
410 | gdb_expect 60 { | |
411 | -re "104\\\^done,source-path=.*\r\n$mi_gdb_prompt$" {} | |
412 | -re "$mi_gdb_prompt$" {} | |
413 | timeout {error "Dir reinitialization failed (timeout)"} | |
da81390b | 414 | } |
fb40c209 AC |
415 | } |
416 | ||
417 | send_gdb "105-environment-directory $subdir\n" | |
418 | gdb_expect 60 { | |
419 | -re "Source directories searched.*$mi_gdb_prompt$" { | |
420 | verbose "Dir set to $subdir" | |
421 | } | |
da81390b | 422 | -re "105\\\^done.*\r\n$mi_gdb_prompt$" { |
4392c534 | 423 | # FIXME: We return just the prompt for now. |
fb40c209 AC |
424 | verbose "Dir set to $subdir" |
425 | # perror "Dir \"$subdir\" failed." | |
426 | } | |
427 | } | |
428 | } | |
429 | ||
da6012e5 DJ |
430 | # Send GDB the "target" command. |
431 | # FIXME: Some of these patterns are not appropriate for MI. Based on | |
432 | # config/monitor.exp:gdb_target_command. | |
433 | proc mi_gdb_target_cmd { targetname serialport } { | |
434 | global mi_gdb_prompt | |
435 | ||
ef783a7d | 436 | set serialport_re [string_to_regexp $serialport] |
da6012e5 DJ |
437 | for {set i 1} {$i <= 3} {incr i} { |
438 | send_gdb "47-target-select $targetname $serialport\n" | |
439 | gdb_expect 60 { | |
56a8e183 | 440 | -re "47\\^connected.*$mi_gdb_prompt" { |
4ec70201 | 441 | verbose "Set target to $targetname" |
ae59b1da | 442 | return 0 |
da6012e5 | 443 | } |
401ea829 | 444 | -re "unknown host.*$mi_gdb_prompt" { |
4392c534 | 445 | verbose "Couldn't look up $serialport" |
401ea829 | 446 | } |
da6012e5 | 447 | -re "Couldn't establish connection to remote.*$mi_gdb_prompt$" { |
4ec70201 | 448 | verbose "Connection failed" |
da6012e5 DJ |
449 | } |
450 | -re "Remote MIPS debugging.*$mi_gdb_prompt$" { | |
4ec70201 | 451 | verbose "Set target to $targetname" |
ae59b1da | 452 | return 0 |
da6012e5 | 453 | } |
ef783a7d | 454 | -re "Remote debugging using .*$serialport_re.*$mi_gdb_prompt$" { |
4ec70201 | 455 | verbose "Set target to $targetname" |
ae59b1da | 456 | return 0 |
da6012e5 DJ |
457 | } |
458 | -re "Remote target $targetname connected to.*$mi_gdb_prompt$" { | |
4ec70201 | 459 | verbose "Set target to $targetname" |
ae59b1da | 460 | return 0 |
da6012e5 | 461 | } |
4392c534 | 462 | -re "Connected to.*$mi_gdb_prompt$" { |
4ec70201 | 463 | verbose "Set target to $targetname" |
ae59b1da | 464 | return 0 |
da6012e5 DJ |
465 | } |
466 | -re "Ending remote.*$mi_gdb_prompt$" { } | |
467 | -re "Connection refused.*$mi_gdb_prompt$" { | |
468 | verbose "Connection refused by remote target. Pausing, and trying again." | |
469 | sleep 5 | |
470 | continue | |
471 | } | |
56a8e183 | 472 | -re "Non-stop mode requested, but remote does not support non-stop.*$mi_gdb_prompt" { |
bc6c7af4 | 473 | unsupported "non-stop mode not supported" |
56a8e183 PA |
474 | return 1 |
475 | } | |
da6012e5 | 476 | -re "Timeout reading from remote system.*$mi_gdb_prompt$" { |
4ec70201 | 477 | verbose "Got timeout error from gdb." |
da6012e5 DJ |
478 | } |
479 | timeout { | |
4ec70201 | 480 | send_gdb "\ 3" |
da6012e5 DJ |
481 | break |
482 | } | |
483 | } | |
484 | } | |
485 | return 1 | |
486 | } | |
487 | ||
fb40c209 | 488 | # |
da6012e5 | 489 | # load a file into the debugger (file command only). |
fb40c209 AC |
490 | # return a -1 if anything goes wrong. |
491 | # | |
da6012e5 | 492 | proc mi_gdb_file_cmd { arg } { |
fb40c209 AC |
493 | global loadpath |
494 | global loadfile | |
495 | global GDB | |
496 | global mi_gdb_prompt | |
b741e217 | 497 | global last_loaded_file |
fb40c209 AC |
498 | upvar timeout timeout |
499 | ||
6b6a3e05 JM |
500 | # GCC for Windows target may create foo.exe given "-o foo". |
501 | if { ![file exists $arg] && [file exists "$arg.exe"] } { | |
502 | set arg "$arg.exe" | |
503 | } | |
504 | ||
b741e217 | 505 | set last_loaded_file $arg |
b53f9b27 | 506 | |
da6012e5 | 507 | if [is_remote host] { |
4ec70201 | 508 | set arg [remote_download host $arg] |
da6012e5 DJ |
509 | if { $arg == "" } { |
510 | error "download failed" | |
ae59b1da | 511 | return -1 |
da6012e5 DJ |
512 | } |
513 | } | |
fb40c209 | 514 | |
fb40c209 AC |
515 | # FIXME: Several of these patterns are only acceptable for console |
516 | # output. Queries are an error for mi. | |
517 | send_gdb "105-file-exec-and-symbols $arg\n" | |
518 | gdb_expect 120 { | |
3453e7e4 | 519 | -re "Reading symbols from.*$mi_gdb_prompt$" { |
4392c534 YQ |
520 | verbose "\t\tLoaded $arg into the $GDB" |
521 | return 0 | |
522 | } | |
523 | -re "has no symbol-table.*$mi_gdb_prompt$" { | |
524 | perror "$arg wasn't compiled with \"-g\"" | |
525 | return -1 | |
526 | } | |
527 | -re "Load new symbol table from \".*\".*y or n. $" { | |
528 | send_gdb "y\n" | |
529 | gdb_expect 120 { | |
3453e7e4 | 530 | -re "Reading symbols from.*$mi_gdb_prompt$" { |
4392c534 YQ |
531 | verbose "\t\tLoaded $arg with new symbol table into $GDB" |
532 | # All OK | |
533 | } | |
534 | timeout { | |
535 | perror "(timeout) Couldn't load $arg, other program already loaded." | |
536 | return -1 | |
537 | } | |
538 | } | |
539 | } | |
540 | -re "No such file or directory.*$mi_gdb_prompt$" { | |
541 | perror "($arg) No such file or directory\n" | |
542 | return -1 | |
543 | } | |
544 | -re "105-file-exec-and-symbols .*\r\n105\\\^done\r\n$mi_gdb_prompt$" { | |
545 | # We (MI) are just giving the prompt back for now, instead of giving | |
da6012e5 DJ |
546 | # some acknowledgement. |
547 | return 0 | |
548 | } | |
4392c534 YQ |
549 | timeout { |
550 | perror "couldn't load $arg into $GDB (timed out)." | |
551 | return -1 | |
552 | } | |
da6012e5 | 553 | eof { |
4392c534 YQ |
554 | # This is an attempt to detect a core dump, but seems not to |
555 | # work. Perhaps we need to match .* followed by eof, in which | |
556 | # gdb_expect does not seem to have a way to do that. | |
557 | perror "couldn't load $arg into $GDB (end of file)." | |
558 | return -1 | |
559 | } | |
fb40c209 | 560 | } |
da6012e5 DJ |
561 | } |
562 | ||
563 | # | |
b741e217 | 564 | # connect to the target and download a file, if necessary. |
da6012e5 DJ |
565 | # return a -1 if anything goes wrong. |
566 | # | |
b741e217 | 567 | proc mi_gdb_target_load { } { |
da6012e5 DJ |
568 | global loadpath |
569 | global loadfile | |
570 | global GDB | |
571 | global mi_gdb_prompt | |
e2d69cb5 JZ |
572 | |
573 | if [target_info exists gdb_load_timeout] { | |
574 | set loadtimeout [target_info gdb_load_timeout] | |
575 | } else { | |
576 | set loadtimeout 1600 | |
577 | } | |
da6012e5 | 578 | |
da6012e5 | 579 | if { [info procs gdbserver_gdb_load] != "" } { |
2226f861 | 580 | mi_gdb_test "kill" ".*" "" |
09635af7 MR |
581 | if { [catch gdbserver_gdb_load res] == 1 } { |
582 | perror $res | |
583 | return -1 | |
584 | } | |
da6012e5 DJ |
585 | set protocol [lindex $res 0] |
586 | set gdbport [lindex $res 1] | |
587 | ||
588 | if { [mi_gdb_target_cmd $protocol $gdbport] != 0 } { | |
589 | return -1 | |
590 | } | |
591 | } elseif { [info procs send_target_sid] != "" } { | |
fb40c209 | 592 | # For SID, things get complex |
2b97317d KB |
593 | send_gdb "kill\n" |
594 | gdb_expect 10 { | |
595 | -re ".*$mi_gdb_prompt$" | |
596 | } | |
fb40c209 | 597 | send_target_sid |
e2d69cb5 | 598 | gdb_expect $loadtimeout { |
2f168eed | 599 | -re "\\^done.*$mi_gdb_prompt$" { |
fb40c209 AC |
600 | } |
601 | timeout { | |
e2d69cb5 | 602 | perror "Unable to connect to SID target (timeout)" |
fb40c209 AC |
603 | return -1 |
604 | } | |
605 | } | |
606 | send_gdb "48-target-download\n" | |
e2d69cb5 | 607 | gdb_expect $loadtimeout { |
fb40c209 AC |
608 | -re "48\\^done.*$mi_gdb_prompt$" { |
609 | } | |
610 | timeout { | |
e2d69cb5 | 611 | perror "Unable to download to SID target (timeout)" |
fb40c209 AC |
612 | return -1 |
613 | } | |
614 | } | |
615 | } elseif { [target_info protocol] == "sim" } { | |
cc3c2846 | 616 | set target_sim_options "[board_info target gdb,target_sim_options]" |
fb40c209 | 617 | # For the simulator, just connect to it directly. |
cc3c2846 | 618 | send_gdb "47-target-select sim $target_sim_options\n" |
e2d69cb5 | 619 | gdb_expect $loadtimeout { |
fb40c209 AC |
620 | -re "47\\^connected.*$mi_gdb_prompt$" { |
621 | } | |
622 | timeout { | |
e2d69cb5 | 623 | perror "Unable to select sim target (timeout)" |
fb40c209 AC |
624 | return -1 |
625 | } | |
626 | } | |
627 | send_gdb "48-target-download\n" | |
e2d69cb5 | 628 | gdb_expect $loadtimeout { |
fb40c209 AC |
629 | -re "48\\^done.*$mi_gdb_prompt$" { |
630 | } | |
631 | timeout { | |
e2d69cb5 | 632 | perror "Unable to download to sim target (timeout)" |
fb40c209 AC |
633 | return -1 |
634 | } | |
635 | } | |
b53f9b27 MS |
636 | } elseif { [target_info gdb_protocol] == "remote" } { |
637 | # remote targets | |
8e3049aa PB |
638 | if { [mi_gdb_target_cmd "remote" [target_info netport]] != 0 } { |
639 | perror "Unable to connect to remote target" | |
640 | return -1 | |
b53f9b27 MS |
641 | } |
642 | send_gdb "48-target-download\n" | |
e2d69cb5 | 643 | gdb_expect $loadtimeout { |
b53f9b27 MS |
644 | -re "48\\^done.*$mi_gdb_prompt$" { |
645 | } | |
646 | timeout { | |
e2d69cb5 | 647 | perror "Unable to download to remote target (timeout)" |
b53f9b27 MS |
648 | return -1 |
649 | } | |
650 | } | |
fb40c209 AC |
651 | } |
652 | return 0 | |
653 | } | |
654 | ||
b741e217 DJ |
655 | # |
656 | # load a file into the debugger. | |
657 | # return a -1 if anything goes wrong. | |
658 | # | |
659 | proc mi_gdb_load { arg } { | |
660 | if { $arg != "" } { | |
661 | return [mi_gdb_file_cmd $arg] | |
662 | } | |
663 | return 0 | |
664 | } | |
665 | ||
29119da4 TV |
666 | # Return 1 if symbols were read in using -readnow. Otherwise, return 0. |
667 | # Based on readnow from lib/gdb.exp. | |
668 | ||
669 | proc mi_readnow { args } { | |
670 | global mi_gdb_prompt | |
671 | ||
672 | if { [llength $args] == 1 } { | |
673 | set re [lindex $args 0] | |
674 | } else { | |
675 | set re "" | |
676 | } | |
677 | ||
678 | set readnow_p 0 | |
679 | set cmd "maint print objfiles $re" | |
680 | send_gdb "$cmd\n" | |
681 | gdb_expect { | |
682 | -re ".gdb_index: faked for ..readnow.." { | |
683 | # Record that we've seen the above pattern. | |
684 | set readnow_p 1 | |
685 | exp_continue | |
686 | } | |
687 | -re "\\^done\r\n$mi_gdb_prompt$" { | |
688 | } | |
689 | } | |
690 | ||
691 | return $readnow_p | |
692 | } | |
693 | ||
ecd3fd0f BR |
694 | # mi_gdb_test COMMAND PATTERN MESSAGE [IPATTERN] -- send a command to gdb; |
695 | # test the result. | |
fb40c209 AC |
696 | # |
697 | # COMMAND is the command to execute, send to GDB with send_gdb. If | |
698 | # this is the null string no command is sent. | |
699 | # PATTERN is the pattern to match for a PASS, and must NOT include | |
700 | # the \r\n sequence immediately before the gdb prompt. | |
4392c534 YQ |
701 | # MESSAGE is the message to be printed. (If this is the empty string, |
702 | # then sometimes we don't call pass or fail at all; I don't | |
f1ea48cb | 703 | # understand this at all.) |
ecd3fd0f | 704 | # IPATTERN is the pattern to match for the inferior's output. This parameter |
4392c534 | 705 | # is optional. If present, it will produce a PASS if the match is |
ecd3fd0f | 706 | # successful, and a FAIL if unsuccessful. |
fb40c209 AC |
707 | # |
708 | # Returns: | |
709 | # 1 if the test failed, | |
710 | # 0 if the test passes, | |
711 | # -1 if there was an internal error. | |
4392c534 | 712 | # |
fb40c209 AC |
713 | proc mi_gdb_test { args } { |
714 | global verbose | |
715 | global mi_gdb_prompt | |
07c98896 | 716 | global GDB expect_out |
405e54e9 | 717 | global inferior_exited_re async |
fb40c209 AC |
718 | upvar timeout timeout |
719 | ||
fb40c209 AC |
720 | set command [lindex $args 0] |
721 | set pattern [lindex $args 1] | |
f1ea48cb | 722 | set message [lindex $args 2] |
fb40c209 | 723 | |
ecd3fd0f BR |
724 | if [llength $args]==4 { |
725 | set ipattern [lindex $args 3] | |
726 | } | |
727 | ||
fb40c209 | 728 | if [llength $args]==5 { |
4ec70201 PA |
729 | set question_string [lindex $args 3] |
730 | set response_string [lindex $args 4] | |
fb40c209 AC |
731 | } else { |
732 | set question_string "^FOOBAR$" | |
733 | } | |
734 | ||
735 | if $verbose>2 then { | |
736 | send_user "Sending \"$command\" to gdb\n" | |
737 | send_user "Looking to match \"$pattern\"\n" | |
738 | send_user "Message is \"$message\"\n" | |
739 | } | |
740 | ||
741 | set result -1 | |
4ec70201 | 742 | set string "${command}\n" |
39fb8e9e BR |
743 | set string_regex [string_to_regexp $command] |
744 | ||
fb40c209 AC |
745 | if { $command != "" } { |
746 | while { "$string" != "" } { | |
4ec70201 PA |
747 | set foo [string first "\n" "$string"] |
748 | set len [string length "$string"] | |
fb40c209 | 749 | if { $foo < [expr $len - 1] } { |
4ec70201 | 750 | set str [string range "$string" 0 $foo] |
fb40c209 | 751 | if { [send_gdb "$str"] != "" } { |
0ac85db5 | 752 | perror "Couldn't send $command to GDB." |
fb40c209 AC |
753 | } |
754 | gdb_expect 2 { | |
755 | -re "\[\r\n\]" { } | |
756 | timeout { } | |
757 | } | |
4ec70201 | 758 | set string [string range "$string" [expr $foo + 1] end] |
fb40c209 | 759 | } else { |
4ec70201 | 760 | break |
fb40c209 AC |
761 | } |
762 | } | |
763 | if { "$string" != "" } { | |
764 | if { [send_gdb "$string"] != "" } { | |
0ac85db5 | 765 | perror "Couldn't send $command to GDB." |
fb40c209 AC |
766 | } |
767 | } | |
768 | } | |
769 | ||
770 | if [info exists timeout] { | |
4ec70201 | 771 | set tmt $timeout |
fb40c209 | 772 | } else { |
4ec70201 | 773 | global timeout |
fb40c209 | 774 | if [info exists timeout] { |
4ec70201 | 775 | set tmt $timeout |
fb40c209 | 776 | } else { |
4ec70201 | 777 | set tmt 60 |
fb40c209 AC |
778 | } |
779 | } | |
405e54e9 JK |
780 | if {$async} { |
781 | # With $prompt_re "" there may come arbitrary asynchronous response | |
782 | # from the previous command, before or after $string_regex. | |
783 | set string_regex ".*" | |
784 | } | |
9d81d21b | 785 | verbose -log "Expecting: ^($string_regex\[\r\n\]+)?($pattern\[\r\n\]+$mi_gdb_prompt\[ \]*)" |
fb40c209 AC |
786 | gdb_expect $tmt { |
787 | -re "\\*\\*\\* DOSEXIT code.*" { | |
788 | if { $message != "" } { | |
4ec70201 | 789 | fail "$message" |
fb40c209 | 790 | } |
ae59b1da | 791 | return -1 |
fb40c209 AC |
792 | } |
793 | -re "Ending remote debugging.*$mi_gdb_prompt\[ \]*$" { | |
794 | if ![isnative] then { | |
795 | warning "Can`t communicate to remote target." | |
796 | } | |
797 | gdb_exit | |
798 | gdb_start | |
799 | set result -1 | |
7ddebc7e | 800 | } |
405e54e9 | 801 | -re "^($string_regex\[\r\n\]+)?($pattern\[\r\n\]+$mi_gdb_prompt\[ \]*)" { |
39fb8e9e BR |
802 | # At this point, $expect_out(1,string) is the MI input command. |
803 | # and $expect_out(2,string) is the MI output command. | |
804 | # If $expect_out(1,string) is "", then there was no MI input command here. | |
805 | ||
40e55bef BR |
806 | # NOTE, there is no trailing anchor because with GDB/MI, |
807 | # asynchronous responses can happen at any point, causing more | |
808 | # data to be available. Normally an anchor is used to make | |
809 | # sure the end of the output is matched, however, $mi_gdb_prompt | |
810 | # is just as good of an anchor since mi_gdb_test is meant to | |
811 | # match a single mi output command. If a second GDB/MI output | |
812 | # response is sent, it will be in the buffer for the next | |
813 | # time mi_gdb_test is called. | |
7ddebc7e KS |
814 | if ![string match "" $message] then { |
815 | pass "$message" | |
816 | } | |
817 | set result 0 | |
fb40c209 AC |
818 | } |
819 | -re "(${question_string})$" { | |
4ec70201 PA |
820 | send_gdb "$response_string\n" |
821 | exp_continue | |
fb40c209 AC |
822 | } |
823 | -re "Undefined.* command:.*$mi_gdb_prompt\[ \]*$" { | |
824 | perror "Undefined command \"$command\"." | |
4392c534 | 825 | fail "$message" |
fb40c209 AC |
826 | set result 1 |
827 | } | |
828 | -re "Ambiguous command.*$mi_gdb_prompt\[ \]*$" { | |
829 | perror "\"$command\" is not a unique command name." | |
4392c534 | 830 | fail "$message" |
fb40c209 | 831 | set result 1 |
fb40c209 | 832 | } |
fda326dd | 833 | -re "$inferior_exited_re with code \[0-9\]+.*$mi_gdb_prompt\[ \]*$" { |
fb40c209 | 834 | if ![string match "" $message] then { |
ed4c619a | 835 | set errmsg "$message (the program exited)" |
fb40c209 | 836 | } else { |
ed4c619a | 837 | set errmsg "$command (the program exited)" |
fb40c209 AC |
838 | } |
839 | fail "$errmsg" | |
840 | return -1 | |
841 | } | |
842 | -re "The program is not being run.*$mi_gdb_prompt\[ \]*$" { | |
843 | if ![string match "" $message] then { | |
ed4c619a | 844 | set errmsg "$message (the program is no longer running)" |
fb40c209 | 845 | } else { |
ed4c619a | 846 | set errmsg "$command (the program is no longer running)" |
fb40c209 AC |
847 | } |
848 | fail "$errmsg" | |
849 | return -1 | |
850 | } | |
851 | -re ".*$mi_gdb_prompt\[ \]*$" { | |
852 | if ![string match "" $message] then { | |
5b291c04 | 853 | fail "$message (unexpected output)" |
fb40c209 AC |
854 | } |
855 | set result 1 | |
856 | } | |
857 | "<return>" { | |
858 | send_gdb "\n" | |
859 | perror "Window too small." | |
4392c534 | 860 | fail "$message" |
fb40c209 AC |
861 | } |
862 | eof { | |
863 | perror "Process no longer exists" | |
864 | if { $message != "" } { | |
865 | fail "$message" | |
866 | } | |
867 | return -1 | |
868 | } | |
869 | full_buffer { | |
870 | perror "internal buffer is full." | |
4392c534 | 871 | fail "$message" |
fb40c209 AC |
872 | } |
873 | timeout { | |
874 | if ![string match "" $message] then { | |
875 | fail "$message (timeout)" | |
876 | } | |
877 | set result 1 | |
878 | } | |
879 | } | |
ecd3fd0f BR |
880 | |
881 | # If the GDB output matched, compare the inferior output. | |
882 | if { $result == 0 } { | |
883 | if [ info exists ipattern ] { | |
d084b331 | 884 | if { ![target_info exists gdb,noinferiorio] } { |
e8376742 PA |
885 | global gdb_spawn_id inferior_spawn_id |
886 | ||
887 | set sid "$inferior_spawn_id $gdb_spawn_id" | |
888 | gdb_expect { | |
889 | -i "$sid" -re "$ipattern" { | |
890 | pass "$message inferior output" | |
d084b331 | 891 | } |
e8376742 PA |
892 | timeout { |
893 | fail "$message inferior output (timeout)" | |
894 | set result 1 | |
d084b331 | 895 | } |
ecd3fd0f | 896 | } |
d084b331 DJ |
897 | } else { |
898 | unsupported "$message inferior output" | |
ecd3fd0f | 899 | } |
6ec41e1e | 900 | } |
ecd3fd0f BR |
901 | } |
902 | ||
fb40c209 AC |
903 | return $result |
904 | } | |
905 | ||
17b2616c PA |
906 | # Collect output sent to the console output stream until UNTIL is |
907 | # seen. UNTIL is a regular expression. MESSAGE is the message to be | |
908 | # printed in case of timeout. | |
909 | ||
910 | proc mi_gdb_expect_cli_output {until message} { | |
911 | ||
912 | set output "" | |
913 | gdb_expect { | |
914 | -re "~\"(\[^\r\n\]+)\"\r\n" { | |
915 | append output $expect_out(1,string) | |
916 | exp_continue | |
917 | } | |
918 | -notransfer -re "$until" { | |
919 | # Done | |
920 | } | |
921 | timeout { | |
922 | fail "$message (timeout)" | |
923 | return "" | |
924 | } | |
925 | } | |
926 | ||
927 | return $output | |
928 | } | |
929 | ||
fb40c209 AC |
930 | # |
931 | # MI run command. (A modified version of gdb_run_cmd) | |
932 | # | |
933 | ||
934 | # In patterns, the newline sequence ``\r\n'' is matched explicitly as | |
935 | # ``.*$'' could swallow up output that we attempt to match elsewhere. | |
936 | ||
a2199296 SM |
937 | # Send the command to run the test program. |
938 | # | |
939 | # If USE_MI_COMMAND is true, the "-exec-run" command is used. | |
940 | # Otherwise, the "run" (CLI) command is used. If the global USE_GDB_STUB is | |
941 | # true, -exec-continue and continue are used instead of their run counterparts. | |
942 | # | |
943 | # ARGS is passed as argument to the command used to run the test program. | |
944 | # Beware that arguments to "-exec-run" do not have the same semantics as | |
945 | # arguments to the "run" command, so USE_MI_COMMAND influences the meaning | |
946 | # of ARGS. If USE_MI_COMMAND is true, they are arguments to -exec-run. | |
947 | # If USE_MI_COMMAND is false, they are effectively arguments passed | |
948 | # to the test program. If the global USE_GDB_STUB is true, ARGS is not used. | |
36dfb11c | 949 | proc mi_run_cmd_full {use_mi_command args} { |
e11ac3a3 | 950 | global mi_gdb_prompt use_gdb_stub |
66bb093b | 951 | global thread_selected_re |
c86cf029 | 952 | global library_loaded_re |
fb40c209 | 953 | |
36dfb11c TT |
954 | if {$use_mi_command} { |
955 | set run_prefix "220-exec-" | |
956 | set run_match "220" | |
957 | } else { | |
958 | set run_prefix "" | |
959 | set run_match "" | |
960 | } | |
961 | ||
a25eb028 MR |
962 | foreach command [gdb_init_commands] { |
963 | send_gdb "$command\n" | |
fb40c209 AC |
964 | gdb_expect 30 { |
965 | -re "$mi_gdb_prompt$" { } | |
966 | default { | |
cf144ec8 | 967 | unresolved "gdb_init_command for target failed" |
ae59b1da | 968 | return -1 |
fb40c209 AC |
969 | } |
970 | } | |
971 | } | |
972 | ||
b741e217 | 973 | if { [mi_gdb_target_load] < 0 } { |
56a8e183 | 974 | return -1 |
b741e217 DJ |
975 | } |
976 | ||
e11ac3a3 | 977 | if $use_gdb_stub { |
fb40c209 | 978 | if [target_info exists gdb,do_reload_on_run] { |
4ec70201 | 979 | send_gdb "${run_prefix}continue\n" |
fb40c209 | 980 | gdb_expect 60 { |
36dfb11c | 981 | -re "${run_match}\\^running\[\r\n\]+\\*running,thread-id=\"\[^\"\]+\"\r\n$mi_gdb_prompt" {} |
88bbeca9 | 982 | -re "${run_match}\\^error.*$mi_gdb_prompt" {return -1} |
fb40c209 AC |
983 | default {} |
984 | } | |
ae59b1da | 985 | return 0 |
fb40c209 | 986 | } |
6a90e1d0 AC |
987 | |
988 | if [target_info exists gdb,start_symbol] { | |
4ec70201 | 989 | set start [target_info gdb,start_symbol] |
6a90e1d0 | 990 | } else { |
4ec70201 | 991 | set start "start" |
6a90e1d0 AC |
992 | } |
993 | ||
994 | # HACK: Should either use 000-jump or fix the target code | |
995 | # to better handle RUN. | |
996 | send_gdb "jump *$start\n" | |
997 | warning "Using CLI jump command, expect run-to-main FAIL" | |
6d265cb4 | 998 | gdb_expect { |
089a9490 AB |
999 | -re "&\"jump \\*${start}\\\\n\"\[\r\n\]+~\"Continuing at 0x\[0-9A-Fa-f\]+\.\\\\n\"\[\r\n\]+\\^running\[\r\n\]+\\*running,thread-id=\"\[^\"\]+\"\[\r\n\]+${mi_gdb_prompt}" {} |
1000 | timeout { | |
cf144ec8 | 1001 | unresolved "unable to start target" |
089a9490 AB |
1002 | return -1 |
1003 | } | |
6d265cb4 | 1004 | } |
56a8e183 | 1005 | return 0 |
fb40c209 AC |
1006 | } |
1007 | ||
2f25d70f | 1008 | send_gdb "${run_prefix}run $args\n" |
fb40c209 | 1009 | gdb_expect { |
36dfb11c | 1010 | -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 | 1011 | } |
56a8e183 | 1012 | -re "\\^error,msg=\"The target does not support running in non-stop mode.\"" { |
bc6c7af4 | 1013 | unsupported "non-stop mode not supported" |
56a8e183 PA |
1014 | return -1 |
1015 | } | |
fb40c209 | 1016 | timeout { |
cf144ec8 | 1017 | unresolved "unable to start target" |
56a8e183 | 1018 | return -1 |
fb40c209 AC |
1019 | } |
1020 | } | |
2d0720d9 | 1021 | # NOTE: Shortly after this there will be a ``000*stopped,...(gdb)'' |
56a8e183 PA |
1022 | |
1023 | return 0 | |
fb40c209 AC |
1024 | } |
1025 | ||
36dfb11c TT |
1026 | # A wrapper for mi_run_cmd_full which uses -exec-run and |
1027 | # -exec-continue, as appropriate. ARGS are passed verbatim to | |
1028 | # mi_run_cmd_full. | |
1029 | proc mi_run_cmd {args} { | |
1030 | return [eval mi_run_cmd_full 1 $args] | |
1031 | } | |
1032 | ||
1033 | # A wrapper for mi_run_cmd_full which uses the CLI commands 'run' and | |
1034 | # 'continue', as appropriate. ARGS are passed verbatim to | |
1035 | # mi_run_cmd_full. | |
1036 | proc mi_run_with_cli {args} { | |
1037 | return [eval mi_run_cmd_full 0 $args] | |
1038 | } | |
1039 | ||
b75d55d4 PA |
1040 | # Starts fresh GDB binary and loads an optional executable into GDB. |
1041 | # Usage: mi_clean_restart [executable] | |
1042 | # EXECUTABLE is the basename of the binary. | |
1043 | # Return -1 if starting gdb or loading the executable failed. | |
fb40c209 | 1044 | |
b75d55d4 | 1045 | proc mi_clean_restart { args } { |
fb40c209 AC |
1046 | global srcdir |
1047 | global subdir | |
b75d55d4 PA |
1048 | global errcnt |
1049 | global warncnt | |
1050 | ||
1051 | if { [llength $args] > 1 } { | |
1052 | error "bad number of args: [llength $args]" | |
1053 | } | |
1054 | ||
1055 | gdb_exit | |
1056 | ||
1057 | # This is a clean restart, so reset error and warning count. | |
1058 | set errcnt 0 | |
1059 | set warncnt 0 | |
1060 | ||
1061 | if {[mi_gdb_start]} { | |
1062 | return -1 | |
1063 | } | |
fb40c209 | 1064 | |
fb40c209 | 1065 | mi_gdb_reinitialize_dir $srcdir/$subdir |
fb40c209 | 1066 | |
b75d55d4 PA |
1067 | if { [llength $args] >= 1 } { |
1068 | set executable [lindex $args 0] | |
1069 | set binfile [standard_output_file ${executable}] | |
1070 | return [mi_gdb_load ${binfile}] | |
1071 | } | |
fb40c209 | 1072 | |
b75d55d4 PA |
1073 | return 0 |
1074 | } | |
08b468e0 KS |
1075 | |
1076 | # Just like gdb's "runto" proc, it will run the target to a given | |
1077 | # function. The big difference here between mi_runto and mi_execute_to | |
1078 | # is that mi_execute_to must have the inferior running already. This | |
1079 | # proc will (like gdb's runto) (re)start the inferior, too. | |
1080 | # | |
1081 | # FUNC is the linespec of the place to stop (it inserts a breakpoint here). | |
1082 | # It returns: | |
0ac85db5 | 1083 | # -1 if failed, timedout |
08b468e0 | 1084 | # 0 if test passed |
8abd8ee8 PA |
1085 | # |
1086 | # Supported options: | |
1087 | # | |
1088 | # -qualified -- pass --qualified to -break-insert | |
08b468e0 | 1089 | |
8abd8ee8 | 1090 | proc mi_runto_helper {func run_or_continue args} { |
08b468e0 | 1091 | global mi_gdb_prompt expect_out |
76ff342d | 1092 | global hex decimal fullname_syntax |
08b468e0 | 1093 | |
8abd8ee8 PA |
1094 | parse_args {{qualified}} |
1095 | ||
08b468e0 | 1096 | set test "mi runto $func" |
4b48d439 KS |
1097 | set bp [mi_make_breakpoint -type breakpoint -disp del \ |
1098 | -func $func\(\\\(.*\\\)\)?] | |
8abd8ee8 PA |
1099 | set extra_opts "" |
1100 | if {$qualified} { | |
1101 | append extra_opts "--qualified" | |
1102 | } | |
1103 | mi_gdb_test "200-break-insert $extra_opts -t $func" "200\\^done,$bp" \ | |
4b48d439 | 1104 | "breakpoint at $func" |
08b468e0 | 1105 | |
f7e97bb3 | 1106 | if {$run_or_continue == "run"} { |
56a8e183 PA |
1107 | if { [mi_run_cmd] < 0 } { |
1108 | return -1 | |
1109 | } | |
f7e97bb3 | 1110 | } else { |
bb378428 | 1111 | mi_send_resuming_command "exec-continue" "$test" |
f7e97bb3 | 1112 | } |
74a44383 | 1113 | |
18ac113b | 1114 | mi_expect_stop "breakpoint-hit" $func ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } $test |
fb40c209 AC |
1115 | } |
1116 | ||
f7e97bb3 | 1117 | proc mi_runto {func} { |
56a8e183 | 1118 | return [mi_runto_helper $func "run"] |
f7e97bb3 | 1119 | } |
fb40c209 | 1120 | |
f71e6719 PA |
1121 | # Just like runto_main but works with the MI interface. |
1122 | ||
1123 | proc mi_runto_main {} { | |
8abd8ee8 | 1124 | return [mi_runto_helper "main" "run" -qualified] |
f71e6719 PA |
1125 | } |
1126 | ||
fb40c209 | 1127 | # Next to the next statement |
08b468e0 | 1128 | # For return values, see mi_execute_to_helper |
fb40c209 AC |
1129 | |
1130 | proc mi_next { test } { | |
dc360f58 | 1131 | return [mi_next_to {.*} {.*} {.*} {.*} $test] |
fb40c209 AC |
1132 | } |
1133 | ||
1134 | ||
1135 | # Step to the next statement | |
08b468e0 | 1136 | # For return values, see mi_execute_to_helper |
fb40c209 AC |
1137 | |
1138 | proc mi_step { test } { | |
dc360f58 | 1139 | return [mi_step_to {.*} {.*} {.*} {.*} $test] |
fb40c209 | 1140 | } |
dcf95b47 | 1141 | |
f7f9a841 VP |
1142 | set async "unknown" |
1143 | ||
fcdfa280 | 1144 | proc mi_detect_async {} { |
f7f9a841 VP |
1145 | global async |
1146 | global mi_gdb_prompt | |
1147 | ||
329ea579 | 1148 | send_gdb "show mi-async\n" |
4392c534 | 1149 | |
a2840c35 | 1150 | gdb_expect { |
329ea579 | 1151 | -re "asynchronous mode is on...*$mi_gdb_prompt$" { |
4392c534 YQ |
1152 | set async 1 |
1153 | } | |
1154 | -re ".*$mi_gdb_prompt$" { | |
1155 | set async 0 | |
1156 | } | |
1157 | timeout { | |
1158 | set async 0 | |
1159 | } | |
f7f9a841 VP |
1160 | } |
1161 | return $async | |
1162 | } | |
1163 | ||
bb378428 VP |
1164 | # Wait for MI *stopped notification to appear. |
1165 | # The REASON, FUNC, ARGS, FILE and LINE are regular expressions | |
05acf274 JK |
1166 | # to match against whatever is output in *stopped. FILE may also match |
1167 | # filename of a file without debug info. ARGS should not include [] the | |
1168 | # list of argument is enclosed in, and other regular expressions should | |
1169 | # not include quotes. | |
bb378428 VP |
1170 | # If EXTRA is a list of one element, it's the regular expression |
1171 | # for output expected right after *stopped, and before GDB prompt. | |
1172 | # If EXTRA is a list of two elements, the first element is for | |
1173 | # output right after *stopped, and the second element is output | |
1174 | # right after reason field. The regex after reason should not include | |
1175 | # the comma separating it from the following fields. | |
4392c534 | 1176 | # |
05acf274 JK |
1177 | # When we fail to match output at all, -1 is returned. If FILE does |
1178 | # match and the target system has no debug info for FILE return 0. | |
1179 | # Otherwise, the line at which we stop is returned. This is useful when | |
1180 | # exact line is not possible to specify for some reason -- one can pass | |
d0b76dc6 DJ |
1181 | # the .* or "\[0-9\]*" regexps for line, and then check the line |
1182 | # programmatically. | |
1183 | # | |
1184 | # Do not pass .* for any argument if you are expecting more than one stop. | |
bb378428 | 1185 | proc mi_expect_stop { reason func args file line extra test } { |
1902c51f | 1186 | |
dcf95b47 DJ |
1187 | global mi_gdb_prompt |
1188 | global hex | |
1189 | global decimal | |
76ff342d | 1190 | global fullname_syntax |
f7f9a841 | 1191 | global async |
66bb093b | 1192 | global thread_selected_re |
8d3788bd | 1193 | global breakpoint_re |
bb378428 | 1194 | |
0c7e1a46 PA |
1195 | set any "\[^\n\]*" |
1196 | ||
bb378428 VP |
1197 | set after_stopped "" |
1198 | set after_reason "" | |
1199 | if { [llength $extra] == 2 } { | |
4392c534 YQ |
1200 | set after_stopped [lindex $extra 0] |
1201 | set after_reason [lindex $extra 1] | |
1202 | set after_reason "${after_reason}," | |
bb378428 | 1203 | } elseif { [llength $extra] == 1 } { |
4392c534 | 1204 | set after_stopped [lindex $extra 0] |
bb378428 VP |
1205 | } |
1206 | ||
f7f9a841 | 1207 | if {$async} { |
4392c534 | 1208 | set prompt_re "" |
f7f9a841 | 1209 | } else { |
4392c534 | 1210 | set prompt_re "$mi_gdb_prompt$" |
f7f9a841 VP |
1211 | } |
1212 | ||
1213 | if { $reason == "really-no-reason" } { | |
4392c534 YQ |
1214 | gdb_expect { |
1215 | -re "\\*stopped\r\n$prompt_re" { | |
1216 | pass "$test" | |
1217 | } | |
1218 | timeout { | |
73eb7709 | 1219 | fail "$test (timeout)" |
4392c534 YQ |
1220 | } |
1221 | } | |
1222 | return | |
1223 | } | |
1224 | ||
bb378428 VP |
1225 | if { $reason == "exited-normally" } { |
1226 | ||
4392c534 YQ |
1227 | gdb_expect { |
1228 | -re "\\*stopped,reason=\"exited-normally\"\r\n$prompt_re" { | |
1229 | pass "$test" | |
1230 | } | |
1231 | -re ".*$mi_gdb_prompt$" {fail "continue to end (2)"} | |
1232 | timeout { | |
73eb7709 | 1233 | fail "$test (timeout)" |
4392c534 YQ |
1234 | } |
1235 | } | |
1236 | return | |
bb378428 | 1237 | } |
3deb39c6 SM |
1238 | if { $reason == "exited" } { |
1239 | gdb_expect { | |
1240 | -re "\\*stopped,reason=\"exited\",exit-code=\"\[0-7\]+\"\r\n$prompt_re" { | |
1241 | pass "$test" | |
1242 | } | |
1243 | -re ".*$mi_gdb_prompt$" { | |
1244 | fail "$test (inferior not stopped)" | |
1245 | } | |
1246 | timeout { | |
73eb7709 | 1247 | fail "$test (timeout)" |
3deb39c6 SM |
1248 | } |
1249 | } | |
1250 | return | |
1251 | } | |
bb378428 | 1252 | |
0c7e1a46 PA |
1253 | if { $reason == "solib-event" } { |
1254 | set pattern "\\*stopped,reason=\"solib-event\",thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re" | |
1255 | verbose -log "mi_expect_stop: expecting: $pattern" | |
1256 | gdb_expect { | |
1257 | -re "$pattern" { | |
1258 | pass "$test" | |
1259 | } | |
1260 | timeout { | |
73eb7709 | 1261 | fail "$test (timeout)" |
0c7e1a46 PA |
1262 | } |
1263 | } | |
1264 | return | |
1265 | } | |
1266 | ||
bb378428 VP |
1267 | set args "\\\[$args\\\]" |
1268 | ||
1269 | set bn "" | |
30056ea0 | 1270 | set ebn "" |
bb378428 | 1271 | if { $reason == "breakpoint-hit" } { |
4392c534 | 1272 | set bn {bkptno="[0-9]+",} |
edcc5120 TT |
1273 | } elseif { $reason == "solib-event" } { |
1274 | set bn ".*" | |
30056ea0 AB |
1275 | } elseif { $reason == "exception-caught" } { |
1276 | set ebn {bkptno="[0-9]+",} | |
1277 | set bn ".*" | |
1278 | set reason "breakpoint-hit" | |
bb378428 VP |
1279 | } |
1280 | ||
1281 | set r "" | |
1282 | if { $reason != "" } { | |
4392c534 | 1283 | set r "reason=\"$reason\"," |
bb378428 VP |
1284 | } |
1285 | ||
18ac113b AR |
1286 | |
1287 | set a $after_reason | |
1288 | ||
30056ea0 | 1289 | verbose -log "mi_expect_stop: expecting: \\*stopped,${ebn}${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$func\",args=$args,(?:file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"$line\",arch=\"$any\"|from=\"$file\")\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re" |
dcf95b47 | 1290 | gdb_expect { |
30056ea0 | 1291 | -re "\\*stopped,${ebn}${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$func\",args=$args,(?:file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"($line)\",arch=\"$any\"|from=\"$file\")\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re" { |
dcf95b47 | 1292 | pass "$test" |
05acf274 JK |
1293 | if {[array names expect_out "2,string"] != ""} { |
1294 | return $expect_out(2,string) | |
1295 | } | |
1296 | # No debug info available but $file does match. | |
1297 | return 0 | |
dcf95b47 | 1298 | } |
30056ea0 | 1299 | -re "\\*stopped,${ebn}${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$any\",args=\[\\\[\{\]$any\[\\\]\}\],file=\"$any\",fullname=\"${fullname_syntax}$any\",line=\"\[0-9\]*\",arch=\"$any\"\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re" { |
4392c534 | 1300 | verbose -log "got $expect_out(buffer)" |
dcf95b47 DJ |
1301 | fail "$test (stopped at wrong place)" |
1302 | return -1 | |
1303 | } | |
f7f9a841 | 1304 | -re ".*\r\n$mi_gdb_prompt$" { |
4392c534 | 1305 | verbose -log "got $expect_out(buffer)" |
dcf95b47 DJ |
1306 | fail "$test (unknown output after running)" |
1307 | return -1 | |
1308 | } | |
dcf95b47 DJ |
1309 | timeout { |
1310 | fail "$test (timeout)" | |
1311 | return -1 | |
1312 | } | |
4392c534 | 1313 | } |
dcf95b47 DJ |
1314 | } |
1315 | ||
1ad15515 PA |
1316 | # Wait for MI *stopped notification related to an interrupt request to |
1317 | # appear. | |
1318 | proc mi_expect_interrupt { test } { | |
1319 | global mi_gdb_prompt | |
1320 | global decimal | |
1321 | global async | |
1322 | ||
1323 | if {$async} { | |
1324 | set prompt_re "" | |
1325 | } else { | |
3eb7562a | 1326 | set prompt_re "$mi_gdb_prompt" |
1ad15515 PA |
1327 | } |
1328 | ||
a8d9763a SM |
1329 | set r_nonstop "reason=\"signal-received\",signal-name=\"0\",signal-meaning=\"Signal 0\"" |
1330 | set r_allstop "reason=\"signal-received\",signal-name=\"SIGINT\",signal-meaning=\"Interrupt\"" | |
1331 | set r "(${r_nonstop}|${r_allstop})" | |
1ad15515 PA |
1332 | set any "\[^\n\]*" |
1333 | ||
1334 | # A signal can land anywhere, just ignore the location | |
1d33d6ba | 1335 | verbose -log "mi_expect_interrupt: expecting: \\*stopped,${r}$any\r\n$prompt_re" |
1ad15515 | 1336 | gdb_expect { |
1d33d6ba | 1337 | -re "\\*stopped,${r}$any\r\n$prompt_re" { |
1ad15515 | 1338 | pass "$test" |
ae59b1da | 1339 | return 0 |
1ad15515 | 1340 | } |
3eb7562a | 1341 | -re ".*\r\n$mi_gdb_prompt" { |
1ad15515 PA |
1342 | verbose -log "got $expect_out(buffer)" |
1343 | fail "$test (unknown output after running)" | |
1344 | return -1 | |
1345 | } | |
1346 | timeout { | |
1347 | fail "$test (timeout)" | |
1348 | return -1 | |
1349 | } | |
1350 | } | |
1351 | } | |
1352 | ||
bb378428 VP |
1353 | # cmd should not include the number or newline (i.e. "exec-step 3", not |
1354 | # "220-exec-step 3\n" | |
1355 | ||
1356 | # Can not match -re ".*\r\n${mi_gdb_prompt}", because of false positives | |
1357 | # after the first prompt is printed. | |
1358 | ||
08b468e0 | 1359 | proc mi_execute_to { cmd reason func args file line extra test } { |
bb378428 VP |
1360 | mi_send_resuming_command "$cmd" "$test" |
1361 | set r [mi_expect_stop $reason $func $args $file $line $extra $test] | |
1362 | return $r | |
dcf95b47 DJ |
1363 | } |
1364 | ||
1365 | proc mi_next_to { func args file line test } { | |
08b468e0 | 1366 | mi_execute_to "exec-next" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
1367 | "$file" "$line" "" "$test" |
1368 | } | |
1369 | ||
1370 | proc mi_step_to { func args file line test } { | |
08b468e0 | 1371 | mi_execute_to "exec-step" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
1372 | "$file" "$line" "" "$test" |
1373 | } | |
1374 | ||
1375 | proc mi_finish_to { func args file line result ret test } { | |
08b468e0 | 1376 | mi_execute_to "exec-finish" "function-finished" "$func" "$args" \ |
dcf95b47 DJ |
1377 | "$file" "$line" \ |
1378 | ",gdb-result-var=\"$result\",return-value=\"$ret\"" \ | |
1379 | "$test" | |
1380 | } | |
1381 | ||
f7e97bb3 VP |
1382 | proc mi_continue_to {func} { |
1383 | mi_runto_helper $func "continue" | |
dcf95b47 DJ |
1384 | } |
1385 | ||
08b468e0 KS |
1386 | proc mi0_execute_to { cmd reason func args file line extra test } { |
1387 | mi_execute_to_helper "$cmd" "$reason" "$func" "\{$args\}" \ | |
dcf95b47 DJ |
1388 | "$file" "$line" "$extra" "$test" |
1389 | } | |
1390 | ||
1391 | proc mi0_next_to { func args file line test } { | |
08b468e0 | 1392 | mi0_execute_to "exec-next" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
1393 | "$file" "$line" "" "$test" |
1394 | } | |
1395 | ||
1396 | proc mi0_step_to { func args file line test } { | |
08b468e0 | 1397 | mi0_execute_to "exec-step" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
1398 | "$file" "$line" "" "$test" |
1399 | } | |
1400 | ||
1401 | proc mi0_finish_to { func args file line result ret test } { | |
08b468e0 | 1402 | mi0_execute_to "exec-finish" "function-finished" "$func" "$args" \ |
dcf95b47 DJ |
1403 | "$file" "$line" \ |
1404 | ",gdb-result-var=\"$result\",return-value=\"$ret\"" \ | |
1405 | "$test" | |
1406 | } | |
1407 | ||
1408 | proc mi0_continue_to { bkptno func args file line test } { | |
08b468e0 | 1409 | mi0_execute_to "exec-continue" "breakpoint-hit\",bkptno=\"$bkptno" \ |
dcf95b47 DJ |
1410 | "$func" "$args" "$file" "$line" "" "$test" |
1411 | } | |
b26ed50d | 1412 | |
4b48d439 KS |
1413 | # Creates a breakpoint and checks the reported fields are as expected. |
1414 | # This procedure takes the same options as mi_make_breakpoint and | |
1415 | # returns the breakpoint regexp from that procedure. | |
d24317b4 | 1416 | |
4b48d439 KS |
1417 | proc mi_create_breakpoint {location test args} { |
1418 | set bp [eval mi_make_breakpoint $args] | |
1419 | mi_gdb_test "222-break-insert $location" "222\\^done,$bp" $test | |
1420 | return $bp | |
d24317b4 VP |
1421 | } |
1422 | ||
6791b117 PA |
1423 | # Like mi_create_breakpoint, but creates a breakpoint with multiple |
1424 | # locations using mi_make_breakpoint_multi instead. | |
1425 | ||
1426 | proc mi_create_breakpoint_multi {location test args} { | |
1427 | set bp [eval mi_make_breakpoint_multi $args] | |
1428 | mi_gdb_test "222-break-insert $location" "222\\^done,$bp" $test | |
1429 | return $bp | |
1430 | } | |
1431 | ||
b26ed50d VP |
1432 | # Creates varobj named NAME for EXPRESSION. |
1433 | # Name cannot be "-". | |
1434 | proc mi_create_varobj { name expression testname } { | |
1435 | mi_gdb_test "-var-create $name * $expression" \ | |
4392c534 YQ |
1436 | "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=.*,has_more=\"0\"" \ |
1437 | $testname | |
b26ed50d VP |
1438 | } |
1439 | ||
fcacd99f VP |
1440 | proc mi_create_floating_varobj { name expression testname } { |
1441 | mi_gdb_test "-var-create $name @ $expression" \ | |
4392c534 YQ |
1442 | "\\^done,name=\"$name\",numchild=\"\(-1\|\[0-9\]+\)\",value=\".*\",type=.*" \ |
1443 | $testname | |
fcacd99f VP |
1444 | } |
1445 | ||
1446 | ||
9e8e3afe VP |
1447 | # Same as mi_create_varobj, but also checks the reported type |
1448 | # of the varobj. | |
1449 | proc mi_create_varobj_checked { name expression type testname } { | |
1450 | mi_gdb_test "-var-create $name * $expression" \ | |
4392c534 YQ |
1451 | "\\^done,name=\"$name\",numchild=\"\[0-9\]+\",value=\".*\",type=\"$type\".*" \ |
1452 | $testname | |
9e8e3afe VP |
1453 | } |
1454 | ||
0cc7d26f TT |
1455 | # Same as mi_create_floating_varobj, but assumes the test is creating |
1456 | # a dynamic varobj that has children, so the value must be "{...}". | |
0a1e6121 YQ |
1457 | # The "has_more" attribute is checked. |
1458 | proc mi_create_dynamic_varobj {name expression has_more testname} { | |
0cc7d26f | 1459 | mi_gdb_test "-var-create $name @ $expression" \ |
0a1e6121 | 1460 | "\\^done,name=\"$name\",numchild=\"0\",value=\"{\\.\\.\\.}\",type=.*,has_more=\"${has_more}\"" \ |
4392c534 | 1461 | $testname |
0cc7d26f TT |
1462 | } |
1463 | ||
4392c534 | 1464 | # Deletes the specified NAME. |
6e2a9270 VP |
1465 | proc mi_delete_varobj { name testname } { |
1466 | mi_gdb_test "-var-delete $name" \ | |
4392c534 YQ |
1467 | "\\^done,ndeleted=.*" \ |
1468 | $testname | |
6e2a9270 VP |
1469 | } |
1470 | ||
b26ed50d VP |
1471 | # Updates varobj named NAME and checks that all varobjs in EXPECTED |
1472 | # are reported as updated, and no other varobj is updated. | |
1473 | # Assumes that no varobj is out of scope and that no varobj changes | |
1474 | # types. | |
1475 | proc mi_varobj_update { name expected testname } { | |
1476 | set er "\\^done,changelist=\\\[" | |
1477 | set first 1 | |
1478 | foreach item $expected { | |
4392c534 YQ |
1479 | set v "{name=\"$item\",in_scope=\"true\",type_changed=\"false\",has_more=\".\"}" |
1480 | if {$first == 1} { | |
1481 | set er "$er$v" | |
1482 | set first 0 | |
1483 | } else { | |
1484 | set er "$er,$v" | |
1485 | } | |
b26ed50d VP |
1486 | } |
1487 | set er "$er\\\]" | |
1488 | ||
1489 | verbose -log "Expecting: $er" 2 | |
1490 | mi_gdb_test "-var-update $name" $er $testname | |
1491 | } | |
1492 | ||
8264ba82 AG |
1493 | proc mi_varobj_update_with_child_type_change { name child_name new_type new_children testname } { |
1494 | set v "{name=\"$child_name\",in_scope=\"true\",type_changed=\"true\",new_type=\"$new_type\",new_num_children=\"$new_children\",has_more=\".\"}" | |
fcacd99f VP |
1495 | set er "\\^done,changelist=\\\[$v\\\]" |
1496 | verbose -log "Expecting: $er" | |
1497 | mi_gdb_test "-var-update $name" $er $testname | |
1498 | } | |
1499 | ||
8264ba82 AG |
1500 | proc mi_varobj_update_with_type_change { name new_type new_children testname } { |
1501 | mi_varobj_update_with_child_type_change $name $name $new_type $new_children $testname | |
1502 | } | |
1503 | ||
0cc7d26f TT |
1504 | # A helper that turns a key/value list into a regular expression |
1505 | # matching some MI output. | |
1506 | proc mi_varobj_update_kv_helper {list} { | |
1507 | set first 1 | |
1508 | set rx "" | |
1509 | foreach {key value} $list { | |
1510 | if {!$first} { | |
1511 | append rx , | |
1512 | } | |
1513 | set first 0 | |
1514 | if {$key == "new_children"} { | |
1515 | append rx "$key=\\\[$value\\\]" | |
1516 | } else { | |
1517 | append rx "$key=\"$value\"" | |
1518 | } | |
1519 | } | |
1520 | return $rx | |
1521 | } | |
b6313243 | 1522 | |
0cc7d26f TT |
1523 | # A helper for mi_varobj_update_dynamic that computes a match |
1524 | # expression given a child list. | |
1525 | proc mi_varobj_update_dynamic_helper {children} { | |
1526 | set crx "" | |
b6313243 | 1527 | |
0cc7d26f TT |
1528 | set first 1 |
1529 | foreach child $children { | |
1530 | if {!$first} { | |
1531 | append crx , | |
1532 | } | |
1533 | set first 0 | |
1534 | append crx "{" | |
1535 | append crx [mi_varobj_update_kv_helper $child] | |
1536 | append crx "}" | |
1537 | } | |
1538 | ||
1539 | return $crx | |
1540 | } | |
1541 | ||
1542 | # Update a dynamic varobj named NAME. CHILDREN is a list of children | |
1543 | # that have been updated; NEW_CHILDREN is a list of children that were | |
1544 | # added to the primary varobj. Each child is a list of key/value | |
1545 | # pairs that are expected. SELF is a key/value list holding | |
1546 | # information about the varobj itself. TESTNAME is the name of the | |
1547 | # test. | |
1548 | proc mi_varobj_update_dynamic {name testname self children new_children} { | |
1549 | if {[llength $new_children]} { | |
1550 | set newrx [mi_varobj_update_dynamic_helper $new_children] | |
1551 | lappend self new_children $newrx | |
1552 | } | |
1553 | set selfrx [mi_varobj_update_kv_helper $self] | |
1554 | set crx [mi_varobj_update_dynamic_helper $children] | |
1555 | ||
1556 | set er "\\^done,changelist=\\\[\{name=\"$name\",in_scope=\"true\"" | |
1557 | append er ",$selfrx\}" | |
1558 | if {"$crx" != ""} { | |
1559 | append er ",$crx" | |
1560 | } | |
1561 | append er "\\\]" | |
b6313243 TT |
1562 | |
1563 | verbose -log "Expecting: $er" | |
1564 | mi_gdb_test "-var-update $name" $er $testname | |
1565 | } | |
1566 | ||
b26ed50d VP |
1567 | proc mi_check_varobj_value { name value testname } { |
1568 | ||
1569 | mi_gdb_test "-var-evaluate-expression $name" \ | |
1570 | "\\^done,value=\"$value\"" \ | |
1571 | $testname | |
1572 | } | |
038224f6 | 1573 | |
b6313243 TT |
1574 | # Helper proc which constructs a child regexp for |
1575 | # mi_list_varobj_children and mi_varobj_update_dynamic. | |
1576 | proc mi_child_regexp {children add_child} { | |
1577 | set children_exp {} | |
b6313243 TT |
1578 | |
1579 | if {$add_child} { | |
1580 | set pre "child=" | |
1581 | } else { | |
1582 | set pre "" | |
1583 | } | |
1584 | ||
1585 | foreach item $children { | |
1586 | ||
4392c534 YQ |
1587 | set name [lindex $item 0] |
1588 | set exp [lindex $item 1] | |
1589 | set numchild [lindex $item 2] | |
1590 | if {[llength $item] == 5} { | |
1591 | set type [lindex $item 3] | |
1592 | set value [lindex $item 4] | |
1593 | ||
1594 | lappend children_exp\ | |
31b4ab9e | 1595 | "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",value=\"$value\",type=\"$type\"(,thread-id=\"\[0-9\]+\")?}" |
4392c534 YQ |
1596 | } elseif {[llength $item] == 4} { |
1597 | set type [lindex $item 3] | |
1598 | ||
1599 | lappend children_exp\ | |
31b4ab9e | 1600 | "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\",type=\"$type\"(,thread-id=\"\[0-9\]+\")?}" |
4392c534 YQ |
1601 | } else { |
1602 | lappend children_exp\ | |
1603 | "$pre{name=\"$name\",exp=\"$exp\",numchild=\"$numchild\"(,thread-id=\"\[0-9\]+\")?}" | |
1604 | } | |
b6313243 TT |
1605 | } |
1606 | return [join $children_exp ","] | |
1607 | } | |
1608 | ||
038224f6 VP |
1609 | # Check the results of the: |
1610 | # | |
1611 | # -var-list-children VARNAME | |
1612 | # | |
1613 | # command. The CHILDREN parement should be a list of lists. | |
1614 | # Each inner list can have either 3 or 4 elements, describing | |
1615 | # fields that gdb is expected to report for child variable object, | |
1616 | # in the following order | |
1617 | # | |
1618 | # - Name | |
1619 | # - Expression | |
1620 | # - Number of children | |
1621 | # - Type | |
1622 | # | |
1623 | # If inner list has 3 elements, the gdb is expected to output no | |
9e8e3afe VP |
1624 | # type for a child and no value. |
1625 | # | |
1626 | # If the inner list has 4 elements, gdb output is expected to | |
1627 | # have no value. | |
038224f6 VP |
1628 | # |
1629 | proc mi_list_varobj_children { varname children testname } { | |
0cc7d26f | 1630 | mi_list_varobj_children_range $varname "" "" [llength $children] $children \ |
b6313243 TT |
1631 | $testname |
1632 | } | |
038224f6 | 1633 | |
0cc7d26f TT |
1634 | # Like mi_list_varobj_children, but sets a subrange. NUMCHILDREN is |
1635 | # the total number of children. | |
1636 | proc mi_list_varobj_children_range {varname from to numchildren children testname} { | |
9e8e3afe VP |
1637 | set options "" |
1638 | if {[llength $varname] == 2} { | |
4392c534 YQ |
1639 | set options [lindex $varname 1] |
1640 | set varname [lindex $varname 0] | |
9e8e3afe VP |
1641 | } |
1642 | ||
b6313243 | 1643 | set children_exp_j [mi_child_regexp $children 1] |
9e8e3afe | 1644 | if {$numchildren} { |
4392c534 | 1645 | set expected "\\^done,numchild=\".*\",children=\\\[$children_exp_j.*\\\]" |
9e8e3afe | 1646 | } { |
4392c534 | 1647 | set expected "\\^done,numchild=\"0\"" |
9e8e3afe | 1648 | } |
038224f6 | 1649 | |
0cc7d26f | 1650 | if {"$to" == ""} { |
4392c534 | 1651 | append expected ",has_more=\"0\"" |
0cc7d26f | 1652 | } elseif {$to >= 0 && $numchildren > $to} { |
4392c534 | 1653 | append expected ",has_more=\"1\"" |
0cc7d26f | 1654 | } else { |
4392c534 | 1655 | append expected ",has_more=\"0\"" |
0cc7d26f TT |
1656 | } |
1657 | ||
038224f6 VP |
1658 | verbose -log "Expecting: $expected" |
1659 | ||
0cc7d26f TT |
1660 | mi_gdb_test "-var-list-children $options $varname $from $to" \ |
1661 | $expected $testname | |
9e8e3afe VP |
1662 | } |
1663 | ||
1664 | # Verifies that variable object VARNAME has NUMBER children, | |
1665 | # where each one is named $VARNAME.<index-of-child> and has type TYPE. | |
1666 | proc mi_list_array_varobj_children { varname number type testname } { | |
f84bc218 KB |
1667 | mi_list_array_varobj_children_with_index $varname $number 0 $type $testname |
1668 | } | |
1669 | ||
1670 | # Same as mi_list_array_varobj_children, but allowing to pass a start index | |
1671 | # for an array. | |
1672 | proc mi_list_array_varobj_children_with_index { varname number start_index \ | |
1673 | type testname } { | |
9e8e3afe | 1674 | set t {} |
f84bc218 | 1675 | set index $start_index |
9e8e3afe | 1676 | for {set i 0} {$i < $number} {incr i} { |
f84bc218 KB |
1677 | lappend t [list $varname.$index $index 0 $type] |
1678 | incr index | |
9e8e3afe VP |
1679 | } |
1680 | mi_list_varobj_children $varname $t $testname | |
038224f6 | 1681 | } |
2d0720d9 VP |
1682 | |
1683 | # A list of two-element lists. First element of each list is | |
1684 | # a Tcl statement, and the second element is the line | |
1685 | # number of source C file where the statement originates. | |
1686 | set mi_autotest_data "" | |
1687 | # The name of the source file for autotesting. | |
1688 | set mi_autotest_source "" | |
1689 | ||
1690 | proc count_newlines { string } { | |
1691 | return [regexp -all "\n" $string] | |
1692 | } | |
1693 | ||
1694 | # Prepares for running inline tests in FILENAME. | |
1695 | # See comments for mi_run_inline_test for detailed | |
1696 | # explanation of the idea and syntax. | |
1697 | proc mi_prepare_inline_tests { filename } { | |
1698 | ||
1699 | global srcdir | |
1700 | global subdir | |
1701 | global mi_autotest_source | |
1702 | global mi_autotest_data | |
1703 | ||
1704 | set mi_autotest_data {} | |
1705 | ||
1706 | set mi_autotest_source $filename | |
4392c534 | 1707 | |
2d0720d9 VP |
1708 | if { ! [regexp "^/" "$filename"] } then { |
1709 | set filename "$srcdir/$subdir/$filename" | |
1710 | } | |
1711 | ||
1712 | set chan [open $filename] | |
1713 | set content [read $chan] | |
1714 | set line_number 1 | |
1715 | while {1} { | |
4392c534 YQ |
1716 | set start [string first "/*:" $content] |
1717 | if {$start != -1} { | |
1718 | set end [string first ":*/" $content] | |
1719 | if {$end == -1} { | |
1720 | error "Unterminated special comment in $filename" | |
1721 | } | |
1722 | ||
1723 | set prefix [string range $content 0 $start] | |
1724 | set prefix_newlines [count_newlines $prefix] | |
1725 | ||
1726 | set line_number [expr $line_number+$prefix_newlines] | |
1727 | set comment_line $line_number | |
1728 | ||
1729 | set comment [string range $content [expr $start+3] [expr $end-1]] | |
1730 | ||
1731 | set comment_newlines [count_newlines $comment] | |
1732 | set line_number [expr $line_number+$comment_newlines] | |
1733 | ||
1734 | set comment [string trim $comment] | |
1735 | set content [string range $content [expr $end+3] \ | |
1736 | [string length $content]] | |
1737 | lappend mi_autotest_data [list $comment $comment_line] | |
1738 | } else { | |
1739 | break | |
1740 | } | |
2d0720d9 VP |
1741 | } |
1742 | close $chan | |
1743 | } | |
1744 | ||
1745 | # Helper to mi_run_inline_test below. | |
1746 | # Return the list of all (statement,line_number) lists | |
1747 | # that comprise TESTCASE. The begin and end markers | |
1748 | # are not included. | |
1749 | proc mi_get_inline_test {testcase} { | |
1750 | ||
1751 | global mi_gdb_prompt | |
1752 | global mi_autotest_data | |
1753 | global mi_autotest_source | |
1754 | ||
1755 | set result {} | |
1756 | ||
1757 | set seen_begin 0 | |
1758 | set seen_end 0 | |
1759 | foreach l $mi_autotest_data { | |
1760 | ||
4392c534 | 1761 | set comment [lindex $l 0] |
2d0720d9 | 1762 | |
4392c534 YQ |
1763 | if {$comment == "BEGIN: $testcase"} { |
1764 | set seen_begin 1 | |
1765 | } elseif {$comment == "END: $testcase"} { | |
1766 | set seen_end 1 | |
1767 | break | |
1768 | } elseif {$seen_begin==1} { | |
1769 | lappend result $l | |
1770 | } | |
2d0720d9 VP |
1771 | } |
1772 | ||
1773 | if {$seen_begin == 0} { | |
4392c534 | 1774 | error "Autotest $testcase not found" |
2d0720d9 VP |
1775 | } |
1776 | ||
1777 | if {$seen_begin == 1 && $seen_end == 0} { | |
4392c534 | 1778 | error "Missing end marker for test $testcase" |
2d0720d9 VP |
1779 | } |
1780 | ||
1781 | return $result | |
1782 | } | |
1783 | ||
1784 | # Sets temporary breakpoint at LOCATION. | |
1785 | proc mi_tbreak {location} { | |
1786 | ||
1787 | global mi_gdb_prompt | |
1788 | ||
1789 | mi_gdb_test "-break-insert -t $location" \ | |
4392c534 YQ |
1790 | {\^done,bkpt=.*} \ |
1791 | "run to $location (set breakpoint)" | |
2d0720d9 VP |
1792 | } |
1793 | ||
1794 | # Send COMMAND that must be a command that resumes | |
7bf9deb0 | 1795 | # the inferior (run/continue/next/etc) and consumes |
2d0720d9 | 1796 | # the "^running" output from it. |
a2840c35 | 1797 | proc mi_send_resuming_command_raw {command test} { |
2d0720d9 VP |
1798 | |
1799 | global mi_gdb_prompt | |
66bb093b | 1800 | global thread_selected_re |
c86cf029 | 1801 | global library_loaded_re |
2d0720d9 | 1802 | |
a2840c35 | 1803 | send_gdb "$command\n" |
2d0720d9 | 1804 | gdb_expect { |
4392c534 YQ |
1805 | -re "\\^running\r\n\\*running,thread-id=\"\[^\"\]+\"\r\n($library_loaded_re)*($thread_selected_re)?${mi_gdb_prompt}" { |
1806 | # Note that lack of 'pass' call here -- this works around limitation | |
1807 | # in DejaGNU xfail mechanism. mi-until.exp has this: | |
1808 | # | |
1809 | # setup_kfail gdb/2104 "*-*-*" | |
1810 | # mi_execute_to ... | |
1811 | # | |
1812 | # and mi_execute_to uses mi_send_resuming_command. If we use 'pass' here, | |
1813 | # it will reset kfail, so when the actual test fails, it will be flagged | |
1814 | # as real failure. | |
d0b76dc6 | 1815 | return 0 |
4392c534 YQ |
1816 | } |
1817 | -re "\\^error,msg=\"Displaced stepping is only supported in ARM mode\".*" { | |
1818 | unsupported "$test (Thumb mode)" | |
1819 | return -1 | |
1820 | } | |
1821 | -re "\\^error,msg=.*" { | |
1822 | fail "$test (MI error)" | |
4ea95be9 | 1823 | return -1 |
4392c534 YQ |
1824 | } |
1825 | -re ".*${mi_gdb_prompt}" { | |
1826 | fail "$test (failed to resume)" | |
1827 | return -1 | |
1828 | } | |
1829 | timeout { | |
bb378428 VP |
1830 | fail "$test" |
1831 | return -1 | |
4392c534 | 1832 | } |
2d0720d9 VP |
1833 | } |
1834 | } | |
1835 | ||
a2840c35 VP |
1836 | proc mi_send_resuming_command {command test} { |
1837 | mi_send_resuming_command_raw -$command $test | |
1838 | } | |
1839 | ||
2d0720d9 VP |
1840 | # Helper to mi_run_inline_test below. |
1841 | # Sets a temporary breakpoint at LOCATION and runs | |
1842 | # the program using COMMAND. When the program is stopped | |
1843 | # returns the line at which it. Returns -1 if line cannot | |
1844 | # be determined. | |
1845 | # Does not check that the line is the same as requested. | |
1846 | # The caller can check itself if required. | |
a73bafbc | 1847 | proc mi_continue_to_line {location test} { |
2d0720d9 | 1848 | |
4392c534 | 1849 | mi_tbreak $location |
2d0720d9 | 1850 | mi_send_resuming_command "exec-continue" "run to $location (exec-continue)" |
bb378428 | 1851 | return [mi_get_stop_line $test] |
2d0720d9 VP |
1852 | } |
1853 | ||
1854 | # Wait until gdb prints the current line. | |
bb378428 | 1855 | proc mi_get_stop_line {test} { |
2d0720d9 VP |
1856 | |
1857 | global mi_gdb_prompt | |
f7f9a841 VP |
1858 | global async |
1859 | ||
1860 | if {$async} { | |
1861 | set prompt_re "" | |
1862 | } else { | |
d0b76dc6 | 1863 | set prompt_re "$mi_gdb_prompt$" |
f7f9a841 | 1864 | } |
2d0720d9 VP |
1865 | |
1866 | gdb_expect { | |
d0b76dc6 | 1867 | -re ".*line=\"(\[0-9\]*)\".*\r\n$prompt_re" { |
4392c534 | 1868 | return $expect_out(1,string) |
2d0720d9 | 1869 | } |
d0b76dc6 | 1870 | -re ".*$mi_gdb_prompt" { |
4392c534 | 1871 | fail "wait for stop ($test)" |
2d0720d9 VP |
1872 | } |
1873 | timeout { | |
4392c534 | 1874 | fail "wait for stop ($test)" |
2d0720d9 VP |
1875 | } |
1876 | } | |
1877 | } | |
1878 | ||
1879 | # Run a MI test embedded in comments in a C file. | |
1880 | # The C file should contain special comments in the following | |
1881 | # three forms: | |
1882 | # | |
1883 | # /*: BEGIN: testname :*/ | |
1884 | # /*: <Tcl statements> :*/ | |
1885 | # /*: END: testname :*/ | |
1886 | # | |
1887 | # This procedure find the begin and end marker for the requested | |
1888 | # test. Then, a temporary breakpoint is set at the begin | |
1889 | # marker and the program is run (from start). | |
1890 | # | |
1891 | # After that, for each special comment between the begin and end | |
1892 | # marker, the Tcl statements are executed. It is assumed that | |
1893 | # for each comment, the immediately preceding line is executable | |
1894 | # C statement. Then, gdb will be single-stepped until that | |
1895 | # preceding C statement is executed, and after that the | |
1896 | # Tcl statements in the comment will be executed. | |
1897 | # | |
1898 | # For example: | |
1899 | # | |
1900 | # /*: BEGIN: assignment-test :*/ | |
1901 | # v = 10; | |
1902 | # /*: <Tcl code to check that 'v' is indeed 10 :*/ | |
1903 | # /*: END: assignment-test :*/ | |
1904 | # | |
1905 | # The mi_prepare_inline_tests function should be called before | |
1906 | # calling this function. A given C file can contain several | |
1907 | # inline tests. The names of the tests must be unique within one | |
1908 | # C file. | |
1909 | # | |
1910 | proc mi_run_inline_test { testcase } { | |
1911 | ||
1912 | global mi_gdb_prompt | |
1913 | global hex | |
1914 | global decimal | |
1915 | global fullname_syntax | |
1916 | global mi_autotest_source | |
1917 | ||
1918 | set commands [mi_get_inline_test $testcase] | |
1919 | ||
1920 | set first 1 | |
1921 | set line_now 1 | |
1922 | ||
1923 | foreach c $commands { | |
4392c534 YQ |
1924 | set statements [lindex $c 0] |
1925 | set line [lindex $c 1] | |
1926 | set line [expr $line-1] | |
1927 | ||
1928 | # We want gdb to be stopped at the expression immediately | |
1929 | # before the comment. If this is the first comment, the | |
1930 | # program is either not started yet or is in some random place, | |
1931 | # so we run it. For further comments, we might be already | |
1932 | # standing at the right line. If not continue till the | |
1933 | # right line. | |
1934 | ||
1935 | if {$first==1} { | |
1936 | # Start the program afresh. | |
1937 | mi_tbreak "$mi_autotest_source:$line" | |
1938 | mi_run_cmd | |
1939 | set line_now [mi_get_stop_line "$testcase: step to $line"] | |
1940 | set first 0 | |
1941 | } elseif {$line_now!=$line} { | |
1942 | set line_now [mi_continue_to_line "$mi_autotest_source:$line" "continue to $line"] | |
1943 | } | |
1944 | ||
1945 | if {$line_now!=$line} { | |
1946 | fail "$testcase: go to line $line" | |
1947 | } | |
1948 | ||
1949 | # We're not at the statement right above the comment. | |
1950 | # Execute that statement so that the comment can test | |
1951 | # the state after the statement is executed. | |
1952 | ||
1953 | # Single-step past the line. | |
1954 | if { [mi_send_resuming_command "exec-next" "$testcase: step over $line"] != 0 } { | |
d0b76dc6 DJ |
1955 | return -1 |
1956 | } | |
1957 | set line_now [mi_get_stop_line "$testcase: step over $line"] | |
2d0720d9 | 1958 | |
4392c534 YQ |
1959 | # We probably want to use 'uplevel' so that statements |
1960 | # have direct access to global variables that the | |
1961 | # main 'exp' file has set up. But it's not yet clear, | |
1962 | # will need more experience to be sure. | |
1963 | eval $statements | |
2d0720d9 VP |
1964 | } |
1965 | } | |
9d81d21b VP |
1966 | |
1967 | proc get_mi_thread_list {name} { | |
1968 | global expect_out | |
1969 | ||
1970 | # MI will return a list of thread ids: | |
1971 | # | |
1972 | # -thread-list-ids | |
1973 | # ^done,thread-ids=[thread-id="1",thread-id="2",...],number-of-threads="N" | |
1974 | # (gdb) | |
1975 | mi_gdb_test "-thread-list-ids" \ | |
592375cd | 1976 | {.*\^done,thread-ids={(thread-id="[0-9]+"(,)?)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \ |
9d81d21b VP |
1977 | "-thread_list_ids ($name)" |
1978 | ||
1979 | set output {} | |
1980 | if {[info exists expect_out(buffer)]} { | |
1981 | set output $expect_out(buffer) | |
1982 | } | |
1983 | ||
1984 | set thread_list {} | |
1985 | if {![regexp {thread-ids=\{(thread-id="[0-9]+"(,)?)*\}} $output threads]} { | |
1986 | fail "finding threads in MI output ($name)" | |
1987 | } else { | |
1988 | pass "finding threads in MI output ($name)" | |
1989 | ||
1990 | # Make list of console threads | |
1991 | set start [expr {[string first \{ $threads] + 1}] | |
1992 | set end [expr {[string first \} $threads] - 1}] | |
1993 | set threads [string range $threads $start $end] | |
1994 | foreach thread [split $threads ,] { | |
1995 | if {[scan $thread {thread-id="%d"} num]} { | |
1996 | lappend thread_list $num | |
1997 | } | |
1998 | } | |
1999 | } | |
2000 | ||
2001 | return $thread_list | |
2002 | } | |
2003 | ||
2004 | # Check that MI and the console know of the same threads. | |
2005 | # Appends NAME to all test names. | |
2006 | proc check_mi_and_console_threads {name} { | |
2007 | global expect_out | |
2008 | ||
2009 | mi_gdb_test "-thread-list-ids" \ | |
592375cd | 2010 | {.*\^done,thread-ids={(thread-id="[0-9]+"(,)*)+},current-thread-id="[0-9]+",number-of-threads="[0-9]+"} \ |
9d81d21b VP |
2011 | "-thread-list-ids ($name)" |
2012 | set mi_output {} | |
2013 | if {[info exists expect_out(buffer)]} { | |
2014 | set mi_output $expect_out(buffer) | |
2015 | } | |
2016 | ||
2017 | # GDB will return a list of thread ids and some more info: | |
2018 | # | |
2019 | # (gdb) | |
2020 | # -interpreter-exec console "info threads" | |
2021 | # ~" 4 Thread 2051 (LWP 7734) 0x401166b1 in __libc_nanosleep () at __libc_nanosleep:-1" | |
2022 | # ~" 3 Thread 1026 (LWP 7733) () at __libc_nanosleep:-1" | |
2023 | # ~" 2 Thread 2049 (LWP 7732) 0x401411f8 in __poll (fds=0x804bb24, nfds=1, timeout=2000) at ../sysdeps/unix/sysv/linux/poll.c:63" | |
2024 | # ~"* 1 Thread 1024 (LWP 7731) main (argc=1, argv=0xbfffdd94) at ../../../src/gdb/testsuite/gdb.mi/pthreads.c:160" | |
2025 | # FIXME: kseitz/2002-09-05: Don't use the hack-cli method. | |
2026 | mi_gdb_test "info threads" \ | |
2027 | {.*(~".*"[\r\n]*)+.*} \ | |
2028 | "info threads ($name)" | |
2029 | set console_output {} | |
2030 | if {[info exists expect_out(buffer)]} { | |
2031 | set console_output $expect_out(buffer) | |
2032 | } | |
2033 | ||
2034 | # Make a list of all known threads to console (gdb's thread IDs) | |
2035 | set console_thread_list {} | |
2036 | foreach line [split $console_output \n] { | |
2037 | if {[string index $line 0] == "~"} { | |
2038 | # This is a line from the console; trim off "~", " ", "*", and "\"" | |
2039 | set line [string trim $line ~\ \"\*] | |
2040 | if {[scan $line "%d" id] == 1} { | |
2041 | lappend console_thread_list $id | |
2042 | } | |
2043 | } | |
2044 | } | |
2045 | ||
2046 | # Now find the result string from MI | |
2047 | set mi_result "" | |
2048 | foreach line [split $mi_output \n] { | |
2049 | if {[string range $line 0 4] == "^done"} { | |
2050 | set mi_result $line | |
2051 | } | |
2052 | } | |
2053 | if {$mi_result == ""} { | |
2054 | fail "finding MI result string ($name)" | |
2055 | } else { | |
2056 | pass "finding MI result string ($name)" | |
2057 | } | |
2058 | ||
2059 | # Finally, extract the thread ids and compare them to the console | |
2060 | set num_mi_threads_str "" | |
2061 | if {![regexp {number-of-threads="[0-9]+"} $mi_result num_mi_threads_str]} { | |
2062 | fail "finding number of threads in MI output ($name)" | |
2063 | } else { | |
2064 | pass "finding number of threads in MI output ($name)" | |
2065 | ||
2066 | # Extract the number of threads from the MI result | |
2067 | if {![scan $num_mi_threads_str {number-of-threads="%d"} num_mi_threads]} { | |
2068 | fail "got number of threads from MI ($name)" | |
2069 | } else { | |
2070 | pass "got number of threads from MI ($name)" | |
2071 | ||
2072 | # Check if MI and console have same number of threads | |
2073 | if {$num_mi_threads != [llength $console_thread_list]} { | |
2074 | fail "console and MI have same number of threads ($name)" | |
2075 | } else { | |
2076 | pass "console and MI have same number of threads ($name)" | |
2077 | ||
2078 | # Get MI thread list | |
2079 | set mi_thread_list [get_mi_thread_list $name] | |
2080 | ||
2081 | # Check if MI and console have the same threads | |
2082 | set fails 0 | |
2083 | foreach ct [lsort $console_thread_list] mt [lsort $mi_thread_list] { | |
2084 | if {$ct != $mt} { | |
2085 | incr fails | |
2086 | } | |
2087 | } | |
2088 | if {$fails > 0} { | |
2089 | fail "MI and console have same threads ($name)" | |
2090 | ||
2091 | # Send a list of failures to the log | |
2092 | send_log "Console has thread ids: $console_thread_list\n" | |
2093 | send_log "MI has thread ids: $mi_thread_list\n" | |
2094 | } else { | |
2095 | pass "MI and console have same threads ($name)" | |
2096 | } | |
2097 | } | |
2098 | } | |
2099 | } | |
2100 | } | |
5e06a3d1 | 2101 | |
759f0f0b | 2102 | # Download shared libraries to the target. |
5e06a3d1 | 2103 | proc mi_load_shlibs { args } { |
5e06a3d1 | 2104 | foreach file $args { |
7817ea46 | 2105 | gdb_remote_download target [shlib_target_file $file] |
5e06a3d1 VP |
2106 | } |
2107 | ||
6e774b13 SM |
2108 | if {[is_remote target]} { |
2109 | # If the target is remote, we need to tell gdb where to find the | |
2110 | # libraries. | |
2111 | # | |
2112 | # We could set this even when not testing remotely, but a user | |
2113 | # generally won't set it unless necessary. In order to make the tests | |
2114 | # more like the real-life scenarios, we don't set it for local testing. | |
2115 | mi_gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "\^done" "" | |
2116 | } | |
5e06a3d1 VP |
2117 | } |
2118 | ||
b05b1202 | 2119 | proc mi_check_thread_states { states test } { |
1ad15515 | 2120 | global expect_out |
f4e164aa | 2121 | set pattern ".*\\^done,threads=\\\[" |
1ad15515 PA |
2122 | foreach s $states { |
2123 | set pattern "${pattern}(.*)state=\"$s\"" | |
2124 | } | |
dc146f7c | 2125 | set pattern "${pattern}(,core=\"\[0-9\]*\")?\\\}\\\].*" |
1ad15515 PA |
2126 | |
2127 | verbose -log "expecting: $pattern" | |
2128 | mi_gdb_test "-thread-info" $pattern $test | |
2129 | } | |
b6313243 TT |
2130 | |
2131 | # Return a list of MI features supported by this gdb. | |
2132 | proc mi_get_features {} { | |
2133 | global expect_out mi_gdb_prompt | |
2134 | ||
2135 | send_gdb "-list-features\n" | |
2136 | ||
2137 | gdb_expect { | |
2138 | -re "\\^done,features=\\\[(.*)\\\]\r\n$mi_gdb_prompt$" { | |
2139 | regsub -all -- \" $expect_out(1,string) "" features | |
2140 | return [split $features ,] | |
2141 | } | |
2142 | -re ".*\r\n$mi_gdb_prompt$" { | |
2143 | verbose -log "got $expect_out(buffer)" | |
2144 | return "" | |
2145 | } | |
2146 | timeout { | |
2147 | verbose -log "timeout in mi_gdb_prompt" | |
2148 | return "" | |
2149 | } | |
2150 | } | |
2151 | } | |
1eec78bd KS |
2152 | |
2153 | # Variable Object Trees | |
2154 | # | |
2155 | # Yet another way to check varobjs. Pass mi_walk_varobj_tree a "list" of | |
2156 | # variables (not unlike the actual source code definition), and it will | |
2157 | # automagically test the children for you (by default). | |
2158 | # | |
2159 | # Example: | |
2160 | # | |
2161 | # source code: | |
2162 | # struct bar { | |
2163 | # union { | |
2164 | # int integer; | |
2165 | # void *ptr; | |
2166 | # }; | |
2167 | # const int *iPtr; | |
2168 | # }; | |
2169 | # | |
2170 | # class foo { | |
2171 | # public: | |
2172 | # int a; | |
2173 | # struct { | |
2174 | # int b; | |
2175 | # struct bar *c; | |
2176 | # }; | |
2177 | # }; | |
2178 | # | |
2179 | # foo *f = new foo (); <-- break here | |
2180 | # | |
2181 | # We want to check all the children of "f". | |
2182 | # | |
2183 | # Translate the above structures into the following tree: | |
2184 | # | |
2185 | # set tree { | |
2186 | # foo f { | |
2187 | # {} public { | |
2188 | # int a {} | |
2189 | # anonymous struct { | |
2190 | # {} public { | |
2191 | # int b {} | |
2192 | # {bar *} c { | |
2193 | # {} public { | |
2194 | # anonymous union { | |
2195 | # {} public { | |
2196 | # int integer {} | |
2197 | # {void *} ptr {} | |
2198 | # } | |
2199 | # } | |
2200 | # {const int *} iPtr { | |
2201 | # {const int} {*iPtr} {} | |
2202 | # } | |
2203 | # } | |
2204 | # } | |
2205 | # } | |
2206 | # } | |
2207 | # } | |
2208 | # } | |
2209 | # } | |
2210 | # | |
440e2fca | 2211 | # mi_walk_varobj_tree c++ $tree |
1eec78bd KS |
2212 | # |
2213 | # If you'd prefer to walk the tree using your own callback, | |
2214 | # simply pass the name of the callback to mi_walk_varobj_tree. | |
2215 | # | |
2216 | # This callback should take one argument, the name of the variable | |
2217 | # to process. This name is the name of a global array holding the | |
2218 | # variable's properties (object name, type, etc). | |
2219 | # | |
2220 | # An example callback: | |
2221 | # | |
2222 | # proc my_callback {var} { | |
2223 | # upvar #0 $var varobj | |
2224 | # | |
2225 | # puts "my_callback: called on varobj $varobj(obj_name)" | |
2226 | # } | |
2227 | # | |
2228 | # The arrays created for each variable object contain the following | |
2229 | # members: | |
2230 | # | |
2231 | # obj_name - the object name for accessing this variable via MI | |
2232 | # display_name - the display name for this variable (exp="display_name" in | |
2233 | # the output of -var-list-children) | |
2234 | # type - the type of this variable (type="type" in the output | |
2235 | # of -var-list-children, or the special tag "anonymous" | |
2236 | # path_expr - the "-var-info-path-expression" for this variable | |
440e2fca KS |
2237 | # NOTE: This member cannot be used reliably with typedefs. |
2238 | # Use with caution! | |
2239 | # See notes inside get_path_expr for more. | |
1eec78bd KS |
2240 | # parent - the variable name of the parent varobj |
2241 | # children - a list of children variable names (which are the | |
2242 | # names Tcl arrays, not object names) | |
2243 | # | |
2244 | # For each variable object, an array containing the above fields will | |
2245 | # be created under the root node (conveniently called, "root"). For example, | |
2246 | # a variable object with handle "OBJ.public.0_anonymous.a" will have | |
2247 | # a corresponding global Tcl variable named "root.OBJ.public.0_anonymous.a". | |
2248 | # | |
2249 | # Note that right now, this mechanism cannot be used for recursive data | |
2250 | # structures like linked lists. | |
2251 | ||
2252 | namespace eval ::varobj_tree { | |
2253 | # An index which is appended to root varobjs to ensure uniqueness. | |
2254 | variable _root_idx 0 | |
2255 | ||
2256 | # A procedure to help with debuggging varobj trees. | |
2257 | # VARIABLE_NAME is the name of the variable to dump. | |
2258 | # CMD, if present, is the name of the callback to output the contstructed | |
2259 | # strings. By default, it uses expect's "send_log" command. | |
2260 | # TERM, if present, is a terminating character. By default it is the newline. | |
2261 | # | |
2262 | # To output to the terminal (not the expect log), use | |
2263 | # mi_varobj_tree_dump_variable my_variable puts "" | |
2264 | ||
2265 | proc mi_varobj_tree_dump_variable {variable_name {cmd send_log} {term "\n"}} { | |
2266 | upvar #0 $variable_name varobj | |
2267 | ||
2268 | eval "$cmd \"VAR = $variable_name$term\"" | |
2269 | ||
2270 | # Explicitly encode the array indices, since outputting them | |
2271 | # in some logical order is better than what "array names" might | |
2272 | # return. | |
2273 | foreach idx {obj_name parent display_name type path_expr} { | |
2274 | eval "$cmd \"\t$idx = $varobj($idx)$term\"" | |
2275 | } | |
2276 | ||
2277 | # Output children | |
2278 | set num [llength $varobj(children)] | |
2279 | eval "$cmd \"\tnum_children = $num$term\"" | |
2280 | if {$num > 0} { | |
2281 | eval "$cmd \"\tchildren = $varobj(children)$term\"" | |
2282 | } | |
2283 | } | |
2284 | ||
2285 | # The default callback used by mi_walk_varobj_tree. This callback | |
440e2fca KS |
2286 | # simply checks all of VAR's children. It specifically does not test |
2287 | # path expressions, since that is very problematic. | |
1eec78bd KS |
2288 | # |
2289 | # This procedure may be used in custom callbacks. | |
2290 | proc test_children_callback {variable_name} { | |
2291 | upvar #0 $variable_name varobj | |
2292 | ||
2293 | if {[llength $varobj(children)] > 0} { | |
2294 | # Construct the list of children the way mi_list_varobj_children | |
2295 | # expects to get it: | |
2296 | # { {obj_name display_name num_children type} ... } | |
2297 | set children_list {} | |
2298 | foreach child $varobj(children) { | |
2299 | upvar #0 $child c | |
2300 | set clist [list [string_to_regexp $c(obj_name)] \ | |
2301 | [string_to_regexp $c(display_name)] \ | |
2302 | [llength $c(children)]] | |
2303 | if {[string length $c(type)] > 0} { | |
2304 | lappend clist [string_to_regexp $c(type)] | |
2305 | } | |
2306 | lappend children_list $clist | |
2307 | } | |
2308 | ||
2309 | mi_list_varobj_children $varobj(obj_name) $children_list \ | |
2310 | "VT: list children of $varobj(obj_name)" | |
2311 | } | |
2312 | } | |
2313 | ||
2314 | # Set the properties of the varobj represented by | |
2315 | # PARENT_VARIABLE - the name of the parent's variable | |
2316 | # OBJNAME - the MI object name of this variable | |
2317 | # DISP_NAME - the display name of this variable | |
2318 | # TYPE - the type of this variable | |
2319 | # PATH - the path expression for this variable | |
2320 | # CHILDREN - a list of the variable's children | |
2321 | proc create_varobj {parent_variable objname disp_name \ | |
2322 | type path children} { | |
2323 | upvar #0 $parent_variable parent | |
2324 | ||
2325 | set var_name "root.$objname" | |
2326 | global $var_name | |
2327 | array set $var_name [list obj_name $objname] | |
2328 | array set $var_name [list display_name $disp_name] | |
2329 | array set $var_name [list type $type] | |
2330 | array set $var_name [list path_expr $path] | |
2331 | array set $var_name [list parent "$parent_variable"] | |
2332 | array set $var_name [list children \ | |
2333 | [get_tree_children $var_name $children]] | |
2334 | return $var_name | |
2335 | } | |
2336 | ||
2337 | # Should VARIABLE be used in path expressions? The CPLUS_FAKE_CHILD | |
2338 | # varobjs and anonymous structs/unions are not used for path expressions. | |
2339 | proc is_path_expr_parent {variable} { | |
2340 | upvar #0 $variable varobj | |
2341 | ||
2342 | # If the varobj's type is "", it is a CPLUS_FAKE_CHILD. | |
2343 | # If the tail of the varobj's object name is "%d_anonymous", | |
2344 | # then it represents an anonymous struct or union. | |
2345 | if {[string length $varobj(type)] == 0 \ | |
2346 | || [regexp {[0-9]+_anonymous$} $varobj(obj_name)]} { | |
2347 | return false | |
2348 | } | |
2349 | ||
2350 | return true | |
2351 | } | |
2352 | ||
2353 | # Return the path expression for the variable named NAME in | |
2354 | # parent varobj whose variable name is given by PARENT_VARIABLE. | |
2355 | proc get_path_expr {parent_variable name type} { | |
2356 | upvar #0 $parent_variable parent | |
440e2fca | 2357 | upvar #0 $parent_variable path_parent |
1eec78bd KS |
2358 | |
2359 | # If TYPE is "", this is one of the CPLUS_FAKE_CHILD varobjs, | |
440e2fca KS |
2360 | # which has no path expression. Likewsise for anonymous structs |
2361 | # and unions. | |
2362 | if {[string length $type] == 0 \ | |
2363 | || [string compare $type "anonymous"] == 0} { | |
1eec78bd KS |
2364 | return "" |
2365 | } | |
2366 | ||
2367 | # Find the path parent variable. | |
2368 | while {![is_path_expr_parent $parent_variable]} { | |
440e2fca KS |
2369 | set parent_variable $path_parent(parent) |
2370 | upvar #0 $parent_variable path_parent | |
2371 | } | |
2372 | ||
2373 | # This is where things get difficult. We do not actually know | |
2374 | # the real type for variables defined via typedefs, so we don't actually | |
2375 | # know whether the parent is a structure/union or not. | |
2376 | # | |
2377 | # So we assume everything that isn't a simple type is a compound type. | |
2378 | set stars "" | |
2379 | regexp {\*+} $parent(type) stars | |
2380 | set is_compound 1 | |
2381 | if {[string index $name 0] == "*"} { | |
2382 | set is_compound 0 | |
2383 | } | |
2384 | ||
2385 | if {[string index $parent(type) end] == "\]"} { | |
2386 | # Parent is an array. | |
2387 | return "($path_parent(path_expr))\[$name\]" | |
2388 | } elseif {$is_compound} { | |
2389 | # Parent is a structure or union or a pointer to one. | |
2390 | if {[string length $stars]} { | |
2391 | set join "->" | |
2392 | } else { | |
2393 | set join "." | |
2394 | } | |
2395 | ||
2396 | global root | |
1eec78bd | 2397 | |
440e2fca KS |
2398 | # To make matters even more hideous, varobj.c has slightly different |
2399 | # path expressions for C and C++. | |
2400 | set path_expr "($path_parent(path_expr))$join$name" | |
2401 | if {[string compare -nocase $root(language) "c"] == 0} { | |
2402 | return $path_expr | |
2403 | } else { | |
2404 | return "($path_expr)" | |
2405 | } | |
2406 | } else { | |
2407 | # Parent is a pointer. | |
2408 | return "*($path_parent(path_expr))" | |
2409 | } | |
1eec78bd KS |
2410 | } |
2411 | ||
2412 | # Process the CHILDREN (a list of varobj_tree elements) of the variable | |
2413 | # given by PARENT_VARIABLE. Returns a list of children variables. | |
2414 | proc get_tree_children {parent_variable children} { | |
2415 | upvar #0 $parent_variable parent | |
2416 | ||
2417 | set field_idx 0 | |
2418 | set children_list {} | |
2419 | foreach {type name children} $children { | |
2420 | if {[string compare $parent_variable "root"] == 0} { | |
2421 | # Root variable | |
2422 | variable _root_idx | |
2423 | incr _root_idx | |
2424 | set objname "$name$_root_idx" | |
2425 | set disp_name "$name" | |
2426 | set path_expr "$name" | |
2427 | } elseif {[string compare $type "anonymous"] == 0} { | |
2428 | # Special case: anonymous types. In this case, NAME will either be | |
2429 | # "struct" or "union". | |
2430 | set objname "$parent(obj_name).${field_idx}_anonymous" | |
2431 | set disp_name "<anonymous $name>" | |
2432 | set path_expr "" | |
2433 | set type "$name {...}" | |
2434 | } else { | |
2435 | set objname "$parent(obj_name).$name" | |
2436 | set disp_name $name | |
2437 | set path_expr [get_path_expr $parent_variable $name $type] | |
2438 | } | |
2439 | ||
2440 | lappend children_list [create_varobj $parent_variable $objname \ | |
2441 | $disp_name $type $path_expr $children] | |
2442 | incr field_idx | |
2443 | } | |
2444 | ||
2445 | return $children_list | |
2446 | } | |
2447 | ||
2448 | # The main procedure to call the given CALLBACK on the elements of the | |
2449 | # given varobj TREE. See detailed explanation above. | |
440e2fca | 2450 | proc walk_tree {language tree callback} { |
1eec78bd | 2451 | global root |
f44eeb11 | 2452 | variable _root_idx |
1eec78bd KS |
2453 | |
2454 | if {[llength $tree] < 3} { | |
2455 | error "tree does not contain enough elements" | |
2456 | } | |
2457 | ||
f44eeb11 TT |
2458 | set _root_idx 0 |
2459 | ||
1eec78bd | 2460 | # Create root node and process the tree. |
440e2fca | 2461 | array set root [list language $language] |
1eec78bd KS |
2462 | array set root [list obj_name "root"] |
2463 | array set root [list display_name "root"] | |
2464 | array set root [list type "root"] | |
2465 | array set root [list path_expr "root"] | |
2466 | array set root [list parent "root"] | |
2467 | array set root [list children [get_tree_children root $tree]] | |
2468 | ||
2469 | # Walk the tree | |
2470 | set all_nodes $root(children); # a stack of nodes | |
2471 | while {[llength $all_nodes] > 0} { | |
2472 | # "Pop" the name of the global variable containing this varobj's | |
2473 | # information from the stack of nodes. | |
2474 | set var_name [lindex $all_nodes 0] | |
2475 | set all_nodes [lreplace $all_nodes 0 0] | |
2476 | ||
2477 | # Bring the global named in VAR_NAME into scope as the local variable | |
2478 | # VAROBJ. | |
2479 | upvar #0 $var_name varobj | |
2480 | ||
2481 | # Append any children of VAROBJ to the list of nodes to walk. | |
2482 | if {[llength $varobj(children)] > 0} { | |
2483 | set all_nodes [concat $all_nodes $varobj(children)] | |
2484 | } | |
2485 | ||
2486 | # If this is a root variable, create the variable object for it. | |
2487 | if {[string compare $varobj(parent) "root"] == 0} { | |
2488 | mi_create_varobj $varobj(obj_name) $varobj(display_name) \ | |
2489 | "VT: create root varobj for $varobj(display_name)" | |
2490 | } | |
2491 | ||
2492 | # Now call the callback for VAROBJ. | |
2493 | uplevel #0 $callback $var_name | |
2494 | } | |
2495 | } | |
2496 | } | |
2497 | ||
2498 | # The default varobj tree callback, which simply tests -var-list-children. | |
2499 | proc mi_varobj_tree_test_children_callback {variable} { | |
2500 | ::varobj_tree::test_children_callback $variable | |
2501 | } | |
2502 | ||
2503 | # Walk the variable object tree given by TREE, calling the specified | |
2504 | # CALLBACK. By default this uses mi_varobj_tree_test_children_callback. | |
440e2fca KS |
2505 | proc mi_walk_varobj_tree {language tree \ |
2506 | {callback \ | |
2507 | mi_varobj_tree_test_children_callback}} { | |
2508 | ::varobj_tree::walk_tree $language $tree $callback | |
1eec78bd | 2509 | } |
4b48d439 KS |
2510 | |
2511 | # Build a list of key-value pairs given by the list ATTR_LIST. Flatten | |
2512 | # this list using the optional JOINER, a comma by default. | |
2513 | # | |
2514 | # The list must contain an even number of elements, which are the key-value | |
2515 | # pairs. Each value will be surrounded by quotes, according to the grammar, | |
2516 | # except if the value starts with \[ or \{, when the quotes will be omitted. | |
2517 | # | |
2518 | # Example: mi_build_kv_pairs {a b c d e f g \[.*\]} | |
2519 | # returns a=\"b\",c=\"d\",e=\"f\",g=\[.*\] | |
2520 | proc mi_build_kv_pairs {attr_list {joiner ,}} { | |
2521 | set l {} | |
2522 | foreach {var value} $attr_list { | |
2523 | if {[string range $value 0 1] == "\\\[" | |
2524 | || [string range $value 0 1] == "\\\{"} { | |
2525 | lappend l "$var=$value" | |
2526 | } else { | |
2527 | lappend l "$var=\"$value\"" | |
2528 | } | |
2529 | } | |
2530 | return "[join $l $joiner]" | |
2531 | } | |
2532 | ||
6791b117 PA |
2533 | # Construct a breakpoint location regexp. This may be used along with |
2534 | # mi_make_breakpoint_multi to test the output of -break-insert, | |
2535 | # -dprintf-insert, or -break-info with breapoints with multiple | |
2536 | # locations. | |
4b48d439 | 2537 | # |
6791b117 PA |
2538 | # All arguments for the breakpoint location may be specified using the |
2539 | # options number, enabled, addr, func, file, fullname, line and | |
2540 | # thread-groups. | |
4b48d439 | 2541 | # |
6791b117 PA |
2542 | # Example: mi_make_breakpoint_loc -number 2.1 -file ".*/myfile.c" -line 3 |
2543 | # will return the breakpoint location: | |
2544 | # {number="2.1",enabled=".*",addr=".*",func=".*", | |
2545 | # file=".*/myfile.c",fullname=".*",line="3",thread-groups=\[.*\]} | |
4b48d439 | 2546 | |
6791b117 PA |
2547 | proc mi_make_breakpoint_loc {args} { |
2548 | parse_args {{number .*} {enabled .*} {addr .*} | |
4b48d439 | 2549 | {func .*} {file .*} {fullname .*} {line .*} |
6791b117 | 2550 | {thread-groups \\\[.*\\\]}} |
4b48d439 KS |
2551 | |
2552 | set attr_list {} | |
6791b117 | 2553 | foreach attr [list number enabled addr func file \ |
eb8c4e2e | 2554 | fullname line thread-groups] { |
4b48d439 KS |
2555 | lappend attr_list $attr [set $attr] |
2556 | } | |
2557 | ||
6791b117 PA |
2558 | return "{[mi_build_kv_pairs $attr_list]}" |
2559 | } | |
2560 | ||
2561 | # Bits shared between mi_make_breakpoint and mi_make_breakpoint_multi. | |
2562 | ||
2563 | proc mi_make_breakpoint_1 {attr_list cond evaluated-by times \ | |
2564 | ignore script original-location} { | |
2565 | set result "bkpt=\\\{[mi_build_kv_pairs $attr_list]" | |
4b48d439 KS |
2566 | |
2567 | # There are always exceptions. | |
eb8c4e2e KS |
2568 | |
2569 | # If COND is not preset, do not output it. | |
2570 | if {[string length $cond] > 0} { | |
2571 | append result "," | |
2572 | append result [mi_build_kv_pairs [list "cond" $cond]] | |
6613eb10 KS |
2573 | |
2574 | # When running on a remote, GDB may output who is evaluating | |
2575 | # breakpoint conditions. | |
2576 | if {[string length ${evaluated-by}] > 0} { | |
2577 | append result [mi_build_kv_pairs \ | |
2578 | [list "evaluated-by" ${evaluated-by}]] | |
2579 | } else { | |
2580 | append result {(,evaluated-by=".*")?} | |
2581 | } | |
eb8c4e2e KS |
2582 | } |
2583 | ||
2584 | append result "," | |
2585 | append result [mi_build_kv_pairs [list "times" $times]] | |
2586 | ||
4b48d439 KS |
2587 | # If SCRIPT and IGNORE are not present, do not output them. |
2588 | if {$ignore != 0} { | |
2589 | append result "," | |
2590 | append result [mi_build_kv_pairs [list "ignore" $ignore]] | |
2591 | append result "," | |
2592 | } | |
2593 | if {[string length $script] > 0} { | |
2594 | append result "," | |
2595 | append result [mi_build_kv_pairs [list "script" $script]] | |
2596 | append result "," | |
2597 | } else { | |
2598 | # Allow anything up until the next "official"/required attribute. | |
2599 | # This pattern skips over script/ignore if matches on those | |
2600 | # were not specifically required by the caller. | |
2601 | append result ".*" | |
2602 | } | |
2603 | append result [mi_build_kv_pairs \ | |
2604 | [list "original-location" ${original-location}]] | |
6791b117 PA |
2605 | |
2606 | return $result | |
2607 | } | |
2608 | ||
2609 | ||
2610 | # Construct a breakpoint regexp, for a breakpoint with multiple | |
2611 | # locations. This may be used to test the output of -break-insert, | |
2612 | # -dprintf-insert, or -break-info with breakpoints with multiple | |
2613 | # locations. | |
2614 | # | |
2615 | # All arguments for the breakpoint may be specified using the options | |
2616 | # number, type, disp, enabled, func, cond, evaluated-by, times, | |
2617 | # ignore, script and locations. | |
2618 | # | |
2619 | # Only if -script and -ignore are given will they appear in the output. | |
2620 | # Otherwise, this procedure will skip them using ".*". | |
2621 | # | |
2622 | # Example: mi_make_breakpoint_multi -number 2 -locations "$loc" | |
2623 | # will return the breakpoint: | |
2624 | # bkpt={number="2",type=".*",disp=".*",enabled=".*",addr="<MULTIPLE>", | |
2625 | # times="0".*original-location=".*",locations=$loc} | |
2626 | # | |
2627 | # You can construct the list of locations with mi_make_breakpoint_loc. | |
2628 | ||
2629 | proc mi_make_breakpoint_multi {args} { | |
2630 | parse_args {{number .*} {type .*} {disp .*} {enabled .*} | |
2631 | {times .*} {ignore 0} | |
2632 | {script ""} {original-location .*} {cond ""} {evaluated-by ""} | |
2633 | {locations .*}} | |
2634 | ||
2635 | set attr_list {} | |
2636 | foreach attr [list number type disp enabled] { | |
2637 | lappend attr_list $attr [set $attr] | |
2638 | } | |
2639 | ||
2640 | lappend attr_list "addr" "<MULTIPLE>" | |
2641 | ||
2642 | set result [mi_make_breakpoint_1 \ | |
2643 | $attr_list $cond ${evaluated-by} $times \ | |
2644 | $ignore $script ${original-location}] | |
2645 | ||
2646 | append result "," | |
2647 | append result [mi_build_kv_pairs [list "locations" $locations]] | |
2648 | ||
2649 | append result "\\\}" | |
2650 | return $result | |
2651 | } | |
2652 | ||
2653 | # Construct a breakpoint regexp. This may be used to test the output of | |
2654 | # -break-insert, -dprintf-insert, or -break-info. | |
2655 | # | |
2656 | # All arguments for the breakpoint may be specified using the options | |
2657 | # number, type, disp, enabled, addr, func, file, fullanme, line, | |
2658 | # thread-groups, cond, evaluated-by, times, ignore, script, | |
2659 | # and original-location. | |
2660 | # | |
2661 | # Only if -script and -ignore are given will they appear in the output. | |
2662 | # Otherwise, this procedure will skip them using ".*". | |
2663 | # | |
2664 | # Example: mi_make_breakpoint -number 2 -file ".*/myfile.c" -line 3 | |
2665 | # will return the breakpoint: | |
2666 | # bkpt={number="2",type=".*",disp=".*",enabled=".*",addr=".*",func=".*", | |
2667 | # file=".*/myfile.c",fullname=".*",line="3",thread-groups=\[.*\], | |
2668 | # times="0".*original-location=".*"} | |
2669 | ||
2670 | proc mi_make_breakpoint {args} { | |
2671 | parse_args {{number .*} {type .*} {disp .*} {enabled .*} {addr .*} | |
2672 | {func .*} {file .*} {fullname .*} {line .*} | |
2673 | {thread-groups \\\[.*\\\]} {times .*} {ignore 0} | |
2674 | {script ""} {original-location .*} {cond ""} {evaluated-by ""}} | |
2675 | ||
2676 | set attr_list {} | |
2677 | foreach attr [list number type disp enabled addr func file \ | |
2678 | fullname line thread-groups] { | |
2679 | lappend attr_list $attr [set $attr] | |
2680 | } | |
2681 | ||
2682 | set result [mi_make_breakpoint_1 \ | |
2683 | $attr_list $cond ${evaluated-by} $times \ | |
2684 | $ignore $script ${original-location}] | |
2685 | ||
2686 | append result "\\\}" | |
4b48d439 KS |
2687 | return $result |
2688 | } | |
2689 | ||
2690 | # Build a breakpoint table regexp given the list of breakpoints in `bp_list', | |
2691 | # constructed by mi_make_breakpoint. | |
2692 | # | |
2693 | # Example: Construct a breakpoint table where the only attributes we | |
2694 | # test for are the existence of three breakpoints numbered 1, 2, and 3. | |
2695 | # | |
2696 | # set bps {} | |
2697 | # lappend bps [mi_make_breakpoint -number 1] | |
2698 | # lappend bps [mi_make_breakpoint -number 2] | |
2699 | # lappned bps [mi_make_breakpoint -number 3] | |
2700 | # mi_make_breakpoint_table $bps | |
2701 | # will return (abbreviated for clarity): | |
2702 | # BreakpointTable={nr_rows="3",nr_cols="6",hdr=[{width=".*",...} ...], | |
2703 | # body=[bkpt={number="1",...},bkpt={number="2",...},bkpt={number="3",...}]} | |
2704 | ||
2705 | proc mi_make_breakpoint_table {bp_list} { | |
2706 | # Build header -- assume a standard header for all breakpoint tables. | |
2707 | set hl {} | |
2708 | foreach {nm hdr} [list number Num type Type disp Disp enabled Enb \ | |
2709 | addr Address what What] { | |
2710 | # The elements here are the MI table headers, which have the | |
2711 | # format: | |
2712 | # {width="7",alignment="-1",col_name="number",colhdr="Num"} | |
2713 | lappend hl "{[mi_build_kv_pairs [list width .* alignment .* \ | |
2714 | col_name $nm colhdr $hdr]]}" | |
2715 | } | |
2716 | set header "hdr=\\\[[join $hl ,]\\\]" | |
2717 | ||
2718 | # The caller has implicitly supplied the number of columns and rows. | |
2719 | set nc [llength $hl] | |
2720 | set nr [llength $bp_list] | |
2721 | ||
2722 | # Build body -- mi_make_breakpoint has done most of the work. | |
2723 | set body "body=\\\[[join $bp_list ,]\\\]" | |
2724 | ||
2725 | # Assemble the final regexp. | |
2726 | return "BreakpointTable={nr_rows=\"$nr\",nr_cols=\"$nc\",$header,$body}" | |
2727 | } | |
4d6cceb4 DE |
2728 | |
2729 | # Return a 1 for configurations that do not support Python scripting. | |
2730 | # Note: This also sets various globals that specify which version of Python | |
2731 | # is in use. See skip_python_tests_prompt. | |
2732 | ||
2733 | proc mi_skip_python_tests {} { | |
2734 | global mi_gdb_prompt | |
2735 | return [skip_python_tests_prompt "$mi_gdb_prompt$"] | |
2736 | } | |
f015c27b | 2737 | |
297989a1 TV |
2738 | # As skip_libstdcxx_probe_tests_prompt, with mi_gdb_prompt. |
2739 | ||
2740 | proc mi_skip_libstdcxx_probe_tests {} { | |
2741 | global mi_gdb_prompt | |
2742 | return [skip_libstdcxx_probe_tests_prompt "$mi_gdb_prompt$"] | |
2743 | } | |
2744 | ||
f015c27b PA |
2745 | # Check whether we're testing with the remote or extended-remote |
2746 | # targets. | |
2747 | ||
2748 | proc mi_is_target_remote {} { | |
2749 | global mi_gdb_prompt | |
2750 | ||
2751 | return [gdb_is_target_remote_prompt "$mi_gdb_prompt"] | |
2752 | } |