* elf.c (assign_file_positions_except_relocs): Assign relocs
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.gdb / selftest.exp
CommitLineData
c3297504
MC
1# Copyright 1988, 1990, 1991, 1992, 1994, 1997, 1999, 2000, 2002,
2# 2003, 2004 Free Software Foundation, Inc.
adf40b2e
JM
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 2 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, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
adf40b2e
JM
18# This file was written by Rob Savoye. (rob@cygnus.com)
19
20if $tracelevel then {
21 strace $tracelevel
22}
23
24set prms_id 0
25set bug_id 0
26
27# are we on a target board
28if [is_remote target] {
29 return
30}
31
adf40b2e
JM
32# Not all of the lines of code near the start of main are executed for
33# every machine. Also, optimization may reorder some of the lines.
34# So all we do is try to step or next over everything until we get
35# to a line that we know is always executed.
36
37proc do_steps_and_nexts {} {
38 global gdb_prompt
39 global srcdir
40
41 gdb_reinitialize_dir $srcdir/..
42
48fe539f 43 for {set count 0} {$count < 32} {incr count} {
adf40b2e 44 send_gdb "list\n"
ee73db83
DC
45 # NOTE: carlton/2002-12-11: The "initial brace" and
46 # "current_directory initialization" possibilities happen to
47 # me with GCC 3.1 on i686-pc-linux-gnu when I compile with
48 # optimization.
adf40b2e 49 gdb_expect {
0d06e24b
JM
50 -re ".*context = data.*$gdb_prompt $" {
51 set description "step over context initialization"
52 set command "step"
53 }
54 -re ".*argc = context->argc.*$gdb_prompt $" {
55 set description "step over argc initialization"
56 set command "step"
57 }
58 -re ".*argv = context->argv.*$gdb_prompt $" {
59 set description "step over argv initialization"
60 set command "step"
61 }
62 -re ".*quiet = 0.*$gdb_prompt $" {
63 set description "step over quiet initialization"
64 set command "step"
65 }
66 -re ".*batch = 0.*$gdb_prompt $" {
67 set description "step over batch initialization"
68 set command "step"
69 }
adf40b2e
JM
70 -re ".*symarg = NULL.*$gdb_prompt $" {
71 set description "step over symarg initialization"
72 set command "step"
73 }
74 -re ".*execarg = NULL.*$gdb_prompt $" {
75 set description "step over execarg initialization"
76 set command "step"
77 }
78 -re ".*corearg = NULL.*$gdb_prompt $" {
79 set description "step over corearg initialization"
80 set command "step"
81 }
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 }
adf40b2e
JM
90 -re ".*time_at_startup = get_run_time.*$gdb_prompt $" {
91 set description "next over get_run_time and everything it calls"
92 set command "next"
93 }
94 -re ".*START_PROGRESS.*$gdb_prompt $" {
9d62932d
EZ
95 # Note: ezannoni/2004/02/17: This check should be
96 # removed, since as of today that source line is not
97 # in gdb anymore.
adf40b2e
JM
98 set description "next over START_PROGRESS and everything it calls"
99 set command "next"
100 }
101 -re ".*mac_init.*$gdb_prompt $" {
102 set description "next over mac_init and everything it calls"
103 set command "next"
104 }
c3297504
MC
105 -re ".*init_malloc.*$gdb_prompt $" {
106 # gdb 6.2.X is the last gdb which called init_malloc
107 set description "next over init_malloc and everything it calls"
108 set command "next"
109 }
6dd77b81
RH
110 -re ".*lim_at_start.*$gdb_prompt $" {
111 set description "next over lim_at_start initialization"
112 set command "next"
113 }
adf40b2e
JM
114 -re ".*count . 0x3.*$gdb_prompt $" {
115 set description "next over conditional stack alignment code 1"
116 set command "next"
117 }
118 -re ".*if .i != 0.*$gdb_prompt $" {
119 set description "next over conditional stack alignment code 2"
120 set command "next"
121 }
122 -re ".*alloca .i - 4.*$gdb_prompt $" {
123 set description "next over conditional stack alignment alloca"
124 set command "next"
125 }
adf40b2e
JM
126 -re ".*cmdsize = 1.*$gdb_prompt $" {
127 set description "step over cmdsize initialization"
128 set command "next"
129 }
130 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
131 set description "next over cmdarg initialization via xmalloc"
132 set command "next"
133 }
134 -re ".*ncmd = 0.*$gdb_prompt $" {
135 set description "next over ncmd initialization"
136 set command "next"
137 }
138 -re ".*dirsize = 1.*$gdb_prompt $" {
139 set description "next over dirsize initialization"
140 set command "next"
141 }
142 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
143 return
144 }
8cf8c2b8
AC
145 -re ".*setlocale .LC_MESSAGES,.*$gdb_prompt $" {
146 set description "next over setlocale LC_MESSAGES"
147 set command "next"
148 }
149 -re ".*setlocale .LC_CTYPE,.*$gdb_prompt $" {
150 set description "next over setlocale LC_CTYPE"
151 set command "next"
152 }
153 -re ".*bindtextdomain .PACKAGE, LOCALEDIR.;.*$gdb_prompt $" {
154 set description "next over bindtextdomain"
155 set command "next"
156 }
157 -re ".*textdomain .PACKAGE.;.*$gdb_prompt $" {
158 set description "next over textdomain PACKAGE"
159 set command "next"
160 }
ee73db83
DC
161 -re "\[0-9\]*\t\{\r\n$gdb_prompt $" {
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 }
183 -re ".*getcwd .gdb_dirbuf, sizeof .gdb_dirbuf..;.*$gdb_prompt $" {
184 set description "next over getcwd"
185 set command "next"
186 }
adf40b2e
JM
187 -re "\[ \t\]+\{\r\n$gdb_prompt $" {
188 setup_xfail "mips-*-irix5*"
189 fail "$description ended up at odd location"
190 }
191 -re ".*main.c.*No such file or directory.*$gdb_prompt $" {
192 setup_xfail "rs6000-*-aix3*"
193 fail "must be able to list source lines"
194 return
195 }
196 -re ".*$gdb_prompt $" {
197 fail "unknown source line after $description"
198 return
199 }
200 default {
201 fail "unknown source line near main"
202 return
203 }
204 }
205 send_gdb "$command\n"
206 gdb_expect {
207 -re ".*No such file or directory.\r\n$gdb_prompt $" {
208 fail "$description (no source available)"
209 }
210 -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" {
211 fail "$description (no source available)"
212 }
213 -re ".*$gdb_prompt $" {
214 pass "$description"
215 }
216 timeout {
217 fail "$description (timeout)"
218 }
219 }
220 }
221}
222
223proc test_with_self { executable } {
224 global gdb_prompt
225 global tool
226 global det_file
227 global decimal
228 global timeout
229
230 # load yourself into the debugger
231 # This can take a relatively long time, particularly for testing where
232 # the executable is being accessed over a network, or where gdb does not
233 # support partial symbols for a particular target and has to load the
234 # entire symbol table. Set the timeout to 10 minutes, which should be
235 # adequate for most environments (it *has* timed out with 5 min on a
236 # SPARCstation SLC under moderate load, so this isn't unreasonable).
237 # After gdb is started, set the timeout to 30 seconds for the duration
238 # of this test, and then back to the original value.
239
240 set oldtimeout $timeout
241 set timeout 600
242 verbose "Timeout is now $timeout seconds" 2
3e3ffd2b
MC
243
244 set result [gdb_load $executable]
adf40b2e
JM
245 set timeout $oldtimeout
246 verbose "Timeout is now $timeout seconds" 2
247
3e3ffd2b
MC
248 if { [lindex $result 0] != "" } then {
249 return -1
3bdcad15
MI
250 } else {
251 if { [lsearch -exact [lrange $result 1 end] "nodebug"] >= 0 } then {
252 untested "No debug information, skipping testcase."
253 return -1
254 }
3e3ffd2b
MC
255 }
256
adf40b2e
JM
257 # disassemble yourself
258 gdb_test "x/10i main" \
259 "x/10i.*main.*main.$decimal.*main.$decimal.*" \
260 "Disassemble main"
261
262 # Set a breakpoint at main
0d06e24b 263 gdb_test "break captured_main" \
adf40b2e 264 "Breakpoint.*at.* file.*, line.*" \
0d06e24b 265 "breakpoint in captured_main"
adf40b2e
JM
266
267 # We'll need this when we send a ^C to GDB. Need to do it before we
268 # run the program and gdb starts saving and restoring tty states.
269 # On Ultrix, we don't need it and it is really slow (because shell_escape
270 # doesn't use vfork).
271 if ![istarget "*-*-ultrix*"] then {
272 gdb_test "shell stty intr '^C'" "" \
273 "set interrupt character in test_with_self"
274 }
275
276 # FIXME: If we put this after the run to main, the first list
277 # command doesn't print the same line as the current line where
278 # gdb is stopped.
279 gdb_test "set listsize 1" "" "set listsize to 1"
280
281 # run yourself
282 # It may take a very long time for the inferior gdb to start (lynx),
283 # so we bump it back up for the duration of this command.
284 set timeout 600
285
0d06e24b 286 set description "run until breakpoint at captured_main"
adf40b2e
JM
287 send_gdb "run -nw\n"
288 gdb_expect {
0d06e24b 289 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
adf40b2e
JM
290 pass "$description"
291 }
0d06e24b 292 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
adf40b2e
JM
293 xfail "$description (line numbers scrambled?)"
294 }
295 -re "vfork: No more processes.*$gdb_prompt $" {
296 fail "$description (out of virtual memory)"
297 set timeout $oldtimeout
298 verbose "Timeout is now $timeout seconds" 2
299 return -1
300 }
301 -re ".*$gdb_prompt $" {
302 fail "$description"
303 set timeout $oldtimeout
304 verbose "Timeout is now $timeout seconds" 2
305 return -1
306 }
307 timeout {
308 fail "$description (timeout)"
309 }
310 }
311
312 set timeout $oldtimeout
313 verbose "Timeout is now $timeout seconds" 2
314
315 # do we have a version number ?
316 send_gdb "print version\n"
317 gdb_expect {
d4f3574e
SS
318 -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
319 pass "printed version as string"
320 }
adf40b2e 321 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
d4f3574e 322 pass "printed version as pointer"
adf40b2e
JM
323 }
324 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
325 pass "printed version with cast"
326 }
327 -re ".*$gdb_prompt $" { fail "printed version" }
328 timeout { fail "(timeout) printed version" }
329 }
330
331 do_steps_and_nexts
332
333 gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string"
334
335 # do_steps_and_nexts left us ready to execute an xmalloc call,
336 # so give that a try.
337 # If we don't actually enter the xmalloc call when we give a
338 # step command that seems like a genuine bug. It seems to happen
339 # on most RISC processors.
48fe539f
DJ
340 # NOTE drow/2003-06-22: However, if we step back to the preceding two
341 # lines, just keep stepping until we enter.
342 set stepped_back 0
adf40b2e
JM
343 setup_xfail "alpha-*-*" "mips-*-*"
344 set description "step into xmalloc call"
345 send_gdb "step\n"
346 gdb_expect {
48fe539f
DJ
347 -re "ncmd = 0;.*$gdb_prompt $" {
348 set stepped_back 1
349 send_gdb "step\n"
350 exp_continue
351 }
274bcba0
EZ
352 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
353 set stepped_back 1
354 send_gdb "step\n"
355 exp_continue
356 }
48fe539f
DJ
357 -re "dirsize = 1;.*$gdb_prompt $" {
358 set stepped_back 1
359 send_gdb "step\n"
360 exp_continue
361 }
362 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
363 if { $stepped_back == 1 } {
364 send_gdb "step\n"
365 exp_continue
366 } else {
367 fail "$description"
368 }
369 }
adf40b2e
JM
370 -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" {
371 pass "$description"
372 }
373 -re ".*No such file or directory.\r\n$gdb_prompt $" {
374 pass "$description (no source available)"
375 }
376 -re "A file or directory .* does not exist..\r\n$gdb_prompt $" {
377 pass "$description (no source available)"
378 }
379 -re ".*$gdb_prompt $" {
380 fail "$description"
381 }
382 timeout {
383 fail "$description (timeout)"
384 }
385 }
386
387 # start the "xgdb" process
388 send_gdb "continue\n"
389 gdb_expect {
390 -re "GNU gdb \[0-9\.\]*.*
391Copyright \[0-9\]* Free Software Foundation, Inc.*
392GDB is free software, covered by the GNU General Public License, and you are.*
393welcome to change it and/or distribute copies of it under certain conditions.*
394Type \"show copying\" to see the conditions.*
395There is absolutely no warranty for GDB. Type \"show warranty\" for details.*
396This GDB was configured as .*$gdb_prompt $"\
397 { pass "xgdb is at prompt" }
398 -re "GDB is free software and you are welcome to distribute copies of it.*
399 under certain conditions; type \"show copying\" to see the conditions..*
400There is absolutely no warranty for GDB; type \"show warranty\" for details..*
401GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$gdb_prompt $"\
402 { pass "xgdb is at prompt (obsolescent gdb)" }
403 -re ".*$gdb_prompt $" { fail "xgdb is at prompt" }
404 timeout { fail "(timeout) xgdb is at prompt" }
405 }
406
407 # set xgdb prompt so we can tell which is which
408 send_gdb "set prompt (xgdb) \n"
409 gdb_expect {
410 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
411 -re ".*$gdb_prompt $" { fail "Set xgdb prompt" }
412 default { fail "(timeout) Set xgdb prompt" }
413 }
414
415 # kill the xgdb process
416 set description "send ^C to child process"
417 send_gdb "\003"
418 gdb_expect {
419 -re "Program received signal SIGINT.*$gdb_prompt $" {
420 pass "$description"
421 }
422 -re ".*$gdb_prompt $" {
423 fail "$description"
424 }
425 timeout {
426 fail "$description (timeout)"
427 }
428 }
429
430 set description "send SIGINT signal to child process"
431 send_gdb "signal SIGINT\n"
432 gdb_expect {
433 -re "Continuing with signal SIGINT.*$gdb_prompt $" {
434 pass "$description"
435 }
436 -re ".*$gdb_prompt $" {
437 fail "$description"
438 }
439 timeout {
440 fail "$description (timeout)"
441 }
442 }
443
444 # get a stack trace
445 #
446 # This fails on some linux systems for unknown reasons. On the
447 # systems where it fails, sometimes it works fine when run manually.
448 # The testsuite failures may not be limited to just aout systems.
634d57ec 449 setup_xfail "i*86-pc-linuxaout-gnu"
adf40b2e
JM
450 set description "backtrace through signal handler"
451 send_gdb "backtrace\n"
452 gdb_expect {
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 }
465 timeout {
466 fail "$description (timeout)"
467 }
468 }
469
470
471 # Set the timeout back to the value it had when we were called.
472 set timeout $oldtimeout
473 verbose "Timeout is now $timeout seconds" 2
474
475 # Restart gdb in case next test expects it to be started already.
476 return 0
477}
478
479# Find a pathname to a file that we would execute if the shell was asked
480# to run $arg using the current PATH.
481
482proc find_gdb { arg } {
483
484 # If the arg directly specifies an existing executable file, then
485 # simply use it.
486
487 if [file executable $arg] then {
488 return $arg
489 }
490
491 set result [which $arg]
492 if [string match "/" [ string range $result 0 0 ]] then {
493 return $result
494 }
495
496 # If everything fails, just return the unqualified pathname as default
497 # and hope for best.
498
499 return $arg
500}
501
502# Run the test with self.
503# Copy the file executable file in case this OS doesn't like to edit its own
504# text space.
505
506set GDB_FULLPATH [find_gdb $GDB]
507
508# Remove any old copy lying around.
509remote_file host delete x$tool
510
511gdb_start
512set file [remote_download host $GDB_FULLPATH x$tool]
513set result [test_with_self $file];
514gdb_exit;
515catch "remote_file host delete $file";
516
517if {$result <0} then {
518 warning "Couldn't test self"
519 return -1
520}
This page took 0.624326 seconds and 4 git commands to generate.