Commit | Line | Data |
---|---|---|
b5ab8ff3 | 1 | # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
94b8e876 | 2 | # 2002, 2003, 2004 |
b6ba6518 | 3 | # Free Software Foundation, Inc. |
c906108c SS |
4 | |
5 | # This program is free software; you can redistribute it and/or modify | |
6 | # it under the terms of the GNU General Public License as published by | |
7 | # the Free Software Foundation; either version 2 of the License, or | |
8 | # (at your option) any later version. | |
9 | # | |
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program; if not, write to the Free Software | |
17 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 | ||
c906108c SS |
19 | # This file was written by Fred Fish. (fnf@cygnus.com) |
20 | ||
21 | # Generic gdb subroutines that should work for any target. If these | |
22 | # need to be modified for any target, it can be done with a variable | |
23 | # or by passing arguments. | |
24 | ||
25 | load_lib libgloss.exp | |
26 | ||
27 | global GDB | |
c906108c SS |
28 | |
29 | if [info exists TOOL_EXECUTABLE] { | |
30 | set GDB $TOOL_EXECUTABLE; | |
31 | } | |
32 | if ![info exists GDB] { | |
33 | if ![is_remote host] { | |
34 | set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]] | |
35 | } else { | |
36 | set GDB [transform gdb]; | |
37 | } | |
38 | } | |
39 | verbose "using GDB = $GDB" 2 | |
40 | ||
41 | global GDBFLAGS | |
42 | if ![info exists GDBFLAGS] { | |
43 | set GDBFLAGS "-nx" | |
44 | } | |
45 | verbose "using GDBFLAGS = $GDBFLAGS" 2 | |
46 | ||
9e0b60a8 JM |
47 | # The variable gdb_prompt is a regexp which matches the gdb prompt. |
48 | # Set it if it is not already set. | |
c906108c | 49 | global gdb_prompt |
9e0b60a8 | 50 | if ![info exists gdb_prompt] then { |
c906108c SS |
51 | set gdb_prompt "\[(\]gdb\[)\]" |
52 | } | |
53 | ||
93076499 ND |
54 | # Needed for some tests under Cygwin. |
55 | global EXEEXT | |
56 | global env | |
57 | ||
58 | if ![info exists env(EXEEXT)] { | |
59 | set EXEEXT "" | |
60 | } else { | |
61 | set EXEEXT $env(EXEEXT) | |
62 | } | |
63 | ||
085dd6e6 JM |
64 | ### Only procedures should come after this point. |
65 | ||
c906108c SS |
66 | # |
67 | # gdb_version -- extract and print the version number of GDB | |
68 | # | |
69 | proc default_gdb_version {} { | |
70 | global GDB | |
71 | global GDBFLAGS | |
72 | global gdb_prompt | |
73 | set fileid [open "gdb_cmd" w]; | |
74 | puts $fileid "q"; | |
75 | close $fileid; | |
76 | set cmdfile [remote_download host "gdb_cmd"]; | |
77 | set output [remote_exec host "$GDB -nw --command $cmdfile"] | |
78 | remote_file build delete "gdb_cmd"; | |
79 | remote_file host delete "$cmdfile"; | |
80 | set tmp [lindex $output 1]; | |
81 | set version "" | |
82 | regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version | |
83 | if ![is_remote host] { | |
84 | clone_output "[which $GDB] version $version $GDBFLAGS\n" | |
85 | } else { | |
86 | clone_output "$GDB on remote host version $version $GDBFLAGS\n" | |
87 | } | |
88 | } | |
89 | ||
90 | proc gdb_version { } { | |
91 | return [default_gdb_version]; | |
92 | } | |
93 | ||
94 | # | |
95 | # gdb_unload -- unload a file if one is loaded | |
96 | # | |
97 | ||
98 | proc gdb_unload {} { | |
99 | global verbose | |
100 | global GDB | |
101 | global gdb_prompt | |
102 | send_gdb "file\n" | |
103 | gdb_expect 60 { | |
104 | -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue } | |
105 | -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue } | |
106 | -re "A program is being debugged already..*Kill it.*y or n. $"\ | |
107 | { send_gdb "y\n" | |
108 | verbose "\t\tKilling previous program being debugged" | |
109 | exp_continue | |
110 | } | |
111 | -re "Discard symbol table from .*y or n.*$" { | |
112 | send_gdb "y\n" | |
113 | exp_continue | |
114 | } | |
115 | -re "$gdb_prompt $" {} | |
116 | timeout { | |
117 | perror "couldn't unload file in $GDB (timed out)." | |
118 | return -1 | |
119 | } | |
120 | } | |
121 | } | |
122 | ||
123 | # Many of the tests depend on setting breakpoints at various places and | |
124 | # running until that breakpoint is reached. At times, we want to start | |
125 | # with a clean-slate with respect to breakpoints, so this utility proc | |
126 | # lets us do this without duplicating this code everywhere. | |
127 | # | |
128 | ||
129 | proc delete_breakpoints {} { | |
130 | global gdb_prompt | |
131 | ||
a0b3c4fd JM |
132 | # we need a larger timeout value here or this thing just confuses |
133 | # itself. May need a better implementation if possible. - guo | |
134 | # | |
c906108c | 135 | send_gdb "delete breakpoints\n" |
a0b3c4fd | 136 | gdb_expect 100 { |
c906108c SS |
137 | -re "Delete all breakpoints.*y or n.*$" { |
138 | send_gdb "y\n"; | |
139 | exp_continue | |
140 | } | |
141 | -re "$gdb_prompt $" { # This happens if there were no breakpoints | |
142 | } | |
143 | timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return } | |
144 | } | |
145 | send_gdb "info breakpoints\n" | |
a0b3c4fd | 146 | gdb_expect 100 { |
c906108c SS |
147 | -re "No breakpoints or watchpoints..*$gdb_prompt $" {} |
148 | -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return } | |
149 | -re "Delete all breakpoints.*or n.*$" { | |
150 | send_gdb "y\n"; | |
151 | exp_continue | |
152 | } | |
153 | timeout { perror "info breakpoints (timeout)" ; return } | |
154 | } | |
155 | } | |
156 | ||
157 | ||
158 | # | |
159 | # Generic run command. | |
160 | # | |
161 | # The second pattern below matches up to the first newline *only*. | |
162 | # Using ``.*$'' could swallow up output that we attempt to match | |
163 | # elsewhere. | |
164 | # | |
165 | proc gdb_run_cmd {args} { | |
166 | global gdb_prompt | |
167 | ||
168 | if [target_info exists gdb_init_command] { | |
169 | send_gdb "[target_info gdb_init_command]\n"; | |
170 | gdb_expect 30 { | |
171 | -re "$gdb_prompt $" { } | |
172 | default { | |
173 | perror "gdb_init_command for target failed"; | |
174 | return; | |
175 | } | |
176 | } | |
177 | } | |
178 | ||
179 | if [target_info exists use_gdb_stub] { | |
180 | if [target_info exists gdb,do_reload_on_run] { | |
917317f4 JM |
181 | # Specifying no file, defaults to the executable |
182 | # currently being debugged. | |
2db8e78e | 183 | if { [gdb_load ""] != 0 } { |
917317f4 JM |
184 | return; |
185 | } | |
c906108c SS |
186 | send_gdb "continue\n"; |
187 | gdb_expect 60 { | |
188 | -re "Continu\[^\r\n\]*\[\r\n\]" {} | |
189 | default {} | |
190 | } | |
191 | return; | |
192 | } | |
193 | ||
194 | if [target_info exists gdb,start_symbol] { | |
195 | set start [target_info gdb,start_symbol]; | |
196 | } else { | |
197 | set start "start"; | |
198 | } | |
199 | send_gdb "jump *$start\n" | |
917317f4 JM |
200 | set start_attempt 1; |
201 | while { $start_attempt } { | |
202 | # Cap (re)start attempts at three to ensure that this loop | |
203 | # always eventually fails. Don't worry about trying to be | |
204 | # clever and not send a command when it has failed. | |
205 | if [expr $start_attempt > 3] { | |
206 | perror "Jump to start() failed (retry count exceeded)"; | |
c906108c SS |
207 | return; |
208 | } | |
917317f4 JM |
209 | set start_attempt [expr $start_attempt + 1]; |
210 | gdb_expect 30 { | |
211 | -re "Continuing at \[^\r\n\]*\[\r\n\]" { | |
212 | set start_attempt 0; | |
213 | } | |
214 | -re "No symbol \"_start\" in current.*$gdb_prompt $" { | |
215 | perror "Can't find start symbol to run in gdb_run"; | |
216 | return; | |
217 | } | |
218 | -re "No symbol \"start\" in current.*$gdb_prompt $" { | |
219 | send_gdb "jump *_start\n"; | |
220 | } | |
221 | -re "No symbol.*context.*$gdb_prompt $" { | |
222 | set start_attempt 0; | |
223 | } | |
224 | -re "Line.* Jump anyway.*y or n. $" { | |
225 | send_gdb "y\n" | |
226 | } | |
227 | -re "The program is not being run.*$gdb_prompt $" { | |
2db8e78e | 228 | if { [gdb_load ""] != 0 } { |
917317f4 JM |
229 | return; |
230 | } | |
231 | send_gdb "jump *$start\n"; | |
232 | } | |
233 | timeout { | |
234 | perror "Jump to start() failed (timeout)"; | |
235 | return | |
236 | } | |
c906108c | 237 | } |
c906108c SS |
238 | } |
239 | if [target_info exists gdb_stub] { | |
240 | gdb_expect 60 { | |
241 | -re "$gdb_prompt $" { | |
242 | send_gdb "continue\n" | |
243 | } | |
244 | } | |
245 | } | |
246 | return | |
247 | } | |
83f66e8f DJ |
248 | |
249 | if [target_info exists gdb,do_reload_on_run] { | |
2db8e78e | 250 | if { [gdb_load ""] != 0 } { |
83f66e8f DJ |
251 | return; |
252 | } | |
253 | } | |
c906108c SS |
254 | send_gdb "run $args\n" |
255 | # This doesn't work quite right yet. | |
256 | gdb_expect 60 { | |
257 | -re "The program .* has been started already.*y or n. $" { | |
258 | send_gdb "y\n" | |
259 | exp_continue | |
260 | } | |
261 | -re "Starting program: \[^\r\n\]*" {} | |
262 | } | |
263 | } | |
264 | ||
78a1a894 DJ |
265 | # Set a breakpoint at FUNCTION. If there is an additional argument it is |
266 | # a list of options; the only currently supported option is allow-pending. | |
267 | ||
268 | proc gdb_breakpoint { function args } { | |
c906108c SS |
269 | global gdb_prompt |
270 | global decimal | |
271 | ||
78a1a894 DJ |
272 | set pending_response n |
273 | if {[lsearch -exact [lindex $args 0] allow-pending] != -1} { | |
274 | set pending_response y | |
275 | } | |
276 | ||
c906108c SS |
277 | send_gdb "break $function\n" |
278 | # The first two regexps are what we get with -g, the third is without -g. | |
279 | gdb_expect 30 { | |
280 | -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {} | |
281 | -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {} | |
282 | -re "Breakpoint \[0-9\]* at .*$gdb_prompt $" {} | |
78a1a894 DJ |
283 | -re "Breakpoint \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" { |
284 | if {$pending_response == "n"} { | |
285 | fail "setting breakpoint at $function" | |
286 | return 0 | |
287 | } | |
288 | } | |
9f27c604 | 289 | -re "Make breakpoint pending.*y or \\\[n\\\]. $" { |
78a1a894 | 290 | send_gdb "$pending_response\n" |
14b1a056 | 291 | exp_continue |
18fe2033 | 292 | } |
c906108c SS |
293 | -re "$gdb_prompt $" { fail "setting breakpoint at $function" ; return 0 } |
294 | timeout { fail "setting breakpoint at $function (timeout)" ; return 0 } | |
295 | } | |
296 | return 1; | |
297 | } | |
298 | ||
299 | # Set breakpoint at function and run gdb until it breaks there. | |
300 | # Since this is the only breakpoint that will be set, if it stops | |
301 | # at a breakpoint, we will assume it is the one we want. We can't | |
302 | # just compare to "function" because it might be a fully qualified, | |
78a1a894 DJ |
303 | # single quoted C++ function specifier. If there's an additional argument, |
304 | # pass it to gdb_breakpoint. | |
c906108c | 305 | |
78a1a894 | 306 | proc runto { function args } { |
c906108c SS |
307 | global gdb_prompt |
308 | global decimal | |
309 | ||
310 | delete_breakpoints | |
311 | ||
78a1a894 | 312 | if ![gdb_breakpoint $function [lindex $args 0]] { |
c906108c SS |
313 | return 0; |
314 | } | |
315 | ||
316 | gdb_run_cmd | |
317 | ||
318 | # the "at foo.c:36" output we get with -g. | |
319 | # the "in func" output we get without -g. | |
320 | gdb_expect 30 { | |
321 | -re "Break.* at .*:$decimal.*$gdb_prompt $" { | |
322 | return 1 | |
323 | } | |
324 | -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" { | |
325 | return 1 | |
326 | } | |
327 | -re "$gdb_prompt $" { | |
328 | fail "running to $function in runto" | |
329 | return 0 | |
330 | } | |
331 | timeout { | |
332 | fail "running to $function in runto (timeout)" | |
333 | return 0 | |
334 | } | |
335 | } | |
336 | return 1 | |
337 | } | |
338 | ||
339 | # | |
340 | # runto_main -- ask gdb to run until we hit a breakpoint at main. | |
341 | # The case where the target uses stubs has to be handled | |
342 | # specially--if it uses stubs, assuming we hit | |
343 | # breakpoint() and just step out of the function. | |
344 | # | |
345 | proc runto_main { } { | |
346 | global gdb_prompt | |
347 | global decimal | |
348 | ||
349 | if ![target_info exists gdb_stub] { | |
350 | return [runto main] | |
351 | } | |
352 | ||
353 | delete_breakpoints | |
354 | ||
355 | gdb_step_for_stub; | |
356 | ||
357 | return 1 | |
358 | } | |
359 | ||
7a292a7a | 360 | |
4ce44c66 JM |
361 | ### Continue, and expect to hit a breakpoint. |
362 | ### Report a pass or fail, depending on whether it seems to have | |
363 | ### worked. Use NAME as part of the test name; each call to | |
364 | ### continue_to_breakpoint should use a NAME which is unique within | |
365 | ### that test file. | |
366 | proc gdb_continue_to_breakpoint {name} { | |
367 | global gdb_prompt | |
368 | set full_name "continue to breakpoint: $name" | |
369 | ||
370 | send_gdb "continue\n" | |
371 | gdb_expect { | |
372 | -re "Breakpoint .* at .*\r\n$gdb_prompt $" { | |
373 | pass $full_name | |
374 | } | |
375 | -re ".*$gdb_prompt $" { | |
376 | fail $full_name | |
377 | } | |
378 | timeout { | |
379 | fail "$full_name (timeout)" | |
380 | } | |
381 | } | |
382 | } | |
383 | ||
384 | ||
039cf96d AC |
385 | # gdb_internal_error_resync: |
386 | # | |
387 | # Answer the questions GDB asks after it reports an internal error | |
388 | # until we get back to a GDB prompt. Decline to quit the debugging | |
389 | # session, and decline to create a core file. Return non-zero if the | |
390 | # resync succeeds. | |
391 | # | |
392 | # This procedure just answers whatever questions come up until it sees | |
393 | # a GDB prompt; it doesn't require you to have matched the input up to | |
394 | # any specific point. However, it only answers questions it sees in | |
395 | # the output itself, so if you've matched a question, you had better | |
396 | # answer it yourself before calling this. | |
397 | # | |
398 | # You can use this function thus: | |
399 | # | |
400 | # gdb_expect { | |
401 | # ... | |
402 | # -re ".*A problem internal to GDB has been detected" { | |
403 | # gdb_internal_error_resync | |
404 | # } | |
405 | # ... | |
406 | # } | |
407 | # | |
408 | proc gdb_internal_error_resync {} { | |
409 | global gdb_prompt | |
410 | ||
411 | set count 0 | |
412 | while {$count < 10} { | |
413 | gdb_expect { | |
414 | -re "Quit this debugging session\\? \\(y or n\\) $" { | |
415 | send_gdb "n\n" | |
416 | incr count | |
417 | } | |
418 | -re "Create a core file of GDB\\? \\(y or n\\) $" { | |
419 | send_gdb "n\n" | |
420 | incr count | |
421 | } | |
422 | -re "$gdb_prompt $" { | |
423 | # We're resynchronized. | |
424 | return 1 | |
425 | } | |
426 | timeout { | |
427 | perror "Could not resync from internal error (timeout)" | |
428 | return 0 | |
429 | } | |
430 | } | |
431 | } | |
2b211c59 AC |
432 | perror "Could not resync from internal error (resync count exceeded)" |
433 | return 0 | |
039cf96d AC |
434 | } |
435 | ||
4ce44c66 | 436 | |
2307bd6a | 437 | # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS |
8dbfb380 | 438 | # Send a command to gdb; test the result. |
c906108c SS |
439 | # |
440 | # COMMAND is the command to execute, send to GDB with send_gdb. If | |
441 | # this is the null string no command is sent. | |
2307bd6a DJ |
442 | # MESSAGE is a message to be printed with the built-in failure patterns |
443 | # if one of them matches. If MESSAGE is empty COMMAND will be used. | |
444 | # EXPECT_ARGUMENTS will be fed to expect in addition to the standard | |
445 | # patterns. Pattern elements will be evaluated in the caller's | |
446 | # context; action elements will be executed in the caller's context. | |
447 | # Unlike patterns for gdb_test, these patterns should generally include | |
448 | # the final newline and prompt. | |
c906108c SS |
449 | # |
450 | # Returns: | |
2307bd6a DJ |
451 | # 1 if the test failed, according to a built-in failure pattern |
452 | # 0 if only user-supplied patterns matched | |
c906108c SS |
453 | # -1 if there was an internal error. |
454 | # | |
d422fe19 AC |
455 | # You can use this function thus: |
456 | # | |
457 | # gdb_test_multiple "print foo" "test foo" { | |
458 | # -re "expected output 1" { | |
459 | # pass "print foo" | |
460 | # } | |
461 | # -re "expected output 2" { | |
462 | # fail "print foo" | |
463 | # } | |
464 | # } | |
465 | # | |
466 | # The standard patterns, such as "Program exited..." and "A problem | |
467 | # ...", all being implicitly appended to that list. | |
468 | # | |
2307bd6a | 469 | proc gdb_test_multiple { command message user_code } { |
c906108c SS |
470 | global verbose |
471 | global gdb_prompt | |
472 | global GDB | |
473 | upvar timeout timeout | |
c47cebdb | 474 | upvar expect_out expect_out |
c906108c | 475 | |
2307bd6a DJ |
476 | if { $message == "" } { |
477 | set message $command | |
c906108c | 478 | } |
c906108c | 479 | |
2307bd6a DJ |
480 | # TCL/EXPECT WART ALERT |
481 | # Expect does something very strange when it receives a single braced | |
482 | # argument. It splits it along word separators and performs substitutions. | |
483 | # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is | |
484 | # evaluated as "\[ab\]". But that's not how TCL normally works; inside a | |
485 | # double-quoted list item, "\[ab\]" is just a long way of representing | |
486 | # "[ab]", because the backslashes will be removed by lindex. | |
487 | ||
488 | # Unfortunately, there appears to be no easy way to duplicate the splitting | |
489 | # that expect will do from within TCL. And many places make use of the | |
490 | # "\[0-9\]" construct, so we need to support that; and some places make use | |
491 | # of the "[func]" construct, so we need to support that too. In order to | |
492 | # get this right we have to substitute quoted list elements differently | |
493 | # from braced list elements. | |
494 | ||
495 | # We do this roughly the same way that Expect does it. We have to use two | |
496 | # lists, because if we leave unquoted newlines in the argument to uplevel | |
497 | # they'll be treated as command separators, and if we escape newlines | |
498 | # we mangle newlines inside of command blocks. This assumes that the | |
499 | # input doesn't contain a pattern which contains actual embedded newlines | |
500 | # at this point! | |
501 | ||
502 | regsub -all {\n} ${user_code} { } subst_code | |
503 | set subst_code [uplevel list $subst_code] | |
504 | ||
505 | set processed_code "" | |
506 | set patterns "" | |
507 | set expecting_action 0 | |
508 | foreach item $user_code subst_item $subst_code { | |
509 | if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } { | |
510 | lappend processed_code $item | |
511 | continue | |
512 | } | |
513 | if {$item == "-indices" || $item == "-re" || $item == "-ex"} { | |
514 | lappend processed_code $item | |
515 | continue | |
516 | } | |
517 | if { $expecting_action } { | |
518 | lappend processed_code "uplevel [list $item]" | |
519 | set expecting_action 0 | |
520 | # Cosmetic, no effect on the list. | |
521 | append processed_code "\n" | |
522 | continue | |
523 | } | |
524 | set expecting_action 1 | |
525 | lappend processed_code $subst_item | |
526 | if {$patterns != ""} { | |
527 | append patterns "; " | |
528 | } | |
529 | append patterns "\"$subst_item\"" | |
c906108c SS |
530 | } |
531 | ||
2307bd6a DJ |
532 | # Also purely cosmetic. |
533 | regsub -all {\r} $patterns {\\r} patterns | |
534 | regsub -all {\n} $patterns {\\n} patterns | |
535 | ||
c906108c SS |
536 | if $verbose>2 then { |
537 | send_user "Sending \"$command\" to gdb\n" | |
2307bd6a | 538 | send_user "Looking to match \"$patterns\"\n" |
c906108c SS |
539 | send_user "Message is \"$message\"\n" |
540 | } | |
541 | ||
542 | set result -1 | |
543 | set string "${command}\n"; | |
544 | if { $command != "" } { | |
545 | while { "$string" != "" } { | |
546 | set foo [string first "\n" "$string"]; | |
547 | set len [string length "$string"]; | |
548 | if { $foo < [expr $len - 1] } { | |
549 | set str [string range "$string" 0 $foo]; | |
550 | if { [send_gdb "$str"] != "" } { | |
551 | global suppress_flag; | |
552 | ||
553 | if { ! $suppress_flag } { | |
554 | perror "Couldn't send $command to GDB."; | |
555 | } | |
556 | fail "$message"; | |
557 | return $result; | |
558 | } | |
a0b3c4fd JM |
559 | # since we're checking if each line of the multi-line |
560 | # command are 'accepted' by GDB here, | |
561 | # we need to set -notransfer expect option so that | |
562 | # command output is not lost for pattern matching | |
563 | # - guo | |
5f279fa6 DJ |
564 | gdb_expect 2 { |
565 | -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 } | |
566 | timeout { verbose "partial: timeout" 3 } | |
c906108c SS |
567 | } |
568 | set string [string range "$string" [expr $foo + 1] end]; | |
569 | } else { | |
570 | break; | |
571 | } | |
572 | } | |
573 | if { "$string" != "" } { | |
574 | if { [send_gdb "$string"] != "" } { | |
575 | global suppress_flag; | |
576 | ||
577 | if { ! $suppress_flag } { | |
578 | perror "Couldn't send $command to GDB."; | |
579 | } | |
580 | fail "$message"; | |
581 | return $result; | |
582 | } | |
583 | } | |
584 | } | |
585 | ||
9d2e1bab ND |
586 | if [target_info exists gdb,timeout] { |
587 | set tmt [target_info gdb,timeout]; | |
c906108c | 588 | } else { |
c906108c SS |
589 | if [info exists timeout] { |
590 | set tmt $timeout; | |
591 | } else { | |
9d2e1bab ND |
592 | global timeout; |
593 | if [info exists timeout] { | |
594 | set tmt $timeout; | |
595 | } else { | |
596 | set tmt 60; | |
597 | } | |
c906108c SS |
598 | } |
599 | } | |
2307bd6a DJ |
600 | |
601 | set code { | |
039cf96d AC |
602 | -re ".*A problem internal to GDB has been detected" { |
603 | fail "$message (GDB internal error)" | |
604 | gdb_internal_error_resync | |
605 | } | |
c906108c SS |
606 | -re "\\*\\*\\* DOSEXIT code.*" { |
607 | if { $message != "" } { | |
608 | fail "$message"; | |
609 | } | |
610 | gdb_suppress_entire_file "GDB died"; | |
2307bd6a | 611 | set result -1; |
c906108c | 612 | } |
9e0b60a8 | 613 | -re "Ending remote debugging.*$gdb_prompt $" { |
c906108c SS |
614 | if ![isnative] then { |
615 | warning "Can`t communicate to remote target." | |
616 | } | |
617 | gdb_exit | |
618 | gdb_start | |
619 | set result -1 | |
620 | } | |
2307bd6a DJ |
621 | } |
622 | append code $processed_code | |
623 | append code { | |
9e0b60a8 | 624 | -re "Undefined\[a-z\]* command:.*$gdb_prompt $" { |
c906108c | 625 | perror "Undefined command \"$command\"." |
9e0b60a8 | 626 | fail "$message" |
c906108c SS |
627 | set result 1 |
628 | } | |
629 | -re "Ambiguous command.*$gdb_prompt $" { | |
630 | perror "\"$command\" is not a unique command name." | |
9e0b60a8 | 631 | fail "$message" |
c906108c SS |
632 | set result 1 |
633 | } | |
634 | -re "Program exited with code \[0-9\]+.*$gdb_prompt $" { | |
635 | if ![string match "" $message] then { | |
ed4c619a | 636 | set errmsg "$message (the program exited)" |
c906108c | 637 | } else { |
ed4c619a | 638 | set errmsg "$command (the program exited)" |
c906108c SS |
639 | } |
640 | fail "$errmsg" | |
2307bd6a | 641 | set result -1 |
cb9a9d3e MS |
642 | } |
643 | -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" { | |
644 | if ![string match "" $message] then { | |
ed4c619a | 645 | set errmsg "$message (the program exited)" |
cb9a9d3e | 646 | } else { |
ed4c619a | 647 | set errmsg "$command (the program exited)" |
cb9a9d3e MS |
648 | } |
649 | fail "$errmsg" | |
2307bd6a | 650 | set result -1 |
c906108c SS |
651 | } |
652 | -re "The program is not being run.*$gdb_prompt $" { | |
653 | if ![string match "" $message] then { | |
ed4c619a | 654 | set errmsg "$message (the program is no longer running)" |
c906108c | 655 | } else { |
ed4c619a | 656 | set errmsg "$command (the program is no longer running)" |
c906108c SS |
657 | } |
658 | fail "$errmsg" | |
2307bd6a | 659 | set result -1 |
c906108c | 660 | } |
734b8fe8 | 661 | -re "\r\n$gdb_prompt $" { |
c906108c SS |
662 | if ![string match "" $message] then { |
663 | fail "$message" | |
664 | } | |
665 | set result 1 | |
666 | } | |
667 | "<return>" { | |
668 | send_gdb "\n" | |
669 | perror "Window too small." | |
9e0b60a8 | 670 | fail "$message" |
2307bd6a | 671 | set result -1 |
c906108c SS |
672 | } |
673 | -re "\\(y or n\\) " { | |
674 | send_gdb "n\n" | |
675 | perror "Got interactive prompt." | |
9e0b60a8 | 676 | fail "$message" |
2307bd6a | 677 | set result -1 |
c906108c SS |
678 | } |
679 | eof { | |
680 | perror "Process no longer exists" | |
681 | if { $message != "" } { | |
682 | fail "$message" | |
683 | } | |
684 | return -1 | |
685 | } | |
686 | full_buffer { | |
687 | perror "internal buffer is full." | |
9e0b60a8 | 688 | fail "$message" |
2307bd6a | 689 | set result -1 |
c906108c SS |
690 | } |
691 | timeout { | |
692 | if ![string match "" $message] then { | |
693 | fail "$message (timeout)" | |
694 | } | |
695 | set result 1 | |
696 | } | |
697 | } | |
2307bd6a DJ |
698 | |
699 | set result 0 | |
04f6ecf2 DJ |
700 | set code [catch {gdb_expect $tmt $code} string] |
701 | if {$code == 1} { | |
702 | global errorInfo errorCode; | |
703 | return -code error -errorinfo $errorInfo -errorcode $errorCode $string | |
704 | } elseif {$code == 2} { | |
705 | return -code return $string | |
706 | } elseif {$code == 3} { | |
707 | return | |
708 | } elseif {$code > 4} { | |
709 | return -code $code $string | |
710 | } | |
c906108c SS |
711 | return $result |
712 | } | |
2307bd6a DJ |
713 | |
714 | # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE | |
715 | # Send a command to gdb; test the result. | |
716 | # | |
717 | # COMMAND is the command to execute, send to GDB with send_gdb. If | |
718 | # this is the null string no command is sent. | |
719 | # PATTERN is the pattern to match for a PASS, and must NOT include | |
720 | # the \r\n sequence immediately before the gdb prompt. | |
721 | # MESSAGE is an optional message to be printed. If this is | |
722 | # omitted, then the pass/fail messages use the command string as the | |
723 | # message. (If this is the empty string, then sometimes we don't | |
724 | # call pass or fail at all; I don't understand this at all.) | |
725 | # QUESTION is a question GDB may ask in response to COMMAND, like | |
726 | # "are you sure?" | |
727 | # RESPONSE is the response to send if QUESTION appears. | |
728 | # | |
729 | # Returns: | |
730 | # 1 if the test failed, | |
731 | # 0 if the test passes, | |
732 | # -1 if there was an internal error. | |
733 | # | |
734 | proc gdb_test { args } { | |
735 | global verbose | |
736 | global gdb_prompt | |
737 | global GDB | |
738 | upvar timeout timeout | |
739 | ||
740 | if [llength $args]>2 then { | |
741 | set message [lindex $args 2] | |
742 | } else { | |
743 | set message [lindex $args 0] | |
744 | } | |
745 | set command [lindex $args 0] | |
746 | set pattern [lindex $args 1] | |
747 | ||
748 | if [llength $args]==5 { | |
749 | set question_string [lindex $args 3]; | |
750 | set response_string [lindex $args 4]; | |
751 | } else { | |
752 | set question_string "^FOOBAR$" | |
753 | } | |
754 | ||
755 | return [gdb_test_multiple $command $message { | |
756 | -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" { | |
757 | if ![string match "" $message] then { | |
758 | pass "$message" | |
759 | } | |
760 | } | |
761 | -re "(${question_string})$" { | |
762 | send_gdb "$response_string\n"; | |
763 | exp_continue; | |
764 | } | |
765 | }] | |
766 | } | |
c906108c SS |
767 | \f |
768 | # Test that a command gives an error. For pass or fail, return | |
769 | # a 1 to indicate that more tests can proceed. However a timeout | |
770 | # is a serious error, generates a special fail message, and causes | |
771 | # a 0 to be returned to indicate that more tests are likely to fail | |
772 | # as well. | |
773 | ||
774 | proc test_print_reject { args } { | |
775 | global gdb_prompt | |
776 | global verbose | |
777 | ||
778 | if [llength $args]==2 then { | |
779 | set expectthis [lindex $args 1] | |
780 | } else { | |
781 | set expectthis "should never match this bogus string" | |
782 | } | |
783 | set sendthis [lindex $args 0] | |
784 | if $verbose>2 then { | |
785 | send_user "Sending \"$sendthis\" to gdb\n" | |
786 | send_user "Looking to match \"$expectthis\"\n" | |
787 | } | |
788 | send_gdb "$sendthis\n" | |
789 | #FIXME: Should add timeout as parameter. | |
790 | gdb_expect { | |
791 | -re "A .* in expression.*\\.*$gdb_prompt $" { | |
792 | pass "reject $sendthis" | |
793 | return 1 | |
794 | } | |
795 | -re "Invalid syntax in expression.*$gdb_prompt $" { | |
796 | pass "reject $sendthis" | |
797 | return 1 | |
798 | } | |
799 | -re "Junk after end of expression.*$gdb_prompt $" { | |
800 | pass "reject $sendthis" | |
801 | return 1 | |
802 | } | |
803 | -re "Invalid number.*$gdb_prompt $" { | |
804 | pass "reject $sendthis" | |
805 | return 1 | |
806 | } | |
807 | -re "Invalid character constant.*$gdb_prompt $" { | |
808 | pass "reject $sendthis" | |
809 | return 1 | |
810 | } | |
811 | -re "No symbol table is loaded.*$gdb_prompt $" { | |
812 | pass "reject $sendthis" | |
813 | return 1 | |
814 | } | |
815 | -re "No symbol .* in current context.*$gdb_prompt $" { | |
816 | pass "reject $sendthis" | |
817 | return 1 | |
818 | } | |
c4b7bc2b JB |
819 | -re "Unmatched single quote.*$gdb_prompt $" { |
820 | pass "reject $sendthis" | |
821 | return 1 | |
822 | } | |
823 | -re "A character constant must contain at least one character.*$gdb_prompt $" { | |
824 | pass "reject $sendthis" | |
825 | return 1 | |
826 | } | |
c906108c SS |
827 | -re "$expectthis.*$gdb_prompt $" { |
828 | pass "reject $sendthis" | |
829 | return 1 | |
830 | } | |
831 | -re ".*$gdb_prompt $" { | |
832 | fail "reject $sendthis" | |
833 | return 1 | |
834 | } | |
835 | default { | |
836 | fail "reject $sendthis (eof or timeout)" | |
837 | return 0 | |
838 | } | |
839 | } | |
840 | } | |
841 | \f | |
842 | # Given an input string, adds backslashes as needed to create a | |
843 | # regexp that will match the string. | |
844 | ||
845 | proc string_to_regexp {str} { | |
846 | set result $str | |
847 | regsub -all {[]*+.|()^$\[]} $str {\\&} result | |
848 | return $result | |
849 | } | |
850 | ||
851 | # Same as gdb_test, but the second parameter is not a regexp, | |
852 | # but a string that must match exactly. | |
853 | ||
854 | proc gdb_test_exact { args } { | |
855 | upvar timeout timeout | |
856 | ||
857 | set command [lindex $args 0] | |
858 | ||
859 | # This applies a special meaning to a null string pattern. Without | |
860 | # this, "$pattern\r\n$gdb_prompt $" will match anything, including error | |
861 | # messages from commands that should have no output except a new | |
862 | # prompt. With this, only results of a null string will match a null | |
863 | # string pattern. | |
864 | ||
865 | set pattern [lindex $args 1] | |
866 | if [string match $pattern ""] { | |
867 | set pattern [string_to_regexp [lindex $args 0]] | |
868 | } else { | |
869 | set pattern [string_to_regexp [lindex $args 1]] | |
870 | } | |
871 | ||
872 | # It is most natural to write the pattern argument with only | |
873 | # embedded \n's, especially if you are trying to avoid Tcl quoting | |
874 | # problems. But gdb_expect really wants to see \r\n in patterns. So | |
875 | # transform the pattern here. First transform \r\n back to \n, in | |
876 | # case some users of gdb_test_exact already do the right thing. | |
877 | regsub -all "\r\n" $pattern "\n" pattern | |
878 | regsub -all "\n" $pattern "\r\n" pattern | |
879 | if [llength $args]==3 then { | |
880 | set message [lindex $args 2] | |
881 | } else { | |
882 | set message $command | |
883 | } | |
884 | ||
885 | return [gdb_test $command $pattern $message] | |
886 | } | |
887 | \f | |
888 | proc gdb_reinitialize_dir { subdir } { | |
889 | global gdb_prompt | |
890 | ||
891 | if [is_remote host] { | |
892 | return ""; | |
893 | } | |
894 | send_gdb "dir\n" | |
895 | gdb_expect 60 { | |
896 | -re "Reinitialize source path to empty.*y or n. " { | |
897 | send_gdb "y\n" | |
898 | gdb_expect 60 { | |
899 | -re "Source directories searched.*$gdb_prompt $" { | |
900 | send_gdb "dir $subdir\n" | |
901 | gdb_expect 60 { | |
902 | -re "Source directories searched.*$gdb_prompt $" { | |
903 | verbose "Dir set to $subdir" | |
904 | } | |
905 | -re "$gdb_prompt $" { | |
906 | perror "Dir \"$subdir\" failed." | |
907 | } | |
908 | } | |
909 | } | |
910 | -re "$gdb_prompt $" { | |
911 | perror "Dir \"$subdir\" failed." | |
912 | } | |
913 | } | |
914 | } | |
915 | -re "$gdb_prompt $" { | |
916 | perror "Dir \"$subdir\" failed." | |
917 | } | |
918 | } | |
919 | } | |
920 | ||
921 | # | |
922 | # gdb_exit -- exit the GDB, killing the target program if necessary | |
923 | # | |
924 | proc default_gdb_exit {} { | |
925 | global GDB | |
926 | global GDBFLAGS | |
927 | global verbose | |
928 | global gdb_spawn_id; | |
929 | ||
930 | gdb_stop_suppressing_tests; | |
931 | ||
932 | if ![info exists gdb_spawn_id] { | |
933 | return; | |
934 | } | |
935 | ||
936 | verbose "Quitting $GDB $GDBFLAGS" | |
937 | ||
938 | if { [is_remote host] && [board_info host exists fileid] } { | |
939 | send_gdb "quit\n"; | |
940 | gdb_expect 10 { | |
941 | -re "y or n" { | |
942 | send_gdb "y\n"; | |
943 | exp_continue; | |
944 | } | |
945 | -re "DOSEXIT code" { } | |
946 | default { } | |
947 | } | |
948 | } | |
949 | ||
950 | if ![is_remote host] { | |
951 | remote_close host; | |
952 | } | |
953 | unset gdb_spawn_id | |
954 | } | |
955 | ||
3e3ffd2b | 956 | # Load a file into the debugger. |
2db8e78e | 957 | # The return value is 0 for success, -1 for failure. |
c906108c | 958 | # |
2db8e78e MC |
959 | # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO |
960 | # to one of these values: | |
3e3ffd2b | 961 | # |
2db8e78e MC |
962 | # debug file was loaded successfully and has debug information |
963 | # nodebug file was loaded successfully and has no debug information | |
964 | # fail file was not loaded | |
c906108c | 965 | # |
2db8e78e MC |
966 | # I tried returning this information as part of the return value, |
967 | # but ran into a mess because of the many re-implementations of | |
968 | # gdb_load in config/*.exp. | |
3e3ffd2b | 969 | # |
2db8e78e MC |
970 | # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use |
971 | # this if they can get more information set. | |
3e3ffd2b | 972 | |
c906108c | 973 | proc gdb_file_cmd { arg } { |
3e3ffd2b | 974 | global gdb_prompt |
c906108c | 975 | global verbose |
c906108c | 976 | global GDB |
c906108c | 977 | |
2db8e78e MC |
978 | # Set whether debug info was found. |
979 | # Default to "fail". | |
980 | global gdb_file_cmd_debug_info | |
981 | set gdb_file_cmd_debug_info "fail" | |
982 | ||
c906108c | 983 | if [is_remote host] { |
3e3ffd2b | 984 | set arg [remote_download host $arg] |
c906108c | 985 | if { $arg == "" } { |
2db8e78e MC |
986 | perror "download failed" |
987 | return -1 | |
c906108c SS |
988 | } |
989 | } | |
990 | ||
991 | send_gdb "file $arg\n" | |
992 | gdb_expect 120 { | |
3e3ffd2b MC |
993 | -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" { |
994 | verbose "\t\tLoaded $arg into the $GDB with no debugging symbols" | |
2db8e78e MC |
995 | set gdb_file_cmd_debug_info "nodebug" |
996 | return 0 | |
3e3ffd2b | 997 | } |
c906108c SS |
998 | -re "Reading symbols from.*done.*$gdb_prompt $" { |
999 | verbose "\t\tLoaded $arg into the $GDB" | |
2db8e78e MC |
1000 | set gdb_file_cmd_debug_info "debug" |
1001 | return 0 | |
c906108c SS |
1002 | } |
1003 | -re "A program is being debugged already.*Kill it.*y or n. $" { | |
1004 | send_gdb "y\n" | |
2db8e78e | 1005 | verbose "\t\tKilling previous program being debugged" |
c906108c SS |
1006 | exp_continue |
1007 | } | |
1008 | -re "Load new symbol table from \".*\".*y or n. $" { | |
1009 | send_gdb "y\n" | |
1010 | gdb_expect 120 { | |
1011 | -re "Reading symbols from.*done.*$gdb_prompt $" { | |
1012 | verbose "\t\tLoaded $arg with new symbol table into $GDB" | |
2db8e78e MC |
1013 | set gdb_file_cmd_debug_info "debug" |
1014 | return 0 | |
c906108c SS |
1015 | } |
1016 | timeout { | |
2db8e78e MC |
1017 | perror "(timeout) Couldn't load $arg, other program already loaded." |
1018 | return -1 | |
c906108c SS |
1019 | } |
1020 | } | |
1021 | } | |
1022 | -re "No such file or directory.*$gdb_prompt $" { | |
2db8e78e MC |
1023 | perror "($arg) No such file or directory" |
1024 | return -1 | |
c906108c SS |
1025 | } |
1026 | -re "$gdb_prompt $" { | |
2db8e78e MC |
1027 | perror "couldn't load $arg into $GDB." |
1028 | return -1 | |
c906108c SS |
1029 | } |
1030 | timeout { | |
2db8e78e MC |
1031 | perror "couldn't load $arg into $GDB (timed out)." |
1032 | return -1 | |
c906108c SS |
1033 | } |
1034 | eof { | |
1035 | # This is an attempt to detect a core dump, but seems not to | |
1036 | # work. Perhaps we need to match .* followed by eof, in which | |
1037 | # gdb_expect does not seem to have a way to do that. | |
2db8e78e MC |
1038 | perror "couldn't load $arg into $GDB (end of file)." |
1039 | return -1 | |
c906108c SS |
1040 | } |
1041 | } | |
1042 | } | |
1043 | ||
1044 | # | |
1045 | # start gdb -- start gdb running, default procedure | |
1046 | # | |
1047 | # When running over NFS, particularly if running many simultaneous | |
1048 | # tests on different hosts all using the same server, things can | |
1049 | # get really slow. Give gdb at least 3 minutes to start up. | |
1050 | # | |
1051 | proc default_gdb_start { } { | |
1052 | global verbose | |
1053 | global GDB | |
1054 | global GDBFLAGS | |
1055 | global gdb_prompt | |
1056 | global timeout | |
1057 | global gdb_spawn_id; | |
1058 | ||
1059 | gdb_stop_suppressing_tests; | |
1060 | ||
1061 | verbose "Spawning $GDB -nw $GDBFLAGS" | |
1062 | ||
1063 | if [info exists gdb_spawn_id] { | |
1064 | return 0; | |
1065 | } | |
1066 | ||
1067 | if ![is_remote host] { | |
1068 | if { [which $GDB] == 0 } then { | |
1069 | perror "$GDB does not exist." | |
1070 | exit 1 | |
1071 | } | |
1072 | } | |
1073 | set res [remote_spawn host "$GDB -nw $GDBFLAGS [host_info gdb_opts]"]; | |
1074 | if { $res < 0 || $res == "" } { | |
1075 | perror "Spawning $GDB failed." | |
1076 | return 1; | |
1077 | } | |
1078 | gdb_expect 360 { | |
1079 | -re "\[\r\n\]$gdb_prompt $" { | |
1080 | verbose "GDB initialized." | |
1081 | } | |
1082 | -re "$gdb_prompt $" { | |
1083 | perror "GDB never initialized." | |
1084 | return -1 | |
1085 | } | |
1086 | timeout { | |
1087 | perror "(timeout) GDB never initialized after 10 seconds." | |
1088 | remote_close host; | |
1089 | return -1 | |
1090 | } | |
1091 | } | |
1092 | set gdb_spawn_id -1; | |
1093 | # force the height to "unlimited", so no pagers get used | |
1094 | ||
1095 | send_gdb "set height 0\n" | |
1096 | gdb_expect 10 { | |
1097 | -re "$gdb_prompt $" { | |
1098 | verbose "Setting height to 0." 2 | |
1099 | } | |
1100 | timeout { | |
1101 | warning "Couldn't set the height to 0" | |
1102 | } | |
1103 | } | |
1104 | # force the width to "unlimited", so no wraparound occurs | |
1105 | send_gdb "set width 0\n" | |
1106 | gdb_expect 10 { | |
1107 | -re "$gdb_prompt $" { | |
1108 | verbose "Setting width to 0." 2 | |
1109 | } | |
1110 | timeout { | |
1111 | warning "Couldn't set the width to 0." | |
1112 | } | |
1113 | } | |
1114 | return 0; | |
1115 | } | |
1116 | ||
d4f3574e SS |
1117 | # Return a 1 for configurations for which we don't even want to try to |
1118 | # test C++. | |
1119 | ||
1120 | proc skip_cplus_tests {} { | |
1121 | if { [istarget "d10v-*-*"] } { | |
1122 | return 1 | |
1123 | } | |
1124 | if { [istarget "h8300-*-*"] } { | |
1125 | return 1 | |
1126 | } | |
1146c7f1 SC |
1127 | |
1128 | # The C++ IO streams are too large for HC11/HC12 and are thus not | |
1129 | # available. The gdb C++ tests use them and don't compile. | |
1130 | if { [istarget "m6811-*-*"] } { | |
1131 | return 1 | |
1132 | } | |
1133 | if { [istarget "m6812-*-*"] } { | |
1134 | return 1 | |
1135 | } | |
d4f3574e SS |
1136 | return 0 |
1137 | } | |
1138 | ||
89a237cb MC |
1139 | # Return a 1 if I don't even want to try to test FORTRAN. |
1140 | ||
1141 | proc skip_fortran_tests {} { | |
1142 | return 0 | |
1143 | } | |
1144 | ||
7a292a7a SS |
1145 | # Skip all the tests in the file if you are not on an hppa running |
1146 | # hpux target. | |
1147 | ||
1148 | proc skip_hp_tests {} { | |
1149 | eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ] | |
c906108c SS |
1150 | verbose "Skip hp tests is $skip_hp" |
1151 | return $skip_hp | |
1152 | } | |
1153 | ||
94b8e876 MC |
1154 | set compiler_info "unknown" |
1155 | set gcc_compiled 0 | |
1156 | set hp_cc_compiler 0 | |
1157 | set hp_aCC_compiler 0 | |
94b8e876 MC |
1158 | |
1159 | # Figure out what compiler I am using. | |
1160 | # | |
1161 | # BINFILE is a "compiler information" output file. This implementation | |
1162 | # does not use BINFILE. | |
1163 | # | |
1164 | # ARGS can be empty or "C++". If empty, "C" is assumed. | |
1165 | # | |
1166 | # There are several ways to do this, with various problems. | |
1167 | # | |
1168 | # [ gdb_compile -E $ifile -o $binfile.ci ] | |
1169 | # source $binfile.ci | |
1170 | # | |
1171 | # Single Unix Spec v3 says that "-E -o ..." together are not | |
1172 | # specified. And in fact, the native compiler on hp-ux 11 (among | |
1173 | # others) does not work with "-E -o ...". Most targets used to do | |
1174 | # this, and it mostly worked, because it works with gcc. | |
1175 | # | |
1176 | # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ] | |
1177 | # source $binfile.ci | |
1178 | # | |
1179 | # This avoids the problem with -E and -o together. This almost works | |
1180 | # if the build machine is the same as the host machine, which is | |
1181 | # usually true of the targets which are not gcc. But this code does | |
1182 | # not figure which compiler to call, and it always ends up using the C | |
1183 | # compiler. Not good for setting hp_aCC_compiler. Targets | |
1184 | # hppa*-*-hpux* and mips*-*-irix* used to do this. | |
1185 | # | |
1186 | # [ gdb_compile -E $ifile > $binfile.ci ] | |
1187 | # source $binfile.ci | |
1188 | # | |
1189 | # dejagnu target_compile says that it supports output redirection, | |
1190 | # but the code is completely different from the normal path and I | |
1191 | # don't want to sweep the mines from that path. So I didn't even try | |
1192 | # this. | |
1193 | # | |
1194 | # set cppout [ gdb_compile $ifile "" preprocess $args quiet ] | |
1195 | # eval $cppout | |
1196 | # | |
1197 | # I actually do this for all targets now. gdb_compile runs the right | |
1198 | # compiler, and TCL captures the output, and I eval the output. | |
1199 | # | |
1200 | # Unfortunately, expect logs the output of the command as it goes by, | |
1201 | # and dejagnu helpfully prints a second copy of it right afterwards. | |
1202 | # So I turn off expect logging for a moment. | |
1203 | # | |
1204 | # [ gdb_compile $ifile $ciexe_file executable $args ] | |
1205 | # [ remote_exec $ciexe_file ] | |
1206 | # [ source $ci_file.out ] | |
1207 | # | |
1208 | # I could give up on -E and just do this. | |
1209 | # I didn't get desperate enough to try this. | |
1210 | # | |
1211 | # -- chastain 2004-01-06 | |
853d6e5b | 1212 | |
c906108c | 1213 | proc get_compiler_info {binfile args} { |
94b8e876 | 1214 | # For compiler.c and compiler.cc |
c906108c | 1215 | global srcdir |
94b8e876 MC |
1216 | |
1217 | # I am going to play with the log to keep noise out. | |
1218 | global outdir | |
1219 | global tool | |
1220 | ||
1221 | # These come from compiler.c or compiler.cc | |
853d6e5b | 1222 | global compiler_info |
4f70a4c9 MC |
1223 | |
1224 | # Legacy global data symbols. | |
94b8e876 MC |
1225 | global gcc_compiled |
1226 | global hp_cc_compiler | |
1227 | global hp_aCC_compiler | |
c906108c | 1228 | |
94b8e876 MC |
1229 | # Choose which file to preprocess. |
1230 | set ifile "${srcdir}/lib/compiler.c" | |
1231 | if { [llength $args] > 0 && [lindex $args 0] == "c++" } { | |
1232 | set ifile "${srcdir}/lib/compiler.cc" | |
c906108c | 1233 | } |
085dd6e6 | 1234 | |
94b8e876 MC |
1235 | # Run $ifile through the right preprocessor. |
1236 | # Toggle gdb.log to keep the compiler output out of the log. | |
1237 | log_file | |
1238 | set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ] | |
1239 | log_file -a "$outdir/$tool.log" | |
1240 | ||
4f70a4c9 MC |
1241 | # Eval the output. |
1242 | set unknown 0 | |
94b8e876 | 1243 | foreach cppline [ split "$cppout" "\n" ] { |
4f70a4c9 MC |
1244 | if { [ regexp "^#" "$cppline" ] } { |
1245 | # line marker | |
1246 | } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } { | |
1247 | # blank line | |
1248 | } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } { | |
1249 | # eval this line | |
1250 | verbose "get_compiler_info: $cppline" 2 | |
1251 | eval "$cppline" | |
1252 | } else { | |
1253 | # unknown line | |
1254 | verbose -log "get_compiler_info: $cppline" | |
1255 | set unknown 1 | |
94b8e876 | 1256 | } |
085dd6e6 | 1257 | } |
4f70a4c9 MC |
1258 | |
1259 | # Reset to unknown compiler if any diagnostics happened. | |
1260 | if { $unknown } { | |
1261 | set compiler_info "unknown" | |
4f70a4c9 MC |
1262 | } |
1263 | ||
1264 | # Set the legacy symbols. | |
1265 | set gcc_compiled 0 | |
1266 | set hp_cc_compiler 0 | |
1267 | set hp_aCC_compiler 0 | |
1268 | if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 } | |
1269 | if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 } | |
1270 | if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 } | |
1271 | if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 } | |
1272 | if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 } | |
1273 | if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 } | |
1274 | if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 } | |
1275 | ||
1276 | # Log what happened. | |
94b8e876 | 1277 | verbose -log "get_compiler_info: $compiler_info" |
085dd6e6 JM |
1278 | |
1279 | # Most compilers will evaluate comparisons and other boolean | |
1280 | # operations to 0 or 1. | |
1281 | uplevel \#0 { set true 1 } | |
1282 | uplevel \#0 { set false 0 } | |
1283 | ||
94b8e876 MC |
1284 | # Use of aCC results in boolean results being displayed as |
1285 | # "true" or "false" | |
1286 | if { $hp_aCC_compiler } { | |
1287 | uplevel \#0 { set true true } | |
1288 | uplevel \#0 { set false false } | |
085dd6e6 JM |
1289 | } |
1290 | ||
c906108c SS |
1291 | return 0; |
1292 | } | |
1293 | ||
9b593790 | 1294 | proc test_compiler_info { {compiler ""} } { |
853d6e5b | 1295 | global compiler_info |
6e87504d PG |
1296 | |
1297 | # if no arg, return the compiler_info string | |
1298 | ||
1299 | if [string match "" $compiler] { | |
1300 | if [info exists compiler_info] { | |
1301 | return $compiler_info | |
1302 | } else { | |
1303 | perror "No compiler info found." | |
1304 | } | |
1305 | } | |
1306 | ||
853d6e5b AC |
1307 | return [string match $compiler $compiler_info] |
1308 | } | |
1309 | ||
f1c47eb2 MS |
1310 | set gdb_wrapper_initialized 0 |
1311 | ||
1312 | proc gdb_wrapper_init { args } { | |
1313 | global gdb_wrapper_initialized; | |
1314 | global gdb_wrapper_file; | |
1315 | global gdb_wrapper_flags; | |
1316 | ||
1317 | if { $gdb_wrapper_initialized == 1 } { return; } | |
1318 | ||
1319 | if {[target_info exists needs_status_wrapper] && \ | |
277254ba | 1320 | [target_info needs_status_wrapper] != "0"} { |
f1c47eb2 MS |
1321 | set result [build_wrapper "testglue.o"]; |
1322 | if { $result != "" } { | |
1323 | set gdb_wrapper_file [lindex $result 0]; | |
1324 | set gdb_wrapper_flags [lindex $result 1]; | |
1325 | } else { | |
1326 | warning "Status wrapper failed to build." | |
1327 | } | |
1328 | } | |
1329 | set gdb_wrapper_initialized 1 | |
1330 | } | |
1331 | ||
c906108c SS |
1332 | proc gdb_compile {source dest type options} { |
1333 | global GDB_TESTCASE_OPTIONS; | |
f1c47eb2 MS |
1334 | global gdb_wrapper_file; |
1335 | global gdb_wrapper_flags; | |
1336 | global gdb_wrapper_initialized; | |
c906108c SS |
1337 | |
1338 | if [target_info exists gdb_stub] { | |
1339 | set options2 { "additional_flags=-Dusestubs" } | |
1340 | lappend options "libs=[target_info gdb_stub]"; | |
1341 | set options [concat $options2 $options] | |
1342 | } | |
1343 | if [target_info exists is_vxworks] { | |
1344 | set options2 { "additional_flags=-Dvxworks" } | |
1345 | lappend options "libs=[target_info gdb_stub]"; | |
1346 | set options [concat $options2 $options] | |
1347 | } | |
1348 | if [info exists GDB_TESTCASE_OPTIONS] { | |
1349 | lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"; | |
1350 | } | |
1351 | verbose "options are $options" | |
1352 | verbose "source is $source $dest $type $options" | |
1353 | ||
f1c47eb2 MS |
1354 | if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init } |
1355 | ||
1356 | if {[target_info exists needs_status_wrapper] && \ | |
1357 | [target_info needs_status_wrapper] != "0" && \ | |
1358 | [info exists gdb_wrapper_file]} { | |
1359 | lappend options "libs=${gdb_wrapper_file}" | |
1360 | lappend options "ldflags=${gdb_wrapper_flags}" | |
1361 | } | |
1362 | ||
c906108c SS |
1363 | set result [target_compile $source $dest $type $options]; |
1364 | regsub "\[\r\n\]*$" "$result" "" result; | |
1365 | regsub "^\[\r\n\]*" "$result" "" result; | |
b5ab8ff3 | 1366 | if { $result != "" && [lsearch $options quiet] == -1} { |
c906108c SS |
1367 | clone_output "gdb compile failed, $result" |
1368 | } | |
1369 | return $result; | |
1370 | } | |
1371 | ||
b6ff0e81 JB |
1372 | |
1373 | # This is just like gdb_compile, above, except that it tries compiling | |
1374 | # against several different thread libraries, to see which one this | |
1375 | # system has. | |
1376 | proc gdb_compile_pthreads {source dest type options} { | |
0ae67eb3 | 1377 | set built_binfile 0 |
b6ff0e81 JB |
1378 | set why_msg "unrecognized error" |
1379 | foreach lib {-lpthreads -lpthread -lthread} { | |
1380 | # This kind of wipes out whatever libs the caller may have | |
1381 | # set. Or maybe theirs will override ours. How infelicitous. | |
b5ab8ff3 | 1382 | set options_with_lib [concat $options [list libs=$lib quiet]] |
b6ff0e81 JB |
1383 | set ccout [gdb_compile $source $dest $type $options_with_lib] |
1384 | switch -regexp -- $ccout { | |
1385 | ".*no posix threads support.*" { | |
1386 | set why_msg "missing threads include file" | |
1387 | break | |
1388 | } | |
1389 | ".*cannot open -lpthread.*" { | |
1390 | set why_msg "missing runtime threads library" | |
1391 | } | |
1392 | ".*Can't find library for -lpthread.*" { | |
1393 | set why_msg "missing runtime threads library" | |
1394 | } | |
1395 | {^$} { | |
1396 | pass "successfully compiled posix threads test case" | |
1397 | set built_binfile 1 | |
1398 | break | |
1399 | } | |
1400 | } | |
1401 | } | |
0ae67eb3 | 1402 | if {!$built_binfile} { |
b6ff0e81 JB |
1403 | unsupported "Couldn't compile $source: ${why_msg}" |
1404 | return -1 | |
1405 | } | |
1406 | } | |
1407 | ||
130cacce AF |
1408 | # This is just like gdb_compile_pthreads, above, except that we always add the |
1409 | # objc library for compiling Objective-C programs | |
1410 | proc gdb_compile_objc {source dest type options} { | |
1411 | set built_binfile 0 | |
1412 | set why_msg "unrecognized error" | |
1413 | foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} { | |
1414 | # This kind of wipes out whatever libs the caller may have | |
1415 | # set. Or maybe theirs will override ours. How infelicitous. | |
1416 | if { $lib == "solaris" } { | |
1417 | set lib "-lpthread -lposix4" | |
1418 | } | |
1419 | if { $lib != "-lobjc" } { | |
1420 | set lib "-lobjc $lib" | |
1421 | } | |
1422 | set options_with_lib [concat $options [list libs=$lib quiet]] | |
1423 | set ccout [gdb_compile $source $dest $type $options_with_lib] | |
1424 | switch -regexp -- $ccout { | |
1425 | ".*no posix threads support.*" { | |
1426 | set why_msg "missing threads include file" | |
1427 | break | |
1428 | } | |
1429 | ".*cannot open -lpthread.*" { | |
1430 | set why_msg "missing runtime threads library" | |
1431 | } | |
1432 | ".*Can't find library for -lpthread.*" { | |
1433 | set why_msg "missing runtime threads library" | |
1434 | } | |
1435 | {^$} { | |
1436 | pass "successfully compiled objc with posix threads test case" | |
1437 | set built_binfile 1 | |
1438 | break | |
1439 | } | |
1440 | } | |
1441 | } | |
1442 | if {!$built_binfile} { | |
1443 | unsupported "Couldn't compile $source: ${why_msg}" | |
1444 | return -1 | |
1445 | } | |
1446 | } | |
1447 | ||
c906108c SS |
1448 | proc send_gdb { string } { |
1449 | global suppress_flag; | |
1450 | if { $suppress_flag } { | |
1451 | return "suppressed"; | |
1452 | } | |
1453 | return [remote_send host "$string"]; | |
1454 | } | |
1455 | ||
1456 | # | |
1457 | # | |
1458 | ||
1459 | proc gdb_expect { args } { | |
1460 | if { [llength $args] == 2 && [lindex $args 0] != "-re" } { | |
1461 | set gtimeout [lindex $args 0]; | |
1462 | set expcode [list [lindex $args 1]]; | |
1463 | } else { | |
1464 | upvar timeout timeout; | |
1465 | ||
1466 | set expcode $args; | |
1467 | if [target_info exists gdb,timeout] { | |
1468 | if [info exists timeout] { | |
1469 | if { $timeout < [target_info gdb,timeout] } { | |
1470 | set gtimeout [target_info gdb,timeout]; | |
1471 | } else { | |
1472 | set gtimeout $timeout; | |
1473 | } | |
1474 | } else { | |
1475 | set gtimeout [target_info gdb,timeout]; | |
1476 | } | |
1477 | } | |
1478 | ||
1479 | if ![info exists gtimeout] { | |
1480 | global timeout; | |
1481 | if [info exists timeout] { | |
1482 | set gtimeout $timeout; | |
1483 | } else { | |
1484 | # Eeeeew. | |
1485 | set gtimeout 60; | |
1486 | } | |
1487 | } | |
1488 | } | |
1489 | global suppress_flag; | |
1490 | global remote_suppress_flag; | |
1491 | if [info exists remote_suppress_flag] { | |
1492 | set old_val $remote_suppress_flag; | |
1493 | } | |
1494 | if [info exists suppress_flag] { | |
1495 | if { $suppress_flag } { | |
1496 | set remote_suppress_flag 1; | |
1497 | } | |
1498 | } | |
a0b3c4fd | 1499 | set code [catch \ |
5f279fa6 | 1500 | {uplevel remote_expect host $gtimeout $expcode} string]; |
c906108c SS |
1501 | if [info exists old_val] { |
1502 | set remote_suppress_flag $old_val; | |
1503 | } else { | |
1504 | if [info exists remote_suppress_flag] { | |
1505 | unset remote_suppress_flag; | |
1506 | } | |
1507 | } | |
1508 | ||
1509 | if {$code == 1} { | |
1510 | global errorInfo errorCode; | |
1511 | ||
1512 | return -code error -errorinfo $errorInfo -errorcode $errorCode $string | |
1513 | } elseif {$code == 2} { | |
1514 | return -code return $string | |
1515 | } elseif {$code == 3} { | |
1516 | return | |
1517 | } elseif {$code > 4} { | |
1518 | return -code $code $string | |
1519 | } | |
1520 | } | |
1521 | ||
c2d11a7d | 1522 | # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs |
085dd6e6 JM |
1523 | # |
1524 | # Check for long sequence of output by parts. | |
11cf8741 | 1525 | # MESSAGE: is the test message to be printed with the test success/fail. |
085dd6e6 JM |
1526 | # SENTINEL: Is the terminal pattern indicating that output has finished. |
1527 | # LIST: is the sequence of outputs to match. | |
1528 | # If the sentinel is recognized early, it is considered an error. | |
1529 | # | |
11cf8741 JM |
1530 | # Returns: |
1531 | # 1 if the test failed, | |
1532 | # 0 if the test passes, | |
1533 | # -1 if there was an internal error. | |
1534 | # | |
c2d11a7d | 1535 | proc gdb_expect_list {test sentinel list} { |
085dd6e6 | 1536 | global gdb_prompt |
11cf8741 | 1537 | global suppress_flag |
085dd6e6 | 1538 | set index 0 |
43ff13b4 | 1539 | set ok 1 |
11cf8741 JM |
1540 | if { $suppress_flag } { |
1541 | set ok 0 | |
a20ce2c3 | 1542 | unresolved "${test}" |
11cf8741 | 1543 | } |
43ff13b4 | 1544 | while { ${index} < [llength ${list}] } { |
085dd6e6 JM |
1545 | set pattern [lindex ${list} ${index}] |
1546 | set index [expr ${index} + 1] | |
1547 | if { ${index} == [llength ${list}] } { | |
43ff13b4 JM |
1548 | if { ${ok} } { |
1549 | gdb_expect { | |
c2d11a7d | 1550 | -re "${pattern}${sentinel}" { |
a20ce2c3 | 1551 | # pass "${test}, pattern ${index} + sentinel" |
c2d11a7d JM |
1552 | } |
1553 | -re "${sentinel}" { | |
a20ce2c3 | 1554 | fail "${test} (pattern ${index} + sentinel)" |
c2d11a7d | 1555 | set ok 0 |
43ff13b4 | 1556 | } |
5c5455dc AC |
1557 | -re ".*A problem internal to GDB has been detected" { |
1558 | fail "${test} (GDB internal error)" | |
1559 | set ok 0 | |
1560 | gdb_internal_error_resync | |
1561 | } | |
43ff13b4 | 1562 | timeout { |
a20ce2c3 | 1563 | fail "${test} (pattern ${index} + sentinel) (timeout)" |
43ff13b4 JM |
1564 | set ok 0 |
1565 | } | |
085dd6e6 | 1566 | } |
43ff13b4 | 1567 | } else { |
a20ce2c3 | 1568 | # unresolved "${test}, pattern ${index} + sentinel" |
085dd6e6 JM |
1569 | } |
1570 | } else { | |
43ff13b4 JM |
1571 | if { ${ok} } { |
1572 | gdb_expect { | |
1573 | -re "${pattern}" { | |
a20ce2c3 | 1574 | # pass "${test}, pattern ${index}" |
43ff13b4 | 1575 | } |
c2d11a7d | 1576 | -re "${sentinel}" { |
a20ce2c3 | 1577 | fail "${test} (pattern ${index})" |
43ff13b4 JM |
1578 | set ok 0 |
1579 | } | |
5c5455dc AC |
1580 | -re ".*A problem internal to GDB has been detected" { |
1581 | fail "${test} (GDB internal error)" | |
1582 | set ok 0 | |
1583 | gdb_internal_error_resync | |
1584 | } | |
43ff13b4 | 1585 | timeout { |
a20ce2c3 | 1586 | fail "${test} (pattern ${index}) (timeout)" |
43ff13b4 JM |
1587 | set ok 0 |
1588 | } | |
085dd6e6 | 1589 | } |
43ff13b4 | 1590 | } else { |
a20ce2c3 | 1591 | # unresolved "${test}, pattern ${index}" |
085dd6e6 JM |
1592 | } |
1593 | } | |
1594 | } | |
11cf8741 | 1595 | if { ${ok} } { |
a20ce2c3 | 1596 | pass "${test}" |
11cf8741 JM |
1597 | return 0 |
1598 | } else { | |
1599 | return 1 | |
1600 | } | |
085dd6e6 JM |
1601 | } |
1602 | ||
1603 | # | |
1604 | # | |
c906108c SS |
1605 | proc gdb_suppress_entire_file { reason } { |
1606 | global suppress_flag; | |
1607 | ||
1608 | warning "$reason\n"; | |
1609 | set suppress_flag -1; | |
1610 | } | |
1611 | ||
1612 | # | |
1613 | # Set suppress_flag, which will cause all subsequent calls to send_gdb and | |
1614 | # gdb_expect to fail immediately (until the next call to | |
1615 | # gdb_stop_suppressing_tests). | |
1616 | # | |
1617 | proc gdb_suppress_tests { args } { | |
1618 | global suppress_flag; | |
1619 | ||
1620 | return; # fnf - disable pending review of results where | |
1621 | # testsuite ran better without this | |
1622 | incr suppress_flag; | |
1623 | ||
1624 | if { $suppress_flag == 1 } { | |
1625 | if { [llength $args] > 0 } { | |
1626 | warning "[lindex $args 0]\n"; | |
1627 | } else { | |
1628 | warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n"; | |
1629 | } | |
1630 | } | |
1631 | } | |
1632 | ||
1633 | # | |
1634 | # Clear suppress_flag. | |
1635 | # | |
1636 | proc gdb_stop_suppressing_tests { } { | |
1637 | global suppress_flag; | |
1638 | ||
1639 | if [info exists suppress_flag] { | |
1640 | if { $suppress_flag > 0 } { | |
1641 | set suppress_flag 0; | |
1642 | clone_output "Tests restarted.\n"; | |
1643 | } | |
1644 | } else { | |
1645 | set suppress_flag 0; | |
1646 | } | |
1647 | } | |
1648 | ||
1649 | proc gdb_clear_suppressed { } { | |
1650 | global suppress_flag; | |
1651 | ||
1652 | set suppress_flag 0; | |
1653 | } | |
1654 | ||
1655 | proc gdb_start { } { | |
1656 | default_gdb_start | |
1657 | } | |
1658 | ||
1659 | proc gdb_exit { } { | |
1660 | catch default_gdb_exit | |
1661 | } | |
1662 | ||
1663 | # | |
1664 | # gdb_load -- load a file into the debugger. | |
2db8e78e | 1665 | # Many files in config/*.exp override this procedure. |
c906108c SS |
1666 | # |
1667 | proc gdb_load { arg } { | |
1668 | return [gdb_file_cmd $arg] | |
1669 | } | |
1670 | ||
1671 | proc gdb_continue { function } { | |
1672 | global decimal | |
1673 | ||
1674 | return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]; | |
1675 | } | |
1676 | ||
1677 | proc default_gdb_init { args } { | |
277254ba MS |
1678 | global gdb_wrapper_initialized |
1679 | ||
c906108c SS |
1680 | gdb_clear_suppressed; |
1681 | ||
277254ba MS |
1682 | # Make sure that the wrapper is rebuilt |
1683 | # with the appropriate multilib option. | |
1684 | set gdb_wrapper_initialized 0 | |
1685 | ||
c906108c SS |
1686 | # Uh, this is lame. Really, really, really lame. But there's this *one* |
1687 | # testcase that will fail in random places if we don't increase this. | |
1688 | match_max -d 20000 | |
1689 | ||
1690 | # We want to add the name of the TCL testcase to the PASS/FAIL messages. | |
1691 | if { [llength $args] > 0 } { | |
1692 | global pf_prefix | |
1693 | ||
1694 | set file [lindex $args 0]; | |
1695 | ||
1696 | set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:"; | |
1697 | } | |
1698 | global gdb_prompt; | |
1699 | if [target_info exists gdb_prompt] { | |
1700 | set gdb_prompt [target_info gdb_prompt]; | |
1701 | } else { | |
1702 | set gdb_prompt "\\(gdb\\)" | |
1703 | } | |
1704 | } | |
1705 | ||
1706 | proc gdb_init { args } { | |
1707 | return [eval default_gdb_init $args]; | |
1708 | } | |
1709 | ||
1710 | proc gdb_finish { } { | |
1711 | gdb_exit; | |
1712 | } | |
1713 | ||
1714 | global debug_format | |
7a292a7a | 1715 | set debug_format "unknown" |
c906108c SS |
1716 | |
1717 | # Run the gdb command "info source" and extract the debugging format | |
1718 | # information from the output and save it in debug_format. | |
1719 | ||
1720 | proc get_debug_format { } { | |
1721 | global gdb_prompt | |
1722 | global verbose | |
1723 | global expect_out | |
1724 | global debug_format | |
1725 | ||
1726 | set debug_format "unknown" | |
1727 | send_gdb "info source\n" | |
1728 | gdb_expect 10 { | |
919d772c | 1729 | -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" { |
c906108c SS |
1730 | set debug_format $expect_out(1,string) |
1731 | verbose "debug format is $debug_format" | |
1732 | return 1; | |
1733 | } | |
1734 | -re "No current source file.\r\n$gdb_prompt $" { | |
1735 | perror "get_debug_format used when no current source file" | |
1736 | return 0; | |
1737 | } | |
1738 | -re "$gdb_prompt $" { | |
1739 | warning "couldn't check debug format (no valid response)." | |
1740 | return 1; | |
1741 | } | |
1742 | timeout { | |
1743 | warning "couldn't check debug format (timed out)." | |
1744 | return 1; | |
1745 | } | |
1746 | } | |
1747 | } | |
1748 | ||
838ae6c4 JB |
1749 | # Return true if FORMAT matches the debug format the current test was |
1750 | # compiled with. FORMAT is a shell-style globbing pattern; it can use | |
1751 | # `*', `[...]', and so on. | |
1752 | # | |
1753 | # This function depends on variables set by `get_debug_format', above. | |
1754 | ||
1755 | proc test_debug_format {format} { | |
1756 | global debug_format | |
1757 | ||
1758 | return [expr [string match $format $debug_format] != 0] | |
1759 | } | |
1760 | ||
c906108c SS |
1761 | # Like setup_xfail, but takes the name of a debug format (DWARF 1, |
1762 | # COFF, stabs, etc). If that format matches the format that the | |
1763 | # current test was compiled with, then the next test is expected to | |
1764 | # fail for any target. Returns 1 if the next test or set of tests is | |
1765 | # expected to fail, 0 otherwise (or if it is unknown). Must have | |
1766 | # previously called get_debug_format. | |
b55a4771 | 1767 | proc setup_xfail_format { format } { |
838ae6c4 | 1768 | set ret [test_debug_format $format]; |
b55a4771 | 1769 | |
838ae6c4 | 1770 | if {$ret} then { |
b55a4771 MS |
1771 | setup_xfail "*-*-*" |
1772 | } | |
1773 | return $ret; | |
1774 | } | |
c906108c SS |
1775 | |
1776 | proc gdb_step_for_stub { } { | |
1777 | global gdb_prompt; | |
1778 | ||
1779 | if ![target_info exists gdb,use_breakpoint_for_stub] { | |
1780 | if [target_info exists gdb_stub_step_command] { | |
1781 | set command [target_info gdb_stub_step_command]; | |
1782 | } else { | |
1783 | set command "step"; | |
1784 | } | |
1785 | send_gdb "${command}\n"; | |
1786 | set tries 0; | |
1787 | gdb_expect 60 { | |
1788 | -re "(main.* at |.*in .*start).*$gdb_prompt" { | |
1789 | return; | |
1790 | } | |
1791 | -re ".*$gdb_prompt" { | |
1792 | incr tries; | |
1793 | if { $tries == 5 } { | |
1794 | fail "stepping out of breakpoint function"; | |
1795 | return; | |
1796 | } | |
1797 | send_gdb "${command}\n"; | |
1798 | exp_continue; | |
1799 | } | |
1800 | default { | |
1801 | fail "stepping out of breakpoint function"; | |
1802 | return; | |
1803 | } | |
1804 | } | |
1805 | } | |
1806 | send_gdb "where\n"; | |
1807 | gdb_expect { | |
1808 | -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" { | |
1809 | set file $expect_out(1,string); | |
1810 | set linenum [expr $expect_out(2,string) + 1]; | |
1811 | set breakplace "${file}:${linenum}"; | |
1812 | } | |
1813 | default {} | |
1814 | } | |
1815 | send_gdb "break ${breakplace}\n"; | |
1816 | gdb_expect 60 { | |
1817 | -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" { | |
1818 | set breakpoint $expect_out(1,string); | |
1819 | } | |
1820 | -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" { | |
1821 | set breakpoint $expect_out(1,string); | |
1822 | } | |
1823 | default {} | |
1824 | } | |
1825 | send_gdb "continue\n"; | |
1826 | gdb_expect 60 { | |
1827 | -re "Breakpoint ${breakpoint},.*$gdb_prompt" { | |
1828 | gdb_test "delete $breakpoint" ".*" ""; | |
1829 | return; | |
1830 | } | |
1831 | default {} | |
1832 | } | |
1833 | } | |
1834 | ||
c6fee705 MC |
1835 | # gdb_get_line_number TEXT [FILE] |
1836 | # | |
1837 | # Search the source file FILE, and return the line number of the | |
1838 | # first line containing TEXT. If no match is found, return -1. | |
1839 | # | |
1840 | # TEXT is a string literal, not a regular expression. | |
1841 | # | |
1842 | # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is | |
1843 | # specified, and does not start with "/", then it is assumed to be in | |
1844 | # "$srcdir/$subdir". This is awkward, and can be fixed in the future, | |
1845 | # by changing the callers and the interface at the same time. | |
1846 | # In particular: gdb.base/break.exp, gdb.base/condbreak.exp, | |
1847 | # gdb.base/ena-dis-br.exp. | |
1848 | # | |
1849 | # Use this function to keep your test scripts independent of the | |
1850 | # exact line numbering of the source file. Don't write: | |
1851 | # | |
1852 | # send_gdb "break 20" | |
1853 | # | |
1854 | # This means that if anyone ever edits your test's source file, | |
1855 | # your test could break. Instead, put a comment like this on the | |
1856 | # source file line you want to break at: | |
1857 | # | |
1858 | # /* breakpoint spot: frotz.exp: test name */ | |
1859 | # | |
1860 | # and then write, in your test script (which we assume is named | |
1861 | # frotz.exp): | |
1862 | # | |
1863 | # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n" | |
1864 | # | |
1865 | # (Yes, Tcl knows how to handle the nested quotes and brackets. | |
1866 | # Try this: | |
1867 | # $ tclsh | |
1868 | # % puts "foo [lindex "bar baz" 1]" | |
1869 | # foo baz | |
1870 | # % | |
1871 | # Tcl is quite clever, for a little stringy language.) | |
1872 | # | |
1873 | # === | |
1874 | # | |
1875 | # The previous implementation of this procedure used the gdb search command. | |
1876 | # This version is different: | |
1877 | # | |
1878 | # . It works with MI, and it also works when gdb is not running. | |
1879 | # | |
1880 | # . It operates on the build machine, not the host machine. | |
1881 | # | |
1882 | # . For now, this implementation fakes a current directory of | |
1883 | # $srcdir/$subdir to be compatible with the old implementation. | |
1884 | # This will go away eventually and some callers will need to | |
1885 | # be changed. | |
1886 | # | |
1887 | # . The TEXT argument is literal text and matches literally, | |
1888 | # not a regular expression as it was before. | |
1889 | # | |
1890 | # . State changes in gdb, such as changing the current file | |
1891 | # and setting $_, no longer happen. | |
1892 | # | |
1893 | # After a bit of time we can forget about the differences from the | |
1894 | # old implementation. | |
1895 | # | |
1896 | # --chastain 2004-08-05 | |
1897 | ||
1898 | proc gdb_get_line_number { text { file "" } } { | |
1899 | global srcdir | |
1900 | global subdir | |
1901 | global srcfile | |
c906108c | 1902 | |
c6fee705 MC |
1903 | if { "$file" == "" } then { |
1904 | set file "$srcfile" | |
1905 | } | |
1906 | if { ! [regexp "^/" "$file"] } then { | |
1907 | set file "$srcdir/$subdir/$file" | |
c906108c SS |
1908 | } |
1909 | ||
c6fee705 MC |
1910 | if { [ catch { set fd [open "$file"] } message ] } then { |
1911 | perror "$message" | |
1912 | return -1 | |
c906108c | 1913 | } |
c6fee705 MC |
1914 | |
1915 | set found -1 | |
1916 | for { set line 1 } { 1 } { incr line } { | |
1917 | if { [ catch { set nchar [gets "$fd" body] } message ] } then { | |
1918 | perror "$message" | |
1919 | return -1 | |
1920 | } | |
1921 | if { $nchar < 0 } then { | |
1922 | break | |
1923 | } | |
1924 | if { [string first "$text" "$body"] >= 0 } then { | |
1925 | set found $line | |
1926 | break | |
1927 | } | |
1928 | } | |
1929 | ||
1930 | if { [ catch { close "$fd" } message ] } then { | |
1931 | perror "$message" | |
1932 | return -1 | |
1933 | } | |
1934 | ||
1935 | return $found | |
c906108c SS |
1936 | } |
1937 | ||
7a292a7a SS |
1938 | # gdb_continue_to_end: |
1939 | # The case where the target uses stubs has to be handled specially. If a | |
1940 | # stub is used, we set a breakpoint at exit because we cannot rely on | |
1941 | # exit() behavior of a remote target. | |
1942 | # | |
1943 | # mssg is the error message that gets printed. | |
1944 | ||
1945 | proc gdb_continue_to_end {mssg} { | |
1946 | if [target_info exists use_gdb_stub] { | |
1947 | if {![gdb_breakpoint "exit"]} { | |
1948 | return 0 | |
1949 | } | |
1950 | gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \ | |
1951 | "continue until exit at $mssg" | |
1952 | } else { | |
1953 | # Continue until we exit. Should not stop again. | |
1954 | # Don't bother to check the output of the program, that may be | |
1955 | # extremely tough for some remote systems. | |
1956 | gdb_test "continue"\ | |
1c56143a | 1957 | "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\ |
7a292a7a SS |
1958 | "continue until exit at $mssg" |
1959 | } | |
1960 | } | |
1961 | ||
1962 | proc rerun_to_main {} { | |
1963 | global gdb_prompt | |
1964 | ||
1965 | if [target_info exists use_gdb_stub] { | |
1966 | gdb_run_cmd | |
1967 | gdb_expect { | |
1968 | -re ".*Breakpoint .*main .*$gdb_prompt $"\ | |
1969 | {pass "rerun to main" ; return 0} | |
1970 | -re "$gdb_prompt $"\ | |
1971 | {fail "rerun to main" ; return 0} | |
1972 | timeout {fail "(timeout) rerun to main" ; return 0} | |
1973 | } | |
1974 | } else { | |
1975 | send_gdb "run\n" | |
1976 | gdb_expect { | |
11350d2a CV |
1977 | -re "The program .* has been started already.*y or n. $" { |
1978 | send_gdb "y\n" | |
1979 | exp_continue | |
1980 | } | |
7a292a7a SS |
1981 | -re "Starting program.*$gdb_prompt $"\ |
1982 | {pass "rerun to main" ; return 0} | |
1983 | -re "$gdb_prompt $"\ | |
1984 | {fail "rerun to main" ; return 0} | |
1985 | timeout {fail "(timeout) rerun to main" ; return 0} | |
1986 | } | |
1987 | } | |
1988 | } | |
c906108c | 1989 | |
13a5e3b8 MS |
1990 | # Print a message and return true if a test should be skipped |
1991 | # due to lack of floating point suport. | |
1992 | ||
1993 | proc gdb_skip_float_test { msg } { | |
1994 | if [target_info exists gdb,skip_float_tests] { | |
1995 | verbose "Skipping test '$msg': no float tests."; | |
1996 | return 1; | |
1997 | } | |
1998 | return 0; | |
1999 | } | |
2000 | ||
2001 | # Print a message and return true if a test should be skipped | |
2002 | # due to lack of stdio support. | |
2003 | ||
2004 | proc gdb_skip_stdio_test { msg } { | |
2005 | if [target_info exists gdb,noinferiorio] { | |
2006 | verbose "Skipping test '$msg': no inferior i/o."; | |
2007 | return 1; | |
2008 | } | |
2009 | return 0; | |
2010 | } | |
2011 | ||
2012 | proc gdb_skip_bogus_test { msg } { | |
2013 | return 0; | |
2014 | } | |
2015 | ||
1f8a6abb EZ |
2016 | |
2017 | # Note: the procedure gdb_gnu_strip_debug will produce an executable called | |
2018 | # ${binfile}.dbglnk, which is just like the executable ($binfile) but without | |
2019 | # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains | |
2020 | # the name of a idebuginfo only file. This file will be stored in the | |
2021 | # gdb.base/.debug subdirectory. | |
2022 | ||
2023 | # Functions for separate debug info testing | |
2024 | ||
2025 | # starting with an executable: | |
2026 | # foo --> original executable | |
2027 | ||
2028 | # at the end of the process we have: | |
2029 | # foo.stripped --> foo w/o debug info | |
2030 | # .debug/foo.debug --> foo's debug info | |
2031 | # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug. | |
2032 | ||
2033 | # Return the name of the file in which we should stor EXEC's separated | |
2034 | # debug info. EXEC contains the full path. | |
2035 | proc separate_debug_filename { exec } { | |
2036 | ||
2037 | # In a .debug subdirectory off the same directory where the testcase | |
2038 | # executable is going to be. Something like: | |
2039 | # <your-path>/gdb/testsuite/gdb.base/.debug/blah.debug. | |
2040 | # This is the default location where gdb expects to findi | |
2041 | # the debug info file. | |
2042 | ||
2043 | set exec_dir [file dirname $exec] | |
2044 | set exec_file [file tail $exec] | |
2045 | set debug_dir [file join $exec_dir ".debug"] | |
2046 | set debug_file [file join $debug_dir "${exec_file}.debug"] | |
2047 | ||
2048 | return $debug_file | |
2049 | } | |
2050 | ||
2051 | ||
2052 | proc gdb_gnu_strip_debug { dest } { | |
2053 | ||
2054 | set debug_file [separate_debug_filename $dest] | |
2055 | set strip_to_file_program strip | |
2056 | set objcopy_program objcopy | |
2057 | ||
2058 | # Make sure the directory that will hold the separated debug | |
2059 | # info actually exists. | |
2060 | set debug_dir [file dirname $debug_file] | |
2061 | if {! [file isdirectory $debug_dir]} { | |
2062 | file mkdir $debug_dir | |
2063 | } | |
2064 | ||
2065 | set debug_link [file tail $debug_file] | |
2066 | set stripped_file "${dest}.stripped" | |
2067 | ||
2068 | # Get rid of the debug info, and store result in stripped_file | |
2069 | # something like gdb/testsuite/gdb.base/blah.stripped. | |
2070 | set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output] | |
2071 | verbose "result is $result" | |
2072 | verbose "output is $output" | |
2073 | if {$result == 1} { | |
2074 | return 1 | |
2075 | } | |
2076 | ||
2077 | # Get rid of everything but the debug info, and store result in debug_file | |
2078 | # This will be in the .debug subdirectory, see above. | |
2079 | set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output] | |
2080 | verbose "result is $result" | |
2081 | verbose "output is $output" | |
2082 | if {$result == 1} { | |
2083 | return 1 | |
2084 | } | |
2085 | ||
2086 | # Link the two previous output files together, adding the .gnu_debuglink | |
2087 | # section to the stripped_file, containing a pointer to the debug_file, | |
2088 | # save the new file in dest. | |
2089 | # This will be the regular executable filename, in the usual location. | |
2090 | set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output] | |
2091 | verbose "result is $result" | |
2092 | verbose "output is $output" | |
2093 | if {$result == 1} { | |
2094 | return 1 | |
2095 | } | |
2096 | ||
2097 | return 0 | |
2098 | } | |
2099 |