* gdb.gdb/selftest.exp (do_steps_and_nexts): Handle bfd_init
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.gdb / selftest.exp
CommitLineData
8acc9f48 1# Copyright 1988-2013 Free Software Foundation, Inc.
adf40b2e
JM
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
adf40b2e 6# (at your option) any later version.
e22f8b7c 7#
adf40b2e
JM
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
e22f8b7c 12#
adf40b2e 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
adf40b2e 15
adf40b2e
JM
16# This file was written by Rob Savoye. (rob@cygnus.com)
17
adf40b2e
JM
18
19# are we on a target board
c1d88655 20if { [is_remote target] || ![isnative] } then {
adf40b2e
JM
21 return
22}
23
adf40b2e
JM
24# Not all of the lines of code near the start of main are executed for
25# every machine. Also, optimization may reorder some of the lines.
26# So all we do is try to step or next over everything until we get
27# to a line that we know is always executed.
28
29proc do_steps_and_nexts {} {
30 global gdb_prompt
31 global srcdir
32
33 gdb_reinitialize_dir $srcdir/..
34
2fa63963 35 set unlikely_line 0
48fe539f 36 for {set count 0} {$count < 32} {incr count} {
ee73db83
DC
37 # NOTE: carlton/2002-12-11: The "initial brace" and
38 # "current_directory initialization" possibilities happen to
39 # me with GCC 3.1 on i686-pc-linux-gnu when I compile with
40 # optimization.
a127f7b4 41 gdb_test_multiple "list" "list" {
0d06e24b
JM
42 -re ".*context = data.*$gdb_prompt $" {
43 set description "step over context initialization"
44 set command "step"
45 }
46 -re ".*argc = context->argc.*$gdb_prompt $" {
47 set description "step over argc initialization"
48 set command "step"
49 }
50 -re ".*argv = context->argv.*$gdb_prompt $" {
51 set description "step over argv initialization"
52 set command "step"
53 }
54 -re ".*quiet = 0.*$gdb_prompt $" {
55 set description "step over quiet initialization"
56 set command "step"
57 }
58 -re ".*batch = 0.*$gdb_prompt $" {
59 set description "step over batch initialization"
60 set command "step"
61 }
adf40b2e
JM
62 -re ".*symarg = NULL.*$gdb_prompt $" {
63 set description "step over symarg initialization"
64 set command "step"
65 }
66 -re ".*execarg = NULL.*$gdb_prompt $" {
67 set description "step over execarg initialization"
68 set command "step"
69 }
5def8285
MK
70 -re ".*pidarg = NULL.*$gdb_prompt $" {
71 set description "step over pidarg initialization"
72 set command "step"
73 }
adf40b2e
JM
74 -re ".*corearg = NULL.*$gdb_prompt $" {
75 set description "step over corearg initialization"
76 set command "step"
77 }
5def8285
MK
78 -re ".*pid_or_core_arg = NULL.*$gdb_prompt $" {
79 set description "step over pid_or_core_arg initialization"
80 set command "step"
81 }
adf40b2e
JM
82 -re ".*cdarg = NULL.*$gdb_prompt $" {
83 set description "step over cdarg initialization"
84 set command "step"
85 }
86 -re ".*ttyarg = NULL.*$gdb_prompt $" {
87 set description "step over ttyarg initialization"
88 set command "step"
89 }
8320cc4f
JK
90 -re ".*cmdarg_vec = NULL.*$gdb_prompt $" {
91 set description "step over cmdarg_vec initialization"
92 set command "step"
93 }
0f3bb72e
PH
94 -re ".*pre_stat_chain = make_command_stats_cleanup.*$gdb_prompt $" {
95 set description "next over make_command_stats_cleanup and everything it calls"
adf40b2e
JM
96 set command "next"
97 }
98 -re ".*START_PROGRESS.*$gdb_prompt $" {
9d62932d
EZ
99 # Note: ezannoni/2004/02/17: This check should be
100 # removed, since as of today that source line is not
101 # in gdb anymore.
adf40b2e
JM
102 set description "next over START_PROGRESS and everything it calls"
103 set command "next"
104 }
105 -re ".*mac_init.*$gdb_prompt $" {
106 set description "next over mac_init and everything it calls"
107 set command "next"
108 }
c3297504
MC
109 -re ".*init_malloc.*$gdb_prompt $" {
110 # gdb 6.2.X is the last gdb which called init_malloc
111 set description "next over init_malloc and everything it calls"
112 set command "next"
113 }
6dd77b81
RH
114 -re ".*lim_at_start.*$gdb_prompt $" {
115 set description "next over lim_at_start initialization"
116 set command "next"
117 }
adf40b2e
JM
118 -re ".*count . 0x3.*$gdb_prompt $" {
119 set description "next over conditional stack alignment code 1"
120 set command "next"
121 }
122 -re ".*if .i != 0.*$gdb_prompt $" {
123 set description "next over conditional stack alignment code 2"
124 set command "next"
125 }
126 -re ".*alloca .i - 4.*$gdb_prompt $" {
127 set description "next over conditional stack alignment alloca"
128 set command "next"
129 }
adf40b2e
JM
130 -re ".*dirsize = 1.*$gdb_prompt $" {
131 set description "next over dirsize initialization"
132 set command "next"
133 }
134 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
135 return
136 }
8cf8c2b8
AC
137 -re ".*setlocale .LC_MESSAGES,.*$gdb_prompt $" {
138 set description "next over setlocale LC_MESSAGES"
139 set command "next"
140 }
141 -re ".*setlocale .LC_CTYPE,.*$gdb_prompt $" {
142 set description "next over setlocale LC_CTYPE"
143 set command "next"
144 }
145 -re ".*bindtextdomain .PACKAGE, LOCALEDIR.;.*$gdb_prompt $" {
146 set description "next over bindtextdomain"
147 set command "next"
148 }
149 -re ".*textdomain .PACKAGE.;.*$gdb_prompt $" {
150 set description "next over textdomain PACKAGE"
151 set command "next"
152 }
ea3aedcb
TT
153 -re ".*bfd_init ..;.*$gdb_prompt $" {
154 set description "next over bfd_init"
155 set command "next"
156 }
8320cc4f
JK
157 -re ".*VEC_cleanup .cmdarg_s.*$gdb_prompt $" {
158 set description "next over cmdarg_s VEC_cleanup"
159 set command "next"
160 }
b6db2c47 161 -re "\[0-9\]+\[\t \]+\{\r\n$gdb_prompt $" {
ee73db83
DC
162 set description "step over initial brace"
163 set command "step"
164 }
165 -re ".*current_directory = gdb_dirbuf.*$gdb_prompt $" {
166 set description "step over current_directory initialization"
167 set command "step"
168 }
a1769aca
DC
169 -re ".*gdb_sysroot = .*$gdb_prompt $" {
170 # NOTE: carlton/2003-01-15: More optimization reordering,
171 # observed on GCC 3.1.
172 set description "step over gdb_sysroot initialization"
173 set command "step"
174 }
180dea7c
AS
175 -re ".*ndir = 0.*$gdb_prompt $" {
176 set description "step over ndir initialization"
177 set command "step"
178 }
179 -re ".*instream = stdin.*$gdb_prompt $" {
180 set description "step over instream initialization"
181 set command "step"
182 }
96e25403 183 -re ".*getcwd .gdb_dirbuf, sizeof .gdb_dirbuf.*$gdb_prompt $" {
180dea7c
AS
184 set description "next over getcwd"
185 set command "next"
186 }
96e25403
YQ
187 -re ".*gdb_program_name = xstrdup.*$gdb_prompt $" {
188 set description "next over xstrdup"
189 set command "next"
190 }
191 -re ".*quit_flag = 0.*$gdb_prompt $" {
6d9c3a87
AS
192 set description "step over quit_flag initialization"
193 set command "step"
194 }
195 -re ".*gdb_stdout = stdio_fileopen .stdout.;.*$gdb_prompt $" {
196 set description "step over gdb_stdout initialization"
197 set command "step"
198 }
199 -re ".*gdb_stderr = stdio_fileopen .stderr.;.*$gdb_prompt $" {
200 set description "step over gdb_stderr initialization"
201 set command "step"
202 }
adf40b2e
JM
203 -re ".*main.c.*No such file or directory.*$gdb_prompt $" {
204 setup_xfail "rs6000-*-aix3*"
205 fail "must be able to list source lines"
206 return
207 }
2fa63963
DJ
208 -re ".*interpreter_p = xstrdup.*$gdb_prompt $" {
209 if { $unlikely_line == 0 } {
210 # This is a GCC optimization bug; a constant has been
211 # associated with the wrong line number.
212 setup_xfail "*-*-*" gcc/26475
213 fail "$description (unlikely line from gcc)"
214 set unlikely_line 1
215 }
216 set description "next over xstrdup"
217 set command "next"
218 }
adf40b2e
JM
219 -re ".*$gdb_prompt $" {
220 fail "unknown source line after $description"
221 return
222 }
223 default {
224 fail "unknown source line near main"
225 return
226 }
227 }
a127f7b4 228 gdb_test_multiple "$command" "$description" {
adf40b2e
JM
229 -re ".*No such file or directory.\r\n$gdb_prompt $" {
230 fail "$description (no source available)"
231 }
232 -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" {
233 fail "$description (no source available)"
234 }
235 -re ".*$gdb_prompt $" {
236 pass "$description"
237 }
adf40b2e
JM
238 }
239 }
240}
241
242proc test_with_self { executable } {
243 global gdb_prompt
244 global tool
245 global det_file
246 global decimal
247 global timeout
b4ca5ed9 248 global INTERNAL_GDBFLAGS
adf40b2e
JM
249
250 # load yourself into the debugger
251 # This can take a relatively long time, particularly for testing where
252 # the executable is being accessed over a network, or where gdb does not
253 # support partial symbols for a particular target and has to load the
254 # entire symbol table. Set the timeout to 10 minutes, which should be
255 # adequate for most environments (it *has* timed out with 5 min on a
256 # SPARCstation SLC under moderate load, so this isn't unreasonable).
257 # After gdb is started, set the timeout to 30 seconds for the duration
258 # of this test, and then back to the original value.
259
260 set oldtimeout $timeout
261 set timeout 600
262 verbose "Timeout is now $timeout seconds" 2
3e3ffd2b 263
2db8e78e
MC
264 global gdb_file_cmd_debug_info
265 set gdb_file_cmd_debug_info "unset"
266
3e3ffd2b 267 set result [gdb_load $executable]
adf40b2e
JM
268 set timeout $oldtimeout
269 verbose "Timeout is now $timeout seconds" 2
270
2db8e78e
MC
271 if { $result != 0 } then {
272 return -1
273 }
274
275 if { $gdb_file_cmd_debug_info != "debug" } then {
276 untested "No debug information, skipping testcase."
3e3ffd2b
MC
277 return -1
278 }
279
adf40b2e
JM
280 # disassemble yourself
281 gdb_test "x/10i main" \
282 "x/10i.*main.*main.$decimal.*main.$decimal.*" \
283 "Disassemble main"
284
285 # Set a breakpoint at main
0d06e24b 286 gdb_test "break captured_main" \
adf40b2e 287 "Breakpoint.*at.* file.*, line.*" \
0d06e24b 288 "breakpoint in captured_main"
adf40b2e
JM
289
290 # We'll need this when we send a ^C to GDB. Need to do it before we
291 # run the program and gdb starts saving and restoring tty states.
292 # On Ultrix, we don't need it and it is really slow (because shell_escape
293 # doesn't use vfork).
294 if ![istarget "*-*-ultrix*"] then {
f6978de9 295 gdb_test "shell stty intr '^C'" ".*" \
adf40b2e
JM
296 "set interrupt character in test_with_self"
297 }
298
299 # FIXME: If we put this after the run to main, the first list
300 # command doesn't print the same line as the current line where
301 # gdb is stopped.
019ebafc 302 gdb_test_no_output "set listsize 1" "set listsize to 1"
adf40b2e
JM
303
304 # run yourself
305 # It may take a very long time for the inferior gdb to start (lynx),
306 # so we bump it back up for the duration of this command.
307 set timeout 600
308
0d06e24b 309 set description "run until breakpoint at captured_main"
b4ca5ed9 310 gdb_test_multiple "run $INTERNAL_GDBFLAGS" "$description" {
0d06e24b 311 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
adf40b2e
JM
312 pass "$description"
313 }
0d06e24b 314 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
adf40b2e
JM
315 xfail "$description (line numbers scrambled?)"
316 }
317 -re "vfork: No more processes.*$gdb_prompt $" {
318 fail "$description (out of virtual memory)"
319 set timeout $oldtimeout
320 verbose "Timeout is now $timeout seconds" 2
321 return -1
322 }
323 -re ".*$gdb_prompt $" {
324 fail "$description"
325 set timeout $oldtimeout
326 verbose "Timeout is now $timeout seconds" 2
327 return -1
328 }
adf40b2e
JM
329 }
330
331 set timeout $oldtimeout
332 verbose "Timeout is now $timeout seconds" 2
333
334 # do we have a version number ?
a127f7b4 335 gdb_test_multiple "print version" "printed version" {
d4f3574e
SS
336 -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
337 pass "printed version as string"
338 }
adf40b2e 339 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
d4f3574e 340 pass "printed version as pointer"
adf40b2e
JM
341 }
342 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
343 pass "printed version with cast"
344 }
adf40b2e
JM
345 }
346
347 do_steps_and_nexts
348
349 gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string"
350
351 # do_steps_and_nexts left us ready to execute an xmalloc call,
352 # so give that a try.
353 # If we don't actually enter the xmalloc call when we give a
354 # step command that seems like a genuine bug. It seems to happen
355 # on most RISC processors.
48fe539f
DJ
356 # NOTE drow/2003-06-22: However, if we step back to the preceding two
357 # lines, just keep stepping until we enter.
358 set stepped_back 0
adf40b2e
JM
359 setup_xfail "alpha-*-*" "mips-*-*"
360 set description "step into xmalloc call"
a127f7b4 361 gdb_test_multiple "step" "$description" {
48fe539f
DJ
362 -re "ncmd = 0;.*$gdb_prompt $" {
363 set stepped_back 1
364 send_gdb "step\n"
365 exp_continue
366 }
274bcba0
EZ
367 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
368 set stepped_back 1
369 send_gdb "step\n"
370 exp_continue
371 }
48fe539f
DJ
372 -re "dirsize = 1;.*$gdb_prompt $" {
373 set stepped_back 1
374 send_gdb "step\n"
375 exp_continue
376 }
377 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
378 if { $stepped_back == 1 } {
379 send_gdb "step\n"
380 exp_continue
381 } else {
382 fail "$description"
383 }
384 }
adf40b2e
JM
385 -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" {
386 pass "$description"
387 }
388 -re ".*No such file or directory.\r\n$gdb_prompt $" {
389 pass "$description (no source available)"
390 }
391 -re "A file or directory .* does not exist..\r\n$gdb_prompt $" {
392 pass "$description (no source available)"
393 }
adf40b2e
JM
394 }
395
396 # start the "xgdb" process
c0b9f2c6
PA
397 if [target_info exists gdb,noinferiorio] {
398 # Maybe testing with a local extended-remote gdbserver. With
399 # no way to interact with inferior GDB, all we can do is let
400 # it run.
401 send_gdb "continue\n"
402 # Wait a bit while the inferior gdb gets to its prompt.
403 sleep 1
404 } else {
405 set test "xgdb is at prompt"
406 gdb_test_multiple "continue" $test {
407 -re "GNU gdb \[0-9\.\]*.*Copyright \\(C\\) \[0-9\]* Free Software Foundation, Inc.*License GPLv3\\+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.*This is free software: you are free to change and redistribute it.*There is NO WARRANTY, to the extent permitted by law. Type \"show copying\".*and \"show warranty\" for details.*This GDB was configured as .*$gdb_prompt $" {
408 pass $test
409 }
a127f7b4 410 }
c0b9f2c6
PA
411
412 # set xgdb prompt so we can tell which is which
413 gdb_test_multiple "set prompt (xgdb) " "Set xgdb_prompt" {
414 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" {
415 pass "Set xgdb prompt"
416 }
a127f7b4 417 }
adf40b2e 418 }
c0b9f2c6 419
adf40b2e
JM
420 # kill the xgdb process
421 set description "send ^C to child process"
422 send_gdb "\003"
423 gdb_expect {
424 -re "Program received signal SIGINT.*$gdb_prompt $" {
425 pass "$description"
426 }
427 -re ".*$gdb_prompt $" {
428 fail "$description"
429 }
430 timeout {
431 fail "$description (timeout)"
432 }
433 }
434
435 set description "send SIGINT signal to child process"
a127f7b4
MS
436 gdb_test "signal SIGINT" \
437 "Continuing with signal SIGINT.*" \
438 "$description"
adf40b2e
JM
439
440 # get a stack trace
441 #
442 # This fails on some linux systems for unknown reasons. On the
443 # systems where it fails, sometimes it works fine when run manually.
444 # The testsuite failures may not be limited to just aout systems.
634d57ec 445 setup_xfail "i*86-pc-linuxaout-gnu"
adf40b2e 446 set description "backtrace through signal handler"
a127f7b4 447 gdb_test_multiple "backtrace" "$description" {
92806416 448 -re "#0.*(read|poll).*in main \\(.*\\) at .*gdb\\.c.*$gdb_prompt $" {
adf40b2e
JM
449 pass "$description"
450 }
451 -re ".*$gdb_prompt $" {
452 # On the alpha, we hit the infamous problem about gdb
453 # being unable to get the frame pointer (mentioned in
454 # gdb/README). As it is intermittent, there is no way to
455 # XFAIL it which will give us an XPASS if the problem goes
456 # away.
457 setup_xfail "alpha*-*-osf*"
458 fail "$description"
459 }
adf40b2e
JM
460 }
461
462
463 # Set the timeout back to the value it had when we were called.
464 set timeout $oldtimeout
465 verbose "Timeout is now $timeout seconds" 2
466
467 # Restart gdb in case next test expects it to be started already.
468 return 0
469}
470
471# Find a pathname to a file that we would execute if the shell was asked
472# to run $arg using the current PATH.
473
474proc find_gdb { arg } {
475
476 # If the arg directly specifies an existing executable file, then
477 # simply use it.
478
479 if [file executable $arg] then {
480 return $arg
481 }
482
483 set result [which $arg]
484 if [string match "/" [ string range $result 0 0 ]] then {
485 return $result
486 }
487
488 # If everything fails, just return the unqualified pathname as default
489 # and hope for best.
490
491 return $arg
492}
493
494# Run the test with self.
495# Copy the file executable file in case this OS doesn't like to edit its own
496# text space.
497
498set GDB_FULLPATH [find_gdb $GDB]
499
500# Remove any old copy lying around.
501remote_file host delete x$tool
502
503gdb_start
504set file [remote_download host $GDB_FULLPATH x$tool]
505set result [test_with_self $file];
506gdb_exit;
507catch "remote_file host delete $file";
508
509if {$result <0} then {
510 warning "Couldn't test self"
511 return -1
512}
This page took 1.244 seconds and 4 git commands to generate.