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