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