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