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