]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.gdb/selftest.exp
Updated copyright notices for most files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.gdb / selftest.exp
1 # Copyright 1988, 1990, 1991, 1992, 1994, 1997, 1999, 2000, 2002, 2003, 2004,
2 # 2005, 2006, 2007, 2008 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 <http://www.gnu.org/licenses/>.
16
17 # This file was written by Rob Savoye. (rob@cygnus.com)
18
19 if $tracelevel then {
20 strace $tracelevel
21 }
22
23 set prms_id 0
24 set bug_id 0
25
26 # are we on a target board
27 if { [is_remote target] || ![isnative] } then {
28 return
29 }
30
31 # Not all of the lines of code near the start of main are executed for
32 # every machine. Also, optimization may reorder some of the lines.
33 # So all we do is try to step or next over everything until we get
34 # to a line that we know is always executed.
35
36 proc do_steps_and_nexts {} {
37 global gdb_prompt
38 global srcdir
39
40 gdb_reinitialize_dir $srcdir/..
41
42 set unlikely_line 0
43 for {set count 0} {$count < 32} {incr count} {
44 send_gdb "list\n"
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.
49 gdb_expect {
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 }
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 }
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 $" {
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.
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 }
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 }
110 -re ".*lim_at_start.*$gdb_prompt $" {
111 set description "next over lim_at_start initialization"
112 set command "next"
113 }
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 }
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 }
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 }
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 }
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 }
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 }
187 -re ".*quit_flag = 0.*$gdb_prompt $" {
188 set description "step over quit_flag initialization"
189 set command "step"
190 }
191 -re ".*gdb_stdout = stdio_fileopen .stdout.;.*$gdb_prompt $" {
192 set description "step over gdb_stdout initialization"
193 set command "step"
194 }
195 -re ".*gdb_stderr = stdio_fileopen .stderr.;.*$gdb_prompt $" {
196 set description "step over gdb_stderr initialization"
197 set command "step"
198 }
199 -re ".*main.c.*No such file or directory.*$gdb_prompt $" {
200 setup_xfail "rs6000-*-aix3*"
201 fail "must be able to list source lines"
202 return
203 }
204 -re ".*interpreter_p = xstrdup.*$gdb_prompt $" {
205 if { $unlikely_line == 0 } {
206 # This is a GCC optimization bug; a constant has been
207 # associated with the wrong line number.
208 setup_xfail "*-*-*" gcc/26475
209 fail "$description (unlikely line from gcc)"
210 set unlikely_line 1
211 }
212 set description "next over xstrdup"
213 set command "next"
214 }
215 -re ".*$gdb_prompt $" {
216 fail "unknown source line after $description"
217 return
218 }
219 default {
220 fail "unknown source line near main"
221 return
222 }
223 }
224 send_gdb "$command\n"
225 gdb_expect {
226 -re ".*No such file or directory.\r\n$gdb_prompt $" {
227 fail "$description (no source available)"
228 }
229 -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" {
230 fail "$description (no source available)"
231 }
232 -re ".*$gdb_prompt $" {
233 pass "$description"
234 }
235 timeout {
236 fail "$description (timeout)"
237 }
238 }
239 }
240 }
241
242 proc test_with_self { executable } {
243 global gdb_prompt
244 global tool
245 global det_file
246 global decimal
247 global timeout
248
249 # load yourself into the debugger
250 # This can take a relatively long time, particularly for testing where
251 # the executable is being accessed over a network, or where gdb does not
252 # support partial symbols for a particular target and has to load the
253 # entire symbol table. Set the timeout to 10 minutes, which should be
254 # adequate for most environments (it *has* timed out with 5 min on a
255 # SPARCstation SLC under moderate load, so this isn't unreasonable).
256 # After gdb is started, set the timeout to 30 seconds for the duration
257 # of this test, and then back to the original value.
258
259 set oldtimeout $timeout
260 set timeout 600
261 verbose "Timeout is now $timeout seconds" 2
262
263 global gdb_file_cmd_debug_info
264 set gdb_file_cmd_debug_info "unset"
265
266 set result [gdb_load $executable]
267 set timeout $oldtimeout
268 verbose "Timeout is now $timeout seconds" 2
269
270 if { $result != 0 } then {
271 return -1
272 }
273
274 if { $gdb_file_cmd_debug_info != "debug" } then {
275 untested "No debug information, skipping testcase."
276 return -1
277 }
278
279 # disassemble yourself
280 gdb_test "x/10i main" \
281 "x/10i.*main.*main.$decimal.*main.$decimal.*" \
282 "Disassemble main"
283
284 # Set a breakpoint at main
285 gdb_test "break captured_main" \
286 "Breakpoint.*at.* file.*, line.*" \
287 "breakpoint in captured_main"
288
289 # We'll need this when we send a ^C to GDB. Need to do it before we
290 # run the program and gdb starts saving and restoring tty states.
291 # On Ultrix, we don't need it and it is really slow (because shell_escape
292 # doesn't use vfork).
293 if ![istarget "*-*-ultrix*"] then {
294 gdb_test "shell stty intr '^C'" "" \
295 "set interrupt character in test_with_self"
296 }
297
298 # FIXME: If we put this after the run to main, the first list
299 # command doesn't print the same line as the current line where
300 # gdb is stopped.
301 gdb_test "set listsize 1" "" "set listsize to 1"
302
303 # run yourself
304 # It may take a very long time for the inferior gdb to start (lynx),
305 # so we bump it back up for the duration of this command.
306 set timeout 600
307
308 set description "run until breakpoint at captured_main"
309 send_gdb "run -nw\n"
310 gdb_expect {
311 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
312 pass "$description"
313 }
314 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
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 }
329 timeout {
330 fail "$description (timeout)"
331 }
332 }
333
334 set timeout $oldtimeout
335 verbose "Timeout is now $timeout seconds" 2
336
337 # do we have a version number ?
338 send_gdb "print version\n"
339 gdb_expect {
340 -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
341 pass "printed version as string"
342 }
343 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
344 pass "printed version as pointer"
345 }
346 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
347 pass "printed version with cast"
348 }
349 -re ".*$gdb_prompt $" { fail "printed version" }
350 timeout { fail "(timeout) printed version" }
351 }
352
353 do_steps_and_nexts
354
355 gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string"
356
357 # do_steps_and_nexts left us ready to execute an xmalloc call,
358 # so give that a try.
359 # If we don't actually enter the xmalloc call when we give a
360 # step command that seems like a genuine bug. It seems to happen
361 # on most RISC processors.
362 # NOTE drow/2003-06-22: However, if we step back to the preceding two
363 # lines, just keep stepping until we enter.
364 set stepped_back 0
365 setup_xfail "alpha-*-*" "mips-*-*"
366 set description "step into xmalloc call"
367 send_gdb "step\n"
368 gdb_expect {
369 -re "ncmd = 0;.*$gdb_prompt $" {
370 set stepped_back 1
371 send_gdb "step\n"
372 exp_continue
373 }
374 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
375 set stepped_back 1
376 send_gdb "step\n"
377 exp_continue
378 }
379 -re "dirsize = 1;.*$gdb_prompt $" {
380 set stepped_back 1
381 send_gdb "step\n"
382 exp_continue
383 }
384 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
385 if { $stepped_back == 1 } {
386 send_gdb "step\n"
387 exp_continue
388 } else {
389 fail "$description"
390 }
391 }
392 -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" {
393 pass "$description"
394 }
395 -re ".*No such file or directory.\r\n$gdb_prompt $" {
396 pass "$description (no source available)"
397 }
398 -re "A file or directory .* does not exist..\r\n$gdb_prompt $" {
399 pass "$description (no source available)"
400 }
401 -re ".*$gdb_prompt $" {
402 fail "$description"
403 }
404 timeout {
405 fail "$description (timeout)"
406 }
407 }
408
409 # start the "xgdb" process
410 send_gdb "continue\n"
411 gdb_expect {
412 -re "GNU gdb \[0-9\.\]*.*
413 Copyright \\(C\\) \[0-9\]* Free Software Foundation, Inc.*
414 License GPLv3\\+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.*
415 This is free software: you are free to change and redistribute it.*
416 There is NO WARRANTY, to the extent permitted by law. Type \"show copying\".*
417 and \"show warranty\" for details.*
418 This GDB was configured as .*$gdb_prompt $"\
419 { pass "xgdb is at prompt" }
420 -re "GNU gdb \[0-9\.\]*.*
421 Copyright \\(C\\) \[0-9\]* Free Software Foundation, Inc.*
422 GDB is free software, covered by the GNU General Public License, and you are.*
423 welcome to change it and/or distribute copies of it under certain conditions.*
424 Type \"show copying\" to see the conditions.*
425 There is absolutely no warranty for GDB. Type \"show warranty\" for details.*
426 This GDB was configured as .*$gdb_prompt $"\
427 { pass "xgdb is at prompt (obsolescent gdb 2)" }
428 -re "GDB is free software and you are welcome to distribute copies of it.*
429 under certain conditions; type \"show copying\" to see the conditions..*
430 There is absolutely no warranty for GDB; type \"show warranty\" for details..*
431 GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$gdb_prompt $"\
432 { pass "xgdb is at prompt (obsolescent gdb 1)" }
433 -re ".*$gdb_prompt $" { fail "xgdb is at prompt" }
434 timeout { fail "(timeout) xgdb is at prompt" }
435 }
436
437 # set xgdb prompt so we can tell which is which
438 send_gdb "set prompt (xgdb) \n"
439 gdb_expect {
440 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
441 -re ".*$gdb_prompt $" { fail "Set xgdb prompt" }
442 default { fail "(timeout) Set xgdb prompt" }
443 }
444
445 # kill the xgdb process
446 set description "send ^C to child process"
447 send_gdb "\003"
448 gdb_expect {
449 -re "Program received signal SIGINT.*$gdb_prompt $" {
450 pass "$description"
451 }
452 -re ".*$gdb_prompt $" {
453 fail "$description"
454 }
455 timeout {
456 fail "$description (timeout)"
457 }
458 }
459
460 set description "send SIGINT signal to child process"
461 send_gdb "signal SIGINT\n"
462 gdb_expect {
463 -re "Continuing with signal SIGINT.*$gdb_prompt $" {
464 pass "$description"
465 }
466 -re ".*$gdb_prompt $" {
467 fail "$description"
468 }
469 timeout {
470 fail "$description (timeout)"
471 }
472 }
473
474 # get a stack trace
475 #
476 # This fails on some linux systems for unknown reasons. On the
477 # systems where it fails, sometimes it works fine when run manually.
478 # The testsuite failures may not be limited to just aout systems.
479 setup_xfail "i*86-pc-linuxaout-gnu"
480 set description "backtrace through signal handler"
481 send_gdb "backtrace\n"
482 gdb_expect {
483 -re "#0.*(read|poll).*in main \\(.*\\) at .*gdb\\.c.*$gdb_prompt $" {
484 pass "$description"
485 }
486 -re ".*$gdb_prompt $" {
487 # On the alpha, we hit the infamous problem about gdb
488 # being unable to get the frame pointer (mentioned in
489 # gdb/README). As it is intermittent, there is no way to
490 # XFAIL it which will give us an XPASS if the problem goes
491 # away.
492 setup_xfail "alpha*-*-osf*"
493 fail "$description"
494 }
495 timeout {
496 fail "$description (timeout)"
497 }
498 }
499
500
501 # Set the timeout back to the value it had when we were called.
502 set timeout $oldtimeout
503 verbose "Timeout is now $timeout seconds" 2
504
505 # Restart gdb in case next test expects it to be started already.
506 return 0
507 }
508
509 # Find a pathname to a file that we would execute if the shell was asked
510 # to run $arg using the current PATH.
511
512 proc find_gdb { arg } {
513
514 # If the arg directly specifies an existing executable file, then
515 # simply use it.
516
517 if [file executable $arg] then {
518 return $arg
519 }
520
521 set result [which $arg]
522 if [string match "/" [ string range $result 0 0 ]] then {
523 return $result
524 }
525
526 # If everything fails, just return the unqualified pathname as default
527 # and hope for best.
528
529 return $arg
530 }
531
532 # Run the test with self.
533 # Copy the file executable file in case this OS doesn't like to edit its own
534 # text space.
535
536 set GDB_FULLPATH [find_gdb $GDB]
537
538 # Remove any old copy lying around.
539 remote_file host delete x$tool
540
541 gdb_start
542 set file [remote_download host $GDB_FULLPATH x$tool]
543 set result [test_with_self $file];
544 gdb_exit;
545 catch "remote_file host delete $file";
546
547 if {$result <0} then {
548 warning "Couldn't test self"
549 return -1
550 }