]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/list.exp
gdb: Add an error when 'list -' reaches the start of a file.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / list.exp
1 # Copyright 1992-2015 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 standard_testfile list0.c list1.c
20
21 # Need to download the header to the host.
22 gdb_remote_download host ${srcdir}/${subdir}/list0.h
23
24 if {[prepare_for_testing $testfile.exp $testfile [list $srcfile $srcfile2] \
25 {debug}]} {
26 return -1
27 }
28
29 # Create and source the file that provides information about the compiler
30 # used to compile the test case.
31 if [get_compiler_info] {
32 return -1
33 }
34
35 # The last line in the file.
36 set last_line [gdb_get_line_number "last line" "list0.c"]
37
38 # Regex matching the last line in the file.
39 set last_line_re "${last_line}\[ \t\]+} /\\* last line \\*/"
40
41 #
42 # Local utility proc just to set and verify listsize
43 # Return 1 if success, 0 if fail.
44 #
45
46 set set_listsize_count 0
47
48 proc set_listsize { arg } {
49 global gdb_prompt
50 global set_listsize_count
51
52 incr set_listsize_count
53 if [gdb_test_no_output "set listsize $arg" "setting listsize to $arg #$set_listsize_count"] {
54 return 0
55 }
56 if { $arg == 0 } {
57 set arg "unlimited"
58 }
59
60 if [gdb_test "show listsize" "Number of source lines.* is ${arg}.*" "show listsize $arg #$set_listsize_count"] {
61 return 0
62 }
63 return 1
64 }
65
66 #
67 # Test display of listsize lines around a given line number.
68 #
69
70 proc test_listsize {} {
71 global gdb_prompt
72 global hp_cc_compiler
73 global hp_aCC_compiler
74 global last_line_re
75
76 # Show default size
77
78 gdb_test "show listsize" "Number of source lines gdb will list by default is 10.*" "show default list size"
79
80 # Show the default lines
81
82 gdb_test "list" "(1\[ \t\]+#include \"list0.h\".*7\[ \t\]+x = 0;\r\n.*10\[ \t\]+foo .x\[+)\]+;)" "list default lines around main"
83
84 # Ensure we can limit printouts to one line
85
86 if [set_listsize 1] {
87 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"" "list line 1 with listsize 1"
88 gdb_test "list 2" "2\[ \t\]+" "list line 2 with listsize 1"
89 }
90
91 # Try just two lines
92
93 if [ set_listsize 2 ] {
94 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 1 with listsize 2"
95 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 2 with listsize 2"
96 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+" "list line 3 with listsize 2"
97 }
98
99 # Try small listsize > 1 that is an odd number
100
101 if [ set_listsize 3 ] {
102 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 1 with listsize 3"
103 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 2 with listsize 3"
104 gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[(\]+\[)\]+\r\n4\[ \t\]+\{" "list line 3 with listsize 3"
105 }
106
107 # Try small listsize > 2 that is an even number.
108
109 if [ set_listsize 4 ] then {
110 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 1 with listsize 4"
111 gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 2 with listsize 4"
112
113 gdb_test "list 3" "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{" "list line 3 with listsize 4"
114 gdb_test "list 4" "2\[ \t\]+\r\n.*5\[ \t\]+int x;.*" "list line 4 with listsize 4"
115 }
116
117 # Try a size larger than the entire file.
118
119 if [ set_listsize 100 ] then {
120 gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*\r\n${last_line_re}" "list line 1 with listsize 100"
121
122 gdb_test "list 10" "1\[ \t\]+#include \"list0.h\".*\r\n${last_line_re}" "list line 10 with listsize 100"
123 }
124
125 # Try listsize of 0 which is special, and means unlimited.
126
127 set_listsize 0
128 gdb_test "list 1" "1\[ \t\]+#include .*\r\n${last_line_re}" "list line 1 with unlimited listsize"
129 }
130
131 #
132 # Test "list filename:number" for C include file
133 #
134
135 proc test_list_include_file {} {
136 global gdb_prompt
137
138 setup_xfail_format "COFF"
139 gdb_test "list list0.h:1" "1\[ \t\]+/\[*\]+ An include file .*10\[ \t\]+bar \\(x\\+\\+\\);" "list line 1 in include file"
140
141 setup_xfail_format "COFF"
142 gdb_test "list list0.h:100" "Line number 95 out of range; .*list0.h has 3\[67\] lines." "list message for lines past EOF"
143 }
144
145 #
146 # Test "list filename:number" for C source file
147 #
148
149 proc test_list_filename_and_number {} {
150 global gdb_prompt
151
152 set testcnt 0
153
154 send_gdb "list list0.c:1\n"
155 gdb_expect {
156 -re "1\[ \t\]+#include \"list0.h\".*10\[ \t\]+foo .x\[+)\]+;\r\n$gdb_prompt $" {
157 incr testcnt
158 }
159 -re ".*$gdb_prompt $" { fail "list list0.c:1" ; gdb_suppress_tests }
160 timeout { fail "list list0.c:1 (timeout)" ; gdb_suppress_tests }
161 }
162 send_gdb "list list0.c:10\n"
163 gdb_expect {
164 -re "5\[ \t\]+int x;.*14\[ \t\]+foo .x\[+)\]+;\r\n$gdb_prompt $" {
165 incr testcnt
166 }
167 -re ".*$gdb_prompt $" { fail "list list.c:10" ; gdb_suppress_tests }
168 timeout { fail "list list.c:10 (timeout)" ; gdb_suppress_tests }
169 }
170 send_gdb "list list1.c:1\n"
171 gdb_expect {
172 -re "1\[ \t\]+\#include.*4\[ \t\]+.*int oof\[ \t\]*\(.*\);\r\n.*$gdb_prompt $" {
173 incr testcnt
174 }
175 -re ".*$gdb_prompt $" { fail "list list1.c:1" ; gdb_suppress_tests }
176 timeout { fail "list list1.c:1 (timeout)" ; gdb_suppress_tests }
177 }
178 send_gdb "list list1.c:12\n"
179 gdb_expect {
180 -re "12\[ \t\]+long_line \[(\]+.*\[)\]+;.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
181 incr testcnt
182 }
183 -re ".*$gdb_prompt $" { fail "list list1.c:12" ; gdb_suppress_tests }
184 timeout { fail "list list1.c:12 (timeout)" ; gdb_suppress_tests }
185 }
186 pass "list filename:number ($testcnt tests)"
187 gdb_stop_suppressing_tests
188 }
189
190 #
191 # Test "list function" for C source file
192 #
193
194 proc test_list_function {} {
195 global gdb_prompt
196
197 # gcc appears to generate incorrect debugging information for code
198 # in include files, which breaks this test.
199 # SunPRO cc is the second case below, it's also correct.
200 gdb_test "list main" "(5\[ \t\]+int x;.*8\[ \t\]+foo \[(\]+.*\[)\]+;|1\[ \t\]+#include .*7\[ \t\]+x = 0;)" "list function in source file 1"
201
202 # Ultrix gdb takes the second case below; it's also correct.
203 # SunPRO cc is the third case.
204 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"
205
206 # Test "list function" for C include file
207 # Ultrix gdb is the second case, still correct.
208 # SunPRO cc is the third case.
209 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"
210 }
211
212 proc test_list_forward {} {
213 global gdb_prompt
214 global last_line_re
215
216 set testcnt 0
217
218 send_gdb "list list0.c:10\n"
219 gdb_expect {
220 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
221 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
222 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
223 }
224
225 send_gdb "list\n"
226 gdb_expect {
227 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
228 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
229 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
230 }
231
232 send_gdb "list\n"
233 gdb_expect {
234 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
235 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
236 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
237 }
238
239 send_gdb "list\n"
240 gdb_expect {
241 -re "35\[ \t\]+foo \\(.*\\);.*${last_line_re}\r\n$gdb_prompt $" { incr testcnt }
242 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
243 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
244 }
245
246 pass "successive list commands to page forward ($testcnt tests)"
247
248 gdb_test "list" "Line number 44 out of range; \[^\r\n\]+ has 43 lines\." \
249 "end of file error after \"list\" command"
250
251 gdb_stop_suppressing_tests
252 }
253
254 # Test that repeating the list linenum command doesn't print the same
255 # lines over again. Note that this test makes sure that the argument
256 # linenum is dropped, when we repeat the previous command. 'x/5i $pc'
257 # works the same way.
258
259 proc test_repeat_list_command {} {
260 global gdb_prompt
261 global last_line_re
262
263 set testcnt 0
264
265 send_gdb "list list0.c:10\n"
266 gdb_expect {
267 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
268 -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests }
269 timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests }
270 }
271
272 send_gdb "\n"
273 gdb_expect {
274 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
275 -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests }
276 timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests }
277 }
278
279 send_gdb "\n"
280 gdb_expect {
281 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
282 -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests }
283 timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests }
284 }
285
286 send_gdb "\n"
287 gdb_expect {
288 -re "35\[ \t\]+foo \\(.*\\);.*${last_line_re}\r\n$gdb_prompt $" { incr testcnt }
289 -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests }
290 timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests }
291 }
292
293 pass "repeat list commands to page forward using 'return' ($testcnt tests)"
294
295 gdb_test "list" "Line number 44 out of range; \[^\r\n\]+ has 43 lines\." \
296 "end of file error after using 'return' to repeat the list command"
297
298 gdb_stop_suppressing_tests
299 }
300
301 proc test_list_backwards {} {
302 global gdb_prompt
303
304 set testcnt 0
305
306 send_gdb "list list0.c:33\n"
307 gdb_expect {
308 -re "28\[ \t\]+foo \\(.*\\);.*37\[ \t\]+\}\r\n$gdb_prompt $" { incr testcnt }
309 -re ".*$gdb_prompt $" { fail "list list0.c:33" ; gdb_suppress_tests }
310 timeout { fail "list list0.c:33 (timeout)" ; gdb_suppress_tests }
311 }
312
313 send_gdb "list -\n"
314 gdb_expect {
315 -re "18\[ \t\]+foo \[(\]+.*\[)\]+;.*27\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
316 -re ".*$gdb_prompt $" { fail "list 18-27" ; gdb_suppress_tests }
317 timeout { fail "list 18-27 (timeout)" ; gdb_suppress_tests }
318 }
319
320 send_gdb "list -\n"
321 gdb_expect {
322 -re "8\[ \t\]+foo \[(\]+.*\[)\]+;.*17\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt }
323 -re ".*$gdb_prompt $" { fail "list 8-17" ; gdb_suppress_tests }
324 timeout { fail "list 8-17 (timeout)" ; gdb_suppress_tests }
325 }
326
327 send_gdb "list -\n"
328 gdb_expect {
329 -re "1\[ \t\]+#include .*7\[ \t\]+x = 0;\r\n$gdb_prompt $" { incr testcnt }
330 -re ".*$gdb_prompt $" { fail "list 1-7" ; gdb_suppress_tests }
331 timeout { fail "list 1-7 (timeout)" ; gdb_suppress_tests }
332 }
333
334 pass "$testcnt successive \"list -\" commands to page backwards"
335
336 gdb_test "list -" "Already at the start of .*\." \
337 "beginning of file error after \"list -\" command"
338
339 gdb_stop_suppressing_tests
340 }
341
342 #
343 # Test "list first,last"
344 #
345
346 proc test_list_range {} {
347 global gdb_prompt
348 global last_line_re
349 global last_line
350
351 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"
352
353 gdb_test "list 2,5" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+.*5\[ \t\]+int x;" "list range; line1,line2"
354
355 # gdb_test "list -1,6" "Line number 0 out of range; .*list0.c has 39 lines." "list range; lower bound negative"
356
357 # gdb_test "list -100,-40" "Line number -60 out of range; .*list0.c has 39 lines." "list range; both bounds negative"
358
359 set past_end [expr ${last_line} + 10]
360 set much_past_end [expr ${past_end} + 10]
361
362 gdb_test "list 30,${past_end}" "30\[ \t\]+foo \(.*\);.*${last_line_re}" "list range; upper bound past EOF"
363
364 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"
365
366 gdb_test "list list0.c:2,list1.c:17" "Specified start and end are in different files." "list range, must be same files"
367 }
368
369 #
370 # Test "list filename:function"
371 #
372
373 proc test_list_filename_and_function {} {
374 global gdb_prompt
375 global last_line_re
376
377 set testcnt 0
378
379 # gcc appears to generate incorrect debugging information for code
380 # in include files, which breaks this test.
381 # SunPRO cc is the second case below, it's also correct.
382 send_gdb "list list0.c:main\n"
383 gdb_expect {
384 -re "1\[ \t\]+#include .*10\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
385 incr testcnt
386 }
387 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
388 pass "list function in source file 1"
389 }
390 -re ".*$gdb_prompt $" { fail "list list0.c:main" }
391 timeout { fail "list list0.c:main (timeout)" }
392 }
393
394 # Not sure what the point of having this function be unused is.
395 # AIX is legitimately removing it.
396 setup_xfail "rs6000-*-aix*"
397 send_gdb "list list0.c:unused\n"
398 gdb_expect {
399 -re "40\[ \t\]+unused.*${last_line_re}\r\n$gdb_prompt $" {
400 incr testcnt
401 }
402 -re "37.*42\[ \t\]+\}\r\n$gdb_prompt $" {
403 incr testcnt
404 }
405 -re ".*$gdb_prompt $" { fail "list list0.c:unused" }
406 timeout { fail "list list0.c:unused (timeout)" }
407 }
408 clear_xfail "rs6000-*-aix*"
409
410 # gcc appears to generate incorrect debugging information for code
411 # in include files, which breaks this test.
412 # Ultrix gdb is the second case, one line different but still correct.
413 # SunPRO cc is the third case.
414 setup_xfail "rs6000-*-*" 1804
415 setup_xfail_format "COFF"
416 send_gdb "list list0.h:foo\n"
417 gdb_expect {
418 -re "2\[ \t\]+including file. This.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
419 incr testcnt
420 }
421 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
422 incr testcnt
423 }
424 -re "3\[ \t\]+.*12\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" {
425 incr testcnt
426 }
427 -re "No source file named list0.h.\r\n$gdb_prompt $" {
428 fail "list list0.h:foo"
429 }
430 -re ".*$gdb_prompt $" { fail "list list0.h:foo" }
431 timeout { fail "list list0.h:foo (timeout)" }
432 }
433
434 # Ultrix gdb is the second case.
435 send_gdb "list list1.c:bar\n"
436 gdb_expect {
437 -re "4\[ \t\]+void.*13\[ \t\]+\}\r\n$gdb_prompt $" {
438 incr testcnt
439 }
440 -re "4\[ \t\]+void.*12\[ \t\]*long_line ..;\r\n$gdb_prompt $" {
441 incr testcnt
442 }
443 -re "4\[ \t\]+void.*11\[ \t\]*\r\n$gdb_prompt $" {
444 incr testcnt
445 }
446 -re ".*$gdb_prompt $" { fail "list list1.c:bar" }
447 timeout { fail "list list1.c:bar (timeout)" }
448 }
449
450 # Not sure what the point of having this function be unused is.
451 # AIX is legitimately removing it.
452 setup_xfail "rs6000-*-aix*"
453 send_gdb "list list1.c:unused\n"
454 gdb_expect {
455 -re "12\[ \t\]+long_line \[(\]\[)\];.*13\[ \t\]+\}\r\n.*$gdb_prompt $" {
456 incr testcnt
457 }
458 -re "14.*19\[ \t\]+\}\r\n.*$gdb_prompt $" {
459 incr testcnt
460 }
461 -re ".*$gdb_prompt $" { fail "list list1.c:unused" }
462 timeout { fail "list list1.c:unused (timeout)" }
463 }
464 clear_xfail "rs6000-*-aix*"
465
466 pass "list filename:function ($testcnt tests)"
467
468 # Test with quoting.
469 gdb_test "list 'list0.c:main'" "int main.*"
470
471 # Test some invalid specs
472 # The following test takes the FIXME result on most systems using
473 # DWARF. It fails to notice that main() is not in the file requested.
474
475 setup_xfail "*-*-*"
476
477 # Does this actually work ANYWHERE? I believe not, as this is an `aspect' of
478 # lookup_symbol(), where, when it is given a specific symtab which does not
479 # contain the requested symbol, it will subsequently search all of the symtabs
480 # for the requested symbol.
481
482 gdb_test "list list0.c:foo" "Function \"foo\" not defined in .*list0.c" "list filename:function; wrong filename rejected"
483
484 gdb_test "list foobar.c:main" "No source file named foobar.c.|Location not found" "list filename:function; nonexistant file"
485
486 gdb_test "list list0.h:foobar" "Function \"foobar\" not defined in \"list0.h\"." "list filename:function; nonexistant function"
487
488 }
489
490 proc test_forward_search {} {
491 global timeout
492
493 gdb_test_no_output "set listsize 4"
494 # On SunOS4, this gives us lines 19-22. On AIX, it gives us
495 # lines 20-23. This depends on whether the line number of a function
496 # is considered to be the openbrace or the first statement--either one
497 # is acceptable.
498 gdb_test "list long_line" "24\[ \t\]+long_line .*"
499
500 gdb_test "search 4321" " not found"
501
502 gdb_test "search 6789" "28\[ \t\]+oof .6789.;"
503
504 # Test that GDB won't crash if the line being searched is extremely long.
505
506 set oldtimeout $timeout
507 set timeout [expr "$timeout + 300"]
508 verbose "Timeout is now $timeout seconds" 2
509 gdb_test "search 1234" ".*1234.*" "search extremely long line (> 5000 chars)"
510 set timeout $oldtimeout
511 verbose "Timeout is now $timeout seconds" 2
512 }
513
514 proc test_only_end {} {
515 gdb_test_no_output "set listsize 2"
516 gdb_test "list 1" "list 1\r\n1\[ \t\]\[^\r\n\]*\r\n2\[ \t\]\[^\r\n\]*"
517 gdb_test "list ,5" "list ,5\r\n4\[ \t\]\[^\r\n\]*\r\n5\[ \t\]\[^\r\n\]*"
518 }
519
520 proc test_list_invalid_args {} {
521 global binfile
522
523 clean_restart ${binfile}
524 gdb_test "list -INVALID" \
525 "invalid explicit location argument, \"-INVALID\"" \
526 "first use of \"list -INVALID\""
527 gdb_test "list -INVALID" \
528 "invalid explicit location argument, \"-INVALID\"" \
529 "second use of \"list -INVALID\""
530
531 clean_restart ${binfile}
532 gdb_test "list +INVALID" "Function \"\\+INVALID\" not defined." \
533 "first use of \"list +INVALID\""
534 gdb_test "list +INVALID" "Function \"\\+INVALID\" not defined." \
535 "second use of \"list +INVALID\""
536 }
537
538 # Start with a fresh gdb.
539
540 gdb_exit
541 gdb_start
542 gdb_reinitialize_dir $srcdir/$subdir
543 gdb_file_cmd ${binfile}
544
545 gdb_test_no_output "set width 0"
546
547 test_listsize
548 get_debug_format
549 if [ set_listsize 10 ] then {
550 test_list_include_file
551 test_list_filename_and_number
552 test_list_function
553 test_list_forward
554 test_list_backwards
555 test_repeat_list_command
556 test_list_range
557 test_list_filename_and_function
558 test_forward_search
559 test_only_end
560 test_list_invalid_args
561 }
562
563 # Follows tests that require execution.
564
565 # Build source listing pattern based on a line range spec string. The
566 # range can be specificed as "START-END" indicating all lines in range
567 # (inclusive); or just "LINE", indicating just that line.
568
569 proc build_pattern { range_spec } {
570 global line_re
571
572 set range_list [split $range_spec -]
573 set range_list_len [llength $range_list]
574
575 set range_start [lindex $range_list 0]
576 if { $range_list_len > 2 || $range_list_len < 1} {
577 error "invalid range spec string: $range_spec"
578 } elseif { $range_list_len == 2 } {
579 set range_end [lindex $range_list 1]
580 } else {
581 set range_end $range_start
582 }
583
584 for {set i $range_start} {$i <= $range_end} {incr i} {
585 append pattern "\r\n$i\[ \t\]\[^\r\n\]*"
586 }
587
588 verbose -log "pattern $pattern"
589 return $pattern
590 }
591
592 # Test "list" command invocations right after stopping for an event.
593 # COMMAND is the actual list command, including arguments. LISTSIZE1
594 # and LISTSIZE2 are the listsizes set just before and after running
595 # the program to the stop point. COMMAND is issued twice. The first
596 # time, the lines specificed by LINERANGE1 are expected; the second
597 # time, the lines specified by LINERANGE2 are expected.
598
599 proc test_list {command listsize1 listsize2 linerange1 linerange2} {
600 with_test_prefix "$command after stop: $listsize1, $listsize2" {
601 global binfile
602
603 clean_restart $binfile
604 if ![runto_main] then {
605 fail "Can't run to main"
606 return
607 }
608
609 # Test changing the listsize both before nexting, and after
610 # stopping, but before listing. Only the second listsize
611 # change should affect which lines are listed.
612 with_test_prefix "before next" {
613 gdb_test_no_output "set listsize $listsize1"
614 }
615 gdb_test "next" "foo \\(.*"
616 with_test_prefix "after next" {
617 gdb_test_no_output "set listsize $listsize2"
618 }
619
620 set pattern1 [build_pattern $linerange1]
621 set pattern2 [build_pattern $linerange2]
622 gdb_test "$command" "${pattern1}" "$command #1"
623 gdb_test "$command" "${pattern2}" "$command #2"
624 }
625 }
626
627
628 # The first "list" should center the listing around line 8, the stop
629 # line.
630 test_list "list" 1 10 "3-12" "13-22"
631
632 # Likewise.
633 test_list "list" 10 10 "3-12" "13-22"
634
635 # Likewise, but show only one line. IOW, the first list should show
636 # line 8. Note how the listsize is 10 at the time of the stop, but
637 # before any listing had been requested. That should not affect the
638 # line range that is first listed.
639 test_list "list" 10 1 "8" "9"
640
641 # Likewise, but show two lines.
642 test_list "list" 10 2 "7-8" "9-10"
643
644 # Three lines.
645 test_list "list" 10 3 "7-9" "10-12"
646
647 # Now test backwards. Just like "list", the first "list -" should
648 # center the listing around the stop line.
649 test_list "list -" 10 10 "3-12" "2"
650
651 # Likewise, but test showing 3 lines at a time.
652 test_list "list -" 10 3 "7-9" "4-6"
653
654 # 2 lines at a time.
655 test_list "list -" 10 2 "7-8" "5-6"
656
657 # Test listing one line only. This case is a little special and
658 # starts showing the previous line immediately instead of repeating
659 # the current line.
660 test_list "list -" 10 1 "7" "6"
661
662 remote_exec build "rm -f list0.h"