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