1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2002, 2003, 2007, 2008
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 3 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, see <http://www.gnu.org/licenses/>.
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
36 if { [gdb_compile "${srcdir}/${subdir}/list0.c" "${binfile}0.o" object {debug}] != "" } {
41 if { [gdb_compile "${srcdir}/${subdir}/list1.c" "${binfile}1.o" object {debug}] != "" } {
46 if { [gdb_compile "${binfile}0.o ${binfile}1.o" ${binfile} executable {debug}] != "" } {
53 # Create and source the file that provides information about the compiler
54 # used to compile the test case.
55 if [get_compiler_info ${binfile}] {
60 # Local utility proc just to set and verify listsize
61 # Return 1 if success, 0 if fail.
64 set set_listsize_count 0;
66 proc set_listsize { arg } {
68 global set_listsize_count;
70 incr set_listsize_count;
71 if [gdb_test "set listsize $arg" "" "setting listsize to $arg #$set_listsize_count"] {
78 if [gdb_test "show listsize" "Number of source lines.* is ${arg}.*" "show listsize $arg #$set_listsize_count"] {
85 # Test display of listsize lines around a given line number.
88 proc test_listsize {} {
91 global hp_aCC_compiler
95 gdb_test "show listsize" "Number of source lines gdb will list by default is 10.*" "show default list size"
97 # Show the default lines
98 # Note that remote targets that have debugging info for _start available will
99 # list the lines there instead of main, so we skip this test for remote targets.
100 # The second case is for optimized code, it is still correct.
102 if [is_remote target] {
104 unsupported "list default lines around main";
106 gdb_test "list" "(1\[ \t\]+#include \"list0.h\".*10\[ \t\]+x = 0;|2.*11\[ \t\]+foo .x\[+)\]+;)" "list default lines around main"
109 # Ensure we can limit printouts to one line
111 if [set_listsize 1] {
112 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"" "list line 1 with listsize 1"
113 gdb_test "list 2" "2\[ \t\]+" "list line 2 with listsize 1"
118 if [ set_listsize 2 ] {
119 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 1 with listsize 2"
120 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 2 with listsize 2"
121 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+" "list line 3 with listsize 2"
124 # Try small listsize > 1 that is an odd number
126 if [ set_listsize 3 ] {
127 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 1 with listsize 3"
128 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 2 with listsize 3"
129 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[(\]+\[)\]+\r\n4\[ \t\]+\{" "list line 3 with listsize 3"
132 # Try small listsize > 2 that is an even number.
134 if [ set_listsize 4 ] then {
135 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 1 with listsize 4"
136 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 2 with listsize 4"
138 gdb_test "list 3" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 3 with listsize 4"
139 gdb_test "list 4" "2\[ \t\]+\r\n.*5\[ \t\]+int x;.*" "list line 4 with listsize 4"
142 # Try a size larger than the entire file.
144 if [ set_listsize 100 ] then {
145 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*\r\n4\[23\]\[ \t\]+\}" "list line 1 with listsize 100"
147 gdb_test "list 10" "1\[ \t\]+#include \"list0.h\".*\r\n4\[23\]\[ \t\]+\}" "list line 10 with listsize 100"
150 # Try listsize of 0 which suppresses printing.
153 gdb_test "list 1" "" "listsize of 0 suppresses output"
155 # Try listsize of -1 which is special, and means unlimited.
159 gdb_test "list 1" "1\[ \t\]+#include .*\r\n39\[ \t\]+\}" "list line 1 with unlimited listsize"
163 # Test "list filename:number" for C include file
166 proc test_list_include_file {} {
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 setup_xfail_format "COFF"
173 gdb_test "list list0.h:100" "Line number 95 out of range; .*list0.h has 3\[67\] lines." "list message for lines past EOF"
177 # Test "list filename:number" for C source file
180 proc test_list_filename_and_number {} {
185 send_gdb "list list0.c:1\n"
187 -re "1\[ \t\]+#include \"list0.h\".*10\[ \t]+x = 0;\r\n$gdb_prompt $" {
190 -re ".*$gdb_prompt $" { fail "list list0.c:1" ; gdb_suppress_tests }
191 timeout { fail "list list0.c:1 (timeout)" ; gdb_suppress_tests }
193 send_gdb "list list0.c:10\n"
195 -re "5\[ \t\]+int x;.*14\[ \t\]+foo .x\[+)\]+;\r\n$gdb_prompt $" {
198 -re ".*$gdb_prompt $" { fail "list list.c:10" ; gdb_suppress_tests }
199 timeout { fail "list list.c:10 (timeout)" ; gdb_suppress_tests }
201 send_gdb "list list1.c:1\n"
203 -re "1\[ \t\]+\#include.*4\[ \t\]+.*int oof\[ \t\]*\(.*\);\r\n.*$gdb_prompt $" {
206 -re ".*$gdb_prompt $" { fail "list list1.c:1" ; gdb_suppress_tests }
207 timeout { fail "list list1.c:1 (timeout)" ; gdb_suppress_tests }
209 send_gdb "list list1.c:12\n"
211 -re "12\[ \t\]+long_line \[(\]+.*\[)\]+;.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
214 -re ".*$gdb_prompt $" { fail "list list1.c:12" ; gdb_suppress_tests }
215 timeout { fail "list list1.c:12 (timeout)" ; gdb_suppress_tests }
217 pass "list filename:number ($testcnt tests)"
218 gdb_stop_suppressing_tests;
222 # Test "list function" for C source file
225 proc test_list_function {} {
228 # gcc appears to generate incorrect debugging information for code
229 # in include files, which breaks this test.
230 # SunPRO cc is the second case below, it's also correct.
231 gdb_test "list main" "(5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;|1\[ \t\]+#include .*10\[ \t\]+x = 0;)" "list function in source file 1"
233 # Ultrix gdb takes the second case below; it's also correct.
234 # SunPRO cc is the third case.
235 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"
237 # Test "list function" for C include file
238 # Ultrix gdb is the second case, still correct.
239 # SunPRO cc is the third case.
240 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"
243 proc test_list_forward {} {
248 send_gdb "list list0.c:10\n"
250 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
251 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
252 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
257 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
258 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
259 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
264 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
265 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
266 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
271 -re "35\[ \t\]+foo \\(.*\\);.*42\[ \t\]+.*\}\r\n$gdb_prompt $" { incr testcnt }
272 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
273 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
276 pass "successive list commands to page forward ($testcnt tests)"
277 gdb_stop_suppressing_tests;
280 # Test that repeating the list linenum command doesn't print the same
281 # lines over again. Note that this test makes sure that the argument
282 # linenum is dropped, when we repeat the previous command. 'x/5i $pc'
283 # works the same way.
285 proc test_repeat_list_command {} {
290 send_gdb "list list0.c:10\n"
292 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
293 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
294 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
299 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
300 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
301 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
306 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
307 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
308 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
313 -re "35\[ \t\]+foo \\(.*\\);.*42\[ \t\]+.*\}\r\n$gdb_prompt $" { incr testcnt }
314 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
315 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
318 pass "repeat list commands to page forward using 'return' ($testcnt tests)"
319 gdb_stop_suppressing_tests;
322 proc test_list_backwards {} {
327 send_gdb "list list0.c:33\n"
329 -re "28\[ \t\]+foo \\(.*\\);.*37\[ \t\]+\}\r\n$gdb_prompt $" { incr testcnt }
330 -re ".*$gdb_prompt $" { fail "list list0.c:33" ; gdb_suppress_tests }
331 timeout { fail "list list0.c:33 (timeout)" ; gdb_suppress_tests }
336 -re "18\[ \t\]+foo \[(\]+.*\[)\]+;.*27\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
337 -re ".*$gdb_prompt $" { fail "list 18-27" ; gdb_suppress_tests }
338 timeout { fail "list 18-27 (timeout)" ; gdb_suppress_tests }
343 -re "8\[ \t\]+breakpoint\[(\]\[)\];.*17\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
344 -re ".*$gdb_prompt $" { fail "list 8-17" ; gdb_suppress_tests }
345 timeout { fail "list 8-17 (timeout)" ; gdb_suppress_tests }
350 -re "1\[ \t\]+#include .*7\[ \t\]+set_debug_traps\[(\]\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
351 -re ".*$gdb_prompt $" { fail "list 1-7" ; gdb_suppress_tests }
352 timeout { fail "list 1-7 (timeout)" ; gdb_suppress_tests }
355 pass "$testcnt successive \"list -\" commands to page backwards"
356 gdb_stop_suppressing_tests;
360 # Test "list first,last"
363 proc test_list_range {} {
366 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"
368 gdb_test "list 2,5" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+.*5\[ \t\]+int x;" "list range; line1,line2"
370 # gdb_test "list -1,6" "Line number 0 out of range; .*list0.c has 39 lines." "list range; lower bound negative"
372 # gdb_test "list -100,-40" "Line number -60 out of range; .*list0.c has 39 lines." "list range; both bounds negative"
374 gdb_test "list 30,45" "30\[ \t\]+foo \(.*\);.*43\[ \t\]+\}" "list range; upper bound past EOF"
376 gdb_test "list 45,100" "Line number 45 out of range; .*list0.c has 43 lines." "list range; both bounds past EOF"
378 gdb_test "list list0.c:2,list1.c:17" "Specified start and end are in different files." "list range, must be same files"
382 # Test "list filename:function"
385 proc test_list_filename_and_function {} {
390 # gcc appears to generate incorrect debugging information for code
391 # in include files, which breaks this test.
392 # SunPRO cc is the second case below, it's also correct.
393 send_gdb "list list0.c:main\n"
395 -re "1\[ \t\]+#include .*10\[ \t\]+x = 0;\r\n$gdb_prompt $" {
398 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
399 pass "list function in source file 1"
401 -re ".*$gdb_prompt $" { fail "list list0.c:main" }
402 timeout { fail "list list0.c:main (timeout)" }
405 # Not sure what the point of having this function be unused is.
406 # AIX is legitimately removing it.
407 setup_xfail "rs6000-*-aix*"
408 send_gdb "list list0.c:unused\n"
410 -re "40\[ \t\]+unused.*43\[ \t\]+\}\r\n$gdb_prompt $" {
413 -re "37.*42\[ \t\]+\}\r\n$gdb_prompt $" {
416 -re ".*$gdb_prompt $" { fail "list list0.c:unused" }
417 timeout { fail "list list0.c:unused (timeout)" }
419 clear_xfail "rs6000-*-aix*"
421 # gcc appears to generate incorrect debugging information for code
422 # in include files, which breaks this test.
423 # Ultrix gdb is the second case, one line different but still correct.
424 # SunPRO cc is the third case.
425 setup_xfail "rs6000-*-*" 1804
426 setup_xfail_format "COFF"
427 send_gdb "list list0.h:foo\n"
429 -re "2\[ \t\]+including file. This.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
432 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
435 -re "3\[ \t\]+.*12\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
438 -re "No source file named list0.h.\r\n$gdb_prompt $" {
439 fail "list list0.h:foo"
441 -re ".*$gdb_prompt $" { fail "list list0.h:foo" }
442 timeout { fail "list list0.h:foo (timeout)" }
445 # Ultrix gdb is the second case.
446 send_gdb "list list1.c:bar\n"
448 -re "4\[ \t\]+void.*13\[ \t\]+\}\r\n$gdb_prompt $" {
451 -re "4\[ \t\]+void.*12\[ \t\]*long_line ..;\r\n$gdb_prompt $" {
454 -re "4\[ \t\]+void.*11\[ \t\]*\r\n$gdb_prompt $" {
457 -re ".*$gdb_prompt $" { fail "list list1.c:bar" }
458 timeout { fail "list list1.c:bar (timeout)" }
461 # Not sure what the point of having this function be unused is.
462 # AIX is legitimately removing it.
463 setup_xfail "rs6000-*-aix*"
464 send_gdb "list list1.c:unused\n"
466 -re "12\[ \t\]+long_line \[(\]\[)\];.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
469 -re "14.*19\[ \t\]+\}\r\n.*$gdb_prompt $" {
472 -re ".*$gdb_prompt $" { fail "list list1.c:unused" }
473 timeout { fail "list list1.c:unused (timeout)" }
475 clear_xfail "rs6000-*-aix*"
477 pass "list filename:function ($testcnt tests)"
479 # Test some invalid specs
480 # The following test takes the FIXME result on most systems using
481 # DWARF. It fails to notice that main() is not in the file requested.
485 # Does this actually work ANYWHERE? I believe not, as this is an `aspect' of
486 # lookup_symbol(), where, when it is given a specific symtab which does not
487 # contain the requested symbol, it will subsequently search all of the symtabs
488 # for the requested symbol.
490 gdb_test "list list0.c:foo" "Function \"foo\" not defined in .*list0.c" "list filename:function; wrong filename rejected"
492 gdb_test "list foobar.c:main" "No source file named foobar.c.|Location not found" "list filename:function; nonexistant file"
494 gdb_test "list list0.h:foobar" "Function \"foobar\" not defined.|Location not found" "list filename:function; nonexistant function"
498 proc test_forward_search {} {
501 gdb_test "set listsize 4" ""
502 # On SunOS4, this gives us lines 19-22. On AIX, it gives us
503 # lines 20-23. This depends on whether the line number of a function
504 # is considered to be the openbrace or the first statement--either one
506 gdb_test "list long_line" "24\[ \t\]+long_line .*"
508 gdb_test "search 4321" " not found"
510 gdb_test "search 6789" "28\[ \t\]+oof .6789.;"
512 # Test that GDB won't crash if the line being searched is extremely long.
514 set oldtimeout $timeout
515 set timeout [expr "$timeout + 300"]
516 verbose "Timeout is now $timeout seconds" 2
517 gdb_test "search 1234" ".*1234.*" "search extremely long line (> 5000 chars)"
518 set timeout $oldtimeout
519 verbose "Timeout is now $timeout seconds" 2
522 # Start with a fresh gdb.
526 gdb_reinitialize_dir $srcdir/$subdir
529 if [target_info exists gdb_stub] {
533 gdb_test "set width 0" "" "set width 0"
537 if [ set_listsize 10 ] then {
538 test_list_include_file
539 test_list_filename_and_number
543 test_repeat_list_command
545 test_list_filename_and_function
549 remote_exec build "rm -f list0.h"