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