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