]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/list.exp
import gdb-1999-07-12 snapshot
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / list.exp
CommitLineData
c906108c
SS
1# Copyright (C) 1992, 1994, 1995, 1997, 1998 Free Software Foundation, Inc.
2
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.
7#
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.
12#
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.
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
20# This file was written by Fred Fish. (fnf@cygnus.com)
21
22if $tracelevel then {
23 strace $tracelevel
24}
25
26set prms_id 0
27set bug_id 0
28
29set testfile "list"
30set binfile ${objdir}/${subdir}/${testfile}
31
32# Need to download the header to the host.
33remote_download host ${srcdir}/${subdir}/list0.h list0.h
34
35
36if { [gdb_compile "${srcdir}/${subdir}/list0.c" "${binfile}0.o" object {debug}] != "" } {
37 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
38}
39
40if { [gdb_compile "${srcdir}/${subdir}/list1.c" "${binfile}1.o" object {debug}] != "" } {
41 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
42}
43
44if { [gdb_compile "${binfile}0.o ${binfile}1.o" ${binfile} executable {debug}] != "" } {
45 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
46}
47
48
49
50# Create and source the file that provides information about the compiler
51# used to compile the test case.
52if [get_compiler_info ${binfile}] {
53 return -1;
54}
55
56#
57# Local utility proc just to set and verify listsize
58# Return 1 if success, 0 if fail.
59#
60
61set set_listsize_count 0;
62
63proc set_listsize { arg } {
64 global gdb_prompt
65 global set_listsize_count;
66
67 incr set_listsize_count;
68 if [gdb_test "set listsize $arg" "" "setting listsize to $arg #$set_listsize_count"] {
69 return 0;
70 }
71 if { $arg <= 0 } {
72 set arg "unlimited";
73 }
74
75 if [gdb_test "show listsize" "Number of source lines.* is ${arg}.*" "show listsize $arg #$set_listsize_count"] {
76 return 0;
77 }
78 return 1
79}
80
81#
82# Test display of listsize lines around a given line number.
83#
84
85proc test_listsize {} {
86 global gdb_prompt
085dd6e6
JM
87 global hp_cc_compiler
88 global hp_aCC_compiler
c906108c
SS
89
90 # Show default size
91
92 gdb_test "show listsize" "Number of source lines gdb will list by default is 10.*" "show default list size"
93
94 # Show the default lines
95 # The second case is for optimized code, it is still correct.
96
97 if ![isnative] {
98 runto_main;
99 unsupported "list default lines around main";
100 } else {
101 gdb_test "list" "(1\[ \t\]+#include \"list0.h\".*10\[ \t\]+x = 0;|2.*11\[ \t\]+foo .x\[+)\]+;)" "list default lines around main"
102 }
103
104 # Ensure we can limit printouts to one line
105
085dd6e6 106 if [set_listsize 1] {
c906108c 107 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"" "list line 1 with listsize 1"
c906108c
SS
108 gdb_test "list 2" "2\[ \t\]+" "list line 2 with listsize 1"
109 }
110
111 # Try just two lines
112
113 if [ set_listsize 2 ] {
114 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"" "list line 1 with listsize 2"
115 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 2 with listsize 2"
085dd6e6 116 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+" "list line 3 with listsize 2"
c906108c
SS
117 }
118
119 # Try small listsize > 1 that is an odd number
120
121 if [ set_listsize 3 ] {
122 setup_xfail "*-*-*"
123 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"2\[ \t\]+" "list line 1 with listsize 3"
085dd6e6 124 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 2 with listsize 3"
c906108c 125
085dd6e6 126 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[(\]+\[)\]+\r\n4\[ \t\]+\{" "list line 3 with listsize 3"
c906108c
SS
127 }
128
129 # Try small listsize > 2 that is an even number.
130
131 if [ set_listsize 4 ] then {
132 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 1 with listsize 4"
085dd6e6 133 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 2 with listsize 4"
c906108c
SS
134
135 gdb_test "list 3" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 3 with listsize 4"
136 gdb_test "list 4" "2\[ \t\]+\r\n.*5\[ \t\]+int x;.*" "list line 4 with listsize 4"
137 }
138
139 # Try a size larger than the entire file.
140
141 if [ set_listsize 100 ] then {
085dd6e6 142 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*\r\n4\[23\]\[ \t\]+\}" "list line 1 with listsize 100"
c906108c 143
085dd6e6 144 gdb_test "list 10" "1\[ \t\]+#include \"list0.h\".*\r\n4\[23\]\[ \t\]+\}" "list line 10 with listsize 100"
c906108c
SS
145 }
146
147 # Try listsize of 0 which suppresses printing.
148
149 set_listsize 0
150 gdb_test "list 1" "" "listsize of 0 suppresses output"
151
152 # Try listsize of -1 which is special, and means unlimited.
153
154 set_listsize -1
155 setup_xfail "*-*-*"
156 gdb_test "list 1" "1\[ \t\]+#include .*\r\n39\[ \t\]+\}" "list line 1 with unlimited listsize"
157}
158
159#
160# Test "list filename:number" for C include file
161#
162
163proc test_list_include_file {} {
164 global gdb_prompt
165
166 setup_xfail "a29k-*-udi"
167 setup_xfail_format "DWARF 1"
168 setup_xfail_format "COFF"
085dd6e6 169 gdb_test "list list0.h:1" "1\[ \t\]+/\[*\]+ An include file .*4\[ \t\]+.*foo \(.*x.*\).*" "list line 1 in include file"
c906108c
SS
170
171 setup_xfail "a29k-*-udi"
172 setup_xfail_format "DWARF 1"
173 setup_xfail_format "COFF"
085dd6e6 174 gdb_test "list list0.h:100" "Line number 95 out of range; .*list0.h has 3\[67\] lines." "list message for lines past EOF"
c906108c
SS
175}
176
177#
178# Test "list filename:number" for C source file
179#
180
181proc test_list_filename_and_number {} {
182 global gdb_prompt
183
184 set testcnt 0
185
186 send_gdb "list list0.c:1\n"
187 gdb_expect {
188 -re "1\[ \t\]+#include \"list0.h\".*5\[ \t\]+int x;\r\n$gdb_prompt $" {
189 incr testcnt
190 }
191 -re ".*$gdb_prompt $" { fail "list list0.c:1" ; gdb_suppress_tests }
192 timeout { fail "list list0.c:1 (timeout)" ; gdb_suppress_tests }
193 }
194 send_gdb "list list0.c:10\n"
195 gdb_expect {
196 -re "5\[ \t\]+int x;.*14\[ \t\]+foo .x\[+)\]+;\r\n$gdb_prompt $" {
197 incr testcnt
198 }
199 -re ".*$gdb_prompt $" { fail "list list.c:10" ; gdb_suppress_tests }
200 timeout { fail "list list.c:10 (timeout)" ; gdb_suppress_tests }
201 }
202 send_gdb "list list1.c:1\n"
203 gdb_expect {
085dd6e6 204 -re "1\[ \t\]+\#include.*4\[ \t\]+.*int oof\[ \t\]*\(.*\);\r\n.*$gdb_prompt $" {
c906108c
SS
205 incr testcnt
206 }
207 -re ".*$gdb_prompt $" { fail "list list1.c:1" ; gdb_suppress_tests }
208 timeout { fail "list list1.c:1 (timeout)" ; gdb_suppress_tests }
209 }
210 send_gdb "list list1.c:12\n"
211 gdb_expect {
085dd6e6 212 -re "12\[ \t\]+long_line \[(\]+.*\[)\]+;.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
c906108c
SS
213 incr testcnt
214 }
215 -re ".*$gdb_prompt $" { fail "list list1.c:12" ; gdb_suppress_tests }
216 timeout { fail "list list1.c:12 (timeout)" ; gdb_suppress_tests }
217 }
218 pass "list filename:number ($testcnt tests)"
219 gdb_stop_suppressing_tests;
220}
221
222#
223# Test "list function" for C source file
224#
225
226proc test_list_function {} {
227 global gdb_prompt
228 global gcc_compiled
229
230 # gcc appears to generate incorrect debugging information for code
231 # in include files, which breaks this test.
232 # SunPRO cc is the second case below, it's also correct.
233 setup_xfail "a29k-*-udi"
234 gdb_test "list main" "(5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;|1\[ \t\]+#include .*8\[ \t\]+breakpoint\[(\]\[)\]+;)" "list function in source file 1"
235
236 # Ultrix gdb takes the second case below; it's also correct.
237 # SunPRO cc is the third case.
085dd6e6 238 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"
c906108c
SS
239
240 # Test "list function" for C include file
241 # Ultrix gdb is the second case, still correct.
242 # SunPRO cc is the third case.
243 setup_xfail "powerpc-*-*"
244 setup_xfail_format "DWARF 1"
245 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"
246}
247
248proc test_list_forward {} {
249 global gdb_prompt
250
251 set testcnt 0
252
253 send_gdb "list list0.c:10\n"
254 gdb_expect {
255 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
256 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
257 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
258 }
259
260 send_gdb "list\n"
261 gdb_expect {
262 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
263 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
264 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
265 }
266
267 send_gdb "list\n"
268 gdb_expect {
269 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
270 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
271 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
272 }
273
274 send_gdb "list\n"
275 gdb_expect {
085dd6e6 276 -re "35\[ \t\]+foo \\(.*\\);.*42\[ \t\]+.*\}\r\n$gdb_prompt $" { incr testcnt }
c906108c
SS
277 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
278 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
279 }
280
281 pass "successive list commands to page forward ($testcnt tests)"
282 gdb_stop_suppressing_tests;
283}
284
285proc test_list_backwards {} {
286 global gdb_prompt
287
288 set testcnt 0
289
290 send_gdb "list list0.c:33\n"
291 gdb_expect {
085dd6e6 292 -re "28\[ \t\]+foo \\(.*\\);.*37\[ \t\]+\}\r\n$gdb_prompt $" { incr testcnt }
c906108c
SS
293 -re ".*$gdb_prompt $" { fail "list list0.c:33" ; gdb_suppress_tests }
294 timeout { fail "list list0.c:33 (timeout)" ; gdb_suppress_tests }
295 }
296
297 send_gdb "list -\n"
298 gdb_expect {
299 -re "18\[ \t\]+foo \[(\]+.*\[)\]+;.*27\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
300 -re ".*$gdb_prompt $" { fail "list 18-27" ; gdb_suppress_tests }
301 timeout { fail "list 18-27 (timeout)" ; gdb_suppress_tests }
302 }
303
304 send_gdb "list -\n"
305 gdb_expect {
306 -re "8\[ \t\]+breakpoint\[(\]\[)\];.*17\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
307 -re ".*$gdb_prompt $" { fail "list 8-17" ; gdb_suppress_tests }
308 timeout { fail "list 8-17 (timeout)" ; gdb_suppress_tests }
309 }
310
311 send_gdb "list -\n"
312 gdb_expect {
313 -re "1\[ \t\]+#include .*7\[ \t\]+set_debug_traps\[(\]\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
314 -re ".*$gdb_prompt $" { fail "list 1-7" ; gdb_suppress_tests }
315 timeout { fail "list 1-7 (timeout)" ; gdb_suppress_tests }
316 }
317
318 pass "$testcnt successive \"list -\" commands to page backwards"
319 gdb_stop_suppressing_tests;
320}
321
322#
323# Test "list first,last"
324#
325
326proc test_list_range {} {
327 global gdb_prompt
328
085dd6e6 329 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"
c906108c 330
085dd6e6 331 gdb_test "list 2,5" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+.*5\[ \t\]+int x;" "list range; line1,line2"
c906108c
SS
332
333# gdb_test "list -1,6" "Line number 0 out of range; .*list0.c has 39 lines." "list range; lower bound negative"
334
335# gdb_test "list -100,-40" "Line number -60 out of range; .*list0.c has 39 lines." "list range; both bounds negative"
336
085dd6e6 337 gdb_test "list 30,45" "30\[ \t\]+foo \(.*\);.*43\[ \t\]+\}" "list range; upper bound past EOF"
c906108c 338
085dd6e6 339 gdb_test "list 45,100" "Line number 45 out of range; .*list0.c has 43 lines." "list range; both bounds past EOF"
c906108c
SS
340
341 gdb_test "list list0.c:2,list1.c:17" "Specified start and end are in different files." "list range, must be same files"
342}
343
344#
345# Test "list filename:function"
346#
347
348proc test_list_filename_and_function {} {
349 global gdb_prompt
350
351 set testcnt 0
352
353 # gcc appears to generate incorrect debugging information for code
354 # in include files, which breaks this test.
355 # SunPRO cc is the second case below, it's also correct.
356 setup_xfail "a29k-*-udi"
357 send_gdb "list list0.c:main\n"
358 gdb_expect {
359 -re "1\[ \t\]+#include .*8\[ \t\]+breakpoint\[(\]\[)\]+;\r\n$gdb_prompt $" {
360 incr testcnt
361 }
362 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
363 pass "list function in source file 1"
364 }
365 -re ".*$gdb_prompt $" { fail "list list0.c:main" }
366 timeout { fail "list list0.c:main (timeout)" }
367 }
368
369 # The i960 and a29k-amd-udi are the second case
370
371 # Not sure what the point of having this function be unused is.
372 # AIX is legitimately removing it.
373 setup_xfail "rs6000-*-aix*"
374 send_gdb "list list0.c:unused\n"
375 gdb_expect {
085dd6e6 376 -re "40\[ \t\]+unused.*43\[ \t\]+\}\r\n$gdb_prompt $" {
c906108c
SS
377 incr testcnt
378 }
379 -re "37.*42\[ \t\]+\}\r\n$gdb_prompt $" {
380 incr testcnt
381 }
382 -re ".*$gdb_prompt $" { fail "list list0.c:unused" }
383 timeout { fail "list list0.c:unused (timeout)" }
384 }
385 clear_xfail "rs6000-*-aix*"
386
387 # gcc appears to generate incorrect debugging information for code
388 # in include files, which breaks this test.
389 # Ultrix gdb is the second case, one line different but still correct.
390 # SunPRO cc is the third case.
391 setup_xfail "rs6000-*-*" 1804
392 setup_xfail "powerpc-*-*" 1804
393 setup_xfail "a29k-*-udi"
394 setup_xfail_format "DWARF 1"
395 setup_xfail_format "COFF"
396 send_gdb "list list0.h:foo\n"
397 gdb_expect {
398 -re "2\[ \t\]+including file. This.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
399 incr testcnt
400 }
401 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
402 incr testcnt
403 }
404 -re "3\[ \t\]+.*12\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
405 incr testcnt
406 }
407 -re "No source file named list0.h.\r\n$gdb_prompt $" {
408 fail "list list0.h:foo"
409 }
410 -re ".*$gdb_prompt $" { fail "list list0.h:foo" }
411 timeout { fail "list list0.h:foo (timeout)" }
412 }
413
414 # Ultrix gdb is the second case.
415 # a29k-amd-udi is the third case.
416 send_gdb "list list1.c:bar\n"
417 gdb_expect {
085dd6e6 418 -re "4\[ \t\]+void.*13\[ \t\]+\}\r\n$gdb_prompt $" {
c906108c
SS
419 incr testcnt
420 }
085dd6e6 421 -re "4\[ \t\]+void.*12\[ \t\]*long_line ..;\r\n$gdb_prompt $" {
c906108c
SS
422 incr testcnt
423 }
085dd6e6 424 -re "4\[ \t\]+void.*11\[ \t\]*\r\n$gdb_prompt $" {
c906108c
SS
425 incr testcnt
426 }
427 -re ".*$gdb_prompt $" { fail "list list1.c:bar" }
428 timeout { fail "list list1.c:bar (timeout)" }
429 }
430
431 # The i960 and a29k-amd-udi are the second case
432
433 # Not sure what the point of having this function be unused is.
434 # AIX is legitimately removing it.
435 setup_xfail "rs6000-*-aix*"
436 send_gdb "list list1.c:unused\n"
437 gdb_expect {
085dd6e6 438 -re "12\[ \t\]+long_line \[(\]\[)\];.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
c906108c
SS
439 incr testcnt
440 }
085dd6e6 441 -re "14.*19\[ \t\]+\}\r\n.*$gdb_prompt $" {
c906108c
SS
442 incr testcnt
443 }
444 -re ".*$gdb_prompt $" { fail "list list1.c:unused" }
445 timeout { fail "list list1.c:unused (timeout)" }
446 }
447 clear_xfail "rs6000-*-aix*"
448
449 pass "list filename:function ($testcnt tests)"
450
451 # Test some invalid specs
452 # The following test takes the FIXME result on most systems using
453 # DWARF. It fails to notice that main() is not in the file requested.
454
455 setup_xfail "*-*-*"
456
457# Does this actually work ANYWHERE? I believe not, as this is an `aspect' of
458# lookup_symbol(), where, when it is given a specific symtab which does not
459# contain the requested symbol, it will subsequently search all of the symtabs
460# for the requested symbol.
461
462 gdb_test "list list0.c:foo" "Function \"foo\" not defined in .*list0.c" "list filename:function; wrong filename rejected"
463
085dd6e6 464 gdb_test "list foobar.c:main" "No source file named foobar.c.|Location not found" "list filename:function; nonexistant file"
c906108c
SS
465
466 setup_xfail_format "DWARF 1"
085dd6e6 467 gdb_test "list list0.h:foobar" "Function \"foobar\" not defined.|Location not found" "list filename:function; nonexistant function"
c906108c
SS
468
469}
470
471proc test_forward_search {} {
472 global timeout
473
474 gdb_test "set listsize 4" ""
475 # On SunOS4, this gives us lines 19-22. On AIX, it gives us
476 # lines 20-23. This depends on whether the line number of a function
477 # is considered to be the openbrace or the first statement--either one
478 # is acceptable.
085dd6e6 479 gdb_test "list long_line" "24\[ \t\]+long_line .*"
c906108c
SS
480
481 gdb_test "search 4321" " not found"
482
085dd6e6 483 gdb_test "search 6789" "28\[ \t\]+oof .6789.;"
c906108c
SS
484
485 # Test that GDB won't crash if the line being searched is extremely long.
486
487 set oldtimeout $timeout
488 set timeout [expr "$timeout + 300"]
489 verbose "Timeout is now $timeout seconds" 2
490 gdb_test "search 1234" ".*1234.*" "search extremely long line (> 5000 chars)"
491 set timeout $oldtimeout
492 verbose "Timeout is now $timeout seconds" 2
493}
494
495# Start with a fresh gdb.
496
497gdb_exit
498gdb_start
499gdb_reinitialize_dir $srcdir/$subdir
500gdb_load ${binfile}
501
502if [target_info exists gdb_stub] {
503 gdb_step_for_stub;
504}
505
506gdb_test "set width 0" "" "set width 0"
507
508test_listsize
509get_debug_format
510if [ set_listsize 10 ] then {
511 test_list_include_file
512 test_list_filename_and_number
513 test_list_function
514 test_list_forward
515 test_list_backwards
516 test_list_range
517 test_list_filename_and_function
518 test_forward_search
519}
085dd6e6
JM
520
521remote_exec build "rm -f list0.h"