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