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