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