* lib/gdb.exp (gdb_test): Between $pattern and $prompt, expect
[binutils-gdb.git] / gdb / testsuite / gdb.base / list.exp
1 # Copyright (C) 1992, 1994 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., 675 Mass Ave, Cambridge, MA 02139, 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 binfile "list"
30 set srcfile $binfile.c
31
32 if ![file exists $objdir/$subdir/$binfile] then {
33 perror "$objdir/$subdir/$binfile does not exist."
34 return 0
35 }
36
37 #
38 # Local utility proc just to set and verify listsize
39 # Return 1 if success, 0 if fail.
40 #
41
42 proc set_listsize { arg } {
43 global prompt
44
45 send "set listsize $arg\n"
46 expect {
47 -re "set listsize $arg\r\n$prompt $" {}
48 -re ".*$prompt $" { fail "setting listsize to $arg" ; return 0 }
49 timeout { fail "set listsize to $arg (timeout)" ; return 0 }
50 }
51
52 send "show listsize\n"
53 expect {
54 -re "Number of source lines .* is $arg.\r\n.*$prompt $" {}
55 -re ".*$prompt $" { fail "listsize not set to $arg" ; return 0 }
56 timeout { fail "show listsize (timeout)" ; return 0 }
57 }
58 return 1
59 }
60
61 #
62 # Test display of listsize lines around a given line number.
63 #
64
65 proc test_listsize {} {
66 global prompt
67
68 # Show default size
69
70 send "show listsize\n"
71 expect {
72 -re "Number of source lines gdb will list by default is 10.*$prompt $" {
73 pass "show default list size"
74 }
75 -re ".*$prompt $" {
76 fail "show default listsize (10)"
77 }
78 timeout {
79 fail "show listsize (timeout)"
80 }
81 }
82
83 # Show the default lines
84
85 # This doesn't work for COFF targets.
86 setup_xfail "a29k-*-udi"
87 send "list\n"
88 expect {
89 -re "1\[ \t\]+#include \"list0.h\".*10\[ \t\]+foo .x\[+)\]+;\r\n$prompt $" {
90 pass "show default lines around main"
91 }
92 -re ".*$prompt $" {
93 fail "list default lines around main"
94 }
95 timeout {
96 fail "list default lines around main (timeout)"
97 }
98 }
99
100 # Ensure we can limit printouts to one line
101
102 if [ set_listsize 1 ] then {
103 setup_xfail "*-*-*"
104 send "list 1\n"
105 expect {
106 -re "1\[ \t\]+#include \"list0.h\"\r\n$prompt $" {
107 pass "list line 1 with listsize 1"
108 }
109 -re "list 1\r\n$prompt $" {
110 fail "list line 1 with listsize 1"
111 }
112 -re ".*$prompt $" {
113 fail "list line 1 with listsize 1"
114 }
115 timeout {
116 fail "list line 1 with listsize 1 (timeout)"
117 }
118 }
119
120 setup_xfail "*-*-*"
121 send "list 2\n"
122 expect {
123 -re "2\[ \t\]+\r\n$prompt $" {
124 pass "list line 2 with listsize 1"
125 }
126 -re "list 2\r\n$prompt $" {
127 fail "list line 2 with listsize 1"
128 }
129 -re ".*$prompt $" {
130 fail "list line 2 with listsize 1"
131 }
132 timeout {
133 fail "list line 2 with listsize 1 (timeout)"
134 }
135 }
136 }
137
138 # Try just two lines
139
140 if [ set_listsize 2 ] then {
141 send "list 1\n"
142 expect {
143 -re "1\[ \t\]+#include \"list0.h\"\r\n$prompt $" {
144 pass "list line 1 with listsize 2"
145 }
146 -re ".*$prompt $" {
147 fail "list line 1 with listsize 2"
148 }
149 timeout {
150 fail "list line 1 with listsize 2 (timeout)"
151 }
152 }
153
154 send "list 2\n"
155 expect {
156 -re "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+\r\n$prompt $" {
157 pass "list line 2 with listsize 2"
158 }
159 -re ".*$prompt $" {
160 fail "list line 2 with listsize 2"
161 }
162 timeout {
163 fail "list line 2 with listsize 2 (timeout)"
164 }
165 }
166
167 send "list 3\n"
168 expect {
169 -re "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+\r\n$prompt $" {
170 pass "list line 3 with listsize 2"
171 }
172 -re ".*$prompt $" {
173 fail "list line 3 with listsize 2"
174 }
175 timeout {
176 fail "list line 3 with listsize 2 (timeout)"
177 }
178 }
179 }
180
181 # Try small listsize > 1 that is an odd number
182
183 if [ set_listsize 3 ] then {
184 setup_xfail "*-*-*"
185 send "list 1\n"
186 expect {
187 -re "1\[ \t\]+#include \"list0.h\"2\[ \t\]+\r\n$prompt $" {
188 pass "list line 1 with listsize 3"
189 }
190 -re "1\[ \t\]+#include \"list0.h\"\r\n$prompt $" {
191 fail "list line 1 with listsize 3"
192 }
193 -re ".*$prompt $" {
194 fail "list line 1 with listsize 3"
195 }
196 timeout {
197 fail "list line 1 with listsize 3 (timeout)"
198 }
199 }
200
201 setup_xfail "*-*-*"
202 send "list 2\n"
203 expect {
204 -re "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+main \[)(\]+\r\n$prompt $" {
205 pass "list line 2 with listsize 3"
206 }
207 -re "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+\r\n$prompt $" {
208 fail "list line 2 with listsize 3"
209 }
210 -re ".*$prompt $" {
211 fail "list line 2 with listsize 3"
212 }
213 timeout {
214 fail "list line 2 with listsize 3 (timeout)"
215 }
216 }
217
218 setup_xfail "*-*-*"
219 send "list 3\n"
220 expect {
221 -re "2\[ \t\]+\r\n3\[ \t\]+main \[(\]+\[)\]+\r\n4\[ \t\]+\{\r\n$prompt $" {
222 pass "list line 3 with listsize 3"
223 }
224 -re "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+\r\n$prompt $" {
225 fail "list line 3 with listsize 3"
226 }
227 -re ".*$prompt $" {
228 fail "list line 3 with listsize 3"
229 }
230 timeout {
231 fail "list line 3 with listsize 3 (timeout)"
232 }
233 }
234 }
235
236 # Try small listsize > 2 that is an even number.
237
238 if [ set_listsize 4 ] then {
239 send "list 1\n"
240 expect {
241 -re "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+\r\n$prompt $" {
242 pass "list line 1 with listsize 4"
243 }
244 -re ".*$prompt $" {
245 fail "list line 1 with listsize 4"
246 }
247 timeout {
248 fail "list line 1 with listsize 4 (timeout)"
249 }
250 }
251
252 send "list 2\n"
253 expect {
254 -re "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+main \[)(\]+\r\n$prompt $" {
255 pass "list line 2 with listsize 4"
256 }
257 -re ".*$prompt $" {
258 fail "list line 2 with listsize 4"
259 }
260 timeout {
261 fail "list line 2 with listsize 4 (timeout)"
262 }
263 }
264
265 send "list 3\n"
266 expect {
267 -re "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{\r\n$prompt $" {
268 pass "list line 3 with listsize 4"
269 }
270 -re ".*$prompt $" {
271 fail "list line 3 with listsize 4"
272 }
273 timeout {
274 fail "list line 3 with listsize 4 (timeout)"
275 }
276 }
277
278 send "list 4\n"
279 expect {
280 -re "2\[ \t\]+\r\n.*5\[ \t\]+int x;\r\n$prompt $" {
281 pass "list line 4 with listsize 4"
282 }
283 -re ".*$prompt $" {
284 fail "list line 4 with listsize 4"
285 }
286 timeout {
287 fail "list line 4 with listsize 4 (timeout)"
288 }
289 }
290 }
291
292 # Try a size larger than the entire file.
293
294 if [ set_listsize 100 ] then {
295 send "list 1\n"
296 expect {
297 -re "1\[ \t\]+#include \"list0.h\".*\r\n39\[ \t\]+\}\r\n$prompt $" {
298 pass "list line 1 with listsize 100"
299 }
300 timeout {
301 fail "list line 1 with listsize 100"
302 }
303 }
304
305 send "list 10\n"
306 expect {
307 -re "1\[ \t\]+#include \"list0.h\".*\r\n39\[ \t\]+\}\r\n$prompt $" {
308 pass "list line 1 with listsize 100"
309 }
310 timeout {
311 fail "list line 1 with listsize 100"
312 }
313 }
314 }
315
316 # Try listsize of 0 which suppresses printing.
317
318 send "set listsize 0\n"
319 expect {
320 -re "set listsize 0\r\n$prompt $" {
321 setup_xfail "*-*-*"
322 send "show listsize\n"
323 expect {
324 -re "Number of source lines .* is 0.\r\n.*$prompt $" {
325 pass "listsize of 0 displays as 0"
326 }
327 -re "Number of source lines .* is unlimited.\r\n.*$prompt $" {
328 fail "listsize of 0 displays as unlimited"
329 }
330 -re ".*$prompt $" {
331 fail "listsize not set to unlimited (0)"
332 }
333 timeout {
334 fail "show listsize (timeout)"
335 }
336 }
337 send "list 1\n"
338 expect {
339 -re "list 1\r\n$prompt $" {
340 pass "listsize of 0 suppresses output"
341 }
342 -re ".*$prompt $" {
343 fail "listsize of 0 should suppress output"
344 }
345 timeout {
346 fail "listsize of 0 suppresses output (timeout)"
347 }
348 }
349 }
350 -re ".*$prompt $" {
351 fail "setting listsize to 0"
352 }
353 timeout {
354 fail "set listsize to 0 (timeout)"
355 }
356 }
357
358 # Try listsize of -1 which is special, and means unlimited.
359
360 send "set listsize -1\n"
361 expect {
362 -re "set listsize -1\r\n$prompt $" {
363 send "show listsize\n"
364 expect {
365 -re "Number of source lines .* is unlimited.\r\n.*$prompt $" {
366 pass "listsize of -1 displays as unlimited"
367 }
368 -re ".*$prompt $" {
369 fail "listsize not set to unlimited (-1)"
370 }
371 timeout {
372 fail "show listsize (timeout)"
373 }
374 }
375 setup_xfail "*-*-*"
376 send "list 1\n"
377 expect {
378 -re "1\[ \t\]+#include .*\r\n39\[ \t\]+\}\r\n$prompt $" {
379 pass "list line 1 with unlimited listsize"
380 }
381 -re "list 1\r\n$prompt $" {
382 fail "listsize of -1 (unlimited) suppresses output"
383 }
384 timeout {
385 fail "list line 1 with unlimited listsize"
386 }
387 }
388 }
389 -re ".*$prompt $" {
390 fail "setting listsize to -1"
391 }
392 timeout {
393 fail "set listsize to -1 (timeout)"
394 }
395 }
396 }
397
398 #
399 # Test "list filename:number" for C include file
400 #
401
402 proc test_list_include_file {} {
403 global prompt
404
405 # FIXME This fails on DWARF.
406 setup_xfail "*-*-sysv4*"
407 # FIXME Fails for COFF as well, I think.
408 setup_xfail "a29k-*-udi"
409 send "list list0.h:1\n"
410 expect {
411 -re "1\[ \t\]+/\[*\]+ An include file .*5\[ \t\]+foo \[(\]+x\[)\]+\r\n$prompt $" {
412 pass "list line 1 in include file"
413 }
414 -re "No source file named list0.h.\r\n$prompt $" {
415 fail "list line 1 in include file"
416 }
417 -re ".*$prompt $" {
418 fail "list line 1 in include file"
419 }
420 timeout {
421 fail "list line 1 in include file (timeout)"
422 }
423 }
424
425 # FIXME fails on DWARF
426 setup_xfail "*-*-sysv4*"
427 # FIXME Fails for COFF as well, I think.
428 setup_xfail "a29k-*-udi"
429 send "list list0.h:100\n"
430 expect {
431 -re "Line number 95 out of range; .*list0.h has 36 lines.\r\n$prompt $" {
432 pass "list message for lines past EOF"
433 }
434 -re "No source file named list0.h.\r\n$prompt $" {
435 fail "list message for lines past EOF"
436 }
437 -re ".*$prompt $" {
438 fail "list message for lines past EOF"
439 }
440 timeout {
441 fail "list message for lines past EOF (timeout)"
442 }
443 }
444 }
445
446 #
447 # Test "list filename:number" for C source file
448 #
449
450 proc test_list_filename_and_number {} {
451 global prompt
452
453 set testcnt 0
454
455 send "list list0.c:1\n"
456 expect {
457 -re "1\[ \t\]+#include \"list0.h\".*5\[ \t\]+int x;\r\n$prompt $" {
458 incr testcnt
459 }
460 -re ".*$prompt $" { fail "list list0.c:1" ; return }
461 timeout { fail "list list0.c:1" ; return }
462 }
463 send "list list0.c:10\n"
464 expect {
465 -re "5\[ \t\]+int x;.*14\[ \t\]+foo .x\[+)\]+;\r\n$prompt $" {
466 incr testcnt
467 }
468 -re ".*$prompt $" { fail "list list.c:10" ; return }
469 timeout { fail "list list.c:10" ; return }
470 }
471 send "list list1.c:1\n"
472 expect {
473 -re "1\[ \t\]+void.*5\[ \t\]+printf \[(\]+.*\[)\]+;\r\n$prompt $" {
474 incr testcnt
475 }
476 -re ".*$prompt $" { fail "list list1.c:1" ; return }
477 timeout { fail "list list1.c:1" ; return }
478 }
479 send "list list1.c:12\n"
480 expect {
481 -re "7\[ \t\]+long_line \[(\]+.*\[)\]+;.*14\[ \t\]+\}\r\n.*$prompt $" {
482 incr testcnt
483 }
484 -re ".*$prompt $" { fail "list list1.c:12" ; return }
485 timeout { fail "list list1.c:12" ; return }
486 }
487 pass "list filename:number ($testcnt tests)"
488 }
489
490 #
491 # Test "list function" for C source file
492 #
493
494 proc test_list_function {} {
495 global prompt
496
497 # gcc appears to generate incorrect debugging information for code
498 # in include files, which breaks this test.
499 setup_xfail "rs6000-*-*" 1804
500 setup_xfail "a29k-*-udi"
501 send "list main\n"
502 expect {
503 -re "1\[ \t\]+#include .*8\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" {
504 pass "list function in source file 1"
505 }
506 -re ".*$prompt $" { fail "list main" ; return }
507 timeout { fail "list main" ; return }
508 }
509
510 # Ultrix gdb takes the second case below; it's also correct.
511 send "list bar\n"
512 expect {
513 -re "1\[ \t\]+void.*8\[ \t\]+\}\r\n$prompt $" {
514 pass "list function in source file 2"
515 }
516 -re "1\[ \t\]+void.*7\[ \t\]*long_line ..;\r\n$prompt $" {
517 pass "list function in source file 2"
518 }
519 -re ".*$prompt $" { fail "list bar" ; return }
520 timeout { fail "list bar" ; return }
521 }
522
523 # Test "list function" for C include file
524 # Ultrix gdb is the second case, still correct.
525 # FIXME This fails on DWARF
526 setup_xfail "*-*-sysv4*"
527 send "list foo\n"
528 expect {
529 -re "2\[ \t\]+including file.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" {
530 pass "list function in include file"
531 }
532 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" {
533 pass "list function in include file"
534 }
535 -re ".*main \[)(\]+.*$prompt $" {
536 fail "list function in include file"
537 }
538 -re ".*$prompt $" { fail "list foo (in include file)" ; return }
539 timeout { fail "list foo (timeout)" ; return }
540 }
541 }
542
543 proc test_list_forward {} {
544 global prompt
545
546 set testcnt 0
547
548 send "list list0.c:10\n"
549 expect {
550 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { incr testcnt }
551 -re ".*$prompt $" { fail "list list0.c:10" ; return }
552 timeout { fail "list list0.c:10" ; return }
553 }
554
555 send "list\n"
556 expect {
557 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { incr testcnt }
558 -re ".*$prompt $" { fail "list 15-24" ; return }
559 timeout { fail "list 15-24 (timeout)" ; return }
560 }
561
562 send "list\n"
563 expect {
564 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+\r\n$prompt $" { incr testcnt }
565 -re ".*$prompt $" { fail "list 25-34" ; return }
566 timeout { fail "list 25-34 (timeout)" ; return }
567 }
568
569 send "list\n"
570 expect {
571 -re "35\[ \t\]+static void.*39\[ \t\]+\}\r\n$prompt $" { incr testcnt }
572 -re ".*$prompt $" { fail "list 35-39" ; return }
573 timeout { fail "list 35-39 (timeout)" ; return }
574 }
575
576 pass "successive list commands to page forward ($testcnt tests)"
577 }
578
579 proc test_list_backwards {} {
580 global prompt
581
582 set testcnt 0
583
584 send "list list0.c:30\n"
585 expect {
586 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+\r\n$prompt $" { incr testcnt }
587 -re ".*$prompt $" { fail "list list0.c:30" ; return }
588 timeout { fail "list list0.c:30" ; return }
589 }
590
591 send "list -\n"
592 expect {
593 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { incr testcnt }
594 -re ".*$prompt $" { fail "list 15-24" ; return }
595 timeout { fail "list 15-24 (timeout)" ; return }
596 }
597
598 send "list -\n"
599 expect {
600 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { incr testcnt }
601 -re ".*$prompt $" { fail "list 5-14" ; return }
602 timeout { fail "list 5-14 (timeout)" ; return }
603 }
604
605 send "list -\n"
606 expect {
607 -re "1\[ \t\]+#include .*4\[ \t\]+\{\r\n$prompt $" { incr testcnt }
608 -re ".*$prompt $" { fail "list 1-4" ; return }
609 timeout { fail "list 1-4 (timeout)" ; return }
610 }
611
612 pass "$testcnt successive \"list -\" commands to page backwards"
613 }
614
615 #
616 # Test "list first,last"
617 #
618
619 proc test_list_range {} {
620 global prompt
621
622 send "list list0.c:2,list0.c:5\n"
623 expect {
624 -re "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+.*5\[ \t\]+int x;\r\n$prompt $" {
625 pass "list range; filename:line1,filename:line2"
626 }
627 -re ".*$prompt $" { fail "list list0.c:2,list0.c:5" }
628 timeout { fail "list list0.c:2,list0.c:5" }
629 }
630
631 send "list 2,5\n"
632 expect {
633 -re "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+.*5\[ \t\]+int x;\r\n$prompt $" {
634 pass "list range; line1,line2"
635 }
636 -re ".*$prompt $" { fail "list 2,5" }
637 timeout { fail "list 2,5" }
638 }
639
640 #send "list -1,6\n"
641 #expect {
642 #-re "Line number 0 out of range; .*list0.c has 39 lines.\r\n$prompt $" {
643 #pass "list range; lower bound negative"
644 #}
645 #-re ".*$prompt $" { fail "list -1,6" }
646 #timeout { fail "list -1,6" }
647 #}
648
649 #send "list -100,-40\n"
650 #expect {
651 #-re "Line number -60 out of range; .*list0.c has 39 lines.\r\n$prompt $" {
652 #pass "list range; both bounds negative"
653 #}
654 #-re ".*$prompt $" { fail "-100,-40" }
655 #timeout { fail "-100,-40" }
656 #}
657
658 send "list 30,40\n"
659 expect {
660 -re "30\[ \t\]+foo \[(\]+.*\[)\]+;.*39\[ \t\]+\}\r\n$prompt $" {
661 pass "list range; upper bound past EOF"
662 }
663 -re ".*$prompt $" { fail "list 30,40" }
664 timeout { fail "list 30,40" }
665 }
666
667 send "list 40,100\n"
668 expect {
669 -re "Line number 40 out of range; .*list0.c has 39 lines.\r\n$prompt $" {
670 pass "list range; both bounds past EOF"
671 }
672 -re ".*$prompt $" { fail "40,100" }
673 timeout { fail "40,100" }
674 }
675
676 send "list list0.c:2,list1.c:17\n"
677 expect {
678 -re "Specified start and end are in different files.\r\n$prompt $" {
679 pass "list range, must be same files"
680 }
681 -re ".*$prompt $" { fail "list0.c:2,list1.c:17" }
682 timeout { fail "list0.c:2,list1.c:17" }
683 }
684 }
685
686 #
687 # Test "list filename:function"
688 #
689
690 proc test_list_filename_and_function {} {
691 global prompt
692
693 set testcnt 0
694
695 # gcc appears to generate incorrect debugging information for code
696 # in include files, which breaks this test.
697 setup_xfail "rs6000-*-*" 1804
698 setup_xfail "a29k-*-udi"
699 send "list list0.c:main\n"
700 expect {
701 -re "1\[ \t\]+#include .*8\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" {
702 incr testcnt
703 }
704 -re ".*$prompt $" { fail "list list0.c:main" }
705 timeout { fail "list list0.c:main (timeout)" }
706 }
707
708 # The i960 and a29k-amd-udi are the second case
709
710 # Not sure what the point of having this function be unused is.
711 # AIX is legitimately removing it.
712 setup_xfail "rs6000-*-aix*"
713 send "list list0.c:unused\n"
714 expect {
715 -re "32\[ \t\]+foo \[(\]+.*\[)\]+;.*39\[ \t\]+\}\r\n$prompt $" {
716 incr testcnt
717 }
718 -re "34.*39\[ \t\]+\}\r\n$prompt $" {
719 incr testcnt
720 }
721 -re ".*$prompt $" { fail "list list0.c:unused" }
722 timeout { fail "list list0.c:unused (timeout)" }
723 }
724 clear_xfail "rs6000-*-aix*"
725
726 # gcc appears to generate incorrect debugging information for code
727 # in include files, which breaks this test.
728 # Ultrix gdb is the second case, one line different but still correct.
729 # FIXME This fails on DWARF
730 setup_xfail "rs6000-*-*" 1804
731 setup_xfail "*-*-sysv4*"
732 # FIXME Fails for COFF as well, I think.
733 setup_xfail "a29k-*-udi"
734 send "list list0.h:foo\n"
735 expect {
736 -re "2\[ \t\]+including file. This.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" {
737 incr testcnt
738 }
739 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" {
740 incr testcnt
741 }
742 -re "No source file named list0.h.\r\n$prompt $" {
743 fail "list list0.h:foo"
744 }
745 -re ".*$prompt $" { fail "list list0.h:foo" }
746 timeout { fail "list list0.h:foo (timeout)" }
747 }
748
749 # Ultrix gdb is the second case.
750 # a29k-amd-udi is the third case.
751 send "list list1.c:bar\n"
752 expect {
753 -re "1\[ \t\]+void.*8\[ \t\]+\}\r\n$prompt $" {
754 incr testcnt
755 }
756 -re "1\[ \t\]+void.*7\[ \t\]*long_line ..;\r\n$prompt $" {
757 incr testcnt
758 }
759 -re "1\[ \t\]+void.*9\[ \t\]*\r\n$prompt $" {
760 incr testcnt
761 }
762 -re ".*$prompt $" { fail "list list1.c:bar" }
763 timeout { fail "list list1.c:bar (timeout)" }
764 }
765
766 # The i960 and a29k-amd-udi are the second case
767
768 # Not sure what the point of having this function be unused is.
769 # AIX is legitimately removing it.
770 setup_xfail "rs6000-*-aix*"
771 send "list list1.c:unused\n"
772 expect {
773 -re "7\[ \t\]+long_line \[(\]\[)\];.*14\[ \t\]+\}\r\n.*$prompt $" {
774 incr testcnt
775 }
776 -re "9.*14\[ \t\]+\}\r\n.*$prompt $" {
777 incr testcnt
778 }
779 -re ".*$prompt $" { fail "list list1.c:unused" }
780 timeout { fail "list list1.c:unused (timeout)" }
781 }
782 clear_xfail "rs6000-*-aix*"
783
784 pass "list filename:function ($testcnt tests)"
785
786 # Test some invalid specs
787 # The following test takes the FIXME result on most systems using
788 # DWARF. It fails to notice that main() is not in the file requested.
789
790 setup_xfail "*-*-*"
791
792 # Does this actually work ANYWHERE? I believe not, as this is an `aspect' of
793 # lookup_symbol(), where, when it is given a specific symtab which does not
794 # contain the requested symbol, it will subsequently search all of the symtabs
795 # for the requested symbol.
796
797 send "list list0.c:foo\n"
798 expect {
799 -re "Function \"foo\" not defined in .*list0.c\r\n$prompt $" {
800 pass "list filename:function; wrong filename rejected"
801 }
802 -re "2\[ \t\]+including file.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" {
803 fail "list filename:function; wrong filename not rejected"
804 }
805 -re ".*main \[)(\]+.*$prompt $" {
806 fail "list filename:function; wrong filename not rejected"
807 }
808 -re ".*$prompt $" {
809 fail "list filename:function; wrong filename not rejected"
810 }
811 timeout {
812 fail "list filename:function; wrong filename (timeout)"
813 }
814 }
815
816 send "list foobar.c:main\n"
817 expect {
818 -re "No source file named foobar.c.\r\n$prompt $" {
819 pass "list filename:function; nonexistant file"
820 }
821 -re ".*$prompt $" {
822 fail "list filename:function; nonexistant file"
823 }
824 timeout {
825 fail "list filename:function; nonexistant file (timeout)"
826 }
827 }
828
829 # The following test takes the FIXME result on most systems using
830 # DWARF. It doesn't know how to find functions in include files.
831
832 setup_xfail "*-*-sysv4*"
833 send "list list0.h:foobar\n"
834 expect {
835 -re "Function \"foobar\" not defined.\r\n$prompt $" {
836 pass "list filename:function; nonexistant function"
837 }
838 -re "No source file named list0.h.\r\n$prompt $" {
839 fail "list filename:function; nonexistant function"
840 }
841 -re ".*$prompt $" {
842 fail "list filename:function; nonexistant function"
843 }
844 timeout {
845 fail "list filename:function; nonexistant function (timeout)"
846 }
847 }
848
849 }
850
851 proc test_forward_search {} {
852 gdb_test "set listsize 2" ""
853 gdb_test "list long_line" "20\[ \t\]+long_line "
854
855 gdb_test "search 4321" " not found"
856
857 gdb_test "search 6789" "22\[ \t\]+oof .6789.;"
858
859 # We could look at the result of this, but dejagnu seems to
860 # fail, perhaps because expect's buffers are too small.
861 # In any case, we just want GDB to not crash if the line
862 # being searched is extremely long.
863
864 gdb_test "search 1234" ""
865 }
866
867 # Start with a fresh gdb.
868
869 gdb_exit
870 gdb_start
871 gdb_reinitialize_dir $srcdir/$subdir
872 gdb_load $objdir/$subdir/$binfile
873
874 send "set width 0\n"
875 expect -re "$prompt $"
876
877 test_listsize
878 if [ set_listsize 10 ] then {
879 test_list_include_file
880 test_list_filename_and_number
881 test_list_function
882 test_list_forward
883 test_list_backwards
884 test_list_range
885 test_list_filename_and_function
886 test_forward_search
887 }