11aafd95e2e39da56fdc28de323770baf81193b2
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / list.exp
1 # Copyright 1992-2013 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 3 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, see <http://www.gnu.org/licenses/>.
15
16 # This file was written by Fred Fish. (fnf@cygnus.com)
17
18
19 set testfile "list"
20 set binfile ${objdir}/${subdir}/${testfile}
21
22 # Need to download the header to the host.
23 remote_download host ${srcdir}/${subdir}/list0.h list0.h
24
25
26 if { [gdb_compile "${srcdir}/${subdir}/list0.c" "${binfile}0.o" object {debug}] != "" } {
27 untested list.exp
28 return -1
29 }
30
31 if { [gdb_compile "${srcdir}/${subdir}/list1.c" "${binfile}1.o" object {debug}] != "" } {
32 untested list.exp
33 return -1
34 }
35
36 if { [gdb_compile "${binfile}0.o ${binfile}1.o" ${binfile} executable {debug}] != "" } {
37 untested list.exp
38 return -1
39 }
40
41
42
43 # Create and source the file that provides information about the compiler
44 # used to compile the test case.
45 if [get_compiler_info] {
46 return -1
47 }
48
49 # The last line in the file.
50 set last_line [gdb_get_line_number "last line" "list0.c"]
51
52 # Regex matching the last line in the file.
53 set last_line_re "${last_line}\[ \t\]+} /\\* last line \\*/"
54
55 #
56 # Local utility proc just to set and verify listsize
57 # Return 1 if success, 0 if fail.
58 #
59
60 set set_listsize_count 0
61
62 proc set_listsize { arg } {
63 global gdb_prompt
64 global set_listsize_count
65
66 incr set_listsize_count
67 if [gdb_test_no_output "set listsize $arg" "setting listsize to $arg #$set_listsize_count"] {
68 return 0
69 }
70 if { $arg == 0 } {
71 set arg "unlimited"
72 }
73
74 if [gdb_test "show listsize" "Number of source lines.* is ${arg}.*" "show listsize $arg #$set_listsize_count"] {
75 return 0
76 }
77 return 1
78 }
79
80 #
81 # Test display of listsize lines around a given line number.
82 #
83
84 proc test_listsize {} {
85 global gdb_prompt
86 global hp_cc_compiler
87 global hp_aCC_compiler
88 global last_line_re
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
96 gdb_test "list" "(1\[ \t\]+#include \"list0.h\".*7\[ \t\]+x = 0;\r\n.*10\[ \t\]+foo .x\[+)\]+;)" "list default lines around main"
97
98 # Ensure we can limit printouts to one line
99
100 if [set_listsize 1] {
101 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"" "list line 1 with listsize 1"
102 gdb_test "list 2" "2\[ \t\]+" "list line 2 with listsize 1"
103 }
104
105 # Try just two lines
106
107 if [ set_listsize 2 ] {
108 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 1 with listsize 2"
109 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 2 with listsize 2"
110 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+" "list line 3 with listsize 2"
111 }
112
113 # Try small listsize > 1 that is an odd number
114
115 if [ set_listsize 3 ] {
116 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 1 with listsize 3"
117 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 2 with listsize 3"
118 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[(\]+\[)\]+\r\n4\[ \t\]+\{" "list line 3 with listsize 3"
119 }
120
121 # Try small listsize > 2 that is an even number.
122
123 if [ set_listsize 4 ] then {
124 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 1 with listsize 4"
125 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 2 with listsize 4"
126
127 gdb_test "list 3" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 3 with listsize 4"
128 gdb_test "list 4" "2\[ \t\]+\r\n.*5\[ \t\]+int x;.*" "list line 4 with listsize 4"
129 }
130
131 # Try a size larger than the entire file.
132
133 if [ set_listsize 100 ] then {
134 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*\r\n${last_line_re}" "list line 1 with listsize 100"
135
136 gdb_test "list 10" "1\[ \t\]+#include \"list0.h\".*\r\n${last_line_re}" "list line 10 with listsize 100"
137 }
138
139 # Try listsize of 0 which is special, and means unlimited.
140
141 set_listsize 0
142 gdb_test "list 1" "1\[ \t\]+#include .*\r\n${last_line_re}" "list line 1 with unlimited listsize"
143 }
144
145 #
146 # Test "list filename:number" for C include file
147 #
148
149 proc test_list_include_file {} {
150 global gdb_prompt
151
152 setup_xfail_format "COFF"
153 gdb_test "list list0.h:1" "1\[ \t\]+/\[*\]+ An include file .*10\[ \t\]+bar \\(x\\+\\+\\);" "list line 1 in include file"
154
155 setup_xfail_format "COFF"
156 gdb_test "list list0.h:100" "Line number 95 out of range; .*list0.h has 3\[67\] lines." "list message for lines past EOF"
157 }
158
159 #
160 # Test "list filename:number" for C source file
161 #
162
163 proc test_list_filename_and_number {} {
164 global gdb_prompt
165
166 set testcnt 0
167
168 send_gdb "list list0.c:1\n"
169 gdb_expect {
170 -re "1\[ \t\]+#include \"list0.h\".*10\[ \t\]+foo .x\[+)\]+;\r\n$gdb_prompt $" {
171 incr testcnt
172 }
173 -re ".*$gdb_prompt $" { fail "list list0.c:1" ; gdb_suppress_tests }
174 timeout { fail "list list0.c:1 (timeout)" ; gdb_suppress_tests }
175 }
176 send_gdb "list list0.c:10\n"
177 gdb_expect {
178 -re "5\[ \t\]+int x;.*14\[ \t\]+foo .x\[+)\]+;\r\n$gdb_prompt $" {
179 incr testcnt
180 }
181 -re ".*$gdb_prompt $" { fail "list list.c:10" ; gdb_suppress_tests }
182 timeout { fail "list list.c:10 (timeout)" ; gdb_suppress_tests }
183 }
184 send_gdb "list list1.c:1\n"
185 gdb_expect {
186 -re "1\[ \t\]+\#include.*4\[ \t\]+.*int oof\[ \t\]*\(.*\);\r\n.*$gdb_prompt $" {
187 incr testcnt
188 }
189 -re ".*$gdb_prompt $" { fail "list list1.c:1" ; gdb_suppress_tests }
190 timeout { fail "list list1.c:1 (timeout)" ; gdb_suppress_tests }
191 }
192 send_gdb "list list1.c:12\n"
193 gdb_expect {
194 -re "12\[ \t\]+long_line \[(\]+.*\[)\]+;.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
195 incr testcnt
196 }
197 -re ".*$gdb_prompt $" { fail "list list1.c:12" ; gdb_suppress_tests }
198 timeout { fail "list list1.c:12 (timeout)" ; gdb_suppress_tests }
199 }
200 pass "list filename:number ($testcnt tests)"
201 gdb_stop_suppressing_tests
202 }
203
204 #
205 # Test "list function" for C source file
206 #
207
208 proc test_list_function {} {
209 global gdb_prompt
210
211 # gcc appears to generate incorrect debugging information for code
212 # in include files, which breaks this test.
213 # SunPRO cc is the second case below, it's also correct.
214 gdb_test "list main" "(5\[ \t\]+int x;.*8\[ \t\]+foo \[(\]+.*\[)\]+;|1\[ \t\]+#include .*7\[ \t\]+x = 0;)" "list function in source file 1"
215
216 # Ultrix gdb takes the second case below; it's also correct.
217 # SunPRO cc is the third case.
218 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"
219
220 # Test "list function" for C include file
221 # Ultrix gdb is the second case, still correct.
222 # SunPRO cc is the third case.
223 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"
224 }
225
226 proc test_list_forward {} {
227 global gdb_prompt
228 global last_line_re
229
230 set testcnt 0
231
232 send_gdb "list list0.c:10\n"
233 gdb_expect {
234 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
235 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
236 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
237 }
238
239 send_gdb "list\n"
240 gdb_expect {
241 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
242 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
243 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
244 }
245
246 send_gdb "list\n"
247 gdb_expect {
248 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
249 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
250 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
251 }
252
253 send_gdb "list\n"
254 gdb_expect {
255 -re "35\[ \t\]+foo \\(.*\\);.*${last_line_re}\r\n$gdb_prompt $" { incr testcnt }
256 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
257 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
258 }
259
260 pass "successive list commands to page forward ($testcnt tests)"
261 gdb_stop_suppressing_tests
262 }
263
264 # Test that repeating the list linenum command doesn't print the same
265 # lines over again. Note that this test makes sure that the argument
266 # linenum is dropped, when we repeat the previous command. 'x/5i $pc'
267 # works the same way.
268
269 proc test_repeat_list_command {} {
270 global gdb_prompt
271 global last_line_re
272
273 set testcnt 0
274
275 send_gdb "list list0.c:10\n"
276 gdb_expect {
277 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
278 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
279 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
280 }
281
282 send_gdb "\n"
283 gdb_expect {
284 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
285 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
286 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
287 }
288
289 send_gdb "\n"
290 gdb_expect {
291 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
292 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
293 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
294 }
295
296 send_gdb "\n"
297 gdb_expect {
298 -re "35\[ \t\]+foo \\(.*\\);.*${last_line_re}\r\n$gdb_prompt $" { incr testcnt }
299 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
300 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
301 }
302
303 pass "repeat list commands to page forward using 'return' ($testcnt tests)"
304 gdb_stop_suppressing_tests
305 }
306
307 proc test_list_backwards {} {
308 global gdb_prompt
309
310 set testcnt 0
311
312 send_gdb "list list0.c:33\n"
313 gdb_expect {
314 -re "28\[ \t\]+foo \\(.*\\);.*37\[ \t\]+\}\r\n$gdb_prompt $" { incr testcnt }
315 -re ".*$gdb_prompt $" { fail "list list0.c:33" ; gdb_suppress_tests }
316 timeout { fail "list list0.c:33 (timeout)" ; gdb_suppress_tests }
317 }
318
319 send_gdb "list -\n"
320 gdb_expect {
321 -re "18\[ \t\]+foo \[(\]+.*\[)\]+;.*27\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
322 -re ".*$gdb_prompt $" { fail "list 18-27" ; gdb_suppress_tests }
323 timeout { fail "list 18-27 (timeout)" ; gdb_suppress_tests }
324 }
325
326 send_gdb "list -\n"
327 gdb_expect {
328 -re "8\[ \t\]+foo \[(\]+.*\[)\]+;.*17\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
329 -re ".*$gdb_prompt $" { fail "list 8-17" ; gdb_suppress_tests }
330 timeout { fail "list 8-17 (timeout)" ; gdb_suppress_tests }
331 }
332
333 send_gdb "list -\n"
334 gdb_expect {
335 -re "1\[ \t\]+#include .*7\[ \t\]+x = 0;\r\n$gdb_prompt $" { incr testcnt }
336 -re ".*$gdb_prompt $" { fail "list 1-7" ; gdb_suppress_tests }
337 timeout { fail "list 1-7 (timeout)" ; gdb_suppress_tests }
338 }
339
340 pass "$testcnt successive \"list -\" commands to page backwards"
341 gdb_stop_suppressing_tests
342 }
343
344 #
345 # Test "list first,last"
346 #
347
348 proc test_list_range {} {
349 global gdb_prompt
350 global last_line_re
351 global last_line
352
353 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"
354
355 gdb_test "list 2,5" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+.*5\[ \t\]+int x;" "list range; line1,line2"
356
357 # gdb_test "list -1,6" "Line number 0 out of range; .*list0.c has 39 lines." "list range; lower bound negative"
358
359 # gdb_test "list -100,-40" "Line number -60 out of range; .*list0.c has 39 lines." "list range; both bounds negative"
360
361 set past_end [expr ${last_line} + 10]
362 set much_past_end [expr ${past_end} + 10]
363
364 gdb_test "list 30,${past_end}" "30\[ \t\]+foo \(.*\);.*${last_line_re}" "list range; upper bound past EOF"
365
366 gdb_test "list ${past_end},${much_past_end}" "Line number ${past_end} out of range; .*list0.c has ${last_line} lines." "list range; both bounds past EOF"
367
368 gdb_test "list list0.c:2,list1.c:17" "Specified start and end are in different files." "list range, must be same files"
369 }
370
371 #
372 # Test "list filename:function"
373 #
374
375 proc test_list_filename_and_function {} {
376 global gdb_prompt
377 global last_line_re
378
379 set testcnt 0
380
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"
385 gdb_expect {
386 -re "1\[ \t\]+#include .*10\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
387 incr testcnt
388 }
389 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
390 pass "list function in source file 1"
391 }
392 -re ".*$gdb_prompt $" { fail "list list0.c:main" }
393 timeout { fail "list list0.c:main (timeout)" }
394 }
395
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"
400 gdb_expect {
401 -re "40\[ \t\]+unused.*${last_line_re}\r\n$gdb_prompt $" {
402 incr testcnt
403 }
404 -re "37.*42\[ \t\]+\}\r\n$gdb_prompt $" {
405 incr testcnt
406 }
407 -re ".*$gdb_prompt $" { fail "list list0.c:unused" }
408 timeout { fail "list list0.c:unused (timeout)" }
409 }
410 clear_xfail "rs6000-*-aix*"
411
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"
419 gdb_expect {
420 -re "2\[ \t\]+including file. This.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
421 incr testcnt
422 }
423 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
424 incr testcnt
425 }
426 -re "3\[ \t\]+.*12\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
427 incr testcnt
428 }
429 -re "No source file named list0.h.\r\n$gdb_prompt $" {
430 fail "list list0.h:foo"
431 }
432 -re ".*$gdb_prompt $" { fail "list list0.h:foo" }
433 timeout { fail "list list0.h:foo (timeout)" }
434 }
435
436 # Ultrix gdb is the second case.
437 send_gdb "list list1.c:bar\n"
438 gdb_expect {
439 -re "4\[ \t\]+void.*13\[ \t\]+\}\r\n$gdb_prompt $" {
440 incr testcnt
441 }
442 -re "4\[ \t\]+void.*12\[ \t\]*long_line ..;\r\n$gdb_prompt $" {
443 incr testcnt
444 }
445 -re "4\[ \t\]+void.*11\[ \t\]*\r\n$gdb_prompt $" {
446 incr testcnt
447 }
448 -re ".*$gdb_prompt $" { fail "list list1.c:bar" }
449 timeout { fail "list list1.c:bar (timeout)" }
450 }
451
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"
456 gdb_expect {
457 -re "12\[ \t\]+long_line \[(\]\[)\];.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
458 incr testcnt
459 }
460 -re "14.*19\[ \t\]+\}\r\n.*$gdb_prompt $" {
461 incr testcnt
462 }
463 -re ".*$gdb_prompt $" { fail "list list1.c:unused" }
464 timeout { fail "list list1.c:unused (timeout)" }
465 }
466 clear_xfail "rs6000-*-aix*"
467
468 pass "list filename:function ($testcnt tests)"
469
470 # Test with quoting.
471 gdb_test "list 'list0.c:main'" "int main.*"
472
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.
476
477 setup_xfail "*-*-*"
478
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.
483
484 gdb_test "list list0.c:foo" "Function \"foo\" not defined in .*list0.c" "list filename:function; wrong filename rejected"
485
486 gdb_test "list foobar.c:main" "No source file named foobar.c.|Location not found" "list filename:function; nonexistant file"
487
488 gdb_test "list list0.h:foobar" "Function \"foobar\" not defined in \"list0.h\"." "list filename:function; nonexistant function"
489
490 }
491
492 proc test_forward_search {} {
493 global timeout
494
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
499 # is acceptable.
500 gdb_test "list long_line" "24\[ \t\]+long_line .*"
501
502 gdb_test "search 4321" " not found"
503
504 gdb_test "search 6789" "28\[ \t\]+oof .6789.;"
505
506 # Test that GDB won't crash if the line being searched is extremely long.
507
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
514 }
515
516 proc test_only_end {} {
517 gdb_test_no_output "set listsize 2"
518 gdb_test "list 1" "list 1\r\n1\[ \t\]\[^\r\n\]*\r\n2\[ \t\]\[^\r\n\]*"
519 gdb_test "list ,5" "list ,5\r\n4\[ \t\]\[^\r\n\]*\r\n5\[ \t\]\[^\r\n\]*"
520 }
521
522 # Start with a fresh gdb.
523
524 gdb_exit
525 gdb_start
526 gdb_reinitialize_dir $srcdir/$subdir
527 gdb_file_cmd ${binfile}
528
529 gdb_test_no_output "set width 0"
530
531 test_listsize
532 get_debug_format
533 if [ set_listsize 10 ] then {
534 test_list_include_file
535 test_list_filename_and_number
536 test_list_function
537 test_list_forward
538 test_list_backwards
539 test_repeat_list_command
540 test_list_range
541 test_list_filename_and_function
542 test_forward_search
543 test_only_end
544 }
545
546 remote_exec build "rm -f list0.h"
This page took 0.040365 seconds and 4 git commands to generate.