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