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