1 # Copyright (C) 1992, 1994 Free Software Foundation, Inc.
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.
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.
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. */
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Fred Fish. (fnf@cygnus.com)
30 set srcfile $binfile.c
32 if ![file exists $objdir/$subdir/$binfile] then {
33 perror "$objdir/$subdir/$binfile does not exist."
38 # Local utility proc just to set and verify listsize
39 # Return 1 if success, 0 if fail.
42 proc set_listsize { arg } {
45 send "set listsize $arg\n"
47 -re "set listsize $arg\r\n$prompt $" {}
48 -re ".*$prompt $" { fail "setting listsize to $arg" ; return 0 }
49 timeout { fail "set listsize to $arg (timeout)" ; return 0 }
52 send "show listsize\n"
54 -re "Number of source lines .* is $arg.\r\n.*$prompt $" {}
55 -re ".*$prompt $" { fail "listsize not set to $arg" ; return 0 }
56 timeout { fail "show listsize (timeout)" ; return 0 }
62 # Test display of listsize lines around a given line number.
65 proc test_listsize {} {
70 send "show listsize\n"
72 -re "Number of source lines gdb will list by default is 10.*$prompt $" {
73 pass "show default list size"
76 fail "show default listsize (10)"
79 fail "show listsize (timeout)"
83 # Show the default lines
85 # This doesn't work for COFF targets.
86 setup_xfail "a29k-*-udi"
89 -re "1\[ \t\]+#include \"list0.h\".*10\[ \t\]+foo .x\[+)\]+;\r\n$prompt $" {
90 pass "show default lines around main"
93 fail "list default lines around main"
96 fail "list default lines around main (timeout)"
100 # Ensure we can limit printouts to one line
102 if [ set_listsize 1 ] then {
106 -re "1\[ \t\]+#include \"list0.h\"\r\n$prompt $" {
107 pass "list line 1 with listsize 1"
109 -re "list 1\r\n$prompt $" {
110 fail "list line 1 with listsize 1"
113 fail "list line 1 with listsize 1"
116 fail "list line 1 with listsize 1 (timeout)"
123 -re "2\[ \t\]+\r\n$prompt $" {
124 pass "list line 2 with listsize 1"
126 -re "list 2\r\n$prompt $" {
127 fail "list line 2 with listsize 1"
130 fail "list line 2 with listsize 1"
133 fail "list line 2 with listsize 1 (timeout)"
140 if [ set_listsize 2 ] then {
143 -re "1\[ \t\]+#include \"list0.h\"\r\n$prompt $" {
144 pass "list line 1 with listsize 2"
147 fail "list line 1 with listsize 2"
150 fail "list line 1 with listsize 2 (timeout)"
156 -re "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+\r\n$prompt $" {
157 pass "list line 2 with listsize 2"
160 fail "list line 2 with listsize 2"
163 fail "list line 2 with listsize 2 (timeout)"
169 -re "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+\r\n$prompt $" {
170 pass "list line 3 with listsize 2"
173 fail "list line 3 with listsize 2"
176 fail "list line 3 with listsize 2 (timeout)"
181 # Try small listsize > 1 that is an odd number
183 if [ set_listsize 3 ] then {
187 -re "1\[ \t\]+#include \"list0.h\"2\[ \t\]+\r\n$prompt $" {
188 pass "list line 1 with listsize 3"
190 -re "1\[ \t\]+#include \"list0.h\"\r\n$prompt $" {
191 fail "list line 1 with listsize 3"
194 fail "list line 1 with listsize 3"
197 fail "list line 1 with listsize 3 (timeout)"
204 -re "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+main \[)(\]+\r\n$prompt $" {
205 pass "list line 2 with listsize 3"
207 -re "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+\r\n$prompt $" {
208 fail "list line 2 with listsize 3"
211 fail "list line 2 with listsize 3"
214 fail "list line 2 with listsize 3 (timeout)"
221 -re "2\[ \t\]+\r\n3\[ \t\]+main \[(\]+\[)\]+\r\n4\[ \t\]+\{\r\n$prompt $" {
222 pass "list line 3 with listsize 3"
224 -re "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+\r\n$prompt $" {
225 fail "list line 3 with listsize 3"
228 fail "list line 3 with listsize 3"
231 fail "list line 3 with listsize 3 (timeout)"
236 # Try small listsize > 2 that is an even number.
238 if [ set_listsize 4 ] then {
241 -re "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+\r\n$prompt $" {
242 pass "list line 1 with listsize 4"
245 fail "list line 1 with listsize 4"
248 fail "list line 1 with listsize 4 (timeout)"
254 -re "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+main \[)(\]+\r\n$prompt $" {
255 pass "list line 2 with listsize 4"
258 fail "list line 2 with listsize 4"
261 fail "list line 2 with listsize 4 (timeout)"
267 -re "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{\r\n$prompt $" {
268 pass "list line 3 with listsize 4"
271 fail "list line 3 with listsize 4"
274 fail "list line 3 with listsize 4 (timeout)"
280 -re "2\[ \t\]+\r\n.*5\[ \t\]+int x;\r\n$prompt $" {
281 pass "list line 4 with listsize 4"
284 fail "list line 4 with listsize 4"
287 fail "list line 4 with listsize 4 (timeout)"
292 # Try a size larger than the entire file.
294 if [ set_listsize 100 ] then {
297 -re "1\[ \t\]+#include \"list0.h\".*\r\n39\[ \t\]+\}\r\n$prompt $" {
298 pass "list line 1 with listsize 100"
301 fail "list line 1 with listsize 100"
307 -re "1\[ \t\]+#include \"list0.h\".*\r\n39\[ \t\]+\}\r\n$prompt $" {
308 pass "list line 1 with listsize 100"
311 fail "list line 1 with listsize 100"
316 # Try listsize of 0 which suppresses printing.
318 send "set listsize 0\n"
320 -re "set listsize 0\r\n$prompt $" {
322 send "show listsize\n"
324 -re "Number of source lines .* is 0.\r\n.*$prompt $" {
325 pass "listsize of 0 displays as 0"
327 -re "Number of source lines .* is unlimited.\r\n.*$prompt $" {
328 fail "listsize of 0 displays as unlimited"
331 fail "listsize not set to unlimited (0)"
334 fail "show listsize (timeout)"
339 -re "list 1\r\n$prompt $" {
340 pass "listsize of 0 suppresses output"
343 fail "listsize of 0 should suppress output"
346 fail "listsize of 0 suppresses output (timeout)"
351 fail "setting listsize to 0"
354 fail "set listsize to 0 (timeout)"
358 # Try listsize of -1 which is special, and means unlimited.
360 send "set listsize -1\n"
362 -re "set listsize -1\r\n$prompt $" {
363 send "show listsize\n"
365 -re "Number of source lines .* is unlimited.\r\n.*$prompt $" {
366 pass "listsize of -1 displays as unlimited"
369 fail "listsize not set to unlimited (-1)"
372 fail "show listsize (timeout)"
378 -re "1\[ \t\]+#include .*\r\n39\[ \t\]+\}\r\n$prompt $" {
379 pass "list line 1 with unlimited listsize"
381 -re "list 1\r\n$prompt $" {
382 fail "listsize of -1 (unlimited) suppresses output"
385 fail "list line 1 with unlimited listsize"
390 fail "setting listsize to -1"
393 fail "set listsize to -1 (timeout)"
399 # Test "list filename:number" for C include file
402 proc test_list_include_file {} {
405 # FIXME This fails on DWARF.
406 setup_xfail "*-*-sysv4*"
407 # FIXME Fails for COFF as well, I think.
408 setup_xfail "a29k-*-udi"
409 send "list list0.h:1\n"
411 -re "1\[ \t\]+/\[*\]+ An include file .*5\[ \t\]+foo \[(\]+x\[)\]+\r\n$prompt $" {
412 pass "list line 1 in include file"
414 -re "No source file named list0.h.\r\n$prompt $" {
415 fail "list line 1 in include file"
418 fail "list line 1 in include file"
421 fail "list line 1 in include file (timeout)"
425 # FIXME fails on DWARF
426 setup_xfail "*-*-sysv4*"
427 # FIXME Fails for COFF as well, I think.
428 setup_xfail "a29k-*-udi"
429 send "list list0.h:100\n"
431 -re "Line number 95 out of range; .*list0.h has 36 lines.\r\n$prompt $" {
432 pass "list message for lines past EOF"
434 -re "No source file named list0.h.\r\n$prompt $" {
435 fail "list message for lines past EOF"
438 fail "list message for lines past EOF"
441 fail "list message for lines past EOF (timeout)"
447 # Test "list filename:number" for C source file
450 proc test_list_filename_and_number {} {
455 send "list list0.c:1\n"
457 -re "1\[ \t\]+#include \"list0.h\".*5\[ \t\]+int x;\r\n$prompt $" {
460 -re ".*$prompt $" { fail "list list0.c:1" ; return }
461 timeout { fail "list list0.c:1" ; return }
463 send "list list0.c:10\n"
465 -re "5\[ \t\]+int x;.*14\[ \t\]+foo .x\[+)\]+;\r\n$prompt $" {
468 -re ".*$prompt $" { fail "list list.c:10" ; return }
469 timeout { fail "list list.c:10" ; return }
471 send "list list1.c:1\n"
473 -re "1\[ \t\]+void.*5\[ \t\]+printf \[(\]+.*\[)\]+;\r\n$prompt $" {
476 -re ".*$prompt $" { fail "list list1.c:1" ; return }
477 timeout { fail "list list1.c:1" ; return }
479 send "list list1.c:12\n"
481 -re "7\[ \t\]+long_line \[(\]+.*\[)\]+;.*14\[ \t\]+\}\r\n.*$prompt $" {
484 -re ".*$prompt $" { fail "list list1.c:12" ; return }
485 timeout { fail "list list1.c:12" ; return }
487 pass "list filename:number ($testcnt tests)"
491 # Test "list function" for C source file
494 proc test_list_function {} {
497 # gcc appears to generate incorrect debugging information for code
498 # in include files, which breaks this test.
499 setup_xfail "rs6000-*-*" 1804
500 setup_xfail "a29k-*-udi"
503 -re "1\[ \t\]+#include .*8\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" {
504 pass "list function in source file 1"
506 -re ".*$prompt $" { fail "list main" ; return }
507 timeout { fail "list main" ; return }
510 # Ultrix gdb takes the second case below; it's also correct.
513 -re "1\[ \t\]+void.*8\[ \t\]+\}\r\n$prompt $" {
514 pass "list function in source file 2"
516 -re "1\[ \t\]+void.*7\[ \t\]*long_line ..;\r\n$prompt $" {
517 pass "list function in source file 2"
519 -re ".*$prompt $" { fail "list bar" ; return }
520 timeout { fail "list bar" ; return }
523 # Test "list function" for C include file
524 # Ultrix gdb is the second case, still correct.
525 # FIXME This fails on DWARF
526 setup_xfail "*-*-sysv4*"
529 -re "2\[ \t\]+including file.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" {
530 pass "list function in include file"
532 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" {
533 pass "list function in include file"
535 -re ".*main \[)(\]+.*$prompt $" {
536 fail "list function in include file"
538 -re ".*$prompt $" { fail "list foo (in include file)" ; return }
539 timeout { fail "list foo (timeout)" ; return }
543 proc test_list_forward {} {
548 send "list list0.c:10\n"
550 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { incr testcnt }
551 -re ".*$prompt $" { fail "list list0.c:10" ; return }
552 timeout { fail "list list0.c:10" ; return }
557 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { incr testcnt }
558 -re ".*$prompt $" { fail "list 15-24" ; return }
559 timeout { fail "list 15-24 (timeout)" ; return }
564 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+\r\n$prompt $" { incr testcnt }
565 -re ".*$prompt $" { fail "list 25-34" ; return }
566 timeout { fail "list 25-34 (timeout)" ; return }
571 -re "35\[ \t\]+static void.*39\[ \t\]+\}\r\n$prompt $" { incr testcnt }
572 -re ".*$prompt $" { fail "list 35-39" ; return }
573 timeout { fail "list 35-39 (timeout)" ; return }
576 pass "successive list commands to page forward ($testcnt tests)"
579 proc test_list_backwards {} {
584 send "list list0.c:30\n"
586 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+\r\n$prompt $" { incr testcnt }
587 -re ".*$prompt $" { fail "list list0.c:30" ; return }
588 timeout { fail "list list0.c:30" ; return }
593 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { incr testcnt }
594 -re ".*$prompt $" { fail "list 15-24" ; return }
595 timeout { fail "list 15-24 (timeout)" ; return }
600 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { incr testcnt }
601 -re ".*$prompt $" { fail "list 5-14" ; return }
602 timeout { fail "list 5-14 (timeout)" ; return }
607 -re "1\[ \t\]+#include .*4\[ \t\]+\{\r\n$prompt $" { incr testcnt }
608 -re ".*$prompt $" { fail "list 1-4" ; return }
609 timeout { fail "list 1-4 (timeout)" ; return }
612 pass "$testcnt successive \"list -\" commands to page backwards"
616 # Test "list first,last"
619 proc test_list_range {} {
622 send "list list0.c:2,list0.c:5\n"
624 -re "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+.*5\[ \t\]+int x;\r\n$prompt $" {
625 pass "list range; filename:line1,filename:line2"
627 -re ".*$prompt $" { fail "list list0.c:2,list0.c:5" }
628 timeout { fail "list list0.c:2,list0.c:5" }
633 -re "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+.*5\[ \t\]+int x;\r\n$prompt $" {
634 pass "list range; line1,line2"
636 -re ".*$prompt $" { fail "list 2,5" }
637 timeout { fail "list 2,5" }
642 #-re "Line number 0 out of range; .*list0.c has 39 lines.\r\n$prompt $" {
643 #pass "list range; lower bound negative"
645 #-re ".*$prompt $" { fail "list -1,6" }
646 #timeout { fail "list -1,6" }
649 #send "list -100,-40\n"
651 #-re "Line number -60 out of range; .*list0.c has 39 lines.\r\n$prompt $" {
652 #pass "list range; both bounds negative"
654 #-re ".*$prompt $" { fail "-100,-40" }
655 #timeout { fail "-100,-40" }
660 -re "30\[ \t\]+foo \[(\]+.*\[)\]+;.*39\[ \t\]+\}\r\n$prompt $" {
661 pass "list range; upper bound past EOF"
663 -re ".*$prompt $" { fail "list 30,40" }
664 timeout { fail "list 30,40" }
669 -re "Line number 40 out of range; .*list0.c has 39 lines.\r\n$prompt $" {
670 pass "list range; both bounds past EOF"
672 -re ".*$prompt $" { fail "40,100" }
673 timeout { fail "40,100" }
676 send "list list0.c:2,list1.c:17\n"
678 -re "Specified start and end are in different files.\r\n$prompt $" {
679 pass "list range, must be same files"
681 -re ".*$prompt $" { fail "list0.c:2,list1.c:17" }
682 timeout { fail "list0.c:2,list1.c:17" }
687 # Test "list filename:function"
690 proc test_list_filename_and_function {} {
695 # gcc appears to generate incorrect debugging information for code
696 # in include files, which breaks this test.
697 setup_xfail "rs6000-*-*" 1804
698 setup_xfail "a29k-*-udi"
699 send "list list0.c:main\n"
701 -re "1\[ \t\]+#include .*8\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" {
704 -re ".*$prompt $" { fail "list list0.c:main" }
705 timeout { fail "list list0.c:main (timeout)" }
708 # The i960 and a29k-amd-udi are the second case
710 # Not sure what the point of having this function be unused is.
711 # AIX is legitimately removing it.
712 setup_xfail "rs6000-*-aix*"
713 send "list list0.c:unused\n"
715 -re "32\[ \t\]+foo \[(\]+.*\[)\]+;.*39\[ \t\]+\}\r\n$prompt $" {
718 -re "34.*39\[ \t\]+\}\r\n$prompt $" {
721 -re ".*$prompt $" { fail "list list0.c:unused" }
722 timeout { fail "list list0.c:unused (timeout)" }
724 clear_xfail "rs6000-*-aix*"
726 # gcc appears to generate incorrect debugging information for code
727 # in include files, which breaks this test.
728 # Ultrix gdb is the second case, one line different but still correct.
729 # FIXME This fails on DWARF
730 setup_xfail "rs6000-*-*" 1804
731 setup_xfail "*-*-sysv4*"
732 # FIXME Fails for COFF as well, I think.
733 setup_xfail "a29k-*-udi"
734 send "list list0.h:foo\n"
736 -re "2\[ \t\]+including file. This.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" {
739 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" {
742 -re "No source file named list0.h.\r\n$prompt $" {
743 fail "list list0.h:foo"
745 -re ".*$prompt $" { fail "list list0.h:foo" }
746 timeout { fail "list list0.h:foo (timeout)" }
749 # Ultrix gdb is the second case.
750 # a29k-amd-udi is the third case.
751 send "list list1.c:bar\n"
753 -re "1\[ \t\]+void.*8\[ \t\]+\}\r\n$prompt $" {
756 -re "1\[ \t\]+void.*7\[ \t\]*long_line ..;\r\n$prompt $" {
759 -re "1\[ \t\]+void.*9\[ \t\]*\r\n$prompt $" {
762 -re ".*$prompt $" { fail "list list1.c:bar" }
763 timeout { fail "list list1.c:bar (timeout)" }
766 # The i960 and a29k-amd-udi are the second case
768 # Not sure what the point of having this function be unused is.
769 # AIX is legitimately removing it.
770 setup_xfail "rs6000-*-aix*"
771 send "list list1.c:unused\n"
773 -re "7\[ \t\]+long_line \[(\]\[)\];.*14\[ \t\]+\}\r\n.*$prompt $" {
776 -re "9.*14\[ \t\]+\}\r\n.*$prompt $" {
779 -re ".*$prompt $" { fail "list list1.c:unused" }
780 timeout { fail "list list1.c:unused (timeout)" }
782 clear_xfail "rs6000-*-aix*"
784 pass "list filename:function ($testcnt tests)"
786 # Test some invalid specs
787 # The following test takes the FIXME result on most systems using
788 # DWARF. It fails to notice that main() is not in the file requested.
792 # Does this actually work ANYWHERE? I believe not, as this is an `aspect' of
793 # lookup_symbol(), where, when it is given a specific symtab which does not
794 # contain the requested symbol, it will subsequently search all of the symtabs
795 # for the requested symbol.
797 send "list list0.c:foo\n"
799 -re "Function \"foo\" not defined in .*list0.c\r\n$prompt $" {
800 pass "list filename:function; wrong filename rejected"
802 -re "2\[ \t\]+including file.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" {
803 fail "list filename:function; wrong filename not rejected"
805 -re ".*main \[)(\]+.*$prompt $" {
806 fail "list filename:function; wrong filename not rejected"
809 fail "list filename:function; wrong filename not rejected"
812 fail "list filename:function; wrong filename (timeout)"
816 send "list foobar.c:main\n"
818 -re "No source file named foobar.c.\r\n$prompt $" {
819 pass "list filename:function; nonexistant file"
822 fail "list filename:function; nonexistant file"
825 fail "list filename:function; nonexistant file (timeout)"
829 # The following test takes the FIXME result on most systems using
830 # DWARF. It doesn't know how to find functions in include files.
832 setup_xfail "*-*-sysv4*"
833 send "list list0.h:foobar\n"
835 -re "Function \"foobar\" not defined.\r\n$prompt $" {
836 pass "list filename:function; nonexistant function"
838 -re "No source file named list0.h.\r\n$prompt $" {
839 fail "list filename:function; nonexistant function"
842 fail "list filename:function; nonexistant function"
845 fail "list filename:function; nonexistant function (timeout)"
851 proc test_forward_search {} {
852 gdb_test "set listsize 2" ""
853 gdb_test "list long_line" "20\[ \t\]+long_line "
855 gdb_test "search 4321" " not found"
857 gdb_test "search 6789" "22\[ \t\]+oof .6789.;"
859 # We could look at the result of this, but dejagnu seems to
860 # fail, perhaps because expect's buffers are too small.
861 # In any case, we just want GDB to not crash if the line
862 # being searched is extremely long.
864 gdb_test "search 1234" ""
867 # Start with a fresh gdb.
871 gdb_reinitialize_dir $srcdir/$subdir
872 gdb_load $objdir/$subdir/$binfile
875 expect -re "$prompt $"
878 if [ set_listsize 10 ] then {
879 test_list_include_file
880 test_list_filename_and_number
885 test_list_filename_and_function