* gdb.gdb/selftest.exp (do_steps_and_nexts): Add more matches.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.gdb / selftest.exp
CommitLineData
6aba47ca
DJ
1# Copyright 1988, 1990, 1991, 1992, 1994, 1997, 1999, 2000, 2002, 2003, 2004,
2# 2005, 2006, 2007 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
c1d88655 28if { [is_remote target] || ![isnative] } then {
adf40b2e
JM
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
2fa63963 43 set unlikely_line 0
48fe539f 44 for {set count 0} {$count < 32} {incr count} {
adf40b2e 45 send_gdb "list\n"
ee73db83
DC
46 # NOTE: carlton/2002-12-11: The "initial brace" and
47 # "current_directory initialization" possibilities happen to
48 # me with GCC 3.1 on i686-pc-linux-gnu when I compile with
49 # optimization.
adf40b2e 50 gdb_expect {
0d06e24b
JM
51 -re ".*context = data.*$gdb_prompt $" {
52 set description "step over context initialization"
53 set command "step"
54 }
55 -re ".*argc = context->argc.*$gdb_prompt $" {
56 set description "step over argc initialization"
57 set command "step"
58 }
59 -re ".*argv = context->argv.*$gdb_prompt $" {
60 set description "step over argv initialization"
61 set command "step"
62 }
63 -re ".*quiet = 0.*$gdb_prompt $" {
64 set description "step over quiet initialization"
65 set command "step"
66 }
67 -re ".*batch = 0.*$gdb_prompt $" {
68 set description "step over batch initialization"
69 set command "step"
70 }
adf40b2e
JM
71 -re ".*symarg = NULL.*$gdb_prompt $" {
72 set description "step over symarg initialization"
73 set command "step"
74 }
75 -re ".*execarg = NULL.*$gdb_prompt $" {
76 set description "step over execarg initialization"
77 set command "step"
78 }
79 -re ".*corearg = NULL.*$gdb_prompt $" {
80 set description "step over corearg initialization"
81 set command "step"
82 }
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 }
adf40b2e
JM
91 -re ".*time_at_startup = get_run_time.*$gdb_prompt $" {
92 set description "next over get_run_time and everything it calls"
93 set command "next"
94 }
95 -re ".*START_PROGRESS.*$gdb_prompt $" {
9d62932d
EZ
96 # Note: ezannoni/2004/02/17: This check should be
97 # removed, since as of today that source line is not
98 # in gdb anymore.
adf40b2e
JM
99 set description "next over START_PROGRESS and everything it calls"
100 set command "next"
101 }
102 -re ".*mac_init.*$gdb_prompt $" {
103 set description "next over mac_init and everything it calls"
104 set command "next"
105 }
c3297504
MC
106 -re ".*init_malloc.*$gdb_prompt $" {
107 # gdb 6.2.X is the last gdb which called init_malloc
108 set description "next over init_malloc and everything it calls"
109 set command "next"
110 }
6dd77b81
RH
111 -re ".*lim_at_start.*$gdb_prompt $" {
112 set description "next over lim_at_start initialization"
113 set command "next"
114 }
adf40b2e
JM
115 -re ".*count . 0x3.*$gdb_prompt $" {
116 set description "next over conditional stack alignment code 1"
117 set command "next"
118 }
119 -re ".*if .i != 0.*$gdb_prompt $" {
120 set description "next over conditional stack alignment code 2"
121 set command "next"
122 }
123 -re ".*alloca .i - 4.*$gdb_prompt $" {
124 set description "next over conditional stack alignment alloca"
125 set command "next"
126 }
adf40b2e
JM
127 -re ".*cmdsize = 1.*$gdb_prompt $" {
128 set description "step over cmdsize initialization"
129 set command "next"
130 }
131 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
132 set description "next over cmdarg initialization via xmalloc"
133 set command "next"
134 }
135 -re ".*ncmd = 0.*$gdb_prompt $" {
136 set description "next over ncmd initialization"
137 set command "next"
138 }
139 -re ".*dirsize = 1.*$gdb_prompt $" {
140 set description "next over dirsize initialization"
141 set command "next"
142 }
143 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
144 return
145 }
8cf8c2b8
AC
146 -re ".*setlocale .LC_MESSAGES,.*$gdb_prompt $" {
147 set description "next over setlocale LC_MESSAGES"
148 set command "next"
149 }
150 -re ".*setlocale .LC_CTYPE,.*$gdb_prompt $" {
151 set description "next over setlocale LC_CTYPE"
152 set command "next"
153 }
154 -re ".*bindtextdomain .PACKAGE, LOCALEDIR.;.*$gdb_prompt $" {
155 set description "next over bindtextdomain"
156 set command "next"
157 }
158 -re ".*textdomain .PACKAGE.;.*$gdb_prompt $" {
159 set description "next over textdomain PACKAGE"
160 set command "next"
161 }
ee73db83
DC
162 -re "\[0-9\]*\t\{\r\n$gdb_prompt $" {
163 set description "step over initial brace"
164 set command "step"
165 }
166 -re ".*current_directory = gdb_dirbuf.*$gdb_prompt $" {
167 set description "step over current_directory initialization"
168 set command "step"
169 }
a1769aca
DC
170 -re ".*gdb_sysroot = .*$gdb_prompt $" {
171 # NOTE: carlton/2003-01-15: More optimization reordering,
172 # observed on GCC 3.1.
173 set description "step over gdb_sysroot initialization"
174 set command "step"
175 }
180dea7c
AS
176 -re ".*ndir = 0.*$gdb_prompt $" {
177 set description "step over ndir initialization"
178 set command "step"
179 }
180 -re ".*instream = stdin.*$gdb_prompt $" {
181 set description "step over instream initialization"
182 set command "step"
183 }
184 -re ".*getcwd .gdb_dirbuf, sizeof .gdb_dirbuf..;.*$gdb_prompt $" {
185 set description "next over getcwd"
186 set command "next"
187 }
6d9c3a87
AS
188 -re ".*quit_flag = 0.*$gdb_prompt $" {
189 set description "step over quit_flag initialization"
190 set command "step"
191 }
192 -re ".*gdb_stdout = stdio_fileopen .stdout.;.*$gdb_prompt $" {
193 set description "step over gdb_stdout initialization"
194 set command "step"
195 }
196 -re ".*gdb_stderr = stdio_fileopen .stderr.;.*$gdb_prompt $" {
197 set description "step over gdb_stderr initialization"
198 set command "step"
199 }
adf40b2e
JM
200 -re "\[ \t\]+\{\r\n$gdb_prompt $" {
201 setup_xfail "mips-*-irix5*"
202 fail "$description ended up at odd location"
203 }
204 -re ".*main.c.*No such file or directory.*$gdb_prompt $" {
205 setup_xfail "rs6000-*-aix3*"
206 fail "must be able to list source lines"
207 return
208 }
2fa63963
DJ
209 -re ".*interpreter_p = xstrdup.*$gdb_prompt $" {
210 if { $unlikely_line == 0 } {
211 # This is a GCC optimization bug; a constant has been
212 # associated with the wrong line number.
213 setup_xfail "*-*-*" gcc/26475
214 fail "$description (unlikely line from gcc)"
215 set unlikely_line 1
216 }
217 set description "next over xstrdup"
218 set command "next"
219 }
adf40b2e
JM
220 -re ".*$gdb_prompt $" {
221 fail "unknown source line after $description"
222 return
223 }
224 default {
225 fail "unknown source line near main"
226 return
227 }
228 }
229 send_gdb "$command\n"
230 gdb_expect {
231 -re ".*No such file or directory.\r\n$gdb_prompt $" {
232 fail "$description (no source available)"
233 }
234 -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" {
235 fail "$description (no source available)"
236 }
237 -re ".*$gdb_prompt $" {
238 pass "$description"
239 }
240 timeout {
241 fail "$description (timeout)"
242 }
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
253
254 # load yourself into the debugger
255 # This can take a relatively long time, particularly for testing where
256 # the executable is being accessed over a network, or where gdb does not
257 # support partial symbols for a particular target and has to load the
258 # entire symbol table. Set the timeout to 10 minutes, which should be
259 # adequate for most environments (it *has* timed out with 5 min on a
260 # SPARCstation SLC under moderate load, so this isn't unreasonable).
261 # After gdb is started, set the timeout to 30 seconds for the duration
262 # of this test, and then back to the original value.
263
264 set oldtimeout $timeout
265 set timeout 600
266 verbose "Timeout is now $timeout seconds" 2
3e3ffd2b 267
2db8e78e
MC
268 global gdb_file_cmd_debug_info
269 set gdb_file_cmd_debug_info "unset"
270
3e3ffd2b 271 set result [gdb_load $executable]
adf40b2e
JM
272 set timeout $oldtimeout
273 verbose "Timeout is now $timeout seconds" 2
274
2db8e78e
MC
275 if { $result != 0 } then {
276 return -1
277 }
278
279 if { $gdb_file_cmd_debug_info != "debug" } then {
280 untested "No debug information, skipping testcase."
3e3ffd2b
MC
281 return -1
282 }
283
adf40b2e
JM
284 # disassemble yourself
285 gdb_test "x/10i main" \
286 "x/10i.*main.*main.$decimal.*main.$decimal.*" \
287 "Disassemble main"
288
289 # Set a breakpoint at main
0d06e24b 290 gdb_test "break captured_main" \
adf40b2e 291 "Breakpoint.*at.* file.*, line.*" \
0d06e24b 292 "breakpoint in captured_main"
adf40b2e
JM
293
294 # We'll need this when we send a ^C to GDB. Need to do it before we
295 # run the program and gdb starts saving and restoring tty states.
296 # On Ultrix, we don't need it and it is really slow (because shell_escape
297 # doesn't use vfork).
298 if ![istarget "*-*-ultrix*"] then {
299 gdb_test "shell stty intr '^C'" "" \
300 "set interrupt character in test_with_self"
301 }
302
303 # FIXME: If we put this after the run to main, the first list
304 # command doesn't print the same line as the current line where
305 # gdb is stopped.
306 gdb_test "set listsize 1" "" "set listsize to 1"
307
308 # run yourself
309 # It may take a very long time for the inferior gdb to start (lynx),
310 # so we bump it back up for the duration of this command.
311 set timeout 600
312
0d06e24b 313 set description "run until breakpoint at captured_main"
adf40b2e
JM
314 send_gdb "run -nw\n"
315 gdb_expect {
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 }
334 timeout {
335 fail "$description (timeout)"
336 }
337 }
338
339 set timeout $oldtimeout
340 verbose "Timeout is now $timeout seconds" 2
341
342 # do we have a version number ?
343 send_gdb "print version\n"
344 gdb_expect {
d4f3574e
SS
345 -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
346 pass "printed version as string"
347 }
adf40b2e 348 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
d4f3574e 349 pass "printed version as pointer"
adf40b2e
JM
350 }
351 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
352 pass "printed version with cast"
353 }
354 -re ".*$gdb_prompt $" { fail "printed version" }
355 timeout { fail "(timeout) printed version" }
356 }
357
358 do_steps_and_nexts
359
360 gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string"
361
362 # do_steps_and_nexts left us ready to execute an xmalloc call,
363 # so give that a try.
364 # If we don't actually enter the xmalloc call when we give a
365 # step command that seems like a genuine bug. It seems to happen
366 # on most RISC processors.
48fe539f
DJ
367 # NOTE drow/2003-06-22: However, if we step back to the preceding two
368 # lines, just keep stepping until we enter.
369 set stepped_back 0
adf40b2e
JM
370 setup_xfail "alpha-*-*" "mips-*-*"
371 set description "step into xmalloc call"
372 send_gdb "step\n"
373 gdb_expect {
48fe539f
DJ
374 -re "ncmd = 0;.*$gdb_prompt $" {
375 set stepped_back 1
376 send_gdb "step\n"
377 exp_continue
378 }
274bcba0
EZ
379 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
380 set stepped_back 1
381 send_gdb "step\n"
382 exp_continue
383 }
48fe539f
DJ
384 -re "dirsize = 1;.*$gdb_prompt $" {
385 set stepped_back 1
386 send_gdb "step\n"
387 exp_continue
388 }
389 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
390 if { $stepped_back == 1 } {
391 send_gdb "step\n"
392 exp_continue
393 } else {
394 fail "$description"
395 }
396 }
adf40b2e
JM
397 -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" {
398 pass "$description"
399 }
400 -re ".*No such file or directory.\r\n$gdb_prompt $" {
401 pass "$description (no source available)"
402 }
403 -re "A file or directory .* does not exist..\r\n$gdb_prompt $" {
404 pass "$description (no source available)"
405 }
406 -re ".*$gdb_prompt $" {
407 fail "$description"
408 }
409 timeout {
410 fail "$description (timeout)"
411 }
412 }
413
414 # start the "xgdb" process
415 send_gdb "continue\n"
416 gdb_expect {
417 -re "GNU gdb \[0-9\.\]*.*
d082a1e2 418Copyright \\(C\\) \[0-9\]* Free Software Foundation, Inc.*
adf40b2e
JM
419GDB is free software, covered by the GNU General Public License, and you are.*
420welcome to change it and/or distribute copies of it under certain conditions.*
421Type \"show copying\" to see the conditions.*
422There is absolutely no warranty for GDB. Type \"show warranty\" for details.*
423This GDB was configured as .*$gdb_prompt $"\
424 { pass "xgdb is at prompt" }
425 -re "GDB is free software and you are welcome to distribute copies of it.*
426 under certain conditions; type \"show copying\" to see the conditions..*
427There is absolutely no warranty for GDB; type \"show warranty\" for details..*
428GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$gdb_prompt $"\
429 { pass "xgdb is at prompt (obsolescent gdb)" }
430 -re ".*$gdb_prompt $" { fail "xgdb is at prompt" }
431 timeout { fail "(timeout) xgdb is at prompt" }
432 }
433
434 # set xgdb prompt so we can tell which is which
435 send_gdb "set prompt (xgdb) \n"
436 gdb_expect {
437 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
438 -re ".*$gdb_prompt $" { fail "Set xgdb prompt" }
439 default { fail "(timeout) Set xgdb prompt" }
440 }
441
442 # kill the xgdb process
443 set description "send ^C to child process"
444 send_gdb "\003"
445 gdb_expect {
446 -re "Program received signal SIGINT.*$gdb_prompt $" {
447 pass "$description"
448 }
449 -re ".*$gdb_prompt $" {
450 fail "$description"
451 }
452 timeout {
453 fail "$description (timeout)"
454 }
455 }
456
457 set description "send SIGINT signal to child process"
458 send_gdb "signal SIGINT\n"
459 gdb_expect {
460 -re "Continuing with signal SIGINT.*$gdb_prompt $" {
461 pass "$description"
462 }
463 -re ".*$gdb_prompt $" {
464 fail "$description"
465 }
466 timeout {
467 fail "$description (timeout)"
468 }
469 }
470
471 # get a stack trace
472 #
473 # This fails on some linux systems for unknown reasons. On the
474 # systems where it fails, sometimes it works fine when run manually.
475 # The testsuite failures may not be limited to just aout systems.
634d57ec 476 setup_xfail "i*86-pc-linuxaout-gnu"
adf40b2e
JM
477 set description "backtrace through signal handler"
478 send_gdb "backtrace\n"
479 gdb_expect {
92806416 480 -re "#0.*(read|poll).*in main \\(.*\\) at .*gdb\\.c.*$gdb_prompt $" {
adf40b2e
JM
481 pass "$description"
482 }
483 -re ".*$gdb_prompt $" {
484 # On the alpha, we hit the infamous problem about gdb
485 # being unable to get the frame pointer (mentioned in
486 # gdb/README). As it is intermittent, there is no way to
487 # XFAIL it which will give us an XPASS if the problem goes
488 # away.
489 setup_xfail "alpha*-*-osf*"
490 fail "$description"
491 }
492 timeout {
493 fail "$description (timeout)"
494 }
495 }
496
497
498 # Set the timeout back to the value it had when we were called.
499 set timeout $oldtimeout
500 verbose "Timeout is now $timeout seconds" 2
501
502 # Restart gdb in case next test expects it to be started already.
503 return 0
504}
505
506# Find a pathname to a file that we would execute if the shell was asked
507# to run $arg using the current PATH.
508
509proc find_gdb { arg } {
510
511 # If the arg directly specifies an existing executable file, then
512 # simply use it.
513
514 if [file executable $arg] then {
515 return $arg
516 }
517
518 set result [which $arg]
519 if [string match "/" [ string range $result 0 0 ]] then {
520 return $result
521 }
522
523 # If everything fails, just return the unqualified pathname as default
524 # and hope for best.
525
526 return $arg
527}
528
529# Run the test with self.
530# Copy the file executable file in case this OS doesn't like to edit its own
531# text space.
532
533set GDB_FULLPATH [find_gdb $GDB]
534
535# Remove any old copy lying around.
536remote_file host delete x$tool
537
538gdb_start
539set file [remote_download host $GDB_FULLPATH x$tool]
540set result [test_with_self $file];
541gdb_exit;
542catch "remote_file host delete $file";
543
544if {$result <0} then {
545 warning "Couldn't test self"
546 return -1
547}
This page took 1.117763 seconds and 4 git commands to generate.