Commit | Line | Data |
---|---|---|
7ddebc7e | 1 | # Copyright 1999, 2000, 2002 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 | |
5 | # the Free Software Foundation; either version 2 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
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. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program; if not, write to the Free Software | |
15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
16 | ||
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@prep.ai.mit.edu | |
19 | ||
20 | # This file was based on a file written by Fred Fish. (fnf@cygnus.com) | |
21 | ||
22 | # Test setup routines that work with the MI interpreter. | |
23 | ||
24 | # The variable mi_gdb_prompt is a regexp which matches the gdb mi prompt. | |
25 | # Set it if it is not already set. | |
26 | global mi_gdb_prompt | |
27 | if ![info exists mi_gdb_prompt] then { | |
28 | set mi_gdb_prompt "\[(\]gdb\[)\] \r\n" | |
29 | } | |
30 | ||
31 | set MIFLAGS "-i=mi" | |
32 | ||
33 | # | |
34 | # mi_gdb_exit -- exit the GDB, killing the target program if necessary | |
35 | # | |
36 | proc mi_gdb_exit {} { | |
37 | catch mi_uncatched_gdb_exit | |
38 | } | |
39 | ||
40 | proc mi_uncatched_gdb_exit {} { | |
41 | global GDB | |
42 | global GDBFLAGS | |
43 | global verbose | |
44 | global gdb_spawn_id; | |
45 | global gdb_prompt | |
46 | global mi_gdb_prompt | |
47 | global MIFLAGS | |
48 | ||
49 | gdb_stop_suppressing_tests; | |
50 | ||
51 | if { [info procs sid_exit] != "" } { | |
52 | sid_exit | |
53 | } | |
54 | ||
55 | if ![info exists gdb_spawn_id] { | |
56 | return; | |
57 | } | |
58 | ||
59 | verbose "Quitting $GDB $GDBFLAGS $MIFLAGS" | |
60 | ||
61 | if { [is_remote host] && [board_info host exists fileid] } { | |
62 | send_gdb "999-gdb-exit\n"; | |
63 | gdb_expect 10 { | |
64 | -re "y or n" { | |
65 | send_gdb "y\n"; | |
66 | exp_continue; | |
67 | } | |
68 | -re "Undefined command.*$gdb_prompt $" { | |
69 | send_gdb "quit\n" | |
70 | exp_continue; | |
71 | } | |
72 | -re "DOSEXIT code" { } | |
73 | default { } | |
74 | } | |
75 | } | |
76 | ||
77 | if ![is_remote host] { | |
78 | remote_close host; | |
79 | } | |
80 | unset gdb_spawn_id | |
81 | } | |
82 | ||
83 | # | |
84 | # start gdb -- start gdb running, default procedure | |
85 | # | |
86 | # When running over NFS, particularly if running many simultaneous | |
87 | # tests on different hosts all using the same server, things can | |
88 | # get really slow. Give gdb at least 3 minutes to start up. | |
89 | # | |
90 | proc mi_gdb_start { } { | |
91 | global verbose | |
92 | global GDB | |
93 | global GDBFLAGS | |
94 | global gdb_prompt | |
95 | global mi_gdb_prompt | |
96 | global timeout | |
97 | global gdb_spawn_id; | |
98 | global MIFLAGS | |
99 | ||
100 | gdb_stop_suppressing_tests; | |
101 | ||
1759b3c3 AC |
102 | # Start SID. |
103 | if { [info procs sid_start] != "" } { | |
104 | verbose "Spawning SID" | |
105 | sid_start | |
106 | } | |
107 | ||
fb40c209 AC |
108 | verbose "Spawning $GDB -nw $GDBFLAGS $MIFLAGS" |
109 | ||
110 | if [info exists gdb_spawn_id] { | |
111 | return 0; | |
112 | } | |
113 | ||
114 | if ![is_remote host] { | |
115 | if { [which $GDB] == 0 } then { | |
116 | perror "$GDB does not exist." | |
117 | exit 1 | |
118 | } | |
119 | } | |
120 | set res [remote_spawn host "$GDB -nw $GDBFLAGS $MIFLAGS [host_info gdb_opts]"]; | |
121 | if { $res < 0 || $res == "" } { | |
122 | perror "Spawning $GDB failed." | |
123 | return 1; | |
124 | } | |
125 | gdb_expect { | |
1f312e79 JJ |
126 | -re "~\"GNU.*\r\n~\".*$mi_gdb_prompt$" { |
127 | # We have a new format mi startup prompt. If we are | |
128 | # running mi1, then this is an error as we should be | |
129 | # using the old-style prompt. | |
130 | if { $MIFLAGS == "-i=mi1" } { | |
131 | perror "(mi startup) Got unexpected new mi prompt." | |
132 | remote_close host; | |
133 | return -1; | |
134 | } | |
135 | verbose "GDB initialized." | |
136 | } | |
137 | -re "\[^~\].*$mi_gdb_prompt$" { | |
138 | # We have an old format mi startup prompt. If we are | |
139 | # not running mi1, then this is an error as we should be | |
140 | # using the new-style prompt. | |
141 | if { $MIFLAGS != "-i=mi1" } { | |
142 | perror "(mi startup) Got unexpected old mi prompt." | |
143 | remote_close host; | |
144 | return -1; | |
145 | } | |
d20bf2e8 | 146 | verbose "GDB initialized." |
fb40c209 AC |
147 | } |
148 | -re ".*$gdb_prompt $" { | |
149 | untested "Skip mi tests (got non-mi prompt)." | |
150 | remote_close host; | |
151 | return -1; | |
152 | } | |
76c520e0 AC |
153 | -re ".*unrecognized option.*for a complete list of options." { |
154 | untested "Skip mi tests (not compiled with mi support)." | |
155 | remote_close host; | |
156 | return -1; | |
157 | } | |
7d76bd60 MK |
158 | -re ".*Interpreter `mi' unrecognized." { |
159 | untested "Skip mi tests (not compiled with mi support)." | |
160 | remote_close host; | |
161 | return -1; | |
162 | } | |
fb40c209 AC |
163 | timeout { |
164 | perror "(timeout) GDB never initialized after 10 seconds." | |
165 | remote_close host; | |
166 | return -1 | |
167 | } | |
168 | } | |
169 | set gdb_spawn_id -1; | |
170 | ||
171 | # FIXME: mi output does not go through pagers, so these can be removed. | |
172 | # force the height to "unlimited", so no pagers get used | |
173 | send_gdb "100-gdb-set height 0\n" | |
174 | gdb_expect 10 { | |
175 | -re ".*100-gdb-set height 0\r\n100\\\^done\r\n$mi_gdb_prompt$" { | |
176 | verbose "Setting height to 0." 2 | |
177 | } | |
178 | timeout { | |
179 | warning "Couldn't set the height to 0" | |
180 | } | |
181 | } | |
182 | # force the width to "unlimited", so no wraparound occurs | |
183 | send_gdb "101-gdb-set width 0\n" | |
184 | gdb_expect 10 { | |
185 | -re ".*101-gdb-set width 0\r\n101\\\^done\r\n$mi_gdb_prompt$" { | |
186 | verbose "Setting width to 0." 2 | |
187 | } | |
188 | timeout { | |
189 | warning "Couldn't set the width to 0." | |
190 | } | |
191 | } | |
192 | ||
fb40c209 AC |
193 | return 0; |
194 | } | |
195 | ||
196 | # Many of the tests depend on setting breakpoints at various places and | |
197 | # running until that breakpoint is reached. At times, we want to start | |
198 | # with a clean-slate with respect to breakpoints, so this utility proc | |
199 | # lets us do this without duplicating this code everywhere. | |
200 | # | |
201 | ||
202 | proc mi_delete_breakpoints {} { | |
203 | global mi_gdb_prompt | |
204 | ||
205 | # FIXME: The mi operation won't accept a prompt back and will use the 'all' arg | |
206 | send_gdb "102-break-delete\n" | |
207 | gdb_expect 30 { | |
208 | -re "Delete all breakpoints.*y or n.*$" { | |
209 | send_gdb "y\n"; | |
210 | exp_continue | |
211 | } | |
212 | -re ".*102-break-delete\r\n102\\\^done\r\n$mi_gdb_prompt$" { | |
213 | # This happens if there were no breakpoints | |
214 | } | |
f1c8a949 | 215 | timeout { perror "Delete all breakpoints in mi_delete_breakpoints (timeout)" ; return } |
fb40c209 AC |
216 | } |
217 | ||
218 | # The correct output is not "No breakpoints or watchpoints." but an | |
219 | # empty BreakpointTable. Also, a query is not acceptable with mi. | |
220 | send_gdb "103-break-list\n" | |
221 | gdb_expect 30 { | |
222 | -re "103-break-list\r\n103\\\^done,BreakpointTable=\{\}\r\n$mi_gdb_prompt$" {} | |
cff22675 | 223 | -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=\\\[\\\]\}" {} |
fb40c209 AC |
224 | -re "103-break-list\r\n103\\\^doneNo breakpoints or watchpoints.\r\n\r\n$mi_gdb_prompt$" {warning "Unexpected console text received"} |
225 | -re "$mi_gdb_prompt$" { perror "Breakpoints not deleted" ; return } | |
226 | -re "Delete all breakpoints.*or n.*$" { | |
227 | warning "Unexpected prompt for breakpoints deletion"; | |
228 | send_gdb "y\n"; | |
229 | exp_continue | |
230 | } | |
231 | timeout { perror "-break-list (timeout)" ; return } | |
232 | } | |
233 | } | |
234 | ||
235 | proc mi_gdb_reinitialize_dir { subdir } { | |
236 | global mi_gdb_prompt | |
da81390b | 237 | global MIFLAGS |
fb40c209 AC |
238 | |
239 | global suppress_flag | |
240 | if { $suppress_flag } { | |
241 | return | |
242 | } | |
243 | ||
244 | if [is_remote host] { | |
245 | return ""; | |
246 | } | |
247 | ||
da81390b JJ |
248 | if { $MIFLAGS == "-i=mi1" } { |
249 | send_gdb "104-environment-directory\n" | |
250 | gdb_expect 60 { | |
fb40c209 AC |
251 | -re ".*Reinitialize source path to empty.*y or n. " { |
252 | warning "Got confirmation prompt for dir reinitialization." | |
253 | send_gdb "y\n" | |
254 | gdb_expect 60 { | |
255 | -re "$mi_gdb_prompt$" {} | |
256 | timeout {error "Dir reinitialization failed (timeout)"} | |
257 | } | |
258 | } | |
259 | -re "$mi_gdb_prompt$" {} | |
260 | timeout {error "Dir reinitialization failed (timeout)"} | |
da81390b JJ |
261 | } |
262 | } else { | |
263 | send_gdb "104-environment-directory -r\n" | |
264 | gdb_expect 60 { | |
265 | -re "104\\\^done,source-path=.*\r\n$mi_gdb_prompt$" {} | |
266 | -re "$mi_gdb_prompt$" {} | |
267 | timeout {error "Dir reinitialization failed (timeout)"} | |
268 | } | |
fb40c209 AC |
269 | } |
270 | ||
271 | send_gdb "105-environment-directory $subdir\n" | |
272 | gdb_expect 60 { | |
273 | -re "Source directories searched.*$mi_gdb_prompt$" { | |
274 | verbose "Dir set to $subdir" | |
275 | } | |
da81390b | 276 | -re "105\\\^done.*\r\n$mi_gdb_prompt$" { |
fb40c209 AC |
277 | # FIXME: We return just the prompt for now. |
278 | verbose "Dir set to $subdir" | |
279 | # perror "Dir \"$subdir\" failed." | |
280 | } | |
281 | } | |
282 | } | |
283 | ||
284 | # | |
285 | # load a file into the debugger. | |
286 | # return a -1 if anything goes wrong. | |
287 | # | |
288 | proc mi_gdb_load { arg } { | |
289 | global verbose | |
290 | global loadpath | |
291 | global loadfile | |
292 | global GDB | |
293 | global mi_gdb_prompt | |
b53f9b27 | 294 | global last_mi_gdb_file |
fb40c209 AC |
295 | upvar timeout timeout |
296 | ||
b53f9b27 MS |
297 | if { $arg == "" } { |
298 | set arg $last_mi_gdb_file; | |
299 | } | |
300 | ||
301 | set last_mi_gdb_file $arg; | |
302 | ||
fb40c209 AC |
303 | # ``gdb_unload'' |
304 | ||
305 | # ``gdb_file_cmd'' | |
306 | # FIXME: Several of these patterns are only acceptable for console | |
307 | # output. Queries are an error for mi. | |
308 | send_gdb "105-file-exec-and-symbols $arg\n" | |
309 | gdb_expect 120 { | |
310 | -re "Reading symbols from.*done.*$mi_gdb_prompt$" { | |
311 | verbose "\t\tLoaded $arg into the $GDB" | |
312 | # All OK | |
313 | } | |
314 | -re "has no symbol-table.*$mi_gdb_prompt$" { | |
315 | perror "$arg wasn't compiled with \"-g\"" | |
316 | return -1 | |
317 | } | |
318 | -re "A program is being debugged already.*Kill it.*y or n. $" { | |
319 | send_gdb "y\n" | |
320 | verbose "\t\tKilling previous program being debugged" | |
321 | exp_continue | |
322 | } | |
323 | -re "Load new symbol table from \".*\".*y or n. $" { | |
324 | send_gdb "y\n" | |
325 | gdb_expect 120 { | |
326 | -re "Reading symbols from.*done.*$mi_gdb_prompt$" { | |
327 | verbose "\t\tLoaded $arg with new symbol table into $GDB" | |
328 | # All OK | |
329 | } | |
330 | timeout { | |
331 | perror "(timeout) Couldn't load $arg, other program already loaded." | |
332 | return -1 | |
333 | } | |
334 | } | |
335 | } | |
336 | -re "No such file or directory.*$mi_gdb_prompt$" { | |
337 | perror "($arg) No such file or directory\n" | |
338 | return -1 | |
339 | } | |
340 | -re "105-file-exec-and-symbols .*\r\n105\\\^done\r\n$mi_gdb_prompt$" { | |
341 | # We are just giving the prompt back for now | |
342 | # All OK | |
343 | } | |
344 | timeout { | |
345 | perror "couldn't load $arg into $GDB (timed out)." | |
346 | return -1 | |
347 | } | |
348 | eof { | |
349 | # This is an attempt to detect a core dump, but seems not to | |
350 | # work. Perhaps we need to match .* followed by eof, in which | |
351 | # gdb_expect does not seem to have a way to do that. | |
352 | perror "couldn't load $arg into $GDB (end of file)." | |
353 | return -1 | |
354 | } | |
355 | } | |
356 | ||
357 | # ``load'' | |
358 | if { [info procs send_target_sid] != "" } { | |
359 | # For SID, things get complex | |
360 | send_target_sid | |
361 | gdb_expect 60 { | |
362 | -re "\\^done,.*$mi_gdb_prompt$" { | |
363 | } | |
364 | timeout { | |
365 | perror "Unable to connect to SID target" | |
366 | return -1 | |
367 | } | |
368 | } | |
369 | send_gdb "48-target-download\n" | |
370 | gdb_expect 10 { | |
371 | -re "48\\^done.*$mi_gdb_prompt$" { | |
372 | } | |
373 | timeout { | |
374 | perror "Unable to download to SID target" | |
375 | return -1 | |
376 | } | |
377 | } | |
378 | } elseif { [target_info protocol] == "sim" } { | |
379 | # For the simulator, just connect to it directly. | |
380 | send_gdb "47-target-select sim\n" | |
381 | gdb_expect 10 { | |
382 | -re "47\\^connected.*$mi_gdb_prompt$" { | |
383 | } | |
384 | timeout { | |
385 | perror "Unable to select sim target" | |
386 | return -1 | |
387 | } | |
388 | } | |
389 | send_gdb "48-target-download\n" | |
390 | gdb_expect 10 { | |
391 | -re "48\\^done.*$mi_gdb_prompt$" { | |
392 | } | |
393 | timeout { | |
394 | perror "Unable to download to sim target" | |
395 | return -1 | |
396 | } | |
397 | } | |
b53f9b27 MS |
398 | } elseif { [target_info gdb_protocol] == "remote" } { |
399 | # remote targets | |
400 | send_gdb "target [target_info gdb_protocol] [target_info netport]\n" | |
401 | gdb_expect 60 { | |
402 | -re "\\^done,.*$mi_gdb_prompt$" { | |
403 | } | |
404 | timeout { | |
405 | perror "Unable to connect to remote target" | |
406 | return -1 | |
407 | } | |
408 | } | |
409 | send_gdb "48-target-download\n" | |
410 | gdb_expect 10 { | |
411 | -re "48\\^done.*$mi_gdb_prompt$" { | |
412 | } | |
413 | timeout { | |
414 | perror "Unable to download to remote target" | |
415 | return -1 | |
416 | } | |
417 | } | |
fb40c209 AC |
418 | } |
419 | return 0 | |
420 | } | |
421 | ||
422 | # mi_gdb_test COMMAND PATTERN MESSAGE -- send a command to gdb; test the result. | |
423 | # | |
424 | # COMMAND is the command to execute, send to GDB with send_gdb. If | |
425 | # this is the null string no command is sent. | |
426 | # PATTERN is the pattern to match for a PASS, and must NOT include | |
427 | # the \r\n sequence immediately before the gdb prompt. | |
428 | # MESSAGE is an optional message to be printed. If this is | |
429 | # omitted, then the pass/fail messages use the command string as the | |
430 | # message. (If this is the empty string, then sometimes we don't | |
431 | # call pass or fail at all; I don't understand this at all.) | |
432 | # | |
433 | # Returns: | |
434 | # 1 if the test failed, | |
435 | # 0 if the test passes, | |
436 | # -1 if there was an internal error. | |
437 | # | |
438 | proc mi_gdb_test { args } { | |
439 | global verbose | |
440 | global mi_gdb_prompt | |
07c98896 | 441 | global GDB expect_out |
fb40c209 AC |
442 | upvar timeout timeout |
443 | ||
444 | if [llength $args]>2 then { | |
445 | set message [lindex $args 2] | |
446 | } else { | |
447 | set message [lindex $args 0] | |
448 | } | |
449 | set command [lindex $args 0] | |
450 | set pattern [lindex $args 1] | |
451 | ||
452 | if [llength $args]==5 { | |
453 | set question_string [lindex $args 3]; | |
454 | set response_string [lindex $args 4]; | |
455 | } else { | |
456 | set question_string "^FOOBAR$" | |
457 | } | |
458 | ||
459 | if $verbose>2 then { | |
460 | send_user "Sending \"$command\" to gdb\n" | |
461 | send_user "Looking to match \"$pattern\"\n" | |
462 | send_user "Message is \"$message\"\n" | |
463 | } | |
464 | ||
465 | set result -1 | |
466 | set string "${command}\n"; | |
467 | if { $command != "" } { | |
468 | while { "$string" != "" } { | |
469 | set foo [string first "\n" "$string"]; | |
470 | set len [string length "$string"]; | |
471 | if { $foo < [expr $len - 1] } { | |
472 | set str [string range "$string" 0 $foo]; | |
473 | if { [send_gdb "$str"] != "" } { | |
474 | global suppress_flag; | |
475 | ||
476 | if { ! $suppress_flag } { | |
477 | perror "Couldn't send $command to GDB."; | |
478 | } | |
479 | fail "$message"; | |
480 | return $result; | |
481 | } | |
482 | gdb_expect 2 { | |
483 | -re "\[\r\n\]" { } | |
484 | timeout { } | |
485 | } | |
486 | set string [string range "$string" [expr $foo + 1] end]; | |
487 | } else { | |
488 | break; | |
489 | } | |
490 | } | |
491 | if { "$string" != "" } { | |
492 | if { [send_gdb "$string"] != "" } { | |
493 | global suppress_flag; | |
494 | ||
495 | if { ! $suppress_flag } { | |
496 | perror "Couldn't send $command to GDB."; | |
497 | } | |
498 | fail "$message"; | |
499 | return $result; | |
500 | } | |
501 | } | |
502 | } | |
503 | ||
504 | if [info exists timeout] { | |
505 | set tmt $timeout; | |
506 | } else { | |
507 | global timeout; | |
508 | if [info exists timeout] { | |
509 | set tmt $timeout; | |
510 | } else { | |
511 | set tmt 60; | |
512 | } | |
513 | } | |
514 | gdb_expect $tmt { | |
515 | -re "\\*\\*\\* DOSEXIT code.*" { | |
516 | if { $message != "" } { | |
517 | fail "$message"; | |
518 | } | |
519 | gdb_suppress_entire_file "GDB died"; | |
520 | return -1; | |
521 | } | |
522 | -re "Ending remote debugging.*$mi_gdb_prompt\[ \]*$" { | |
523 | if ![isnative] then { | |
524 | warning "Can`t communicate to remote target." | |
525 | } | |
526 | gdb_exit | |
527 | gdb_start | |
528 | set result -1 | |
7ddebc7e KS |
529 | } |
530 | -re "\[\r\n\]*($pattern)\[\r\n\]+$mi_gdb_prompt\[ \]*$" { | |
531 | if ![string match "" $message] then { | |
532 | pass "$message" | |
533 | } | |
534 | set result 0 | |
fb40c209 AC |
535 | } |
536 | -re "(${question_string})$" { | |
537 | send_gdb "$response_string\n"; | |
538 | exp_continue; | |
539 | } | |
540 | -re "Undefined.* command:.*$mi_gdb_prompt\[ \]*$" { | |
541 | perror "Undefined command \"$command\"." | |
542 | fail "$message" | |
543 | set result 1 | |
544 | } | |
545 | -re "Ambiguous command.*$mi_gdb_prompt\[ \]*$" { | |
546 | perror "\"$command\" is not a unique command name." | |
547 | fail "$message" | |
548 | set result 1 | |
fb40c209 AC |
549 | } |
550 | -re "Program exited with code \[0-9\]+.*$mi_gdb_prompt\[ \]*$" { | |
551 | if ![string match "" $message] then { | |
ed4c619a | 552 | set errmsg "$message (the program exited)" |
fb40c209 | 553 | } else { |
ed4c619a | 554 | set errmsg "$command (the program exited)" |
fb40c209 AC |
555 | } |
556 | fail "$errmsg" | |
557 | return -1 | |
558 | } | |
559 | -re "The program is not being run.*$mi_gdb_prompt\[ \]*$" { | |
560 | if ![string match "" $message] then { | |
ed4c619a | 561 | set errmsg "$message (the program is no longer running)" |
fb40c209 | 562 | } else { |
ed4c619a | 563 | set errmsg "$command (the program is no longer running)" |
fb40c209 AC |
564 | } |
565 | fail "$errmsg" | |
566 | return -1 | |
567 | } | |
568 | -re ".*$mi_gdb_prompt\[ \]*$" { | |
569 | if ![string match "" $message] then { | |
570 | fail "$message" | |
571 | } | |
572 | set result 1 | |
573 | } | |
574 | "<return>" { | |
575 | send_gdb "\n" | |
576 | perror "Window too small." | |
577 | fail "$message" | |
578 | } | |
579 | -re "\\(y or n\\) " { | |
580 | send_gdb "n\n" | |
581 | perror "Got interactive prompt." | |
582 | fail "$message" | |
583 | } | |
584 | eof { | |
585 | perror "Process no longer exists" | |
586 | if { $message != "" } { | |
587 | fail "$message" | |
588 | } | |
589 | return -1 | |
590 | } | |
591 | full_buffer { | |
592 | perror "internal buffer is full." | |
593 | fail "$message" | |
594 | } | |
595 | timeout { | |
596 | if ![string match "" $message] then { | |
597 | fail "$message (timeout)" | |
598 | } | |
599 | set result 1 | |
600 | } | |
601 | } | |
602 | return $result | |
603 | } | |
604 | ||
605 | # | |
606 | # MI run command. (A modified version of gdb_run_cmd) | |
607 | # | |
608 | ||
609 | # In patterns, the newline sequence ``\r\n'' is matched explicitly as | |
610 | # ``.*$'' could swallow up output that we attempt to match elsewhere. | |
611 | ||
612 | proc mi_run_cmd {args} { | |
613 | global suppress_flag | |
614 | if { $suppress_flag } { | |
615 | return -1 | |
616 | } | |
617 | global mi_gdb_prompt | |
618 | ||
619 | if [target_info exists gdb_init_command] { | |
620 | send_gdb "[target_info gdb_init_command]\n"; | |
621 | gdb_expect 30 { | |
622 | -re "$mi_gdb_prompt$" { } | |
623 | default { | |
624 | perror "gdb_init_command for target failed"; | |
625 | return; | |
626 | } | |
627 | } | |
628 | } | |
629 | ||
630 | if [target_info exists use_gdb_stub] { | |
631 | if [target_info exists gdb,do_reload_on_run] { | |
632 | # Specifying no file, defaults to the executable | |
633 | # currently being debugged. | |
634 | if { [mi_gdb_load ""] < 0 } { | |
635 | return; | |
636 | } | |
637 | send_gdb "000-exec-continue\n"; | |
638 | gdb_expect 60 { | |
639 | -re "Continu\[^\r\n\]*\[\r\n\]" {} | |
640 | default {} | |
641 | } | |
642 | return; | |
643 | } | |
6a90e1d0 AC |
644 | |
645 | if [target_info exists gdb,start_symbol] { | |
646 | set start [target_info gdb,start_symbol]; | |
647 | } else { | |
648 | set start "start"; | |
649 | } | |
650 | ||
651 | # HACK: Should either use 000-jump or fix the target code | |
652 | # to better handle RUN. | |
653 | send_gdb "jump *$start\n" | |
654 | warning "Using CLI jump command, expect run-to-main FAIL" | |
655 | return | |
fb40c209 AC |
656 | } |
657 | ||
658 | send_gdb "000-exec-run $args\n" | |
659 | gdb_expect { | |
660 | -re "000\\^running\r\n${mi_gdb_prompt}" { | |
661 | } | |
662 | timeout { | |
663 | perror "Unable to start target" | |
664 | return | |
665 | } | |
666 | } | |
667 | # NOTE: Shortly after this there will be a ``000*stopping,...(gdb)'' | |
668 | } | |
669 | ||
670 | # | |
671 | # Just like run-to-main but works with the MI interface | |
672 | # | |
673 | ||
674 | proc mi_run_to_main { } { | |
675 | global suppress_flag | |
676 | if { $suppress_flag } { | |
677 | return -1 | |
678 | } | |
679 | ||
fb40c209 AC |
680 | global srcdir |
681 | global subdir | |
682 | global binfile | |
683 | global srcfile | |
684 | ||
fb40c209 AC |
685 | mi_delete_breakpoints |
686 | mi_gdb_reinitialize_dir $srcdir/$subdir | |
687 | mi_gdb_load ${binfile} | |
688 | ||
08b468e0 KS |
689 | mi_runto main |
690 | } | |
fb40c209 | 691 | |
08b468e0 KS |
692 | |
693 | # Just like gdb's "runto" proc, it will run the target to a given | |
694 | # function. The big difference here between mi_runto and mi_execute_to | |
695 | # is that mi_execute_to must have the inferior running already. This | |
696 | # proc will (like gdb's runto) (re)start the inferior, too. | |
697 | # | |
698 | # FUNC is the linespec of the place to stop (it inserts a breakpoint here). | |
699 | # It returns: | |
700 | # -1 if test suppressed, failed, timedout | |
701 | # 0 if test passed | |
702 | ||
703 | proc mi_runto {func} { | |
704 | global suppress_flag | |
705 | if { $suppress_flag } { | |
706 | return -1 | |
707 | } | |
708 | ||
709 | global mi_gdb_prompt expect_out | |
710 | global hex decimal | |
711 | ||
712 | set test "mi runto $func" | |
713 | mi_gdb_test "200-break-insert $func" \ | |
714 | "200\\^done,bkpt=\{number=\"\[0-9\]+\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"$func\",file=\".*\",line=\"\[0-9\]*\",times=\"0\"\}" \ | |
715 | "breakpoint at $func" | |
716 | ||
717 | if {![regexp {number="[0-9]+"} $expect_out(buffer) str] | |
718 | || ![scan $str {number="%d"} bkptno]} { | |
719 | set bkptno {[0-9]+} | |
720 | } | |
721 | ||
722 | mi_run_cmd | |
723 | gdb_expect { | |
724 | -re ".*000\\*stopped,reason=\"breakpoint-hit\",bkptno=\"$bkptno\",thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\"$func\",args=\(\\\[.*\\\]\|\{.*\}\),file=\".*\",line=\"\[0-9\]*\"\}\r\n$mi_gdb_prompt$" { | |
725 | pass "$test" | |
726 | return 0 | |
727 | } | |
728 | -re ".*$mi_gdb_prompt$" { | |
729 | fail "$test (2)" | |
730 | } | |
731 | timeout { | |
732 | fail "$test (timeout)" | |
733 | return -1 | |
734 | } | |
735 | } | |
fb40c209 AC |
736 | } |
737 | ||
738 | ||
739 | # Next to the next statement | |
08b468e0 | 740 | # For return values, see mi_execute_to_helper |
fb40c209 AC |
741 | |
742 | proc mi_next { test } { | |
dc360f58 | 743 | return [mi_next_to {.*} {.*} {.*} {.*} $test] |
fb40c209 AC |
744 | } |
745 | ||
746 | ||
747 | # Step to the next statement | |
08b468e0 | 748 | # For return values, see mi_execute_to_helper |
fb40c209 AC |
749 | |
750 | proc mi_step { test } { | |
dc360f58 | 751 | return [mi_step_to {.*} {.*} {.*} {.*} $test] |
fb40c209 | 752 | } |
dcf95b47 DJ |
753 | |
754 | # cmd should not include the number or newline (i.e. "exec-step 3", not | |
755 | # "220-exec-step 3\n" | |
756 | ||
1902c51f DJ |
757 | # Can not match -re ".*\r\n${mi_gdb_prompt}", because of false positives |
758 | # after the first prompt is printed. | |
759 | ||
08b468e0 | 760 | proc mi_execute_to_helper { cmd reason func args file line extra test } { |
dcf95b47 DJ |
761 | global suppress_flag |
762 | if { $suppress_flag } { | |
763 | return -1 | |
764 | } | |
765 | global mi_gdb_prompt | |
766 | global hex | |
767 | global decimal | |
768 | send_gdb "220-$cmd\n" | |
769 | gdb_expect { | |
dc360f58 | 770 | -re ".*220\\^running\r\n${mi_gdb_prompt}.*220\\*stopped,reason=\"$reason\",thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\"$func\",args=$args,file=\".*$file\",line=\"$line\"\}$extra\r\n$mi_gdb_prompt$" { |
dcf95b47 DJ |
771 | pass "$test" |
772 | return 0 | |
773 | } | |
dc360f58 | 774 | -re ".*220\\^running\r\n${mi_gdb_prompt}.*220\\*stopped,reason=\"$reason\",thread-id=\"$decimal\",frame=\{addr=\"$hex\",func=\".*\",args=\[\\\[\{\].*\[\\\]\}\],file=\".*\",line=\"\[0-9\]*\"\}.*\r\n$mi_gdb_prompt$" { |
dcf95b47 DJ |
775 | fail "$test (stopped at wrong place)" |
776 | return -1 | |
777 | } | |
778 | -re "220\\^running\r\n${mi_gdb_prompt}.*\r\n${mi_gdb_prompt}$" { | |
779 | fail "$test (unknown output after running)" | |
780 | return -1 | |
781 | } | |
dcf95b47 DJ |
782 | timeout { |
783 | fail "$test (timeout)" | |
784 | return -1 | |
785 | } | |
786 | } | |
787 | } | |
788 | ||
08b468e0 KS |
789 | proc mi_execute_to { cmd reason func args file line extra test } { |
790 | mi_execute_to_helper "$cmd" "$reason" "$func" "\\\[$args\\\]" \ | |
dcf95b47 DJ |
791 | "$file" "$line" "$extra" "$test" |
792 | } | |
793 | ||
794 | proc mi_next_to { func args file line test } { | |
08b468e0 | 795 | mi_execute_to "exec-next" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
796 | "$file" "$line" "" "$test" |
797 | } | |
798 | ||
799 | proc mi_step_to { func args file line test } { | |
08b468e0 | 800 | mi_execute_to "exec-step" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
801 | "$file" "$line" "" "$test" |
802 | } | |
803 | ||
804 | proc mi_finish_to { func args file line result ret test } { | |
08b468e0 | 805 | mi_execute_to "exec-finish" "function-finished" "$func" "$args" \ |
dcf95b47 DJ |
806 | "$file" "$line" \ |
807 | ",gdb-result-var=\"$result\",return-value=\"$ret\"" \ | |
808 | "$test" | |
809 | } | |
810 | ||
811 | proc mi_continue_to { bkptno func args file line test } { | |
08b468e0 | 812 | mi_execute_to "exec-continue" "breakpoint-hit\",bkptno=\"$bkptno" \ |
dcf95b47 DJ |
813 | "$func" "$args" "$file" "$line" "" "$test" |
814 | } | |
815 | ||
08b468e0 KS |
816 | proc mi0_execute_to { cmd reason func args file line extra test } { |
817 | mi_execute_to_helper "$cmd" "$reason" "$func" "\{$args\}" \ | |
dcf95b47 DJ |
818 | "$file" "$line" "$extra" "$test" |
819 | } | |
820 | ||
821 | proc mi0_next_to { func args file line test } { | |
08b468e0 | 822 | mi0_execute_to "exec-next" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
823 | "$file" "$line" "" "$test" |
824 | } | |
825 | ||
826 | proc mi0_step_to { func args file line test } { | |
08b468e0 | 827 | mi0_execute_to "exec-step" "end-stepping-range" "$func" "$args" \ |
dcf95b47 DJ |
828 | "$file" "$line" "" "$test" |
829 | } | |
830 | ||
831 | proc mi0_finish_to { func args file line result ret test } { | |
08b468e0 | 832 | mi0_execute_to "exec-finish" "function-finished" "$func" "$args" \ |
dcf95b47 DJ |
833 | "$file" "$line" \ |
834 | ",gdb-result-var=\"$result\",return-value=\"$ret\"" \ | |
835 | "$test" | |
836 | } | |
837 | ||
838 | proc mi0_continue_to { bkptno func args file line test } { | |
08b468e0 | 839 | mi0_execute_to "exec-continue" "breakpoint-hit\",bkptno=\"$bkptno" \ |
dcf95b47 DJ |
840 | "$func" "$args" "$file" "$line" "" "$test" |
841 | } |