Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright 1992-2015 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 | 19 | standard_testfile list0.c list1.c |
c906108c SS |
20 | |
21 | # Need to download the header to the host. | |
08b3fe69 | 22 | gdb_remote_download host ${srcdir}/${subdir}/list0.h |
c906108c | 23 | |
f8b41b00 TT |
24 | if {[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 | 31 | if [get_compiler_info] { |
ae59b1da | 32 | return -1 |
c906108c SS |
33 | } |
34 | ||
fc0da894 PA |
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 | ||
c906108c SS |
41 | # |
42 | # Local utility proc just to set and verify listsize | |
43 | # Return 1 if success, 0 if fail. | |
44 | # | |
45 | ||
4ec70201 | 46 | set set_listsize_count 0 |
c906108c SS |
47 | |
48 | proc 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 | ||
70 | proc test_listsize {} { | |
8e09ad05 | 71 | global gdb_prompt |
085dd6e6 JM |
72 | global hp_cc_compiler |
73 | global hp_aCC_compiler | |
fc0da894 | 74 | global last_line_re |
c906108c SS |
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 | |
8e09ad05 IS |
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" | |
c906108c SS |
83 | |
84 | # Ensure we can limit printouts to one line | |
85 | ||
085dd6e6 | 86 | if [set_listsize 1] { |
c906108c | 87 | gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"" "list line 1 with listsize 1" |
c906108c SS |
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 ] { | |
d4f3574e | 94 | gdb_test "list 1" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 1 with listsize 2" |
c906108c | 95 | gdb_test "list 2" "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+" "list line 2 with listsize 2" |
085dd6e6 | 96 | gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+" "list line 3 with listsize 2" |
c906108c SS |
97 | } |
98 | ||
99 | # Try small listsize > 1 that is an odd number | |
100 | ||
101 | if [ set_listsize 3 ] { | |
d4f3574e | 102 | gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 1 with listsize 3" |
085dd6e6 | 103 | gdb_test "list 2" "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+int main \[)(\]+" "list line 2 with listsize 3" |
085dd6e6 | 104 | gdb_test "list 3" "2\[ \t\]+\r\n3\[ \t\]+int main \[(\]+\[)\]+\r\n4\[ \t\]+\{" "list line 3 with listsize 3" |
c906108c SS |
105 | } |
106 | ||
107 | # Try small listsize > 2 that is an even number. | |
108 | ||
109 | if [ set_listsize 4 ] then { | |
d4f3574e SS |
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" | |
c906108c SS |
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 { | |
fc0da894 | 120 | gdb_test "list 1" "1\[ \t\]+#include \"list0.h\".*\r\n${last_line_re}" "list line 1 with listsize 100" |
c906108c | 121 | |
fc0da894 | 122 | gdb_test "list 10" "1\[ \t\]+#include \"list0.h\".*\r\n${last_line_re}" "list line 10 with listsize 100" |
c906108c SS |
123 | } |
124 | ||
7f7cc265 | 125 | # Try listsize of 0 which is special, and means unlimited. |
c906108c SS |
126 | |
127 | set_listsize 0 | |
fc0da894 | 128 | gdb_test "list 1" "1\[ \t\]+#include .*\r\n${last_line_re}" "list line 1 with unlimited listsize" |
c906108c SS |
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 | ||
c906108c | 138 | setup_xfail_format "COFF" |
d4f3574e | 139 | gdb_test "list list0.h:1" "1\[ \t\]+/\[*\]+ An include file .*10\[ \t\]+bar \\(x\\+\\+\\);" "list line 1 in include file" |
c906108c | 140 | |
c906108c | 141 | setup_xfail_format "COFF" |
085dd6e6 | 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" |
c906108c SS |
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 { | |
924437bc | 156 | -re "1\[ \t\]+#include \"list0.h\".*10\[ \t\]+foo .x\[+)\]+;\r\n$gdb_prompt $" { |
c906108c SS |
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 { | |
085dd6e6 | 172 | -re "1\[ \t\]+\#include.*4\[ \t\]+.*int oof\[ \t\]*\(.*\);\r\n.*$gdb_prompt $" { |
c906108c SS |
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 { | |
085dd6e6 | 180 | -re "12\[ \t\]+long_line \[(\]+.*\[)\]+;.*13\[ \t\]+\}\r\n.*$gdb_prompt $" { |
c906108c SS |
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)" | |
4ec70201 | 187 | gdb_stop_suppressing_tests |
c906108c SS |
188 | } |
189 | ||
190 | # | |
191 | # Test "list function" for C source file | |
192 | # | |
193 | ||
194 | proc test_list_function {} { | |
195 | global gdb_prompt | |
c906108c SS |
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. | |
924437bc | 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" |
c906108c SS |
201 | |
202 | # Ultrix gdb takes the second case below; it's also correct. | |
203 | # SunPRO cc is the third case. | |
085dd6e6 | 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" |
c906108c SS |
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. | |
c906108c SS |
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 | |
fc0da894 | 214 | global last_line_re |
c906108c SS |
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 { | |
fc0da894 | 241 | -re "35\[ \t\]+foo \\(.*\\);.*${last_line_re}\r\n$gdb_prompt $" { incr testcnt } |
c906108c SS |
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)" | |
4ec70201 | 247 | gdb_stop_suppressing_tests |
c906108c SS |
248 | } |
249 | ||
a0b3c4fd JM |
250 | # Test that repeating the list linenum command doesn't print the same |
251 | # lines over again. Note that this test makes sure that the argument | |
252 | # linenum is dropped, when we repeat the previous command. 'x/5i $pc' | |
253 | # works the same way. | |
254 | ||
255 | proc test_repeat_list_command {} { | |
256 | global gdb_prompt | |
fc0da894 | 257 | global last_line_re |
a0b3c4fd JM |
258 | |
259 | set testcnt 0 | |
260 | ||
261 | send_gdb "list list0.c:10\n" | |
262 | gdb_expect { | |
263 | -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt } | |
264 | -re ".*$gdb_prompt $" { fail "list list0.c:10" ; gdb_suppress_tests } | |
265 | timeout { fail "list list0.c:10 (timeout)" ; gdb_suppress_tests } | |
266 | } | |
267 | ||
268 | send_gdb "\n" | |
269 | gdb_expect { | |
270 | -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt } | |
271 | -re ".*$gdb_prompt $" { fail "list 15-24" ; gdb_suppress_tests } | |
272 | timeout { fail "list 15-24 (timeout)" ; gdb_suppress_tests } | |
273 | } | |
274 | ||
275 | send_gdb "\n" | |
276 | gdb_expect { | |
277 | -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt } | |
278 | -re ".*$gdb_prompt $" { fail "list 25-34" ; gdb_suppress_tests } | |
279 | timeout { fail "list 25-34 (timeout)" ; gdb_suppress_tests } | |
280 | } | |
281 | ||
282 | send_gdb "\n" | |
283 | gdb_expect { | |
fc0da894 | 284 | -re "35\[ \t\]+foo \\(.*\\);.*${last_line_re}\r\n$gdb_prompt $" { incr testcnt } |
a0b3c4fd JM |
285 | -re ".*$gdb_prompt $" { fail "list 35-42" ; gdb_suppress_tests } |
286 | timeout { fail "list 35-42 (timeout)" ; gdb_suppress_tests } | |
287 | } | |
288 | ||
289 | pass "repeat list commands to page forward using 'return' ($testcnt tests)" | |
4ec70201 | 290 | gdb_stop_suppressing_tests |
a0b3c4fd JM |
291 | } |
292 | ||
c906108c SS |
293 | proc test_list_backwards {} { |
294 | global gdb_prompt | |
295 | ||
296 | set testcnt 0 | |
297 | ||
298 | send_gdb "list list0.c:33\n" | |
299 | gdb_expect { | |
085dd6e6 | 300 | -re "28\[ \t\]+foo \\(.*\\);.*37\[ \t\]+\}\r\n$gdb_prompt $" { incr testcnt } |
c906108c SS |
301 | -re ".*$gdb_prompt $" { fail "list list0.c:33" ; gdb_suppress_tests } |
302 | timeout { fail "list list0.c:33 (timeout)" ; gdb_suppress_tests } | |
303 | } | |
304 | ||
305 | send_gdb "list -\n" | |
306 | gdb_expect { | |
307 | -re "18\[ \t\]+foo \[(\]+.*\[)\]+;.*27\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt } | |
308 | -re ".*$gdb_prompt $" { fail "list 18-27" ; gdb_suppress_tests } | |
309 | timeout { fail "list 18-27 (timeout)" ; gdb_suppress_tests } | |
310 | } | |
311 | ||
312 | send_gdb "list -\n" | |
313 | gdb_expect { | |
924437bc | 314 | -re "8\[ \t\]+foo \[(\]+.*\[)\]+;.*17\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { incr testcnt } |
c906108c SS |
315 | -re ".*$gdb_prompt $" { fail "list 8-17" ; gdb_suppress_tests } |
316 | timeout { fail "list 8-17 (timeout)" ; gdb_suppress_tests } | |
317 | } | |
318 | ||
319 | send_gdb "list -\n" | |
320 | gdb_expect { | |
924437bc | 321 | -re "1\[ \t\]+#include .*7\[ \t\]+x = 0;\r\n$gdb_prompt $" { incr testcnt } |
c906108c SS |
322 | -re ".*$gdb_prompt $" { fail "list 1-7" ; gdb_suppress_tests } |
323 | timeout { fail "list 1-7 (timeout)" ; gdb_suppress_tests } | |
324 | } | |
325 | ||
326 | pass "$testcnt successive \"list -\" commands to page backwards" | |
4ec70201 | 327 | gdb_stop_suppressing_tests |
c906108c SS |
328 | } |
329 | ||
330 | # | |
331 | # Test "list first,last" | |
332 | # | |
333 | ||
334 | proc test_list_range {} { | |
335 | global gdb_prompt | |
fc0da894 PA |
336 | global last_line_re |
337 | global last_line | |
c906108c | 338 | |
085dd6e6 | 339 | 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 | 340 | |
085dd6e6 | 341 | gdb_test "list 2,5" "2\[ \t\]+\r\n3\[ \t\]+int main \[)(\]+.*5\[ \t\]+int x;" "list range; line1,line2" |
c906108c SS |
342 | |
343 | # gdb_test "list -1,6" "Line number 0 out of range; .*list0.c has 39 lines." "list range; lower bound negative" | |
344 | ||
345 | # gdb_test "list -100,-40" "Line number -60 out of range; .*list0.c has 39 lines." "list range; both bounds negative" | |
346 | ||
fc0da894 PA |
347 | set past_end [expr ${last_line} + 10] |
348 | set much_past_end [expr ${past_end} + 10] | |
349 | ||
350 | gdb_test "list 30,${past_end}" "30\[ \t\]+foo \(.*\);.*${last_line_re}" "list range; upper bound past EOF" | |
c906108c | 351 | |
fc0da894 | 352 | 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 |
353 | |
354 | gdb_test "list list0.c:2,list1.c:17" "Specified start and end are in different files." "list range, must be same files" | |
355 | } | |
356 | ||
357 | # | |
358 | # Test "list filename:function" | |
359 | # | |
360 | ||
361 | proc test_list_filename_and_function {} { | |
362 | global gdb_prompt | |
fc0da894 | 363 | global last_line_re |
c906108c SS |
364 | |
365 | set testcnt 0 | |
366 | ||
367 | # gcc appears to generate incorrect debugging information for code | |
368 | # in include files, which breaks this test. | |
369 | # SunPRO cc is the second case below, it's also correct. | |
c906108c SS |
370 | send_gdb "list list0.c:main\n" |
371 | gdb_expect { | |
924437bc | 372 | -re "1\[ \t\]+#include .*10\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { |
c906108c SS |
373 | incr testcnt |
374 | } | |
375 | -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { | |
376 | pass "list function in source file 1" | |
377 | } | |
378 | -re ".*$gdb_prompt $" { fail "list list0.c:main" } | |
379 | timeout { fail "list list0.c:main (timeout)" } | |
380 | } | |
381 | ||
c906108c SS |
382 | # Not sure what the point of having this function be unused is. |
383 | # AIX is legitimately removing it. | |
384 | setup_xfail "rs6000-*-aix*" | |
385 | send_gdb "list list0.c:unused\n" | |
386 | gdb_expect { | |
fc0da894 | 387 | -re "40\[ \t\]+unused.*${last_line_re}\r\n$gdb_prompt $" { |
c906108c SS |
388 | incr testcnt |
389 | } | |
390 | -re "37.*42\[ \t\]+\}\r\n$gdb_prompt $" { | |
391 | incr testcnt | |
392 | } | |
393 | -re ".*$gdb_prompt $" { fail "list list0.c:unused" } | |
394 | timeout { fail "list list0.c:unused (timeout)" } | |
395 | } | |
396 | clear_xfail "rs6000-*-aix*" | |
397 | ||
398 | # gcc appears to generate incorrect debugging information for code | |
399 | # in include files, which breaks this test. | |
400 | # Ultrix gdb is the second case, one line different but still correct. | |
401 | # SunPRO cc is the third case. | |
402 | setup_xfail "rs6000-*-*" 1804 | |
c906108c SS |
403 | setup_xfail_format "COFF" |
404 | send_gdb "list list0.h:foo\n" | |
405 | gdb_expect { | |
406 | -re "2\[ \t\]+including file. This.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { | |
407 | incr testcnt | |
408 | } | |
409 | -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { | |
410 | incr testcnt | |
411 | } | |
412 | -re "3\[ \t\]+.*12\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$gdb_prompt $" { | |
413 | incr testcnt | |
414 | } | |
415 | -re "No source file named list0.h.\r\n$gdb_prompt $" { | |
416 | fail "list list0.h:foo" | |
417 | } | |
418 | -re ".*$gdb_prompt $" { fail "list list0.h:foo" } | |
419 | timeout { fail "list list0.h:foo (timeout)" } | |
420 | } | |
421 | ||
422 | # Ultrix gdb is the second case. | |
c906108c SS |
423 | send_gdb "list list1.c:bar\n" |
424 | gdb_expect { | |
085dd6e6 | 425 | -re "4\[ \t\]+void.*13\[ \t\]+\}\r\n$gdb_prompt $" { |
c906108c SS |
426 | incr testcnt |
427 | } | |
085dd6e6 | 428 | -re "4\[ \t\]+void.*12\[ \t\]*long_line ..;\r\n$gdb_prompt $" { |
c906108c SS |
429 | incr testcnt |
430 | } | |
085dd6e6 | 431 | -re "4\[ \t\]+void.*11\[ \t\]*\r\n$gdb_prompt $" { |
c906108c SS |
432 | incr testcnt |
433 | } | |
434 | -re ".*$gdb_prompt $" { fail "list list1.c:bar" } | |
435 | timeout { fail "list list1.c:bar (timeout)" } | |
436 | } | |
437 | ||
c906108c SS |
438 | # Not sure what the point of having this function be unused is. |
439 | # AIX is legitimately removing it. | |
440 | setup_xfail "rs6000-*-aix*" | |
441 | send_gdb "list list1.c:unused\n" | |
442 | gdb_expect { | |
085dd6e6 | 443 | -re "12\[ \t\]+long_line \[(\]\[)\];.*13\[ \t\]+\}\r\n.*$gdb_prompt $" { |
c906108c SS |
444 | incr testcnt |
445 | } | |
085dd6e6 | 446 | -re "14.*19\[ \t\]+\}\r\n.*$gdb_prompt $" { |
c906108c SS |
447 | incr testcnt |
448 | } | |
449 | -re ".*$gdb_prompt $" { fail "list list1.c:unused" } | |
450 | timeout { fail "list list1.c:unused (timeout)" } | |
451 | } | |
452 | clear_xfail "rs6000-*-aix*" | |
453 | ||
454 | pass "list filename:function ($testcnt tests)" | |
455 | ||
791dfb64 DJ |
456 | # Test with quoting. |
457 | gdb_test "list 'list0.c:main'" "int main.*" | |
458 | ||
c906108c SS |
459 | # Test some invalid specs |
460 | # The following test takes the FIXME result on most systems using | |
461 | # DWARF. It fails to notice that main() is not in the file requested. | |
462 | ||
463 | setup_xfail "*-*-*" | |
464 | ||
465 | # Does this actually work ANYWHERE? I believe not, as this is an `aspect' of | |
466 | # lookup_symbol(), where, when it is given a specific symtab which does not | |
467 | # contain the requested symbol, it will subsequently search all of the symtabs | |
468 | # for the requested symbol. | |
469 | ||
470 | gdb_test "list list0.c:foo" "Function \"foo\" not defined in .*list0.c" "list filename:function; wrong filename rejected" | |
471 | ||
085dd6e6 | 472 | gdb_test "list foobar.c:main" "No source file named foobar.c.|Location not found" "list filename:function; nonexistant file" |
c906108c | 473 | |
f8eba3c6 | 474 | gdb_test "list list0.h:foobar" "Function \"foobar\" not defined in \"list0.h\"." "list filename:function; nonexistant function" |
c906108c SS |
475 | |
476 | } | |
477 | ||
478 | proc test_forward_search {} { | |
479 | global timeout | |
480 | ||
27d3a1a2 | 481 | gdb_test_no_output "set listsize 4" |
c906108c SS |
482 | # On SunOS4, this gives us lines 19-22. On AIX, it gives us |
483 | # lines 20-23. This depends on whether the line number of a function | |
484 | # is considered to be the openbrace or the first statement--either one | |
485 | # is acceptable. | |
085dd6e6 | 486 | gdb_test "list long_line" "24\[ \t\]+long_line .*" |
c906108c SS |
487 | |
488 | gdb_test "search 4321" " not found" | |
489 | ||
085dd6e6 | 490 | gdb_test "search 6789" "28\[ \t\]+oof .6789.;" |
c906108c SS |
491 | |
492 | # Test that GDB won't crash if the line being searched is extremely long. | |
493 | ||
494 | set oldtimeout $timeout | |
495 | set timeout [expr "$timeout + 300"] | |
496 | verbose "Timeout is now $timeout seconds" 2 | |
497 | gdb_test "search 1234" ".*1234.*" "search extremely long line (> 5000 chars)" | |
498 | set timeout $oldtimeout | |
499 | verbose "Timeout is now $timeout seconds" 2 | |
500 | } | |
501 | ||
777f26c2 JK |
502 | proc test_only_end {} { |
503 | gdb_test_no_output "set listsize 2" | |
504 | gdb_test "list 1" "list 1\r\n1\[ \t\]\[^\r\n\]*\r\n2\[ \t\]\[^\r\n\]*" | |
505 | gdb_test "list ,5" "list ,5\r\n4\[ \t\]\[^\r\n\]*\r\n5\[ \t\]\[^\r\n\]*" | |
506 | } | |
507 | ||
c906108c SS |
508 | # Start with a fresh gdb. |
509 | ||
510 | gdb_exit | |
511 | gdb_start | |
512 | gdb_reinitialize_dir $srcdir/$subdir | |
8e09ad05 | 513 | gdb_file_cmd ${binfile} |
c906108c | 514 | |
27d3a1a2 | 515 | gdb_test_no_output "set width 0" |
c906108c SS |
516 | |
517 | test_listsize | |
518 | get_debug_format | |
519 | if [ set_listsize 10 ] then { | |
520 | test_list_include_file | |
521 | test_list_filename_and_number | |
522 | test_list_function | |
523 | test_list_forward | |
524 | test_list_backwards | |
a0b3c4fd | 525 | test_repeat_list_command |
c906108c SS |
526 | test_list_range |
527 | test_list_filename_and_function | |
528 | test_forward_search | |
777f26c2 | 529 | test_only_end |
c906108c | 530 | } |
085dd6e6 | 531 | |
5166082f PA |
532 | # Follows tests that require execution. |
533 | ||
534 | # Build source listing pattern based on a line range spec string. The | |
535 | # range can be specificed as "START-END" indicating all lines in range | |
536 | # (inclusive); or just "LINE", indicating just that line. | |
537 | ||
538 | proc build_pattern { range_spec } { | |
539 | global line_re | |
540 | ||
541 | set range_list [split $range_spec -] | |
542 | set range_list_len [llength $range_list] | |
543 | ||
544 | set range_start [lindex $range_list 0] | |
545 | if { $range_list_len > 2 || $range_list_len < 1} { | |
546 | error "invalid range spec string: $range_spec" | |
547 | } elseif { $range_list_len == 2 } { | |
548 | set range_end [lindex $range_list 1] | |
549 | } else { | |
550 | set range_end $range_start | |
551 | } | |
552 | ||
553 | for {set i $range_start} {$i <= $range_end} {incr i} { | |
554 | append pattern "\r\n$i\[ \t\]\[^\r\n\]*" | |
555 | } | |
556 | ||
557 | verbose -log "pattern $pattern" | |
558 | return $pattern | |
559 | } | |
560 | ||
561 | # Test "list" command invocations right after stopping for an event. | |
562 | # COMMAND is the actual list command, including arguments. LISTSIZE1 | |
563 | # and LISTSIZE2 are the listsizes set just before and after running | |
564 | # the program to the stop point. COMMAND is issued twice. The first | |
565 | # time, the lines specificed by LINERANGE1 are expected; the second | |
566 | # time, the lines specified by LINERANGE2 are expected. | |
567 | ||
568 | proc test_list {command listsize1 listsize2 linerange1 linerange2} { | |
569 | with_test_prefix "$command after stop: $listsize1, $listsize2" { | |
570 | global binfile | |
571 | ||
572 | clean_restart $binfile | |
573 | if ![runto_main] then { | |
574 | fail "Can't run to main" | |
575 | return | |
576 | } | |
577 | ||
578 | # Test changing the listsize both before nexting, and after | |
579 | # stopping, but before listing. Only the second listsize | |
580 | # change should affect which lines are listed. | |
581 | gdb_test_no_output "set listsize $listsize1" | |
582 | gdb_test "next" "foo \\(.*" | |
583 | gdb_test_no_output "set listsize $listsize2" | |
584 | ||
585 | set pattern1 [build_pattern $linerange1] | |
586 | set pattern2 [build_pattern $linerange2] | |
587 | gdb_test "$command" "${pattern1}" "$command #1" | |
588 | gdb_test "$command" "${pattern2}" "$command #2" | |
589 | } | |
590 | } | |
591 | ||
592 | ||
593 | # The first "list" should center the listing around line 8, the stop | |
594 | # line. | |
595 | test_list "list" 1 10 "3-12" "13-22" | |
596 | ||
597 | # Likewise. | |
598 | test_list "list" 10 10 "3-12" "13-22" | |
599 | ||
600 | # Likewise, but show only one line. IOW, the first list should show | |
601 | # line 8. Note how the listsize is 10 at the time of the stop, but | |
602 | # before any listing had been requested. That should not affect the | |
603 | # line range that is first listed. | |
604 | test_list "list" 10 1 "8" "9" | |
605 | ||
606 | # Likewise, but show two lines. | |
607 | test_list "list" 10 2 "7-8" "9-10" | |
608 | ||
609 | # Three lines. | |
610 | test_list "list" 10 3 "7-9" "10-12" | |
611 | ||
612 | # Now test backwards. Just like "list", the first "list -" should | |
613 | # center the listing around the stop line. | |
614 | test_list "list -" 10 10 "3-12" "2" | |
615 | ||
616 | # Likewise, but test showing 3 lines at a time. | |
617 | test_list "list -" 10 3 "7-9" "4-6" | |
618 | ||
619 | # 2 lines at a time. | |
620 | test_list "list -" 10 2 "7-8" "5-6" | |
621 | ||
622 | # Test listing one line only. This case is a little special and | |
623 | # starts showing the previous line immediately instead of repeating | |
624 | # the current line. | |
625 | test_list "list -" 10 1 "7" "6" | |
626 | ||
085dd6e6 | 627 | remote_exec build "rm -f list0.h" |