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