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