* lib/gdb.exp (default_gdb_start): Fix typo.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / a1-selftest.exp
CommitLineData
ef44eed1
SS
1# Copyright (C) 1988, 1990, 1991, 1992, 1994 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
6c9638b4 15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
ef44eed1
SS
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
20# This file was written by Rob Savoye. (rob@cygnus.com)
21
22if $tracelevel then {
23 strace $tracelevel
24 }
25
26set prms_id 0
27set bug_id 0
28
29# are we on a target board
30if ![isnative] then {
782445c7 31 return
ef44eed1 32}
1fb1efcd
JK
33if [istarget "m68k*-*-hpux*"] then {
34 # The top-level makefile passes CFLAGS= (no -g) for hp300. This probably
35 # should be fixed (it is only needed for gcc bootstrapping, not gdb),
36 # but until then.....
37 setup_xfail "*-*-*"
38 fail "cannot test self if compiled without debug info"
782445c7 39 return -1
1fb1efcd 40}
ef44eed1
SS
41
42proc test_with_self {} {
43 global prompt
44 global tool
45 global det_file
ef44eed1
SS
46 global decimal
47
48 # load yourself into the debugger
49 # This can take a relatively long time, particularly for testing where
50 # the executable is being accessed over a network, or where gdb does not
51 # support partial symbols for a particular target and has to load the
52 # entire symbol table. Set the timeout to 10 minutes, which should be
53 # adequate for most environments (it *has* timed out with 5 min on a
54 # SPARCstation SLC under moderate load, so this isn't unreasonable).
f1c9e446 55 # After gdb is started, set the timeout to 30 seconds for the duration
ef44eed1
SS
56 # of this test, and then back to the original value.
57
ef44eed1
SS
58 set timeout 600
59 if {[gdb_load "./x$tool"] <0} then {
60 return -1
61 }
62
ef44eed1
SS
63 # disassemble yourself
64 send "x/10i main\n"
65 expect {
66 -re "x/10i.*main.*main.$decimal.*main.$decimal.*$prompt $"\
67 { pass "Disassemble main" }
68 -re ".*$prompt $" { fail "Disassemble main" }
69 timeout { fail "(timeout) Disassemble main" }
70 }
71
72 set description "set breakpoint at main"
73 send "break main\n"
74 expect {
75 -re "Breakpoint.*at.* file.*, line.*$prompt $" {
76 pass "$description"
77 }
78 -re ".*$prompt $" {
79 fail "$description"
80 }
81 timeout {
82 fail "$description (timeout)"
83 }
84 }
85
ff884d6e
JK
86 # We'll need this when we send a ^C to GDB. Need to do it before we
87 # run the program and gdb starts saving and restoring tty states.
88 # On Ultrix, we don't need it and it is really slow (because shell_escape
89 # doesn't use vfork).
90 if ![istarget "*-*-ultrix*"] then {
91 gdb_test "shell stty intr '^C'" "" \
92 "set interrupt character in test_with_self"
93 }
94
ef44eed1
SS
95 # run yourself
96 set description "run until breakpoint at main"
f526457c 97 send "run -nw\n"
ef44eed1
SS
98 expect {
99 -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.* at .*main.c:.*$prompt $" {
100 pass "$description"
101 }
102 -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.*$prompt $" {
103 xfail "$description (line numbers scrambled?)"
104 }
105 -re "vfork: No more processes.*$prompt $" {
106 fail "$description (out of virtual memory)"
107 return -1
108 }
109 -re ".*$prompt $" {
110 fail "$description"
111 return -1
112 }
113 timeout {
114 fail "$description (timeout)"
115 }
116 }
117
f1c9e446
JL
118 # It may take a very long time for the inferior gdb to start (lynx),
119 # so we wait until after it's started to reset the timeout value.
120 set timeout 30
121
ef44eed1
SS
122 # do we have a version number ?
123 send "print version\n"
124 expect {
125 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$prompt $" {
126 pass "printed version"
127 }
128 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$prompt $" {
129 pass "printed version with cast"
130 }
131 -re ".*$prompt $" { fail "printed version" }
132 timeout { fail "(timeout) printed version" }
133 }
134
135 # lets do a few single steps
136
137 set description "step over symarg initialization"
138 send "step\n"
139 expect {
140 -re "char \[*\]+execarg = NULL;.*$prompt $" {
141 pass "$description"
142 }
143 -re ".*No such file or directory.\r\n$prompt $" {
144 pass "$description (no source available)"
145 }
146 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
147 pass "$description (no source available)"
148 }
149 -re ".*$prompt $" {
150 fail "$description"
151 }
152 timeout {
153 fail "$description (timeout)"
154 }
155 }
156
edc1ccab 157 setup_xfail "alpha-dec-osf2*"
ef44eed1
SS
158 set description "step over execarg initialization"
159 send "step\n"
160 expect {
161 -re "char \[*\]corearg = NULL;.*$prompt $" {
162 pass "$description"
163 }
164 -re ".*No such file or directory.\r\n$prompt $" {
165 pass "$description (no source available)"
166 }
167 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
168 pass "$description (no source available)"
169 }
170 -re ".*$prompt $" {
171 fail "$description"
172 }
173 timeout {
31ce4360 174 fail "$description (timeout)"
ef44eed1
SS
175 }
176 }
177
edc1ccab 178 setup_xfail "alpha-dec-osf2*"
ef44eed1
SS
179 set description "step over corearg initialization"
180 send "step\n"
181 expect {
182 -re "char \[*\]cdarg = NULL;.*$prompt $" {
183 pass "$description"
184 }
185 -re ".*No such file or directory.\r\n$prompt $" {
186 pass "$description (no source available)"
187 }
188 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
189 pass "$description (no source available)"
190 }
191 -re ".*$prompt $" {
192 fail "$description"
193 }
194 timeout {
31ce4360 195 fail "$description (timeout)"
ef44eed1
SS
196 }
197 }
198
89e6c70d 199 set ttyarg_in_delay_slot 0
ef44eed1
SS
200 set description "step over cdarg initialization"
201 send "step\n"
202 expect {
203 -re "char \[*\]ttyarg = NULL;.*$prompt $" {
204 pass "$description"
205 }
89e6c70d
FF
206 -re ".*time_at_startup = get_run_time .*$prompt $" {
207 pass "$description"
208 set ttyarg_in_delay_slot 1
209 }
ef44eed1
SS
210 -re ".*No such file or directory.\r\n$prompt $" {
211 pass "$description (no source available)"
212 }
213 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
214 pass "$description (no source available)"
215 }
216 -re ".*$prompt $" {
217 fail "$description"
218 }
219 timeout {
31ce4360 220 fail "$description (timeout)"
ef44eed1
SS
221 }
222 }
223
224 set description "step over ttyarg initialization"
89e6c70d
FF
225 if $ttyarg_in_delay_slot==1 then {
226 pass "$description (in delay slot)"
227 } else {
228 send "step\n"
229 expect {
230 -re ".*time_at_startup = get_run_time .*$prompt $" {
231 pass "$description"
232 }
233 -re ".*No such file or directory.\r\n$prompt $" {
234 pass "$description (no source available)"
235 }
236 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
237 pass "$description (no source available)"
238 }
239 -re ".*$prompt $" {
240 fail "$description"
241 }
242 timeout {
243 fail "$description (timeout)"
244 }
ef44eed1
SS
245 }
246 }
247
248 # now jump over a few functions
249
3046ecae 250 set description "next over get_run_time and everything it calls"
9b826d6d 251 set got_over_get_run_time 0
ef44eed1
SS
252 send "next\n"
253 expect {
3046ecae 254 -re ".*init_malloc.*$prompt $" {
ef44eed1 255 pass "$description"
9b826d6d
JK
256 set got_over_get_run_time 1
257 }
258 -re ".*No such file or directory.\r\n$prompt $" {
259 pass "$description (no source available)"
260 set got_over_get_run_time 1
261 }
262 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
263 pass "$description (no source available)"
264 set got_over_get_run_time 1
265 }
266 -re ".*$prompt $" {
267 fail "$description"
268 }
269 timeout {
270 fail "$description (timeout)"
271 }
272 }
273 # -re "if \(setmp \(to_top_level\)\).*$prompt $" { pass "first next" }
274
275 if $got_over_get_run_time then {
276 set description "next over init_malloc and everything it calls"
277 send "next\n"
278 expect {
3046ecae
SS
279 -re "if.*SET_TOP_LEVEL.*$prompt $" {
280 pass "$description"
281 }
282 -re "i = .*count.*$prompt $" {
283 pass "$description"
284 set description "next over ALIGN_STACK_ON_STARTUP code"
285 send "next\n"
286 expect {
ef44eed1
SS
287 -re "if.*i != 0.*$prompt $" {
288 pass "$description"
289 send "next\n"
290 expect {
291 -re "if.*SET_TOP_LEVEL.*$prompt $" {
292 pass "$description"
293 }
294 -re "alloca.*$prompt $" {
295 send "next\n"
296 expect {
297 -re "if.*level.*$prompt $" {
298 pass "$description"
299 }
300 }
301 }
302 }
303 }
3046ecae 304 }
9b826d6d
JK
305 }
306 -re ".*No such file or directory.\r\n$prompt $" {
307 pass "$description (no source available)"
308 }
309 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
310 pass "$description (no source available)"
311 }
312 -re ".*$prompt $" {
313 fail "$description"
314 }
315 default {
316 fail "$description (timeout or eof)"
317 }
ef44eed1
SS
318 }
319 }
9b826d6d 320
ef44eed1
SS
321 set next_ok 1
322 set need_to_step_over_cmdsize 1
323 set description "next over SET_TOP_LEVEL call"
324 send "next\n"
325 expect {
326 -re "cmdsize = 1;.*$prompt $" {
327 pass "$description"
328 }
329 -re "cmdarg = .*xmalloc.*$prompt $" {
330 # This can happen in optimized code where the "cmdsize = 1" line
331 # is basically removed.
332 pass "$description"
333 set need_to_step_over_cmdsize 0
334 }
335 -re ".*No such file or directory.\r\n$prompt $" {
336 pass "$description (no source available)"
337 }
338 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
339 pass "$description (no source available)"
340 }
341 -re ".*$prompt $" {
342 fail "$description"
343 set next_ok 0
344 }
345 timeout {
346 fail "$description (timeout)"
347 set next_ok 0
348 }
349 }
350
351 set description "print a string"
352 send "print \"foo\"\n"
353 expect {
354 -re ".\[0-9\]+ = \"foo\".*$prompt $" {
355 pass "$description"
356 }
357 -re ".*$prompt $" {
358 fail "$description"
359 }
360 timeout {
361 fail "$description (timeout)"
362 }
363 }
364
365 if $need_to_step_over_cmdsize {
366 set description "step over cmdsize initialization"
367 send "step\n"
368 expect {
369 -re "cmdarg = .*xmalloc.*$prompt $" {
370 pass "$description"
371 }
372 -re ".*No such file or directory.\r\n$prompt $" {
373 pass "$description (no source available)"
374 }
375 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
376 pass "$description (no source available)"
377 }
378 -re ".*$prompt $" {
379 fail "$description"
380 }
381 timeout {
31ce4360 382 fail "$description (timeout)"
ef44eed1
SS
383 }
384 }
385 }
386
387 # and another step for good luck
ef44eed1
SS
388 if $next_ok {
389 set description "step into xmalloc call"
390 send "step\n"
391 expect {
392 -re "xmalloc.*size=.*at.*utils.c.*$prompt $" {
393 pass "$description"
394 }
395 -re ".*No such file or directory.\r\n$prompt $" {
396 pass "$description (no source available)"
397 }
398 -re "A file or directory .* does not exist..\r\n$prompt $" {
399 pass "$description (no source available)"
400 }
401 -re ".*$prompt $" {
402 fail "$description"
403 }
404 timeout {
405 fail "$description (timeout)"
406 }
407 }
408 }
66b063c0 409
ef44eed1
SS
410 # start the "xgdb" process
411 send "continue\n"
412 expect {
413 -re "GDB is free software and you are welcome to distribute copies of it.*
414 under certain conditions; type \"show copying\" to see the conditions..*
415There is absolutely no warranty for GDB; type \"show warranty\" for details..*
416GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$prompt $"\
417 { pass "xgdb is at prompt" }
418 -re ".*$prompt $" { fail "xgdb is at prompt" }
419 timeout { fail "(timeout) xgdb is at prompt" }
420 }
421
422 # set xgdb prompt so we can tell which is which
423 send "set prompt (xgdb) \n"
424 expect {
425 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
426 -re ".*$prompt $" { fail "Set xgdb prompt" }
427 default { fail "(timeout) Set xgdb prompt" }
428 }
429
430 # kill the xgdb process
431 set description "send ^C to child process"
432 send "\003"
433 expect {
434 -re "Program received signal SIGINT.*$prompt $" {
435 pass "$description"
436 }
437 -re ".*$prompt $" {
438 fail "$description"
439 }
440 timeout {
441 fail "$description (timeout)"
442 }
443 }
444
445 set description "send SIGINT signal to child process"
446 send "signal SIGINT\n"
447 expect {
448 -re "Continuing with signal SIGINT.*$prompt $" {
449 pass "$description"
450 }
451 -re ".*$prompt $" {
452 fail "$description"
453 }
454 timeout {
455 fail "$description (timeout)"
456 }
457 }
458
459 # get a stack trace
782445c7 460 setup_xfail "i*86-*-linuxaout"
ef44eed1
SS
461 set description "backtrace through signal handler"
462 send "backtrace\n"
463 expect {
ac35a003 464 -re "#0.*read.*in main \\(.*\\) at .*main\\.c.*$prompt $" {
ef44eed1
SS
465 pass "$description"
466 }
467 -re ".*$prompt $" {
9b86fdca
JK
468 # On the alpha, we hit the infamous problem about gdb
469 # being unable to get the frame pointer (mentioned in
470 # gdb/README). As it is intermittent, there is no way to
471 # XFAIL it which will give us an XPASS if the problem goes
472 # away.
473 setup_xfail "alpha*-*-osf*"
ef44eed1
SS
474 fail "$description"
475 }
476 timeout {
477 fail "$description (timeout)"
478 }
479 }
4a2170f0
JK
480
481 gdb_exit
ef44eed1
SS
482
483 # Set the timeout back to the value it had when we were called.
ef44eed1
SS
484
485 # Restart gdb in case next test expects it to be started already.
486 gdb_start
487 return 0
488}
489
490# Find a pathname to a file that we would execute if the shell was asked
491# to run $arg using the current PATH.
492
493proc find_gdb { arg } {
494
495 # If the arg directly specifies an existing executable file, then
496 # simply use it.
497
498 if [file executable $arg] then {
499 return $arg
500 }
501
502 set result [which $arg]
503 if [string match "/" [ string range $result 0 0 ]] then {
504 return $result
505 }
506
507 # If everything fails, just return the unqualified pathname as default
508 # and hope for best.
509
510 return $arg
511}
512
513# Run the test with self.
514# Copy the file executable file in case this OS doesn't like to edit it's own
515# text space.
516
517set GDB_FULLPATH [find_gdb $GDB]
518
519# Remove any old copy lying around.
520catch "exec rm -f ./x$tool"
521
522if ![file executable $GDB_FULLPATH] then {
523 fail "couldn't convert $GDB to absolute pathname to make local copy"
524} else {
525 if [catch "exec cp $GDB_FULLPATH ./x$tool"] then {
526 fail "couldn't copy $GDB_FULLPATH to current directory"
527 } else {
528 verbose "\t\tCopied $GDB_FULLPATH to ./x$tool"
529 if {[test_with_self] <0} then {
530 warning "Couldn't test self"
531 catch "exec rm -f ./x$tool"
532 return -1
533 }
534 catch "exec rm -f ./x$tool"
535 }
536}
This page took 0.125819 seconds and 4 git commands to generate.