1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2002
2 # Free Software Foundation, Inc.
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.
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.
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.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # This file was written by Fred Fish. (fnf@cygnus.com)
31 set binfile ${objdir}/${subdir}/${testfile}
33 # Need to download the header to the host.
34 remote_download host ${srcdir}/${subdir}/list0.h list0.h
37 if { [gdb_compile "${srcdir}/${subdir}/list0.c" "${binfile}0.o" object {debug}] != "" } {
38 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
41 if { [gdb_compile "${srcdir}/${subdir}/list1.c" "${binfile}1.o" object {debug}] != "" } {
42 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
45 if { [gdb_compile "${binfile}0.o ${binfile}1.o" ${binfile} executable {debug}] != "" } {
46 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
51 # Create and source the file that provides information about the compiler
52 # used to compile the test case.
53 if [get_compiler_info ${binfile}] {
58 # Local utility proc just to set and verify listsize
59 # Return 1 if success, 0 if fail.
62 set set_listsize_count 0;
64 proc set_listsize { arg } {
66 global set_listsize_count;
68 incr set_listsize_count;
69 if [gdb_test "set listsize $arg" "" "setting listsize to $arg #$set_listsize_count"] {
76 if [gdb_test "show listsize" "Number of source lines.* is ${arg}.*" "show listsize $arg #$set_listsize_count"] {
83 # Test display of listsize lines around a given line number.
86 proc test_listsize {} {
89 global hp_aCC_compiler
93 gdb_test "show listsize" "Number of source lines gdb will list by default is 10.*" "show default list size"
95 # Show the default lines
96 # Note that remote targets that have debugging info for _start available will
97 # list the lines there instead of main, so we skip this test for remote targets.
98 # The second case is for optimized code, it is still correct.
100 if [is_remote target] {
102 unsupported "list default lines around main";
104 gdb_test "list" "(1\[ \t\]+#include \"list0.h\".*10\[ \t\]+x = 0;|2.*11\[ \t\]+foo .x\[+)\]+;)" "list default lines around main"
107 # Ensure we can limit printouts to one line
109 if [set_listsize 1] {
110 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"" "list line 1 with listsize 1"
111 gdb_test "list 2" "2\[ \t\]+" "list line 2 with listsize 1"
116 if [ set_listsize 2 ] {
117 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 1 with listsize 2"
118 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 2 with listsize 2"
119 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+" "list line 3 with listsize 2"
122 # Try small listsize > 1 that is an odd number
124 if [ set_listsize 3 ] {
125 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 1 with listsize 3"
126 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 2 with listsize 3"
127 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[(\]+\[)\]+\r\n4\[ \t\]+\{" "list line 3 with listsize 3"
130 # Try small listsize > 2 that is an even number.
132 if [ set_listsize 4 ] then {
133 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 1 with listsize 4"
134 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 2 with listsize 4"
136 gdb_test "list 3" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 3 with listsize 4"
137 gdb_test "list 4" "2\[ \t\]+\r\n.*5\[ \t\]+int x;.*" "list line 4 with listsize 4"
140 # Try a size larger than the entire file.
142 if [ set_listsize 100 ] then {
143 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*\r\n4\[23\]\[ \t\]+\}" "list line 1 with listsize 100"
145 gdb_test "list 10" "1\[ \t\]+#include \"list0.h\".*\r\n4\[23\]\[ \t\]+\}" "list line 10 with listsize 100"
148 # Try listsize of 0 which suppresses printing.
151 gdb_test "list 1" "" "listsize of 0 suppresses output"
153 # Try listsize of -1 which is special, and means unlimited.
157 gdb_test "list 1" "1\[ \t\]+#include .*\r\n39\[ \t\]+\}" "list line 1 with unlimited listsize"
161 # Test "list filename:number" for C include file
164 proc test_list_include_file {} {
167 # OBSOLETE setup_xfail "a29k-*-udi"
168 setup_xfail_format "DWARF 1"
169 setup_xfail_format "COFF"
170 gdb_test "list list0.h:1" "1\[ \t\]+/\[*\]+ An include file .*10\[ \t\]+bar \\(x\\+\\+\\);" "list line 1 in include file"
172 # OBSOLETE setup_xfail "a29k-*-udi"
173 setup_xfail_format "DWARF 1"
174 setup_xfail_format "COFF"
175 gdb_test "list list0.h:100" "Line number 95 out of range; .*list0.h has 3\[67\] lines." "list message for lines past EOF"
179 # Test "list filename:number" for C source file
182 proc test_list_filename_and_number {} {
187 send_gdb "list list0.c:1\n"
189 -re "1\[ \t\]+#include \"list0.h\".*10\[ \t]+x = 0;\r\n$gdb_prompt $" {
192 -re ".*$gdb_prompt $" { fail "list list0.c:1" ; gdb_suppress_tests }
193 timeout { fail "list list0.c:1 (timeout)" ; gdb_suppress_tests }
195 send_gdb "list list0.c:10\n"
197 -re "5\[ \t\]+int x;.*14\[ \t\]+foo .x\[+)\]+;\r\n$gdb_prompt $" {
200 -re ".*$gdb_prompt $" { fail "list list.c:10" ; gdb_suppress_tests }
201 timeout { fail "list list.c:10 (timeout)" ; gdb_suppress_tests }
203 send_gdb "list list1.c:1\n"
205 -re "1\[ \t\]+\#include.*4\[ \t\]+.*int oof\[ \t\]*\(.*\);\r\n.*$gdb_prompt $" {
208 -re ".*$gdb_prompt $" { fail "list list1.c:1" ; gdb_suppress_tests }
209 timeout { fail "list list1.c:1 (timeout)" ; gdb_suppress_tests }
211 send_gdb "list list1.c:12\n"
213 -re "12\[ \t\]+long_line \[(\]+.*\[)\]+;.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
216 -re ".*$gdb_prompt $" { fail "list list1.c:12" ; gdb_suppress_tests }
217 timeout { fail "list list1.c:12 (timeout)" ; gdb_suppress_tests }
219 pass "list filename:number ($testcnt tests)"
220 gdb_stop_suppressing_tests;
224 # Test "list function" for C source file
227 proc test_list_function {} {
231 # gcc appears to generate incorrect debugging information for code
232 # in include files, which breaks this test.
233 # SunPRO cc is the second case below, it's also correct.
234 # OBSOLETE setup_xfail "a29k-*-udi"
235 gdb_test "list main" "(5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;|1\[ \t\]+#include .*10\[ \t\]+x = 0;)" "list function in source file 1"
237 # Ultrix gdb takes the second case below; it's also correct.
238 # SunPRO cc is the third case.
239 gdb_test "list bar" "(4\[ \t\]+void.*\[ \t\]*long_line.*;.*bar.*9\[ \t\]*.*|1\[ \t\]+void.*8\[ \t\]+\}|1\[ \t\]+void.*7\[ \t\]*long_line ..;|7\[ \t\]+void.*14\[ \t\]+\})" "list function in source file 2"
241 # Test "list function" for C include file
242 # Ultrix gdb is the second case, still correct.
243 # SunPRO cc is the third case.
244 setup_xfail "powerpc-*-*"
245 setup_xfail_format "DWARF 1"
246 gdb_test "list foo" "(3\[ \t\]+.*12\[ \t\]+bar \[(\]+.*\[)\]+;|2\[ \t\]+including file.*11\[ \t\]+bar \[(\]+.*\[)\]+;|1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;)" "list function in include file"
249 proc test_list_forward {} {
254 send_gdb "list list0.c:10\n"
256 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
257 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
258 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
263 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
264 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
265 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
270 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
271 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
272 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
277 -re "35\[ \t\]+foo \\(.*\\);.*42\[ \t\]+.*\}\r\n$gdb_prompt $" { incr testcnt }
278 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
279 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
282 pass "successive list commands to page forward ($testcnt tests)"
283 gdb_stop_suppressing_tests;
286 # Test that repeating the list linenum command doesn't print the same
287 # lines over again. Note that this test makes sure that the argument
288 # linenum is dropped, when we repeat the previous command. 'x/5i $pc'
289 # works the same way.
291 proc test_repeat_list_command {} {
296 send_gdb "list list0.c:10\n"
298 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
299 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
300 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
305 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
306 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
307 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
312 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
313 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
314 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
319 -re "35\[ \t\]+foo \\(.*\\);.*42\[ \t\]+.*\}\r\n$gdb_prompt $" { incr testcnt }
320 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
321 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
324 pass "repeat list commands to page forward using 'return' ($testcnt tests)"
325 gdb_stop_suppressing_tests;
328 proc test_list_backwards {} {
333 send_gdb "list list0.c:33\n"
335 -re "28\[ \t\]+foo \\(.*\\);.*37\[ \t\]+\}\r\n$gdb_prompt $" { incr testcnt }
336 -re ".*$gdb_prompt $" { fail "list list0.c:33" ; gdb_suppress_tests }
337 timeout { fail "list list0.c:33 (timeout)" ; gdb_suppress_tests }
342 -re "18\[ \t\]+foo \[(\]+.*\[)\]+;.*27\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
343 -re ".*$gdb_prompt $" { fail "list 18-27" ; gdb_suppress_tests }
344 timeout { fail "list 18-27 (timeout)" ; gdb_suppress_tests }
349 -re "8\[ \t\]+breakpoint\[(\]\[)\];.*17\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
350 -re ".*$gdb_prompt $" { fail "list 8-17" ; gdb_suppress_tests }
351 timeout { fail "list 8-17 (timeout)" ; gdb_suppress_tests }
356 -re "1\[ \t\]+#include .*7\[ \t\]+set_debug_traps\[(\]\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
357 -re ".*$gdb_prompt $" { fail "list 1-7" ; gdb_suppress_tests }
358 timeout { fail "list 1-7 (timeout)" ; gdb_suppress_tests }
361 pass "$testcnt successive \"list -\" commands to page backwards"
362 gdb_stop_suppressing_tests;
366 # Test "list first,last"
369 proc test_list_range {} {
372 gdb_test "list list0.c:2,list0.c:5" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+.*5\[ \t\]+int x;" "list range; filename:line1,filename:line2"
374 gdb_test "list 2,5" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+.*5\[ \t\]+int x;" "list range; line1,line2"
376 # gdb_test "list -1,6" "Line number 0 out of range; .*list0.c has 39 lines." "list range; lower bound negative"
378 # gdb_test "list -100,-40" "Line number -60 out of range; .*list0.c has 39 lines." "list range; both bounds negative"
380 gdb_test "list 30,45" "30\[ \t\]+foo \(.*\);.*43\[ \t\]+\}" "list range; upper bound past EOF"
382 gdb_test "list 45,100" "Line number 45 out of range; .*list0.c has 43 lines." "list range; both bounds past EOF"
384 gdb_test "list list0.c:2,list1.c:17" "Specified start and end are in different files." "list range, must be same files"
388 # Test "list filename:function"
391 proc test_list_filename_and_function {} {
396 # gcc appears to generate incorrect debugging information for code
397 # in include files, which breaks this test.
398 # SunPRO cc is the second case below, it's also correct.
399 # OBSOLETE setup_xfail "a29k-*-udi"
400 send_gdb "list list0.c:main\n"
402 -re "1\[ \t\]+#include .*10\[ \t\]+x = 0;\r\n$gdb_prompt $" {
405 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
406 pass "list function in source file 1"
408 -re ".*$gdb_prompt $" { fail "list list0.c:main" }
409 timeout { fail "list list0.c:main (timeout)" }
412 # The i960 is a second case
413 # OBSOLETE # The a29k-amd-udi is a second case
415 # Not sure what the point of having this function be unused is.
416 # AIX is legitimately removing it.
417 setup_xfail "rs6000-*-aix*"
418 send_gdb "list list0.c:unused\n"
420 -re "40\[ \t\]+unused.*43\[ \t\]+\}\r\n$gdb_prompt $" {
423 -re "37.*42\[ \t\]+\}\r\n$gdb_prompt $" {
426 -re ".*$gdb_prompt $" { fail "list list0.c:unused" }
427 timeout { fail "list list0.c:unused (timeout)" }
429 clear_xfail "rs6000-*-aix*"
431 # gcc appears to generate incorrect debugging information for code
432 # in include files, which breaks this test.
433 # Ultrix gdb is the second case, one line different but still correct.
434 # SunPRO cc is the third case.
435 setup_xfail "rs6000-*-*" 1804
436 setup_xfail "powerpc-*-*" 1804
437 # OBSOLETE setup_xfail "a29k-*-udi"
438 setup_xfail_format "DWARF 1"
439 setup_xfail_format "COFF"
440 send_gdb "list list0.h:foo\n"
442 -re "2\[ \t\]+including file. This.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
445 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
448 -re "3\[ \t\]+.*12\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
451 -re "No source file named list0.h.\r\n$gdb_prompt $" {
452 fail "list list0.h:foo"
454 -re ".*$gdb_prompt $" { fail "list list0.h:foo" }
455 timeout { fail "list list0.h:foo (timeout)" }
458 # Ultrix gdb is the second case.
459 # OBSOLETE # a29k-amd-udi is the third case.
460 send_gdb "list list1.c:bar\n"
462 -re "4\[ \t\]+void.*13\[ \t\]+\}\r\n$gdb_prompt $" {
465 -re "4\[ \t\]+void.*12\[ \t\]*long_line ..;\r\n$gdb_prompt $" {
468 -re "4\[ \t\]+void.*11\[ \t\]*\r\n$gdb_prompt $" {
471 -re ".*$gdb_prompt $" { fail "list list1.c:bar" }
472 timeout { fail "list list1.c:bar (timeout)" }
475 # The i960 is a second case
476 # OBSOLETE # The a29k-amd-udi is a second case
478 # Not sure what the point of having this function be unused is.
479 # AIX is legitimately removing it.
480 setup_xfail "rs6000-*-aix*"
481 send_gdb "list list1.c:unused\n"
483 -re "12\[ \t\]+long_line \[(\]\[)\];.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
486 -re "14.*19\[ \t\]+\}\r\n.*$gdb_prompt $" {
489 -re ".*$gdb_prompt $" { fail "list list1.c:unused" }
490 timeout { fail "list list1.c:unused (timeout)" }
492 clear_xfail "rs6000-*-aix*"
494 pass "list filename:function ($testcnt tests)"
496 # Test some invalid specs
497 # The following test takes the FIXME result on most systems using
498 # DWARF. It fails to notice that main() is not in the file requested.
502 # Does this actually work ANYWHERE? I believe not, as this is an `aspect' of
503 # lookup_symbol(), where, when it is given a specific symtab which does not
504 # contain the requested symbol, it will subsequently search all of the symtabs
505 # for the requested symbol.
507 gdb_test "list list0.c:foo" "Function \"foo\" not defined in .*list0.c" "list filename:function; wrong filename rejected"
509 gdb_test "list foobar.c:main" "No source file named foobar.c.|Location not found" "list filename:function; nonexistant file"
511 setup_xfail_format "DWARF 1"
512 gdb_test "list list0.h:foobar" "Function \"foobar\" not defined.|Location not found" "list filename:function; nonexistant function"
516 proc test_forward_search {} {
519 gdb_test "set listsize 4" ""
520 # On SunOS4, this gives us lines 19-22. On AIX, it gives us
521 # lines 20-23. This depends on whether the line number of a function
522 # is considered to be the openbrace or the first statement--either one
524 gdb_test "list long_line" "24\[ \t\]+long_line .*"
526 gdb_test "search 4321" " not found"
528 gdb_test "search 6789" "28\[ \t\]+oof .6789.;"
530 # Test that GDB won't crash if the line being searched is extremely long.
532 set oldtimeout $timeout
533 set timeout [expr "$timeout + 300"]
534 verbose "Timeout is now $timeout seconds" 2
535 gdb_test "search 1234" ".*1234.*" "search extremely long line (> 5000 chars)"
536 set timeout $oldtimeout
537 verbose "Timeout is now $timeout seconds" 2
540 # Start with a fresh gdb.
544 gdb_reinitialize_dir $srcdir/$subdir
547 if [target_info exists gdb_stub] {
551 gdb_test "set width 0" "" "set width 0"
555 if [ set_listsize 10 ] then {
556 test_list_include_file
557 test_list_filename_and_number
561 test_repeat_list_command
563 test_list_filename_and_function
567 remote_exec build "rm -f list0.h"