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