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 {} {
80 global gdb_prompt use_gdb_stub
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
89 # Note that remote targets that have debugging info for _start available will
90 # list the lines there instead of main, so we skip this test for remote targets.
91 # The second case is for optimized code, it is still correct.
95 unsupported "list default lines around main";
97 gdb_test "list" "(1\[ \t\]+#include \"list0.h\".*7\[ \t\]+x = 0;\r\n.*10\[ \t\]+foo .x\[+)\]+;)" "list default lines around main"
100 # Ensure we can limit printouts to one line
102 if [set_listsize 1] {
103 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"" "list line 1 with listsize 1"
104 gdb_test "list 2" "2\[ \t\]+" "list line 2 with listsize 1"
109 if [ set_listsize 2 ] {
110 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 1 with listsize 2"
111 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 2 with listsize 2"
112 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+" "list line 3 with listsize 2"
115 # Try small listsize > 1 that is an odd number
117 if [ set_listsize 3 ] {
118 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 1 with listsize 3"
119 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 2 with listsize 3"
120 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[(\]+\[)\]+\r\n4\[ \t\]+\{" "list line 3 with listsize 3"
123 # Try small listsize > 2 that is an even number.
125 if [ set_listsize 4 ] then {
126 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 1 with listsize 4"
127 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 2 with listsize 4"
129 gdb_test "list 3" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 3 with listsize 4"
130 gdb_test "list 4" "2\[ \t\]+\r\n.*5\[ \t\]+int x;.*" "list line 4 with listsize 4"
133 # Try a size larger than the entire file.
135 if [ set_listsize 100 ] then {
136 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*\r\n4\[23\]\[ \t\]+\}" "list line 1 with listsize 100"
138 gdb_test "list 10" "1\[ \t\]+#include \"list0.h\".*\r\n4\[23\]\[ \t\]+\}" "list line 10 with listsize 100"
141 # Try listsize of 0 which suppresses printing.
144 gdb_test "list 1" "" "listsize of 0 suppresses output"
146 # Try listsize of -1 which is special, and means unlimited.
150 gdb_test "list 1" "1\[ \t\]+#include .*\r\n39\[ \t\]+\}" "list line 1 with unlimited listsize"
154 # Test "list filename:number" for C include file
157 proc test_list_include_file {} {
160 setup_xfail_format "COFF"
161 gdb_test "list list0.h:1" "1\[ \t\]+/\[*\]+ An include file .*10\[ \t\]+bar \\(x\\+\\+\\);" "list line 1 in include file"
163 setup_xfail_format "COFF"
164 gdb_test "list list0.h:100" "Line number 95 out of range; .*list0.h has 3\[67\] lines." "list message for lines past EOF"
168 # Test "list filename:number" for C source file
171 proc test_list_filename_and_number {} {
176 send_gdb "list list0.c:1\n"
178 -re "1\[ \t\]+#include \"list0.h\".*10\[ \t\]+foo .x\[+)\]+;\r\n$gdb_prompt $" {
181 -re ".*$gdb_prompt $" { fail "list list0.c:1" ; gdb_suppress_tests }
182 timeout { fail "list list0.c:1 (timeout)" ; gdb_suppress_tests }
184 send_gdb "list list0.c:10\n"
186 -re "5\[ \t\]+int x;.*14\[ \t\]+foo .x\[+)\]+;\r\n$gdb_prompt $" {
189 -re ".*$gdb_prompt $" { fail "list list.c:10" ; gdb_suppress_tests }
190 timeout { fail "list list.c:10 (timeout)" ; gdb_suppress_tests }
192 send_gdb "list list1.c:1\n"
194 -re "1\[ \t\]+\#include.*4\[ \t\]+.*int oof\[ \t\]*\(.*\);\r\n.*$gdb_prompt $" {
197 -re ".*$gdb_prompt $" { fail "list list1.c:1" ; gdb_suppress_tests }
198 timeout { fail "list list1.c:1 (timeout)" ; gdb_suppress_tests }
200 send_gdb "list list1.c:12\n"
202 -re "12\[ \t\]+long_line \[(\]+.*\[)\]+;.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
205 -re ".*$gdb_prompt $" { fail "list list1.c:12" ; gdb_suppress_tests }
206 timeout { fail "list list1.c:12 (timeout)" ; gdb_suppress_tests }
208 pass "list filename:number ($testcnt tests)"
209 gdb_stop_suppressing_tests;
213 # Test "list function" for C source file
216 proc test_list_function {} {
219 # gcc appears to generate incorrect debugging information for code
220 # in include files, which breaks this test.
221 # SunPRO cc is the second case below, it's also correct.
222 gdb_test "list main" "(5\[ \t\]+int x;.*8\[ \t\]+foo \[(\]+.*\[)\]+;|1\[ \t\]+#include .*7\[ \t\]+x = 0;)" "list function in source file 1"
224 # Ultrix gdb takes the second case below; it's also correct.
225 # SunPRO cc is the third case.
226 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"
228 # Test "list function" for C include file
229 # Ultrix gdb is the second case, still correct.
230 # SunPRO cc is the third case.
231 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"
234 proc test_list_forward {} {
239 send_gdb "list list0.c:10\n"
241 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
242 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
243 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
248 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
249 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
250 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
255 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
256 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
257 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
262 -re "35\[ \t\]+foo \\(.*\\);.*42\[ \t\]+.*\}\r\n$gdb_prompt $" { incr testcnt }
263 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
264 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
267 pass "successive list commands to page forward ($testcnt tests)"
268 gdb_stop_suppressing_tests;
271 # Test that repeating the list linenum command doesn't print the same
272 # lines over again. Note that this test makes sure that the argument
273 # linenum is dropped, when we repeat the previous command. 'x/5i $pc'
274 # works the same way.
276 proc test_repeat_list_command {} {
281 send_gdb "list list0.c:10\n"
283 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
284 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
285 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
290 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
291 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
292 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
297 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
298 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
299 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
304 -re "35\[ \t\]+foo \\(.*\\);.*42\[ \t\]+.*\}\r\n$gdb_prompt $" { incr testcnt }
305 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
306 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
309 pass "repeat list commands to page forward using 'return' ($testcnt tests)"
310 gdb_stop_suppressing_tests;
313 proc test_list_backwards {} {
318 send_gdb "list list0.c:33\n"
320 -re "28\[ \t\]+foo \\(.*\\);.*37\[ \t\]+\}\r\n$gdb_prompt $" { incr testcnt }
321 -re ".*$gdb_prompt $" { fail "list list0.c:33" ; gdb_suppress_tests }
322 timeout { fail "list list0.c:33 (timeout)" ; gdb_suppress_tests }
327 -re "18\[ \t\]+foo \[(\]+.*\[)\]+;.*27\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
328 -re ".*$gdb_prompt $" { fail "list 18-27" ; gdb_suppress_tests }
329 timeout { fail "list 18-27 (timeout)" ; gdb_suppress_tests }
334 -re "8\[ \t\]+foo \[(\]+.*\[)\]+;.*17\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
335 -re ".*$gdb_prompt $" { fail "list 8-17" ; gdb_suppress_tests }
336 timeout { fail "list 8-17 (timeout)" ; gdb_suppress_tests }
341 -re "1\[ \t\]+#include .*7\[ \t\]+x = 0;\r\n$gdb_prompt $" { incr testcnt }
342 -re ".*$gdb_prompt $" { fail "list 1-7" ; gdb_suppress_tests }
343 timeout { fail "list 1-7 (timeout)" ; gdb_suppress_tests }
346 pass "$testcnt successive \"list -\" commands to page backwards"
347 gdb_stop_suppressing_tests;
351 # Test "list first,last"
354 proc test_list_range {} {
357 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"
359 gdb_test "list 2,5" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+.*5\[ \t\]+int x;" "list range; line1,line2"
361 # gdb_test "list -1,6" "Line number 0 out of range; .*list0.c has 39 lines." "list range; lower bound negative"
363 # gdb_test "list -100,-40" "Line number -60 out of range; .*list0.c has 39 lines." "list range; both bounds negative"
365 gdb_test "list 30,45" "30\[ \t\]+foo \(.*\);.*43\[ \t\]+\}" "list range; upper bound past EOF"
367 gdb_test "list 45,100" "Line number 45 out of range; .*list0.c has 43 lines." "list range; both bounds past EOF"
369 gdb_test "list list0.c:2,list1.c:17" "Specified start and end are in different files." "list range, must be same files"
373 # Test "list filename:function"
376 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.*43\[ \t\]+\}\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 # Start with a fresh gdb.
520 gdb_reinitialize_dir $srcdir/$subdir
523 gdb_test_no_output "set width 0"
527 if [ set_listsize 10 ] then {
528 test_list_include_file
529 test_list_filename_and_number
533 test_repeat_list_command
535 test_list_filename_and_function
539 remote_exec build "rm -f list0.h"