1 # Copyright 1992, 1994-1999, 2002-2003, 2007-2012 Free Software
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 # This file was written by Fred Fish. (fnf@cygnus.com)
21 set binfile ${objdir}/${subdir}/${testfile}
23 # Need to download the header to the host.
24 remote_download host ${srcdir}/${subdir}/list0.h list0.h
27 if { [gdb_compile "${srcdir}/${subdir}/list0.c" "${binfile}0.o" object {debug}] != "" } {
32 if { [gdb_compile "${srcdir}/${subdir}/list1.c" "${binfile}1.o" object {debug}] != "" } {
37 if { [gdb_compile "${binfile}0.o ${binfile}1.o" ${binfile} executable {debug}] != "" } {
44 # Create and source the file that provides information about the compiler
45 # used to compile the test case.
46 if [get_compiler_info ${binfile}] {
51 # Local utility proc just to set and verify listsize
52 # Return 1 if success, 0 if fail.
55 set set_listsize_count 0;
57 proc set_listsize { arg } {
59 global set_listsize_count;
61 incr set_listsize_count;
62 if [gdb_test "set listsize $arg" ".*" "setting listsize to $arg #$set_listsize_count"] {
69 if [gdb_test "show listsize" "Number of source lines.* is ${arg}.*" "show listsize $arg #$set_listsize_count"] {
76 # Test display of listsize lines around a given line number.
79 proc test_listsize {} {
82 global hp_aCC_compiler
86 gdb_test "show listsize" "Number of source lines gdb will list by default is 10.*" "show default list size"
88 # Show the default lines
90 gdb_test "list" "(1\[ \t\]+#include \"list0.h\".*7\[ \t\]+x = 0;\r\n.*10\[ \t\]+foo .x\[+)\]+;)" "list default lines around main"
92 # Ensure we can limit printouts to one line
95 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"" "list line 1 with listsize 1"
96 gdb_test "list 2" "2\[ \t\]+" "list line 2 with listsize 1"
101 if [ set_listsize 2 ] {
102 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 1 with listsize 2"
103 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 2 with listsize 2"
104 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+" "list line 3 with listsize 2"
107 # Try small listsize > 1 that is an odd number
109 if [ set_listsize 3 ] {
110 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 1 with listsize 3"
111 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 2 with listsize 3"
112 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[(\]+\[)\]+\r\n4\[ \t\]+\{" "list line 3 with listsize 3"
115 # Try small listsize > 2 that is an even number.
117 if [ set_listsize 4 ] then {
118 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 1 with listsize 4"
119 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 2 with listsize 4"
121 gdb_test "list 3" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 3 with listsize 4"
122 gdb_test "list 4" "2\[ \t\]+\r\n.*5\[ \t\]+int x;.*" "list line 4 with listsize 4"
125 # Try a size larger than the entire file.
127 if [ set_listsize 100 ] then {
128 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*\r\n4\[23\]\[ \t\]+\}" "list line 1 with listsize 100"
130 gdb_test "list 10" "1\[ \t\]+#include \"list0.h\".*\r\n4\[23\]\[ \t\]+\}" "list line 10 with listsize 100"
133 # Try listsize of 0 which suppresses printing.
136 gdb_test "list 1" "" "listsize of 0 suppresses output"
138 # Try listsize of -1 which is special, and means unlimited.
142 gdb_test "list 1" "1\[ \t\]+#include .*\r\n39\[ \t\]+\}" "list line 1 with unlimited listsize"
146 # Test "list filename:number" for C include file
149 proc test_list_include_file {} {
152 setup_xfail_format "COFF"
153 gdb_test "list list0.h:1" "1\[ \t\]+/\[*\]+ An include file .*10\[ \t\]+bar \\(x\\+\\+\\);" "list line 1 in include file"
155 setup_xfail_format "COFF"
156 gdb_test "list list0.h:100" "Line number 95 out of range; .*list0.h has 3\[67\] lines." "list message for lines past EOF"
160 # Test "list filename:number" for C source file
163 proc test_list_filename_and_number {} {
168 send_gdb "list list0.c:1\n"
170 -re "1\[ \t\]+#include \"list0.h\".*10\[ \t\]+foo .x\[+)\]+;\r\n$gdb_prompt $" {
173 -re ".*$gdb_prompt $" { fail "list list0.c:1" ; gdb_suppress_tests }
174 timeout { fail "list list0.c:1 (timeout)" ; gdb_suppress_tests }
176 send_gdb "list list0.c:10\n"
178 -re "5\[ \t\]+int x;.*14\[ \t\]+foo .x\[+)\]+;\r\n$gdb_prompt $" {
181 -re ".*$gdb_prompt $" { fail "list list.c:10" ; gdb_suppress_tests }
182 timeout { fail "list list.c:10 (timeout)" ; gdb_suppress_tests }
184 send_gdb "list list1.c:1\n"
186 -re "1\[ \t\]+\#include.*4\[ \t\]+.*int oof\[ \t\]*\(.*\);\r\n.*$gdb_prompt $" {
189 -re ".*$gdb_prompt $" { fail "list list1.c:1" ; gdb_suppress_tests }
190 timeout { fail "list list1.c:1 (timeout)" ; gdb_suppress_tests }
192 send_gdb "list list1.c:12\n"
194 -re "12\[ \t\]+long_line \[(\]+.*\[)\]+;.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
197 -re ".*$gdb_prompt $" { fail "list list1.c:12" ; gdb_suppress_tests }
198 timeout { fail "list list1.c:12 (timeout)" ; gdb_suppress_tests }
200 pass "list filename:number ($testcnt tests)"
201 gdb_stop_suppressing_tests;
205 # Test "list function" for C source file
208 proc test_list_function {} {
211 # gcc appears to generate incorrect debugging information for code
212 # in include files, which breaks this test.
213 # SunPRO cc is the second case below, it's also correct.
214 gdb_test "list main" "(5\[ \t\]+int x;.*8\[ \t\]+foo \[(\]+.*\[)\]+;|1\[ \t\]+#include .*7\[ \t\]+x = 0;)" "list function in source file 1"
216 # Ultrix gdb takes the second case below; it's also correct.
217 # SunPRO cc is the third case.
218 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"
220 # Test "list function" for C include file
221 # Ultrix gdb is the second case, still correct.
222 # SunPRO cc is the third case.
223 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"
226 proc test_list_forward {} {
231 send_gdb "list list0.c:10\n"
233 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
234 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
235 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
240 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
241 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
242 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
247 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
248 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
249 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
254 -re "35\[ \t\]+foo \\(.*\\);.*42\[ \t\]+.*\}\r\n$gdb_prompt $" { incr testcnt }
255 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
256 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
259 pass "successive list commands to page forward ($testcnt tests)"
260 gdb_stop_suppressing_tests;
263 # Test that repeating the list linenum command doesn't print the same
264 # lines over again. Note that this test makes sure that the argument
265 # linenum is dropped, when we repeat the previous command. 'x/5i $pc'
266 # works the same way.
268 proc test_repeat_list_command {} {
273 send_gdb "list list0.c:10\n"
275 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
276 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
277 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
282 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
283 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
284 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
289 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
290 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
291 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
296 -re "35\[ \t\]+foo \\(.*\\);.*42\[ \t\]+.*\}\r\n$gdb_prompt $" { incr testcnt }
297 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
298 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
301 pass "repeat list commands to page forward using 'return' ($testcnt tests)"
302 gdb_stop_suppressing_tests;
305 proc test_list_backwards {} {
310 send_gdb "list list0.c:33\n"
312 -re "28\[ \t\]+foo \\(.*\\);.*37\[ \t\]+\}\r\n$gdb_prompt $" { incr testcnt }
313 -re ".*$gdb_prompt $" { fail "list list0.c:33" ; gdb_suppress_tests }
314 timeout { fail "list list0.c:33 (timeout)" ; gdb_suppress_tests }
319 -re "18\[ \t\]+foo \[(\]+.*\[)\]+;.*27\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
320 -re ".*$gdb_prompt $" { fail "list 18-27" ; gdb_suppress_tests }
321 timeout { fail "list 18-27 (timeout)" ; gdb_suppress_tests }
326 -re "8\[ \t\]+foo \[(\]+.*\[)\]+;.*17\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
327 -re ".*$gdb_prompt $" { fail "list 8-17" ; gdb_suppress_tests }
328 timeout { fail "list 8-17 (timeout)" ; gdb_suppress_tests }
333 -re "1\[ \t\]+#include .*7\[ \t\]+x = 0;\r\n$gdb_prompt $" { incr testcnt }
334 -re ".*$gdb_prompt $" { fail "list 1-7" ; gdb_suppress_tests }
335 timeout { fail "list 1-7 (timeout)" ; gdb_suppress_tests }
338 pass "$testcnt successive \"list -\" commands to page backwards"
339 gdb_stop_suppressing_tests;
343 # Test "list first,last"
346 proc test_list_range {} {
349 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"
351 gdb_test "list 2,5" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+.*5\[ \t\]+int x;" "list range; line1,line2"
353 # gdb_test "list -1,6" "Line number 0 out of range; .*list0.c has 39 lines." "list range; lower bound negative"
355 # gdb_test "list -100,-40" "Line number -60 out of range; .*list0.c has 39 lines." "list range; both bounds negative"
357 gdb_test "list 30,45" "30\[ \t\]+foo \(.*\);.*43\[ \t\]+\}" "list range; upper bound past EOF"
359 gdb_test "list 45,100" "Line number 45 out of range; .*list0.c has 43 lines." "list range; both bounds past EOF"
361 gdb_test "list list0.c:2,list1.c:17" "Specified start and end are in different files." "list range, must be same files"
365 # Test "list filename:function"
368 proc test_list_filename_and_function {} {
373 # gcc appears to generate incorrect debugging information for code
374 # in include files, which breaks this test.
375 # SunPRO cc is the second case below, it's also correct.
376 send_gdb "list list0.c:main\n"
378 -re "1\[ \t\]+#include .*10\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
381 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
382 pass "list function in source file 1"
384 -re ".*$gdb_prompt $" { fail "list list0.c:main" }
385 timeout { fail "list list0.c:main (timeout)" }
388 # Not sure what the point of having this function be unused is.
389 # AIX is legitimately removing it.
390 setup_xfail "rs6000-*-aix*"
391 send_gdb "list list0.c:unused\n"
393 -re "40\[ \t\]+unused.*43\[ \t\]+\}\r\n$gdb_prompt $" {
396 -re "37.*42\[ \t\]+\}\r\n$gdb_prompt $" {
399 -re ".*$gdb_prompt $" { fail "list list0.c:unused" }
400 timeout { fail "list list0.c:unused (timeout)" }
402 clear_xfail "rs6000-*-aix*"
404 # gcc appears to generate incorrect debugging information for code
405 # in include files, which breaks this test.
406 # Ultrix gdb is the second case, one line different but still correct.
407 # SunPRO cc is the third case.
408 setup_xfail "rs6000-*-*" 1804
409 setup_xfail_format "COFF"
410 send_gdb "list list0.h:foo\n"
412 -re "2\[ \t\]+including file. This.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
415 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
418 -re "3\[ \t\]+.*12\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
421 -re "No source file named list0.h.\r\n$gdb_prompt $" {
422 fail "list list0.h:foo"
424 -re ".*$gdb_prompt $" { fail "list list0.h:foo" }
425 timeout { fail "list list0.h:foo (timeout)" }
428 # Ultrix gdb is the second case.
429 send_gdb "list list1.c:bar\n"
431 -re "4\[ \t\]+void.*13\[ \t\]+\}\r\n$gdb_prompt $" {
434 -re "4\[ \t\]+void.*12\[ \t\]*long_line ..;\r\n$gdb_prompt $" {
437 -re "4\[ \t\]+void.*11\[ \t\]*\r\n$gdb_prompt $" {
440 -re ".*$gdb_prompt $" { fail "list list1.c:bar" }
441 timeout { fail "list list1.c:bar (timeout)" }
444 # Not sure what the point of having this function be unused is.
445 # AIX is legitimately removing it.
446 setup_xfail "rs6000-*-aix*"
447 send_gdb "list list1.c:unused\n"
449 -re "12\[ \t\]+long_line \[(\]\[)\];.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
452 -re "14.*19\[ \t\]+\}\r\n.*$gdb_prompt $" {
455 -re ".*$gdb_prompt $" { fail "list list1.c:unused" }
456 timeout { fail "list list1.c:unused (timeout)" }
458 clear_xfail "rs6000-*-aix*"
460 pass "list filename:function ($testcnt tests)"
463 gdb_test "list 'list0.c:main'" "int main.*"
465 # Test some invalid specs
466 # The following test takes the FIXME result on most systems using
467 # DWARF. It fails to notice that main() is not in the file requested.
471 # Does this actually work ANYWHERE? I believe not, as this is an `aspect' of
472 # lookup_symbol(), where, when it is given a specific symtab which does not
473 # contain the requested symbol, it will subsequently search all of the symtabs
474 # for the requested symbol.
476 gdb_test "list list0.c:foo" "Function \"foo\" not defined in .*list0.c" "list filename:function; wrong filename rejected"
478 gdb_test "list foobar.c:main" "No source file named foobar.c.|Location not found" "list filename:function; nonexistant file"
480 gdb_test "list list0.h:foobar" "Function \"foobar\" not defined in \"list0.h\"." "list filename:function; nonexistant function"
484 proc test_forward_search {} {
487 gdb_test_no_output "set listsize 4"
488 # On SunOS4, this gives us lines 19-22. On AIX, it gives us
489 # lines 20-23. This depends on whether the line number of a function
490 # is considered to be the openbrace or the first statement--either one
492 gdb_test "list long_line" "24\[ \t\]+long_line .*"
494 gdb_test "search 4321" " not found"
496 gdb_test "search 6789" "28\[ \t\]+oof .6789.;"
498 # Test that GDB won't crash if the line being searched is extremely long.
500 set oldtimeout $timeout
501 set timeout [expr "$timeout + 300"]
502 verbose "Timeout is now $timeout seconds" 2
503 gdb_test "search 1234" ".*1234.*" "search extremely long line (> 5000 chars)"
504 set timeout $oldtimeout
505 verbose "Timeout is now $timeout seconds" 2
508 # Start with a fresh gdb.
512 gdb_reinitialize_dir $srcdir/$subdir
513 gdb_file_cmd ${binfile}
515 gdb_test_no_output "set width 0"
519 if [ set_listsize 10 ] then {
520 test_list_include_file
521 test_list_filename_and_number
525 test_repeat_list_command
527 test_list_filename_and_function
531 remote_exec build "rm -f list0.h"