1 # Copyright (C) 1992, 1994, 1995, 1997 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 binfile ${objdir}/${subdir}/${testfile}
32 # Need to download the header to the host.
33 remote_download host ${srcdir}/${subdir}/list0.h list0.h
35 if { [gdb_compile "${srcdir}/${subdir}/list0.c ${srcdir}/${subdir}/list1.c" ${binfile} executable {debug}] != "" } {
36 perror "Couldn't compile list0.c list1.c to executable ${binfile}"
40 # Create and source the file that provides information about the compiler
41 # used to compile the test case.
42 if [get_compiler_info ${binfile}] {
47 # Local utility proc just to set and verify listsize
48 # Return 1 if success, 0 if fail.
51 proc set_listsize { arg } {
54 if [gdb_test "set listsize $arg" "" "setting listsize to $arg"] {
61 if [gdb_test "show listsize" "Number of source lines.* is ${arg}.*" "show listsize $arg"] {
68 # Test display of listsize lines around a given line number.
71 proc test_listsize {} {
76 gdb_test "show listsize" "Number of source lines gdb will list by default is 10.*" "show default list size"
78 # Show the default lines
79 # The second case is for optimized code, it is still correct.
81 # This doesn't work for COFF targets.
82 setup_xfail "a29k-*-udi"
84 if [target_info exists gdb,start_symbol] {
85 set startsym [target_info gdb,start_symbol];
89 gdb_test "set \$pc=$startsym" "" ""
91 gdb_test "list" "(1\[ \t\]+#include \"list0.h\".*10\[ \t\]+x = 0;|2.*11\[ \t\]+foo .x\[+)\]+;)" "list default lines around main"
93 # Ensure we can limit printouts to one line
95 if [ set_listsize 1 ] then {
97 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"" "list line 1 with listsize 1"
99 gdb_test "list 2" "2\[ \t\]+" "list line 2 with listsize 1"
104 if [ set_listsize 2 ] {
105 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"" "list line 1 with listsize 2"
106 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 2 with listsize 2"
107 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+" "list line 3 with listsize 2"
110 # Try small listsize > 1 that is an odd number
112 if [ set_listsize 3 ] {
114 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"2\[ \t\]+" "list line 1 with listsize 3"
116 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+main \[)(\]+" "list line 2 with listsize 3"
119 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+main \[(\]+\[)\]+\r\n4\[ \t\]+\{" "list line 3 with listsize 3"
122 # Try small listsize > 2 that is an even number.
124 if [ set_listsize 4 ] then {
125 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 1 with listsize 4"
126 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+main \[)(\]+" "list line 2 with listsize 4"
128 gdb_test "list 3" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 3 with listsize 4"
129 gdb_test "list 4" "2\[ \t\]+\r\n.*5\[ \t\]+int x;.*" "list line 4 with listsize 4"
132 # Try a size larger than the entire file.
134 if [ set_listsize 100 ] then {
135 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*\r\n42\[ \t\]+\}" "list line 1 with listsize 100"
137 gdb_test "list 10" "1\[ \t\]+#include \"list0.h\".*\r\n42\[ \t\]+\}" "list line 10 with listsize 100"
140 # Try listsize of 0 which suppresses printing.
143 gdb_test "list 1" "" "listsize of 0 suppresses output"
145 # Try listsize of -1 which is special, and means unlimited.
149 gdb_test "list 1" "1\[ \t\]+#include .*\r\n39\[ \t\]+\}" "list line 1 with unlimited listsize"
153 # Test "list filename:number" for C include file
156 proc test_list_include_file {} {
159 setup_xfail "a29k-*-udi"
160 setup_xfail_format "DWARF 1"
161 setup_xfail_format "COFF"
162 gdb_test "list list0.h:1" "1\[ \t\]+/\[*\]+ An include file .*5\[ \t\]+foo \[(\]+x\[)\]+" "list line 1 in include file"
164 setup_xfail "a29k-*-udi"
165 setup_xfail_format "DWARF 1"
166 setup_xfail_format "COFF"
167 gdb_test "list list0.h:100" "Line number 95 out of range; .*list0.h has 36 lines." "list message for lines past EOF"
171 # Test "list filename:number" for C source file
174 proc test_list_filename_and_number {} {
179 send_gdb "list list0.c:1\n"
181 -re "1\[ \t\]+#include \"list0.h\".*5\[ \t\]+int x;\r\n$gdb_prompt $" {
184 -re ".*$gdb_prompt $" { fail "list list0.c:1" ; gdb_suppress_tests }
185 timeout { fail "list list0.c:1 (timeout)" ; gdb_suppress_tests }
187 send_gdb "list list0.c:10\n"
189 -re "5\[ \t\]+int x;.*14\[ \t\]+foo .x\[+)\]+;\r\n$gdb_prompt $" {
192 -re ".*$gdb_prompt $" { fail "list list.c:10" ; gdb_suppress_tests }
193 timeout { fail "list list.c:10 (timeout)" ; gdb_suppress_tests }
195 send_gdb "list list1.c:1\n"
197 -re "1\[ \t\]+void.*5\[ \t\]+printf \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
200 -re ".*$gdb_prompt $" { fail "list list1.c:1" ; gdb_suppress_tests }
201 timeout { fail "list list1.c:1 (timeout)" ; gdb_suppress_tests }
203 send_gdb "list list1.c:12\n"
205 -re "7\[ \t\]+long_line \[(\]+.*\[)\]+;.*14\[ \t\]+\}\r\n.*$gdb_prompt $" {
208 -re ".*$gdb_prompt $" { fail "list list1.c:12" ; gdb_suppress_tests }
209 timeout { fail "list list1.c:12 (timeout)" ; gdb_suppress_tests }
211 pass "list filename:number ($testcnt tests)"
212 gdb_stop_suppressing_tests;
216 # Test "list function" for C source file
219 proc test_list_function {} {
223 # gcc appears to generate incorrect debugging information for code
224 # in include files, which breaks this test.
225 # SunPRO cc is the second case below, it's also correct.
226 setup_xfail "a29k-*-udi"
227 gdb_test "list main" "(5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;|1\[ \t\]+#include .*8\[ \t\]+breakpoint\[(\]\[)\]+;)" "list function in source file 1"
229 # Ultrix gdb takes the second case below; it's also correct.
230 # SunPRO cc is the third case.
231 gdb_test "list bar" "(1\[ \t\]+void.*7\[ \t\]*long_line ..;.*9\[ \t\]*|1\[ \t\]+void.*8\[ \t\]+\}|1\[ \t\]+void.*7\[ \t\]*long_line ..;)" "list function in source file 2"
233 # Test "list function" for C include file
234 # Ultrix gdb is the second case, still correct.
235 # SunPRO cc is the third case.
236 setup_xfail "powerpc-*-*"
237 setup_xfail_format "DWARF 1"
238 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"
241 proc test_list_forward {} {
246 send_gdb "list list0.c:10\n"
248 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
249 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
250 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
255 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
256 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
257 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
262 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
263 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
264 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
269 -re "35\[ \t\]+foo \[(\]+.*\[)\]+;.*42\[ \t\]+\}\r\n$gdb_prompt $" { incr testcnt }
270 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
271 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
274 pass "successive list commands to page forward ($testcnt tests)"
275 gdb_stop_suppressing_tests;
278 proc test_list_backwards {} {
283 send_gdb "list list0.c:33\n"
285 -re "28\[ \t\]+foo \[(\]+.*\[)\]+;.*37\[ \t\]+\r\n$gdb_prompt $" { incr testcnt }
286 -re ".*$gdb_prompt $" { fail "list list0.c:33" ; gdb_suppress_tests }
287 timeout { fail "list list0.c:33 (timeout)" ; gdb_suppress_tests }
292 -re "18\[ \t\]+foo \[(\]+.*\[)\]+;.*27\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
293 -re ".*$gdb_prompt $" { fail "list 18-27" ; gdb_suppress_tests }
294 timeout { fail "list 18-27 (timeout)" ; gdb_suppress_tests }
299 -re "8\[ \t\]+breakpoint\[(\]\[)\];.*17\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
300 -re ".*$gdb_prompt $" { fail "list 8-17" ; gdb_suppress_tests }
301 timeout { fail "list 8-17 (timeout)" ; gdb_suppress_tests }
306 -re "1\[ \t\]+#include .*7\[ \t\]+set_debug_traps\[(\]\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
307 -re ".*$gdb_prompt $" { fail "list 1-7" ; gdb_suppress_tests }
308 timeout { fail "list 1-7 (timeout)" ; gdb_suppress_tests }
311 pass "$testcnt successive \"list -\" commands to page backwards"
312 gdb_stop_suppressing_tests;
316 # Test "list first,last"
319 proc test_list_range {} {
322 gdb_test "list list0.c:2,list0.c:5" "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+.*5\[ \t\]+int x;" "list range; filename:line1,filename:line2"
324 gdb_test "list 2,5" "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+.*5\[ \t\]+int x;" "list range; line1,line2"
326 # gdb_test "list -1,6" "Line number 0 out of range; .*list0.c has 39 lines." "list range; lower bound negative"
328 # gdb_test "list -100,-40" "Line number -60 out of range; .*list0.c has 39 lines." "list range; both bounds negative"
330 gdb_test "list 30,43" "30\[ \t\]+foo \[(\]+.*\[)\]+;.*42\[ \t\]+\}" "list range; upper bound past EOF"
332 gdb_test "list 43,100" "Line number 43 out of range; .*list0.c has 42 lines." "list range; both bounds past EOF"
334 gdb_test "list list0.c:2,list1.c:17" "Specified start and end are in different files." "list range, must be same files"
338 # Test "list filename:function"
341 proc test_list_filename_and_function {} {
346 # gcc appears to generate incorrect debugging information for code
347 # in include files, which breaks this test.
348 # SunPRO cc is the second case below, it's also correct.
349 setup_xfail "a29k-*-udi"
350 send_gdb "list list0.c:main\n"
352 -re "1\[ \t\]+#include .*8\[ \t\]+breakpoint\[(\]\[)\]+;\r\n$gdb_prompt $" {
355 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
356 pass "list function in source file 1"
358 -re ".*$gdb_prompt $" { fail "list list0.c:main" }
359 timeout { fail "list list0.c:main (timeout)" }
362 # The i960 and a29k-amd-udi are the second case
364 # Not sure what the point of having this function be unused is.
365 # AIX is legitimately removing it.
366 setup_xfail "rs6000-*-aix*"
367 send_gdb "list list0.c:unused\n"
369 -re "36\[ \t\]+\}.*42\[ \t\]+\}\r\n$gdb_prompt $" {
372 -re "37.*42\[ \t\]+\}\r\n$gdb_prompt $" {
375 -re ".*$gdb_prompt $" { fail "list list0.c:unused" }
376 timeout { fail "list list0.c:unused (timeout)" }
378 clear_xfail "rs6000-*-aix*"
380 # gcc appears to generate incorrect debugging information for code
381 # in include files, which breaks this test.
382 # Ultrix gdb is the second case, one line different but still correct.
383 # SunPRO cc is the third case.
384 setup_xfail "rs6000-*-*" 1804
385 setup_xfail "powerpc-*-*" 1804
386 setup_xfail "a29k-*-udi"
387 setup_xfail_format "DWARF 1"
388 setup_xfail_format "COFF"
389 send_gdb "list list0.h:foo\n"
391 -re "2\[ \t\]+including file. This.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
394 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
397 -re "3\[ \t\]+.*12\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
400 -re "No source file named list0.h.\r\n$gdb_prompt $" {
401 fail "list list0.h:foo"
403 -re ".*$gdb_prompt $" { fail "list list0.h:foo" }
404 timeout { fail "list list0.h:foo (timeout)" }
407 # Ultrix gdb is the second case.
408 # a29k-amd-udi is the third case.
409 send_gdb "list list1.c:bar\n"
411 -re "1\[ \t\]+void.*8\[ \t\]+\}\r\n$gdb_prompt $" {
414 -re "1\[ \t\]+void.*7\[ \t\]*long_line ..;\r\n$gdb_prompt $" {
417 -re "1\[ \t\]+void.*9\[ \t\]*\r\n$gdb_prompt $" {
420 -re ".*$gdb_prompt $" { fail "list list1.c:bar" }
421 timeout { fail "list list1.c:bar (timeout)" }
424 # The i960 and a29k-amd-udi are the second case
426 # Not sure what the point of having this function be unused is.
427 # AIX is legitimately removing it.
428 setup_xfail "rs6000-*-aix*"
429 send_gdb "list list1.c:unused\n"
431 -re "7\[ \t\]+long_line \[(\]\[)\];.*14\[ \t\]+\}\r\n.*$gdb_prompt $" {
434 -re "9.*14\[ \t\]+\}\r\n.*$gdb_prompt $" {
437 -re ".*$gdb_prompt $" { fail "list list1.c:unused" }
438 timeout { fail "list list1.c:unused (timeout)" }
440 clear_xfail "rs6000-*-aix*"
442 pass "list filename:function ($testcnt tests)"
444 # Test some invalid specs
445 # The following test takes the FIXME result on most systems using
446 # DWARF. It fails to notice that main() is not in the file requested.
450 # Does this actually work ANYWHERE? I believe not, as this is an `aspect' of
451 # lookup_symbol(), where, when it is given a specific symtab which does not
452 # contain the requested symbol, it will subsequently search all of the symtabs
453 # for the requested symbol.
455 gdb_test "list list0.c:foo" "Function \"foo\" not defined in .*list0.c" "list filename:function; wrong filename rejected"
457 gdb_test "list foobar.c:main" "No source file named foobar.c." "list filename:function; nonexistant file"
459 setup_xfail_format "DWARF 1"
460 gdb_test "list list0.h:foobar" "Function \"foobar\" not defined." "list filename:function; nonexistant function"
464 proc test_forward_search {} {
467 gdb_test "set listsize 4" ""
468 # On SunOS4, this gives us lines 19-22. On AIX, it gives us
469 # lines 20-23. This depends on whether the line number of a function
470 # is considered to be the openbrace or the first statement--either one
472 gdb_test "list long_line" "20\[ \t\]+long_line .*"
474 gdb_test "search 4321" " not found"
476 gdb_test "search 6789" "24\[ \t\]+oof .6789.;"
478 # Test that GDB won't crash if the line being searched is extremely long.
480 set oldtimeout $timeout
481 set timeout [expr "$timeout + 300"]
482 verbose "Timeout is now $timeout seconds" 2
483 gdb_test "search 1234" ".*1234.*" "search extremely long line (> 5000 chars)"
484 set timeout $oldtimeout
485 verbose "Timeout is now $timeout seconds" 2
488 # Start with a fresh gdb.
492 gdb_reinitialize_dir $srcdir/$subdir
495 if [target_info exists gdb_stub] {
497 # if use stubs step out of the breakpoint() function.
499 -re "main.* at .*$gdb_prompt $" {}
500 -re ".*in .*start.*$gdb_prompt $" {}
501 timeout { fail "single step at breakpoint() (timeout)" }
505 gdb_test "set width 0" "" "set width 0"
509 if [ set_listsize 10 ] then {
510 test_list_include_file
511 test_list_filename_and_number
516 test_list_filename_and_function