283de5100d9fe9beaf0035eac3d32df1a8439b75
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.gdb / selftest.exp
1 # Copyright 1988, 1990, 1991, 1992, 1994, 1997, 1999, 2000, 2002, 2003
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
20
21 # This file was written by Rob Savoye. (rob@cygnus.com)
22
23 if $tracelevel then {
24 strace $tracelevel
25 }
26
27 set prms_id 0
28 set bug_id 0
29
30 # are we on a target board
31 if [is_remote target] {
32 return
33 }
34
35 # Not all of the lines of code near the start of main are executed for
36 # every machine. Also, optimization may reorder some of the lines.
37 # So all we do is try to step or next over everything until we get
38 # to a line that we know is always executed.
39
40 proc do_steps_and_nexts {} {
41 global gdb_prompt
42 global srcdir
43
44 gdb_reinitialize_dir $srcdir/..
45
46 for {set count 0} {$count < 32} {incr count} {
47 send_gdb "list\n"
48 # NOTE: carlton/2002-12-11: The "initial brace" and
49 # "current_directory initialization" possibilities happen to
50 # me with GCC 3.1 on i686-pc-linux-gnu when I compile with
51 # optimization.
52 gdb_expect {
53 -re ".*context = data.*$gdb_prompt $" {
54 set description "step over context initialization"
55 set command "step"
56 }
57 -re ".*argc = context->argc.*$gdb_prompt $" {
58 set description "step over argc initialization"
59 set command "step"
60 }
61 -re ".*argv = context->argv.*$gdb_prompt $" {
62 set description "step over argv initialization"
63 set command "step"
64 }
65 -re ".*quiet = 0.*$gdb_prompt $" {
66 set description "step over quiet initialization"
67 set command "step"
68 }
69 -re ".*batch = 0.*$gdb_prompt $" {
70 set description "step over batch initialization"
71 set command "step"
72 }
73 -re ".*symarg = NULL.*$gdb_prompt $" {
74 set description "step over symarg initialization"
75 set command "step"
76 }
77 -re ".*execarg = NULL.*$gdb_prompt $" {
78 set description "step over execarg initialization"
79 set command "step"
80 }
81 -re ".*corearg = NULL.*$gdb_prompt $" {
82 set description "step over corearg initialization"
83 set command "step"
84 }
85 -re ".*cdarg = NULL.*$gdb_prompt $" {
86 set description "step over cdarg initialization"
87 set command "step"
88 }
89 -re ".*ttyarg = NULL.*$gdb_prompt $" {
90 set description "step over ttyarg initialization"
91 set command "step"
92 }
93 -re ".*time_at_startup = get_run_time.*$gdb_prompt $" {
94 set description "next over get_run_time and everything it calls"
95 set command "next"
96 }
97 -re ".*START_PROGRESS.*$gdb_prompt $" {
98 # Note: ezannoni/2004/02/17: This check should be
99 # removed, since as of today that source line is not
100 # in gdb anymore.
101 set description "next over START_PROGRESS and everything it calls"
102 set command "next"
103 }
104 -re ".*mac_init.*$gdb_prompt $" {
105 set description "next over mac_init and everything it calls"
106 set command "next"
107 }
108 -re ".*lim_at_start.*$gdb_prompt $" {
109 set description "next over lim_at_start initialization"
110 set command "next"
111 }
112 -re ".*count . 0x3.*$gdb_prompt $" {
113 set description "next over conditional stack alignment code 1"
114 set command "next"
115 }
116 -re ".*if .i != 0.*$gdb_prompt $" {
117 set description "next over conditional stack alignment code 2"
118 set command "next"
119 }
120 -re ".*alloca .i - 4.*$gdb_prompt $" {
121 set description "next over conditional stack alignment alloca"
122 set command "next"
123 }
124 -re ".*cmdsize = 1.*$gdb_prompt $" {
125 set description "step over cmdsize initialization"
126 set command "next"
127 }
128 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
129 set description "next over cmdarg initialization via xmalloc"
130 set command "next"
131 }
132 -re ".*ncmd = 0.*$gdb_prompt $" {
133 set description "next over ncmd initialization"
134 set command "next"
135 }
136 -re ".*dirsize = 1.*$gdb_prompt $" {
137 set description "next over dirsize initialization"
138 set command "next"
139 }
140 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
141 return
142 }
143 -re ".*setlocale .LC_MESSAGES,.*$gdb_prompt $" {
144 set description "next over setlocale LC_MESSAGES"
145 set command "next"
146 }
147 -re ".*setlocale .LC_CTYPE,.*$gdb_prompt $" {
148 set description "next over setlocale LC_CTYPE"
149 set command "next"
150 }
151 -re ".*bindtextdomain .PACKAGE, LOCALEDIR.;.*$gdb_prompt $" {
152 set description "next over bindtextdomain"
153 set command "next"
154 }
155 -re ".*textdomain .PACKAGE.;.*$gdb_prompt $" {
156 set description "next over textdomain PACKAGE"
157 set command "next"
158 }
159 -re "\[0-9\]*\t\{\r\n$gdb_prompt $" {
160 set description "step over initial brace"
161 set command "step"
162 }
163 -re ".*current_directory = gdb_dirbuf.*$gdb_prompt $" {
164 set description "step over current_directory initialization"
165 set command "step"
166 }
167 -re ".*gdb_sysroot = .*$gdb_prompt $" {
168 # NOTE: carlton/2003-01-15: More optimization reordering,
169 # observed on GCC 3.1.
170 set description "step over gdb_sysroot initialization"
171 set command "step"
172 }
173 -re ".*ndir = 0.*$gdb_prompt $" {
174 set description "step over ndir initialization"
175 set command "step"
176 }
177 -re ".*instream = stdin.*$gdb_prompt $" {
178 set description "step over instream initialization"
179 set command "step"
180 }
181 -re ".*getcwd .gdb_dirbuf, sizeof .gdb_dirbuf..;.*$gdb_prompt $" {
182 set description "next over getcwd"
183 set command "next"
184 }
185 -re "\[ \t\]+\{\r\n$gdb_prompt $" {
186 setup_xfail "mips-*-irix5*"
187 fail "$description ended up at odd location"
188 }
189 -re ".*main.c.*No such file or directory.*$gdb_prompt $" {
190 setup_xfail "rs6000-*-aix3*"
191 fail "must be able to list source lines"
192 return
193 }
194 -re ".*$gdb_prompt $" {
195 fail "unknown source line after $description"
196 return
197 }
198 default {
199 fail "unknown source line near main"
200 return
201 }
202 }
203 send_gdb "$command\n"
204 gdb_expect {
205 -re ".*No such file or directory.\r\n$gdb_prompt $" {
206 fail "$description (no source available)"
207 }
208 -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" {
209 fail "$description (no source available)"
210 }
211 -re ".*$gdb_prompt $" {
212 pass "$description"
213 }
214 timeout {
215 fail "$description (timeout)"
216 }
217 }
218 }
219 }
220
221 proc test_with_self { executable } {
222 global gdb_prompt
223 global tool
224 global det_file
225 global decimal
226 global timeout
227
228 # load yourself into the debugger
229 # This can take a relatively long time, particularly for testing where
230 # the executable is being accessed over a network, or where gdb does not
231 # support partial symbols for a particular target and has to load the
232 # entire symbol table. Set the timeout to 10 minutes, which should be
233 # adequate for most environments (it *has* timed out with 5 min on a
234 # SPARCstation SLC under moderate load, so this isn't unreasonable).
235 # After gdb is started, set the timeout to 30 seconds for the duration
236 # of this test, and then back to the original value.
237
238 set oldtimeout $timeout
239 set timeout 600
240 verbose "Timeout is now $timeout seconds" 2
241 if {[gdb_load $executable] <0} then {
242 set timeout $oldtimeout
243 verbose "Timeout is now $timeout seconds" 2
244 return -1
245 }
246 set timeout $oldtimeout
247 verbose "Timeout is now $timeout seconds" 2
248
249 # disassemble yourself
250 gdb_test "x/10i main" \
251 "x/10i.*main.*main.$decimal.*main.$decimal.*" \
252 "Disassemble main"
253
254 # Set a breakpoint at main
255 gdb_test "break captured_main" \
256 "Breakpoint.*at.* file.*, line.*" \
257 "breakpoint in captured_main"
258
259 # We'll need this when we send a ^C to GDB. Need to do it before we
260 # run the program and gdb starts saving and restoring tty states.
261 # On Ultrix, we don't need it and it is really slow (because shell_escape
262 # doesn't use vfork).
263 if ![istarget "*-*-ultrix*"] then {
264 gdb_test "shell stty intr '^C'" "" \
265 "set interrupt character in test_with_self"
266 }
267
268 # FIXME: If we put this after the run to main, the first list
269 # command doesn't print the same line as the current line where
270 # gdb is stopped.
271 gdb_test "set listsize 1" "" "set listsize to 1"
272
273 # run yourself
274 # It may take a very long time for the inferior gdb to start (lynx),
275 # so we bump it back up for the duration of this command.
276 set timeout 600
277
278 set description "run until breakpoint at captured_main"
279 send_gdb "run -nw\n"
280 gdb_expect {
281 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
282 pass "$description"
283 }
284 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
285 xfail "$description (line numbers scrambled?)"
286 }
287 -re "vfork: No more processes.*$gdb_prompt $" {
288 fail "$description (out of virtual memory)"
289 set timeout $oldtimeout
290 verbose "Timeout is now $timeout seconds" 2
291 return -1
292 }
293 -re ".*$gdb_prompt $" {
294 fail "$description"
295 set timeout $oldtimeout
296 verbose "Timeout is now $timeout seconds" 2
297 return -1
298 }
299 timeout {
300 fail "$description (timeout)"
301 }
302 }
303
304 set timeout $oldtimeout
305 verbose "Timeout is now $timeout seconds" 2
306
307 # do we have a version number ?
308 send_gdb "print version\n"
309 gdb_expect {
310 -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
311 pass "printed version as string"
312 }
313 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
314 pass "printed version as pointer"
315 }
316 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
317 pass "printed version with cast"
318 }
319 -re ".*$gdb_prompt $" { fail "printed version" }
320 timeout { fail "(timeout) printed version" }
321 }
322
323 do_steps_and_nexts
324
325 gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string"
326
327 # do_steps_and_nexts left us ready to execute an xmalloc call,
328 # so give that a try.
329 # If we don't actually enter the xmalloc call when we give a
330 # step command that seems like a genuine bug. It seems to happen
331 # on most RISC processors.
332 # NOTE drow/2003-06-22: However, if we step back to the preceding two
333 # lines, just keep stepping until we enter.
334 set stepped_back 0
335 setup_xfail "alpha-*-*" "mips-*-*"
336 set description "step into xmalloc call"
337 send_gdb "step\n"
338 gdb_expect {
339 -re "ncmd = 0;.*$gdb_prompt $" {
340 set stepped_back 1
341 send_gdb "step\n"
342 exp_continue
343 }
344 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
345 set stepped_back 1
346 send_gdb "step\n"
347 exp_continue
348 }
349 -re "dirsize = 1;.*$gdb_prompt $" {
350 set stepped_back 1
351 send_gdb "step\n"
352 exp_continue
353 }
354 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
355 if { $stepped_back == 1 } {
356 send_gdb "step\n"
357 exp_continue
358 } else {
359 fail "$description"
360 }
361 }
362 -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" {
363 pass "$description"
364 }
365 -re ".*No such file or directory.\r\n$gdb_prompt $" {
366 pass "$description (no source available)"
367 }
368 -re "A file or directory .* does not exist..\r\n$gdb_prompt $" {
369 pass "$description (no source available)"
370 }
371 -re ".*$gdb_prompt $" {
372 fail "$description"
373 }
374 timeout {
375 fail "$description (timeout)"
376 }
377 }
378
379 # start the "xgdb" process
380 send_gdb "continue\n"
381 gdb_expect {
382 -re "GNU gdb \[0-9\.\]*.*
383 Copyright \[0-9\]* Free Software Foundation, Inc.*
384 GDB is free software, covered by the GNU General Public License, and you are.*
385 welcome to change it and/or distribute copies of it under certain conditions.*
386 Type \"show copying\" to see the conditions.*
387 There is absolutely no warranty for GDB. Type \"show warranty\" for details.*
388 This GDB was configured as .*$gdb_prompt $"\
389 { pass "xgdb is at prompt" }
390 -re "GDB is free software and you are welcome to distribute copies of it.*
391 under certain conditions; type \"show copying\" to see the conditions..*
392 There is absolutely no warranty for GDB; type \"show warranty\" for details..*
393 GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$gdb_prompt $"\
394 { pass "xgdb is at prompt (obsolescent gdb)" }
395 -re ".*$gdb_prompt $" { fail "xgdb is at prompt" }
396 timeout { fail "(timeout) xgdb is at prompt" }
397 }
398
399 # set xgdb prompt so we can tell which is which
400 send_gdb "set prompt (xgdb) \n"
401 gdb_expect {
402 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
403 -re ".*$gdb_prompt $" { fail "Set xgdb prompt" }
404 default { fail "(timeout) Set xgdb prompt" }
405 }
406
407 # kill the xgdb process
408 set description "send ^C to child process"
409 send_gdb "\003"
410 gdb_expect {
411 -re "Program received signal SIGINT.*$gdb_prompt $" {
412 pass "$description"
413 }
414 -re ".*$gdb_prompt $" {
415 fail "$description"
416 }
417 timeout {
418 fail "$description (timeout)"
419 }
420 }
421
422 set description "send SIGINT signal to child process"
423 send_gdb "signal SIGINT\n"
424 gdb_expect {
425 -re "Continuing with signal SIGINT.*$gdb_prompt $" {
426 pass "$description"
427 }
428 -re ".*$gdb_prompt $" {
429 fail "$description"
430 }
431 timeout {
432 fail "$description (timeout)"
433 }
434 }
435
436 # get a stack trace
437 #
438 # This fails on some linux systems for unknown reasons. On the
439 # systems where it fails, sometimes it works fine when run manually.
440 # The testsuite failures may not be limited to just aout systems.
441 setup_xfail "i*86-pc-linuxaout-gnu"
442 set description "backtrace through signal handler"
443 send_gdb "backtrace\n"
444 gdb_expect {
445 -re "#0.*(read|poll).*in main \\(.*\\) at .*gdb\\.c.*$gdb_prompt $" {
446 pass "$description"
447 }
448 -re ".*$gdb_prompt $" {
449 # On the alpha, we hit the infamous problem about gdb
450 # being unable to get the frame pointer (mentioned in
451 # gdb/README). As it is intermittent, there is no way to
452 # XFAIL it which will give us an XPASS if the problem goes
453 # away.
454 setup_xfail "alpha*-*-osf*"
455 fail "$description"
456 }
457 timeout {
458 fail "$description (timeout)"
459 }
460 }
461
462
463 # Set the timeout back to the value it had when we were called.
464 set timeout $oldtimeout
465 verbose "Timeout is now $timeout seconds" 2
466
467 # Restart gdb in case next test expects it to be started already.
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 its own
496 # text space.
497
498 set GDB_FULLPATH [find_gdb $GDB]
499
500 # Remove any old copy lying around.
501 remote_file host delete x$tool
502
503 gdb_start
504 set file [remote_download host $GDB_FULLPATH x$tool]
505 set result [test_with_self $file];
506 gdb_exit;
507 catch "remote_file host delete $file";
508
509 if {$result <0} then {
510 warning "Couldn't test self"
511 return -1
512 }
This page took 0.074054 seconds and 4 git commands to generate.