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