* gdb.base/a1-selftest.exp (test_with_self), gdb.base/interrupt.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 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 ".*time_at_startup = get_run_time .*$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 get_run_time and everything it calls"
224 set got_over_get_run_time 0
225 send "next\n"
226 expect {
227 -re ".*init_malloc.*$prompt $" {
228 pass "$description"
229 set got_over_get_run_time 1
230 }
231 -re ".*No such file or directory.\r\n$prompt $" {
232 pass "$description (no source available)"
233 set got_over_get_run_time 1
234 }
235 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
236 pass "$description (no source available)"
237 set got_over_get_run_time 1
238 }
239 -re ".*$prompt $" {
240 fail "$description"
241 }
242 timeout {
243 fail "$description (timeout)"
244 }
245 }
246 # -re "if \(setmp \(to_top_level\)\).*$prompt $" { pass "first next" }
247
248 if $got_over_get_run_time then {
249 set description "next over init_malloc and everything it calls"
250 send "next\n"
251 expect {
252 -re "if.*SET_TOP_LEVEL.*$prompt $" {
253 pass "$description"
254 }
255 -re "i = .*count.*$prompt $" {
256 pass "$description"
257 set description "next over ALIGN_STACK_ON_STARTUP code"
258 send "next\n"
259 expect {
260 -re "if.*i != 0.*$prompt $" {
261 pass "$description"
262 send "next\n"
263 expect {
264 -re "if.*SET_TOP_LEVEL.*$prompt $" {
265 pass "$description"
266 }
267 -re "alloca.*$prompt $" {
268 send "next\n"
269 expect {
270 -re "if.*level.*$prompt $" {
271 pass "$description"
272 }
273 }
274 }
275 }
276 }
277 }
278 }
279 -re ".*No such file or directory.\r\n$prompt $" {
280 pass "$description (no source available)"
281 }
282 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
283 pass "$description (no source available)"
284 }
285 -re ".*$prompt $" {
286 fail "$description"
287 }
288 default {
289 fail "$description (timeout or eof)"
290 }
291 }
292 }
293
294 # This one fails on Solaris (for some versions of gdb) because you
295 # can't next over library functions
296 setup_xfail "sparc-sun-solaris2" 1817
297 set next_ok 1
298 set need_to_step_over_cmdsize 1
299 set description "next over SET_TOP_LEVEL call"
300 send "next\n"
301 expect {
302 -re "cmdsize = 1;.*$prompt $" {
303 pass "$description"
304 }
305 -re "cmdarg = .*xmalloc.*$prompt $" {
306 # This can happen in optimized code where the "cmdsize = 1" line
307 # is basically removed.
308 pass "$description"
309 set need_to_step_over_cmdsize 0
310 }
311 -re ".*No such file or directory.\r\n$prompt $" {
312 pass "$description (no source available)"
313 }
314 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
315 pass "$description (no source available)"
316 }
317 -re ".*$prompt $" {
318 fail "$description"
319 set next_ok 0
320 }
321 timeout {
322 fail "$description (timeout)"
323 set next_ok 0
324 }
325 }
326
327 set description "print a string"
328 send "print \"foo\"\n"
329 expect {
330 -re ".\[0-9\]+ = \"foo\".*$prompt $" {
331 pass "$description"
332 }
333 -re ".*$prompt $" {
334 fail "$description"
335 }
336 timeout {
337 fail "$description (timeout)"
338 }
339 }
340
341 if $need_to_step_over_cmdsize {
342 set description "step over cmdsize initialization"
343 send "step\n"
344 expect {
345 -re "cmdarg = .*xmalloc.*$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 # and another step for good luck
364 # This one fails on Solaris (for some versions of gdb) because you
365 # can't step into library functions
366 if $next_ok {
367 set description "step into xmalloc call"
368 send "step\n"
369 expect {
370 -re "xmalloc.*size=.*at.*utils.c.*$prompt $" {
371 pass "$description"
372 }
373 -re ".*No such file or directory.\r\n$prompt $" {
374 pass "$description (no source available)"
375 }
376 -re "A file or directory .* does not exist..\r\n$prompt $" {
377 pass "$description (no source available)"
378 }
379 -re ".*$prompt $" {
380 fail "$description"
381 }
382 timeout {
383 fail "$description (timeout)"
384 }
385 }
386 }
387
388 # We'll need this when we send a ^C to GDB
389 gdb_test "shell stty intr ^C" "" \
390 "set interrupt character in test_with_self"
391
392 # start the "xgdb" process
393 send "continue\n"
394 expect {
395 -re "GDB is free software and you are welcome to distribute copies of it.*
396 under certain conditions; type \"show copying\" to see the conditions..*
397 There is absolutely no warranty for GDB; type \"show warranty\" for details..*
398 GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$prompt $"\
399 { pass "xgdb is at prompt" }
400 -re ".*$prompt $" { fail "xgdb is at prompt" }
401 timeout { fail "(timeout) xgdb is at prompt" }
402 }
403
404 # set xgdb prompt so we can tell which is which
405 send "set prompt (xgdb) \n"
406 expect {
407 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
408 -re ".*$prompt $" { fail "Set xgdb prompt" }
409 default { fail "(timeout) Set xgdb prompt" }
410 }
411
412 # kill the xgdb process
413 set description "send ^C to child process"
414 send "\003"
415 expect {
416 -re "Program received signal SIGINT.*$prompt $" {
417 pass "$description"
418 }
419 -re ".*$prompt $" {
420 fail "$description"
421 }
422 timeout {
423 fail "$description (timeout)"
424 }
425 }
426
427 set description "send SIGINT signal to child process"
428 send "signal SIGINT\n"
429 expect {
430 -re "Continuing with signal SIGINT.*$prompt $" {
431 pass "$description"
432 }
433 -re ".*$prompt $" {
434 fail "$description"
435 }
436 timeout {
437 fail "$description (timeout)"
438 }
439 }
440
441 # get a stack trace
442 setup_xfail "i486-*-sysv4"
443 set description "backtrace through signal handler"
444 send "backtrace\n"
445 expect {
446 -re "#0.*read.*#\[1-9\].*main.c.*$prompt $" {
447 pass "$description"
448 }
449 -re ".*$prompt $" {
450 fail "$description"
451 }
452 timeout {
453 fail "$description (timeout)"
454 }
455 }
456
457 gdb_exit
458
459 # Set the timeout back to the value it had when we were called.
460 set timeout $oldtimeout
461
462 # Restart gdb in case next test expects it to be started already.
463 gdb_start
464 return 0
465 }
466
467 # Find a pathname to a file that we would execute if the shell was asked
468 # to run $arg using the current PATH.
469
470 proc find_gdb { arg } {
471
472 # If the arg directly specifies an existing executable file, then
473 # simply use it.
474
475 if [file executable $arg] then {
476 return $arg
477 }
478
479 set result [which $arg]
480 if [string match "/" [ string range $result 0 0 ]] then {
481 return $result
482 }
483
484 # If everything fails, just return the unqualified pathname as default
485 # and hope for best.
486
487 return $arg
488 }
489
490 # Run the test with self.
491 # Copy the file executable file in case this OS doesn't like to edit it's own
492 # text space.
493
494 set GDB_FULLPATH [find_gdb $GDB]
495
496 # Remove any old copy lying around.
497 catch "exec rm -f ./x$tool"
498
499 if ![file executable $GDB_FULLPATH] then {
500 fail "couldn't convert $GDB to absolute pathname to make local copy"
501 } else {
502 if [catch "exec cp $GDB_FULLPATH ./x$tool"] then {
503 fail "couldn't copy $GDB_FULLPATH to current directory"
504 } else {
505 verbose "\t\tCopied $GDB_FULLPATH to ./x$tool"
506 if {[test_with_self] <0} then {
507 warning "Couldn't test self"
508 catch "exec rm -f ./x$tool"
509 return -1
510 }
511 catch "exec rm -f ./x$tool"
512 }
513 }
This page took 0.042522 seconds and 5 git commands to generate.