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