Commit | Line | Data |
---|---|---|
8acc9f48 | 1 | # Copyright 1992-2013 Free Software Foundation, Inc. |
c906108c SS |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c906108c SS |
8 | # This program is distributed in the hope that it will be useful, |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
e22f8b7c | 12 | # |
c906108c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 15 | |
c906108c SS |
16 | # This file was written by Fred Fish. (fnf@cygnus.com) |
17 | ||
18 | # Generic gdb subroutines that should work for any target. If these | |
19 | # need to be modified for any target, it can be done with a variable | |
20 | # or by passing arguments. | |
21 | ||
97c3f1f3 JK |
22 | if {$tool == ""} { |
23 | # Tests would fail, logs on get_compiler_info() would be missing. | |
24 | send_error "`site.exp' not found, run `make site.exp'!\n" | |
25 | exit 2 | |
26 | } | |
27 | ||
c906108c SS |
28 | load_lib libgloss.exp |
29 | ||
30 | global GDB | |
c906108c SS |
31 | |
32 | if [info exists TOOL_EXECUTABLE] { | |
33 | set GDB $TOOL_EXECUTABLE; | |
34 | } | |
35 | if ![info exists GDB] { | |
36 | if ![is_remote host] { | |
37 | set GDB [findfile $base_dir/../../gdb/gdb "$base_dir/../../gdb/gdb" [transform gdb]] | |
38 | } else { | |
39 | set GDB [transform gdb]; | |
40 | } | |
41 | } | |
42 | verbose "using GDB = $GDB" 2 | |
43 | ||
6b8ce727 DE |
44 | # GDBFLAGS is available for the user to set on the command line. |
45 | # E.g. make check RUNTESTFLAGS=GDBFLAGS=mumble | |
46 | # Testcases may use it to add additional flags, but they must: | |
47 | # - append new flags, not overwrite | |
48 | # - restore the original value when done | |
c906108c SS |
49 | global GDBFLAGS |
50 | if ![info exists GDBFLAGS] { | |
6b8ce727 | 51 | set GDBFLAGS "" |
c906108c SS |
52 | } |
53 | verbose "using GDBFLAGS = $GDBFLAGS" 2 | |
54 | ||
2f4e0a80 DE |
55 | # Make the build data directory available to tests. |
56 | set BUILD_DATA_DIRECTORY "[pwd]/../data-directory" | |
57 | ||
6b8ce727 | 58 | # INTERNAL_GDBFLAGS contains flags that the testsuite requires. |
1be00882 DE |
59 | global INTERNAL_GDBFLAGS |
60 | if ![info exists INTERNAL_GDBFLAGS] { | |
2f4e0a80 | 61 | set INTERNAL_GDBFLAGS "-nw -nx -data-directory $BUILD_DATA_DIRECTORY" |
1be00882 | 62 | } |
6b8ce727 | 63 | |
9e0b60a8 JM |
64 | # The variable gdb_prompt is a regexp which matches the gdb prompt. |
65 | # Set it if it is not already set. | |
c906108c | 66 | global gdb_prompt |
9e0b60a8 | 67 | if ![info exists gdb_prompt] then { |
c906108c SS |
68 | set gdb_prompt "\[(\]gdb\[)\]" |
69 | } | |
70 | ||
6006a3a1 BR |
71 | # The variable fullname_syntax_POSIX is a regexp which matches a POSIX |
72 | # absolute path ie. /foo/ | |
d0b76dc6 | 73 | set fullname_syntax_POSIX {/[^\n]*/} |
6006a3a1 BR |
74 | # The variable fullname_syntax_UNC is a regexp which matches a Windows |
75 | # UNC path ie. \\D\foo\ | |
d0b76dc6 | 76 | set fullname_syntax_UNC {\\\\[^\\]+\\[^\n]+\\} |
6006a3a1 BR |
77 | # The variable fullname_syntax_DOS_CASE is a regexp which matches a |
78 | # particular DOS case that GDB most likely will output | |
79 | # ie. \foo\, but don't match \\.*\ | |
d0b76dc6 | 80 | set fullname_syntax_DOS_CASE {\\[^\\][^\n]*\\} |
6006a3a1 BR |
81 | # The variable fullname_syntax_DOS is a regexp which matches a DOS path |
82 | # ie. a:\foo\ && a:foo\ | |
d0b76dc6 | 83 | set fullname_syntax_DOS {[a-zA-Z]:[^\n]*\\} |
6006a3a1 BR |
84 | # The variable fullname_syntax is a regexp which matches what GDB considers |
85 | # an absolute path. It is currently debatable if the Windows style paths | |
86 | # d:foo and \abc should be considered valid as an absolute path. | |
87 | # Also, the purpse of this regexp is not to recognize a well formed | |
88 | # absolute path, but to say with certainty that a path is absolute. | |
89 | set fullname_syntax "($fullname_syntax_POSIX|$fullname_syntax_UNC|$fullname_syntax_DOS_CASE|$fullname_syntax_DOS)" | |
90 | ||
93076499 ND |
91 | # Needed for some tests under Cygwin. |
92 | global EXEEXT | |
93 | global env | |
94 | ||
95 | if ![info exists env(EXEEXT)] { | |
96 | set EXEEXT "" | |
97 | } else { | |
98 | set EXEEXT $env(EXEEXT) | |
99 | } | |
100 | ||
bb2bed55 NR |
101 | set octal "\[0-7\]+" |
102 | ||
eceb0c5f | 103 | set inferior_exited_re "(\\\[Inferior \[0-9\]+ \\(.*\\) exited)" |
fda326dd | 104 | |
085dd6e6 JM |
105 | ### Only procedures should come after this point. |
106 | ||
c906108c SS |
107 | # |
108 | # gdb_version -- extract and print the version number of GDB | |
109 | # | |
110 | proc default_gdb_version {} { | |
111 | global GDB | |
6b8ce727 | 112 | global INTERNAL_GDBFLAGS GDBFLAGS |
c906108c | 113 | global gdb_prompt |
fa335448 | 114 | set output [remote_exec host "$GDB $INTERNAL_GDBFLAGS --version"] |
c906108c SS |
115 | set tmp [lindex $output 1]; |
116 | set version "" | |
117 | regexp " \[0-9\]\[^ \t\n\r\]+" "$tmp" version | |
118 | if ![is_remote host] { | |
6b8ce727 | 119 | clone_output "[which $GDB] version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n" |
c906108c | 120 | } else { |
6b8ce727 | 121 | clone_output "$GDB on remote host version $version $INTERNAL_GDBFLAGS $GDBFLAGS\n" |
c906108c SS |
122 | } |
123 | } | |
124 | ||
125 | proc gdb_version { } { | |
ae59b1da | 126 | return [default_gdb_version] |
c906108c SS |
127 | } |
128 | ||
129 | # | |
130 | # gdb_unload -- unload a file if one is loaded | |
608e2dbb | 131 | # Return 0 on success, -1 on error. |
c906108c SS |
132 | # |
133 | ||
134 | proc gdb_unload {} { | |
135 | global verbose | |
136 | global GDB | |
137 | global gdb_prompt | |
138 | send_gdb "file\n" | |
139 | gdb_expect 60 { | |
140 | -re "No executable file now\[^\r\n\]*\[\r\n\]" { exp_continue } | |
141 | -re "No symbol file now\[^\r\n\]*\[\r\n\]" { exp_continue } | |
959e7469 PM |
142 | -re "A program is being debugged already.*Are you sure you want to change the file.*y or n. $" { |
143 | send_gdb "y\n" | |
c906108c SS |
144 | exp_continue |
145 | } | |
146 | -re "Discard symbol table from .*y or n.*$" { | |
147 | send_gdb "y\n" | |
148 | exp_continue | |
149 | } | |
150 | -re "$gdb_prompt $" {} | |
151 | timeout { | |
975531db | 152 | perror "couldn't unload file in $GDB (timeout)." |
c906108c SS |
153 | return -1 |
154 | } | |
155 | } | |
608e2dbb | 156 | return 0 |
c906108c SS |
157 | } |
158 | ||
159 | # Many of the tests depend on setting breakpoints at various places and | |
160 | # running until that breakpoint is reached. At times, we want to start | |
161 | # with a clean-slate with respect to breakpoints, so this utility proc | |
162 | # lets us do this without duplicating this code everywhere. | |
163 | # | |
164 | ||
165 | proc delete_breakpoints {} { | |
166 | global gdb_prompt | |
167 | ||
a0b3c4fd JM |
168 | # we need a larger timeout value here or this thing just confuses |
169 | # itself. May need a better implementation if possible. - guo | |
170 | # | |
c906108c | 171 | send_gdb "delete breakpoints\n" |
a0b3c4fd | 172 | gdb_expect 100 { |
c906108c SS |
173 | -re "Delete all breakpoints.*y or n.*$" { |
174 | send_gdb "y\n"; | |
175 | exp_continue | |
176 | } | |
177 | -re "$gdb_prompt $" { # This happens if there were no breakpoints | |
178 | } | |
179 | timeout { perror "Delete all breakpoints in delete_breakpoints (timeout)" ; return } | |
180 | } | |
181 | send_gdb "info breakpoints\n" | |
a0b3c4fd | 182 | gdb_expect 100 { |
c906108c SS |
183 | -re "No breakpoints or watchpoints..*$gdb_prompt $" {} |
184 | -re "$gdb_prompt $" { perror "breakpoints not deleted" ; return } | |
185 | -re "Delete all breakpoints.*or n.*$" { | |
186 | send_gdb "y\n"; | |
187 | exp_continue | |
188 | } | |
189 | timeout { perror "info breakpoints (timeout)" ; return } | |
190 | } | |
191 | } | |
192 | ||
c906108c SS |
193 | # Generic run command. |
194 | # | |
195 | # The second pattern below matches up to the first newline *only*. | |
196 | # Using ``.*$'' could swallow up output that we attempt to match | |
197 | # elsewhere. | |
198 | # | |
1d41d75c DE |
199 | # N.B. This function does not wait for gdb to return to the prompt, |
200 | # that is the caller's responsibility. | |
201 | ||
c906108c | 202 | proc gdb_run_cmd {args} { |
e11ac3a3 | 203 | global gdb_prompt use_gdb_stub |
c906108c SS |
204 | |
205 | if [target_info exists gdb_init_command] { | |
206 | send_gdb "[target_info gdb_init_command]\n"; | |
207 | gdb_expect 30 { | |
208 | -re "$gdb_prompt $" { } | |
209 | default { | |
210 | perror "gdb_init_command for target failed"; | |
211 | return; | |
212 | } | |
213 | } | |
214 | } | |
215 | ||
e11ac3a3 | 216 | if $use_gdb_stub { |
c906108c | 217 | if [target_info exists gdb,do_reload_on_run] { |
b741e217 | 218 | if { [gdb_reload] != 0 } { |
917317f4 JM |
219 | return; |
220 | } | |
c906108c SS |
221 | send_gdb "continue\n"; |
222 | gdb_expect 60 { | |
223 | -re "Continu\[^\r\n\]*\[\r\n\]" {} | |
224 | default {} | |
225 | } | |
226 | return; | |
227 | } | |
228 | ||
229 | if [target_info exists gdb,start_symbol] { | |
230 | set start [target_info gdb,start_symbol]; | |
231 | } else { | |
232 | set start "start"; | |
233 | } | |
234 | send_gdb "jump *$start\n" | |
917317f4 JM |
235 | set start_attempt 1; |
236 | while { $start_attempt } { | |
237 | # Cap (re)start attempts at three to ensure that this loop | |
238 | # always eventually fails. Don't worry about trying to be | |
239 | # clever and not send a command when it has failed. | |
240 | if [expr $start_attempt > 3] { | |
241 | perror "Jump to start() failed (retry count exceeded)"; | |
c906108c SS |
242 | return; |
243 | } | |
917317f4 JM |
244 | set start_attempt [expr $start_attempt + 1]; |
245 | gdb_expect 30 { | |
246 | -re "Continuing at \[^\r\n\]*\[\r\n\]" { | |
247 | set start_attempt 0; | |
248 | } | |
249 | -re "No symbol \"_start\" in current.*$gdb_prompt $" { | |
250 | perror "Can't find start symbol to run in gdb_run"; | |
251 | return; | |
252 | } | |
253 | -re "No symbol \"start\" in current.*$gdb_prompt $" { | |
254 | send_gdb "jump *_start\n"; | |
255 | } | |
256 | -re "No symbol.*context.*$gdb_prompt $" { | |
257 | set start_attempt 0; | |
258 | } | |
259 | -re "Line.* Jump anyway.*y or n. $" { | |
260 | send_gdb "y\n" | |
261 | } | |
262 | -re "The program is not being run.*$gdb_prompt $" { | |
b741e217 | 263 | if { [gdb_reload] != 0 } { |
917317f4 JM |
264 | return; |
265 | } | |
266 | send_gdb "jump *$start\n"; | |
267 | } | |
268 | timeout { | |
269 | perror "Jump to start() failed (timeout)"; | |
270 | return | |
271 | } | |
c906108c | 272 | } |
c906108c | 273 | } |
c906108c SS |
274 | return |
275 | } | |
83f66e8f DJ |
276 | |
277 | if [target_info exists gdb,do_reload_on_run] { | |
b741e217 | 278 | if { [gdb_reload] != 0 } { |
83f66e8f DJ |
279 | return; |
280 | } | |
281 | } | |
c906108c SS |
282 | send_gdb "run $args\n" |
283 | # This doesn't work quite right yet. | |
5aa7ddc2 PM |
284 | # Use -notransfer here so that test cases (like chng-sym.exp) |
285 | # may test for additional start-up messages. | |
286 | gdb_expect 60 { | |
c906108c SS |
287 | -re "The program .* has been started already.*y or n. $" { |
288 | send_gdb "y\n" | |
289 | exp_continue | |
290 | } | |
bbb88ebf | 291 | -notransfer -re "Starting program: \[^\r\n\]*" {} |
8e46892c JK |
292 | -notransfer -re "$gdb_prompt $" { |
293 | # There is no more input expected. | |
294 | } | |
c906108c SS |
295 | } |
296 | } | |
297 | ||
b741e217 DJ |
298 | # Generic start command. Return 0 if we could start the program, -1 |
299 | # if we could not. | |
1d41d75c DE |
300 | # |
301 | # N.B. This function does not wait for gdb to return to the prompt, | |
302 | # that is the caller's responsibility. | |
b741e217 DJ |
303 | |
304 | proc gdb_start_cmd {args} { | |
e11ac3a3 | 305 | global gdb_prompt use_gdb_stub |
b741e217 DJ |
306 | |
307 | if [target_info exists gdb_init_command] { | |
308 | send_gdb "[target_info gdb_init_command]\n"; | |
309 | gdb_expect 30 { | |
310 | -re "$gdb_prompt $" { } | |
311 | default { | |
312 | perror "gdb_init_command for target failed"; | |
ae59b1da | 313 | return -1 |
b741e217 DJ |
314 | } |
315 | } | |
316 | } | |
317 | ||
e11ac3a3 | 318 | if $use_gdb_stub { |
b741e217 DJ |
319 | return -1 |
320 | } | |
321 | ||
322 | send_gdb "start $args\n" | |
2de75e71 JB |
323 | # Use -notransfer here so that test cases (like chng-sym.exp) |
324 | # may test for additional start-up messages. | |
b741e217 DJ |
325 | gdb_expect 60 { |
326 | -re "The program .* has been started already.*y or n. $" { | |
327 | send_gdb "y\n" | |
328 | exp_continue | |
329 | } | |
b741e217 DJ |
330 | -notransfer -re "Starting program: \[^\r\n\]*" { |
331 | return 0 | |
332 | } | |
333 | } | |
334 | return -1 | |
335 | } | |
336 | ||
78a1a894 | 337 | # Set a breakpoint at FUNCTION. If there is an additional argument it is |
55cd6f92 | 338 | # a list of options; the supported options are allow-pending, temporary, |
5b7d0050 DE |
339 | # message, no-message, and passfail. |
340 | # The result is 1 for success, 0 for failure. | |
341 | # | |
342 | # Note: The handling of message vs no-message is messed up, but it's based | |
343 | # on historical usage. By default this function does not print passes, | |
344 | # only fails. | |
345 | # no-message: turns off printing of fails (and passes, but they're already off) | |
346 | # message: turns on printing of passes (and fails, but they're already on) | |
78a1a894 DJ |
347 | |
348 | proc gdb_breakpoint { function args } { | |
c906108c SS |
349 | global gdb_prompt |
350 | global decimal | |
351 | ||
78a1a894 | 352 | set pending_response n |
5b7d0050 | 353 | if {[lsearch -exact $args allow-pending] != -1} { |
78a1a894 DJ |
354 | set pending_response y |
355 | } | |
356 | ||
e48883f7 | 357 | set break_command "break" |
18ac113b | 358 | set break_message "Breakpoint" |
5b7d0050 | 359 | if {[lsearch -exact $args temporary] != -1} { |
e48883f7 | 360 | set break_command "tbreak" |
18ac113b | 361 | set break_message "Temporary breakpoint" |
e48883f7 DJ |
362 | } |
363 | ||
5b7d0050 DE |
364 | set print_pass 0 |
365 | set print_fail 1 | |
366 | set no_message_loc [lsearch -exact $args no-message] | |
367 | set message_loc [lsearch -exact $args message] | |
368 | # The last one to appear in args wins. | |
369 | if { $no_message_loc > $message_loc } { | |
370 | set print_fail 0 | |
371 | } elseif { $message_loc > $no_message_loc } { | |
372 | set print_pass 1 | |
55cd6f92 DJ |
373 | } |
374 | ||
5b7d0050 DE |
375 | set test_name "setting breakpoint at $function" |
376 | ||
e48883f7 | 377 | send_gdb "$break_command $function\n" |
c906108c SS |
378 | # The first two regexps are what we get with -g, the third is without -g. |
379 | gdb_expect 30 { | |
18ac113b AR |
380 | -re "$break_message \[0-9\]* at .*: file .*, line $decimal.\r\n$gdb_prompt $" {} |
381 | -re "$break_message \[0-9\]*: file .*, line $decimal.\r\n$gdb_prompt $" {} | |
382 | -re "$break_message \[0-9\]* at .*$gdb_prompt $" {} | |
383 | -re "$break_message \[0-9\]* \\(.*\\) pending.*$gdb_prompt $" { | |
78a1a894 | 384 | if {$pending_response == "n"} { |
5b7d0050 DE |
385 | if { $print_fail } { |
386 | fail $test_name | |
55cd6f92 | 387 | } |
78a1a894 DJ |
388 | return 0 |
389 | } | |
390 | } | |
9f27c604 | 391 | -re "Make breakpoint pending.*y or \\\[n\\\]. $" { |
78a1a894 | 392 | send_gdb "$pending_response\n" |
14b1a056 | 393 | exp_continue |
18fe2033 | 394 | } |
28781456 | 395 | -re "A problem internal to GDB has been detected" { |
5b7d0050 DE |
396 | if { $print_fail } { |
397 | fail "$test_name (GDB internal error)" | |
398 | } | |
28781456 JK |
399 | gdb_internal_error_resync |
400 | return 0 | |
401 | } | |
55cd6f92 | 402 | -re "$gdb_prompt $" { |
5b7d0050 DE |
403 | if { $print_fail } { |
404 | fail $test_name | |
405 | } | |
406 | return 0 | |
407 | } | |
408 | eof { | |
409 | if { $print_fail } { | |
410 | fail "$test_name (eof)" | |
55cd6f92 DJ |
411 | } |
412 | return 0 | |
413 | } | |
414 | timeout { | |
5b7d0050 DE |
415 | if { $print_fail } { |
416 | fail "$test_name (timeout)" | |
55cd6f92 DJ |
417 | } |
418 | return 0 | |
419 | } | |
c906108c | 420 | } |
5b7d0050 DE |
421 | if { $print_pass } { |
422 | pass $test_name | |
423 | } | |
ae59b1da | 424 | return 1 |
c906108c SS |
425 | } |
426 | ||
427 | # Set breakpoint at function and run gdb until it breaks there. | |
428 | # Since this is the only breakpoint that will be set, if it stops | |
429 | # at a breakpoint, we will assume it is the one we want. We can't | |
430 | # just compare to "function" because it might be a fully qualified, | |
5b7d0050 DE |
431 | # single quoted C++ function specifier. |
432 | # | |
433 | # If there are additional arguments, pass them to gdb_breakpoint. | |
434 | # We recognize no-message/message ourselves. | |
435 | # The default is no-message. | |
436 | # no-message is messed up here, like gdb_breakpoint: to preserve | |
437 | # historical usage fails are always printed by default. | |
438 | # no-message: turns off printing of fails (and passes, but they're already off) | |
439 | # message: turns on printing of passes (and fails, but they're already on) | |
c906108c | 440 | |
78a1a894 | 441 | proc runto { function args } { |
c906108c SS |
442 | global gdb_prompt |
443 | global decimal | |
444 | ||
445 | delete_breakpoints | |
446 | ||
5b7d0050 DE |
447 | # Default to "no-message". |
448 | set args "no-message $args" | |
449 | ||
450 | set print_pass 0 | |
451 | set print_fail 1 | |
452 | set no_message_loc [lsearch -exact $args no-message] | |
453 | set message_loc [lsearch -exact $args message] | |
454 | # The last one to appear in args wins. | |
455 | if { $no_message_loc > $message_loc } { | |
456 | set print_fail 0 | |
457 | } elseif { $message_loc > $no_message_loc } { | |
458 | set print_pass 1 | |
459 | } | |
460 | ||
461 | set test_name "running to $function in runto" | |
462 | ||
463 | # We need to use eval here to pass our varargs args to gdb_breakpoint | |
464 | # which is also a varargs function. | |
2c47921e DE |
465 | # But we also have to be careful because $function may have multiple |
466 | # elements, and we don't want Tcl to move the remaining elements after | |
467 | # the first to $args. That is why $function is wrapped in {}. | |
468 | if ![eval gdb_breakpoint {$function} $args] { | |
ae59b1da | 469 | return 0 |
c906108c SS |
470 | } |
471 | ||
472 | gdb_run_cmd | |
473 | ||
474 | # the "at foo.c:36" output we get with -g. | |
475 | # the "in func" output we get without -g. | |
476 | gdb_expect 30 { | |
477 | -re "Break.* at .*:$decimal.*$gdb_prompt $" { | |
5b7d0050 DE |
478 | if { $print_pass } { |
479 | pass $test_name | |
480 | } | |
c906108c SS |
481 | return 1 |
482 | } | |
483 | -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in .*$gdb_prompt $" { | |
5b7d0050 DE |
484 | if { $print_pass } { |
485 | pass $test_name | |
486 | } | |
c906108c SS |
487 | return 1 |
488 | } | |
8e46892c | 489 | -re "The target does not support running in non-stop mode.\r\n$gdb_prompt $" { |
5b7d0050 DE |
490 | if { $print_fail } { |
491 | unsupported "Non-stop mode not supported" | |
492 | } | |
8e46892c JK |
493 | return 0 |
494 | } | |
569b05a5 | 495 | -re ".*A problem internal to GDB has been detected" { |
5b7d0050 DE |
496 | if { $print_fail } { |
497 | fail "$test_name (GDB internal error)" | |
498 | } | |
569b05a5 JK |
499 | gdb_internal_error_resync |
500 | return 0 | |
501 | } | |
c906108c | 502 | -re "$gdb_prompt $" { |
5b7d0050 DE |
503 | if { $print_fail } { |
504 | fail $test_name | |
505 | } | |
c906108c SS |
506 | return 0 |
507 | } | |
72c63395 | 508 | eof { |
5b7d0050 DE |
509 | if { $print_fail } { |
510 | fail "$test_name (eof)" | |
511 | } | |
72c63395 JK |
512 | return 0 |
513 | } | |
c906108c | 514 | timeout { |
5b7d0050 DE |
515 | if { $print_fail } { |
516 | fail "$test_name (timeout)" | |
517 | } | |
c906108c SS |
518 | return 0 |
519 | } | |
520 | } | |
5b7d0050 DE |
521 | if { $print_pass } { |
522 | pass $test_name | |
523 | } | |
c906108c SS |
524 | return 1 |
525 | } | |
526 | ||
1d41d75c | 527 | # Ask gdb to run until we hit a breakpoint at main. |
c906108c | 528 | # |
1d41d75c DE |
529 | # N.B. This function deletes all existing breakpoints. |
530 | # If you don't want that, use gdb_start_cmd. | |
531 | ||
c906108c | 532 | proc runto_main { } { |
5b7d0050 | 533 | return [runto main no-message] |
c906108c SS |
534 | } |
535 | ||
4ce44c66 JM |
536 | ### Continue, and expect to hit a breakpoint. |
537 | ### Report a pass or fail, depending on whether it seems to have | |
538 | ### worked. Use NAME as part of the test name; each call to | |
539 | ### continue_to_breakpoint should use a NAME which is unique within | |
540 | ### that test file. | |
74960c60 | 541 | proc gdb_continue_to_breakpoint {name {location_pattern .*}} { |
4ce44c66 JM |
542 | global gdb_prompt |
543 | set full_name "continue to breakpoint: $name" | |
544 | ||
545 | send_gdb "continue\n" | |
546 | gdb_expect { | |
a1624241 | 547 | -re "(?:Breakpoint|Temporary breakpoint) .* (at|in) $location_pattern\r\n$gdb_prompt $" { |
4ce44c66 JM |
548 | pass $full_name |
549 | } | |
550 | -re ".*$gdb_prompt $" { | |
551 | fail $full_name | |
552 | } | |
553 | timeout { | |
554 | fail "$full_name (timeout)" | |
555 | } | |
556 | } | |
557 | } | |
558 | ||
559 | ||
039cf96d AC |
560 | # gdb_internal_error_resync: |
561 | # | |
562 | # Answer the questions GDB asks after it reports an internal error | |
563 | # until we get back to a GDB prompt. Decline to quit the debugging | |
564 | # session, and decline to create a core file. Return non-zero if the | |
565 | # resync succeeds. | |
566 | # | |
567 | # This procedure just answers whatever questions come up until it sees | |
568 | # a GDB prompt; it doesn't require you to have matched the input up to | |
569 | # any specific point. However, it only answers questions it sees in | |
570 | # the output itself, so if you've matched a question, you had better | |
571 | # answer it yourself before calling this. | |
572 | # | |
573 | # You can use this function thus: | |
574 | # | |
575 | # gdb_expect { | |
576 | # ... | |
577 | # -re ".*A problem internal to GDB has been detected" { | |
578 | # gdb_internal_error_resync | |
579 | # } | |
580 | # ... | |
581 | # } | |
582 | # | |
583 | proc gdb_internal_error_resync {} { | |
584 | global gdb_prompt | |
585 | ||
5b7d0050 DE |
586 | verbose -log "Resyncing due to internal error." |
587 | ||
039cf96d AC |
588 | set count 0 |
589 | while {$count < 10} { | |
590 | gdb_expect { | |
591 | -re "Quit this debugging session\\? \\(y or n\\) $" { | |
592 | send_gdb "n\n" | |
593 | incr count | |
594 | } | |
595 | -re "Create a core file of GDB\\? \\(y or n\\) $" { | |
596 | send_gdb "n\n" | |
597 | incr count | |
598 | } | |
599 | -re "$gdb_prompt $" { | |
600 | # We're resynchronized. | |
601 | return 1 | |
602 | } | |
603 | timeout { | |
604 | perror "Could not resync from internal error (timeout)" | |
605 | return 0 | |
606 | } | |
607 | } | |
608 | } | |
2b211c59 AC |
609 | perror "Could not resync from internal error (resync count exceeded)" |
610 | return 0 | |
039cf96d AC |
611 | } |
612 | ||
4ce44c66 | 613 | |
2307bd6a | 614 | # gdb_test_multiple COMMAND MESSAGE EXPECT_ARGUMENTS |
8dbfb380 | 615 | # Send a command to gdb; test the result. |
c906108c SS |
616 | # |
617 | # COMMAND is the command to execute, send to GDB with send_gdb. If | |
618 | # this is the null string no command is sent. | |
2307bd6a DJ |
619 | # MESSAGE is a message to be printed with the built-in failure patterns |
620 | # if one of them matches. If MESSAGE is empty COMMAND will be used. | |
621 | # EXPECT_ARGUMENTS will be fed to expect in addition to the standard | |
622 | # patterns. Pattern elements will be evaluated in the caller's | |
623 | # context; action elements will be executed in the caller's context. | |
624 | # Unlike patterns for gdb_test, these patterns should generally include | |
625 | # the final newline and prompt. | |
c906108c SS |
626 | # |
627 | # Returns: | |
2307bd6a DJ |
628 | # 1 if the test failed, according to a built-in failure pattern |
629 | # 0 if only user-supplied patterns matched | |
c906108c SS |
630 | # -1 if there was an internal error. |
631 | # | |
d422fe19 AC |
632 | # You can use this function thus: |
633 | # | |
634 | # gdb_test_multiple "print foo" "test foo" { | |
635 | # -re "expected output 1" { | |
636 | # pass "print foo" | |
637 | # } | |
638 | # -re "expected output 2" { | |
639 | # fail "print foo" | |
640 | # } | |
641 | # } | |
642 | # | |
fda326dd | 643 | # The standard patterns, such as "Inferior exited..." and "A problem |
d422fe19 AC |
644 | # ...", all being implicitly appended to that list. |
645 | # | |
2307bd6a | 646 | proc gdb_test_multiple { command message user_code } { |
e11ac3a3 | 647 | global verbose use_gdb_stub |
c906108c SS |
648 | global gdb_prompt |
649 | global GDB | |
fda326dd | 650 | global inferior_exited_re |
c906108c | 651 | upvar timeout timeout |
c47cebdb | 652 | upvar expect_out expect_out |
c906108c | 653 | |
2307bd6a DJ |
654 | if { $message == "" } { |
655 | set message $command | |
c906108c | 656 | } |
c906108c | 657 | |
824cc8dd JK |
658 | if [string match "*\[\r\n\]" $command] { |
659 | error "Invalid trailing newline in \"$message\" test" | |
660 | } | |
661 | ||
8344e389 JK |
662 | if [string match "*\[\r\n\]*" $message] { |
663 | error "Invalid newline in \"$message\" test" | |
664 | } | |
665 | ||
e11ac3a3 | 666 | if {$use_gdb_stub |
9bfee719 | 667 | && [regexp -nocase {^\s*(r|run|star|start|at|att|atta|attac|attach)\M} \ |
e11ac3a3 JK |
668 | $command]} { |
669 | error "gdbserver does not support $command without extended-remote" | |
670 | } | |
671 | ||
2307bd6a DJ |
672 | # TCL/EXPECT WART ALERT |
673 | # Expect does something very strange when it receives a single braced | |
674 | # argument. It splits it along word separators and performs substitutions. | |
675 | # This means that { "[ab]" } is evaluated as "[ab]", but { "\[ab\]" } is | |
676 | # evaluated as "\[ab\]". But that's not how TCL normally works; inside a | |
677 | # double-quoted list item, "\[ab\]" is just a long way of representing | |
678 | # "[ab]", because the backslashes will be removed by lindex. | |
679 | ||
680 | # Unfortunately, there appears to be no easy way to duplicate the splitting | |
681 | # that expect will do from within TCL. And many places make use of the | |
682 | # "\[0-9\]" construct, so we need to support that; and some places make use | |
683 | # of the "[func]" construct, so we need to support that too. In order to | |
684 | # get this right we have to substitute quoted list elements differently | |
685 | # from braced list elements. | |
686 | ||
687 | # We do this roughly the same way that Expect does it. We have to use two | |
688 | # lists, because if we leave unquoted newlines in the argument to uplevel | |
689 | # they'll be treated as command separators, and if we escape newlines | |
690 | # we mangle newlines inside of command blocks. This assumes that the | |
691 | # input doesn't contain a pattern which contains actual embedded newlines | |
692 | # at this point! | |
693 | ||
694 | regsub -all {\n} ${user_code} { } subst_code | |
695 | set subst_code [uplevel list $subst_code] | |
696 | ||
697 | set processed_code "" | |
698 | set patterns "" | |
699 | set expecting_action 0 | |
21e24d21 | 700 | set expecting_arg 0 |
2307bd6a DJ |
701 | foreach item $user_code subst_item $subst_code { |
702 | if { $item == "-n" || $item == "-notransfer" || $item == "-nocase" } { | |
703 | lappend processed_code $item | |
704 | continue | |
705 | } | |
21e24d21 PA |
706 | if { $item == "-indices" || $item == "-re" || $item == "-ex" } { |
707 | lappend processed_code $item | |
708 | continue | |
709 | } | |
710 | if { $item == "-timeout" } { | |
711 | set expecting_arg 1 | |
712 | lappend processed_code $item | |
713 | continue | |
714 | } | |
715 | if { $expecting_arg } { | |
716 | set expecting_arg 0 | |
2307bd6a DJ |
717 | lappend processed_code $item |
718 | continue | |
719 | } | |
720 | if { $expecting_action } { | |
721 | lappend processed_code "uplevel [list $item]" | |
722 | set expecting_action 0 | |
723 | # Cosmetic, no effect on the list. | |
724 | append processed_code "\n" | |
725 | continue | |
726 | } | |
727 | set expecting_action 1 | |
728 | lappend processed_code $subst_item | |
729 | if {$patterns != ""} { | |
730 | append patterns "; " | |
731 | } | |
732 | append patterns "\"$subst_item\"" | |
c906108c SS |
733 | } |
734 | ||
2307bd6a DJ |
735 | # Also purely cosmetic. |
736 | regsub -all {\r} $patterns {\\r} patterns | |
737 | regsub -all {\n} $patterns {\\n} patterns | |
738 | ||
c906108c SS |
739 | if $verbose>2 then { |
740 | send_user "Sending \"$command\" to gdb\n" | |
2307bd6a | 741 | send_user "Looking to match \"$patterns\"\n" |
c906108c SS |
742 | send_user "Message is \"$message\"\n" |
743 | } | |
744 | ||
745 | set result -1 | |
746 | set string "${command}\n"; | |
747 | if { $command != "" } { | |
543a9323 | 748 | set multi_line_re "\[\r\n\] *>" |
c906108c SS |
749 | while { "$string" != "" } { |
750 | set foo [string first "\n" "$string"]; | |
751 | set len [string length "$string"]; | |
752 | if { $foo < [expr $len - 1] } { | |
753 | set str [string range "$string" 0 $foo]; | |
754 | if { [send_gdb "$str"] != "" } { | |
755 | global suppress_flag; | |
756 | ||
757 | if { ! $suppress_flag } { | |
758 | perror "Couldn't send $command to GDB."; | |
759 | } | |
760 | fail "$message"; | |
ae59b1da | 761 | return $result |
c906108c | 762 | } |
a0b3c4fd JM |
763 | # since we're checking if each line of the multi-line |
764 | # command are 'accepted' by GDB here, | |
765 | # we need to set -notransfer expect option so that | |
766 | # command output is not lost for pattern matching | |
767 | # - guo | |
5f279fa6 | 768 | gdb_expect 2 { |
543a9323 | 769 | -notransfer -re "$multi_line_re$" { verbose "partial: match" 3 } |
5f279fa6 | 770 | timeout { verbose "partial: timeout" 3 } |
c906108c SS |
771 | } |
772 | set string [string range "$string" [expr $foo + 1] end]; | |
543a9323 | 773 | set multi_line_re "$multi_line_re.*\[\r\n\] *>" |
c906108c SS |
774 | } else { |
775 | break; | |
776 | } | |
777 | } | |
778 | if { "$string" != "" } { | |
779 | if { [send_gdb "$string"] != "" } { | |
780 | global suppress_flag; | |
781 | ||
782 | if { ! $suppress_flag } { | |
783 | perror "Couldn't send $command to GDB."; | |
784 | } | |
785 | fail "$message"; | |
ae59b1da | 786 | return $result |
c906108c SS |
787 | } |
788 | } | |
789 | } | |
790 | ||
9d2e1bab ND |
791 | if [target_info exists gdb,timeout] { |
792 | set tmt [target_info gdb,timeout]; | |
c906108c | 793 | } else { |
c906108c SS |
794 | if [info exists timeout] { |
795 | set tmt $timeout; | |
796 | } else { | |
9d2e1bab ND |
797 | global timeout; |
798 | if [info exists timeout] { | |
799 | set tmt $timeout; | |
800 | } else { | |
801 | set tmt 60; | |
802 | } | |
c906108c SS |
803 | } |
804 | } | |
2307bd6a DJ |
805 | |
806 | set code { | |
9bfee719 MR |
807 | -re ".*A problem internal to GDB has been detected" { |
808 | fail "$message (GDB internal error)" | |
809 | gdb_internal_error_resync | |
810 | } | |
811 | -re "\\*\\*\\* DOSEXIT code.*" { | |
812 | if { $message != "" } { | |
813 | fail "$message"; | |
814 | } | |
815 | gdb_suppress_entire_file "GDB died"; | |
816 | set result -1; | |
817 | } | |
b0f4b84b DJ |
818 | } |
819 | append code $processed_code | |
820 | append code { | |
9bfee719 | 821 | -re "Ending remote debugging.*$gdb_prompt $" { |
c906108c SS |
822 | if ![isnative] then { |
823 | warning "Can`t communicate to remote target." | |
824 | } | |
825 | gdb_exit | |
826 | gdb_start | |
827 | set result -1 | |
828 | } | |
9bfee719 | 829 | -re "Undefined\[a-z\]* command:.*$gdb_prompt $" { |
c906108c | 830 | perror "Undefined command \"$command\"." |
9bfee719 | 831 | fail "$message" |
c906108c SS |
832 | set result 1 |
833 | } | |
9bfee719 | 834 | -re "Ambiguous command.*$gdb_prompt $" { |
c906108c | 835 | perror "\"$command\" is not a unique command name." |
9bfee719 | 836 | fail "$message" |
c906108c SS |
837 | set result 1 |
838 | } | |
9bfee719 | 839 | -re "$inferior_exited_re with code \[0-9\]+.*$gdb_prompt $" { |
c906108c | 840 | if ![string match "" $message] then { |
ed4c619a | 841 | set errmsg "$message (the program exited)" |
c906108c | 842 | } else { |
ed4c619a | 843 | set errmsg "$command (the program exited)" |
c906108c SS |
844 | } |
845 | fail "$errmsg" | |
2307bd6a | 846 | set result -1 |
cb9a9d3e | 847 | } |
9bfee719 | 848 | -re "$inferior_exited_re normally.*$gdb_prompt $" { |
cb9a9d3e | 849 | if ![string match "" $message] then { |
ed4c619a | 850 | set errmsg "$message (the program exited)" |
cb9a9d3e | 851 | } else { |
ed4c619a | 852 | set errmsg "$command (the program exited)" |
cb9a9d3e MS |
853 | } |
854 | fail "$errmsg" | |
2307bd6a | 855 | set result -1 |
c906108c | 856 | } |
9bfee719 | 857 | -re "The program is not being run.*$gdb_prompt $" { |
c906108c | 858 | if ![string match "" $message] then { |
ed4c619a | 859 | set errmsg "$message (the program is no longer running)" |
c906108c | 860 | } else { |
ed4c619a | 861 | set errmsg "$command (the program is no longer running)" |
c906108c SS |
862 | } |
863 | fail "$errmsg" | |
2307bd6a | 864 | set result -1 |
c906108c | 865 | } |
9bfee719 | 866 | -re "\r\n$gdb_prompt $" { |
c906108c SS |
867 | if ![string match "" $message] then { |
868 | fail "$message" | |
869 | } | |
870 | set result 1 | |
871 | } | |
9bfee719 | 872 | "<return>" { |
c906108c SS |
873 | send_gdb "\n" |
874 | perror "Window too small." | |
9bfee719 | 875 | fail "$message" |
2307bd6a | 876 | set result -1 |
c906108c | 877 | } |
b598bfda | 878 | -re "\\((y or n|y or \\\[n\\\]|\\\[y\\\] or n)\\) " { |
c906108c | 879 | send_gdb "n\n" |
b598bfda DJ |
880 | gdb_expect -re "$gdb_prompt $" |
881 | fail "$message (got interactive prompt)" | |
882 | set result -1 | |
883 | } | |
884 | -re "\\\[0\\\] cancel\r\n\\\[1\\\] all.*\r\n> $" { | |
885 | send_gdb "0\n" | |
886 | gdb_expect -re "$gdb_prompt $" | |
887 | fail "$message (got breakpoint menu)" | |
2307bd6a | 888 | set result -1 |
c906108c | 889 | } |
9bfee719 MR |
890 | eof { |
891 | perror "Process no longer exists" | |
892 | if { $message != "" } { | |
893 | fail "$message" | |
894 | } | |
895 | return -1 | |
c906108c | 896 | } |
9bfee719 | 897 | full_buffer { |
c906108c | 898 | perror "internal buffer is full." |
9bfee719 | 899 | fail "$message" |
2307bd6a | 900 | set result -1 |
c906108c SS |
901 | } |
902 | timeout { | |
903 | if ![string match "" $message] then { | |
904 | fail "$message (timeout)" | |
905 | } | |
906 | set result 1 | |
907 | } | |
908 | } | |
2307bd6a DJ |
909 | |
910 | set result 0 | |
04f6ecf2 DJ |
911 | set code [catch {gdb_expect $tmt $code} string] |
912 | if {$code == 1} { | |
913 | global errorInfo errorCode; | |
914 | return -code error -errorinfo $errorInfo -errorcode $errorCode $string | |
d6d7a51a | 915 | } elseif {$code > 1} { |
04f6ecf2 DJ |
916 | return -code $code $string |
917 | } | |
c906108c SS |
918 | return $result |
919 | } | |
2307bd6a DJ |
920 | |
921 | # gdb_test COMMAND PATTERN MESSAGE QUESTION RESPONSE | |
922 | # Send a command to gdb; test the result. | |
923 | # | |
924 | # COMMAND is the command to execute, send to GDB with send_gdb. If | |
925 | # this is the null string no command is sent. | |
926 | # PATTERN is the pattern to match for a PASS, and must NOT include | |
927 | # the \r\n sequence immediately before the gdb prompt. | |
928 | # MESSAGE is an optional message to be printed. If this is | |
929 | # omitted, then the pass/fail messages use the command string as the | |
930 | # message. (If this is the empty string, then sometimes we don't | |
931 | # call pass or fail at all; I don't understand this at all.) | |
932 | # QUESTION is a question GDB may ask in response to COMMAND, like | |
933 | # "are you sure?" | |
934 | # RESPONSE is the response to send if QUESTION appears. | |
935 | # | |
936 | # Returns: | |
937 | # 1 if the test failed, | |
938 | # 0 if the test passes, | |
939 | # -1 if there was an internal error. | |
940 | # | |
941 | proc gdb_test { args } { | |
942 | global verbose | |
943 | global gdb_prompt | |
944 | global GDB | |
945 | upvar timeout timeout | |
946 | ||
947 | if [llength $args]>2 then { | |
948 | set message [lindex $args 2] | |
949 | } else { | |
950 | set message [lindex $args 0] | |
951 | } | |
952 | set command [lindex $args 0] | |
953 | set pattern [lindex $args 1] | |
954 | ||
955 | if [llength $args]==5 { | |
956 | set question_string [lindex $args 3]; | |
957 | set response_string [lindex $args 4]; | |
958 | } else { | |
959 | set question_string "^FOOBAR$" | |
960 | } | |
961 | ||
962 | return [gdb_test_multiple $command $message { | |
963 | -re "\[\r\n\]*($pattern)\[\r\n\]+$gdb_prompt $" { | |
964 | if ![string match "" $message] then { | |
965 | pass "$message" | |
966 | } | |
967 | } | |
968 | -re "(${question_string})$" { | |
969 | send_gdb "$response_string\n"; | |
970 | exp_continue; | |
971 | } | |
972 | }] | |
973 | } | |
a7b75dfd JB |
974 | |
975 | # gdb_test_no_output COMMAND MESSAGE | |
976 | # Send a command to GDB and verify that this command generated no output. | |
977 | # | |
978 | # See gdb_test_multiple for a description of the COMMAND and MESSAGE | |
979 | # parameters. If MESSAGE is ommitted, then COMMAND will be used as | |
c22decce JB |
980 | # the message. (If MESSAGE is the empty string, then sometimes we do not |
981 | # call pass or fail at all; I don't understand this at all.) | |
a7b75dfd JB |
982 | |
983 | proc gdb_test_no_output { args } { | |
984 | global gdb_prompt | |
985 | set command [lindex $args 0] | |
986 | if [llength $args]>1 then { | |
987 | set message [lindex $args 1] | |
988 | } else { | |
989 | set message $command | |
990 | } | |
991 | ||
992 | set command_regex [string_to_regexp $command] | |
993 | gdb_test_multiple $command $message { | |
994 | -re "^$command_regex\r\n$gdb_prompt $" { | |
c22decce JB |
995 | if ![string match "" $message] then { |
996 | pass "$message" | |
997 | } | |
a7b75dfd JB |
998 | } |
999 | } | |
1000 | } | |
1001 | ||
6b0ecdc2 DE |
1002 | # Send a command and then wait for a sequence of outputs. |
1003 | # This is useful when the sequence is long and contains ".*", a single | |
1004 | # regexp to match the entire output can get a timeout much easier. | |
1005 | # | |
1006 | # COMMAND is the command to send. | |
1007 | # TEST_NAME is passed to pass/fail. COMMAND is used if TEST_NAME is "". | |
1008 | # EXPECTED_OUTPUT_LIST is a list of regexps of expected output, which are | |
1009 | # processed in order, and all must be present in the output. | |
1010 | # | |
1011 | # It is unnecessary to specify ".*" at the beginning or end of any regexp, | |
1012 | # there is an implicit ".*" between each element of EXPECTED_OUTPUT_LIST. | |
1013 | # There is also an implicit ".*" between the last regexp and the gdb prompt. | |
1014 | # | |
1015 | # Like gdb_test and gdb_test_multiple, the output is expected to end with the | |
1016 | # gdb prompt, which must not be specified in EXPECTED_OUTPUT_LIST. | |
5fa290c1 DE |
1017 | # |
1018 | # Returns: | |
1019 | # 1 if the test failed, | |
1020 | # 0 if the test passes, | |
1021 | # -1 if there was an internal error. | |
6b0ecdc2 DE |
1022 | |
1023 | proc gdb_test_sequence { command test_name expected_output_list } { | |
1024 | global gdb_prompt | |
1025 | if { $test_name == "" } { | |
1026 | set test_name $command | |
1027 | } | |
1028 | lappend expected_output_list ""; # implicit ".*" before gdb prompt | |
1029 | send_gdb "$command\n" | |
5fa290c1 | 1030 | return [gdb_expect_list $test_name "$gdb_prompt $" $expected_output_list] |
6b0ecdc2 DE |
1031 | } |
1032 | ||
c906108c SS |
1033 | \f |
1034 | # Test that a command gives an error. For pass or fail, return | |
1035 | # a 1 to indicate that more tests can proceed. However a timeout | |
1036 | # is a serious error, generates a special fail message, and causes | |
1037 | # a 0 to be returned to indicate that more tests are likely to fail | |
1038 | # as well. | |
1039 | ||
1040 | proc test_print_reject { args } { | |
1041 | global gdb_prompt | |
1042 | global verbose | |
1043 | ||
1044 | if [llength $args]==2 then { | |
1045 | set expectthis [lindex $args 1] | |
1046 | } else { | |
1047 | set expectthis "should never match this bogus string" | |
1048 | } | |
1049 | set sendthis [lindex $args 0] | |
1050 | if $verbose>2 then { | |
1051 | send_user "Sending \"$sendthis\" to gdb\n" | |
1052 | send_user "Looking to match \"$expectthis\"\n" | |
1053 | } | |
1054 | send_gdb "$sendthis\n" | |
1055 | #FIXME: Should add timeout as parameter. | |
1056 | gdb_expect { | |
1057 | -re "A .* in expression.*\\.*$gdb_prompt $" { | |
1058 | pass "reject $sendthis" | |
1059 | return 1 | |
1060 | } | |
1061 | -re "Invalid syntax in expression.*$gdb_prompt $" { | |
1062 | pass "reject $sendthis" | |
1063 | return 1 | |
1064 | } | |
1065 | -re "Junk after end of expression.*$gdb_prompt $" { | |
1066 | pass "reject $sendthis" | |
1067 | return 1 | |
1068 | } | |
1069 | -re "Invalid number.*$gdb_prompt $" { | |
1070 | pass "reject $sendthis" | |
1071 | return 1 | |
1072 | } | |
1073 | -re "Invalid character constant.*$gdb_prompt $" { | |
1074 | pass "reject $sendthis" | |
1075 | return 1 | |
1076 | } | |
1077 | -re "No symbol table is loaded.*$gdb_prompt $" { | |
1078 | pass "reject $sendthis" | |
1079 | return 1 | |
1080 | } | |
1081 | -re "No symbol .* in current context.*$gdb_prompt $" { | |
1082 | pass "reject $sendthis" | |
1083 | return 1 | |
1084 | } | |
c4b7bc2b JB |
1085 | -re "Unmatched single quote.*$gdb_prompt $" { |
1086 | pass "reject $sendthis" | |
1087 | return 1 | |
1088 | } | |
1089 | -re "A character constant must contain at least one character.*$gdb_prompt $" { | |
1090 | pass "reject $sendthis" | |
1091 | return 1 | |
1092 | } | |
c906108c SS |
1093 | -re "$expectthis.*$gdb_prompt $" { |
1094 | pass "reject $sendthis" | |
1095 | return 1 | |
1096 | } | |
1097 | -re ".*$gdb_prompt $" { | |
1098 | fail "reject $sendthis" | |
1099 | return 1 | |
1100 | } | |
1101 | default { | |
1102 | fail "reject $sendthis (eof or timeout)" | |
1103 | return 0 | |
1104 | } | |
1105 | } | |
1106 | } | |
1107 | \f | |
1108 | # Given an input string, adds backslashes as needed to create a | |
1109 | # regexp that will match the string. | |
1110 | ||
1111 | proc string_to_regexp {str} { | |
1112 | set result $str | |
39fb8e9e | 1113 | regsub -all {[]*+.|()^$\[\\]} $str {\\&} result |
c906108c SS |
1114 | return $result |
1115 | } | |
1116 | ||
1117 | # Same as gdb_test, but the second parameter is not a regexp, | |
1118 | # but a string that must match exactly. | |
1119 | ||
1120 | proc gdb_test_exact { args } { | |
1121 | upvar timeout timeout | |
1122 | ||
1123 | set command [lindex $args 0] | |
1124 | ||
1125 | # This applies a special meaning to a null string pattern. Without | |
1126 | # this, "$pattern\r\n$gdb_prompt $" will match anything, including error | |
1127 | # messages from commands that should have no output except a new | |
1128 | # prompt. With this, only results of a null string will match a null | |
1129 | # string pattern. | |
1130 | ||
1131 | set pattern [lindex $args 1] | |
1132 | if [string match $pattern ""] { | |
1133 | set pattern [string_to_regexp [lindex $args 0]] | |
1134 | } else { | |
1135 | set pattern [string_to_regexp [lindex $args 1]] | |
1136 | } | |
1137 | ||
1138 | # It is most natural to write the pattern argument with only | |
1139 | # embedded \n's, especially if you are trying to avoid Tcl quoting | |
1140 | # problems. But gdb_expect really wants to see \r\n in patterns. So | |
1141 | # transform the pattern here. First transform \r\n back to \n, in | |
1142 | # case some users of gdb_test_exact already do the right thing. | |
1143 | regsub -all "\r\n" $pattern "\n" pattern | |
1144 | regsub -all "\n" $pattern "\r\n" pattern | |
1145 | if [llength $args]==3 then { | |
1146 | set message [lindex $args 2] | |
1147 | } else { | |
1148 | set message $command | |
1149 | } | |
1150 | ||
1151 | return [gdb_test $command $pattern $message] | |
1152 | } | |
2dfb8c17 DE |
1153 | |
1154 | # Wrapper around gdb_test_multiple that looks for a list of expected | |
1155 | # output elements, but which can appear in any order. | |
1156 | # CMD is the gdb command. | |
1157 | # NAME is the name of the test. | |
1158 | # ELM_FIND_REGEXP specifies how to partition the output into elements to | |
1159 | # compare. | |
1160 | # ELM_EXTRACT_REGEXP specifies the part of ELM_FIND_REGEXP to compare. | |
1161 | # RESULT_MATCH_LIST is a list of exact matches for each expected element. | |
1162 | # All elements of RESULT_MATCH_LIST must appear for the test to pass. | |
1163 | # | |
1164 | # A typical use of ELM_FIND_REGEXP/ELM_EXTRACT_REGEXP is to extract one line | |
1165 | # of text per element and then strip trailing \r\n's. | |
1166 | # Example: | |
1167 | # gdb_test_list_exact "foo" "bar" \ | |
eec52c44 PM |
1168 | # "\[^\r\n\]+\[\r\n\]+" \ |
1169 | # "\[^\r\n\]+" \ | |
2dfb8c17 DE |
1170 | # { \ |
1171 | # {expected result 1} \ | |
1172 | # {expected result 2} \ | |
1173 | # } | |
1174 | ||
1175 | proc gdb_test_list_exact { cmd name elm_find_regexp elm_extract_regexp result_match_list } { | |
1176 | global gdb_prompt | |
1177 | ||
1178 | set matches [lsort $result_match_list] | |
1179 | set seen {} | |
1180 | gdb_test_multiple $cmd $name { | |
1181 | "$cmd\[\r\n\]" { exp_continue } | |
1182 | -re $elm_find_regexp { | |
1183 | set str $expect_out(0,string) | |
1184 | verbose -log "seen: $str" 3 | |
1185 | regexp -- $elm_extract_regexp $str elm_seen | |
1186 | verbose -log "extracted: $elm_seen" 3 | |
1187 | lappend seen $elm_seen | |
1188 | exp_continue | |
1189 | } | |
1190 | -re "$gdb_prompt $" { | |
1191 | set failed "" | |
1192 | foreach got [lsort $seen] have $matches { | |
1193 | if {![string equal $got $have]} { | |
1194 | set failed $have | |
1195 | break | |
1196 | } | |
1197 | } | |
1198 | if {[string length $failed] != 0} { | |
1199 | fail "$name ($failed not found)" | |
1200 | } else { | |
1201 | pass $name | |
1202 | } | |
1203 | } | |
1204 | } | |
1205 | } | |
c906108c SS |
1206 | \f |
1207 | proc gdb_reinitialize_dir { subdir } { | |
1208 | global gdb_prompt | |
1209 | ||
1210 | if [is_remote host] { | |
ae59b1da | 1211 | return "" |
c906108c SS |
1212 | } |
1213 | send_gdb "dir\n" | |
1214 | gdb_expect 60 { | |
1215 | -re "Reinitialize source path to empty.*y or n. " { | |
1216 | send_gdb "y\n" | |
1217 | gdb_expect 60 { | |
1218 | -re "Source directories searched.*$gdb_prompt $" { | |
1219 | send_gdb "dir $subdir\n" | |
1220 | gdb_expect 60 { | |
1221 | -re "Source directories searched.*$gdb_prompt $" { | |
1222 | verbose "Dir set to $subdir" | |
1223 | } | |
1224 | -re "$gdb_prompt $" { | |
1225 | perror "Dir \"$subdir\" failed." | |
1226 | } | |
1227 | } | |
1228 | } | |
1229 | -re "$gdb_prompt $" { | |
1230 | perror "Dir \"$subdir\" failed." | |
1231 | } | |
1232 | } | |
1233 | } | |
1234 | -re "$gdb_prompt $" { | |
1235 | perror "Dir \"$subdir\" failed." | |
1236 | } | |
1237 | } | |
1238 | } | |
1239 | ||
1240 | # | |
1241 | # gdb_exit -- exit the GDB, killing the target program if necessary | |
1242 | # | |
1243 | proc default_gdb_exit {} { | |
1244 | global GDB | |
6b8ce727 | 1245 | global INTERNAL_GDBFLAGS GDBFLAGS |
c906108c SS |
1246 | global verbose |
1247 | global gdb_spawn_id; | |
1248 | ||
1249 | gdb_stop_suppressing_tests; | |
1250 | ||
1251 | if ![info exists gdb_spawn_id] { | |
1252 | return; | |
1253 | } | |
1254 | ||
6b8ce727 | 1255 | verbose "Quitting $GDB $INTERNAL_GDBFLAGS $GDBFLAGS" |
c906108c SS |
1256 | |
1257 | if { [is_remote host] && [board_info host exists fileid] } { | |
1258 | send_gdb "quit\n"; | |
1259 | gdb_expect 10 { | |
1260 | -re "y or n" { | |
1261 | send_gdb "y\n"; | |
1262 | exp_continue; | |
1263 | } | |
1264 | -re "DOSEXIT code" { } | |
1265 | default { } | |
1266 | } | |
1267 | } | |
1268 | ||
1269 | if ![is_remote host] { | |
1270 | remote_close host; | |
1271 | } | |
1272 | unset gdb_spawn_id | |
1273 | } | |
1274 | ||
3e3ffd2b | 1275 | # Load a file into the debugger. |
2db8e78e | 1276 | # The return value is 0 for success, -1 for failure. |
c906108c | 1277 | # |
2db8e78e MC |
1278 | # This procedure also set the global variable GDB_FILE_CMD_DEBUG_INFO |
1279 | # to one of these values: | |
3e3ffd2b | 1280 | # |
2db8e78e MC |
1281 | # debug file was loaded successfully and has debug information |
1282 | # nodebug file was loaded successfully and has no debug information | |
608e2dbb TT |
1283 | # lzma file was loaded, .gnu_debugdata found, but no LZMA support |
1284 | # compiled in | |
2db8e78e | 1285 | # fail file was not loaded |
c906108c | 1286 | # |
2db8e78e MC |
1287 | # I tried returning this information as part of the return value, |
1288 | # but ran into a mess because of the many re-implementations of | |
1289 | # gdb_load in config/*.exp. | |
3e3ffd2b | 1290 | # |
2db8e78e MC |
1291 | # TODO: gdb.base/sepdebug.exp and gdb.stabs/weird.exp might be able to use |
1292 | # this if they can get more information set. | |
3e3ffd2b | 1293 | |
c906108c | 1294 | proc gdb_file_cmd { arg } { |
3e3ffd2b | 1295 | global gdb_prompt |
c906108c | 1296 | global verbose |
c906108c | 1297 | global GDB |
b741e217 DJ |
1298 | global last_loaded_file |
1299 | ||
975531db | 1300 | # Save this for the benefit of gdbserver-support.exp. |
b741e217 | 1301 | set last_loaded_file $arg |
c906108c | 1302 | |
2db8e78e MC |
1303 | # Set whether debug info was found. |
1304 | # Default to "fail". | |
1305 | global gdb_file_cmd_debug_info | |
1306 | set gdb_file_cmd_debug_info "fail" | |
1307 | ||
c906108c | 1308 | if [is_remote host] { |
3e3ffd2b | 1309 | set arg [remote_download host $arg] |
c906108c | 1310 | if { $arg == "" } { |
2db8e78e MC |
1311 | perror "download failed" |
1312 | return -1 | |
c906108c SS |
1313 | } |
1314 | } | |
1315 | ||
4c42eaff DJ |
1316 | # The file command used to kill the remote target. For the benefit |
1317 | # of the testsuite, preserve this behavior. | |
1318 | send_gdb "kill\n" | |
1319 | gdb_expect 120 { | |
1320 | -re "Kill the program being debugged. .y or n. $" { | |
1321 | send_gdb "y\n" | |
1322 | verbose "\t\tKilling previous program being debugged" | |
1323 | exp_continue | |
1324 | } | |
1325 | -re "$gdb_prompt $" { | |
1326 | # OK. | |
1327 | } | |
1328 | } | |
1329 | ||
c906108c SS |
1330 | send_gdb "file $arg\n" |
1331 | gdb_expect 120 { | |
608e2dbb TT |
1332 | -re "Reading symbols from.*LZMA support was disabled.*done.*$gdb_prompt $" { |
1333 | verbose "\t\tLoaded $arg into $GDB; .gnu_debugdata found but no LZMA available" | |
1334 | set gdb_file_cmd_debug_info "lzma" | |
1335 | return 0 | |
1336 | } | |
3e3ffd2b | 1337 | -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" { |
975531db | 1338 | verbose "\t\tLoaded $arg into $GDB with no debugging symbols" |
2db8e78e MC |
1339 | set gdb_file_cmd_debug_info "nodebug" |
1340 | return 0 | |
3e3ffd2b | 1341 | } |
c906108c | 1342 | -re "Reading symbols from.*done.*$gdb_prompt $" { |
975531db | 1343 | verbose "\t\tLoaded $arg into $GDB" |
2db8e78e MC |
1344 | set gdb_file_cmd_debug_info "debug" |
1345 | return 0 | |
c906108c | 1346 | } |
c906108c SS |
1347 | -re "Load new symbol table from \".*\".*y or n. $" { |
1348 | send_gdb "y\n" | |
1349 | gdb_expect 120 { | |
1350 | -re "Reading symbols from.*done.*$gdb_prompt $" { | |
1351 | verbose "\t\tLoaded $arg with new symbol table into $GDB" | |
2db8e78e MC |
1352 | set gdb_file_cmd_debug_info "debug" |
1353 | return 0 | |
c906108c SS |
1354 | } |
1355 | timeout { | |
975531db | 1356 | perror "Couldn't load $arg, other program already loaded (timeout)." |
2db8e78e | 1357 | return -1 |
c906108c | 1358 | } |
975531db DE |
1359 | eof { |
1360 | perror "Couldn't load $arg, other program already loaded (eof)." | |
1361 | return -1 | |
1362 | } | |
c906108c SS |
1363 | } |
1364 | } | |
1365 | -re "No such file or directory.*$gdb_prompt $" { | |
2db8e78e MC |
1366 | perror "($arg) No such file or directory" |
1367 | return -1 | |
c906108c | 1368 | } |
04e7407c | 1369 | -re "A problem internal to GDB has been detected" { |
5b7d0050 | 1370 | fail "($arg) (GDB internal error)" |
04e7407c JK |
1371 | gdb_internal_error_resync |
1372 | return -1 | |
1373 | } | |
c906108c | 1374 | -re "$gdb_prompt $" { |
975531db | 1375 | perror "Couldn't load $arg into $GDB." |
2db8e78e | 1376 | return -1 |
c906108c SS |
1377 | } |
1378 | timeout { | |
975531db | 1379 | perror "Couldn't load $arg into $GDB (timeout)." |
2db8e78e | 1380 | return -1 |
c906108c SS |
1381 | } |
1382 | eof { | |
1383 | # This is an attempt to detect a core dump, but seems not to | |
1384 | # work. Perhaps we need to match .* followed by eof, in which | |
1385 | # gdb_expect does not seem to have a way to do that. | |
975531db | 1386 | perror "Couldn't load $arg into $GDB (eof)." |
2db8e78e | 1387 | return -1 |
c906108c SS |
1388 | } |
1389 | } | |
1390 | } | |
1391 | ||
1392 | # | |
1393 | # start gdb -- start gdb running, default procedure | |
1394 | # | |
1395 | # When running over NFS, particularly if running many simultaneous | |
1396 | # tests on different hosts all using the same server, things can | |
1397 | # get really slow. Give gdb at least 3 minutes to start up. | |
1398 | # | |
1399 | proc default_gdb_start { } { | |
e11ac3a3 | 1400 | global verbose use_gdb_stub |
c906108c | 1401 | global GDB |
6b8ce727 | 1402 | global INTERNAL_GDBFLAGS GDBFLAGS |
c906108c SS |
1403 | global gdb_prompt |
1404 | global timeout | |
1405 | global gdb_spawn_id; | |
1406 | ||
1407 | gdb_stop_suppressing_tests; | |
1408 | ||
e11ac3a3 JK |
1409 | # Set the default value, it may be overriden later by specific testfile. |
1410 | # | |
1411 | # Use `set_board_info use_gdb_stub' for the board file to flag the inferior | |
1412 | # is already started after connecting and run/attach are not supported. | |
1413 | # This is used for the "remote" protocol. After GDB starts you should | |
1414 | # check global $use_gdb_stub instead of the board as the testfile may force | |
1415 | # a specific different target protocol itself. | |
1416 | set use_gdb_stub [target_info exists use_gdb_stub] | |
1417 | ||
6b8ce727 | 1418 | verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS" |
c906108c SS |
1419 | |
1420 | if [info exists gdb_spawn_id] { | |
ae59b1da | 1421 | return 0 |
c906108c SS |
1422 | } |
1423 | ||
1424 | if ![is_remote host] { | |
1425 | if { [which $GDB] == 0 } then { | |
1426 | perror "$GDB does not exist." | |
1427 | exit 1 | |
1428 | } | |
1429 | } | |
6b8ce727 | 1430 | set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"]; |
c906108c SS |
1431 | if { $res < 0 || $res == "" } { |
1432 | perror "Spawning $GDB failed." | |
ae59b1da | 1433 | return 1 |
c906108c SS |
1434 | } |
1435 | gdb_expect 360 { | |
1436 | -re "\[\r\n\]$gdb_prompt $" { | |
1437 | verbose "GDB initialized." | |
1438 | } | |
1439 | -re "$gdb_prompt $" { | |
1440 | perror "GDB never initialized." | |
1441 | return -1 | |
1442 | } | |
1443 | timeout { | |
1444 | perror "(timeout) GDB never initialized after 10 seconds." | |
1445 | remote_close host; | |
1446 | return -1 | |
1447 | } | |
1448 | } | |
1449 | set gdb_spawn_id -1; | |
1450 | # force the height to "unlimited", so no pagers get used | |
1451 | ||
1452 | send_gdb "set height 0\n" | |
1453 | gdb_expect 10 { | |
1454 | -re "$gdb_prompt $" { | |
1455 | verbose "Setting height to 0." 2 | |
1456 | } | |
1457 | timeout { | |
1458 | warning "Couldn't set the height to 0" | |
1459 | } | |
1460 | } | |
1461 | # force the width to "unlimited", so no wraparound occurs | |
1462 | send_gdb "set width 0\n" | |
1463 | gdb_expect 10 { | |
1464 | -re "$gdb_prompt $" { | |
1465 | verbose "Setting width to 0." 2 | |
1466 | } | |
1467 | timeout { | |
1468 | warning "Couldn't set the width to 0." | |
1469 | } | |
1470 | } | |
ae59b1da | 1471 | return 0 |
c906108c SS |
1472 | } |
1473 | ||
ec3c07fc NS |
1474 | # Examine the output of compilation to determine whether compilation |
1475 | # failed or not. If it failed determine whether it is due to missing | |
1476 | # compiler or due to compiler error. Report pass, fail or unsupported | |
1477 | # as appropriate | |
1478 | ||
1479 | proc gdb_compile_test {src output} { | |
1480 | if { $output == "" } { | |
1481 | pass "compilation [file tail $src]" | |
1482 | } elseif { [regexp {^[a-zA-Z_0-9]+: Can't find [^ ]+\.$} $output] } { | |
1483 | unsupported "compilation [file tail $src]" | |
1484 | } elseif { [regexp {.*: command not found[\r|\n]*$} $output] } { | |
1485 | unsupported "compilation [file tail $src]" | |
6bb85cd1 DE |
1486 | } elseif { [regexp {.*: [^\r\n]*compiler not installed[^\r\n]*[\r|\n]*$} $output] } { |
1487 | unsupported "compilation [file tail $src]" | |
ec3c07fc NS |
1488 | } else { |
1489 | verbose -log "compilation failed: $output" 2 | |
1490 | fail "compilation [file tail $src]" | |
1491 | } | |
1492 | } | |
1493 | ||
d4f3574e SS |
1494 | # Return a 1 for configurations for which we don't even want to try to |
1495 | # test C++. | |
1496 | ||
1497 | proc skip_cplus_tests {} { | |
d4f3574e SS |
1498 | if { [istarget "h8300-*-*"] } { |
1499 | return 1 | |
1500 | } | |
81d2cbae | 1501 | |
1146c7f1 SC |
1502 | # The C++ IO streams are too large for HC11/HC12 and are thus not |
1503 | # available. The gdb C++ tests use them and don't compile. | |
1504 | if { [istarget "m6811-*-*"] } { | |
1505 | return 1 | |
1506 | } | |
1507 | if { [istarget "m6812-*-*"] } { | |
1508 | return 1 | |
1509 | } | |
d4f3574e SS |
1510 | return 0 |
1511 | } | |
1512 | ||
759f0f0b PA |
1513 | # Return a 1 for configurations for which don't have both C++ and the STL. |
1514 | ||
1515 | proc skip_stl_tests {} { | |
1516 | # Symbian supports the C++ language, but the STL is missing | |
1517 | # (both headers and libraries). | |
1518 | if { [istarget "arm*-*-symbianelf*"] } { | |
1519 | return 1 | |
1520 | } | |
1521 | ||
1522 | return [skip_cplus_tests] | |
1523 | } | |
1524 | ||
89a237cb MC |
1525 | # Return a 1 if I don't even want to try to test FORTRAN. |
1526 | ||
1527 | proc skip_fortran_tests {} { | |
1528 | return 0 | |
1529 | } | |
1530 | ||
ec3c07fc NS |
1531 | # Return a 1 if I don't even want to try to test ada. |
1532 | ||
1533 | proc skip_ada_tests {} { | |
1534 | return 0 | |
1535 | } | |
1536 | ||
a766d390 DE |
1537 | # Return a 1 if I don't even want to try to test GO. |
1538 | ||
1539 | proc skip_go_tests {} { | |
1540 | return 0 | |
1541 | } | |
1542 | ||
ec3c07fc NS |
1543 | # Return a 1 if I don't even want to try to test java. |
1544 | ||
1545 | proc skip_java_tests {} { | |
1546 | return 0 | |
1547 | } | |
1548 | ||
f6bbabf0 PM |
1549 | # Return a 1 for configurations that do not support Python scripting. |
1550 | ||
1551 | proc skip_python_tests {} { | |
1552 | global gdb_prompt | |
9325cb04 PK |
1553 | global gdb_py_is_py3k |
1554 | global gdb_py_is_py24 | |
1555 | ||
1556 | gdb_test_multiple "python print ('test')" "verify python support" { | |
f6bbabf0 PM |
1557 | -re "not supported.*$gdb_prompt $" { |
1558 | unsupported "Python support is disabled." | |
1559 | return 1 | |
1560 | } | |
1561 | -re "$gdb_prompt $" {} | |
1562 | } | |
1563 | ||
9325cb04 PK |
1564 | set gdb_py_is_py24 0 |
1565 | gdb_test_multiple "python print (sys.version_info\[0\])" "check if python 3" { | |
1566 | -re "3.*$gdb_prompt $" { | |
1567 | set gdb_py_is_py3k 1 | |
1568 | } | |
1569 | -re ".*$gdb_prompt $" { | |
1570 | set gdb_py_is_py3k 0 | |
1571 | } | |
1572 | } | |
1573 | if { $gdb_py_is_py3k == 0 } { | |
1574 | gdb_test_multiple "python print (sys.version_info\[1\])" "check if python 2.4" { | |
1575 | -re "\[45\].*$gdb_prompt $" { | |
1576 | set gdb_py_is_py24 1 | |
1577 | } | |
1578 | -re ".*$gdb_prompt $" { | |
1579 | set gdb_py_is_py24 0 | |
1580 | } | |
1581 | } | |
1582 | } | |
1583 | ||
f6bbabf0 PM |
1584 | return 0 |
1585 | } | |
1586 | ||
93f02886 DJ |
1587 | # Return a 1 if we should skip shared library tests. |
1588 | ||
1589 | proc skip_shlib_tests {} { | |
1590 | # Run the shared library tests on native systems. | |
1591 | if {[isnative]} { | |
1592 | return 0 | |
1593 | } | |
1594 | ||
1595 | # An abbreviated list of remote targets where we should be able to | |
1596 | # run shared library tests. | |
1597 | if {([istarget *-*-linux*] | |
1598 | || [istarget *-*-*bsd*] | |
1599 | || [istarget *-*-solaris2*] | |
1600 | || [istarget arm*-*-symbianelf*] | |
1601 | || [istarget *-*-mingw*] | |
1602 | || [istarget *-*-cygwin*] | |
1603 | || [istarget *-*-pe*])} { | |
1604 | return 0 | |
1605 | } | |
1606 | ||
1607 | return 1 | |
1608 | } | |
1609 | ||
6a5870ce PA |
1610 | # Test files shall make sure all the test result lines in gdb.sum are |
1611 | # unique in a test run, so that comparing the gdb.sum files of two | |
1612 | # test runs gives correct results. Test files that exercise | |
1613 | # variations of the same tests more than once, shall prefix the | |
1614 | # different test invocations with different identifying strings in | |
1615 | # order to make them unique. | |
1616 | # | |
1617 | # About test prefixes: | |
1618 | # | |
1619 | # $pf_prefix is the string that dejagnu prints after the result (FAIL, | |
1620 | # PASS, etc.), and before the test message/name in gdb.sum. E.g., the | |
1621 | # underlined substring in | |
1622 | # | |
1623 | # PASS: gdb.base/mytest.exp: some test | |
1624 | # ^^^^^^^^^^^^^^^^^^^^ | |
1625 | # | |
1626 | # is $pf_prefix. | |
1627 | # | |
1628 | # The easiest way to adjust the test prefix is to append a test | |
1629 | # variation prefix to the $pf_prefix, using the with_test_prefix | |
1630 | # procedure. E.g., | |
1631 | # | |
1632 | # proc do_tests {} { | |
1633 | # gdb_test ... ... "test foo" | |
1634 | # gdb_test ... ... "test bar" | |
1635 | # | |
0f4d39d5 | 1636 | # with_test_prefix "subvariation a" { |
6a5870ce PA |
1637 | # gdb_test ... ... "test x" |
1638 | # } | |
1639 | # | |
0f4d39d5 | 1640 | # with_test_prefix "subvariation b" { |
6a5870ce PA |
1641 | # gdb_test ... ... "test x" |
1642 | # } | |
1643 | # } | |
1644 | # | |
0f4d39d5 | 1645 | # with_test_prefix "variation1" { |
6a5870ce PA |
1646 | # ...do setup for variation 1... |
1647 | # do_tests | |
1648 | # } | |
1649 | # | |
0f4d39d5 | 1650 | # with_test_prefix "variation2" { |
6a5870ce PA |
1651 | # ...do setup for variation 2... |
1652 | # do_tests | |
1653 | # } | |
1654 | # | |
1655 | # Results in: | |
1656 | # | |
1657 | # PASS: gdb.base/mytest.exp: variation1: test foo | |
1658 | # PASS: gdb.base/mytest.exp: variation1: test bar | |
1659 | # PASS: gdb.base/mytest.exp: variation1: subvariation a: test x | |
1660 | # PASS: gdb.base/mytest.exp: variation1: subvariation b: test x | |
1661 | # PASS: gdb.base/mytest.exp: variation2: test foo | |
1662 | # PASS: gdb.base/mytest.exp: variation2: test bar | |
1663 | # PASS: gdb.base/mytest.exp: variation2: subvariation a: test x | |
1664 | # PASS: gdb.base/mytest.exp: variation2: subvariation b: test x | |
1665 | # | |
1666 | # If for some reason more flexibility is necessary, one can also | |
1667 | # manipulate the pf_prefix global directly, treating it as a string. | |
1668 | # E.g., | |
1669 | # | |
1670 | # global pf_prefix | |
1671 | # set saved_pf_prefix | |
0f4d39d5 | 1672 | # append pf_prefix "${foo}: bar" |
6a5870ce PA |
1673 | # ... actual tests ... |
1674 | # set pf_prefix $saved_pf_prefix | |
1675 | # | |
1676 | ||
1677 | # Run BODY in the context of the caller, with the current test prefix | |
0f4d39d5 PA |
1678 | # (pf_prefix) appended with one space, then PREFIX, and then a colon. |
1679 | # Returns the result of BODY. | |
6a5870ce PA |
1680 | # |
1681 | proc with_test_prefix { prefix body } { | |
1682 | global pf_prefix | |
1683 | ||
1684 | set saved $pf_prefix | |
0f4d39d5 | 1685 | append pf_prefix " " $prefix ":" |
6a5870ce PA |
1686 | set code [catch {uplevel 1 $body} result] |
1687 | set pf_prefix $saved | |
1688 | ||
1689 | if {$code == 1} { | |
1690 | global errorInfo errorCode | |
1691 | return -code $code -errorinfo $errorInfo -errorcode $errorCode $result | |
1692 | } else { | |
1693 | return -code $code $result | |
1694 | } | |
1695 | } | |
1696 | ||
e43ec454 YQ |
1697 | # Return 1 if _Complex types are supported, otherwise, return 0. |
1698 | ||
1699 | proc support_complex_tests {} { | |
1700 | global support_complex_tests_saved | |
1701 | ||
1702 | # Use the cached value, if it exists. | |
1703 | if [info exists support_complex_tests_saved] { | |
1704 | verbose "returning saved $support_complex_tests_saved" 2 | |
1705 | return $support_complex_tests_saved | |
1706 | } | |
1707 | ||
1708 | # Set up, compile, and execute a test program containing _Complex types. | |
1709 | # Include the current process ID in the file names to prevent conflicts | |
1710 | # with invocations for multiple testsuites. | |
1711 | set src complex[pid].c | |
1712 | set exe complex[pid].x | |
1713 | ||
1714 | set f [open $src "w"] | |
1715 | puts $f "int main() {" | |
1716 | puts $f "_Complex float cf;" | |
1717 | puts $f "_Complex double cd;" | |
1718 | puts $f "_Complex long double cld;" | |
1719 | puts $f " return 0; }" | |
1720 | close $f | |
1721 | ||
1722 | verbose "compiling testfile $src" 2 | |
1723 | set compile_flags {debug nowarnings quiet} | |
1724 | set lines [gdb_compile $src $exe executable $compile_flags] | |
1725 | file delete $src | |
1726 | file delete $exe | |
1727 | ||
1728 | if ![string match "" $lines] then { | |
1729 | verbose "testfile compilation failed, returning 0" 2 | |
1730 | set support_complex_tests_saved 0 | |
1731 | } else { | |
1732 | set support_complex_tests_saved 1 | |
1733 | } | |
1734 | ||
1735 | return $support_complex_tests_saved | |
1736 | } | |
1737 | ||
ab254057 YQ |
1738 | # Return 1 if target hardware or OS supports single stepping to signal |
1739 | # handler, otherwise, return 0. | |
1740 | ||
1741 | proc can_single_step_to_signal_handler {} { | |
1742 | ||
1743 | # Targets don't have hardware single step. On these targets, when | |
1744 | # a signal is delivered during software single step, gdb is unable | |
1745 | # to determine the next instruction addresses, because start of signal | |
1746 | # handler is one of them. | |
b0221781 | 1747 | if { [istarget "arm*-*-*"] || [istarget "mips*-*-*"] |
73cd8ab1 | 1748 | || [istarget "tic6x-*-*"] || [istarget "sparc*-*-linux*"] } { |
ab254057 YQ |
1749 | return 0 |
1750 | } | |
1751 | ||
1752 | return 1 | |
1753 | } | |
1754 | ||
d3895d7d YQ |
1755 | # Return 1 if target supports process record, otherwise return 0. |
1756 | ||
1757 | proc supports_process_record {} { | |
1758 | ||
1759 | if [target_info exists gdb,use_precord] { | |
1760 | return [target_info gdb,use_precord] | |
1761 | } | |
1762 | ||
1763 | if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } { | |
1764 | return 1 | |
1765 | } | |
1766 | ||
1767 | return 0 | |
1768 | } | |
1769 | ||
1770 | # Return 1 if target supports reverse debugging, otherwise return 0. | |
1771 | ||
1772 | proc supports_reverse {} { | |
1773 | ||
1774 | if [target_info exists gdb,can_reverse] { | |
1775 | return [target_info gdb,can_reverse] | |
1776 | } | |
1777 | ||
1778 | if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } { | |
1779 | return 1 | |
1780 | } | |
1781 | ||
1782 | return 0 | |
1783 | } | |
1784 | ||
add265ae L |
1785 | # Return 1 if target is ILP32. |
1786 | # This cannot be decided simply from looking at the target string, | |
1787 | # as it might depend on externally passed compiler options like -m64. | |
1788 | proc is_ilp32_target {} { | |
1789 | global is_ilp32_target_saved | |
1790 | ||
1791 | # Use the cached value, if it exists. Cache value per "board" to handle | |
1792 | # runs with multiple options (e.g. unix/{-m32,-64}) correctly. | |
1793 | set me "is_ilp32_target" | |
1794 | set board [target_info name] | |
1795 | if [info exists is_ilp32_target_saved($board)] { | |
1796 | verbose "$me: returning saved $is_ilp32_target_saved($board)" 2 | |
1797 | return $is_ilp32_target_saved($board) | |
1798 | } | |
1799 | ||
1800 | ||
1801 | set src ilp32[pid].c | |
1802 | set obj ilp32[pid].o | |
1803 | ||
1804 | set f [open $src "w"] | |
1805 | puts $f "int dummy\[sizeof (int) == 4" | |
1806 | puts $f " && sizeof (void *) == 4" | |
1807 | puts $f " && sizeof (long) == 4 ? 1 : -1\];" | |
1808 | close $f | |
1809 | ||
1810 | verbose "$me: compiling testfile $src" 2 | |
1811 | set lines [gdb_compile $src $obj object {quiet}] | |
1812 | file delete $src | |
1813 | file delete $obj | |
1814 | ||
1815 | if ![string match "" $lines] then { | |
1816 | verbose "$me: testfile compilation failed, returning 0" 2 | |
1817 | return [set is_ilp32_target_saved($board) 0] | |
1818 | } | |
1819 | ||
1820 | verbose "$me: returning 1" 2 | |
1821 | return [set is_ilp32_target_saved($board) 1] | |
1822 | } | |
1823 | ||
1824 | # Return 1 if target is LP64. | |
1825 | # This cannot be decided simply from looking at the target string, | |
1826 | # as it might depend on externally passed compiler options like -m64. | |
1827 | proc is_lp64_target {} { | |
1828 | global is_lp64_target_saved | |
1829 | ||
1830 | # Use the cached value, if it exists. Cache value per "board" to handle | |
1831 | # runs with multiple options (e.g. unix/{-m32,-64}) correctly. | |
1832 | set me "is_lp64_target" | |
1833 | set board [target_info name] | |
1834 | if [info exists is_lp64_target_saved($board)] { | |
1835 | verbose "$me: returning saved $is_lp64_target_saved($board)" 2 | |
1836 | return $is_lp64_target_saved($board) | |
1837 | } | |
1838 | ||
1839 | set src lp64[pid].c | |
1840 | set obj lp64[pid].o | |
1841 | ||
1842 | set f [open $src "w"] | |
1843 | puts $f "int dummy\[sizeof (int) == 4" | |
1844 | puts $f " && sizeof (void *) == 8" | |
1845 | puts $f " && sizeof (long) == 8 ? 1 : -1\];" | |
1846 | close $f | |
1847 | ||
1848 | verbose "$me: compiling testfile $src" 2 | |
1849 | set lines [gdb_compile $src $obj object {quiet}] | |
1850 | file delete $src | |
1851 | file delete $obj | |
1852 | ||
1853 | if ![string match "" $lines] then { | |
1854 | verbose "$me: testfile compilation failed, returning 0" 2 | |
1855 | return [set is_lp64_target_saved($board) 0] | |
1856 | } | |
1857 | ||
1858 | verbose "$me: returning 1" 2 | |
1859 | return [set is_lp64_target_saved($board) 1] | |
1860 | } | |
1861 | ||
7f062217 JK |
1862 | # Return 1 if target has x86_64 registers - either amd64 or x32. |
1863 | # x32 target identifies as x86_64-*-linux*, therefore it cannot be determined | |
1864 | # just from the target string. | |
1865 | proc is_amd64_regs_target {} { | |
1866 | global is_amd64_regs_target_saved | |
1867 | ||
68fb0ec0 | 1868 | if {![istarget "x86_64-*-*"] && ![istarget "i?86-*"]} { |
7f062217 JK |
1869 | return 0 |
1870 | } | |
1871 | ||
1872 | # Use the cached value, if it exists. Cache value per "board" to handle | |
1873 | # runs with multiple options (e.g. unix/{-m32,-64}) correctly. | |
1874 | set me "is_amd64_regs_target" | |
1875 | set board [target_info name] | |
1876 | if [info exists is_amd64_regs_target_saved($board)] { | |
1877 | verbose "$me: returning saved $is_amd64_regs_target_saved($board)" 2 | |
1878 | return $is_amd64_regs_target_saved($board) | |
1879 | } | |
1880 | ||
1881 | set src reg64[pid].s | |
1882 | set obj reg64[pid].o | |
1883 | ||
1884 | set f [open $src "w"] | |
1885 | foreach reg \ | |
1886 | {rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} { | |
1887 | puts $f "\tincq %$reg" | |
1888 | } | |
1889 | close $f | |
1890 | ||
1891 | verbose "$me: compiling testfile $src" 2 | |
1892 | set lines [gdb_compile $src $obj object {quiet}] | |
1893 | file delete $src | |
1894 | file delete $obj | |
1895 | ||
1896 | if ![string match "" $lines] then { | |
1897 | verbose "$me: testfile compilation failed, returning 0" 2 | |
1898 | return [set is_amd64_regs_target_saved($board) 0] | |
1899 | } | |
1900 | ||
1901 | verbose "$me: returning 1" 2 | |
1902 | return [set is_amd64_regs_target_saved($board) 1] | |
1903 | } | |
1904 | ||
6edba76f TT |
1905 | # Return 1 if this target is an x86 or x86-64 with -m32. |
1906 | proc is_x86_like_target {} { | |
68fb0ec0 | 1907 | if {![istarget "x86_64-*-*"] && ![istarget i?86-*]} { |
6edba76f TT |
1908 | return 0 |
1909 | } | |
7f062217 | 1910 | return [expr [is_ilp32_target] && ![is_amd64_regs_target]] |
6edba76f TT |
1911 | } |
1912 | ||
be777e08 YQ |
1913 | # Return 1 if displaced stepping is supported on target, otherwise, return 0. |
1914 | proc support_displaced_stepping {} { | |
1915 | ||
1916 | if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] | |
1917 | || [istarget "arm*-*-linux*"] || [istarget "powerpc-*-linux*"] | |
1918 | || [istarget "powerpc64-*-linux*"] || [istarget "s390*-*-*"] } { | |
1919 | return 1 | |
1920 | } | |
1921 | ||
1922 | return 0 | |
1923 | } | |
1924 | ||
3c95e6af PG |
1925 | # Run a test on the target to see if it supports vmx hardware. Return 0 if so, |
1926 | # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite. | |
1927 | ||
1928 | proc skip_altivec_tests {} { | |
1929 | global skip_vmx_tests_saved | |
fda326dd | 1930 | global srcdir subdir gdb_prompt inferior_exited_re |
3c95e6af PG |
1931 | |
1932 | # Use the cached value, if it exists. | |
1933 | set me "skip_altivec_tests" | |
1934 | if [info exists skip_vmx_tests_saved] { | |
1935 | verbose "$me: returning saved $skip_vmx_tests_saved" 2 | |
1936 | return $skip_vmx_tests_saved | |
1937 | } | |
1938 | ||
1939 | # Some simulators are known to not support VMX instructions. | |
1940 | if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } { | |
1941 | verbose "$me: target known to not support VMX, returning 1" 2 | |
476308bf | 1942 | return [set skip_vmx_tests_saved 1] |
3c95e6af PG |
1943 | } |
1944 | ||
1945 | # Make sure we have a compiler that understands altivec. | |
fc91c6c2 | 1946 | set compile_flags {debug nowarnings} |
4c93b1db | 1947 | if [get_compiler_info] { |
3c95e6af PG |
1948 | warning "Could not get compiler info" |
1949 | return 1 | |
1950 | } | |
1951 | if [test_compiler_info gcc*] { | |
1952 | set compile_flags "$compile_flags additional_flags=-maltivec" | |
1953 | } elseif [test_compiler_info xlc*] { | |
1954 | set compile_flags "$compile_flags additional_flags=-qaltivec" | |
1955 | } else { | |
1956 | verbose "Could not compile with altivec support, returning 1" 2 | |
1957 | return 1 | |
1958 | } | |
1959 | ||
1960 | # Set up, compile, and execute a test program containing VMX instructions. | |
1961 | # Include the current process ID in the file names to prevent conflicts | |
1962 | # with invocations for multiple testsuites. | |
1963 | set src vmx[pid].c | |
1964 | set exe vmx[pid].x | |
1965 | ||
1966 | set f [open $src "w"] | |
1967 | puts $f "int main() {" | |
1968 | puts $f "#ifdef __MACH__" | |
1969 | puts $f " asm volatile (\"vor v0,v0,v0\");" | |
1970 | puts $f "#else" | |
1971 | puts $f " asm volatile (\"vor 0,0,0\");" | |
1972 | puts $f "#endif" | |
1973 | puts $f " return 0; }" | |
1974 | close $f | |
1975 | ||
1976 | verbose "$me: compiling testfile $src" 2 | |
1977 | set lines [gdb_compile $src $exe executable $compile_flags] | |
1978 | file delete $src | |
1979 | ||
1980 | if ![string match "" $lines] then { | |
1981 | verbose "$me: testfile compilation failed, returning 1" 2 | |
1982 | return [set skip_vmx_tests_saved 1] | |
1983 | } | |
1984 | ||
1985 | # No error message, compilation succeeded so now run it via gdb. | |
1986 | ||
1987 | gdb_exit | |
1988 | gdb_start | |
1989 | gdb_reinitialize_dir $srcdir/$subdir | |
1990 | gdb_load "$exe" | |
1991 | gdb_run_cmd | |
1992 | gdb_expect { | |
1993 | -re ".*Illegal instruction.*${gdb_prompt} $" { | |
1994 | verbose -log "\n$me altivec hardware not detected" | |
1995 | set skip_vmx_tests_saved 1 | |
1996 | } | |
fda326dd | 1997 | -re ".*$inferior_exited_re normally.*${gdb_prompt} $" { |
3c95e6af PG |
1998 | verbose -log "\n$me: altivec hardware detected" |
1999 | set skip_vmx_tests_saved 0 | |
2000 | } | |
2001 | default { | |
2002 | warning "\n$me: default case taken" | |
2003 | set skip_vmx_tests_saved 1 | |
2004 | } | |
2005 | } | |
2006 | gdb_exit | |
2007 | remote_file build delete $exe | |
2008 | ||
2009 | verbose "$me: returning $skip_vmx_tests_saved" 2 | |
2010 | return $skip_vmx_tests_saved | |
2011 | } | |
2012 | ||
604c2f83 LM |
2013 | # Run a test on the target to see if it supports vmx hardware. Return 0 if so, |
2014 | # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite. | |
2015 | ||
2016 | proc skip_vsx_tests {} { | |
2017 | global skip_vsx_tests_saved | |
fda326dd | 2018 | global srcdir subdir gdb_prompt inferior_exited_re |
604c2f83 LM |
2019 | |
2020 | # Use the cached value, if it exists. | |
2021 | set me "skip_vsx_tests" | |
2022 | if [info exists skip_vsx_tests_saved] { | |
2023 | verbose "$me: returning saved $skip_vsx_tests_saved" 2 | |
2024 | return $skip_vsx_tests_saved | |
2025 | } | |
2026 | ||
2027 | # Some simulators are known to not support Altivec instructions, so | |
2028 | # they won't support VSX instructions as well. | |
2029 | if { [istarget powerpc-*-eabi] || [istarget powerpc*-*-eabispe] } { | |
2030 | verbose "$me: target known to not support VSX, returning 1" 2 | |
2031 | return [set skip_vsx_tests_saved 1] | |
2032 | } | |
2033 | ||
2034 | # Make sure we have a compiler that understands altivec. | |
2035 | set compile_flags {debug nowarnings quiet} | |
4c93b1db | 2036 | if [get_compiler_info] { |
604c2f83 LM |
2037 | warning "Could not get compiler info" |
2038 | return 1 | |
2039 | } | |
2040 | if [test_compiler_info gcc*] { | |
2041 | set compile_flags "$compile_flags additional_flags=-mvsx" | |
2042 | } elseif [test_compiler_info xlc*] { | |
d9492458 | 2043 | set compile_flags "$compile_flags additional_flags=-qasm=gcc" |
604c2f83 LM |
2044 | } else { |
2045 | verbose "Could not compile with vsx support, returning 1" 2 | |
2046 | return 1 | |
2047 | } | |
2048 | ||
2049 | set src vsx[pid].c | |
2050 | set exe vsx[pid].x | |
2051 | ||
2052 | set f [open $src "w"] | |
2053 | puts $f "int main() {" | |
d9492458 | 2054 | puts $f " double a\[2\] = { 1.0, 2.0 };" |
604c2f83 | 2055 | puts $f "#ifdef __MACH__" |
d9492458 | 2056 | puts $f " asm volatile (\"lxvd2x v0,v0,%\[addr\]\" : : \[addr\] \"r\" (a));" |
604c2f83 | 2057 | puts $f "#else" |
d9492458 | 2058 | puts $f " asm volatile (\"lxvd2x 0,0,%\[addr\]\" : : \[addr\] \"r\" (a));" |
604c2f83 LM |
2059 | puts $f "#endif" |
2060 | puts $f " return 0; }" | |
2061 | close $f | |
2062 | ||
2063 | verbose "$me: compiling testfile $src" 2 | |
2064 | set lines [gdb_compile $src $exe executable $compile_flags] | |
2065 | file delete $src | |
2066 | ||
2067 | if ![string match "" $lines] then { | |
2068 | verbose "$me: testfile compilation failed, returning 1" 2 | |
2069 | return [set skip_vsx_tests_saved 1] | |
2070 | } | |
2071 | ||
2072 | # No error message, compilation succeeded so now run it via gdb. | |
2073 | ||
2074 | gdb_exit | |
2075 | gdb_start | |
2076 | gdb_reinitialize_dir $srcdir/$subdir | |
2077 | gdb_load "$exe" | |
2078 | gdb_run_cmd | |
2079 | gdb_expect { | |
2080 | -re ".*Illegal instruction.*${gdb_prompt} $" { | |
2081 | verbose -log "\n$me VSX hardware not detected" | |
2082 | set skip_vsx_tests_saved 1 | |
2083 | } | |
fda326dd | 2084 | -re ".*$inferior_exited_re normally.*${gdb_prompt} $" { |
604c2f83 LM |
2085 | verbose -log "\n$me: VSX hardware detected" |
2086 | set skip_vsx_tests_saved 0 | |
2087 | } | |
2088 | default { | |
2089 | warning "\n$me: default case taken" | |
2090 | set skip_vsx_tests_saved 1 | |
2091 | } | |
2092 | } | |
2093 | gdb_exit | |
2094 | remote_file build delete $exe | |
2095 | ||
2096 | verbose "$me: returning $skip_vsx_tests_saved" 2 | |
2097 | return $skip_vsx_tests_saved | |
2098 | } | |
2099 | ||
2f1d9bdd MM |
2100 | # Run a test on the target to see if it supports btrace hardware. Return 0 if so, |
2101 | # 1 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite. | |
2102 | ||
2103 | proc skip_btrace_tests {} { | |
2104 | global skip_btrace_tests_saved | |
2105 | global srcdir subdir gdb_prompt inferior_exited_re | |
2106 | ||
2107 | # Use the cached value, if it exists. | |
2108 | set me "skip_btrace_tests" | |
2109 | if [info exists skip_btrace_tests_saved] { | |
2110 | verbose "$me: returning saved $skip_btrace_tests_saved" 2 | |
2111 | return $skip_btrace_tests_saved | |
2112 | } | |
2113 | ||
2114 | if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } { | |
2115 | verbose "$me: target does not support btrace, returning 1" 2 | |
2116 | return [set skip_btrace_tests_saved 1] | |
2117 | } | |
2118 | ||
2119 | # Set up, compile, and execute a test program. | |
2120 | # Include the current process ID in the file names to prevent conflicts | |
2121 | # with invocations for multiple testsuites. | |
2122 | set src [standard_output_file btrace[pid].c] | |
2123 | set exe [standard_output_file btrace[pid].x] | |
2124 | ||
2125 | set f [open $src "w"] | |
2126 | puts $f "int main(void) { return 0; }" | |
2127 | close $f | |
2128 | ||
2129 | verbose "$me: compiling testfile $src" 2 | |
2130 | set compile_flags {debug nowarnings quiet} | |
2131 | set lines [gdb_compile $src $exe executable $compile_flags] | |
2f1d9bdd MM |
2132 | |
2133 | if ![string match "" $lines] then { | |
2134 | verbose "$me: testfile compilation failed, returning 1" 2 | |
4043f22b | 2135 | file delete $src |
2f1d9bdd MM |
2136 | return [set skip_btrace_tests_saved 1] |
2137 | } | |
2138 | ||
2139 | # No error message, compilation succeeded so now run it via gdb. | |
2140 | ||
2141 | clean_restart btrace[pid].x | |
2142 | if ![runto_main] { | |
4043f22b | 2143 | file delete $src |
2f1d9bdd MM |
2144 | return [set skip_btrace_tests_saved 1] |
2145 | } | |
4043f22b | 2146 | file delete $src |
2f1d9bdd MM |
2147 | # In case of an unexpected output, we return 2 as a fail value. |
2148 | set skip_btrace_tests_saved 2 | |
2149 | gdb_test_multiple "record btrace" "check btrace support" { | |
2150 | -re "You can't do that when your target is.*\r\n$gdb_prompt $" { | |
2151 | set skip_btrace_tests_saved 1 | |
2152 | } | |
2153 | -re "Target does not support branch tracing.*\r\n$gdb_prompt $" { | |
2154 | set skip_btrace_tests_saved 1 | |
2155 | } | |
2156 | -re "Could not enable branch tracing.*\r\n$gdb_prompt $" { | |
2157 | set skip_btrace_tests_saved 1 | |
2158 | } | |
2159 | -re "^record btrace\r\n$gdb_prompt $" { | |
2160 | set skip_btrace_tests_saved 0 | |
2161 | } | |
2162 | } | |
2163 | gdb_exit | |
2164 | remote_file build delete $exe | |
2165 | ||
2166 | verbose "$me: returning $skip_btrace_tests_saved" 2 | |
2167 | return $skip_btrace_tests_saved | |
2168 | } | |
2169 | ||
7a292a7a SS |
2170 | # Skip all the tests in the file if you are not on an hppa running |
2171 | # hpux target. | |
2172 | ||
2173 | proc skip_hp_tests {} { | |
2174 | eval set skip_hp [ expr ![isnative] || ![istarget "hppa*-*-hpux*"] ] | |
c906108c SS |
2175 | verbose "Skip hp tests is $skip_hp" |
2176 | return $skip_hp | |
2177 | } | |
2178 | ||
edb3359d DJ |
2179 | # Return whether we should skip tests for showing inlined functions in |
2180 | # backtraces. Requires get_compiler_info and get_debug_format. | |
2181 | ||
2182 | proc skip_inline_frame_tests {} { | |
2183 | # GDB only recognizes inlining information in DWARF 2 (DWARF 3). | |
2184 | if { ! [test_debug_format "DWARF 2"] } { | |
2185 | return 1 | |
2186 | } | |
2187 | ||
2188 | # GCC before 4.1 does not emit DW_AT_call_file / DW_AT_call_line. | |
2189 | if { ([test_compiler_info "gcc-2-*"] | |
2190 | || [test_compiler_info "gcc-3-*"] | |
2191 | || [test_compiler_info "gcc-4-0-*"]) } { | |
2192 | return 1 | |
2193 | } | |
2194 | ||
2195 | return 0 | |
2196 | } | |
2197 | ||
2198 | # Return whether we should skip tests for showing variables from | |
2199 | # inlined functions. Requires get_compiler_info and get_debug_format. | |
2200 | ||
2201 | proc skip_inline_var_tests {} { | |
2202 | # GDB only recognizes inlining information in DWARF 2 (DWARF 3). | |
2203 | if { ! [test_debug_format "DWARF 2"] } { | |
2204 | return 1 | |
2205 | } | |
2206 | ||
2207 | return 0 | |
2208 | } | |
2209 | ||
b800ec70 UW |
2210 | # Return a 1 if we should skip tests that require hardware breakpoints |
2211 | ||
2212 | proc skip_hw_breakpoint_tests {} { | |
2213 | # Skip tests if requested by the board (note that no_hardware_watchpoints | |
2214 | # disables both watchpoints and breakpoints) | |
2215 | if { [target_info exists gdb,no_hardware_watchpoints]} { | |
2216 | return 1 | |
2217 | } | |
2218 | ||
2219 | # These targets support hardware breakpoints natively | |
2220 | if { [istarget "i?86-*-*"] | |
2221 | || [istarget "x86_64-*-*"] | |
e3039479 UW |
2222 | || [istarget "ia64-*-*"] |
2223 | || [istarget "arm*-*-*"]} { | |
b800ec70 UW |
2224 | return 0 |
2225 | } | |
2226 | ||
2227 | return 1 | |
2228 | } | |
2229 | ||
2230 | # Return a 1 if we should skip tests that require hardware watchpoints | |
2231 | ||
2232 | proc skip_hw_watchpoint_tests {} { | |
2233 | # Skip tests if requested by the board | |
2234 | if { [target_info exists gdb,no_hardware_watchpoints]} { | |
2235 | return 1 | |
2236 | } | |
2237 | ||
2238 | # These targets support hardware watchpoints natively | |
2239 | if { [istarget "i?86-*-*"] | |
2240 | || [istarget "x86_64-*-*"] | |
2241 | || [istarget "ia64-*-*"] | |
e3039479 | 2242 | || [istarget "arm*-*-*"] |
b800ec70 UW |
2243 | || [istarget "powerpc*-*-linux*"] |
2244 | || [istarget "s390*-*-*"] } { | |
2245 | return 0 | |
2246 | } | |
2247 | ||
2248 | return 1 | |
2249 | } | |
2250 | ||
2251 | # Return a 1 if we should skip tests that require *multiple* hardware | |
2252 | # watchpoints to be active at the same time | |
2253 | ||
2254 | proc skip_hw_watchpoint_multi_tests {} { | |
2255 | if { [skip_hw_watchpoint_tests] } { | |
2256 | return 1 | |
2257 | } | |
2258 | ||
2259 | # These targets support just a single hardware watchpoint | |
e3039479 UW |
2260 | if { [istarget "arm*-*-*"] |
2261 | || [istarget "powerpc*-*-linux*"] } { | |
b800ec70 UW |
2262 | return 1 |
2263 | } | |
2264 | ||
2265 | return 0 | |
2266 | } | |
2267 | ||
2268 | # Return a 1 if we should skip tests that require read/access watchpoints | |
2269 | ||
2270 | proc skip_hw_watchpoint_access_tests {} { | |
2271 | if { [skip_hw_watchpoint_tests] } { | |
2272 | return 1 | |
2273 | } | |
2274 | ||
2275 | # These targets support just write watchpoints | |
2276 | if { [istarget "s390*-*-*"] } { | |
2277 | return 1 | |
2278 | } | |
2279 | ||
2280 | return 0 | |
2281 | } | |
2282 | ||
b4893d48 TT |
2283 | # Return 1 if we should skip tests that require the runtime unwinder |
2284 | # hook. This must be invoked while gdb is running, after shared | |
2285 | # libraries have been loaded. This is needed because otherwise a | |
2286 | # shared libgcc won't be visible. | |
2287 | ||
2288 | proc skip_unwinder_tests {} { | |
2289 | global gdb_prompt | |
2290 | ||
4442ada7 | 2291 | set ok 0 |
b4893d48 TT |
2292 | gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" { |
2293 | -re "= .*no debug info.*_Unwind_DebugHook.*\r\n$gdb_prompt $" { | |
b4893d48 TT |
2294 | } |
2295 | -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" { | |
4442ada7 | 2296 | set ok 1 |
b4893d48 TT |
2297 | } |
2298 | -re "No symbol .* in current context.\r\n$gdb_prompt $" { | |
b4893d48 TT |
2299 | } |
2300 | } | |
2301 | if {!$ok} { | |
2302 | gdb_test_multiple "info probe" "check for stap probe in unwinder" { | |
2303 | -re ".*libgcc.*unwind.*\r\n$gdb_prompt $" { | |
b4893d48 TT |
2304 | set ok 1 |
2305 | } | |
2306 | -re "\r\n$gdb_prompt $" { | |
2307 | } | |
2308 | } | |
2309 | } | |
2310 | return $ok | |
2311 | } | |
2312 | ||
72f1fe8a TT |
2313 | # Return 0 if we should skip tests that require the libstdc++ stap |
2314 | # probes. This must be invoked while gdb is running, after shared | |
2315 | # libraries have been loaded. | |
2316 | ||
2317 | proc skip_libstdcxx_probe_tests {} { | |
2318 | global gdb_prompt | |
2319 | ||
2320 | set ok 0 | |
2321 | gdb_test_multiple "info probe" "check for stap probe in libstdc++" { | |
2322 | -re ".*libstdcxx.*catch.*\r\n$gdb_prompt $" { | |
2323 | set ok 1 | |
2324 | } | |
2325 | -re "\r\n$gdb_prompt $" { | |
2326 | } | |
2327 | } | |
2328 | return $ok | |
2329 | } | |
2330 | ||
94b8e876 MC |
2331 | set compiler_info "unknown" |
2332 | set gcc_compiled 0 | |
2333 | set hp_cc_compiler 0 | |
2334 | set hp_aCC_compiler 0 | |
94b8e876 MC |
2335 | |
2336 | # Figure out what compiler I am using. | |
2337 | # | |
4c93b1db | 2338 | # ARG can be empty or "C++". If empty, "C" is assumed. |
94b8e876 MC |
2339 | # |
2340 | # There are several ways to do this, with various problems. | |
2341 | # | |
2342 | # [ gdb_compile -E $ifile -o $binfile.ci ] | |
2343 | # source $binfile.ci | |
2344 | # | |
2345 | # Single Unix Spec v3 says that "-E -o ..." together are not | |
2346 | # specified. And in fact, the native compiler on hp-ux 11 (among | |
2347 | # others) does not work with "-E -o ...". Most targets used to do | |
2348 | # this, and it mostly worked, because it works with gcc. | |
2349 | # | |
2350 | # [ catch "exec $compiler -E $ifile > $binfile.ci" exec_output ] | |
2351 | # source $binfile.ci | |
2352 | # | |
2353 | # This avoids the problem with -E and -o together. This almost works | |
2354 | # if the build machine is the same as the host machine, which is | |
2355 | # usually true of the targets which are not gcc. But this code does | |
2356 | # not figure which compiler to call, and it always ends up using the C | |
2357 | # compiler. Not good for setting hp_aCC_compiler. Targets | |
2358 | # hppa*-*-hpux* and mips*-*-irix* used to do this. | |
2359 | # | |
2360 | # [ gdb_compile -E $ifile > $binfile.ci ] | |
2361 | # source $binfile.ci | |
2362 | # | |
2363 | # dejagnu target_compile says that it supports output redirection, | |
2364 | # but the code is completely different from the normal path and I | |
2365 | # don't want to sweep the mines from that path. So I didn't even try | |
2366 | # this. | |
2367 | # | |
2368 | # set cppout [ gdb_compile $ifile "" preprocess $args quiet ] | |
2369 | # eval $cppout | |
2370 | # | |
2371 | # I actually do this for all targets now. gdb_compile runs the right | |
2372 | # compiler, and TCL captures the output, and I eval the output. | |
2373 | # | |
2374 | # Unfortunately, expect logs the output of the command as it goes by, | |
2375 | # and dejagnu helpfully prints a second copy of it right afterwards. | |
2376 | # So I turn off expect logging for a moment. | |
2377 | # | |
2378 | # [ gdb_compile $ifile $ciexe_file executable $args ] | |
2379 | # [ remote_exec $ciexe_file ] | |
2380 | # [ source $ci_file.out ] | |
2381 | # | |
2382 | # I could give up on -E and just do this. | |
2383 | # I didn't get desperate enough to try this. | |
2384 | # | |
2385 | # -- chastain 2004-01-06 | |
853d6e5b | 2386 | |
4c93b1db | 2387 | proc get_compiler_info {{arg ""}} { |
94b8e876 | 2388 | # For compiler.c and compiler.cc |
c906108c | 2389 | global srcdir |
94b8e876 MC |
2390 | |
2391 | # I am going to play with the log to keep noise out. | |
2392 | global outdir | |
2393 | global tool | |
2394 | ||
2395 | # These come from compiler.c or compiler.cc | |
853d6e5b | 2396 | global compiler_info |
4f70a4c9 MC |
2397 | |
2398 | # Legacy global data symbols. | |
94b8e876 MC |
2399 | global gcc_compiled |
2400 | global hp_cc_compiler | |
2401 | global hp_aCC_compiler | |
c906108c | 2402 | |
94b8e876 MC |
2403 | # Choose which file to preprocess. |
2404 | set ifile "${srcdir}/lib/compiler.c" | |
4c93b1db | 2405 | if { $arg == "c++" } { |
94b8e876 | 2406 | set ifile "${srcdir}/lib/compiler.cc" |
c906108c | 2407 | } |
085dd6e6 | 2408 | |
94b8e876 MC |
2409 | # Run $ifile through the right preprocessor. |
2410 | # Toggle gdb.log to keep the compiler output out of the log. | |
2411 | log_file | |
e7f86de9 JM |
2412 | if [is_remote host] { |
2413 | # We have to use -E and -o together, despite the comments | |
2414 | # above, because of how DejaGnu handles remote host testing. | |
2415 | set ppout "$outdir/compiler.i" | |
4c93b1db | 2416 | gdb_compile "${ifile}" "$ppout" preprocess [list "$arg" quiet] |
e7f86de9 JM |
2417 | set file [open $ppout r] |
2418 | set cppout [read $file] | |
2419 | close $file | |
2420 | } else { | |
4c93b1db | 2421 | set cppout [ gdb_compile "${ifile}" "" preprocess [list "$arg" quiet] ] |
e7f86de9 | 2422 | } |
94b8e876 MC |
2423 | log_file -a "$outdir/$tool.log" |
2424 | ||
4f70a4c9 MC |
2425 | # Eval the output. |
2426 | set unknown 0 | |
94b8e876 | 2427 | foreach cppline [ split "$cppout" "\n" ] { |
4f70a4c9 MC |
2428 | if { [ regexp "^#" "$cppline" ] } { |
2429 | # line marker | |
2430 | } elseif { [ regexp "^\[\n\r\t \]*$" "$cppline" ] } { | |
2431 | # blank line | |
2432 | } elseif { [ regexp "^\[\n\r\t \]*set\[\n\r\t \]" "$cppline" ] } { | |
2433 | # eval this line | |
2434 | verbose "get_compiler_info: $cppline" 2 | |
2435 | eval "$cppline" | |
2436 | } else { | |
2437 | # unknown line | |
2438 | verbose -log "get_compiler_info: $cppline" | |
2439 | set unknown 1 | |
94b8e876 | 2440 | } |
085dd6e6 | 2441 | } |
4f70a4c9 MC |
2442 | |
2443 | # Reset to unknown compiler if any diagnostics happened. | |
2444 | if { $unknown } { | |
2445 | set compiler_info "unknown" | |
4f70a4c9 MC |
2446 | } |
2447 | ||
2448 | # Set the legacy symbols. | |
2449 | set gcc_compiled 0 | |
2450 | set hp_cc_compiler 0 | |
2451 | set hp_aCC_compiler 0 | |
2452 | if { [regexp "^gcc-1-" "$compiler_info" ] } { set gcc_compiled 1 } | |
2453 | if { [regexp "^gcc-2-" "$compiler_info" ] } { set gcc_compiled 2 } | |
2454 | if { [regexp "^gcc-3-" "$compiler_info" ] } { set gcc_compiled 3 } | |
2455 | if { [regexp "^gcc-4-" "$compiler_info" ] } { set gcc_compiled 4 } | |
2456 | if { [regexp "^gcc-5-" "$compiler_info" ] } { set gcc_compiled 5 } | |
2457 | if { [regexp "^hpcc-" "$compiler_info" ] } { set hp_cc_compiler 1 } | |
2458 | if { [regexp "^hpacc-" "$compiler_info" ] } { set hp_aCC_compiler 1 } | |
2459 | ||
2460 | # Log what happened. | |
94b8e876 | 2461 | verbose -log "get_compiler_info: $compiler_info" |
085dd6e6 JM |
2462 | |
2463 | # Most compilers will evaluate comparisons and other boolean | |
2464 | # operations to 0 or 1. | |
2465 | uplevel \#0 { set true 1 } | |
2466 | uplevel \#0 { set false 0 } | |
2467 | ||
94b8e876 MC |
2468 | # Use of aCC results in boolean results being displayed as |
2469 | # "true" or "false" | |
2470 | if { $hp_aCC_compiler } { | |
2471 | uplevel \#0 { set true true } | |
2472 | uplevel \#0 { set false false } | |
085dd6e6 JM |
2473 | } |
2474 | ||
ae59b1da | 2475 | return 0 |
c906108c SS |
2476 | } |
2477 | ||
9b593790 | 2478 | proc test_compiler_info { {compiler ""} } { |
853d6e5b | 2479 | global compiler_info |
6e87504d PG |
2480 | |
2481 | # if no arg, return the compiler_info string | |
2482 | ||
2483 | if [string match "" $compiler] { | |
2484 | if [info exists compiler_info] { | |
2485 | return $compiler_info | |
2486 | } else { | |
2487 | perror "No compiler info found." | |
2488 | } | |
2489 | } | |
2490 | ||
853d6e5b AC |
2491 | return [string match $compiler $compiler_info] |
2492 | } | |
2493 | ||
f6838f81 DJ |
2494 | proc current_target_name { } { |
2495 | global target_info | |
2496 | if [info exists target_info(target,name)] { | |
2497 | set answer $target_info(target,name) | |
2498 | } else { | |
2499 | set answer "" | |
2500 | } | |
2501 | return $answer | |
2502 | } | |
2503 | ||
f1c47eb2 | 2504 | set gdb_wrapper_initialized 0 |
f6838f81 | 2505 | set gdb_wrapper_target "" |
f1c47eb2 MS |
2506 | |
2507 | proc gdb_wrapper_init { args } { | |
2508 | global gdb_wrapper_initialized; | |
2509 | global gdb_wrapper_file; | |
2510 | global gdb_wrapper_flags; | |
f6838f81 | 2511 | global gdb_wrapper_target |
f1c47eb2 MS |
2512 | |
2513 | if { $gdb_wrapper_initialized == 1 } { return; } | |
2514 | ||
2515 | if {[target_info exists needs_status_wrapper] && \ | |
277254ba | 2516 | [target_info needs_status_wrapper] != "0"} { |
f1c47eb2 MS |
2517 | set result [build_wrapper "testglue.o"]; |
2518 | if { $result != "" } { | |
2519 | set gdb_wrapper_file [lindex $result 0]; | |
2520 | set gdb_wrapper_flags [lindex $result 1]; | |
2521 | } else { | |
2522 | warning "Status wrapper failed to build." | |
2523 | } | |
2524 | } | |
2525 | set gdb_wrapper_initialized 1 | |
f6838f81 | 2526 | set gdb_wrapper_target [current_target_name] |
f1c47eb2 MS |
2527 | } |
2528 | ||
f747e0ce PA |
2529 | # Some targets need to always link a special object in. Save its path here. |
2530 | global gdb_saved_set_unbuffered_mode_obj | |
2531 | set gdb_saved_set_unbuffered_mode_obj "" | |
2532 | ||
c906108c SS |
2533 | proc gdb_compile {source dest type options} { |
2534 | global GDB_TESTCASE_OPTIONS; | |
f1c47eb2 MS |
2535 | global gdb_wrapper_file; |
2536 | global gdb_wrapper_flags; | |
2537 | global gdb_wrapper_initialized; | |
f747e0ce PA |
2538 | global srcdir |
2539 | global objdir | |
2540 | global gdb_saved_set_unbuffered_mode_obj | |
c906108c | 2541 | |
695e2681 MK |
2542 | set outdir [file dirname $dest] |
2543 | ||
2544 | # Add platform-specific options if a shared library was specified using | |
2545 | # "shlib=librarypath" in OPTIONS. | |
2546 | set new_options "" | |
2547 | set shlib_found 0 | |
bdf7534a | 2548 | set shlib_load 0 |
695e2681 | 2549 | foreach opt $options { |
57bf0e56 DJ |
2550 | if [regexp {^shlib=(.*)} $opt dummy_var shlib_name] { |
2551 | if [test_compiler_info "xlc-*"] { | |
93f02886 DJ |
2552 | # IBM xlc compiler doesn't accept shared library named other |
2553 | # than .so: use "-Wl," to bypass this | |
2554 | lappend source "-Wl,$shlib_name" | |
2555 | } elseif { ([istarget "*-*-mingw*"] | |
2556 | || [istarget *-*-cygwin*] | |
2557 | || [istarget *-*-pe*])} { | |
2558 | lappend source "${shlib_name}.a" | |
57bf0e56 DJ |
2559 | } else { |
2560 | lappend source $shlib_name | |
2561 | } | |
0413d738 | 2562 | if { $shlib_found == 0 } { |
57bf0e56 | 2563 | set shlib_found 1 |
0413d738 PA |
2564 | if { ([istarget "*-*-mingw*"] |
2565 | || [istarget *-*-cygwin*]) } { | |
bb61102d | 2566 | lappend new_options "additional_flags=-Wl,--enable-auto-import" |
0413d738 | 2567 | } |
57bf0e56 | 2568 | } |
b0f4b84b | 2569 | } elseif { $opt == "shlib_load" } { |
bdf7534a | 2570 | set shlib_load 1 |
57bf0e56 DJ |
2571 | } else { |
2572 | lappend new_options $opt | |
2573 | } | |
695e2681 | 2574 | } |
bdf7534a NF |
2575 | |
2576 | # We typically link to shared libraries using an absolute path, and | |
2577 | # that's how they are found at runtime. If we are going to | |
2578 | # dynamically load one by basename, we must specify rpath. If we | |
2579 | # are using a remote host, DejaGNU will link to the shared library | |
2580 | # using a relative path, so again we must specify an rpath. | |
31f83dc5 | 2581 | if { $shlib_load || ($shlib_found && [is_remote target]) } { |
bdf7534a NF |
2582 | if { ([istarget "*-*-mingw*"] |
2583 | || [istarget *-*-cygwin*] | |
2584 | || [istarget *-*-pe*] | |
bdf7534a NF |
2585 | || [istarget hppa*-*-hpux*])} { |
2586 | # Do not need anything. | |
b2a6bdeb | 2587 | } elseif { [istarget *-*-freebsd*] || [istarget *-*-openbsd*] } { |
d8b34041 | 2588 | lappend new_options "ldflags=-Wl,-rpath,${outdir}" |
759f0f0b PA |
2589 | } elseif { [istarget arm*-*-symbianelf*] } { |
2590 | if { $shlib_load } { | |
2591 | lappend new_options "libs=-ldl" | |
2592 | } | |
bdf7534a NF |
2593 | } else { |
2594 | if { $shlib_load } { | |
2595 | lappend new_options "libs=-ldl" | |
2596 | } | |
d8b34041 | 2597 | lappend new_options "ldflags=-Wl,-rpath,\\\$ORIGIN" |
bdf7534a NF |
2598 | } |
2599 | } | |
695e2681 | 2600 | set options $new_options |
57bf0e56 | 2601 | |
c906108c SS |
2602 | if [target_info exists is_vxworks] { |
2603 | set options2 { "additional_flags=-Dvxworks" } | |
c906108c SS |
2604 | set options [concat $options2 $options] |
2605 | } | |
2606 | if [info exists GDB_TESTCASE_OPTIONS] { | |
2607 | lappend options "additional_flags=$GDB_TESTCASE_OPTIONS"; | |
2608 | } | |
2609 | verbose "options are $options" | |
2610 | verbose "source is $source $dest $type $options" | |
2611 | ||
f1c47eb2 MS |
2612 | if { $gdb_wrapper_initialized == 0 } { gdb_wrapper_init } |
2613 | ||
2614 | if {[target_info exists needs_status_wrapper] && \ | |
2615 | [target_info needs_status_wrapper] != "0" && \ | |
2616 | [info exists gdb_wrapper_file]} { | |
2617 | lappend options "libs=${gdb_wrapper_file}" | |
2618 | lappend options "ldflags=${gdb_wrapper_flags}" | |
2619 | } | |
2620 | ||
fc91c6c2 PB |
2621 | # Replace the "nowarnings" option with the appropriate additional_flags |
2622 | # to disable compiler warnings. | |
2623 | set nowarnings [lsearch -exact $options nowarnings] | |
2624 | if {$nowarnings != -1} { | |
2625 | if [target_info exists gdb,nowarnings_flag] { | |
2626 | set flag "additional_flags=[target_info gdb,nowarnings_flag]" | |
2627 | } else { | |
2628 | set flag "additional_flags=-w" | |
2629 | } | |
2630 | set options [lreplace $options $nowarnings $nowarnings $flag] | |
2631 | } | |
2632 | ||
f747e0ce PA |
2633 | if { $type == "executable" } { |
2634 | if { ([istarget "*-*-mingw*"] | |
56643c5e | 2635 | || [istarget "*-*-*djgpp"] |
f747e0ce PA |
2636 | || [istarget "*-*-cygwin*"])} { |
2637 | # Force output to unbuffered mode, by linking in an object file | |
2638 | # with a global contructor that calls setvbuf. | |
2639 | # | |
2640 | # Compile the special object seperatelly for two reasons: | |
2641 | # 1) Insulate it from $options. | |
2642 | # 2) Avoid compiling it for every gdb_compile invocation, | |
2643 | # which is time consuming, especially if we're remote | |
2644 | # host testing. | |
2645 | # | |
2646 | if { $gdb_saved_set_unbuffered_mode_obj == "" } { | |
2647 | verbose "compiling gdb_saved_set_unbuffered_obj" | |
2648 | set unbuf_src ${srcdir}/lib/set_unbuffered_mode.c | |
2649 | set unbuf_obj ${objdir}/set_unbuffered_mode.o | |
2650 | ||
2651 | set result [gdb_compile "${unbuf_src}" "${unbuf_obj}" object {nowarnings}] | |
2652 | if { $result != "" } { | |
2653 | return $result | |
2654 | } | |
2655 | ||
2656 | set gdb_saved_set_unbuffered_mode_obj ${objdir}/set_unbuffered_mode_saved.o | |
2657 | # Link a copy of the output object, because the | |
2658 | # original may be automatically deleted. | |
2659 | remote_exec host "cp -f $unbuf_obj $gdb_saved_set_unbuffered_mode_obj" | |
2660 | } else { | |
2661 | verbose "gdb_saved_set_unbuffered_obj already compiled" | |
2662 | } | |
2663 | ||
2664 | # Rely on the internal knowledge that the global ctors are ran in | |
2665 | # reverse link order. In that case, we can use ldflags to | |
2666 | # avoid copying the object file to the host multiple | |
2667 | # times. | |
ace5c364 PM |
2668 | # This object can only be added if standard libraries are |
2669 | # used. Thus, we need to disable it if -nostdlib option is used | |
2670 | if {[lsearch -regexp $options "-nostdlib"] < 0 } { | |
2671 | lappend options "ldflags=$gdb_saved_set_unbuffered_mode_obj" | |
2672 | } | |
f747e0ce PA |
2673 | } |
2674 | } | |
2675 | ||
c906108c | 2676 | set result [target_compile $source $dest $type $options]; |
93f02886 DJ |
2677 | |
2678 | # Prune uninteresting compiler (and linker) output. | |
2679 | regsub "Creating library file: \[^\r\n\]*\[\r\n\]+" $result "" result | |
2680 | ||
c906108c SS |
2681 | regsub "\[\r\n\]*$" "$result" "" result; |
2682 | regsub "^\[\r\n\]*" "$result" "" result; | |
ec3c07fc NS |
2683 | |
2684 | if {[lsearch $options quiet] < 0} { | |
2685 | # We shall update this on a per language basis, to avoid | |
2686 | # changing the entire testsuite in one go. | |
2687 | if {[lsearch $options f77] >= 0} { | |
2688 | gdb_compile_test $source $result | |
2689 | } elseif { $result != "" } { | |
2690 | clone_output "gdb compile failed, $result" | |
2691 | } | |
c906108c | 2692 | } |
ae59b1da | 2693 | return $result |
c906108c SS |
2694 | } |
2695 | ||
b6ff0e81 JB |
2696 | |
2697 | # This is just like gdb_compile, above, except that it tries compiling | |
2698 | # against several different thread libraries, to see which one this | |
2699 | # system has. | |
2700 | proc gdb_compile_pthreads {source dest type options} { | |
0ae67eb3 | 2701 | set built_binfile 0 |
b6ff0e81 | 2702 | set why_msg "unrecognized error" |
24486cb7 | 2703 | foreach lib {-lpthreads -lpthread -lthread ""} { |
b6ff0e81 JB |
2704 | # This kind of wipes out whatever libs the caller may have |
2705 | # set. Or maybe theirs will override ours. How infelicitous. | |
b5ab8ff3 | 2706 | set options_with_lib [concat $options [list libs=$lib quiet]] |
b6ff0e81 JB |
2707 | set ccout [gdb_compile $source $dest $type $options_with_lib] |
2708 | switch -regexp -- $ccout { | |
2709 | ".*no posix threads support.*" { | |
2710 | set why_msg "missing threads include file" | |
2711 | break | |
2712 | } | |
2713 | ".*cannot open -lpthread.*" { | |
2714 | set why_msg "missing runtime threads library" | |
2715 | } | |
2716 | ".*Can't find library for -lpthread.*" { | |
2717 | set why_msg "missing runtime threads library" | |
2718 | } | |
2719 | {^$} { | |
2720 | pass "successfully compiled posix threads test case" | |
2721 | set built_binfile 1 | |
2722 | break | |
2723 | } | |
2724 | } | |
2725 | } | |
0ae67eb3 | 2726 | if {!$built_binfile} { |
b6ff0e81 JB |
2727 | unsupported "Couldn't compile $source: ${why_msg}" |
2728 | return -1 | |
2729 | } | |
57bf0e56 DJ |
2730 | } |
2731 | ||
2732 | # Build a shared library from SOURCES. You must use get_compiler_info | |
2733 | # first. | |
2734 | ||
2735 | proc gdb_compile_shlib {sources dest options} { | |
2736 | set obj_options $options | |
2737 | ||
2738 | switch -glob [test_compiler_info] { | |
2739 | "xlc-*" { | |
2740 | lappend obj_options "additional_flags=-qpic" | |
2741 | } | |
2742 | "gcc-*" { | |
2743 | if { !([istarget "powerpc*-*-aix*"] | |
227c54da DJ |
2744 | || [istarget "rs6000*-*-aix*"] |
2745 | || [istarget "*-*-cygwin*"] | |
2746 | || [istarget "*-*-mingw*"] | |
2747 | || [istarget "*-*-pe*"]) } { | |
57bf0e56 DJ |
2748 | lappend obj_options "additional_flags=-fpic" |
2749 | } | |
2750 | } | |
2751 | default { | |
2752 | switch -glob [istarget] { | |
2753 | "hppa*-hp-hpux*" { | |
2754 | lappend obj_options "additional_flags=+z" | |
2755 | } | |
2756 | "mips-sgi-irix*" { | |
2757 | # Disable SGI compiler's implicit -Dsgi | |
2758 | lappend obj_options "additional_flags=-Usgi" | |
2759 | } | |
2760 | default { | |
2761 | # don't know what the compiler is... | |
2762 | } | |
2763 | } | |
2764 | } | |
2765 | } | |
2766 | ||
2767 | set outdir [file dirname $dest] | |
2768 | set objects "" | |
2769 | foreach source $sources { | |
2770 | set sourcebase [file tail $source] | |
2771 | if {[gdb_compile $source "${outdir}/${sourcebase}.o" object $obj_options] != ""} { | |
2772 | return -1 | |
2773 | } | |
2774 | lappend objects ${outdir}/${sourcebase}.o | |
2775 | } | |
2776 | ||
2777 | if [istarget "hppa*-*-hpux*"] { | |
2778 | remote_exec build "ld -b ${objects} -o ${dest}" | |
2779 | } else { | |
2780 | set link_options $options | |
2781 | if [test_compiler_info "xlc-*"] { | |
2782 | lappend link_options "additional_flags=-qmkshrobj" | |
2783 | } else { | |
2784 | lappend link_options "additional_flags=-shared" | |
93f02886 DJ |
2785 | |
2786 | if { ([istarget "*-*-mingw*"] | |
2787 | || [istarget *-*-cygwin*] | |
2788 | || [istarget *-*-pe*])} { | |
2789 | lappend link_options "additional_flags=-Wl,--out-implib,${dest}.a" | |
31f83dc5 UW |
2790 | } elseif [is_remote target] { |
2791 | # By default, we do not set the soname. This causes the linker | |
2792 | # on ELF systems to create a DT_NEEDED entry in the executable | |
2793 | # refering to the full path name of the library. This is a | |
2794 | # problem in remote testing if the library is in a different | |
2795 | # directory there. To fix this, we set a soname of just the | |
2796 | # base filename for the library, and add an appropriate -rpath | |
2797 | # to the main executable (in gdb_compile). | |
2798 | set destbase [file tail $dest] | |
2799 | lappend link_options "additional_flags=-Wl,-soname,$destbase" | |
2800 | } | |
57bf0e56 DJ |
2801 | } |
2802 | if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} { | |
2803 | return -1 | |
2804 | } | |
2805 | } | |
b6ff0e81 JB |
2806 | } |
2807 | ||
756d88a7 UW |
2808 | # This is just like gdb_compile_shlib, above, except that it tries compiling |
2809 | # against several different thread libraries, to see which one this | |
2810 | # system has. | |
2811 | proc gdb_compile_shlib_pthreads {sources dest options} { | |
2812 | set built_binfile 0 | |
2813 | set why_msg "unrecognized error" | |
2814 | foreach lib {-lpthreads -lpthread -lthread ""} { | |
2815 | # This kind of wipes out whatever libs the caller may have | |
2816 | # set. Or maybe theirs will override ours. How infelicitous. | |
2817 | set options_with_lib [concat $options [list libs=$lib quiet]] | |
2818 | set ccout [gdb_compile_shlib $sources $dest $options_with_lib] | |
2819 | switch -regexp -- $ccout { | |
2820 | ".*no posix threads support.*" { | |
2821 | set why_msg "missing threads include file" | |
2822 | break | |
2823 | } | |
2824 | ".*cannot open -lpthread.*" { | |
2825 | set why_msg "missing runtime threads library" | |
2826 | } | |
2827 | ".*Can't find library for -lpthread.*" { | |
2828 | set why_msg "missing runtime threads library" | |
2829 | } | |
2830 | {^$} { | |
2831 | pass "successfully compiled posix threads test case" | |
2832 | set built_binfile 1 | |
2833 | break | |
2834 | } | |
2835 | } | |
2836 | } | |
2837 | if {!$built_binfile} { | |
2838 | unsupported "Couldn't compile $sources: ${why_msg}" | |
2839 | return -1 | |
2840 | } | |
2841 | } | |
2842 | ||
130cacce AF |
2843 | # This is just like gdb_compile_pthreads, above, except that we always add the |
2844 | # objc library for compiling Objective-C programs | |
2845 | proc gdb_compile_objc {source dest type options} { | |
2846 | set built_binfile 0 | |
2847 | set why_msg "unrecognized error" | |
2848 | foreach lib {-lobjc -lpthreads -lpthread -lthread solaris} { | |
2849 | # This kind of wipes out whatever libs the caller may have | |
2850 | # set. Or maybe theirs will override ours. How infelicitous. | |
2851 | if { $lib == "solaris" } { | |
2852 | set lib "-lpthread -lposix4" | |
2853 | } | |
2854 | if { $lib != "-lobjc" } { | |
2855 | set lib "-lobjc $lib" | |
2856 | } | |
2857 | set options_with_lib [concat $options [list libs=$lib quiet]] | |
2858 | set ccout [gdb_compile $source $dest $type $options_with_lib] | |
2859 | switch -regexp -- $ccout { | |
2860 | ".*no posix threads support.*" { | |
2861 | set why_msg "missing threads include file" | |
2862 | break | |
2863 | } | |
2864 | ".*cannot open -lpthread.*" { | |
2865 | set why_msg "missing runtime threads library" | |
2866 | } | |
2867 | ".*Can't find library for -lpthread.*" { | |
2868 | set why_msg "missing runtime threads library" | |
2869 | } | |
2870 | {^$} { | |
2871 | pass "successfully compiled objc with posix threads test case" | |
2872 | set built_binfile 1 | |
2873 | break | |
2874 | } | |
2875 | } | |
2876 | } | |
2877 | if {!$built_binfile} { | |
2878 | unsupported "Couldn't compile $source: ${why_msg}" | |
2879 | return -1 | |
2880 | } | |
2881 | } | |
2882 | ||
c906108c SS |
2883 | proc send_gdb { string } { |
2884 | global suppress_flag; | |
2885 | if { $suppress_flag } { | |
ae59b1da | 2886 | return "suppressed" |
c906108c | 2887 | } |
ae59b1da | 2888 | return [remote_send host "$string"] |
c906108c SS |
2889 | } |
2890 | ||
2891 | # | |
2892 | # | |
2893 | ||
2894 | proc gdb_expect { args } { | |
2895 | if { [llength $args] == 2 && [lindex $args 0] != "-re" } { | |
2f34202f | 2896 | set atimeout [lindex $args 0]; |
c906108c SS |
2897 | set expcode [list [lindex $args 1]]; |
2898 | } else { | |
c906108c | 2899 | set expcode $args; |
2f34202f MR |
2900 | } |
2901 | ||
2902 | upvar timeout timeout; | |
2903 | ||
2904 | if [target_info exists gdb,timeout] { | |
2905 | if [info exists timeout] { | |
2906 | if { $timeout < [target_info gdb,timeout] } { | |
c906108c | 2907 | set gtimeout [target_info gdb,timeout]; |
2f34202f MR |
2908 | } else { |
2909 | set gtimeout $timeout; | |
c906108c | 2910 | } |
2f34202f MR |
2911 | } else { |
2912 | set gtimeout [target_info gdb,timeout]; | |
c906108c | 2913 | } |
2f34202f | 2914 | } |
c906108c | 2915 | |
2f34202f MR |
2916 | if ![info exists gtimeout] { |
2917 | global timeout; | |
2918 | if [info exists timeout] { | |
2919 | set gtimeout $timeout; | |
2920 | } | |
2921 | } | |
2922 | ||
2923 | if [info exists atimeout] { | |
2924 | if { ![info exists gtimeout] || $gtimeout < $atimeout } { | |
db16b772 | 2925 | set gtimeout $atimeout; |
2f34202f MR |
2926 | } |
2927 | } else { | |
c906108c | 2928 | if ![info exists gtimeout] { |
2f34202f MR |
2929 | # Eeeeew. |
2930 | set gtimeout 60; | |
c906108c SS |
2931 | } |
2932 | } | |
2f34202f | 2933 | |
c906108c SS |
2934 | global suppress_flag; |
2935 | global remote_suppress_flag; | |
2936 | if [info exists remote_suppress_flag] { | |
2937 | set old_val $remote_suppress_flag; | |
2938 | } | |
2939 | if [info exists suppress_flag] { | |
2940 | if { $suppress_flag } { | |
2941 | set remote_suppress_flag 1; | |
2942 | } | |
2943 | } | |
a0b3c4fd | 2944 | set code [catch \ |
5f279fa6 | 2945 | {uplevel remote_expect host $gtimeout $expcode} string]; |
c906108c SS |
2946 | if [info exists old_val] { |
2947 | set remote_suppress_flag $old_val; | |
2948 | } else { | |
2949 | if [info exists remote_suppress_flag] { | |
2950 | unset remote_suppress_flag; | |
2951 | } | |
2952 | } | |
2953 | ||
2954 | if {$code == 1} { | |
2955 | global errorInfo errorCode; | |
2956 | ||
2957 | return -code error -errorinfo $errorInfo -errorcode $errorCode $string | |
d6d7a51a | 2958 | } else { |
c906108c SS |
2959 | return -code $code $string |
2960 | } | |
2961 | } | |
2962 | ||
5fa290c1 | 2963 | # gdb_expect_list TEST SENTINEL LIST -- expect a sequence of outputs |
085dd6e6 JM |
2964 | # |
2965 | # Check for long sequence of output by parts. | |
5fa290c1 | 2966 | # TEST: is the test message to be printed with the test success/fail. |
085dd6e6 JM |
2967 | # SENTINEL: Is the terminal pattern indicating that output has finished. |
2968 | # LIST: is the sequence of outputs to match. | |
2969 | # If the sentinel is recognized early, it is considered an error. | |
2970 | # | |
11cf8741 JM |
2971 | # Returns: |
2972 | # 1 if the test failed, | |
2973 | # 0 if the test passes, | |
2974 | # -1 if there was an internal error. | |
5fa290c1 | 2975 | |
c2d11a7d | 2976 | proc gdb_expect_list {test sentinel list} { |
085dd6e6 | 2977 | global gdb_prompt |
11cf8741 | 2978 | global suppress_flag |
085dd6e6 | 2979 | set index 0 |
43ff13b4 | 2980 | set ok 1 |
11cf8741 JM |
2981 | if { $suppress_flag } { |
2982 | set ok 0 | |
a20ce2c3 | 2983 | unresolved "${test}" |
11cf8741 | 2984 | } |
43ff13b4 | 2985 | while { ${index} < [llength ${list}] } { |
085dd6e6 JM |
2986 | set pattern [lindex ${list} ${index}] |
2987 | set index [expr ${index} + 1] | |
6b0ecdc2 | 2988 | verbose -log "gdb_expect_list pattern: /$pattern/" 2 |
085dd6e6 | 2989 | if { ${index} == [llength ${list}] } { |
43ff13b4 JM |
2990 | if { ${ok} } { |
2991 | gdb_expect { | |
c2d11a7d | 2992 | -re "${pattern}${sentinel}" { |
a20ce2c3 | 2993 | # pass "${test}, pattern ${index} + sentinel" |
c2d11a7d JM |
2994 | } |
2995 | -re "${sentinel}" { | |
a20ce2c3 | 2996 | fail "${test} (pattern ${index} + sentinel)" |
c2d11a7d | 2997 | set ok 0 |
43ff13b4 | 2998 | } |
5c5455dc AC |
2999 | -re ".*A problem internal to GDB has been detected" { |
3000 | fail "${test} (GDB internal error)" | |
3001 | set ok 0 | |
3002 | gdb_internal_error_resync | |
3003 | } | |
43ff13b4 | 3004 | timeout { |
a20ce2c3 | 3005 | fail "${test} (pattern ${index} + sentinel) (timeout)" |
43ff13b4 JM |
3006 | set ok 0 |
3007 | } | |
085dd6e6 | 3008 | } |
43ff13b4 | 3009 | } else { |
a20ce2c3 | 3010 | # unresolved "${test}, pattern ${index} + sentinel" |
085dd6e6 JM |
3011 | } |
3012 | } else { | |
43ff13b4 JM |
3013 | if { ${ok} } { |
3014 | gdb_expect { | |
3015 | -re "${pattern}" { | |
a20ce2c3 | 3016 | # pass "${test}, pattern ${index}" |
43ff13b4 | 3017 | } |
c2d11a7d | 3018 | -re "${sentinel}" { |
a20ce2c3 | 3019 | fail "${test} (pattern ${index})" |
43ff13b4 JM |
3020 | set ok 0 |
3021 | } | |
5c5455dc AC |
3022 | -re ".*A problem internal to GDB has been detected" { |
3023 | fail "${test} (GDB internal error)" | |
3024 | set ok 0 | |
3025 | gdb_internal_error_resync | |
3026 | } | |
43ff13b4 | 3027 | timeout { |
a20ce2c3 | 3028 | fail "${test} (pattern ${index}) (timeout)" |
43ff13b4 JM |
3029 | set ok 0 |
3030 | } | |
085dd6e6 | 3031 | } |
43ff13b4 | 3032 | } else { |
a20ce2c3 | 3033 | # unresolved "${test}, pattern ${index}" |
085dd6e6 JM |
3034 | } |
3035 | } | |
3036 | } | |
11cf8741 | 3037 | if { ${ok} } { |
a20ce2c3 | 3038 | pass "${test}" |
11cf8741 JM |
3039 | return 0 |
3040 | } else { | |
3041 | return 1 | |
3042 | } | |
085dd6e6 JM |
3043 | } |
3044 | ||
3045 | # | |
3046 | # | |
c906108c SS |
3047 | proc gdb_suppress_entire_file { reason } { |
3048 | global suppress_flag; | |
3049 | ||
3050 | warning "$reason\n"; | |
3051 | set suppress_flag -1; | |
3052 | } | |
3053 | ||
3054 | # | |
3055 | # Set suppress_flag, which will cause all subsequent calls to send_gdb and | |
3056 | # gdb_expect to fail immediately (until the next call to | |
3057 | # gdb_stop_suppressing_tests). | |
3058 | # | |
3059 | proc gdb_suppress_tests { args } { | |
3060 | global suppress_flag; | |
3061 | ||
3062 | return; # fnf - disable pending review of results where | |
3063 | # testsuite ran better without this | |
3064 | incr suppress_flag; | |
3065 | ||
3066 | if { $suppress_flag == 1 } { | |
3067 | if { [llength $args] > 0 } { | |
3068 | warning "[lindex $args 0]\n"; | |
3069 | } else { | |
3070 | warning "Because of previous failure, all subsequent tests in this group will automatically fail.\n"; | |
3071 | } | |
3072 | } | |
3073 | } | |
3074 | ||
3075 | # | |
3076 | # Clear suppress_flag. | |
3077 | # | |
3078 | proc gdb_stop_suppressing_tests { } { | |
3079 | global suppress_flag; | |
3080 | ||
3081 | if [info exists suppress_flag] { | |
3082 | if { $suppress_flag > 0 } { | |
3083 | set suppress_flag 0; | |
3084 | clone_output "Tests restarted.\n"; | |
3085 | } | |
3086 | } else { | |
3087 | set suppress_flag 0; | |
3088 | } | |
3089 | } | |
3090 | ||
3091 | proc gdb_clear_suppressed { } { | |
3092 | global suppress_flag; | |
3093 | ||
3094 | set suppress_flag 0; | |
3095 | } | |
3096 | ||
3097 | proc gdb_start { } { | |
3098 | default_gdb_start | |
3099 | } | |
3100 | ||
3101 | proc gdb_exit { } { | |
3102 | catch default_gdb_exit | |
3103 | } | |
3104 | ||
e63b55d1 NS |
3105 | # |
3106 | # gdb_load_cmd -- load a file into the debugger. | |
3107 | # ARGS - additional args to load command. | |
3108 | # return a -1 if anything goes wrong. | |
3109 | # | |
3110 | proc gdb_load_cmd { args } { | |
3111 | global gdb_prompt | |
3112 | ||
3113 | if [target_info exists gdb_load_timeout] { | |
3114 | set loadtimeout [target_info gdb_load_timeout] | |
3115 | } else { | |
3116 | set loadtimeout 1600 | |
3117 | } | |
3118 | send_gdb "load $args\n" | |
e91528f0 | 3119 | verbose "Timeout is now $loadtimeout seconds" 2 |
e63b55d1 NS |
3120 | gdb_expect $loadtimeout { |
3121 | -re "Loading section\[^\r\]*\r\n" { | |
3122 | exp_continue | |
3123 | } | |
3124 | -re "Start address\[\r\]*\r\n" { | |
3125 | exp_continue | |
3126 | } | |
3127 | -re "Transfer rate\[\r\]*\r\n" { | |
3128 | exp_continue | |
3129 | } | |
3130 | -re "Memory access error\[^\r\]*\r\n" { | |
3131 | perror "Failed to load program" | |
3132 | return -1 | |
3133 | } | |
3134 | -re "$gdb_prompt $" { | |
3135 | return 0 | |
3136 | } | |
3137 | -re "(.*)\r\n$gdb_prompt " { | |
3138 | perror "Unexpected reponse from 'load' -- $expect_out(1,string)" | |
3139 | return -1 | |
3140 | } | |
3141 | timeout { | |
c4b347c7 | 3142 | perror "Timed out trying to load $args." |
e63b55d1 NS |
3143 | return -1 |
3144 | } | |
3145 | } | |
3146 | return -1 | |
3147 | } | |
3148 | ||
2d338fa9 TT |
3149 | # Invoke "gcore". CORE is the name of the core file to write. TEST |
3150 | # is the name of the test case. This will return 1 if the core file | |
3151 | # was created, 0 otherwise. If this fails to make a core file because | |
3152 | # this configuration of gdb does not support making core files, it | |
3153 | # will call "unsupported", not "fail". However, if this fails to make | |
3154 | # a core file for some other reason, then it will call "fail". | |
3155 | ||
3156 | proc gdb_gcore_cmd {core test} { | |
3157 | global gdb_prompt | |
3158 | ||
3159 | set result 0 | |
3160 | gdb_test_multiple "gcore $core" $test { | |
3161 | -re "Saved corefile .*\[\r\n\]+$gdb_prompt $" { | |
3162 | pass $test | |
3163 | set result 1 | |
3164 | } | |
3165 | ||
3166 | -re "Undefined command.*$gdb_prompt $" { | |
3167 | unsupported $test | |
3168 | verbose -log "'gcore' command undefined in gdb_gcore_cmd" | |
3169 | } | |
3170 | ||
3171 | -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" { | |
3172 | unsupported $test | |
3173 | } | |
3174 | } | |
3175 | ||
3176 | return $result | |
3177 | } | |
3178 | ||
759f0f0b PA |
3179 | # Return the filename to download to the target and load on the target |
3180 | # for this shared library. Normally just LIBNAME, unless shared libraries | |
3181 | # for this target have separate link and load images. | |
3182 | ||
3183 | proc shlib_target_file { libname } { | |
3184 | return $libname | |
3185 | } | |
3186 | ||
3187 | # Return the filename GDB will load symbols from when debugging this | |
3188 | # shared library. Normally just LIBNAME, unless shared libraries for | |
3189 | # this target have separate link and load images. | |
3190 | ||
3191 | proc shlib_symbol_file { libname } { | |
3192 | return $libname | |
3193 | } | |
3194 | ||
56744f0a JJ |
3195 | # Return the filename to download to the target and load for this |
3196 | # executable. Normally just BINFILE unless it is renamed to something | |
3197 | # else for this target. | |
3198 | ||
3199 | proc exec_target_file { binfile } { | |
3200 | return $binfile | |
3201 | } | |
3202 | ||
3203 | # Return the filename GDB will load symbols from when debugging this | |
3204 | # executable. Normally just BINFILE unless executables for this target | |
3205 | # have separate files for symbols. | |
3206 | ||
3207 | proc exec_symbol_file { binfile } { | |
3208 | return $binfile | |
3209 | } | |
3210 | ||
3211 | # Rename the executable file. Normally this is just BINFILE1 being renamed | |
3212 | # to BINFILE2, but some targets require multiple binary files. | |
3213 | proc gdb_rename_execfile { binfile1 binfile2 } { | |
faf067f1 JK |
3214 | file rename -force [exec_target_file ${binfile1}] \ |
3215 | [exec_target_file ${binfile2}] | |
56744f0a | 3216 | if { [exec_target_file ${binfile1}] != [exec_symbol_file ${binfile1}] } { |
faf067f1 JK |
3217 | file rename -force [exec_symbol_file ${binfile1}] \ |
3218 | [exec_symbol_file ${binfile2}] | |
56744f0a JJ |
3219 | } |
3220 | } | |
3221 | ||
3222 | # "Touch" the executable file to update the date. Normally this is just | |
3223 | # BINFILE, but some targets require multiple files. | |
3224 | proc gdb_touch_execfile { binfile } { | |
faf067f1 JK |
3225 | set time [clock seconds] |
3226 | file mtime [exec_target_file ${binfile}] $time | |
56744f0a | 3227 | if { [exec_target_file ${binfile}] != [exec_symbol_file ${binfile}] } { |
faf067f1 | 3228 | file mtime [exec_symbol_file ${binfile}] $time |
56744f0a JJ |
3229 | } |
3230 | } | |
3231 | ||
93f02886 DJ |
3232 | # gdb_download |
3233 | # | |
3234 | # Copy a file to the remote target and return its target filename. | |
3235 | # Schedule the file to be deleted at the end of this test. | |
3236 | ||
3237 | proc gdb_download { filename } { | |
3238 | global cleanfiles | |
3239 | ||
3240 | set destname [remote_download target $filename] | |
3241 | lappend cleanfiles $destname | |
3242 | return $destname | |
3243 | } | |
3244 | ||
3245 | # gdb_load_shlibs LIB... | |
3246 | # | |
3247 | # Copy the listed libraries to the target. | |
3248 | ||
3249 | proc gdb_load_shlibs { args } { | |
3250 | if {![is_remote target]} { | |
3251 | return | |
3252 | } | |
3253 | ||
3254 | foreach file $args { | |
759f0f0b | 3255 | gdb_download [shlib_target_file $file] |
93f02886 DJ |
3256 | } |
3257 | ||
3258 | # Even if the target supplies full paths for shared libraries, | |
3259 | # they may not be paths for this system. | |
3260 | gdb_test "set solib-search-path [file dirname [lindex $args 0]]" "" "" | |
3261 | } | |
3262 | ||
c906108c SS |
3263 | # |
3264 | # gdb_load -- load a file into the debugger. | |
2db8e78e | 3265 | # Many files in config/*.exp override this procedure. |
c906108c SS |
3266 | # |
3267 | proc gdb_load { arg } { | |
3268 | return [gdb_file_cmd $arg] | |
3269 | } | |
3270 | ||
b741e217 DJ |
3271 | # gdb_reload -- load a file into the target. Called before "running", |
3272 | # either the first time or after already starting the program once, | |
3273 | # for remote targets. Most files that override gdb_load should now | |
3274 | # override this instead. | |
3275 | ||
3276 | proc gdb_reload { } { | |
3277 | # For the benefit of existing configurations, default to gdb_load. | |
3278 | # Specifying no file defaults to the executable currently being | |
3279 | # debugged. | |
3280 | return [gdb_load ""] | |
3281 | } | |
3282 | ||
c906108c SS |
3283 | proc gdb_continue { function } { |
3284 | global decimal | |
3285 | ||
ae59b1da | 3286 | return [gdb_test "continue" ".*Breakpoint $decimal, $function .*" "continue to $function"] |
c906108c SS |
3287 | } |
3288 | ||
3289 | proc default_gdb_init { args } { | |
277254ba | 3290 | global gdb_wrapper_initialized |
f6838f81 | 3291 | global gdb_wrapper_target |
0a6d0306 | 3292 | global gdb_test_file_name |
93f02886 | 3293 | global cleanfiles |
277254ba | 3294 | |
93f02886 DJ |
3295 | set cleanfiles {} |
3296 | ||
c906108c SS |
3297 | gdb_clear_suppressed; |
3298 | ||
0a6d0306 TT |
3299 | set gdb_test_file_name [file rootname [file tail [lindex $args 0]]] |
3300 | ||
277254ba MS |
3301 | # Make sure that the wrapper is rebuilt |
3302 | # with the appropriate multilib option. | |
f6838f81 DJ |
3303 | if { $gdb_wrapper_target != [current_target_name] } { |
3304 | set gdb_wrapper_initialized 0 | |
3305 | } | |
277254ba | 3306 | |
7b433602 JB |
3307 | # Unlike most tests, we have a small number of tests that generate |
3308 | # a very large amount of output. We therefore increase the expect | |
3309 | # buffer size to be able to contain the entire test output. | |
3310 | match_max -d 30000 | |
8d417781 PM |
3311 | # Also set this value for the currently running GDB. |
3312 | match_max [match_max -d] | |
c906108c SS |
3313 | |
3314 | # We want to add the name of the TCL testcase to the PASS/FAIL messages. | |
3315 | if { [llength $args] > 0 } { | |
3316 | global pf_prefix | |
3317 | ||
3318 | set file [lindex $args 0]; | |
3319 | ||
3320 | set pf_prefix "[file tail [file dirname $file]]/[file tail $file]:"; | |
3321 | } | |
3322 | global gdb_prompt; | |
3323 | if [target_info exists gdb_prompt] { | |
3324 | set gdb_prompt [target_info gdb_prompt]; | |
3325 | } else { | |
3326 | set gdb_prompt "\\(gdb\\)" | |
3327 | } | |
e11ac3a3 JK |
3328 | global use_gdb_stub |
3329 | if [info exists use_gdb_stub] { | |
3330 | unset use_gdb_stub | |
3331 | } | |
c906108c SS |
3332 | } |
3333 | ||
0a6d0306 | 3334 | # Turn BASENAME into a full file name in the standard output |
8a3e1f8d TT |
3335 | # directory. It is ok if BASENAME is the empty string; in this case |
3336 | # the directory is returned. | |
0a6d0306 TT |
3337 | |
3338 | proc standard_output_file {basename} { | |
3339 | global objdir subdir | |
3340 | ||
8a3e1f8d | 3341 | return [file join $objdir $subdir $basename] |
0a6d0306 TT |
3342 | } |
3343 | ||
3344 | # Set 'testfile', 'srcfile', and 'binfile'. | |
3345 | # | |
3346 | # ARGS is a list of source file specifications. | |
3347 | # Without any arguments, the .exp file's base name is used to | |
3348 | # compute the source file name. The ".c" extension is added in this case. | |
3349 | # If ARGS is not empty, each entry is a source file specification. | |
3350 | # If the specification starts with a ".", it is treated as a suffix | |
3351 | # to append to the .exp file's base name. | |
3352 | # If the specification is the empty string, it is treated as if it | |
3353 | # were ".c". | |
3354 | # Otherwise it is a file name. | |
3355 | # The first file in the list is used to set the 'srcfile' global. | |
3356 | # Each subsequent name is used to set 'srcfile2', 'srcfile3', etc. | |
3357 | # | |
3358 | # Most tests should call this without arguments. | |
3359 | # | |
3360 | # If a completely different binary file name is needed, then it | |
3361 | # should be handled in the .exp file with a suitable comment. | |
3362 | ||
3363 | proc standard_testfile {args} { | |
3364 | global gdb_test_file_name | |
93c0ef37 | 3365 | global subdir |
686f09d0 | 3366 | global gdb_test_file_last_vars |
0a6d0306 TT |
3367 | |
3368 | # Outputs. | |
3369 | global testfile binfile | |
3370 | ||
3371 | set testfile $gdb_test_file_name | |
3372 | set binfile [standard_output_file ${testfile}] | |
3373 | ||
3374 | if {[llength $args] == 0} { | |
3375 | set args .c | |
3376 | } | |
3377 | ||
686f09d0 TT |
3378 | # Unset our previous output variables. |
3379 | # This can help catch hidden bugs. | |
3380 | if {[info exists gdb_test_file_last_vars]} { | |
3381 | foreach varname $gdb_test_file_last_vars { | |
3382 | global $varname | |
3383 | catch {unset $varname} | |
3384 | } | |
3385 | } | |
3386 | # 'executable' is often set by tests. | |
3387 | set gdb_test_file_last_vars {executable} | |
3388 | ||
0a6d0306 TT |
3389 | set suffix "" |
3390 | foreach arg $args { | |
3391 | set varname srcfile$suffix | |
3392 | global $varname | |
3393 | ||
3394 | # Handle an extension. | |
3395 | if {$arg == ""} { | |
3396 | set arg $testfile.c | |
3397 | } elseif {[string range $arg 0 0] == "."} { | |
3398 | set arg $testfile$arg | |
3399 | } | |
3400 | ||
3401 | set $varname $arg | |
686f09d0 | 3402 | lappend gdb_test_file_last_vars $varname |
0a6d0306 TT |
3403 | |
3404 | if {$suffix == ""} { | |
3405 | set suffix 2 | |
3406 | } else { | |
3407 | incr suffix | |
3408 | } | |
3409 | } | |
3410 | } | |
3411 | ||
7b356089 JB |
3412 | # The default timeout used when testing GDB commands. We want to use |
3413 | # the same timeout as the default dejagnu timeout, unless the user has | |
3414 | # already provided a specific value (probably through a site.exp file). | |
3415 | global gdb_test_timeout | |
3416 | if ![info exists gdb_test_timeout] { | |
3417 | set gdb_test_timeout $timeout | |
3418 | } | |
3419 | ||
47050449 JB |
3420 | # A list of global variables that GDB testcases should not use. |
3421 | # We try to prevent their use by monitoring write accesses and raising | |
3422 | # an error when that happens. | |
3423 | set banned_variables { bug_id prms_id } | |
3424 | ||
abcc4978 PA |
3425 | # A list of procedures that GDB testcases should not use. |
3426 | # We try to prevent their use by monitoring invocations and raising | |
3427 | # an error when that happens. | |
3428 | set banned_procedures { strace } | |
3429 | ||
41b2c92d PM |
3430 | # gdb_init is called by runtest at start, but also by several |
3431 | # tests directly; gdb_finish is only called from within runtest after | |
3432 | # each test source execution. | |
3433 | # Placing several traces by repetitive calls to gdb_init leads | |
3434 | # to problems, as only one trace is removed in gdb_finish. | |
3435 | # To overcome this possible problem, we add a variable that records | |
abcc4978 PA |
3436 | # if the banned variables and procedures are already traced. |
3437 | set banned_traced 0 | |
41b2c92d | 3438 | |
c906108c | 3439 | proc gdb_init { args } { |
7b356089 JB |
3440 | # Reset the timeout value to the default. This way, any testcase |
3441 | # that changes the timeout value without resetting it cannot affect | |
3442 | # the timeout used in subsequent testcases. | |
3443 | global gdb_test_timeout | |
3444 | global timeout | |
3445 | set timeout $gdb_test_timeout | |
3446 | ||
abcc4978 PA |
3447 | # Block writes to all banned variables, and invocation of all |
3448 | # banned procedures... | |
47050449 | 3449 | global banned_variables |
abcc4978 PA |
3450 | global banned_procedures |
3451 | global banned_traced | |
3452 | if (!$banned_traced) { | |
41b2c92d PM |
3453 | foreach banned_var $banned_variables { |
3454 | global "$banned_var" | |
3455 | trace add variable "$banned_var" write error | |
3456 | } | |
abcc4978 PA |
3457 | foreach banned_proc $banned_procedures { |
3458 | global "$banned_proc" | |
3459 | trace add execution "$banned_proc" enter error | |
3460 | } | |
3461 | set banned_traced 1 | |
47050449 JB |
3462 | } |
3463 | ||
e7ab5e63 AB |
3464 | # We set LC_ALL, LC_CTYPE, and LANG to C so that we get the same |
3465 | # messages as expected. | |
c6f2ac43 | 3466 | setenv LC_ALL C |
e7ab5e63 | 3467 | setenv LC_CTYPE C |
c6f2ac43 PA |
3468 | setenv LANG C |
3469 | ||
e7ab5e63 AB |
3470 | # Don't let a .inputrc file or an existing setting of INPUTRC mess up |
3471 | # the test results. Even if /dev/null doesn't exist on the particular | |
3472 | # platform, the readline library will use the default setting just by | |
3473 | # failing to open the file. OTOH, opening /dev/null successfully will | |
3474 | # also result in the default settings being used since nothing will be | |
3475 | # read from this file. | |
3476 | setenv INPUTRC "/dev/null" | |
3477 | ||
3478 | # The gdb.base/readline.exp arrow key test relies on the standard VT100 | |
3479 | # bindings, so make sure that an appropriate terminal is selected. | |
3480 | # The same bug doesn't show up if we use ^P / ^N instead. | |
3481 | setenv TERM "vt100" | |
3482 | ||
3483 | # Some tests (for example gdb.base/maint.exp) shell out from gdb to use | |
3484 | # grep. Clear GREP_OPTIONS to make the behavoiur predictable, | |
3485 | # especially having color output turned on can cause tests to fail. | |
3486 | setenv GREP_OPTIONS "" | |
3487 | ||
03f2bd59 JK |
3488 | # Clear $gdbserver_reconnect_p. |
3489 | global gdbserver_reconnect_p | |
3490 | set gdbserver_reconnect_p 1 | |
3491 | unset gdbserver_reconnect_p | |
3492 | ||
ae59b1da | 3493 | return [eval default_gdb_init $args] |
c906108c SS |
3494 | } |
3495 | ||
3496 | proc gdb_finish { } { | |
93f02886 DJ |
3497 | global cleanfiles |
3498 | ||
3499 | # Exit first, so that the files are no longer in use. | |
3500 | gdb_exit | |
3501 | ||
3502 | if { [llength $cleanfiles] > 0 } { | |
3503 | eval remote_file target delete $cleanfiles | |
3504 | set cleanfiles {} | |
3505 | } | |
47050449 JB |
3506 | |
3507 | # Unblock write access to the banned variables. Dejagnu typically | |
3508 | # resets some of them between testcases. | |
3509 | global banned_variables | |
abcc4978 PA |
3510 | global banned_procedures |
3511 | global banned_traced | |
3512 | if ($banned_traced) { | |
41b2c92d PM |
3513 | foreach banned_var $banned_variables { |
3514 | global "$banned_var" | |
3515 | trace remove variable "$banned_var" write error | |
3516 | } | |
abcc4978 PA |
3517 | foreach banned_proc $banned_procedures { |
3518 | global "$banned_proc" | |
3519 | trace remove execution "$banned_proc" enter error | |
3520 | } | |
3521 | set banned_traced 0 | |
47050449 | 3522 | } |
c906108c SS |
3523 | } |
3524 | ||
3525 | global debug_format | |
7a292a7a | 3526 | set debug_format "unknown" |
c906108c SS |
3527 | |
3528 | # Run the gdb command "info source" and extract the debugging format | |
3529 | # information from the output and save it in debug_format. | |
3530 | ||
3531 | proc get_debug_format { } { | |
3532 | global gdb_prompt | |
3533 | global verbose | |
3534 | global expect_out | |
3535 | global debug_format | |
3536 | ||
3537 | set debug_format "unknown" | |
3538 | send_gdb "info source\n" | |
3539 | gdb_expect 10 { | |
919d772c | 3540 | -re "Compiled with (.*) debugging format.\r\n.*$gdb_prompt $" { |
c906108c SS |
3541 | set debug_format $expect_out(1,string) |
3542 | verbose "debug format is $debug_format" | |
ae59b1da | 3543 | return 1 |
c906108c SS |
3544 | } |
3545 | -re "No current source file.\r\n$gdb_prompt $" { | |
3546 | perror "get_debug_format used when no current source file" | |
ae59b1da | 3547 | return 0 |
c906108c SS |
3548 | } |
3549 | -re "$gdb_prompt $" { | |
3550 | warning "couldn't check debug format (no valid response)." | |
ae59b1da | 3551 | return 1 |
c906108c SS |
3552 | } |
3553 | timeout { | |
975531db | 3554 | warning "couldn't check debug format (timeout)." |
ae59b1da | 3555 | return 1 |
c906108c SS |
3556 | } |
3557 | } | |
3558 | } | |
3559 | ||
838ae6c4 JB |
3560 | # Return true if FORMAT matches the debug format the current test was |
3561 | # compiled with. FORMAT is a shell-style globbing pattern; it can use | |
3562 | # `*', `[...]', and so on. | |
3563 | # | |
3564 | # This function depends on variables set by `get_debug_format', above. | |
3565 | ||
3566 | proc test_debug_format {format} { | |
3567 | global debug_format | |
3568 | ||
3569 | return [expr [string match $format $debug_format] != 0] | |
3570 | } | |
3571 | ||
c906108c SS |
3572 | # Like setup_xfail, but takes the name of a debug format (DWARF 1, |
3573 | # COFF, stabs, etc). If that format matches the format that the | |
3574 | # current test was compiled with, then the next test is expected to | |
3575 | # fail for any target. Returns 1 if the next test or set of tests is | |
3576 | # expected to fail, 0 otherwise (or if it is unknown). Must have | |
3577 | # previously called get_debug_format. | |
b55a4771 | 3578 | proc setup_xfail_format { format } { |
838ae6c4 | 3579 | set ret [test_debug_format $format]; |
b55a4771 | 3580 | |
838ae6c4 | 3581 | if {$ret} then { |
b55a4771 MS |
3582 | setup_xfail "*-*-*" |
3583 | } | |
ae59b1da | 3584 | return $ret |
b55a4771 | 3585 | } |
c906108c | 3586 | |
c6fee705 MC |
3587 | # gdb_get_line_number TEXT [FILE] |
3588 | # | |
3589 | # Search the source file FILE, and return the line number of the | |
0d7941a9 | 3590 | # first line containing TEXT. If no match is found, an error is thrown. |
c6fee705 MC |
3591 | # |
3592 | # TEXT is a string literal, not a regular expression. | |
3593 | # | |
3594 | # The default value of FILE is "$srcdir/$subdir/$srcfile". If FILE is | |
3595 | # specified, and does not start with "/", then it is assumed to be in | |
3596 | # "$srcdir/$subdir". This is awkward, and can be fixed in the future, | |
3597 | # by changing the callers and the interface at the same time. | |
3598 | # In particular: gdb.base/break.exp, gdb.base/condbreak.exp, | |
3599 | # gdb.base/ena-dis-br.exp. | |
3600 | # | |
3601 | # Use this function to keep your test scripts independent of the | |
3602 | # exact line numbering of the source file. Don't write: | |
3603 | # | |
3604 | # send_gdb "break 20" | |
3605 | # | |
3606 | # This means that if anyone ever edits your test's source file, | |
3607 | # your test could break. Instead, put a comment like this on the | |
3608 | # source file line you want to break at: | |
3609 | # | |
3610 | # /* breakpoint spot: frotz.exp: test name */ | |
3611 | # | |
3612 | # and then write, in your test script (which we assume is named | |
3613 | # frotz.exp): | |
3614 | # | |
3615 | # send_gdb "break [gdb_get_line_number "frotz.exp: test name"]\n" | |
3616 | # | |
3617 | # (Yes, Tcl knows how to handle the nested quotes and brackets. | |
3618 | # Try this: | |
3619 | # $ tclsh | |
3620 | # % puts "foo [lindex "bar baz" 1]" | |
3621 | # foo baz | |
3622 | # % | |
3623 | # Tcl is quite clever, for a little stringy language.) | |
3624 | # | |
3625 | # === | |
3626 | # | |
3627 | # The previous implementation of this procedure used the gdb search command. | |
3628 | # This version is different: | |
3629 | # | |
3630 | # . It works with MI, and it also works when gdb is not running. | |
3631 | # | |
3632 | # . It operates on the build machine, not the host machine. | |
3633 | # | |
3634 | # . For now, this implementation fakes a current directory of | |
3635 | # $srcdir/$subdir to be compatible with the old implementation. | |
3636 | # This will go away eventually and some callers will need to | |
3637 | # be changed. | |
3638 | # | |
3639 | # . The TEXT argument is literal text and matches literally, | |
3640 | # not a regular expression as it was before. | |
3641 | # | |
3642 | # . State changes in gdb, such as changing the current file | |
3643 | # and setting $_, no longer happen. | |
3644 | # | |
3645 | # After a bit of time we can forget about the differences from the | |
3646 | # old implementation. | |
3647 | # | |
3648 | # --chastain 2004-08-05 | |
3649 | ||
3650 | proc gdb_get_line_number { text { file "" } } { | |
3651 | global srcdir | |
3652 | global subdir | |
3653 | global srcfile | |
c906108c | 3654 | |
c6fee705 MC |
3655 | if { "$file" == "" } then { |
3656 | set file "$srcfile" | |
3657 | } | |
3658 | if { ! [regexp "^/" "$file"] } then { | |
3659 | set file "$srcdir/$subdir/$file" | |
c906108c SS |
3660 | } |
3661 | ||
c6fee705 | 3662 | if { [ catch { set fd [open "$file"] } message ] } then { |
0d7941a9 | 3663 | error "$message" |
c906108c | 3664 | } |
c6fee705 MC |
3665 | |
3666 | set found -1 | |
3667 | for { set line 1 } { 1 } { incr line } { | |
3668 | if { [ catch { set nchar [gets "$fd" body] } message ] } then { | |
0d7941a9 | 3669 | error "$message" |
c6fee705 MC |
3670 | } |
3671 | if { $nchar < 0 } then { | |
3672 | break | |
3673 | } | |
3674 | if { [string first "$text" "$body"] >= 0 } then { | |
3675 | set found $line | |
3676 | break | |
3677 | } | |
3678 | } | |
3679 | ||
3680 | if { [ catch { close "$fd" } message ] } then { | |
0d7941a9 KS |
3681 | error "$message" |
3682 | } | |
3683 | ||
3684 | if {$found == -1} { | |
3685 | error "undefined tag \"$text\"" | |
c6fee705 MC |
3686 | } |
3687 | ||
3688 | return $found | |
c906108c SS |
3689 | } |
3690 | ||
7a292a7a SS |
3691 | # gdb_continue_to_end: |
3692 | # The case where the target uses stubs has to be handled specially. If a | |
3693 | # stub is used, we set a breakpoint at exit because we cannot rely on | |
3694 | # exit() behavior of a remote target. | |
3695 | # | |
fda326dd TT |
3696 | # MSSG is the error message that gets printed. If not given, a |
3697 | # default is used. | |
3698 | # COMMAND is the command to invoke. If not given, "continue" is | |
3699 | # used. | |
eceb0c5f TT |
3700 | # ALLOW_EXTRA is a flag indicating whether the test should expect |
3701 | # extra output between the "Continuing." line and the program | |
3702 | # exiting. By default it is zero; if nonzero, any extra output | |
3703 | # is accepted. | |
fda326dd | 3704 | |
eceb0c5f | 3705 | proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} { |
e11ac3a3 | 3706 | global inferior_exited_re use_gdb_stub |
7a292a7a | 3707 | |
fda326dd TT |
3708 | if {$mssg == ""} { |
3709 | set text "continue until exit" | |
3710 | } else { | |
3711 | set text "continue until exit at $mssg" | |
3712 | } | |
eceb0c5f TT |
3713 | if {$allow_extra} { |
3714 | set extra ".*" | |
3715 | } else { | |
3716 | set extra "" | |
3717 | } | |
e11ac3a3 | 3718 | if $use_gdb_stub { |
7a292a7a SS |
3719 | if {![gdb_breakpoint "exit"]} { |
3720 | return 0 | |
3721 | } | |
eceb0c5f | 3722 | gdb_test $command "Continuing..*Breakpoint .*exit.*" \ |
fda326dd | 3723 | $text |
7a292a7a SS |
3724 | } else { |
3725 | # Continue until we exit. Should not stop again. | |
3726 | # Don't bother to check the output of the program, that may be | |
3727 | # extremely tough for some remote systems. | |
eceb0c5f TT |
3728 | gdb_test $command \ |
3729 | "Continuing.\[\r\n0-9\]+${extra}(... EXIT code 0\[\r\n\]+|$inferior_exited_re normally).*"\ | |
fda326dd | 3730 | $text |
7a292a7a SS |
3731 | } |
3732 | } | |
3733 | ||
3734 | proc rerun_to_main {} { | |
e11ac3a3 | 3735 | global gdb_prompt use_gdb_stub |
7a292a7a | 3736 | |
e11ac3a3 | 3737 | if $use_gdb_stub { |
7a292a7a SS |
3738 | gdb_run_cmd |
3739 | gdb_expect { | |
3740 | -re ".*Breakpoint .*main .*$gdb_prompt $"\ | |
3741 | {pass "rerun to main" ; return 0} | |
3742 | -re "$gdb_prompt $"\ | |
3743 | {fail "rerun to main" ; return 0} | |
3744 | timeout {fail "(timeout) rerun to main" ; return 0} | |
3745 | } | |
3746 | } else { | |
3747 | send_gdb "run\n" | |
3748 | gdb_expect { | |
11350d2a CV |
3749 | -re "The program .* has been started already.*y or n. $" { |
3750 | send_gdb "y\n" | |
3751 | exp_continue | |
3752 | } | |
7a292a7a SS |
3753 | -re "Starting program.*$gdb_prompt $"\ |
3754 | {pass "rerun to main" ; return 0} | |
3755 | -re "$gdb_prompt $"\ | |
3756 | {fail "rerun to main" ; return 0} | |
3757 | timeout {fail "(timeout) rerun to main" ; return 0} | |
3758 | } | |
3759 | } | |
3760 | } | |
c906108c | 3761 | |
13a5e3b8 MS |
3762 | # Print a message and return true if a test should be skipped |
3763 | # due to lack of floating point suport. | |
3764 | ||
3765 | proc gdb_skip_float_test { msg } { | |
3766 | if [target_info exists gdb,skip_float_tests] { | |
3767 | verbose "Skipping test '$msg': no float tests."; | |
ae59b1da | 3768 | return 1 |
13a5e3b8 | 3769 | } |
ae59b1da | 3770 | return 0 |
13a5e3b8 MS |
3771 | } |
3772 | ||
3773 | # Print a message and return true if a test should be skipped | |
3774 | # due to lack of stdio support. | |
3775 | ||
3776 | proc gdb_skip_stdio_test { msg } { | |
3777 | if [target_info exists gdb,noinferiorio] { | |
3778 | verbose "Skipping test '$msg': no inferior i/o."; | |
ae59b1da | 3779 | return 1 |
13a5e3b8 | 3780 | } |
ae59b1da | 3781 | return 0 |
13a5e3b8 MS |
3782 | } |
3783 | ||
3784 | proc gdb_skip_bogus_test { msg } { | |
ae59b1da | 3785 | return 0 |
13a5e3b8 MS |
3786 | } |
3787 | ||
e515b470 DJ |
3788 | # Return true if a test should be skipped due to lack of XML support |
3789 | # in the host GDB. | |
d0ef5df8 | 3790 | # NOTE: This must be called while gdb is *not* running. |
e515b470 DJ |
3791 | |
3792 | proc gdb_skip_xml_test { } { | |
3793 | global gdb_prompt | |
3794 | global srcdir | |
3795 | global xml_missing_cached | |
3796 | ||
3797 | if {[info exists xml_missing_cached]} { | |
3798 | return $xml_missing_cached | |
3799 | } | |
3800 | ||
3801 | gdb_start | |
3802 | set xml_missing_cached 0 | |
3803 | gdb_test_multiple "set tdesc filename ${srcdir}/gdb.xml/trivial.xml" "" { | |
3804 | -re ".*XML support was disabled at compile time.*$gdb_prompt $" { | |
3805 | set xml_missing_cached 1 | |
3806 | } | |
3807 | -re ".*$gdb_prompt $" { } | |
3808 | } | |
3809 | gdb_exit | |
3810 | return $xml_missing_cached | |
3811 | } | |
1f8a6abb EZ |
3812 | |
3813 | # Note: the procedure gdb_gnu_strip_debug will produce an executable called | |
3814 | # ${binfile}.dbglnk, which is just like the executable ($binfile) but without | |
3815 | # the debuginfo. Instead $binfile has a .gnu_debuglink section which contains | |
8e1d0c49 JK |
3816 | # the name of a debuginfo only file. This file will be stored in the same |
3817 | # subdirectory. | |
1f8a6abb EZ |
3818 | |
3819 | # Functions for separate debug info testing | |
3820 | ||
3821 | # starting with an executable: | |
3822 | # foo --> original executable | |
3823 | ||
3824 | # at the end of the process we have: | |
3825 | # foo.stripped --> foo w/o debug info | |
8e1d0c49 | 3826 | # foo.debug --> foo's debug info |
1f8a6abb EZ |
3827 | # foo --> like foo, but with a new .gnu_debuglink section pointing to foo.debug. |
3828 | ||
4935890f JK |
3829 | # Return the build-id hex string (usually 160 bits as 40 hex characters) |
3830 | # converted to the form: .build-id/ab/cdef1234...89.debug | |
3831 | # Return "" if no build-id found. | |
3832 | proc build_id_debug_filename_get { exec } { | |
3833 | set tmp "${exec}-tmp" | |
8b3fc8d8 MK |
3834 | set objcopy_program [transform objcopy] |
3835 | ||
3836 | set result [catch "exec $objcopy_program -j .note.gnu.build-id -O binary $exec $tmp" output] | |
3837 | verbose "result is $result" | |
3838 | verbose "output is $output" | |
3839 | if {$result == 1} { | |
3840 | return "" | |
3841 | } | |
4935890f | 3842 | set fi [open $tmp] |
b7fca990 | 3843 | fconfigure $fi -translation binary |
4935890f JK |
3844 | # Skip the NOTE header. |
3845 | read $fi 16 | |
3846 | set data [read $fi] | |
3847 | close $fi | |
3848 | file delete $tmp | |
7020f05c | 3849 | if ![string compare $data ""] then { |
4935890f JK |
3850 | return "" |
3851 | } | |
3852 | # Convert it to hex. | |
3853 | binary scan $data H* data | |
061b5285 | 3854 | regsub {^..} $data {\0/} data |
ae59b1da | 3855 | return ".build-id/${data}.debug" |
4935890f JK |
3856 | } |
3857 | ||
94277a38 DJ |
3858 | # Create stripped files for DEST, replacing it. If ARGS is passed, it is a |
3859 | # list of optional flags. The only currently supported flag is no-main, | |
3860 | # which removes the symbol entry for main from the separate debug file. | |
c0201579 JK |
3861 | # |
3862 | # Function returns zero on success. Function will return non-zero failure code | |
3863 | # on some targets not supporting separate debug info (such as i386-msdos). | |
1f8a6abb | 3864 | |
94277a38 DJ |
3865 | proc gdb_gnu_strip_debug { dest args } { |
3866 | ||
8e1d0c49 JK |
3867 | # Use the first separate debug info file location searched by GDB so the |
3868 | # run cannot be broken by some stale file searched with higher precedence. | |
3869 | set debug_file "${dest}.debug" | |
3870 | ||
b741e217 DJ |
3871 | set strip_to_file_program [transform strip] |
3872 | set objcopy_program [transform objcopy] | |
1f8a6abb | 3873 | |
1f8a6abb EZ |
3874 | set debug_link [file tail $debug_file] |
3875 | set stripped_file "${dest}.stripped" | |
3876 | ||
3877 | # Get rid of the debug info, and store result in stripped_file | |
3878 | # something like gdb/testsuite/gdb.base/blah.stripped. | |
3879 | set result [catch "exec $strip_to_file_program --strip-debug ${dest} -o ${stripped_file}" output] | |
3880 | verbose "result is $result" | |
3881 | verbose "output is $output" | |
3882 | if {$result == 1} { | |
3883 | return 1 | |
3884 | } | |
3885 | ||
d521f563 JK |
3886 | # Workaround PR binutils/10802: |
3887 | # Preserve the 'x' bit also for PIEs (Position Independent Executables). | |
3888 | set perm [file attributes ${dest} -permissions] | |
3889 | file attributes ${stripped_file} -permissions $perm | |
3890 | ||
1f8a6abb EZ |
3891 | # Get rid of everything but the debug info, and store result in debug_file |
3892 | # This will be in the .debug subdirectory, see above. | |
3893 | set result [catch "exec $strip_to_file_program --only-keep-debug ${dest} -o ${debug_file}" output] | |
3894 | verbose "result is $result" | |
3895 | verbose "output is $output" | |
3896 | if {$result == 1} { | |
3897 | return 1 | |
3898 | } | |
3899 | ||
94277a38 DJ |
3900 | # If no-main is passed, strip the symbol for main from the separate |
3901 | # file. This is to simulate the behavior of elfutils's eu-strip, which | |
3902 | # leaves the symtab in the original file only. There's no way to get | |
3903 | # objcopy or strip to remove the symbol table without also removing the | |
3904 | # debugging sections, so this is as close as we can get. | |
3905 | if { [llength $args] == 1 && [lindex $args 0] == "no-main" } { | |
3906 | set result [catch "exec $objcopy_program -N main ${debug_file} ${debug_file}-tmp" output] | |
3907 | verbose "result is $result" | |
3908 | verbose "output is $output" | |
3909 | if {$result == 1} { | |
3910 | return 1 | |
3911 | } | |
3912 | file delete "${debug_file}" | |
3913 | file rename "${debug_file}-tmp" "${debug_file}" | |
3914 | } | |
3915 | ||
1f8a6abb EZ |
3916 | # Link the two previous output files together, adding the .gnu_debuglink |
3917 | # section to the stripped_file, containing a pointer to the debug_file, | |
3918 | # save the new file in dest. | |
3919 | # This will be the regular executable filename, in the usual location. | |
3920 | set result [catch "exec $objcopy_program --add-gnu-debuglink=${debug_file} ${stripped_file} ${dest}" output] | |
3921 | verbose "result is $result" | |
3922 | verbose "output is $output" | |
3923 | if {$result == 1} { | |
3924 | return 1 | |
3925 | } | |
3926 | ||
d521f563 JK |
3927 | # Workaround PR binutils/10802: |
3928 | # Preserve the 'x' bit also for PIEs (Position Independent Executables). | |
3929 | set perm [file attributes ${stripped_file} -permissions] | |
3930 | file attributes ${dest} -permissions $perm | |
3931 | ||
3932 | return 0 | |
1f8a6abb EZ |
3933 | } |
3934 | ||
d8295fe9 VP |
3935 | # Test the output of GDB_COMMAND matches the pattern obtained |
3936 | # by concatenating all elements of EXPECTED_LINES. This makes | |
3937 | # it possible to split otherwise very long string into pieces. | |
3938 | # If third argument is not empty, it's used as the name of the | |
3939 | # test to be printed on pass/fail. | |
3940 | proc help_test_raw { gdb_command expected_lines args } { | |
3941 | set message $gdb_command | |
3942 | if [llength $args]>0 then { | |
3943 | set message [lindex $args 0] | |
3944 | } | |
3945 | set expected_output [join $expected_lines ""] | |
3946 | gdb_test "${gdb_command}" "${expected_output}" $message | |
3947 | } | |
3948 | ||
6aee0d90 | 3949 | # Test the output of "help COMMAND_CLASS". EXPECTED_INITIAL_LINES |
d8295fe9 VP |
3950 | # are regular expressions that should match the beginning of output, |
3951 | # before the list of commands in that class. The presence of | |
3952 | # command list and standard epilogue will be tested automatically. | |
3953 | proc test_class_help { command_class expected_initial_lines args } { | |
3954 | set l_stock_body { | |
3955 | "List of commands\:.*\[\r\n\]+" | |
3956 | "Type \"help\" followed by command name for full documentation\.\[\r\n\]+" | |
3957 | "Type \"apropos word\" to search for commands related to \"word\"\.[\r\n\]+" | |
3958 | "Command name abbreviations are allowed if unambiguous\." | |
3959 | } | |
3960 | set l_entire_body [concat $expected_initial_lines $l_stock_body] | |
3961 | ||
3962 | eval [list help_test_raw "help ${command_class}" $l_entire_body] $args | |
3963 | } | |
3964 | ||
3965 | # COMMAND_LIST should have either one element -- command to test, or | |
3966 | # two elements -- abbreviated command to test, and full command the first | |
3967 | # element is abbreviation of. | |
3968 | # The command must be a prefix command. EXPECTED_INITIAL_LINES | |
3969 | # are regular expressions that should match the beginning of output, | |
3970 | # before the list of subcommands. The presence of | |
3971 | # subcommand list and standard epilogue will be tested automatically. | |
3972 | proc test_prefix_command_help { command_list expected_initial_lines args } { | |
3973 | set command [lindex $command_list 0] | |
3974 | if {[llength $command_list]>1} { | |
3975 | set full_command [lindex $command_list 1] | |
3976 | } else { | |
3977 | set full_command $command | |
3978 | } | |
3979 | # Use 'list' and not just {} because we want variables to | |
3980 | # be expanded in this list. | |
3981 | set l_stock_body [list\ | |
3982 | "List of $full_command subcommands\:.*\[\r\n\]+"\ | |
3983 | "Type \"help $full_command\" followed by $full_command subcommand name for full documentation\.\[\r\n\]+"\ | |
3984 | "Type \"apropos word\" to search for commands related to \"word\"\.\[\r\n\]+"\ | |
3985 | "Command name abbreviations are allowed if unambiguous\."] | |
3986 | set l_entire_body [concat $expected_initial_lines $l_stock_body] | |
3987 | if {[llength $args]>0} { | |
3988 | help_test_raw "help ${command}" $l_entire_body [lindex $args 0] | |
3989 | } else { | |
3990 | help_test_raw "help ${command}" $l_entire_body | |
3991 | } | |
3992 | } | |
dbc52822 | 3993 | |
85b4440a TT |
3994 | # Build executable named EXECUTABLE from specifications that allow |
3995 | # different options to be passed to different sub-compilations. | |
3996 | # TESTNAME is the name of the test; this is passed to 'untested' if | |
3997 | # something fails. | |
3998 | # OPTIONS is passed to the final link, using gdb_compile. | |
3999 | # ARGS is a flat list of source specifications, of the form: | |
4000 | # { SOURCE1 OPTIONS1 [ SOURCE2 OPTIONS2 ]... } | |
4001 | # Each SOURCE is compiled to an object file using its OPTIONS, | |
4002 | # using gdb_compile. | |
4003 | # Returns 0 on success, -1 on failure. | |
4004 | proc build_executable_from_specs {testname executable options args} { | |
dbc52822 VP |
4005 | global subdir |
4006 | global srcdir | |
dbc52822 | 4007 | |
0a6d0306 | 4008 | set binfile [standard_output_file $executable] |
dbc52822 VP |
4009 | |
4010 | set objects {} | |
85b4440a TT |
4011 | set i 0 |
4012 | foreach {s local_options} $args { | |
4013 | if { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $local_options] != "" } { | |
dbc52822 VP |
4014 | untested $testname |
4015 | return -1 | |
4016 | } | |
4017 | lappend objects "${binfile}${i}.o" | |
85b4440a | 4018 | incr i |
dbc52822 VP |
4019 | } |
4020 | ||
4021 | if { [gdb_compile $objects "${binfile}" executable $options] != "" } { | |
4022 | untested $testname | |
4023 | return -1 | |
4024 | } | |
4025 | ||
fd961404 DE |
4026 | set info_options "" |
4027 | if { [lsearch -exact $options "c++"] >= 0 } { | |
4028 | set info_options "c++" | |
4029 | } | |
4c93b1db | 4030 | if [get_compiler_info ${info_options}] { |
dbc52822 VP |
4031 | return -1 |
4032 | } | |
4033 | return 0 | |
4034 | } | |
4035 | ||
85b4440a TT |
4036 | # Build executable named EXECUTABLE, from SOURCES. If SOURCES are not |
4037 | # provided, uses $EXECUTABLE.c. The TESTNAME paramer is the name of test | |
4038 | # to pass to untested, if something is wrong. OPTIONS are passed | |
4039 | # to gdb_compile directly. | |
4040 | proc build_executable { testname executable {sources ""} {options {debug}} } { | |
4041 | if {[llength $sources]==0} { | |
4042 | set sources ${executable}.c | |
4043 | } | |
4044 | ||
4045 | set arglist [list $testname $executable $options] | |
4046 | foreach source $sources { | |
4047 | lappend arglist $source $options | |
4048 | } | |
4049 | ||
4050 | return [eval build_executable_from_specs $arglist] | |
4051 | } | |
4052 | ||
dbc52822 | 4053 | # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is |
0a6d0306 | 4054 | # the basename of the binary. |
dbc52822 VP |
4055 | proc clean_restart { executable } { |
4056 | global srcdir | |
dbc52822 | 4057 | global subdir |
0a6d0306 | 4058 | set binfile [standard_output_file ${executable}] |
dbc52822 VP |
4059 | |
4060 | gdb_exit | |
4061 | gdb_start | |
4062 | gdb_reinitialize_dir $srcdir/$subdir | |
4063 | gdb_load ${binfile} | |
dbc52822 VP |
4064 | } |
4065 | ||
85b4440a TT |
4066 | # Prepares for testing by calling build_executable_full, then |
4067 | # clean_restart. | |
4068 | # TESTNAME is the name of the test. | |
4069 | # Each element in ARGS is a list of the form | |
4070 | # { EXECUTABLE OPTIONS SOURCE_SPEC... } | |
4071 | # These are passed to build_executable_from_specs, which see. | |
4072 | # The last EXECUTABLE is passed to clean_restart. | |
4073 | # Returns 0 on success, non-zero on failure. | |
4074 | proc prepare_for_testing_full {testname args} { | |
4075 | foreach spec $args { | |
4076 | if {[eval build_executable_from_specs [list $testname] $spec] == -1} { | |
4077 | return -1 | |
4078 | } | |
4079 | set executable [lindex $spec 0] | |
4080 | } | |
4081 | clean_restart $executable | |
4082 | return 0 | |
4083 | } | |
4084 | ||
dbc52822 VP |
4085 | # Prepares for testing, by calling build_executable, and then clean_restart. |
4086 | # Please refer to build_executable for parameter description. | |
4087 | proc prepare_for_testing { testname executable {sources ""} {options {debug}}} { | |
4088 | ||
734a5c36 | 4089 | if {[build_executable $testname $executable $sources $options] == -1} { |
dbc52822 VP |
4090 | return -1 |
4091 | } | |
4092 | clean_restart $executable | |
4093 | ||
4094 | return 0 | |
4095 | } | |
7065b901 TT |
4096 | |
4097 | proc get_valueof { fmt exp default } { | |
4098 | global gdb_prompt | |
4099 | ||
4100 | set test "get valueof \"${exp}\"" | |
4101 | set val ${default} | |
4102 | gdb_test_multiple "print${fmt} ${exp}" "$test" { | |
417e16e2 PM |
4103 | -re "\\$\[0-9\]* = (.*)\[\r\n\]*$gdb_prompt $" { |
4104 | set val $expect_out(1,string) | |
4105 | pass "$test ($val)" | |
4106 | } | |
4107 | timeout { | |
4108 | fail "$test (timeout)" | |
4109 | } | |
4110 | } | |
4111 | return ${val} | |
4112 | } | |
4113 | ||
4114 | proc get_integer_valueof { exp default } { | |
4115 | global gdb_prompt | |
4116 | ||
4117 | set test "get integer valueof \"${exp}\"" | |
4118 | set val ${default} | |
4119 | gdb_test_multiple "print /d ${exp}" "$test" { | |
7065b901 TT |
4120 | -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" { |
4121 | set val $expect_out(1,string) | |
4122 | pass "$test ($val)" | |
4123 | } | |
4124 | timeout { | |
417e16e2 | 4125 | fail "$test (timeout)" |
7065b901 TT |
4126 | } |
4127 | } | |
4128 | return ${val} | |
4129 | } | |
4130 | ||
faafb047 PM |
4131 | proc get_hexadecimal_valueof { exp default } { |
4132 | global gdb_prompt | |
4133 | send_gdb "print /x ${exp}\n" | |
4134 | set test "get hexadecimal valueof \"${exp}\"" | |
4135 | gdb_expect { | |
4136 | -re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" { | |
4137 | set val $expect_out(1,string) | |
4138 | pass "$test" | |
4139 | } | |
4140 | timeout { | |
4141 | set val ${default} | |
4142 | fail "$test (timeout)" | |
4143 | } | |
4144 | } | |
4145 | return ${val} | |
4146 | } | |
417e16e2 | 4147 | |
7065b901 | 4148 | proc get_sizeof { type default } { |
417e16e2 | 4149 | return [get_integer_valueof "sizeof (${type})" $default] |
7065b901 TT |
4150 | } |
4151 | ||
db863c42 MF |
4152 | # Get the current value for remotetimeout and return it. |
4153 | proc get_remotetimeout { } { | |
4154 | global gdb_prompt | |
4155 | global decimal | |
4156 | ||
4157 | gdb_test_multiple "show remotetimeout" "" { | |
4158 | -re "Timeout limit to wait for target to respond is ($decimal).*$gdb_prompt $" { | |
ae59b1da | 4159 | return $expect_out(1,string) |
db863c42 MF |
4160 | } |
4161 | } | |
4162 | ||
4163 | # Pick the default that gdb uses | |
4164 | warning "Unable to read remotetimeout" | |
4165 | return 300 | |
4166 | } | |
4167 | ||
4168 | # Set the remotetimeout to the specified timeout. Nothing is returned. | |
4169 | proc set_remotetimeout { timeout } { | |
4170 | global gdb_prompt | |
4171 | ||
4172 | gdb_test_multiple "set remotetimeout $timeout" "" { | |
4173 | -re "$gdb_prompt $" { | |
4174 | verbose "Set remotetimeout to $timeout\n" | |
4175 | } | |
4176 | } | |
4177 | } | |
4178 | ||
812f7342 TT |
4179 | # Log gdb command line and script if requested. |
4180 | if {[info exists TRANSCRIPT]} { | |
4181 | rename send_gdb real_send_gdb | |
4182 | rename remote_spawn real_remote_spawn | |
4183 | rename remote_close real_remote_close | |
4184 | ||
4185 | global gdb_transcript | |
4186 | set gdb_transcript "" | |
4187 | ||
4188 | global gdb_trans_count | |
4189 | set gdb_trans_count 1 | |
4190 | ||
4191 | proc remote_spawn {args} { | |
4192 | global gdb_transcript gdb_trans_count outdir | |
4193 | ||
4194 | if {$gdb_transcript != ""} { | |
4195 | close $gdb_transcript | |
4196 | } | |
4197 | set gdb_transcript [open [file join $outdir transcript.$gdb_trans_count] w] | |
4198 | puts $gdb_transcript [lindex $args 1] | |
4199 | incr gdb_trans_count | |
4200 | ||
4201 | return [uplevel real_remote_spawn $args] | |
4202 | } | |
4203 | ||
4204 | proc remote_close {args} { | |
4205 | global gdb_transcript | |
4206 | ||
4207 | if {$gdb_transcript != ""} { | |
4208 | close $gdb_transcript | |
4209 | set gdb_transcript "" | |
4210 | } | |
4211 | ||
4212 | return [uplevel real_remote_close $args] | |
4213 | } | |
4214 | ||
4215 | proc send_gdb {args} { | |
4216 | global gdb_transcript | |
4217 | ||
4218 | if {$gdb_transcript != ""} { | |
4219 | puts -nonewline $gdb_transcript [lindex $args 0] | |
4220 | } | |
4221 | ||
4222 | return [uplevel real_send_gdb $args] | |
4223 | } | |
4224 | } | |
37aeb5df | 4225 | |
bbfba9ed | 4226 | proc core_find {binfile {deletefiles {}} {arg ""}} { |
37aeb5df JK |
4227 | global objdir subdir |
4228 | ||
4229 | set destcore "$binfile.core" | |
4230 | file delete $destcore | |
4231 | ||
4232 | # Create a core file named "$destcore" rather than just "core", to | |
4233 | # avoid problems with sys admin types that like to regularly prune all | |
4234 | # files named "core" from the system. | |
4235 | # | |
4236 | # Arbitrarily try setting the core size limit to "unlimited" since | |
4237 | # this does not hurt on systems where the command does not work and | |
4238 | # allows us to generate a core on systems where it does. | |
4239 | # | |
4240 | # Some systems append "core" to the name of the program; others append | |
4241 | # the name of the program to "core"; still others (like Linux, as of | |
4242 | # May 2003) create cores named "core.PID". In the latter case, we | |
4243 | # could have many core files lying around, and it may be difficult to | |
4244 | # tell which one is ours, so let's run the program in a subdirectory. | |
4245 | set found 0 | |
93c0ef37 | 4246 | set coredir [standard_output_file coredir.[getpid]] |
37aeb5df | 4247 | file mkdir $coredir |
bbfba9ed | 4248 | catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile} ${arg}; true) >/dev/null 2>&1\"" |
37aeb5df JK |
4249 | # remote_exec host "${binfile}" |
4250 | foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" { | |
4251 | if [remote_file build exists $i] { | |
4252 | remote_exec build "mv $i $destcore" | |
4253 | set found 1 | |
4254 | } | |
4255 | } | |
4256 | # Check for "core.PID". | |
4257 | if { $found == 0 } { | |
4258 | set names [glob -nocomplain -directory $coredir core.*] | |
4259 | if {[llength $names] == 1} { | |
4260 | set corefile [file join $coredir [lindex $names 0]] | |
4261 | remote_exec build "mv $corefile $destcore" | |
4262 | set found 1 | |
4263 | } | |
4264 | } | |
4265 | if { $found == 0 } { | |
4266 | # The braindamaged HPUX shell quits after the ulimit -c above | |
4267 | # without executing ${binfile}. So we try again without the | |
4268 | # ulimit here if we didn't find a core file above. | |
4269 | # Oh, I should mention that any "braindamaged" non-Unix system has | |
4270 | # the same problem. I like the cd bit too, it's really neat'n stuff. | |
4271 | catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\"" | |
4272 | foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" { | |
4273 | if [remote_file build exists $i] { | |
4274 | remote_exec build "mv $i $destcore" | |
4275 | set found 1 | |
4276 | } | |
4277 | } | |
4278 | } | |
4279 | ||
4280 | # Try to clean up after ourselves. | |
4281 | foreach deletefile $deletefiles { | |
4282 | remote_file build delete [file join $coredir $deletefile] | |
4283 | } | |
4284 | remote_exec build "rmdir $coredir" | |
4285 | ||
4286 | if { $found == 0 } { | |
4287 | warning "can't generate a core file - core tests suppressed - check ulimit -c" | |
4288 | return "" | |
4289 | } | |
4290 | return $destcore | |
4291 | } | |
ee5683ab PM |
4292 | |
4293 | # gdb_target_symbol_prefix_flags returns a string that can be added | |
4294 | # to gdb_compile options to define SYMBOL_PREFIX macro value | |
4295 | # symbol_prefix_flags returns a string that can be added | |
4296 | # for targets that use underscore as symbol prefix. | |
4297 | # TODO: find out automatically if the target needs this. | |
4298 | ||
4299 | proc gdb_target_symbol_prefix_flags {} { | |
4300 | if { [istarget "*-*-cygwin*"] || [istarget "i?86-*-mingw*"] | |
4301 | || [istarget "*-*-msdosdjgpp*"] || [istarget "*-*-go32*"] } { | |
4302 | return "additional_flags=-DSYMBOL_PREFIX=\"_\"" | |
4303 | } else { | |
4304 | return "" | |
4305 | } | |
4306 | } | |
4307 | ||
42159ca5 TT |
4308 | # Always load compatibility stuff. |
4309 | load_lib future.exp |