Commit | Line | Data |
---|---|---|
6aba47ca | 1 | # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
4c38e0a4 | 2 | # 2003, 2004, 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
c906108c SS |
3 | |
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
c906108c SS |
9 | # This program is distributed in the hope that it will be useful, |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
e22f8b7c | 13 | # |
c906108c | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 16 | |
c906108c SS |
17 | # This file was written by Fred Fish. (fnf@cygnus.com) |
18 | ||
19 | # Generic gdb subroutines that should work for any target. If these | |
20 | # need to be modified for any target, it can be done with a variable | |
21 | # or by passing arguments. | |
22 | ||
97c3f1f3 JK |
23 | if {$tool == ""} { |
24 | # Tests would fail, logs on get_compiler_info() would be missing. | |
25 | send_error "`site.exp' not found, run `make site.exp'!\n" | |
26 | exit 2 | |
27 | } | |
28 | ||
c906108c SS |
29 | load_lib libgloss.exp |
30 | ||
31 | global GDB | |
c906108c SS |
32 | |
33 | if [info exists TOOL_EXECUTABLE] { | |
34 | set GDB $TOOL_EXECUTABLE; | |
35 | } | |
36 | if ![info exists GDB] { | |
37 | if ![is_remote host] { | |
38 | set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]] | |
39 | } else { | |
40 | set GDB [transform gdb]; | |
41 | } | |
42 | } | |
43 | verbose "using GDB = $GDB" 2 | |
44 | ||
6b8ce727 DE |
45 | # GDBFLAGS is available for the user to set on the command line. |
46 | # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble | |
47 | # Testcases may use it to add additional flags, but they must: | |
48 | # - append new flags, not overwrite | |
49 | # - restore the original value when done | |
c906108c SS |
50 | global GDBFLAGS |
51 | if ![info exists GDBFLAGS] { | |
6b8ce727 | 52 | set GDBFLAGS "" |
c906108c SS |
53 | } |
54 | verbose "using GDBFLAGS = $GDBFLAGS" 2 | |
55 | ||
6b8ce727 | 56 | # INTERNAL_GDBFLAGS contains flags that the testsuite requires. |
1be00882 DE |
57 | global INTERNAL_GDBFLAGS |
58 | if ![info exists INTERNAL_GDBFLAGS] { | |
59 | set INTERNAL_GDBFLAGS "-nw -nx" | |
60 | } | |
6b8ce727 | 61 | |
9e0b60a8 JM |
62 | # The variable gdb_prompt is a regexp which matches the gdb prompt. |
63 | # Set it if it is not already set. | |
c906108c | 64 | global gdb_prompt |
9e0b60a8 | 65 | if ![info exists gdb_prompt] then { |
c906108c SS |
66 | set gdb_prompt "\[(\]gdb\[)\]" |
67 | } | |
68 | ||
6006a3a1 BR |
69 | # The variable fullname_syntax_POSIX is a regexp which matches a POSIX |
70 | # absolute path ie. /foo/ | |
d0b76dc6 | 71 | set fullname_syntax_POSIX {/[^\n]*/} |
6006a3a1 BR |
72 | # The variable fullname_syntax_UNC is a regexp which matches a Windows |
73 | # UNC path ie. \\D\foo\ | |
d0b76dc6 | 74 | set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\} |
6006a3a1 BR |
75 | # The variable fullname_syntax_DOS_CASE is a regexp which matches a |
76 | # particular DOS case that GDB most likely will output | |
77 | # ie. \foo\, but don't match \\.*\ | |
d0b76dc6 | 78 | set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\} |
6006a3a1 BR |
79 | # The variable fullname_syntax_DOS is a regexp which matches a DOS path |
80 | # ie. a:\foo\ && a:foo\ | |
d0b76dc6 | 81 | set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\} |
6006a3a1 BR |
82 | # The variable fullname_syntax is a regexp which matches what GDB considers |
83 | # an absolute path. It is currently debatable if the Windows style paths | |
84 | # d:foo and \abc should be considered valid as an absolute path. | |
85 | # Also, the purpse of this regexp is not to recognize a well formed | |
86 | # absolute path, but to say with certainty that a path is absolute. | |
87 | set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)" | |
88 | ||
93076499 ND |
89 | # Needed for some tests under Cygwin. |
90 | global EXEEXT | |
91 | global env | |
92 | ||
93 | if ![info exists env(EXEEXT)] { | |
94 | set EXEEXT "" | |
95 | } else { | |
96 | set EXEEXT $env(EXEEXT) | |
97 | } | |
98 | ||
bb2bed55 NR |
99 | set octal "\[0-7\]+" |
100 | ||
085dd6e6 JM |
101 | ### Only procedures should come after this point. |
102 | ||
c906108c SS |
103 | # |
104 | # gdb_version -- extract and print the version number of GDB | |
105 | # | |
106 | proc default_gdb_version {} { | |
107 | global GDB | |
6b8ce727 | 108 | global INTERNAL_GDBFLAGS GDBFLAGS |
c906108c | 109 | global gdb_prompt |
fa335448 | 110 | set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"] |
c906108c SS |
111 | set tmp [lindex $output 1]; |
112 | set version "" | |
113 | regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version | |
114 | if ![is_remote host] { | |
6b8ce727 | 115 | clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n" |
c906108c | 116 | } else { |
6b8ce727 | 117 | clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n" |
c906108c SS |
118 | } |
119 | } | |
120 | ||
121 | proc gdb_version { } { | |
122 | return [default_gdb_version]; | |
123 | } | |
124 | ||
125 | # | |
126 | # gdb_unload -- unload a file if one is loaded | |
127 | # | |
128 | ||
129 | proc gdb_unload {} { | |
130 | global verbose | |
131 | global GDB | |
132 | global gdb_prompt | |
133 | send_gdb "file\n" | |
134 | gdb_expect 60 { | |
135 | -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue } | |
136 | -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue } | |
137 | -re "A program is being debugged already..*Kill it.*y or n. $"\ | |
138 | { send_gdb "y\n" | |
139 | verbose "\t\tKilling previous program being debugged" | |
140 | exp_continue | |
141 | } | |
142 | -re "Discard symbol table from .*y or n.*$" { | |
143 | send_gdb "y\n" | |
144 | exp_continue | |
145 | } | |
146 | -re "$gdb_prompt $" {} | |
147 | timeout { | |
148 | perror "couldn't unload file in $GDB (timed out)." | |
149 | return -1 | |
150 | } | |
151 | } | |
152 | } | |
153 | ||
154 | # Many of the tests depend on setting breakpoints at various places and | |
155 | # running until that breakpoint is reached. At times, we want to start | |
156 | # with a clean-slate with respect to breakpoints, so this utility proc | |
157 | # lets us do this without duplicating this code everywhere. | |
158 | # | |
159 | ||
160 | proc delete_breakpoints {} { | |
161 | global gdb_prompt | |
162 | ||
a0b3c4fd JM |
163 | # we need a larger timeout value here or this thing just confuses |
164 | # itself. May need a better implementation if possible. - guo | |
165 | # | |
c906108c | 166 | send_gdb "delete breakpoints\n" |
a0b3c4fd | 167 | gdb_expect 100 { |
c906108c SS |
168 | -re "Delete all breakpoints.*y or n.*$" { |
169 | send_gdb "y\n"; | |
170 | exp_continue | |
171 | } | |
172 | -re "$gdb_prompt $" { # This happens if there were no breakpoints | |
173 | } | |
174 | timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return } | |
175 | } | |
176 | send_gdb "info breakpoints\n" | |
a0b3c4fd | 177 | gdb_expect 100 { |
c906108c SS |
178 | -re "No breakpoints or watchpoints..*$gdb_prompt $" {} |
179 | -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return } | |
180 | -re "Delete all breakpoints.*or n.*$" { | |
181 | send_gdb "y\n"; | |
182 | exp_continue | |
183 | } | |
184 | timeout { perror "info breakpoints (timeout)" ; return } | |
185 | } | |
186 | } | |
187 | ||
188 | ||
189 | # | |
190 | # Generic run command. | |
191 | # | |
192 | # The second pattern below matches up to the first newline *only*. | |
193 | # Using ``.*$'' could swallow up output that we attempt to match | |
194 | # elsewhere. | |
195 | # | |
196 | proc gdb_run_cmd {args} { | |
197 | global gdb_prompt | |
198 | ||
199 | if [target_info exists gdb_init_command] { | |
200 | send_gdb "[target_info gdb_init_command]\n"; | |
201 | gdb_expect 30 { | |
202 | -re "$gdb_prompt $" { } | |
203 | default { | |
204 | perror "gdb_init_command for target failed"; | |
205 | return; | |
206 | } | |
207 | } | |
208 | } | |
209 | ||
210 | if [target_info exists use_gdb_stub] { | |
211 | if [target_info exists gdb,do_reload_on_run] { | |
b741e217 | 212 | if { [gdb_reload] != 0 } { |
917317f4 JM |
213 | return; |
214 | } | |
c906108c SS |
215 | send_gdb "continue\n"; |
216 | gdb_expect 60 { | |
217 | -re "Continu\[^\r\n\]*\[\r\n\]" {} | |
218 | default {} | |
219 | } | |
220 | return; | |
221 | } | |
222 | ||
223 | if [target_info exists gdb,start_symbol] { | |
224 | set start [target_info gdb,start_symbol]; | |
225 | } else { | |
226 | set start "start"; | |
227 | } | |
228 | send_gdb "jump *$start\n" | |
917317f4 JM |
229 | set start_attempt 1; |
230 | while { $start_attempt } { | |
231 | # Cap (re)start attempts at three to ensure that this loop | |
232 | # always eventually fails. Don't worry about trying to be | |
233 | # clever and not send a command when it has failed. | |
234 | if [expr $start_attempt > 3] { | |
235 | perror "Jump to start() failed (retry count exceeded)"; | |
c906108c SS |
236 | return; |
237 | } | |
917317f4 JM |
238 | set start_attempt [expr $start_attempt + 1]; |
239 | gdb_expect 30 { | |
240 | -re "Continuing at \[^\r\n\]*\[\r\n\]" { | |
241 | set start_attempt 0; | |
242 | } | |
243 | -re "No symbol \"_start\" in current.*$gdb_prompt $" { | |
244 | perror "Can't find start symbol to run in gdb_run"; | |
245 | return; | |
246 | } | |
247 | -re "No symbol \"start\" in current.*$gdb_prompt $" { | |
248 | send_gdb "jump *_start\n"; | |
249 | } | |
250 | -re "No symbol.*context.*$gdb_prompt $" { | |
251 | set start_attempt 0; | |
252 | } | |
253 | -re "Line.* Jump anyway.*y or n. $" { | |
254 | send_gdb "y\n" | |
255 | } | |
256 | -re "The program is not being run.*$gdb_prompt $" { | |
b741e217 | 257 | if { [gdb_reload] != 0 } { |
917317f4 JM |
258 | return; |
259 | } | |
260 | send_gdb "jump *$start\n"; | |
261 | } | |
262 | timeout { | |
263 | perror "Jump to start() failed (timeout)"; | |
264 | return | |
265 | } | |
c906108c | 266 | } |
c906108c SS |
267 | } |
268 | if [target_info exists gdb_stub] { | |
269 | gdb_expect 60 { | |
270 | -re "$gdb_prompt $" { | |
271 | send_gdb "continue\n" | |
272 | } | |
273 | } | |
274 | } | |
275 | return | |
276 | } | |
83f66e8f DJ |
277 | |
278 | if [target_info exists gdb,do_reload_on_run] { | |
b741e217 | 279 | if { [gdb_reload] != 0 } { |
83f66e8f DJ |
280 | return; |
281 | } | |
282 | } | |
c906108c SS |
283 | send_gdb "run $args\n" |
284 | # This doesn't work quite right yet. | |
5aa7ddc2 PM |
285 | # Use -notransfer here so that test cases (like chng-sym.exp) |
286 | # may test for additional start-up messages. | |
287 | gdb_expect 60 { | |
c906108c SS |
288 | -re "The program .* has been started already.*y or n. $" { |
289 | send_gdb "y\n" | |
290 | exp_continue | |
291 | } | |
bbb88ebf | 292 | -notransfer -re "Starting program: \[^\r\n\]*" {} |
c906108c SS |
293 | } |
294 | } | |
295 | ||
b741e217 DJ |
296 | # Generic start command. Return 0 if we could start the program, -1 |
297 | # if we could not. | |
298 | ||
299 | proc gdb_start_cmd {args} { | |
300 | global gdb_prompt | |
301 | ||
302 | if [target_info exists gdb_init_command] { | |
303 | send_gdb "[target_info gdb_init_command]\n"; | |
304 | gdb_expect 30 { | |
305 | -re "$gdb_prompt $" { } | |
306 | default { | |
307 | perror "gdb_init_command for target failed"; | |
308 | return; | |
309 | } | |
310 | } | |
311 | } | |
312 | ||
313 | if [target_info exists use_gdb_stub] { | |
314 | return -1 | |
315 | } | |
316 | ||
317 | send_gdb "start $args\n" | |
2de75e71 JB |
318 | # Use -notransfer here so that test cases (like chng-sym.exp) |
319 | # may test for additional start-up messages. | |
b741e217 DJ |
320 | gdb_expect 60 { |
321 | -re "The program .* has been started already.*y or n. $" { | |
322 | send_gdb "y\n" | |
323 | exp_continue | |
324 | } | |
b741e217 DJ |
325 | -notransfer -re "Starting program: \[^\r\n\]*" { |
326 | return 0 | |
327 | } | |
328 | } | |
329 | return -1 | |
330 | } | |
331 | ||
78a1a894 | 332 | # Set a breakpoint at FUNCTION. If there is an additional argument it is |
55cd6f92 DJ |
333 | # a list of options; the supported options are allow-pending, temporary, |
334 | # and no-message. | |
78a1a894 DJ |
335 | |
336 | proc gdb_breakpoint { function args } { | |
c906108c SS |
337 | global gdb_prompt |
338 | global decimal | |
339 | ||
78a1a894 DJ |
340 | set pending_response n |
341 | if {[lsearch -exact [lindex $args 0] allow-pending] != -1} { | |
342 | set pending_response y | |
343 | } | |
344 | ||
e48883f7 | 345 | set break_command "break" |
18ac113b | 346 | set break_message "Breakpoint" |
e48883f7 DJ |
347 | if {[lsearch -exact [lindex $args 0] temporary] != -1} { |
348 | set break_command "tbreak" | |
18ac113b | 349 | set break_message "Temporary breakpoint" |
e48883f7 DJ |
350 | } |
351 | ||
55cd6f92 DJ |
352 | set no_message 0 |
353 | if {[lsearch -exact [lindex $args 0] no-message] != -1} { | |
354 | set no_message 1 | |
355 | } | |
356 | ||
e48883f7 | 357 | send_gdb "$break_command $function\n" |
c906108c SS |
358 | # The first two regexps are what we get with -g, the third is without -g. |
359 | gdb_expect 30 { | |
18ac113b AR |
360 | -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {} |
361 | -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {} | |
362 | -re "$break_message \[0-9\]* at .*$gdb_prompt $" {} | |
363 | -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" { | |
78a1a894 | 364 | if {$pending_response == "n"} { |
55cd6f92 DJ |
365 | if { $no_message == 0 } { |
366 | fail "setting breakpoint at $function" | |
367 | } | |
78a1a894 DJ |
368 | return 0 |
369 | } | |
370 | } | |
9f27c604 | 371 | -re "Make breakpoint pending.*y or \\\[n\\\]. $" { |
78a1a894 | 372 | send_gdb "$pending_response\n" |
14b1a056 | 373 | exp_continue |
18fe2033 | 374 | } |
55cd6f92 DJ |
375 | -re "$gdb_prompt $" { |
376 | if { $no_message == 0 } { | |
377 | fail "setting breakpoint at $function" | |
378 | } | |
379 | return 0 | |
380 | } | |
381 | timeout { | |
382 | if { $no_message == 0 } { | |
383 | fail "setting breakpoint at $function (timeout)" | |
384 | } | |
385 | return 0 | |
386 | } | |
c906108c SS |
387 | } |
388 | return 1; | |
389 | } | |
390 | ||
391 | # Set breakpoint at function and run gdb until it breaks there. | |
392 | # Since this is the only breakpoint that will be set, if it stops | |
393 | # at a breakpoint, we will assume it is the one we want. We can't | |
394 | # just compare to "function" because it might be a fully qualified, | |
78a1a894 DJ |
395 | # single quoted C++ function specifier. If there's an additional argument, |
396 | # pass it to gdb_breakpoint. | |
c906108c | 397 | |
78a1a894 | 398 | proc runto { function args } { |
c906108c SS |
399 | global gdb_prompt |
400 | global decimal | |
401 | ||
402 | delete_breakpoints | |
403 | ||
78a1a894 | 404 | if ![gdb_breakpoint $function [lindex $args 0]] { |
c906108c SS |
405 | return 0; |
406 | } | |
407 | ||
408 | gdb_run_cmd | |
409 | ||
410 | # the "at foo.c:36" output we get with -g. | |
411 | # the "in func" output we get without -g. | |
412 | gdb_expect 30 { | |
413 | -re "Break.* at .*:$decimal.*$gdb_prompt $" { | |
414 | return 1 | |
415 | } | |
416 | -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" { | |
417 | return 1 | |
418 | } | |
419 | -re "$gdb_prompt $" { | |
420 | fail "running to $function in runto" | |
421 | return 0 | |
422 | } | |
72c63395 JK |
423 | eof { |
424 | fail "running to $function in runto (end of file)" | |
425 | return 0 | |
426 | } | |
c906108c SS |
427 | timeout { |
428 | fail "running to $function in runto (timeout)" | |
429 | return 0 | |
430 | } | |
431 | } | |
432 | return 1 | |
433 | } | |
434 | ||
435 | # | |
436 | # runto_main -- ask gdb to run until we hit a breakpoint at main. | |
437 | # The case where the target uses stubs has to be handled | |
438 | # specially--if it uses stubs, assuming we hit | |
439 | # breakpoint() and just step out of the function. | |
440 | # | |
441 | proc runto_main { } { | |
442 | global gdb_prompt | |
443 | global decimal | |
444 | ||
445 | if ![target_info exists gdb_stub] { | |
446 | return [runto main] | |
447 | } | |
448 | ||
449 | delete_breakpoints | |
450 | ||
451 | gdb_step_for_stub; | |
452 | ||
453 | return 1 | |
454 | } | |
455 | ||
7a292a7a | 456 | |
4ce44c66 JM |
457 | ### Continue, and expect to hit a breakpoint. |
458 | ### Report a pass or fail, depending on whether it seems to have | |
459 | ### worked. Use NAME as part of the test name; each call to | |
460 | ### continue_to_breakpoint should use a NAME which is unique within | |
461 | ### that test file. | |
74960c60 | 462 | proc gdb_continue_to_breakpoint {name {location_pattern .*}} { |
4ce44c66 JM |
463 | global gdb_prompt |
464 | set full_name "continue to breakpoint: $name" | |
465 | ||
466 | send_gdb "continue\n" | |
467 | gdb_expect { | |
b02a33db | 468 | -re "Breakpoint .* (at|in) $location_pattern\r\n$gdb_prompt $" { |
4ce44c66 JM |
469 | pass $full_name |
470 | } | |
471 | -re ".*$gdb_prompt $" { | |
472 | fail $full_name | |
473 | } | |
474 | timeout { | |
475 | fail "$full_name (timeout)" | |
476 | } | |
477 | } | |
478 | } | |
479 | ||
480 | ||
039cf96d AC |
481 | # gdb_internal_error_resync: |
482 | # | |
483 | # Answer the questions GDB asks after it reports an internal error | |
484 | # until we get back to a GDB prompt. Decline to quit the debugging | |
485 | # session, and decline to create a core file. Return non-zero if the | |
486 | # resync succeeds. | |
487 | # | |
488 | # This procedure just answers whatever questions come up until it sees | |
489 | # a GDB prompt; it doesn't require you to have matched the input up to | |
490 | # any specific point. However, it only answers questions it sees in | |
491 | # the output itself, so if you've matched a question, you had better | |
492 | # answer it yourself before calling this. | |
493 | # | |
494 | # You can use this function thus: | |
495 | # | |
496 | # gdb_expect { | |
497 | # ... | |
498 | # -re ".*A problem internal to GDB has been detected" { | |
499 | # gdb_internal_error_resync | |
500 | # } | |
501 | # ... | |
502 | # } | |
503 | # | |
504 | proc gdb_internal_error_resync {} { | |
505 | global gdb_prompt | |
506 | ||
507 | set count 0 | |
508 | while {$count < 10} { | |
509 | gdb_expect { | |
510 | -re "Quit this debugging session\\? \\(y or n\\) $" { | |
511 | send_gdb "n\n" | |
512 | incr count | |
513 | } | |
514 | -re "Create a core file of GDB\\? \\(y or n\\) $" { | |
515 | send_gdb "n\n" | |
516 | incr count | |
517 | } | |
518 | -re "$gdb_prompt $" { | |
519 | # We're resynchronized. | |
520 | return 1 | |
521 | } | |
522 | timeout { | |
523 | perror "Could not resync from internal error (timeout)" | |
524 | return 0 | |
525 | } | |
526 | } | |
527 | } | |
2b211c59 AC |
528 | perror "Could not resync from internal error (resync count exceeded)" |
529 | return 0 | |
039cf96d AC |
530 | } |
531 | ||
4ce44c66 | 532 | |
2307bd6a | 533 | # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS |
8dbfb380 | 534 | # Send a command to gdb; test the result. |
c906108c SS |
535 | # |
536 | # COMMAND is the command to execute, send to GDB with send_gdb. If | |
537 | # this is the null string no command is sent. | |
2307bd6a DJ |
538 | # MESSAGE is a message to be printed with the built-in failure patterns |
539 | # if one of them matches. If MESSAGE is empty COMMAND will be used. | |
540 | # EXPECT_ARGUMENTS will be fed to expect in addition to the standard | |
541 | # patterns. Pattern elements will be evaluated in the caller's | |
542 | # context; action elements will be executed in the caller's context. | |
543 | # Unlike patterns for gdb_test, these patterns should generally include | |
544 | # the final newline and prompt. | |
c906108c SS |
545 | # |
546 | # Returns: | |
2307bd6a DJ |
547 | # 1 if the test failed, according to a built-in failure pattern |
548 | # 0 if only user-supplied patterns matched | |
c906108c SS |
549 | # -1 if there was an internal error. |
550 | # | |
d422fe19 AC |
551 | # You can use this function thus: |
552 | # | |
553 | # gdb_test_multiple "print foo" "test foo" { | |
554 | # -re "expected output 1" { | |
555 | # pass "print foo" | |
556 | # } | |
557 | # -re "expected output 2" { | |
558 | # fail "print foo" | |
559 | # } | |
560 | # } | |
561 | # | |
562 | # The standard patterns, such as "Program exited..." and "A problem | |
563 | # ...", all being implicitly appended to that list. | |
564 | # | |
2307bd6a | 565 | proc gdb_test_multiple { command message user_code } { |
c906108c SS |
566 | global verbose |
567 | global gdb_prompt | |
568 | global GDB | |
569 | upvar timeout timeout | |
c47cebdb | 570 | upvar expect_out expect_out |
c906108c | 571 | |
2307bd6a DJ |
572 | if { $message == "" } { |
573 | set message $command | |
c906108c | 574 | } |
c906108c | 575 | |
2307bd6a DJ |
576 | # TCL/EXPECT WART ALERT |
577 | # Expect does something very strange when it receives a single braced | |
578 | # argument. It splits it along word separators and performs substitutions. | |
579 | # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is | |
580 | # evaluated as "\[ab\]". But that's not how TCL normally works; inside a | |
581 | # double-quoted list item, "\[ab\]" is just a long way of representing | |
582 | # "[ab]", because the backslashes will be removed by lindex. | |
583 | ||
584 | # Unfortunately, there appears to be no easy way to duplicate the splitting | |
585 | # that expect will do from within TCL. And many places make use of the | |
586 | # "\[0-9\]" construct, so we need to support that; and some places make use | |
587 | # of the "[func]" construct, so we need to support that too. In order to | |
588 | # get this right we have to substitute quoted list elements differently | |
589 | # from braced list elements. | |
590 | ||
591 | # We do this roughly the same way that Expect does it. We have to use two | |
592 | # lists, because if we leave unquoted newlines in the argument to uplevel | |
593 | # they'll be treated as command separators, and if we escape newlines | |
594 | # we mangle newlines inside of command blocks. This assumes that the | |
595 | # input doesn't contain a pattern which contains actual embedded newlines | |
596 | # at this point! | |
597 | ||
598 | regsub -all {\n} ${user_code} { } subst_code | |
599 | set subst_code [uplevel list $subst_code] | |
600 | ||
601 | set processed_code "" | |
602 | set patterns "" | |
603 | set expecting_action 0 | |
21e24d21 | 604 | set expecting_arg 0 |
2307bd6a DJ |
605 | foreach item $user_code subst_item $subst_code { |
606 | if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } { | |
607 | lappend processed_code $item | |
608 | continue | |
609 | } | |
21e24d21 PA |
610 | if { $item == "-indices" || $item == "-re" || $item == "-ex" } { |
611 | lappend processed_code $item | |
612 | continue | |
613 | } | |
614 | if { $item == "-timeout" } { | |
615 | set expecting_arg 1 | |
616 | lappend processed_code $item | |
617 | continue | |
618 | } | |
619 | if { $expecting_arg } { | |
620 | set expecting_arg 0 | |
2307bd6a DJ |
621 | lappend processed_code $item |
622 | continue | |
623 | } | |
624 | if { $expecting_action } { | |
625 | lappend processed_code "uplevel [list $item]" | |
626 | set expecting_action 0 | |
627 | # Cosmetic, no effect on the list. | |
628 | append processed_code "\n" | |
629 | continue | |
630 | } | |
631 | set expecting_action 1 | |
632 | lappend processed_code $subst_item | |
633 | if {$patterns != ""} { | |
634 | append patterns "; " | |
635 | } | |
636 | append patterns "\"$subst_item\"" | |
c906108c SS |
637 | } |
638 | ||
2307bd6a DJ |
639 | # Also purely cosmetic. |
640 | regsub -all {\r} $patterns {\\r} patterns | |
641 | regsub -all {\n} $patterns {\\n} patterns | |
642 | ||
c906108c SS |
643 | if $verbose>2 then { |
644 | send_user "Sending \"$command\" to gdb\n" | |
2307bd6a | 645 | send_user "Looking to match \"$patterns\"\n" |
c906108c SS |
646 | send_user "Message is \"$message\"\n" |
647 | } | |
648 | ||
649 | set result -1 | |
650 | set string "${command}\n"; | |
651 | if { $command != "" } { | |
652 | while { "$string" != "" } { | |
653 | set foo [string first "\n" "$string"]; | |
654 | set len [string length "$string"]; | |
655 | if { $foo < [expr $len - 1] } { | |
656 | set str [string range "$string" 0 $foo]; | |
657 | if { [send_gdb "$str"] != "" } { | |
658 | global suppress_flag; | |
659 | ||
660 | if { ! $suppress_flag } { | |
661 | perror "Couldn't send $command to GDB."; | |
662 | } | |
663 | fail "$message"; | |
664 | return $result; | |
665 | } | |
a0b3c4fd JM |
666 | # since we're checking if each line of the multi-line |
667 | # command are 'accepted' by GDB here, | |
668 | # we need to set -notransfer expect option so that | |
669 | # command output is not lost for pattern matching | |
670 | # - guo | |
5f279fa6 DJ |
671 | gdb_expect 2 { |
672 | -notransfer -re "\[\r\n\]" { verbose "partial: match" 3 } | |
673 | timeout { verbose "partial: timeout" 3 } | |
c906108c SS |
674 | } |
675 | set string [string range "$string" [expr $foo + 1] end]; | |
676 | } else { | |
677 | break; | |
678 | } | |
679 | } | |
680 | if { "$string" != "" } { | |
681 | if { [send_gdb "$string"] != "" } { | |
682 | global suppress_flag; | |
683 | ||
684 | if { ! $suppress_flag } { | |
685 | perror "Couldn't send $command to GDB."; | |
686 | } | |
687 | fail "$message"; | |
688 | return $result; | |
689 | } | |
690 | } | |
691 | } | |
692 | ||
9d2e1bab ND |
693 | if [target_info exists gdb,timeout] { |
694 | set tmt [target_info gdb,timeout]; | |
c906108c | 695 | } else { |
c906108c SS |
696 | if [info exists timeout] { |
697 | set tmt $timeout; | |
698 | } else { | |
9d2e1bab ND |
699 | global timeout; |
700 | if [info exists timeout] { | |
701 | set tmt $timeout; | |
702 | } else { | |
703 | set tmt 60; | |
704 | } | |
c906108c SS |
705 | } |
706 | } | |
2307bd6a DJ |
707 | |
708 | set code { | |
039cf96d AC |
709 | -re ".*A problem internal to GDB has been detected" { |
710 | fail "$message (GDB internal error)" | |
711 | gdb_internal_error_resync | |
712 | } | |
c906108c SS |
713 | -re "\\*\\*\\* DOSEXIT code.*" { |
714 | if { $message != "" } { | |
715 | fail "$message"; | |
716 | } | |
717 | gdb_suppress_entire_file "GDB died"; | |
2307bd6a | 718 | set result -1; |
c906108c | 719 | } |
b0f4b84b DJ |
720 | } |
721 | append code $processed_code | |
722 | append code { | |
9e0b60a8 | 723 | -re "Ending remote debugging.*$gdb_prompt $" { |
c906108c SS |
724 | if ![isnative] then { |
725 | warning "Can`t communicate to remote target." | |
726 | } | |
727 | gdb_exit | |
728 | gdb_start | |
729 | set result -1 | |
730 | } | |
9e0b60a8 | 731 | -re "Undefined\[a-z\]* command:.*$gdb_prompt $" { |
c906108c | 732 | perror "Undefined command \"$command\"." |
9e0b60a8 | 733 | fail "$message" |
c906108c SS |
734 | set result 1 |
735 | } | |
736 | -re "Ambiguous command.*$gdb_prompt $" { | |
737 | perror "\"$command\" is not a unique command name." | |
9e0b60a8 | 738 | fail "$message" |
c906108c SS |
739 | set result 1 |
740 | } | |
741 | -re "Program exited with code \[0-9\]+.*$gdb_prompt $" { | |
742 | if ![string match "" $message] then { | |
ed4c619a | 743 | set errmsg "$message (the program exited)" |
c906108c | 744 | } else { |
ed4c619a | 745 | set errmsg "$command (the program exited)" |
c906108c SS |
746 | } |
747 | fail "$errmsg" | |
2307bd6a | 748 | set result -1 |
cb9a9d3e MS |
749 | } |
750 | -re "EXIT code \[0-9\r\n\]+Program exited normally.*$gdb_prompt $" { | |
751 | if ![string match "" $message] then { | |
ed4c619a | 752 | set errmsg "$message (the program exited)" |
cb9a9d3e | 753 | } else { |
ed4c619a | 754 | set errmsg "$command (the program exited)" |
cb9a9d3e MS |
755 | } |
756 | fail "$errmsg" | |
2307bd6a | 757 | set result -1 |
c906108c SS |
758 | } |
759 | -re "The program is not being run.*$gdb_prompt $" { | |
760 | if ![string match "" $message] then { | |
ed4c619a | 761 | set errmsg "$message (the program is no longer running)" |
c906108c | 762 | } else { |
ed4c619a | 763 | set errmsg "$command (the program is no longer running)" |
c906108c SS |
764 | } |
765 | fail "$errmsg" | |
2307bd6a | 766 | set result -1 |
c906108c | 767 | } |
734b8fe8 | 768 | -re "\r\n$gdb_prompt $" { |
c906108c SS |
769 | if ![string match "" $message] then { |
770 | fail "$message" | |
771 | } | |
772 | set result 1 | |
773 | } | |
774 | "<return>" { | |
775 | send_gdb "\n" | |
776 | perror "Window too small." | |
9e0b60a8 | 777 | fail "$message" |
2307bd6a | 778 | set result -1 |
c906108c | 779 | } |
b598bfda | 780 | -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " { |
c906108c | 781 | send_gdb "n\n" |
b598bfda DJ |
782 | gdb_expect -re "$gdb_prompt $" |
783 | fail "$message (got interactive prompt)" | |
784 | set result -1 | |
785 | } | |
786 | -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" { | |
787 | send_gdb "0\n" | |
788 | gdb_expect -re "$gdb_prompt $" | |
789 | fail "$message (got breakpoint menu)" | |
2307bd6a | 790 | set result -1 |
c906108c SS |
791 | } |
792 | eof { | |
793 | perror "Process no longer exists" | |
794 | if { $message != "" } { | |
795 | fail "$message" | |
796 | } | |
797 | return -1 | |
798 | } | |
799 | full_buffer { | |
800 | perror "internal buffer is full." | |
9e0b60a8 | 801 | fail "$message" |
2307bd6a | 802 | set result -1 |
c906108c SS |
803 | } |
804 | timeout { | |
805 | if ![string match "" $message] then { | |
806 | fail "$message (timeout)" | |
807 | } | |
808 | set result 1 | |
809 | } | |
810 | } | |
2307bd6a DJ |
811 | |
812 | set result 0 | |
04f6ecf2 DJ |
813 | set code [catch {gdb_expect $tmt $code} string] |
814 | if {$code == 1} { | |
815 | global errorInfo errorCode; | |
816 | return -code error -errorinfo $errorInfo -errorcode $errorCode $string | |
817 | } elseif {$code == 2} { | |
818 | return -code return $string | |
819 | } elseif {$code == 3} { | |
820 | return | |
821 | } elseif {$code > 4} { | |
822 | return -code $code $string | |
823 | } | |
c906108c SS |
824 | return $result |
825 | } | |
2307bd6a DJ |
826 | |
827 | # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE | |
828 | # Send a command to gdb; test the result. | |
829 | # | |
830 | # COMMAND is the command to execute, send to GDB with send_gdb. If | |
831 | # this is the null string no command is sent. | |
832 | # PATTERN is the pattern to match for a PASS, and must NOT include | |
833 | # the \r\n sequence immediately before the gdb prompt. | |
834 | # MESSAGE is an optional message to be printed. If this is | |
835 | # omitted, then the pass/fail messages use the command string as the | |
836 | # message. (If this is the empty string, then sometimes we don't | |
837 | # call pass or fail at all; I don't understand this at all.) | |
838 | # QUESTION is a question GDB may ask in response to COMMAND, like | |
839 | # "are you sure?" | |
840 | # RESPONSE is the response to send if QUESTION appears. | |
841 | # | |
842 | # Returns: | |
843 | # 1 if the test failed, | |
844 | # 0 if the test passes, | |
845 | # -1 if there was an internal error. | |
846 | # | |
847 | proc gdb_test { args } { | |
848 | global verbose | |
849 | global gdb_prompt | |
850 | global GDB | |
851 | upvar timeout timeout | |
852 | ||
853 | if [llength $args]>2 then { | |
854 | set message [lindex $args 2] | |
855 | } else { | |
856 | set message [lindex $args 0] | |
857 | } | |
858 | set command [lindex $args 0] | |
859 | set pattern [lindex $args 1] | |
860 | ||
861 | if [llength $args]==5 { | |
862 | set question_string [lindex $args 3]; | |
863 | set response_string [lindex $args 4]; | |
864 | } else { | |
865 | set question_string "^FOOBAR$" | |
866 | } | |
867 | ||
868 | return [gdb_test_multiple $command $message { | |
869 | -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" { | |
870 | if ![string match "" $message] then { | |
871 | pass "$message" | |
872 | } | |
873 | } | |
874 | -re "(${question_string})$" { | |
875 | send_gdb "$response_string\n"; | |
876 | exp_continue; | |
877 | } | |
878 | }] | |
879 | } | |
c906108c SS |
880 | \f |
881 | # Test that a command gives an error. For pass or fail, return | |
882 | # a 1 to indicate that more tests can proceed. However a timeout | |
883 | # is a serious error, generates a special fail message, and causes | |
884 | # a 0 to be returned to indicate that more tests are likely to fail | |
885 | # as well. | |
886 | ||
887 | proc test_print_reject { args } { | |
888 | global gdb_prompt | |
889 | global verbose | |
890 | ||
891 | if [llength $args]==2 then { | |
892 | set expectthis [lindex $args 1] | |
893 | } else { | |
894 | set expectthis "should never match this bogus string" | |
895 | } | |
896 | set sendthis [lindex $args 0] | |
897 | if $verbose>2 then { | |
898 | send_user "Sending \"$sendthis\" to gdb\n" | |
899 | send_user "Looking to match \"$expectthis\"\n" | |
900 | } | |
901 | send_gdb "$sendthis\n" | |
902 | #FIXME: Should add timeout as parameter. | |
903 | gdb_expect { | |
904 | -re "A .* in expression.*\\.*$gdb_prompt $" { | |
905 | pass "reject $sendthis" | |
906 | return 1 | |
907 | } | |
908 | -re "Invalid syntax in expression.*$gdb_prompt $" { | |
909 | pass "reject $sendthis" | |
910 | return 1 | |
911 | } | |
912 | -re "Junk after end of expression.*$gdb_prompt $" { | |
913 | pass "reject $sendthis" | |
914 | return 1 | |
915 | } | |
916 | -re "Invalid number.*$gdb_prompt $" { | |
917 | pass "reject $sendthis" | |
918 | return 1 | |
919 | } | |
920 | -re "Invalid character constant.*$gdb_prompt $" { | |
921 | pass "reject $sendthis" | |
922 | return 1 | |
923 | } | |
924 | -re "No symbol table is loaded.*$gdb_prompt $" { | |
925 | pass "reject $sendthis" | |
926 | return 1 | |
927 | } | |
928 | -re "No symbol .* in current context.*$gdb_prompt $" { | |
929 | pass "reject $sendthis" | |
930 | return 1 | |
931 | } | |
c4b7bc2b JB |
932 | -re "Unmatched single quote.*$gdb_prompt $" { |
933 | pass "reject $sendthis" | |
934 | return 1 | |
935 | } | |
936 | -re "A character constant must contain at least one character.*$gdb_prompt $" { | |
937 | pass "reject $sendthis" | |
938 | return 1 | |
939 | } | |
c906108c SS |
940 | -re "$expectthis.*$gdb_prompt $" { |
941 | pass "reject $sendthis" | |
942 | return 1 | |
943 | } | |
944 | -re ".*$gdb_prompt $" { | |
945 | fail "reject $sendthis" | |
946 | return 1 | |
947 | } | |
948 | default { | |
949 | fail "reject $sendthis (eof or timeout)" | |
950 | return 0 | |
951 | } | |
952 | } | |
953 | } | |
954 | \f | |
955 | # Given an input string, adds backslashes as needed to create a | |
956 | # regexp that will match the string. | |
957 | ||
958 | proc string_to_regexp {str} { | |
959 | set result $str | |
39fb8e9e | 960 | regsub -all {[]*+.|()^$\[\\]} $str {\\&} result |
c906108c SS |
961 | return $result |
962 | } | |
963 | ||
964 | # Same as gdb_test, but the second parameter is not a regexp, | |
965 | # but a string that must match exactly. | |
966 | ||
967 | proc gdb_test_exact { args } { | |
968 | upvar timeout timeout | |
969 | ||
970 | set command [lindex $args 0] | |
971 | ||
972 | # This applies a special meaning to a null string pattern. Without | |
973 | # this, "$pattern\r\n$gdb_prompt $" will match anything, including error | |
974 | # messages from commands that should have no output except a new | |
975 | # prompt. With this, only results of a null string will match a null | |
976 | # string pattern. | |
977 | ||
978 | set pattern [lindex $args 1] | |
979 | if [string match $pattern ""] { | |
980 | set pattern [string_to_regexp [lindex $args 0]] | |
981 | } else { | |
982 | set pattern [string_to_regexp [lindex $args 1]] | |
983 | } | |
984 | ||
985 | # It is most natural to write the pattern argument with only | |
986 | # embedded \n's, especially if you are trying to avoid Tcl quoting | |
987 | # problems. But gdb_expect really wants to see \r\n in patterns. So | |
988 | # transform the pattern here. First transform \r\n back to \n, in | |
989 | # case some users of gdb_test_exact already do the right thing. | |
990 | regsub -all "\r\n" $pattern "\n" pattern | |
991 | regsub -all "\n" $pattern "\r\n" pattern | |
992 | if [llength $args]==3 then { | |
993 | set message [lindex $args 2] | |
994 | } else { | |
995 | set message $command | |
996 | } | |
997 | ||
998 | return [gdb_test $command $pattern $message] | |
999 | } | |
1000 | \f | |
1001 | proc gdb_reinitialize_dir { subdir } { | |
1002 | global gdb_prompt | |
1003 | ||
1004 | if [is_remote host] { | |
1005 | return ""; | |
1006 | } | |
1007 | send_gdb "dir\n" | |
1008 | gdb_expect 60 { | |
1009 | -re "Reinitialize source path to empty.*y or n. " { | |
1010 | send_gdb "y\n" | |
1011 | gdb_expect 60 { | |
1012 | -re "Source directories searched.*$gdb_prompt $" { | |
1013 | send_gdb "dir $subdir\n" | |
1014 | gdb_expect 60 { | |
1015 | -re "Source directories searched.*$gdb_prompt $" { | |
1016 | verbose "Dir set to $subdir" | |
1017 | } | |
1018 | -re "$gdb_prompt $" { | |
1019 | perror "Dir \"$subdir\" failed." | |
1020 | } | |
1021 | } | |
1022 | } | |
1023 | -re "$gdb_prompt $" { | |
1024 | perror "Dir \"$subdir\" failed." | |
1025 | } | |
1026 | } | |
1027 | } | |
1028 | -re "$gdb_prompt $" { | |
1029 | perror "Dir \"$subdir\" failed." | |
1030 | } | |
1031 | } | |
1032 | } | |
1033 | ||
1034 | # | |
1035 | # gdb_exit -- exit the GDB, killing the target program if necessary | |
1036 | # | |
1037 | proc default_gdb_exit {} { | |
1038 | global GDB | |
6b8ce727 | 1039 | global INTERNAL_GDBFLAGS GDBFLAGS |
c906108c SS |
1040 | global verbose |
1041 | global gdb_spawn_id; | |
1042 | ||
1043 | gdb_stop_suppressing_tests; | |
1044 | ||
1045 | if ![info exists gdb_spawn_id] { | |
1046 | return; | |
1047 | } | |
1048 | ||
6b8ce727 | 1049 | verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS" |
c906108c SS |
1050 | |
1051 | if { [is_remote host] && [board_info host exists fileid] } { | |
1052 | send_gdb "quit\n"; | |
1053 | gdb_expect 10 { | |
1054 | -re "y or n" { | |
1055 | send_gdb "y\n"; | |
1056 | exp_continue; | |
1057 | } | |
1058 | -re "DOSEXIT code" { } | |
1059 | default { } | |
1060 | } | |
1061 | } | |
1062 | ||
1063 | if ![is_remote host] { | |
1064 | remote_close host; | |
1065 | } | |
1066 | unset gdb_spawn_id | |
1067 | } | |
1068 | ||
3e3ffd2b | 1069 | # Load a file into the debugger. |
2db8e78e | 1070 | # The return value is 0 for success, -1 for failure. |
c906108c | 1071 | # |
2db8e78e MC |
1072 | # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO |
1073 | # to one of these values: | |
3e3ffd2b | 1074 | # |
2db8e78e MC |
1075 | # debug file was loaded successfully and has debug information |
1076 | # nodebug file was loaded successfully and has no debug information | |
1077 | # fail file was not loaded | |
c906108c | 1078 | # |
2db8e78e MC |
1079 | # I tried returning this information as part of the return value, |
1080 | # but ran into a mess because of the many re-implementations of | |
1081 | # gdb_load in config/*.exp. | |
3e3ffd2b | 1082 | # |
2db8e78e MC |
1083 | # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use |
1084 | # this if they can get more information set. | |
3e3ffd2b | 1085 | |
c906108c | 1086 | proc gdb_file_cmd { arg } { |
3e3ffd2b | 1087 | global gdb_prompt |
c906108c | 1088 | global verbose |
c906108c | 1089 | global GDB |
b741e217 DJ |
1090 | global last_loaded_file |
1091 | ||
1092 | set last_loaded_file $arg | |
c906108c | 1093 | |
2db8e78e MC |
1094 | # Set whether debug info was found. |
1095 | # Default to "fail". | |
1096 | global gdb_file_cmd_debug_info | |
1097 | set gdb_file_cmd_debug_info "fail" | |
1098 | ||
c906108c | 1099 | if [is_remote host] { |
3e3ffd2b | 1100 | set arg [remote_download host $arg] |
c906108c | 1101 | if { $arg == "" } { |
2db8e78e MC |
1102 | perror "download failed" |
1103 | return -1 | |
c906108c SS |
1104 | } |
1105 | } | |
1106 | ||
4c42eaff DJ |
1107 | # The file command used to kill the remote target. For the benefit |
1108 | # of the testsuite, preserve this behavior. | |
1109 | send_gdb "kill\n" | |
1110 | gdb_expect 120 { | |
1111 | -re "Kill the program being debugged. .y or n. $" { | |
1112 | send_gdb "y\n" | |
1113 | verbose "\t\tKilling previous program being debugged" | |
1114 | exp_continue | |
1115 | } | |
1116 | -re "$gdb_prompt $" { | |
1117 | # OK. | |
1118 | } | |
1119 | } | |
1120 | ||
c906108c SS |
1121 | send_gdb "file $arg\n" |
1122 | gdb_expect 120 { | |
3e3ffd2b MC |
1123 | -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" { |
1124 | verbose "\t\tLoaded $arg into the $GDB with no debugging symbols" | |
2db8e78e MC |
1125 | set gdb_file_cmd_debug_info "nodebug" |
1126 | return 0 | |
3e3ffd2b | 1127 | } |
c906108c SS |
1128 | -re "Reading symbols from.*done.*$gdb_prompt $" { |
1129 | verbose "\t\tLoaded $arg into the $GDB" | |
2db8e78e MC |
1130 | set gdb_file_cmd_debug_info "debug" |
1131 | return 0 | |
c906108c | 1132 | } |
c906108c SS |
1133 | -re "Load new symbol table from \".*\".*y or n. $" { |
1134 | send_gdb "y\n" | |
1135 | gdb_expect 120 { | |
1136 | -re "Reading symbols from.*done.*$gdb_prompt $" { | |
1137 | verbose "\t\tLoaded $arg with new symbol table into $GDB" | |
2db8e78e MC |
1138 | set gdb_file_cmd_debug_info "debug" |
1139 | return 0 | |
c906108c SS |
1140 | } |
1141 | timeout { | |
2db8e78e MC |
1142 | perror "(timeout) Couldn't load $arg, other program already loaded." |
1143 | return -1 | |
c906108c SS |
1144 | } |
1145 | } | |
1146 | } | |
1147 | -re "No such file or directory.*$gdb_prompt $" { | |
2db8e78e MC |
1148 | perror "($arg) No such file or directory" |
1149 | return -1 | |
c906108c SS |
1150 | } |
1151 | -re "$gdb_prompt $" { | |
2db8e78e MC |
1152 | perror "couldn't load $arg into $GDB." |
1153 | return -1 | |
c906108c SS |
1154 | } |
1155 | timeout { | |
2db8e78e MC |
1156 | perror "couldn't load $arg into $GDB (timed out)." |
1157 | return -1 | |
c906108c SS |
1158 | } |
1159 | eof { | |
1160 | # This is an attempt to detect a core dump, but seems not to | |
1161 | # work. Perhaps we need to match .* followed by eof, in which | |
1162 | # gdb_expect does not seem to have a way to do that. | |
2db8e78e MC |
1163 | perror "couldn't load $arg into $GDB (end of file)." |
1164 | return -1 | |
c906108c SS |
1165 | } |
1166 | } | |
1167 | } | |
1168 | ||
1169 | # | |
1170 | # start gdb -- start gdb running, default procedure | |
1171 | # | |
1172 | # When running over NFS, particularly if running many simultaneous | |
1173 | # tests on different hosts all using the same server, things can | |
1174 | # get really slow. Give gdb at least 3 minutes to start up. | |
1175 | # | |
1176 | proc default_gdb_start { } { | |
1177 | global verbose | |
1178 | global GDB | |
6b8ce727 | 1179 | global INTERNAL_GDBFLAGS GDBFLAGS |
c906108c SS |
1180 | global gdb_prompt |
1181 | global timeout | |
1182 | global gdb_spawn_id; | |
6c7a06a3 | 1183 | global env |
c906108c SS |
1184 | |
1185 | gdb_stop_suppressing_tests; | |
1186 | ||
6c7a06a3 TT |
1187 | set env(LC_CTYPE) C |
1188 | ||
4662c76e JK |
1189 | # Don't let a .inputrc file or an existing setting of INPUTRC mess up |
1190 | # the test results. Even if /dev/null doesn't exist on the particular | |
1191 | # platform, the readline library will use the default setting just by | |
1192 | # failing to open the file. OTOH, opening /dev/null successfully will | |
1193 | # also result in the default settings being used since nothing will be | |
1194 | # read from this file. | |
1195 | set env(INPUTRC) "/dev/null" | |
1196 | ||
1197 | # The gdb.base/readline.exp arrow key test relies on the standard VT100 | |
1198 | # bindings, so make sure that an appropriate terminal is selected. | |
1199 | # The same bug doesn't show up if we use ^P / ^N instead. | |
1200 | set env(TERM) "vt100" | |
1201 | ||
6b8ce727 | 1202 | verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS" |
c906108c SS |
1203 | |
1204 | if [info exists gdb_spawn_id] { | |
1205 | return 0; | |
1206 | } | |
1207 | ||
1208 | if ![is_remote host] { | |
1209 | if { [which $GDB] == 0 } then { | |
1210 | perror "$GDB does not exist." | |
1211 | exit 1 | |
1212 | } | |
1213 | } | |
6b8ce727 | 1214 | set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"]; |
c906108c SS |
1215 | if { $res < 0 || $res == "" } { |
1216 | perror "Spawning $GDB failed." | |
1217 | return 1; | |
1218 | } | |
1219 | gdb_expect 360 { | |
1220 | -re "\[\r\n\]$gdb_prompt $" { | |
1221 | verbose "GDB initialized." | |
1222 | } | |
1223 | -re "$gdb_prompt $" { | |
1224 | perror "GDB never initialized." | |
1225 | return -1 | |
1226 | } | |
1227 | timeout { | |
1228 | perror "(timeout) GDB never initialized after 10 seconds." | |
1229 | remote_close host; | |
1230 | return -1 | |
1231 | } | |
1232 | } | |
1233 | set gdb_spawn_id -1; | |
1234 | # force the height to "unlimited", so no pagers get used | |
1235 | ||
1236 | send_gdb "set height 0\n" | |
1237 | gdb_expect 10 { | |
1238 | -re "$gdb_prompt $" { | |
1239 | verbose "Setting height to 0." 2 | |
1240 | } | |
1241 | timeout { | |
1242 | warning "Couldn't set the height to 0" | |
1243 | } | |
1244 | } | |
1245 | # force the width to "unlimited", so no wraparound occurs | |
1246 | send_gdb "set width 0\n" | |
1247 | gdb_expect 10 { | |
1248 | -re "$gdb_prompt $" { | |
1249 | verbose "Setting width to 0." 2 | |
1250 | } | |
1251 | timeout { | |
1252 | warning "Couldn't set the width to 0." | |
1253 | } | |
1254 | } | |
1255 | return 0; | |
1256 | } | |
1257 | ||
ec3c07fc NS |
1258 | # Examine the output of compilation to determine whether compilation |
1259 | # failed or not. If it failed determine whether it is due to missing | |
1260 | # compiler or due to compiler error. Report pass, fail or unsupported | |
1261 | # as appropriate | |
1262 | ||
1263 | proc gdb_compile_test {src output} { | |
1264 | if { $output == "" } { | |
1265 | pass "compilation [file tail $src]" | |
1266 | } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } { | |
1267 | unsupported "compilation [file tail $src]" | |
1268 | } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } { | |
1269 | unsupported "compilation [file tail $src]" | |
6bb85cd1 DE |
1270 | } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } { |
1271 | unsupported "compilation [file tail $src]" | |
ec3c07fc NS |
1272 | } else { |
1273 | verbose -log "compilation failed: $output" 2 | |
1274 | fail "compilation [file tail $src]" | |
1275 | } | |
1276 | } | |
1277 | ||
d4f3574e SS |
1278 | # Return a 1 for configurations for which we don't even want to try to |
1279 | # test C++. | |
1280 | ||
1281 | proc skip_cplus_tests {} { | |
d4f3574e SS |
1282 | if { [istarget "h8300-*-*"] } { |
1283 | return 1 | |
1284 | } | |
81d2cbae | 1285 | |
1146c7f1 SC |
1286 | # The C++ IO streams are too large for HC11/HC12 and are thus not |
1287 | # available. The gdb C++ tests use them and don't compile. | |
1288 | if { [istarget "m6811-*-*"] } { | |
1289 | return 1 | |
1290 | } | |
1291 | if { [istarget "m6812-*-*"] } { | |
1292 | return 1 | |
1293 | } | |
d4f3574e SS |
1294 | return 0 |
1295 | } | |
1296 | ||
759f0f0b PA |
1297 | # Return a 1 for configurations for which don't have both C++ and the STL. |
1298 | ||
1299 | proc skip_stl_tests {} { | |
1300 | # Symbian supports the C++ language, but the STL is missing | |
1301 | # (both headers and libraries). | |
1302 | if { [istarget "arm*-*-symbianelf*"] } { | |
1303 | return 1 | |
1304 | } | |
1305 | ||
1306 | return [skip_cplus_tests] | |
1307 | } | |
1308 | ||
89a237cb MC |
1309 | # Return a 1 if I don't even want to try to test FORTRAN. |
1310 | ||
1311 | proc skip_fortran_tests {} { | |
1312 | return 0 | |
1313 | } | |
1314 | ||
ec3c07fc NS |
1315 | # Return a 1 if I don't even want to try to test ada. |
1316 | ||
1317 | proc skip_ada_tests {} { | |
1318 | return 0 | |
1319 | } | |
1320 | ||
1321 | # Return a 1 if I don't even want to try to test java. | |
1322 | ||
1323 | proc skip_java_tests {} { | |
1324 | return 0 | |
1325 | } | |
1326 | ||
f6bbabf0 PM |
1327 | # Return a 1 for configurations that do not support Python scripting. |
1328 | ||
1329 | proc skip_python_tests {} { | |
1330 | global gdb_prompt | |
1331 | gdb_test_multiple "python print 'test'" "verify python support" { | |
1332 | -re "not supported.*$gdb_prompt $" { | |
1333 | unsupported "Python support is disabled." | |
1334 | return 1 | |
1335 | } | |
1336 | -re "$gdb_prompt $" {} | |
1337 | } | |
1338 | ||
1339 | return 0 | |
1340 | } | |
1341 | ||
93f02886 DJ |
1342 | # Return a 1 if we should skip shared library tests. |
1343 | ||
1344 | proc skip_shlib_tests {} { | |
1345 | # Run the shared library tests on native systems. | |
1346 | if {[isnative]} { | |
1347 | return 0 | |
1348 | } | |
1349 | ||
1350 | # An abbreviated list of remote targets where we should be able to | |
1351 | # run shared library tests. | |
1352 | if {([istarget *-*-linux*] | |
1353 | || [istarget *-*-*bsd*] | |
1354 | || [istarget *-*-solaris2*] | |
1355 | || [istarget arm*-*-symbianelf*] | |
1356 | || [istarget *-*-mingw*] | |
1357 | || [istarget *-*-cygwin*] | |
1358 | || [istarget *-*-pe*])} { | |
1359 | return 0 | |
1360 | } | |
1361 | ||
1362 | return 1 | |
1363 | } | |
1364 | ||
3c95e6af PG |
1365 | # Run a test on the target to see if it supports vmx hardware. Return 0 if so, |
1366 | # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite. | |
1367 | ||
1368 | proc skip_altivec_tests {} { | |
1369 | global skip_vmx_tests_saved | |
1370 | global srcdir subdir gdb_prompt | |
1371 | ||
1372 | # Use the cached value, if it exists. | |
1373 | set me "skip_altivec_tests" | |
1374 | if [info exists skip_vmx_tests_saved] { | |
1375 | verbose "$me: returning saved $skip_vmx_tests_saved" 2 | |
1376 | return $skip_vmx_tests_saved | |
1377 | } | |
1378 | ||
1379 | # Some simulators are known to not support VMX instructions. | |
1380 | if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } { | |
1381 | verbose "$me: target known to not support VMX, returning 1" 2 | |
476308bf | 1382 | return [set skip_vmx_tests_saved 1] |
3c95e6af PG |
1383 | } |
1384 | ||
1385 | # Make sure we have a compiler that understands altivec. | |
fc91c6c2 | 1386 | set compile_flags {debug nowarnings} |
3c95e6af PG |
1387 | if [get_compiler_info not-used] { |
1388 | warning "Could not get compiler info" | |
1389 | return 1 | |
1390 | } | |
1391 | if [test_compiler_info gcc*] { | |
1392 | set compile_flags "$compile_flags additional_flags=-maltivec" | |
1393 | } elseif [test_compiler_info xlc*] { | |
1394 | set compile_flags "$compile_flags additional_flags=-qaltivec" | |
1395 | } else { | |
1396 | verbose "Could not compile with altivec support, returning 1" 2 | |
1397 | return 1 | |
1398 | } | |
1399 | ||
1400 | # Set up, compile, and execute a test program containing VMX instructions. | |
1401 | # Include the current process ID in the file names to prevent conflicts | |
1402 | # with invocations for multiple testsuites. | |
1403 | set src vmx[pid].c | |
1404 | set exe vmx[pid].x | |
1405 | ||
1406 | set f [open $src "w"] | |
1407 | puts $f "int main() {" | |
1408 | puts $f "#ifdef __MACH__" | |
1409 | puts $f " asm volatile (\"vor v0,v0,v0\");" | |
1410 | puts $f "#else" | |
1411 | puts $f " asm volatile (\"vor 0,0,0\");" | |
1412 | puts $f "#endif" | |
1413 | puts $f " return 0; }" | |
1414 | close $f | |
1415 | ||
1416 | verbose "$me: compiling testfile $src" 2 | |
1417 | set lines [gdb_compile $src $exe executable $compile_flags] | |
1418 | file delete $src | |
1419 | ||
1420 | if ![string match "" $lines] then { | |
1421 | verbose "$me: testfile compilation failed, returning 1" 2 | |
1422 | return [set skip_vmx_tests_saved 1] | |
1423 | } | |
1424 | ||
1425 | # No error message, compilation succeeded so now run it via gdb. | |
1426 | ||
1427 | gdb_exit | |
1428 | gdb_start | |
1429 | gdb_reinitialize_dir $srcdir/$subdir | |
1430 | gdb_load "$exe" | |
1431 | gdb_run_cmd | |
1432 | gdb_expect { | |
1433 | -re ".*Illegal instruction.*${gdb_prompt} $" { | |
1434 | verbose -log "\n$me altivec hardware not detected" | |
1435 | set skip_vmx_tests_saved 1 | |
1436 | } | |
1437 | -re ".*Program exited normally.*${gdb_prompt} $" { | |
1438 | verbose -log "\n$me: altivec hardware detected" | |
1439 | set skip_vmx_tests_saved 0 | |
1440 | } | |
1441 | default { | |
1442 | warning "\n$me: default case taken" | |
1443 | set skip_vmx_tests_saved 1 | |
1444 | } | |
1445 | } | |
1446 | gdb_exit | |
1447 | remote_file build delete $exe | |
1448 | ||
1449 | verbose "$me: returning $skip_vmx_tests_saved" 2 | |
1450 | return $skip_vmx_tests_saved | |
1451 | } | |
1452 | ||
604c2f83 LM |
1453 | # Run a test on the target to see if it supports vmx hardware. Return 0 if so, |
1454 | # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite. | |
1455 | ||
1456 | proc skip_vsx_tests {} { | |
1457 | global skip_vsx_tests_saved | |
1458 | global srcdir subdir gdb_prompt | |
1459 | ||
1460 | # Use the cached value, if it exists. | |
1461 | set me "skip_vsx_tests" | |
1462 | if [info exists skip_vsx_tests_saved] { | |
1463 | verbose "$me: returning saved $skip_vsx_tests_saved" 2 | |
1464 | return $skip_vsx_tests_saved | |
1465 | } | |
1466 | ||
1467 | # Some simulators are known to not support Altivec instructions, so | |
1468 | # they won't support VSX instructions as well. | |
1469 | if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } { | |
1470 | verbose "$me: target known to not support VSX, returning 1" 2 | |
1471 | return [set skip_vsx_tests_saved 1] | |
1472 | } | |
1473 | ||
1474 | # Make sure we have a compiler that understands altivec. | |
1475 | set compile_flags {debug nowarnings quiet} | |
1476 | if [get_compiler_info not-used] { | |
1477 | warning "Could not get compiler info" | |
1478 | return 1 | |
1479 | } | |
1480 | if [test_compiler_info gcc*] { | |
1481 | set compile_flags "$compile_flags additional_flags=-mvsx" | |
1482 | } elseif [test_compiler_info xlc*] { | |
1483 | set compile_flags "$compile_flags additional_flags=-qvsx" | |
1484 | } else { | |
1485 | verbose "Could not compile with vsx support, returning 1" 2 | |
1486 | return 1 | |
1487 | } | |
1488 | ||
1489 | set src vsx[pid].c | |
1490 | set exe vsx[pid].x | |
1491 | ||
1492 | set f [open $src "w"] | |
1493 | puts $f "int main() {" | |
1494 | puts $f "#ifdef __MACH__" | |
1495 | puts $f " asm volatile (\"lxvd2x v0,v0,v0\");" | |
1496 | puts $f "#else" | |
1497 | puts $f " asm volatile (\"lxvd2x 0,0,0\");" | |
1498 | puts $f "#endif" | |
1499 | puts $f " return 0; }" | |
1500 | close $f | |
1501 | ||
1502 | verbose "$me: compiling testfile $src" 2 | |
1503 | set lines [gdb_compile $src $exe executable $compile_flags] | |
1504 | file delete $src | |
1505 | ||
1506 | if ![string match "" $lines] then { | |
1507 | verbose "$me: testfile compilation failed, returning 1" 2 | |
1508 | return [set skip_vsx_tests_saved 1] | |
1509 | } | |
1510 | ||
1511 | # No error message, compilation succeeded so now run it via gdb. | |
1512 | ||
1513 | gdb_exit | |
1514 | gdb_start | |
1515 | gdb_reinitialize_dir $srcdir/$subdir | |
1516 | gdb_load "$exe" | |
1517 | gdb_run_cmd | |
1518 | gdb_expect { | |
1519 | -re ".*Illegal instruction.*${gdb_prompt} $" { | |
1520 | verbose -log "\n$me VSX hardware not detected" | |
1521 | set skip_vsx_tests_saved 1 | |
1522 | } | |
1523 | -re ".*Program exited normally.*${gdb_prompt} $" { | |
1524 | verbose -log "\n$me: VSX hardware detected" | |
1525 | set skip_vsx_tests_saved 0 | |
1526 | } | |
1527 | default { | |
1528 | warning "\n$me: default case taken" | |
1529 | set skip_vsx_tests_saved 1 | |
1530 | } | |
1531 | } | |
1532 | gdb_exit | |
1533 | remote_file build delete $exe | |
1534 | ||
1535 | verbose "$me: returning $skip_vsx_tests_saved" 2 | |
1536 | return $skip_vsx_tests_saved | |
1537 | } | |
1538 | ||
7a292a7a SS |
1539 | # Skip all the tests in the file if you are not on an hppa running |
1540 | # hpux target. | |
1541 | ||
1542 | proc skip_hp_tests {} { | |
1543 | eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ] | |
c906108c SS |
1544 | verbose "Skip hp tests is $skip_hp" |
1545 | return $skip_hp | |
1546 | } | |
1547 | ||
edb3359d DJ |
1548 | # Return whether we should skip tests for showing inlined functions in |
1549 | # backtraces. Requires get_compiler_info and get_debug_format. | |
1550 | ||
1551 | proc skip_inline_frame_tests {} { | |
1552 | # GDB only recognizes inlining information in DWARF 2 (DWARF 3). | |
1553 | if { ! [test_debug_format "DWARF 2"] } { | |
1554 | return 1 | |
1555 | } | |
1556 | ||
1557 | # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line. | |
1558 | if { ([test_compiler_info "gcc-2-*"] | |
1559 | || [test_compiler_info "gcc-3-*"] | |
1560 | || [test_compiler_info "gcc-4-0-*"]) } { | |
1561 | return 1 | |
1562 | } | |
1563 | ||
1564 | return 0 | |
1565 | } | |
1566 | ||
1567 | # Return whether we should skip tests for showing variables from | |
1568 | # inlined functions. Requires get_compiler_info and get_debug_format. | |
1569 | ||
1570 | proc skip_inline_var_tests {} { | |
1571 | # GDB only recognizes inlining information in DWARF 2 (DWARF 3). | |
1572 | if { ! [test_debug_format "DWARF 2"] } { | |
1573 | return 1 | |
1574 | } | |
1575 | ||
1576 | return 0 | |
1577 | } | |
1578 | ||
94b8e876 MC |
1579 | set compiler_info "unknown" |
1580 | set gcc_compiled 0 | |
1581 | set hp_cc_compiler 0 | |
1582 | set hp_aCC_compiler 0 | |
94b8e876 MC |
1583 | |
1584 | # Figure out what compiler I am using. | |
1585 | # | |
1586 | # BINFILE is a "compiler information" output file. This implementation | |
1587 | # does not use BINFILE. | |
1588 | # | |
1589 | # ARGS can be empty or "C++". If empty, "C" is assumed. | |
1590 | # | |
1591 | # There are several ways to do this, with various problems. | |
1592 | # | |
1593 | # [ gdb_compile -E $ifile -o $binfile.ci ] | |
1594 | # source $binfile.ci | |
1595 | # | |
1596 | # Single Unix Spec v3 says that "-E -o ..." together are not | |
1597 | # specified. And in fact, the native compiler on hp-ux 11 (among | |
1598 | # others) does not work with "-E -o ...". Most targets used to do | |
1599 | # this, and it mostly worked, because it works with gcc. | |
1600 | # | |
1601 | # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ] | |
1602 | # source $binfile.ci | |
1603 | # | |
1604 | # This avoids the problem with -E and -o together. This almost works | |
1605 | # if the build machine is the same as the host machine, which is | |
1606 | # usually true of the targets which are not gcc. But this code does | |
1607 | # not figure which compiler to call, and it always ends up using the C | |
1608 | # compiler. Not good for setting hp_aCC_compiler. Targets | |
1609 | # hppa*-*-hpux* and mips*-*-irix* used to do this. | |
1610 | # | |
1611 | # [ gdb_compile -E $ifile > $binfile.ci ] | |
1612 | # source $binfile.ci | |
1613 | # | |
1614 | # dejagnu target_compile says that it supports output redirection, | |
1615 | # but the code is completely different from the normal path and I | |
1616 | # don't want to sweep the mines from that path. So I didn't even try | |
1617 | # this. | |
1618 | # | |
1619 | # set cppout [ gdb_compile $ifile "" preprocess $args quiet ] | |
1620 | # eval $cppout | |
1621 | # | |
1622 | # I actually do this for all targets now. gdb_compile runs the right | |
1623 | # compiler, and TCL captures the output, and I eval the output. | |
1624 | # | |
1625 | # Unfortunately, expect logs the output of the command as it goes by, | |
1626 | # and dejagnu helpfully prints a second copy of it right afterwards. | |
1627 | # So I turn off expect logging for a moment. | |
1628 | # | |
1629 | # [ gdb_compile $ifile $ciexe_file executable $args ] | |
1630 | # [ remote_exec $ciexe_file ] | |
1631 | # [ source $ci_file.out ] | |
1632 | # | |
1633 | # I could give up on -E and just do this. | |
1634 | # I didn't get desperate enough to try this. | |
1635 | # | |
1636 | # -- chastain 2004-01-06 | |
853d6e5b | 1637 | |
c906108c | 1638 | proc get_compiler_info {binfile args} { |
94b8e876 | 1639 | # For compiler.c and compiler.cc |
c906108c | 1640 | global srcdir |
94b8e876 MC |
1641 | |
1642 | # I am going to play with the log to keep noise out. | |
1643 | global outdir | |
1644 | global tool | |
1645 | ||
1646 | # These come from compiler.c or compiler.cc | |
853d6e5b | 1647 | global compiler_info |
4f70a4c9 MC |
1648 | |
1649 | # Legacy global data symbols. | |
94b8e876 MC |
1650 | global gcc_compiled |
1651 | global hp_cc_compiler | |
1652 | global hp_aCC_compiler | |
c906108c | 1653 | |
94b8e876 MC |
1654 | # Choose which file to preprocess. |
1655 | set ifile "${srcdir}/lib/compiler.c" | |
1656 | if { [llength $args] > 0 && [lindex $args 0] == "c++" } { | |
1657 | set ifile "${srcdir}/lib/compiler.cc" | |
c906108c | 1658 | } |
085dd6e6 | 1659 | |
94b8e876 MC |
1660 | # Run $ifile through the right preprocessor. |
1661 | # Toggle gdb.log to keep the compiler output out of the log. | |
1662 | log_file | |
e7f86de9 JM |
1663 | if [is_remote host] { |
1664 | # We have to use -E and -o together, despite the comments | |
1665 | # above, because of how DejaGnu handles remote host testing. | |
1666 | set ppout "$outdir/compiler.i" | |
1667 | gdb_compile "${ifile}" "$ppout" preprocess [list "$args" quiet] | |
1668 | set file [open $ppout r] | |
1669 | set cppout [read $file] | |
1670 | close $file | |
1671 | } else { | |
1672 | set cppout [ gdb_compile "${ifile}" "" preprocess [list "$args" quiet] ] | |
1673 | } | |
94b8e876 MC |
1674 | log_file -a "$outdir/$tool.log" |
1675 | ||
4f70a4c9 MC |
1676 | # Eval the output. |
1677 | set unknown 0 | |
94b8e876 | 1678 | foreach cppline [ split "$cppout" "\n" ] { |
4f70a4c9 MC |
1679 | if { [ regexp "^#" "$cppline" ] } { |
1680 | # line marker | |
1681 | } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } { | |
1682 | # blank line | |
1683 | } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } { | |
1684 | # eval this line | |
1685 | verbose "get_compiler_info: $cppline" 2 | |
1686 | eval "$cppline" | |
1687 | } else { | |
1688 | # unknown line | |
1689 | verbose -log "get_compiler_info: $cppline" | |
1690 | set unknown 1 | |
94b8e876 | 1691 | } |
085dd6e6 | 1692 | } |
4f70a4c9 MC |
1693 | |
1694 | # Reset to unknown compiler if any diagnostics happened. | |
1695 | if { $unknown } { | |
1696 | set compiler_info "unknown" | |
4f70a4c9 MC |
1697 | } |
1698 | ||
1699 | # Set the legacy symbols. | |
1700 | set gcc_compiled 0 | |
1701 | set hp_cc_compiler 0 | |
1702 | set hp_aCC_compiler 0 | |
1703 | if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 } | |
1704 | if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 } | |
1705 | if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 } | |
1706 | if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 } | |
1707 | if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 } | |
1708 | if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 } | |
1709 | if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 } | |
1710 | ||
1711 | # Log what happened. | |
94b8e876 | 1712 | verbose -log "get_compiler_info: $compiler_info" |
085dd6e6 JM |
1713 | |
1714 | # Most compilers will evaluate comparisons and other boolean | |
1715 | # operations to 0 or 1. | |
1716 | uplevel \#0 { set true 1 } | |
1717 | uplevel \#0 { set false 0 } | |
1718 | ||
94b8e876 MC |
1719 | # Use of aCC results in boolean results being displayed as |
1720 | # "true" or "false" | |
1721 | if { $hp_aCC_compiler } { | |
1722 | uplevel \#0 { set true true } | |
1723 | uplevel \#0 { set false false } | |
085dd6e6 JM |
1724 | } |
1725 | ||
c906108c SS |
1726 | return 0; |
1727 | } | |
1728 | ||
9b593790 | 1729 | proc test_compiler_info { {compiler ""} } { |
853d6e5b | 1730 | global compiler_info |
6e87504d PG |
1731 | |
1732 | # if no arg, return the compiler_info string | |
1733 | ||
1734 | if [string match "" $compiler] { | |
1735 | if [info exists compiler_info] { | |
1736 | return $compiler_info | |
1737 | } else { | |
1738 | perror "No compiler info found." | |
1739 | } | |
1740 | } | |
1741 | ||
853d6e5b AC |
1742 | return [string match $compiler $compiler_info] |
1743 | } | |
1744 | ||
f6838f81 DJ |
1745 | proc current_target_name { } { |
1746 | global target_info | |
1747 | if [info exists target_info(target,name)] { | |
1748 | set answer $target_info(target,name) | |
1749 | } else { | |
1750 | set answer "" | |
1751 | } | |
1752 | return $answer | |
1753 | } | |
1754 | ||
f1c47eb2 | 1755 | set gdb_wrapper_initialized 0 |
f6838f81 | 1756 | set gdb_wrapper_target "" |
f1c47eb2 MS |
1757 | |
1758 | proc gdb_wrapper_init { args } { | |
1759 | global gdb_wrapper_initialized; | |
1760 | global gdb_wrapper_file; | |
1761 | global gdb_wrapper_flags; | |
f6838f81 | 1762 | global gdb_wrapper_target |
f1c47eb2 MS |
1763 | |
1764 | if { $gdb_wrapper_initialized == 1 } { return; } | |
1765 | ||
1766 | if {[target_info exists needs_status_wrapper] && \ | |
277254ba | 1767 | [target_info needs_status_wrapper] != "0"} { |
f1c47eb2 MS |
1768 | set result [build_wrapper "testglue.o"]; |
1769 | if { $result != "" } { | |
1770 | set gdb_wrapper_file [lindex $result 0]; | |
1771 | set gdb_wrapper_flags [lindex $result 1]; | |
1772 | } else { | |
1773 | warning "Status wrapper failed to build." | |
1774 | } | |
1775 | } | |
1776 | set gdb_wrapper_initialized 1 | |
f6838f81 | 1777 | set gdb_wrapper_target [current_target_name] |
f1c47eb2 MS |
1778 | } |
1779 | ||
f747e0ce PA |
1780 | # Some targets need to always link a special object in. Save its path here. |
1781 | global gdb_saved_set_unbuffered_mode_obj | |
1782 | set gdb_saved_set_unbuffered_mode_obj "" | |
1783 | ||
c906108c SS |
1784 | proc gdb_compile {source dest type options} { |
1785 | global GDB_TESTCASE_OPTIONS; | |
f1c47eb2 MS |
1786 | global gdb_wrapper_file; |
1787 | global gdb_wrapper_flags; | |
1788 | global gdb_wrapper_initialized; | |
f747e0ce PA |
1789 | global srcdir |
1790 | global objdir | |
1791 | global gdb_saved_set_unbuffered_mode_obj | |
c906108c | 1792 | |
695e2681 MK |
1793 | set outdir [file dirname $dest] |
1794 | ||
1795 | # Add platform-specific options if a shared library was specified using | |
1796 | # "shlib=librarypath" in OPTIONS. | |
1797 | set new_options "" | |
1798 | set shlib_found 0 | |
bdf7534a | 1799 | set shlib_load 0 |
695e2681 | 1800 | foreach opt $options { |
57bf0e56 DJ |
1801 | if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] { |
1802 | if [test_compiler_info "xlc-*"] { | |
93f02886 DJ |
1803 | # IBM xlc compiler doesn't accept shared library named other |
1804 | # than .so: use "-Wl," to bypass this | |
1805 | lappend source "-Wl,$shlib_name" | |
1806 | } elseif { ([istarget "*-*-mingw*"] | |
1807 | || [istarget *-*-cygwin*] | |
1808 | || [istarget *-*-pe*])} { | |
1809 | lappend source "${shlib_name}.a" | |
57bf0e56 DJ |
1810 | } else { |
1811 | lappend source $shlib_name | |
1812 | } | |
0413d738 | 1813 | if { $shlib_found == 0 } { |
57bf0e56 | 1814 | set shlib_found 1 |
0413d738 PA |
1815 | if { ([istarget "*-*-mingw*"] |
1816 | || [istarget *-*-cygwin*]) } { | |
bb61102d | 1817 | lappend new_options "additional_flags=-Wl,--enable-auto-import" |
0413d738 | 1818 | } |
57bf0e56 | 1819 | } |
b0f4b84b | 1820 | } elseif { $opt == "shlib_load" } { |
bdf7534a | 1821 | set shlib_load 1 |
57bf0e56 DJ |
1822 | } else { |
1823 | lappend new_options $opt | |
1824 | } | |
695e2681 | 1825 | } |
bdf7534a NF |
1826 | |
1827 | # We typically link to shared libraries using an absolute path, and | |
1828 | # that's how they are found at runtime. If we are going to | |
1829 | # dynamically load one by basename, we must specify rpath. If we | |
1830 | # are using a remote host, DejaGNU will link to the shared library | |
1831 | # using a relative path, so again we must specify an rpath. | |
1832 | if { $shlib_load || ($shlib_found && [is_remote host]) } { | |
1833 | if { ([istarget "*-*-mingw*"] | |
1834 | || [istarget *-*-cygwin*] | |
1835 | || [istarget *-*-pe*] | |
bdf7534a NF |
1836 | || [istarget hppa*-*-hpux*])} { |
1837 | # Do not need anything. | |
1838 | } elseif { [istarget *-*-openbsd*] } { | |
1839 | lappend new_options "additional_flags=-Wl,-rpath,${outdir}" | |
759f0f0b PA |
1840 | } elseif { [istarget arm*-*-symbianelf*] } { |
1841 | if { $shlib_load } { | |
1842 | lappend new_options "libs=-ldl" | |
1843 | } | |
bdf7534a NF |
1844 | } else { |
1845 | if { $shlib_load } { | |
1846 | lappend new_options "libs=-ldl" | |
1847 | } | |
1848 | lappend new_options "additional_flags=-Wl,-rpath,\\\$ORIGIN" | |
1849 | } | |
1850 | } | |
695e2681 | 1851 | set options $new_options |
57bf0e56 | 1852 | |
c906108c SS |
1853 | if [target_info exists gdb_stub] { |
1854 | set options2 { "additional_flags=-Dusestubs" } | |
1855 | lappend options "libs=[target_info gdb_stub]"; | |
1856 | set options [concat $options2 $options] | |
1857 | } | |
1858 | if [target_info exists is_vxworks] { | |
1859 | set options2 { "additional_flags=-Dvxworks" } | |
1860 | lappend options "libs=[target_info gdb_stub]"; | |
1861 | set options [concat $options2 $options] | |
1862 | } | |
1863 | if [info exists GDB_TESTCASE_OPTIONS] { | |
1864 | lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"; | |
1865 | } | |
1866 | verbose "options are $options" | |
1867 | verbose "source is $source $dest $type $options" | |
1868 | ||
f1c47eb2 MS |
1869 | if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init } |
1870 | ||
1871 | if {[target_info exists needs_status_wrapper] && \ | |
1872 | [target_info needs_status_wrapper] != "0" && \ | |
1873 | [info exists gdb_wrapper_file]} { | |
1874 | lappend options "libs=${gdb_wrapper_file}" | |
1875 | lappend options "ldflags=${gdb_wrapper_flags}" | |
1876 | } | |
1877 | ||
fc91c6c2 PB |
1878 | # Replace the "nowarnings" option with the appropriate additional_flags |
1879 | # to disable compiler warnings. | |
1880 | set nowarnings [lsearch -exact $options nowarnings] | |
1881 | if {$nowarnings != -1} { | |
1882 | if [target_info exists gdb,nowarnings_flag] { | |
1883 | set flag "additional_flags=[target_info gdb,nowarnings_flag]" | |
1884 | } else { | |
1885 | set flag "additional_flags=-w" | |
1886 | } | |
1887 | set options [lreplace $options $nowarnings $nowarnings $flag] | |
1888 | } | |
1889 | ||
f747e0ce PA |
1890 | if { $type == "executable" } { |
1891 | if { ([istarget "*-*-mingw*"] | |
56643c5e | 1892 | || [istarget "*-*-*djgpp"] |
f747e0ce PA |
1893 | || [istarget "*-*-cygwin*"])} { |
1894 | # Force output to unbuffered mode, by linking in an object file | |
1895 | # with a global contructor that calls setvbuf. | |
1896 | # | |
1897 | # Compile the special object seperatelly for two reasons: | |
1898 | # 1) Insulate it from $options. | |
1899 | # 2) Avoid compiling it for every gdb_compile invocation, | |
1900 | # which is time consuming, especially if we're remote | |
1901 | # host testing. | |
1902 | # | |
1903 | if { $gdb_saved_set_unbuffered_mode_obj == "" } { | |
1904 | verbose "compiling gdb_saved_set_unbuffered_obj" | |
1905 | set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c | |
1906 | set unbuf_obj ${objdir}/set_unbuffered_mode.o | |
1907 | ||
1908 | set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}] | |
1909 | if { $result != "" } { | |
1910 | return $result | |
1911 | } | |
1912 | ||
1913 | set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o | |
1914 | # Link a copy of the output object, because the | |
1915 | # original may be automatically deleted. | |
1916 | remote_exec host "cp -f $unbuf_obj $gdb_saved_set_unbuffered_mode_obj" | |
1917 | } else { | |
1918 | verbose "gdb_saved_set_unbuffered_obj already compiled" | |
1919 | } | |
1920 | ||
1921 | # Rely on the internal knowledge that the global ctors are ran in | |
1922 | # reverse link order. In that case, we can use ldflags to | |
1923 | # avoid copying the object file to the host multiple | |
1924 | # times. | |
ace5c364 PM |
1925 | # This object can only be added if standard libraries are |
1926 | # used. Thus, we need to disable it if -nostdlib option is used | |
1927 | if {[lsearch -regexp $options "-nostdlib"] < 0 } { | |
1928 | lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj" | |
1929 | } | |
f747e0ce PA |
1930 | } |
1931 | } | |
1932 | ||
c906108c | 1933 | set result [target_compile $source $dest $type $options]; |
93f02886 DJ |
1934 | |
1935 | # Prune uninteresting compiler (and linker) output. | |
1936 | regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result | |
1937 | ||
c906108c SS |
1938 | regsub "\[\r\n\]*$" "$result" "" result; |
1939 | regsub "^\[\r\n\]*" "$result" "" result; | |
ec3c07fc NS |
1940 | |
1941 | if {[lsearch $options quiet] < 0} { | |
1942 | # We shall update this on a per language basis, to avoid | |
1943 | # changing the entire testsuite in one go. | |
1944 | if {[lsearch $options f77] >= 0} { | |
1945 | gdb_compile_test $source $result | |
1946 | } elseif { $result != "" } { | |
1947 | clone_output "gdb compile failed, $result" | |
1948 | } | |
c906108c SS |
1949 | } |
1950 | return $result; | |
1951 | } | |
1952 | ||
b6ff0e81 JB |
1953 | |
1954 | # This is just like gdb_compile, above, except that it tries compiling | |
1955 | # against several different thread libraries, to see which one this | |
1956 | # system has. | |
1957 | proc gdb_compile_pthreads {source dest type options} { | |
0ae67eb3 | 1958 | set built_binfile 0 |
b6ff0e81 | 1959 | set why_msg "unrecognized error" |
24486cb7 | 1960 | foreach lib {-lpthreads -lpthread -lthread ""} { |
b6ff0e81 JB |
1961 | # This kind of wipes out whatever libs the caller may have |
1962 | # set. Or maybe theirs will override ours. How infelicitous. | |
b5ab8ff3 | 1963 | set options_with_lib [concat $options [list libs=$lib quiet]] |
b6ff0e81 JB |
1964 | set ccout [gdb_compile $source $dest $type $options_with_lib] |
1965 | switch -regexp -- $ccout { | |
1966 | ".*no posix threads support.*" { | |
1967 | set why_msg "missing threads include file" | |
1968 | break | |
1969 | } | |
1970 | ".*cannot open -lpthread.*" { | |
1971 | set why_msg "missing runtime threads library" | |
1972 | } | |
1973 | ".*Can't find library for -lpthread.*" { | |
1974 | set why_msg "missing runtime threads library" | |
1975 | } | |
1976 | {^$} { | |
1977 | pass "successfully compiled posix threads test case" | |
1978 | set built_binfile 1 | |
1979 | break | |
1980 | } | |
1981 | } | |
1982 | } | |
0ae67eb3 | 1983 | if {!$built_binfile} { |
b6ff0e81 JB |
1984 | unsupported "Couldn't compile $source: ${why_msg}" |
1985 | return -1 | |
1986 | } | |
57bf0e56 DJ |
1987 | } |
1988 | ||
1989 | # Build a shared library from SOURCES. You must use get_compiler_info | |
1990 | # first. | |
1991 | ||
1992 | proc gdb_compile_shlib {sources dest options} { | |
1993 | set obj_options $options | |
1994 | ||
1995 | switch -glob [test_compiler_info] { | |
1996 | "xlc-*" { | |
1997 | lappend obj_options "additional_flags=-qpic" | |
1998 | } | |
1999 | "gcc-*" { | |
2000 | if { !([istarget "powerpc*-*-aix*"] | |
227c54da DJ |
2001 | || [istarget "rs6000*-*-aix*"] |
2002 | || [istarget "*-*-cygwin*"] | |
2003 | || [istarget "*-*-mingw*"] | |
2004 | || [istarget "*-*-pe*"]) } { | |
57bf0e56 DJ |
2005 | lappend obj_options "additional_flags=-fpic" |
2006 | } | |
2007 | } | |
2008 | default { | |
2009 | switch -glob [istarget] { | |
2010 | "hppa*-hp-hpux*" { | |
2011 | lappend obj_options "additional_flags=+z" | |
2012 | } | |
2013 | "mips-sgi-irix*" { | |
2014 | # Disable SGI compiler's implicit -Dsgi | |
2015 | lappend obj_options "additional_flags=-Usgi" | |
2016 | } | |
2017 | default { | |
2018 | # don't know what the compiler is... | |
2019 | } | |
2020 | } | |
2021 | } | |
2022 | } | |
2023 | ||
2024 | set outdir [file dirname $dest] | |
2025 | set objects "" | |
2026 | foreach source $sources { | |
2027 | set sourcebase [file tail $source] | |
2028 | if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} { | |
2029 | return -1 | |
2030 | } | |
2031 | lappend objects ${outdir}/${sourcebase}.o | |
2032 | } | |
2033 | ||
2034 | if [istarget "hppa*-*-hpux*"] { | |
2035 | remote_exec build "ld -b ${objects} -o ${dest}" | |
2036 | } else { | |
2037 | set link_options $options | |
2038 | if [test_compiler_info "xlc-*"] { | |
2039 | lappend link_options "additional_flags=-qmkshrobj" | |
2040 | } else { | |
2041 | lappend link_options "additional_flags=-shared" | |
93f02886 DJ |
2042 | |
2043 | if { ([istarget "*-*-mingw*"] | |
2044 | || [istarget *-*-cygwin*] | |
2045 | || [istarget *-*-pe*])} { | |
2046 | lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a" | |
2047 | } | |
57bf0e56 DJ |
2048 | } |
2049 | if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} { | |
2050 | return -1 | |
2051 | } | |
2052 | } | |
b6ff0e81 JB |
2053 | } |
2054 | ||
130cacce AF |
2055 | # This is just like gdb_compile_pthreads, above, except that we always add the |
2056 | # objc library for compiling Objective-C programs | |
2057 | proc gdb_compile_objc {source dest type options} { | |
2058 | set built_binfile 0 | |
2059 | set why_msg "unrecognized error" | |
2060 | foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} { | |
2061 | # This kind of wipes out whatever libs the caller may have | |
2062 | # set. Or maybe theirs will override ours. How infelicitous. | |
2063 | if { $lib == "solaris" } { | |
2064 | set lib "-lpthread -lposix4" | |
2065 | } | |
2066 | if { $lib != "-lobjc" } { | |
2067 | set lib "-lobjc $lib" | |
2068 | } | |
2069 | set options_with_lib [concat $options [list libs=$lib quiet]] | |
2070 | set ccout [gdb_compile $source $dest $type $options_with_lib] | |
2071 | switch -regexp -- $ccout { | |
2072 | ".*no posix threads support.*" { | |
2073 | set why_msg "missing threads include file" | |
2074 | break | |
2075 | } | |
2076 | ".*cannot open -lpthread.*" { | |
2077 | set why_msg "missing runtime threads library" | |
2078 | } | |
2079 | ".*Can't find library for -lpthread.*" { | |
2080 | set why_msg "missing runtime threads library" | |
2081 | } | |
2082 | {^$} { | |
2083 | pass "successfully compiled objc with posix threads test case" | |
2084 | set built_binfile 1 | |
2085 | break | |
2086 | } | |
2087 | } | |
2088 | } | |
2089 | if {!$built_binfile} { | |
2090 | unsupported "Couldn't compile $source: ${why_msg}" | |
2091 | return -1 | |
2092 | } | |
2093 | } | |
2094 | ||
c906108c SS |
2095 | proc send_gdb { string } { |
2096 | global suppress_flag; | |
2097 | if { $suppress_flag } { | |
2098 | return "suppressed"; | |
2099 | } | |
2100 | return [remote_send host "$string"]; | |
2101 | } | |
2102 | ||
2103 | # | |
2104 | # | |
2105 | ||
2106 | proc gdb_expect { args } { | |
2107 | if { [llength $args] == 2 && [lindex $args 0] != "-re" } { | |
2f34202f | 2108 | set atimeout [lindex $args 0]; |
c906108c SS |
2109 | set expcode [list [lindex $args 1]]; |
2110 | } else { | |
c906108c | 2111 | set expcode $args; |
2f34202f MR |
2112 | } |
2113 | ||
2114 | upvar timeout timeout; | |
2115 | ||
2116 | if [target_info exists gdb,timeout] { | |
2117 | if [info exists timeout] { | |
2118 | if { $timeout < [target_info gdb,timeout] } { | |
c906108c | 2119 | set gtimeout [target_info gdb,timeout]; |
2f34202f MR |
2120 | } else { |
2121 | set gtimeout $timeout; | |
c906108c | 2122 | } |
2f34202f MR |
2123 | } else { |
2124 | set gtimeout [target_info gdb,timeout]; | |
c906108c | 2125 | } |
2f34202f | 2126 | } |
c906108c | 2127 | |
2f34202f MR |
2128 | if ![info exists gtimeout] { |
2129 | global timeout; | |
2130 | if [info exists timeout] { | |
2131 | set gtimeout $timeout; | |
2132 | } | |
2133 | } | |
2134 | ||
2135 | if [info exists atimeout] { | |
2136 | if { ![info exists gtimeout] || $gtimeout < $atimeout } { | |
db16b772 | 2137 | set gtimeout $atimeout; |
2f34202f MR |
2138 | } |
2139 | } else { | |
c906108c | 2140 | if ![info exists gtimeout] { |
2f34202f MR |
2141 | # Eeeeew. |
2142 | set gtimeout 60; | |
c906108c SS |
2143 | } |
2144 | } | |
2f34202f | 2145 | |
c906108c SS |
2146 | global suppress_flag; |
2147 | global remote_suppress_flag; | |
2148 | if [info exists remote_suppress_flag] { | |
2149 | set old_val $remote_suppress_flag; | |
2150 | } | |
2151 | if [info exists suppress_flag] { | |
2152 | if { $suppress_flag } { | |
2153 | set remote_suppress_flag 1; | |
2154 | } | |
2155 | } | |
a0b3c4fd | 2156 | set code [catch \ |
5f279fa6 | 2157 | {uplevel remote_expect host $gtimeout $expcode} string]; |
c906108c SS |
2158 | if [info exists old_val] { |
2159 | set remote_suppress_flag $old_val; | |
2160 | } else { | |
2161 | if [info exists remote_suppress_flag] { | |
2162 | unset remote_suppress_flag; | |
2163 | } | |
2164 | } | |
2165 | ||
2166 | if {$code == 1} { | |
2167 | global errorInfo errorCode; | |
2168 | ||
2169 | return -code error -errorinfo $errorInfo -errorcode $errorCode $string | |
2170 | } elseif {$code == 2} { | |
2171 | return -code return $string | |
2172 | } elseif {$code == 3} { | |
2173 | return | |
2174 | } elseif {$code > 4} { | |
2175 | return -code $code $string | |
2176 | } | |
2177 | } | |
2178 | ||
c2d11a7d | 2179 | # gdb_expect_list MESSAGE SENTINEL LIST -- expect a sequence of outputs |
085dd6e6 JM |
2180 | # |
2181 | # Check for long sequence of output by parts. | |
11cf8741 | 2182 | # MESSAGE: is the test message to be printed with the test success/fail. |
085dd6e6 JM |
2183 | # SENTINEL: Is the terminal pattern indicating that output has finished. |
2184 | # LIST: is the sequence of outputs to match. | |
2185 | # If the sentinel is recognized early, it is considered an error. | |
2186 | # | |
11cf8741 JM |
2187 | # Returns: |
2188 | # 1 if the test failed, | |
2189 | # 0 if the test passes, | |
2190 | # -1 if there was an internal error. | |
2191 | # | |
c2d11a7d | 2192 | proc gdb_expect_list {test sentinel list} { |
085dd6e6 | 2193 | global gdb_prompt |
11cf8741 | 2194 | global suppress_flag |
085dd6e6 | 2195 | set index 0 |
43ff13b4 | 2196 | set ok 1 |
11cf8741 JM |
2197 | if { $suppress_flag } { |
2198 | set ok 0 | |
a20ce2c3 | 2199 | unresolved "${test}" |
11cf8741 | 2200 | } |
43ff13b4 | 2201 | while { ${index} < [llength ${list}] } { |
085dd6e6 JM |
2202 | set pattern [lindex ${list} ${index}] |
2203 | set index [expr ${index} + 1] | |
2204 | if { ${index} == [llength ${list}] } { | |
43ff13b4 JM |
2205 | if { ${ok} } { |
2206 | gdb_expect { | |
c2d11a7d | 2207 | -re "${pattern}${sentinel}" { |
a20ce2c3 | 2208 | # pass "${test}, pattern ${index} + sentinel" |
c2d11a7d JM |
2209 | } |
2210 | -re "${sentinel}" { | |
a20ce2c3 | 2211 | fail "${test} (pattern ${index} + sentinel)" |
c2d11a7d | 2212 | set ok 0 |
43ff13b4 | 2213 | } |
5c5455dc AC |
2214 | -re ".*A problem internal to GDB has been detected" { |
2215 | fail "${test} (GDB internal error)" | |
2216 | set ok 0 | |
2217 | gdb_internal_error_resync | |
2218 | } | |
43ff13b4 | 2219 | timeout { |
a20ce2c3 | 2220 | fail "${test} (pattern ${index} + sentinel) (timeout)" |
43ff13b4 JM |
2221 | set ok 0 |
2222 | } | |
085dd6e6 | 2223 | } |
43ff13b4 | 2224 | } else { |
a20ce2c3 | 2225 | # unresolved "${test}, pattern ${index} + sentinel" |
085dd6e6 JM |
2226 | } |
2227 | } else { | |
43ff13b4 JM |
2228 | if { ${ok} } { |
2229 | gdb_expect { | |
2230 | -re "${pattern}" { | |
a20ce2c3 | 2231 | # pass "${test}, pattern ${index}" |
43ff13b4 | 2232 | } |
c2d11a7d | 2233 | -re "${sentinel}" { |
a20ce2c3 | 2234 | fail "${test} (pattern ${index})" |
43ff13b4 JM |
2235 | set ok 0 |
2236 | } | |
5c5455dc AC |
2237 | -re ".*A problem internal to GDB has been detected" { |
2238 | fail "${test} (GDB internal error)" | |
2239 | set ok 0 | |
2240 | gdb_internal_error_resync | |
2241 | } | |
43ff13b4 | 2242 | timeout { |
a20ce2c3 | 2243 | fail "${test} (pattern ${index}) (timeout)" |
43ff13b4 JM |
2244 | set ok 0 |
2245 | } | |
085dd6e6 | 2246 | } |
43ff13b4 | 2247 | } else { |
a20ce2c3 | 2248 | # unresolved "${test}, pattern ${index}" |
085dd6e6 JM |
2249 | } |
2250 | } | |
2251 | } | |
11cf8741 | 2252 | if { ${ok} } { |
a20ce2c3 | 2253 | pass "${test}" |
11cf8741 JM |
2254 | return 0 |
2255 | } else { | |
2256 | return 1 | |
2257 | } | |
085dd6e6 JM |
2258 | } |
2259 | ||
2260 | # | |
2261 | # | |
c906108c SS |
2262 | proc gdb_suppress_entire_file { reason } { |
2263 | global suppress_flag; | |
2264 | ||
2265 | warning "$reason\n"; | |
2266 | set suppress_flag -1; | |
2267 | } | |
2268 | ||
2269 | # | |
2270 | # Set suppress_flag, which will cause all subsequent calls to send_gdb and | |
2271 | # gdb_expect to fail immediately (until the next call to | |
2272 | # gdb_stop_suppressing_tests). | |
2273 | # | |
2274 | proc gdb_suppress_tests { args } { | |
2275 | global suppress_flag; | |
2276 | ||
2277 | return; # fnf - disable pending review of results where | |
2278 | # testsuite ran better without this | |
2279 | incr suppress_flag; | |
2280 | ||
2281 | if { $suppress_flag == 1 } { | |
2282 | if { [llength $args] > 0 } { | |
2283 | warning "[lindex $args 0]\n"; | |
2284 | } else { | |
2285 | warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n"; | |
2286 | } | |
2287 | } | |
2288 | } | |
2289 | ||
2290 | # | |
2291 | # Clear suppress_flag. | |
2292 | # | |
2293 | proc gdb_stop_suppressing_tests { } { | |
2294 | global suppress_flag; | |
2295 | ||
2296 | if [info exists suppress_flag] { | |
2297 | if { $suppress_flag > 0 } { | |
2298 | set suppress_flag 0; | |
2299 | clone_output "Tests restarted.\n"; | |
2300 | } | |
2301 | } else { | |
2302 | set suppress_flag 0; | |
2303 | } | |
2304 | } | |
2305 | ||
2306 | proc gdb_clear_suppressed { } { | |
2307 | global suppress_flag; | |
2308 | ||
2309 | set suppress_flag 0; | |
2310 | } | |
2311 | ||
2312 | proc gdb_start { } { | |
2313 | default_gdb_start | |
2314 | } | |
2315 | ||
2316 | proc gdb_exit { } { | |
2317 | catch default_gdb_exit | |
2318 | } | |
2319 | ||
e63b55d1 NS |
2320 | # |
2321 | # gdb_load_cmd -- load a file into the debugger. | |
2322 | # ARGS - additional args to load command. | |
2323 | # return a -1 if anything goes wrong. | |
2324 | # | |
2325 | proc gdb_load_cmd { args } { | |
2326 | global gdb_prompt | |
2327 | ||
2328 | if [target_info exists gdb_load_timeout] { | |
2329 | set loadtimeout [target_info gdb_load_timeout] | |
2330 | } else { | |
2331 | set loadtimeout 1600 | |
2332 | } | |
2333 | send_gdb "load $args\n" | |
e91528f0 | 2334 | verbose "Timeout is now $loadtimeout seconds" 2 |
e63b55d1 NS |
2335 | gdb_expect $loadtimeout { |
2336 | -re "Loading section\[^\r\]*\r\n" { | |
2337 | exp_continue | |
2338 | } | |
2339 | -re "Start address\[\r\]*\r\n" { | |
2340 | exp_continue | |
2341 | } | |
2342 | -re "Transfer rate\[\r\]*\r\n" { | |
2343 | exp_continue | |
2344 | } | |
2345 | -re "Memory access error\[^\r\]*\r\n" { | |
2346 | perror "Failed to load program" | |
2347 | return -1 | |
2348 | } | |
2349 | -re "$gdb_prompt $" { | |
2350 | return 0 | |
2351 | } | |
2352 | -re "(.*)\r\n$gdb_prompt " { | |
2353 | perror "Unexpected reponse from 'load' -- $expect_out(1,string)" | |
2354 | return -1 | |
2355 | } | |
2356 | timeout { | |
c4b347c7 | 2357 | perror "Timed out trying to load $args." |
e63b55d1 NS |
2358 | return -1 |
2359 | } | |
2360 | } | |
2361 | return -1 | |
2362 | } | |
2363 | ||
759f0f0b PA |
2364 | # Return the filename to download to the target and load on the target |
2365 | # for this shared library. Normally just LIBNAME, unless shared libraries | |
2366 | # for this target have separate link and load images. | |
2367 | ||
2368 | proc shlib_target_file { libname } { | |
2369 | return $libname | |
2370 | } | |
2371 | ||
2372 | # Return the filename GDB will load symbols from when debugging this | |
2373 | # shared library. Normally just LIBNAME, unless shared libraries for | |
2374 | # this target have separate link and load images. | |
2375 | ||
2376 | proc shlib_symbol_file { libname } { | |
2377 | return $libname | |
2378 | } | |
2379 | ||
93f02886 DJ |
2380 | # gdb_download |
2381 | # | |
2382 | # Copy a file to the remote target and return its target filename. | |
2383 | # Schedule the file to be deleted at the end of this test. | |
2384 | ||
2385 | proc gdb_download { filename } { | |
2386 | global cleanfiles | |
2387 | ||
2388 | set destname [remote_download target $filename] | |
2389 | lappend cleanfiles $destname | |
2390 | return $destname | |
2391 | } | |
2392 | ||
2393 | # gdb_load_shlibs LIB... | |
2394 | # | |
2395 | # Copy the listed libraries to the target. | |
2396 | ||
2397 | proc gdb_load_shlibs { args } { | |
2398 | if {![is_remote target]} { | |
2399 | return | |
2400 | } | |
2401 | ||
2402 | foreach file $args { | |
759f0f0b | 2403 | gdb_download [shlib_target_file $file] |
93f02886 DJ |
2404 | } |
2405 | ||
2406 | # Even if the target supplies full paths for shared libraries, | |
2407 | # they may not be paths for this system. | |
2408 | gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" "" | |
2409 | } | |
2410 | ||
c906108c SS |
2411 | # |
2412 | # gdb_load -- load a file into the debugger. | |
2db8e78e | 2413 | # Many files in config/*.exp override this procedure. |
c906108c SS |
2414 | # |
2415 | proc gdb_load { arg } { | |
2416 | return [gdb_file_cmd $arg] | |
2417 | } | |
2418 | ||
b741e217 DJ |
2419 | # gdb_reload -- load a file into the target. Called before "running", |
2420 | # either the first time or after already starting the program once, | |
2421 | # for remote targets. Most files that override gdb_load should now | |
2422 | # override this instead. | |
2423 | ||
2424 | proc gdb_reload { } { | |
2425 | # For the benefit of existing configurations, default to gdb_load. | |
2426 | # Specifying no file defaults to the executable currently being | |
2427 | # debugged. | |
2428 | return [gdb_load ""] | |
2429 | } | |
2430 | ||
c906108c SS |
2431 | proc gdb_continue { function } { |
2432 | global decimal | |
2433 | ||
2434 | return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"]; | |
2435 | } | |
2436 | ||
2437 | proc default_gdb_init { args } { | |
277254ba | 2438 | global gdb_wrapper_initialized |
f6838f81 | 2439 | global gdb_wrapper_target |
93f02886 | 2440 | global cleanfiles |
277254ba | 2441 | |
93f02886 DJ |
2442 | set cleanfiles {} |
2443 | ||
c906108c SS |
2444 | gdb_clear_suppressed; |
2445 | ||
277254ba MS |
2446 | # Make sure that the wrapper is rebuilt |
2447 | # with the appropriate multilib option. | |
f6838f81 DJ |
2448 | if { $gdb_wrapper_target != [current_target_name] } { |
2449 | set gdb_wrapper_initialized 0 | |
2450 | } | |
277254ba | 2451 | |
7b433602 JB |
2452 | # Unlike most tests, we have a small number of tests that generate |
2453 | # a very large amount of output. We therefore increase the expect | |
2454 | # buffer size to be able to contain the entire test output. | |
2455 | match_max -d 30000 | |
8d417781 PM |
2456 | # Also set this value for the currently running GDB. |
2457 | match_max [match_max -d] | |
c906108c SS |
2458 | |
2459 | # We want to add the name of the TCL testcase to the PASS/FAIL messages. | |
2460 | if { [llength $args] > 0 } { | |
2461 | global pf_prefix | |
2462 | ||
2463 | set file [lindex $args 0]; | |
2464 | ||
2465 | set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:"; | |
2466 | } | |
2467 | global gdb_prompt; | |
2468 | if [target_info exists gdb_prompt] { | |
2469 | set gdb_prompt [target_info gdb_prompt]; | |
2470 | } else { | |
2471 | set gdb_prompt "\\(gdb\\)" | |
2472 | } | |
2473 | } | |
2474 | ||
7b356089 JB |
2475 | # The default timeout used when testing GDB commands. We want to use |
2476 | # the same timeout as the default dejagnu timeout, unless the user has | |
2477 | # already provided a specific value (probably through a site.exp file). | |
2478 | global gdb_test_timeout | |
2479 | if ![info exists gdb_test_timeout] { | |
2480 | set gdb_test_timeout $timeout | |
2481 | } | |
2482 | ||
c906108c | 2483 | proc gdb_init { args } { |
7b356089 JB |
2484 | # Reset the timeout value to the default. This way, any testcase |
2485 | # that changes the timeout value without resetting it cannot affect | |
2486 | # the timeout used in subsequent testcases. | |
2487 | global gdb_test_timeout | |
2488 | global timeout | |
2489 | set timeout $gdb_test_timeout | |
2490 | ||
c906108c SS |
2491 | return [eval default_gdb_init $args]; |
2492 | } | |
2493 | ||
2494 | proc gdb_finish { } { | |
93f02886 DJ |
2495 | global cleanfiles |
2496 | ||
2497 | # Exit first, so that the files are no longer in use. | |
2498 | gdb_exit | |
2499 | ||
2500 | if { [llength $cleanfiles] > 0 } { | |
2501 | eval remote_file target delete $cleanfiles | |
2502 | set cleanfiles {} | |
2503 | } | |
c906108c SS |
2504 | } |
2505 | ||
2506 | global debug_format | |
7a292a7a | 2507 | set debug_format "unknown" |
c906108c SS |
2508 | |
2509 | # Run the gdb command "info source" and extract the debugging format | |
2510 | # information from the output and save it in debug_format. | |
2511 | ||
2512 | proc get_debug_format { } { | |
2513 | global gdb_prompt | |
2514 | global verbose | |
2515 | global expect_out | |
2516 | global debug_format | |
2517 | ||
2518 | set debug_format "unknown" | |
2519 | send_gdb "info source\n" | |
2520 | gdb_expect 10 { | |
919d772c | 2521 | -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" { |
c906108c SS |
2522 | set debug_format $expect_out(1,string) |
2523 | verbose "debug format is $debug_format" | |
2524 | return 1; | |
2525 | } | |
2526 | -re "No current source file.\r\n$gdb_prompt $" { | |
2527 | perror "get_debug_format used when no current source file" | |
2528 | return 0; | |
2529 | } | |
2530 | -re "$gdb_prompt $" { | |
2531 | warning "couldn't check debug format (no valid response)." | |
2532 | return 1; | |
2533 | } | |
2534 | timeout { | |
2535 | warning "couldn't check debug format (timed out)." | |
2536 | return 1; | |
2537 | } | |
2538 | } | |
2539 | } | |
2540 | ||
838ae6c4 JB |
2541 | # Return true if FORMAT matches the debug format the current test was |
2542 | # compiled with. FORMAT is a shell-style globbing pattern; it can use | |
2543 | # `*', `[...]', and so on. | |
2544 | # | |
2545 | # This function depends on variables set by `get_debug_format', above. | |
2546 | ||
2547 | proc test_debug_format {format} { | |
2548 | global debug_format | |
2549 | ||
2550 | return [expr [string match $format $debug_format] != 0] | |
2551 | } | |
2552 | ||
c906108c SS |
2553 | # Like setup_xfail, but takes the name of a debug format (DWARF 1, |
2554 | # COFF, stabs, etc). If that format matches the format that the | |
2555 | # current test was compiled with, then the next test is expected to | |
2556 | # fail for any target. Returns 1 if the next test or set of tests is | |
2557 | # expected to fail, 0 otherwise (or if it is unknown). Must have | |
2558 | # previously called get_debug_format. | |
b55a4771 | 2559 | proc setup_xfail_format { format } { |
838ae6c4 | 2560 | set ret [test_debug_format $format]; |
b55a4771 | 2561 | |
838ae6c4 | 2562 | if {$ret} then { |
b55a4771 MS |
2563 | setup_xfail "*-*-*" |
2564 | } | |
2565 | return $ret; | |
2566 | } | |
c906108c SS |
2567 | |
2568 | proc gdb_step_for_stub { } { | |
2569 | global gdb_prompt; | |
2570 | ||
2571 | if ![target_info exists gdb,use_breakpoint_for_stub] { | |
2572 | if [target_info exists gdb_stub_step_command] { | |
2573 | set command [target_info gdb_stub_step_command]; | |
2574 | } else { | |
2575 | set command "step"; | |
2576 | } | |
2577 | send_gdb "${command}\n"; | |
2578 | set tries 0; | |
2579 | gdb_expect 60 { | |
2580 | -re "(main.* at |.*in .*start).*$gdb_prompt" { | |
2581 | return; | |
2582 | } | |
2583 | -re ".*$gdb_prompt" { | |
2584 | incr tries; | |
2585 | if { $tries == 5 } { | |
2586 | fail "stepping out of breakpoint function"; | |
2587 | return; | |
2588 | } | |
2589 | send_gdb "${command}\n"; | |
2590 | exp_continue; | |
2591 | } | |
2592 | default { | |
2593 | fail "stepping out of breakpoint function"; | |
2594 | return; | |
2595 | } | |
2596 | } | |
2597 | } | |
2598 | send_gdb "where\n"; | |
2599 | gdb_expect { | |
2600 | -re "main\[^\r\n\]*at \(\[^:]+\):\(\[0-9\]+\)" { | |
2601 | set file $expect_out(1,string); | |
2602 | set linenum [expr $expect_out(2,string) + 1]; | |
2603 | set breakplace "${file}:${linenum}"; | |
2604 | } | |
2605 | default {} | |
2606 | } | |
2607 | send_gdb "break ${breakplace}\n"; | |
2608 | gdb_expect 60 { | |
2609 | -re "Breakpoint (\[0-9\]+) at.*$gdb_prompt" { | |
2610 | set breakpoint $expect_out(1,string); | |
2611 | } | |
2612 | -re "Breakpoint (\[0-9\]+): file.*$gdb_prompt" { | |
2613 | set breakpoint $expect_out(1,string); | |
2614 | } | |
2615 | default {} | |
2616 | } | |
2617 | send_gdb "continue\n"; | |
2618 | gdb_expect 60 { | |
2619 | -re "Breakpoint ${breakpoint},.*$gdb_prompt" { | |
2620 | gdb_test "delete $breakpoint" ".*" ""; | |
2621 | return; | |
2622 | } | |
2623 | default {} | |
2624 | } | |
2625 | } | |
2626 | ||
c6fee705 MC |
2627 | # gdb_get_line_number TEXT [FILE] |
2628 | # | |
2629 | # Search the source file FILE, and return the line number of the | |
2630 | # first line containing TEXT. If no match is found, return -1. | |
2631 | # | |
2632 | # TEXT is a string literal, not a regular expression. | |
2633 | # | |
2634 | # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is | |
2635 | # specified, and does not start with "/", then it is assumed to be in | |
2636 | # "$srcdir/$subdir". This is awkward, and can be fixed in the future, | |
2637 | # by changing the callers and the interface at the same time. | |
2638 | # In particular: gdb.base/break.exp, gdb.base/condbreak.exp, | |
2639 | # gdb.base/ena-dis-br.exp. | |
2640 | # | |
2641 | # Use this function to keep your test scripts independent of the | |
2642 | # exact line numbering of the source file. Don't write: | |
2643 | # | |
2644 | # send_gdb "break 20" | |
2645 | # | |
2646 | # This means that if anyone ever edits your test's source file, | |
2647 | # your test could break. Instead, put a comment like this on the | |
2648 | # source file line you want to break at: | |
2649 | # | |
2650 | # /* breakpoint spot: frotz.exp: test name */ | |
2651 | # | |
2652 | # and then write, in your test script (which we assume is named | |
2653 | # frotz.exp): | |
2654 | # | |
2655 | # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n" | |
2656 | # | |
2657 | # (Yes, Tcl knows how to handle the nested quotes and brackets. | |
2658 | # Try this: | |
2659 | # $ tclsh | |
2660 | # % puts "foo [lindex "bar baz" 1]" | |
2661 | # foo baz | |
2662 | # % | |
2663 | # Tcl is quite clever, for a little stringy language.) | |
2664 | # | |
2665 | # === | |
2666 | # | |
2667 | # The previous implementation of this procedure used the gdb search command. | |
2668 | # This version is different: | |
2669 | # | |
2670 | # . It works with MI, and it also works when gdb is not running. | |
2671 | # | |
2672 | # . It operates on the build machine, not the host machine. | |
2673 | # | |
2674 | # . For now, this implementation fakes a current directory of | |
2675 | # $srcdir/$subdir to be compatible with the old implementation. | |
2676 | # This will go away eventually and some callers will need to | |
2677 | # be changed. | |
2678 | # | |
2679 | # . The TEXT argument is literal text and matches literally, | |
2680 | # not a regular expression as it was before. | |
2681 | # | |
2682 | # . State changes in gdb, such as changing the current file | |
2683 | # and setting $_, no longer happen. | |
2684 | # | |
2685 | # After a bit of time we can forget about the differences from the | |
2686 | # old implementation. | |
2687 | # | |
2688 | # --chastain 2004-08-05 | |
2689 | ||
2690 | proc gdb_get_line_number { text { file "" } } { | |
2691 | global srcdir | |
2692 | global subdir | |
2693 | global srcfile | |
c906108c | 2694 | |
c6fee705 MC |
2695 | if { "$file" == "" } then { |
2696 | set file "$srcfile" | |
2697 | } | |
2698 | if { ! [regexp "^/" "$file"] } then { | |
2699 | set file "$srcdir/$subdir/$file" | |
c906108c SS |
2700 | } |
2701 | ||
c6fee705 MC |
2702 | if { [ catch { set fd [open "$file"] } message ] } then { |
2703 | perror "$message" | |
2704 | return -1 | |
c906108c | 2705 | } |
c6fee705 MC |
2706 | |
2707 | set found -1 | |
2708 | for { set line 1 } { 1 } { incr line } { | |
2709 | if { [ catch { set nchar [gets "$fd" body] } message ] } then { | |
2710 | perror "$message" | |
2711 | return -1 | |
2712 | } | |
2713 | if { $nchar < 0 } then { | |
2714 | break | |
2715 | } | |
2716 | if { [string first "$text" "$body"] >= 0 } then { | |
2717 | set found $line | |
2718 | break | |
2719 | } | |
2720 | } | |
2721 | ||
2722 | if { [ catch { close "$fd" } message ] } then { | |
2723 | perror "$message" | |
2724 | return -1 | |
2725 | } | |
2726 | ||
2727 | return $found | |
c906108c SS |
2728 | } |
2729 | ||
7a292a7a SS |
2730 | # gdb_continue_to_end: |
2731 | # The case where the target uses stubs has to be handled specially. If a | |
2732 | # stub is used, we set a breakpoint at exit because we cannot rely on | |
2733 | # exit() behavior of a remote target. | |
2734 | # | |
2735 | # mssg is the error message that gets printed. | |
2736 | ||
2737 | proc gdb_continue_to_end {mssg} { | |
2738 | if [target_info exists use_gdb_stub] { | |
2739 | if {![gdb_breakpoint "exit"]} { | |
2740 | return 0 | |
2741 | } | |
2742 | gdb_test "continue" "Continuing..*Breakpoint .*exit.*" \ | |
2743 | "continue until exit at $mssg" | |
2744 | } else { | |
2745 | # Continue until we exit. Should not stop again. | |
2746 | # Don't bother to check the output of the program, that may be | |
2747 | # extremely tough for some remote systems. | |
2748 | gdb_test "continue"\ | |
1c56143a | 2749 | "Continuing.\[\r\n0-9\]+(... EXIT code 0\[\r\n\]+|Program exited normally\\.).*"\ |
7a292a7a SS |
2750 | "continue until exit at $mssg" |
2751 | } | |
2752 | } | |
2753 | ||
2754 | proc rerun_to_main {} { | |
2755 | global gdb_prompt | |
2756 | ||
2757 | if [target_info exists use_gdb_stub] { | |
2758 | gdb_run_cmd | |
2759 | gdb_expect { | |
2760 | -re ".*Breakpoint .*main .*$gdb_prompt $"\ | |
2761 | {pass "rerun to main" ; return 0} | |
2762 | -re "$gdb_prompt $"\ | |
2763 | {fail "rerun to main" ; return 0} | |
2764 | timeout {fail "(timeout) rerun to main" ; return 0} | |
2765 | } | |
2766 | } else { | |
2767 | send_gdb "run\n" | |
2768 | gdb_expect { | |
11350d2a CV |
2769 | -re "The program .* has been started already.*y or n. $" { |
2770 | send_gdb "y\n" | |
2771 | exp_continue | |
2772 | } | |
7a292a7a SS |
2773 | -re "Starting program.*$gdb_prompt $"\ |
2774 | {pass "rerun to main" ; return 0} | |
2775 | -re "$gdb_prompt $"\ | |
2776 | {fail "rerun to main" ; return 0} | |
2777 | timeout {fail "(timeout) rerun to main" ; return 0} | |
2778 | } | |
2779 | } | |
2780 | } | |
c906108c | 2781 | |
13a5e3b8 MS |
2782 | # Print a message and return true if a test should be skipped |
2783 | # due to lack of floating point suport. | |
2784 | ||
2785 | proc gdb_skip_float_test { msg } { | |
2786 | if [target_info exists gdb,skip_float_tests] { | |
2787 | verbose "Skipping test '$msg': no float tests."; | |
2788 | return 1; | |
2789 | } | |
2790 | return 0; | |
2791 | } | |
2792 | ||
2793 | # Print a message and return true if a test should be skipped | |
2794 | # due to lack of stdio support. | |
2795 | ||
2796 | proc gdb_skip_stdio_test { msg } { | |
2797 | if [target_info exists gdb,noinferiorio] { | |
2798 | verbose "Skipping test '$msg': no inferior i/o."; | |
2799 | return 1; | |
2800 | } | |
2801 | return 0; | |
2802 | } | |
2803 | ||
2804 | proc gdb_skip_bogus_test { msg } { | |
2805 | return 0; | |
2806 | } | |
2807 | ||
e515b470 DJ |
2808 | # Return true if a test should be skipped due to lack of XML support |
2809 | # in the host GDB. | |
d0ef5df8 | 2810 | # NOTE: This must be called while gdb is *not* running. |
e515b470 DJ |
2811 | |
2812 | proc gdb_skip_xml_test { } { | |
2813 | global gdb_prompt | |
2814 | global srcdir | |
2815 | global xml_missing_cached | |
2816 | ||
2817 | if {[info exists xml_missing_cached]} { | |
2818 | return $xml_missing_cached | |
2819 | } | |
2820 | ||
2821 | gdb_start | |
2822 | set xml_missing_cached 0 | |
2823 | gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" { | |
2824 | -re ".*XML support was disabled at compile time.*$gdb_prompt $" { | |
2825 | set xml_missing_cached 1 | |
2826 | } | |
2827 | -re ".*$gdb_prompt $" { } | |
2828 | } | |
2829 | gdb_exit | |
2830 | return $xml_missing_cached | |
2831 | } | |
1f8a6abb EZ |
2832 | |
2833 | # Note: the procedure gdb_gnu_strip_debug will produce an executable called | |
2834 | # ${binfile}.dbglnk, which is just like the executable ($binfile) but without | |
2835 | # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains | |
94277a38 | 2836 | # the name of a debuginfo only file. This file will be stored in the |
1f8a6abb EZ |
2837 | # gdb.base/.debug subdirectory. |
2838 | ||
2839 | # Functions for separate debug info testing | |
2840 | ||
2841 | # starting with an executable: | |
2842 | # foo --> original executable | |
2843 | ||
2844 | # at the end of the process we have: | |
2845 | # foo.stripped --> foo w/o debug info | |
2846 | # .debug/foo.debug --> foo's debug info | |
2847 | # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug. | |
2848 | ||
2849 | # Return the name of the file in which we should stor EXEC's separated | |
2850 | # debug info. EXEC contains the full path. | |
2851 | proc separate_debug_filename { exec } { | |
2852 | ||
2853 | # In a .debug subdirectory off the same directory where the testcase | |
2854 | # executable is going to be. Something like: | |
2855 | # <your-path>/gdb/testsuite/gdb.base/.debug/blah.debug. | |
2856 | # This is the default location where gdb expects to findi | |
2857 | # the debug info file. | |
2858 | ||
2859 | set exec_dir [file dirname $exec] | |
2860 | set exec_file [file tail $exec] | |
2861 | set debug_dir [file join $exec_dir ".debug"] | |
2862 | set debug_file [file join $debug_dir "${exec_file}.debug"] | |
2863 | ||
2864 | return $debug_file | |
2865 | } | |
2866 | ||
4935890f JK |
2867 | # Return the build-id hex string (usually 160 bits as 40 hex characters) |
2868 | # converted to the form: .build-id/ab/cdef1234...89.debug | |
2869 | # Return "" if no build-id found. | |
2870 | proc build_id_debug_filename_get { exec } { | |
2871 | set tmp "${exec}-tmp" | |
8b3fc8d8 MK |
2872 | set objcopy_program [transform objcopy] |
2873 | ||
2874 | set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output] | |
2875 | verbose "result is $result" | |
2876 | verbose "output is $output" | |
2877 | if {$result == 1} { | |
2878 | return "" | |
2879 | } | |
4935890f | 2880 | set fi [open $tmp] |
b7fca990 | 2881 | fconfigure $fi -translation binary |
4935890f JK |
2882 | # Skip the NOTE header. |
2883 | read $fi 16 | |
2884 | set data [read $fi] | |
2885 | close $fi | |
2886 | file delete $tmp | |
7020f05c | 2887 | if ![string compare $data ""] then { |
4935890f JK |
2888 | return "" |
2889 | } | |
2890 | # Convert it to hex. | |
2891 | binary scan $data H* data | |
061b5285 | 2892 | regsub {^..} $data {\0/} data |
4935890f JK |
2893 | return ".build-id/${data}.debug"; |
2894 | } | |
2895 | ||
94277a38 DJ |
2896 | # Create stripped files for DEST, replacing it. If ARGS is passed, it is a |
2897 | # list of optional flags. The only currently supported flag is no-main, | |
2898 | # which removes the symbol entry for main from the separate debug file. | |
1f8a6abb | 2899 | |
94277a38 DJ |
2900 | proc gdb_gnu_strip_debug { dest args } { |
2901 | ||
1f8a6abb | 2902 | set debug_file [separate_debug_filename $dest] |
b741e217 DJ |
2903 | set strip_to_file_program [transform strip] |
2904 | set objcopy_program [transform objcopy] | |
1f8a6abb EZ |
2905 | |
2906 | # Make sure the directory that will hold the separated debug | |
2907 | # info actually exists. | |
2908 | set debug_dir [file dirname $debug_file] | |
2909 | if {! [file isdirectory $debug_dir]} { | |
2910 | file mkdir $debug_dir | |
2911 | } | |
2912 | ||
2913 | set debug_link [file tail $debug_file] | |
2914 | set stripped_file "${dest}.stripped" | |
2915 | ||
2916 | # Get rid of the debug info, and store result in stripped_file | |
2917 | # something like gdb/testsuite/gdb.base/blah.stripped. | |
2918 | set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output] | |
2919 | verbose "result is $result" | |
2920 | verbose "output is $output" | |
2921 | if {$result == 1} { | |
2922 | return 1 | |
2923 | } | |
2924 | ||
d521f563 JK |
2925 | # Workaround PR binutils/10802: |
2926 | # Preserve the 'x' bit also for PIEs (Position Independent Executables). | |
2927 | set perm [file attributes ${dest} -permissions] | |
2928 | file attributes ${stripped_file} -permissions $perm | |
2929 | ||
1f8a6abb EZ |
2930 | # Get rid of everything but the debug info, and store result in debug_file |
2931 | # This will be in the .debug subdirectory, see above. | |
2932 | set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output] | |
2933 | verbose "result is $result" | |
2934 | verbose "output is $output" | |
2935 | if {$result == 1} { | |
2936 | return 1 | |
2937 | } | |
2938 | ||
94277a38 DJ |
2939 | # If no-main is passed, strip the symbol for main from the separate |
2940 | # file. This is to simulate the behavior of elfutils's eu-strip, which | |
2941 | # leaves the symtab in the original file only. There's no way to get | |
2942 | # objcopy or strip to remove the symbol table without also removing the | |
2943 | # debugging sections, so this is as close as we can get. | |
2944 | if { [llength $args] == 1 && [lindex $args 0] == "no-main" } { | |
2945 | set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output] | |
2946 | verbose "result is $result" | |
2947 | verbose "output is $output" | |
2948 | if {$result == 1} { | |
2949 | return 1 | |
2950 | } | |
2951 | file delete "${debug_file}" | |
2952 | file rename "${debug_file}-tmp" "${debug_file}" | |
2953 | } | |
2954 | ||
1f8a6abb EZ |
2955 | # Link the two previous output files together, adding the .gnu_debuglink |
2956 | # section to the stripped_file, containing a pointer to the debug_file, | |
2957 | # save the new file in dest. | |
2958 | # This will be the regular executable filename, in the usual location. | |
2959 | set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output] | |
2960 | verbose "result is $result" | |
2961 | verbose "output is $output" | |
2962 | if {$result == 1} { | |
2963 | return 1 | |
2964 | } | |
2965 | ||
d521f563 JK |
2966 | # Workaround PR binutils/10802: |
2967 | # Preserve the 'x' bit also for PIEs (Position Independent Executables). | |
2968 | set perm [file attributes ${stripped_file} -permissions] | |
2969 | file attributes ${dest} -permissions $perm | |
2970 | ||
2971 | return 0 | |
1f8a6abb EZ |
2972 | } |
2973 | ||
d8295fe9 VP |
2974 | # Test the output of GDB_COMMAND matches the pattern obtained |
2975 | # by concatenating all elements of EXPECTED_LINES. This makes | |
2976 | # it possible to split otherwise very long string into pieces. | |
2977 | # If third argument is not empty, it's used as the name of the | |
2978 | # test to be printed on pass/fail. | |
2979 | proc help_test_raw { gdb_command expected_lines args } { | |
2980 | set message $gdb_command | |
2981 | if [llength $args]>0 then { | |
2982 | set message [lindex $args 0] | |
2983 | } | |
2984 | set expected_output [join $expected_lines ""] | |
2985 | gdb_test "${gdb_command}" "${expected_output}" $message | |
2986 | } | |
2987 | ||
2988 | # Test the output of "help COMMNAD_CLASS". EXPECTED_INITIAL_LINES | |
2989 | # are regular expressions that should match the beginning of output, | |
2990 | # before the list of commands in that class. The presence of | |
2991 | # command list and standard epilogue will be tested automatically. | |
2992 | proc test_class_help { command_class expected_initial_lines args } { | |
2993 | set l_stock_body { | |
2994 | "List of commands\:.*\[\r\n\]+" | |
2995 | "Type \"help\" followed by command name for full documentation\.\[\r\n\]+" | |
2996 | "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+" | |
2997 | "Command name abbreviations are allowed if unambiguous\." | |
2998 | } | |
2999 | set l_entire_body [concat $expected_initial_lines $l_stock_body] | |
3000 | ||
3001 | eval [list help_test_raw "help ${command_class}" $l_entire_body] $args | |
3002 | } | |
3003 | ||
3004 | # COMMAND_LIST should have either one element -- command to test, or | |
3005 | # two elements -- abbreviated command to test, and full command the first | |
3006 | # element is abbreviation of. | |
3007 | # The command must be a prefix command. EXPECTED_INITIAL_LINES | |
3008 | # are regular expressions that should match the beginning of output, | |
3009 | # before the list of subcommands. The presence of | |
3010 | # subcommand list and standard epilogue will be tested automatically. | |
3011 | proc test_prefix_command_help { command_list expected_initial_lines args } { | |
3012 | set command [lindex $command_list 0] | |
3013 | if {[llength $command_list]>1} { | |
3014 | set full_command [lindex $command_list 1] | |
3015 | } else { | |
3016 | set full_command $command | |
3017 | } | |
3018 | # Use 'list' and not just {} because we want variables to | |
3019 | # be expanded in this list. | |
3020 | set l_stock_body [list\ | |
3021 | "List of $full_command subcommands\:.*\[\r\n\]+"\ | |
3022 | "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\ | |
3023 | "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\ | |
3024 | "Command name abbreviations are allowed if unambiguous\."] | |
3025 | set l_entire_body [concat $expected_initial_lines $l_stock_body] | |
3026 | if {[llength $args]>0} { | |
3027 | help_test_raw "help ${command}" $l_entire_body [lindex $args 0] | |
3028 | } else { | |
3029 | help_test_raw "help ${command}" $l_entire_body | |
3030 | } | |
3031 | } | |
dbc52822 VP |
3032 | |
3033 | # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not | |
3034 | # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test | |
3035 | # to pass to untested, if something is wrong. OPTIONS are passed | |
3036 | # to gdb_compile directly. | |
3037 | proc build_executable { testname executable {sources ""} {options {debug}} } { | |
3038 | ||
3039 | global objdir | |
3040 | global subdir | |
3041 | global srcdir | |
3042 | if {[llength $sources]==0} { | |
3043 | set sources ${executable}.c | |
3044 | } | |
3045 | ||
3046 | set binfile ${objdir}/${subdir}/${executable} | |
3047 | ||
3048 | set objects {} | |
3049 | for {set i 0} "\$i<[llength $sources]" {incr i} { | |
3050 | set s [lindex $sources $i] | |
3051 | if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } { | |
3052 | untested $testname | |
3053 | return -1 | |
3054 | } | |
3055 | lappend objects "${binfile}${i}.o" | |
3056 | } | |
3057 | ||
3058 | if { [gdb_compile $objects "${binfile}" executable $options] != "" } { | |
3059 | untested $testname | |
3060 | return -1 | |
3061 | } | |
3062 | ||
3063 | if [get_compiler_info ${binfile}] { | |
3064 | return -1 | |
3065 | } | |
3066 | return 0 | |
3067 | } | |
3068 | ||
3069 | # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is | |
3070 | # the name of binary in ${objdir}/${subdir}. | |
3071 | proc clean_restart { executable } { | |
3072 | global srcdir | |
3073 | global objdir | |
3074 | global subdir | |
3075 | set binfile ${objdir}/${subdir}/${executable} | |
3076 | ||
3077 | gdb_exit | |
3078 | gdb_start | |
3079 | gdb_reinitialize_dir $srcdir/$subdir | |
3080 | gdb_load ${binfile} | |
3081 | ||
3082 | if [target_info exists gdb_stub] { | |
3083 | gdb_step_for_stub; | |
3084 | } | |
3085 | } | |
3086 | ||
3087 | # Prepares for testing, by calling build_executable, and then clean_restart. | |
3088 | # Please refer to build_executable for parameter description. | |
3089 | proc prepare_for_testing { testname executable {sources ""} {options {debug}}} { | |
3090 | ||
734a5c36 | 3091 | if {[build_executable $testname $executable $sources $options] == -1} { |
dbc52822 VP |
3092 | return -1 |
3093 | } | |
3094 | clean_restart $executable | |
3095 | ||
3096 | return 0 | |
3097 | } | |
7065b901 TT |
3098 | |
3099 | proc get_valueof { fmt exp default } { | |
3100 | global gdb_prompt | |
3101 | ||
3102 | set test "get valueof \"${exp}\"" | |
3103 | set val ${default} | |
3104 | gdb_test_multiple "print${fmt} ${exp}" "$test" { | |
417e16e2 PM |
3105 | -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" { |
3106 | set val $expect_out(1,string) | |
3107 | pass "$test ($val)" | |
3108 | } | |
3109 | timeout { | |
3110 | fail "$test (timeout)" | |
3111 | } | |
3112 | } | |
3113 | return ${val} | |
3114 | } | |
3115 | ||
3116 | proc get_integer_valueof { exp default } { | |
3117 | global gdb_prompt | |
3118 | ||
3119 | set test "get integer valueof \"${exp}\"" | |
3120 | set val ${default} | |
3121 | gdb_test_multiple "print /d ${exp}" "$test" { | |
7065b901 TT |
3122 | -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" { |
3123 | set val $expect_out(1,string) | |
3124 | pass "$test ($val)" | |
3125 | } | |
3126 | timeout { | |
417e16e2 | 3127 | fail "$test (timeout)" |
7065b901 TT |
3128 | } |
3129 | } | |
3130 | return ${val} | |
3131 | } | |
3132 | ||
faafb047 PM |
3133 | proc get_hexadecimal_valueof { exp default } { |
3134 | global gdb_prompt | |
3135 | send_gdb "print /x ${exp}\n" | |
3136 | set test "get hexadecimal valueof \"${exp}\"" | |
3137 | gdb_expect { | |
3138 | -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" { | |
3139 | set val $expect_out(1,string) | |
3140 | pass "$test" | |
3141 | } | |
3142 | timeout { | |
3143 | set val ${default} | |
3144 | fail "$test (timeout)" | |
3145 | } | |
3146 | } | |
3147 | return ${val} | |
3148 | } | |
417e16e2 | 3149 | |
7065b901 | 3150 | proc get_sizeof { type default } { |
417e16e2 | 3151 | return [get_integer_valueof "sizeof (${type})" $default] |
7065b901 TT |
3152 | } |
3153 | ||
812f7342 TT |
3154 | # Log gdb command line and script if requested. |
3155 | if {[info exists TRANSCRIPT]} { | |
3156 | rename send_gdb real_send_gdb | |
3157 | rename remote_spawn real_remote_spawn | |
3158 | rename remote_close real_remote_close | |
3159 | ||
3160 | global gdb_transcript | |
3161 | set gdb_transcript "" | |
3162 | ||
3163 | global gdb_trans_count | |
3164 | set gdb_trans_count 1 | |
3165 | ||
3166 | proc remote_spawn {args} { | |
3167 | global gdb_transcript gdb_trans_count outdir | |
3168 | ||
3169 | if {$gdb_transcript != ""} { | |
3170 | close $gdb_transcript | |
3171 | } | |
3172 | set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w] | |
3173 | puts $gdb_transcript [lindex $args 1] | |
3174 | incr gdb_trans_count | |
3175 | ||
3176 | return [uplevel real_remote_spawn $args] | |
3177 | } | |
3178 | ||
3179 | proc remote_close {args} { | |
3180 | global gdb_transcript | |
3181 | ||
3182 | if {$gdb_transcript != ""} { | |
3183 | close $gdb_transcript | |
3184 | set gdb_transcript "" | |
3185 | } | |
3186 | ||
3187 | return [uplevel real_remote_close $args] | |
3188 | } | |
3189 | ||
3190 | proc send_gdb {args} { | |
3191 | global gdb_transcript | |
3192 | ||
3193 | if {$gdb_transcript != ""} { | |
3194 | puts -nonewline $gdb_transcript [lindex $args 0] | |
3195 | } | |
3196 | ||
3197 | return [uplevel real_send_gdb $args] | |
3198 | } | |
3199 | } | |
37aeb5df | 3200 | |
bbfba9ed | 3201 | proc core_find {binfile {deletefiles {}} {arg ""}} { |
37aeb5df JK |
3202 | global objdir subdir |
3203 | ||
3204 | set destcore "$binfile.core" | |
3205 | file delete $destcore | |
3206 | ||
3207 | # Create a core file named "$destcore" rather than just "core", to | |
3208 | # avoid problems with sys admin types that like to regularly prune all | |
3209 | # files named "core" from the system. | |
3210 | # | |
3211 | # Arbitrarily try setting the core size limit to "unlimited" since | |
3212 | # this does not hurt on systems where the command does not work and | |
3213 | # allows us to generate a core on systems where it does. | |
3214 | # | |
3215 | # Some systems append "core" to the name of the program; others append | |
3216 | # the name of the program to "core"; still others (like Linux, as of | |
3217 | # May 2003) create cores named "core.PID". In the latter case, we | |
3218 | # could have many core files lying around, and it may be difficult to | |
3219 | # tell which one is ours, so let's run the program in a subdirectory. | |
3220 | set found 0 | |
3221 | set coredir "${objdir}/${subdir}/coredir.[getpid]" | |
3222 | file mkdir $coredir | |
bbfba9ed | 3223 | catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\"" |
37aeb5df JK |
3224 | # remote_exec host "${binfile}" |
3225 | foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" { | |
3226 | if [remote_file build exists $i] { | |
3227 | remote_exec build "mv $i $destcore" | |
3228 | set found 1 | |
3229 | } | |
3230 | } | |
3231 | # Check for "core.PID". | |
3232 | if { $found == 0 } { | |
3233 | set names [glob -nocomplain -directory $coredir core.*] | |
3234 | if {[llength $names] == 1} { | |
3235 | set corefile [file join $coredir [lindex $names 0]] | |
3236 | remote_exec build "mv $corefile $destcore" | |
3237 | set found 1 | |
3238 | } | |
3239 | } | |
3240 | if { $found == 0 } { | |
3241 | # The braindamaged HPUX shell quits after the ulimit -c above | |
3242 | # without executing ${binfile}. So we try again without the | |
3243 | # ulimit here if we didn't find a core file above. | |
3244 | # Oh, I should mention that any "braindamaged" non-Unix system has | |
3245 | # the same problem. I like the cd bit too, it's really neat'n stuff. | |
3246 | catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\"" | |
3247 | foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" { | |
3248 | if [remote_file build exists $i] { | |
3249 | remote_exec build "mv $i $destcore" | |
3250 | set found 1 | |
3251 | } | |
3252 | } | |
3253 | } | |
3254 | ||
3255 | # Try to clean up after ourselves. | |
3256 | foreach deletefile $deletefiles { | |
3257 | remote_file build delete [file join $coredir $deletefile] | |
3258 | } | |
3259 | remote_exec build "rmdir $coredir" | |
3260 | ||
3261 | if { $found == 0 } { | |
3262 | warning "can't generate a core file - core tests suppressed - check ulimit -c" | |
3263 | return "" | |
3264 | } | |
3265 | return $destcore | |
3266 | } |