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