1 # Copyright 1992-2013 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 3 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, see <http://www.gnu.org/licenses/>.
16 # This file was written by Fred Fish. (fnf@cygnus.com)
20 set binfile ${objdir}/${subdir}/${testfile}
22 # Need to download the header to the host.
23 remote_download host ${srcdir}/${subdir}/list0.h list0.h
26 if { [gdb_compile "${srcdir}/${subdir}/list0.c" "${binfile}0.o" object {debug}] != "" } {
31 if { [gdb_compile "${srcdir}/${subdir}/list1.c" "${binfile}1.o" object {debug}] != "" } {
36 if { [gdb_compile "${binfile}0.o ${binfile}1.o" ${binfile} executable {debug}] != "" } {
43 # Create and source the file that provides information about the compiler
44 # used to compile the test case.
45 if [get_compiler_info] {
49 # The last line in the file.
50 set last_line [gdb_get_line_number "last line" "list0.c"]
52 # Regex matching the last line in the file.
53 set last_line_re "${last_line}\[ \t\]+} /\\* last line \\*/"
56 # Local utility proc just to set and verify listsize
57 # Return 1 if success, 0 if fail.
60 set set_listsize_count 0
62 proc set_listsize { arg } {
64 global set_listsize_count
66 incr set_listsize_count
67 if [gdb_test_no_output "set listsize $arg" "setting listsize to $arg #$set_listsize_count"] {
74 if [gdb_test "show listsize" "Number of source lines.* is ${arg}.*" "show listsize $arg #$set_listsize_count"] {
81 # Test display of listsize lines around a given line number.
84 proc test_listsize {} {
87 global hp_aCC_compiler
92 gdb_test "show listsize" "Number of source lines gdb will list by default is 10.*" "show default list size"
94 # Show the default lines
96 gdb_test "list" "(1\[ \t\]+#include \"list0.h\".*7\[ \t\]+x = 0;\r\n.*10\[ \t\]+foo .x\[+)\]+;)" "list default lines around main"
98 # Ensure we can limit printouts to one line
100 if [set_listsize 1] {
101 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"" "list line 1 with listsize 1"
102 gdb_test "list 2" "2\[ \t\]+" "list line 2 with listsize 1"
107 if [ set_listsize 2 ] {
108 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 1 with listsize 2"
109 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 2 with listsize 2"
110 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+" "list line 3 with listsize 2"
113 # Try small listsize > 1 that is an odd number
115 if [ set_listsize 3 ] {
116 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 1 with listsize 3"
117 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 2 with listsize 3"
118 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[(\]+\[)\]+\r\n4\[ \t\]+\{" "list line 3 with listsize 3"
121 # Try small listsize > 2 that is an even number.
123 if [ set_listsize 4 ] then {
124 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 1 with listsize 4"
125 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 2 with listsize 4"
127 gdb_test "list 3" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 3 with listsize 4"
128 gdb_test "list 4" "2\[ \t\]+\r\n.*5\[ \t\]+int x;.*" "list line 4 with listsize 4"
131 # Try a size larger than the entire file.
133 if [ set_listsize 100 ] then {
134 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*\r\n${last_line_re}" "list line 1 with listsize 100"
136 gdb_test "list 10" "1\[ \t\]+#include \"list0.h\".*\r\n${last_line_re}" "list line 10 with listsize 100"
139 # Try listsize of 0 which is special, and means unlimited.
142 gdb_test "list 1" "1\[ \t\]+#include .*\r\n${last_line_re}" "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 {} {
232 send_gdb "list list0.c:10\n"
234 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
235 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
236 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
241 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
242 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
243 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
248 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
249 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
250 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
255 -re "35\[ \t\]+foo \\(.*\\);.*${last_line_re}\r\n$gdb_prompt $" { incr testcnt }
256 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
257 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
260 pass "successive list commands to page forward ($testcnt tests)"
261 gdb_stop_suppressing_tests
264 # Test that repeating the list linenum command doesn't print the same
265 # lines over again. Note that this test makes sure that the argument
266 # linenum is dropped, when we repeat the previous command. 'x/5i $pc'
267 # works the same way.
269 proc test_repeat_list_command {} {
275 send_gdb "list list0.c:10\n"
277 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
278 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
279 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
284 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
285 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
286 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
291 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
292 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
293 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
298 -re "35\[ \t\]+foo \\(.*\\);.*${last_line_re}\r\n$gdb_prompt $" { incr testcnt }
299 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
300 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
303 pass "repeat list commands to page forward using 'return' ($testcnt tests)"
304 gdb_stop_suppressing_tests
307 proc test_list_backwards {} {
312 send_gdb "list list0.c:33\n"
314 -re "28\[ \t\]+foo \\(.*\\);.*37\[ \t\]+\}\r\n$gdb_prompt $" { incr testcnt }
315 -re ".*$gdb_prompt $" { fail "list list0.c:33" ; gdb_suppress_tests }
316 timeout { fail "list list0.c:33 (timeout)" ; gdb_suppress_tests }
321 -re "18\[ \t\]+foo \[(\]+.*\[)\]+;.*27\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
322 -re ".*$gdb_prompt $" { fail "list 18-27" ; gdb_suppress_tests }
323 timeout { fail "list 18-27 (timeout)" ; gdb_suppress_tests }
328 -re "8\[ \t\]+foo \[(\]+.*\[)\]+;.*17\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
329 -re ".*$gdb_prompt $" { fail "list 8-17" ; gdb_suppress_tests }
330 timeout { fail "list 8-17 (timeout)" ; gdb_suppress_tests }
335 -re "1\[ \t\]+#include .*7\[ \t\]+x = 0;\r\n$gdb_prompt $" { incr testcnt }
336 -re ".*$gdb_prompt $" { fail "list 1-7" ; gdb_suppress_tests }
337 timeout { fail "list 1-7 (timeout)" ; gdb_suppress_tests }
340 pass "$testcnt successive \"list -\" commands to page backwards"
341 gdb_stop_suppressing_tests
345 # Test "list first,last"
348 proc test_list_range {} {
353 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"
355 gdb_test "list 2,5" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+.*5\[ \t\]+int x;" "list range; line1,line2"
357 # gdb_test "list -1,6" "Line number 0 out of range; .*list0.c has 39 lines." "list range; lower bound negative"
359 # gdb_test "list -100,-40" "Line number -60 out of range; .*list0.c has 39 lines." "list range; both bounds negative"
361 set past_end [expr ${last_line} + 10]
362 set much_past_end [expr ${past_end} + 10]
364 gdb_test "list 30,${past_end}" "30\[ \t\]+foo \(.*\);.*${last_line_re}" "list range; upper bound past EOF"
366 gdb_test "list ${past_end},${much_past_end}" "Line number ${past_end} out of range; .*list0.c has ${last_line} lines." "list range; both bounds past EOF"
368 gdb_test "list list0.c:2,list1.c:17" "Specified start and end are in different files." "list range, must be same files"
372 # Test "list filename:function"
375 proc test_list_filename_and_function {} {
381 # gcc appears to generate incorrect debugging information for code
382 # in include files, which breaks this test.
383 # SunPRO cc is the second case below, it's also correct.
384 send_gdb "list list0.c:main\n"
386 -re "1\[ \t\]+#include .*10\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
389 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
390 pass "list function in source file 1"
392 -re ".*$gdb_prompt $" { fail "list list0.c:main" }
393 timeout { fail "list list0.c:main (timeout)" }
396 # Not sure what the point of having this function be unused is.
397 # AIX is legitimately removing it.
398 setup_xfail "rs6000-*-aix*"
399 send_gdb "list list0.c:unused\n"
401 -re "40\[ \t\]+unused.*${last_line_re}\r\n$gdb_prompt $" {
404 -re "37.*42\[ \t\]+\}\r\n$gdb_prompt $" {
407 -re ".*$gdb_prompt $" { fail "list list0.c:unused" }
408 timeout { fail "list list0.c:unused (timeout)" }
410 clear_xfail "rs6000-*-aix*"
412 # gcc appears to generate incorrect debugging information for code
413 # in include files, which breaks this test.
414 # Ultrix gdb is the second case, one line different but still correct.
415 # SunPRO cc is the third case.
416 setup_xfail "rs6000-*-*" 1804
417 setup_xfail_format "COFF"
418 send_gdb "list list0.h:foo\n"
420 -re "2\[ \t\]+including file. This.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
423 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
426 -re "3\[ \t\]+.*12\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
429 -re "No source file named list0.h.\r\n$gdb_prompt $" {
430 fail "list list0.h:foo"
432 -re ".*$gdb_prompt $" { fail "list list0.h:foo" }
433 timeout { fail "list list0.h:foo (timeout)" }
436 # Ultrix gdb is the second case.
437 send_gdb "list list1.c:bar\n"
439 -re "4\[ \t\]+void.*13\[ \t\]+\}\r\n$gdb_prompt $" {
442 -re "4\[ \t\]+void.*12\[ \t\]*long_line ..;\r\n$gdb_prompt $" {
445 -re "4\[ \t\]+void.*11\[ \t\]*\r\n$gdb_prompt $" {
448 -re ".*$gdb_prompt $" { fail "list list1.c:bar" }
449 timeout { fail "list list1.c:bar (timeout)" }
452 # Not sure what the point of having this function be unused is.
453 # AIX is legitimately removing it.
454 setup_xfail "rs6000-*-aix*"
455 send_gdb "list list1.c:unused\n"
457 -re "12\[ \t\]+long_line \[(\]\[)\];.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
460 -re "14.*19\[ \t\]+\}\r\n.*$gdb_prompt $" {
463 -re ".*$gdb_prompt $" { fail "list list1.c:unused" }
464 timeout { fail "list list1.c:unused (timeout)" }
466 clear_xfail "rs6000-*-aix*"
468 pass "list filename:function ($testcnt tests)"
471 gdb_test "list 'list0.c:main'" "int main.*"
473 # Test some invalid specs
474 # The following test takes the FIXME result on most systems using
475 # DWARF. It fails to notice that main() is not in the file requested.
479 # Does this actually work ANYWHERE? I believe not, as this is an `aspect' of
480 # lookup_symbol(), where, when it is given a specific symtab which does not
481 # contain the requested symbol, it will subsequently search all of the symtabs
482 # for the requested symbol.
484 gdb_test "list list0.c:foo" "Function \"foo\" not defined in .*list0.c" "list filename:function; wrong filename rejected"
486 gdb_test "list foobar.c:main" "No source file named foobar.c.|Location not found" "list filename:function; nonexistant file"
488 gdb_test "list list0.h:foobar" "Function \"foobar\" not defined in \"list0.h\"." "list filename:function; nonexistant function"
492 proc test_forward_search {} {
495 gdb_test_no_output "set listsize 4"
496 # On SunOS4, this gives us lines 19-22. On AIX, it gives us
497 # lines 20-23. This depends on whether the line number of a function
498 # is considered to be the openbrace or the first statement--either one
500 gdb_test "list long_line" "24\[ \t\]+long_line .*"
502 gdb_test "search 4321" " not found"
504 gdb_test "search 6789" "28\[ \t\]+oof .6789.;"
506 # Test that GDB won't crash if the line being searched is extremely long.
508 set oldtimeout $timeout
509 set timeout [expr "$timeout + 300"]
510 verbose "Timeout is now $timeout seconds" 2
511 gdb_test "search 1234" ".*1234.*" "search extremely long line (> 5000 chars)"
512 set timeout $oldtimeout
513 verbose "Timeout is now $timeout seconds" 2
516 proc test_only_end {} {
517 gdb_test_no_output "set listsize 2"
518 gdb_test "list 1" "list 1\r\n1\[ \t\]\[^\r\n\]*\r\n2\[ \t\]\[^\r\n\]*"
519 gdb_test "list ,5" "list ,5\r\n4\[ \t\]\[^\r\n\]*\r\n5\[ \t\]\[^\r\n\]*"
522 # Start with a fresh gdb.
526 gdb_reinitialize_dir $srcdir/$subdir
527 gdb_file_cmd ${binfile}
529 gdb_test_no_output "set width 0"
533 if [ set_listsize 10 ] then {
534 test_list_include_file
535 test_list_filename_and_number
539 test_repeat_list_command
541 test_list_filename_and_function
546 remote_exec build "rm -f list0.h"