ref-types.exp revision 1.1.1.1
1# Tests for reference types with short type variables in GDB. 2# Copyright 1998, 1999, 2000, 2004 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 2 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, write to the Free Software 16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18# written by Elena Zannoni (ezannoni@cygnus.com) 19 20if $tracelevel then { 21 strace $tracelevel 22 } 23 24# 25# test running programs 26# 27set prms_id 0 28set bug_id 0 29 30if { [skip_cplus_tests] } { continue } 31 32set testfile "ref-types" 33set srcfile ${testfile}.cc 34set binfile ${objdir}/${subdir}/${testfile} 35 36if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { 37 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 38} 39 40gdb_exit 41gdb_start 42gdb_reinitialize_dir $srcdir/$subdir 43gdb_load ${binfile} 44 45 46# 47# set it up at a breakpoint so we can play with the variable values 48# 49if ![runto_main] then { 50 perror "couldn't run to breakpoint" 51 continue 52} 53 54if ![runto 'marker1'] then { 55 perror "couldn't run to marker1" 56 continue 57} 58 59gdb_test "up" ".*main.*" "up from marker1 1" 60 61proc gdb_start_again {} { 62 global srcdir 63 global subdir 64 global binfile 65 global gdb_prompt 66 global decimal 67 68 gdb_start 69 gdb_reinitialize_dir $srcdir/$subdir 70 gdb_load ${binfile} 71 72 # 73 # set it up at a breakpoint so we can play with the variable values 74 # 75 if ![runto_main] then { 76 perror "couldn't run to breakpoint" 77 continue 78 } 79 80 if ![runto 'marker1'] then { 81 perror "couldn't run to marker1" 82 continue 83 } 84 85 gdb_test "up" ".*main.*" "up from marker1 2" 86} 87 88 89 90send_gdb "print s\n" 91gdb_expect { 92 -re ".\[0-9\]* = -1.*$gdb_prompt $" { 93 pass "print value of s" 94 } 95 -re ".*$gdb_prompt $" { fail "print value of s" } 96 timeout { fail "(timeout) print value of s" } 97 } 98 99 100send_gdb "ptype s\n" 101gdb_expect { 102 -re "type = short.*$gdb_prompt $" { pass "ptype s" } 103 -re ".*$gdb_prompt $" { fail "ptype s" } 104 timeout { fail "(timeout) ptype s" } 105} 106 107 108send_gdb "print *ps\n" 109gdb_expect { 110 -re ".\[0-9\]* = -1.*$gdb_prompt $" { 111 pass "print value of ps" 112 } 113 -re ".*$gdb_prompt $" { fail "print value of ps" } 114 timeout { fail "(timeout) print value of ps" } 115 } 116 117 118send_gdb "ptype ps\n" 119gdb_expect { 120 -re "type = short \*.*$gdb_prompt $" { pass "ptype ps" } 121 -re ".*$gdb_prompt $" { fail "ptype ps" } 122 timeout { fail "(timeout) ptype ps" } 123} 124 125send_gdb "print as\[0\]\n" 126gdb_expect { 127 -re ".\[0-9\]* = 0.*$gdb_prompt $" { 128 pass "print value of as\[0\]" 129 } 130 -re ".*$gdb_prompt $" { fail "print value of as\[0\]" } 131 timeout { fail "(timeout) print value of as\[0\]" } 132 } 133 134 135send_gdb "ptype as\n" 136gdb_expect { 137 -re "type = short \\\[4\\\].*$gdb_prompt $" { pass "ptype as" } 138 -re "type = short int \\\[4\\\].*$gdb_prompt $" { pass "ptype as" } 139 -re ".*$gdb_prompt $" { fail "ptype as" } 140 timeout { fail "(timeout) ptype as" } 141} 142 143send_gdb "print as\[1\]\n" 144gdb_expect { 145 -re ".\[0-9\]* = 1.*$gdb_prompt $" { 146 pass "print value of as\[1\]" 147 } 148 -re ".*$gdb_prompt $" { fail "print value of as\[1\]" } 149 timeout { fail "(timeout) print value of as\[1\]" } 150 } 151 152send_gdb "print as\[2\]\n" 153gdb_expect { 154 -re ".\[0-9\]* = 2.*$gdb_prompt $" { 155 pass "print value of as\[2\]" 156 } 157 -re ".*$gdb_prompt $" { fail "print value of as\[2\]" } 158 timeout { fail "(timeout) print value of as\[2\]" } 159 } 160 161send_gdb "print as\[3\]\n" 162gdb_expect { 163 -re ".\[0-9\]* = 3.*$gdb_prompt $" { 164 pass "print value of as\[3\]" 165 } 166 -re ".*$gdb_prompt $" { fail "print value of as\[3\]" } 167 timeout { fail "(timeout) print value of as\[3\]" } 168 } 169 170send_gdb "print rs\n" 171gdb_expect { 172 -re ".\[0-9\]* = \\(short &\\) @$hex: -1.*$gdb_prompt $" { 173 pass "print value of rs" 174 } 175 -re ".\[0-9\]* = \\(short int &\\) @$hex: -1.*$gdb_prompt $" { 176 pass "print value of rs" 177 } 178 -re ".*$gdb_prompt $" { fail "print value of rs" } 179 timeout { fail "(timeout) print value of rs" } 180 eof { fail "print rs ($GDB dumped core) (FIXME)" ; gdb_start_again ; } 181 182 } 183 184send_gdb "ptype rs\n" 185gdb_expect { 186 -re "type = short &.*$gdb_prompt $" { pass "ptype rs" } 187 -re "type = short int &.*$gdb_prompt $" { pass "ptype rs" } 188 -re ".*$gdb_prompt $" { fail "ptype rs" } 189 timeout { fail "(timeout) ptype rs" } 190} 191 192 193send_gdb "print *rps\n" 194gdb_expect { 195 -re ".\[0-9\]* = -1.*$gdb_prompt $" { 196 pass "print value of *rps" 197 } 198 -re ".*$gdb_prompt $" { fail "print value of *rps" } 199 timeout { fail "(timeout) print value of *rps" } 200 } 201 202 203send_gdb "ptype rps\n" 204gdb_expect { 205 -re "type = short \\*&.*$gdb_prompt $" { pass "ptype rps" } 206 -re "type = short int \\*&.*$gdb_prompt $" { pass "ptype rps" } 207 -re ".*$gdb_prompt $" { fail "ptype rps" } 208 timeout { fail "(timeout) ptype rps" } 209} 210 211 212 213send_gdb "print ras\[0\]\n" 214gdb_expect { 215 -re ".\[0-9\]* = 0.*$gdb_prompt $" { 216 pass "print value of ras\[0\]" 217 } 218 -re ".*$gdb_prompt $" { fail "print value of ras\[0\]" } 219 timeout { fail "(timeout) print value of ras\[0\]" } 220 } 221 222 223send_gdb "ptype ras\n" 224gdb_expect { 225 -re "type = short \\\(&\\\)\\\[4\\\].*$gdb_prompt $" { pass "ptype ras" } 226 -re "type = short int \\\(&\\\)\\\[4\\\].*$gdb_prompt $" { pass "ptype ras" } 227 -re ".*$gdb_prompt $" { fail "ptype ras" } 228 timeout { fail "(timeout) ptype ras" } 229} 230 231send_gdb "print ras\[1\]\n" 232gdb_expect { 233 -re ".\[0-9\]* = 1.*$gdb_prompt $" { 234 pass "print value of ras\[1\]" 235 } 236 -re ".*$gdb_prompt $" { fail "print value of ras\[1\]" } 237 timeout { fail "(timeout) print value of ras\[1\]" } 238 } 239 240send_gdb "print ras\[2\]\n" 241gdb_expect { 242 -re ".\[0-9\]* = 2.*$gdb_prompt $" { 243 pass "print value of ras\[2\]" 244 } 245 -re ".*$gdb_prompt $" { fail "print value of ras\[2\]" } 246 timeout { fail "(timeout) print value of ras\[2\]" } 247 } 248 249send_gdb "print ras\[3\]\n" 250gdb_expect { 251 -re ".\[0-9\]* = 3.*$gdb_prompt $" { 252 pass "print value of ras\[3\]" 253 } 254 -re ".*$gdb_prompt $" { fail "print value of ras\[3\]" } 255 timeout { fail "(timeout) print value of ras\[3\]" } 256 } 257 258 259if ![runto 'f'] then { 260 perror "couldn't run to f" 261 continue 262} 263 264gdb_test "up" ".main2.*" "up from f" 265 266send_gdb "print C\n" 267gdb_expect { 268 -re ".\[0-9\]* = 65 \'A\'.*$gdb_prompt $" { 269 pass "print value of C" 270 } 271 -re ".*$gdb_prompt $" { fail "print value of C" } 272 timeout { fail "(timeout) print value of C" } 273 } 274 275 276send_gdb "ptype C\n" 277gdb_expect { 278 -re "type = char.*$gdb_prompt $" { pass "ptype C" } 279 -re ".*$gdb_prompt $" { fail "ptype C" } 280 timeout { fail "(timeout) ptype C" } 281} 282 283 284send_gdb "print UC\n" 285gdb_expect { 286 -re ".\[0-9\]* = 21 '\.025'\.*$gdb_prompt $" { 287 pass "print value of UC" 288 } 289 -re ".*$gdb_prompt $" { fail "print value of UC" } 290 timeout { fail "(timeout) print value of UC" } 291 } 292 293 294send_gdb "ptype UC\n" 295gdb_expect { 296 -re "type = unsigned char.*$gdb_prompt $" { pass "ptype UC" } 297 -re ".*$gdb_prompt $" { fail "ptype UC" } 298 timeout { fail "(timeout) ptype UC" } 299} 300 301 302send_gdb "print S\n" 303gdb_expect { 304 -re ".\[0-9\]* = -14.*$gdb_prompt $" { 305 pass "print value of S" 306 } 307 -re ".*$gdb_prompt $" { fail "print value of S" } 308 timeout { fail "(timeout) print value of S" } 309 } 310 311 312send_gdb "ptype S\n" 313gdb_expect { 314 -re "type = short.*$gdb_prompt $" { pass "ptype S" } 315 -re ".*$gdb_prompt $" { fail "ptype S" } 316 timeout { fail "(timeout) ptype S" } 317} 318 319 320send_gdb "print US\n" 321gdb_expect { 322 -re ".\[0-9\]* = 7.*$gdb_prompt $" { 323 pass "print value of US" 324 } 325 -re ".*$gdb_prompt $" { fail "print value of US" } 326 timeout { fail "(timeout) print value of US" } 327 } 328 329 330send_gdb "ptype US\n" 331gdb_expect { 332 -re "type = unsigned short.*$gdb_prompt $" { pass "ptype US" } 333 -re "type = short unsigned.*$gdb_prompt $" { pass "ptype US" } 334 -re ".*$gdb_prompt $" { fail "ptype US" } 335 timeout { fail "(timeout) ptype US" } 336} 337 338 339send_gdb "print I\n" 340gdb_expect { 341 -re ".\[0-9\]* = 102.*$gdb_prompt $" { 342 pass "print value of I" 343 } 344 -re ".*$gdb_prompt $" { fail "print value of I" } 345 timeout { fail "(timeout) print value of I" } 346 } 347 348 349send_gdb "ptype I\n" 350gdb_expect { 351 -re "type = int.*$gdb_prompt $" { pass "ptype I" } 352 -re ".*$gdb_prompt $" { fail "ptype I" } 353 timeout { fail "(timeout) ptype I" } 354} 355 356 357send_gdb "print UI\n" 358gdb_expect { 359 -re ".\[0-9\]* = 1002.*$gdb_prompt $" { 360 pass "print value of UI" 361 } 362 -re ".*$gdb_prompt $" { fail "print value of UI" } 363 timeout { fail "(timeout) print value of UI" } 364 } 365 366 367send_gdb "ptype UI\n" 368gdb_expect { 369 -re "type = unsigned int.*$gdb_prompt $" { pass "ptype UI" } 370 -re ".*$gdb_prompt $" { fail "ptype UI" } 371 timeout { fail "(timeout) ptype UI" } 372} 373 374 375send_gdb "print L\n" 376gdb_expect { 377 -re ".\[0-9\]* = -234.*$gdb_prompt $" { 378 pass "print value of L" 379 } 380 -re ".*$gdb_prompt $" { fail "print value of L" } 381 timeout { fail "(timeout) print value of L" } 382 } 383 384 385send_gdb "ptype L\n" 386gdb_expect { 387 -re "type = long.*$gdb_prompt $" { pass "ptype L" } 388 -re ".*$gdb_prompt $" { fail "ptype L" } 389 timeout { fail "(timeout) ptype L" } 390} 391 392 393send_gdb "print UL\n" 394gdb_expect { 395 -re ".\[0-9\]* = 234.*$gdb_prompt $" { 396 pass "print value of UL" 397 } 398 -re ".*$gdb_prompt $" { fail "print value of UL" } 399 timeout { fail "(timeout) print value of UL" } 400 } 401 402 403send_gdb "ptype UL\n" 404gdb_expect { 405 -re "type = unsigned long.*$gdb_prompt $" { pass "ptype UL" } 406 -re "type = long unsigned.*$gdb_prompt $" { pass "ptype UL" } 407 -re ".*$gdb_prompt $" { fail "ptype UL" } 408 timeout { fail "(timeout) ptype UL" } 409} 410 411 412send_gdb "print F\n" 413gdb_expect { 414 -re ".\[0-9\]* = 1.2\[0-9\]*e\\+10.*$gdb_prompt $" { 415 pass "print value of F" 416 } 417 -re ".*$gdb_prompt $" { fail "print value of F" } 418 timeout { fail "(timeout) print value of F" } 419 } 420 421 422 423send_gdb "ptype F\n" 424gdb_expect { 425 -re "type = float.*$gdb_prompt $" { pass "ptype F" } 426 -re ".*$gdb_prompt $" { fail "ptype F" } 427 timeout { fail "(timeout) ptype F" } 428} 429 430 431send_gdb "print D\n" 432gdb_expect { 433 -re ".\[0-9\]* = -1.375e-123.*$gdb_prompt $" { 434 pass "print value of D" 435 } 436 -re ".*$gdb_prompt $" { fail "print value of D" } 437 timeout { fail "(timeout) print value of D" } 438 } 439 440 441send_gdb "ptype D\n" 442gdb_expect { 443 -re "type = double.*$gdb_prompt $" { pass "ptype D" } 444 -re ".*$gdb_prompt $" { fail "ptype D" } 445 timeout { fail "(timeout) ptype D" } 446} 447 448 449 450# 451# test reference types 452# 453 454 455 456 457send_gdb "ptype rC\n" 458gdb_expect { 459 -re "type = char &.*$gdb_prompt $" { pass "ptype rC" } 460 -re ".*$gdb_prompt $" { fail "ptype rC" } 461 timeout { fail "(timeout) ptype rC" } 462} 463 464 465 466 467send_gdb "ptype rUC\n" 468gdb_expect { 469 -re "type = unsigned char &.*$gdb_prompt $" { pass "ptype rUC" } 470 -re ".*$gdb_prompt $" { fail "ptype rUC" } 471 timeout { fail "(timeout) ptype rUC" } 472} 473 474 475 476send_gdb "ptype rS\n" 477gdb_expect { 478 -re "type = short &.*$gdb_prompt $" { pass "ptype rS" } 479 -re "type = short int &.*$gdb_prompt $" { pass "ptype rS" } 480 -re ".*$gdb_prompt $" { fail "ptype rS" } 481 timeout { fail "(timeout) ptype rS" } 482} 483 484 485 486send_gdb "ptype rUS\n" 487gdb_expect { 488 -re "type = unsigned short &.*$gdb_prompt $" { pass "ptype rUS" } 489 -re "type = short unsigned int &.*$gdb_prompt $" { pass "ptype rUS" } 490 -re ".*$gdb_prompt $" { fail "ptype rUS" } 491 timeout { fail "(timeout) ptype rUS" } 492} 493 494 495send_gdb "ptype rI\n" 496gdb_expect { 497 -re "type = int &.*$gdb_prompt $" { pass "ptype rI" } 498 -re ".*$gdb_prompt $" { fail "ptype rI" } 499 timeout { fail "(timeout) ptype rI" } 500} 501 502 503 504send_gdb "ptype rUI\n" 505gdb_expect { 506 -re "type = unsigned int &.*$gdb_prompt $" { pass "ptype rUI" } 507 -re ".*$gdb_prompt $" { fail "ptype rUI" } 508 timeout { fail "(timeout) ptype rUI" } 509} 510 511 512 513send_gdb "ptype rL\n" 514gdb_expect { 515 -re "type = long &.*$gdb_prompt $" { pass "ptype rL" } 516 -re "type = long int &.*$gdb_prompt $" { pass "ptype rL" } 517 -re ".*$gdb_prompt $" { fail "ptype rL" } 518 timeout { fail "(timeout) ptype rL" } 519} 520 521 522send_gdb "ptype rUL\n" 523gdb_expect { 524 -re "type = unsigned long &.*$gdb_prompt $" { pass "ptype rUL" } 525 -re "type = long unsigned int &.*$gdb_prompt $" { pass "ptype rUL" } 526 -re ".*$gdb_prompt $" { fail "ptype rUL" } 527 timeout { fail "(timeout) ptype rUL" } 528} 529 530 531send_gdb "ptype rF\n" 532gdb_expect { 533 -re "type = float &.*$gdb_prompt $" { pass "ptype rF" } 534 -re ".*$gdb_prompt $" { fail "ptype rF" } 535 timeout { fail "(timeout) ptype rF" } 536} 537 538 539send_gdb "ptype rD\n" 540gdb_expect { 541 -re "type = double &.*$gdb_prompt $" { pass "ptype rD" } 542 -re ".*$gdb_prompt $" { fail "ptype rD" } 543 timeout { fail "(timeout) ptype rD" } 544} 545 546 547send_gdb "print rC\n" 548gdb_expect { 549 -re ".\[0-9\]* = \\(char &\\) @$hex: 65 \'A\'.*$gdb_prompt $" { 550 pass "print value of rC" 551 } 552 -re ".*$gdb_prompt $" { fail "print value of rC" } 553 timeout { fail "(timeout) print value of rC" } 554 } 555 556 557send_gdb "print rUC\n" 558gdb_expect { 559 -re ".\[0-9\]* = \\(unsigned char &\\) @$hex: 21 \'.025\'.*$gdb_prompt $" { 560 pass "print value of rUC" 561 } 562 -re ".*$gdb_prompt $" { fail "print value of rUC" } 563 timeout { fail "(timeout) print value of rUC" } 564 } 565 566 567send_gdb "print rS\n" 568gdb_expect { 569 -re ".\[0-9\]* = \\(short &\\) @$hex: -14.*$gdb_prompt $" { 570 pass "print value of rS" 571 } 572 -re ".\[0-9\]* = \\(short int &\\) @$hex: -14.*$gdb_prompt $" { 573 pass "print value of rS" 574 } 575 -re ".*$gdb_prompt $" { fail "print value of rS" } 576 timeout { fail "(timeout) print value of rS" } 577 } 578 579 580send_gdb "print rUS\n" 581gdb_expect { 582 -re ".\[0-9\]* = \\(unsigned short &\\) @$hex: 7.*$gdb_prompt $" { 583 pass "print value of rUS" 584 } 585 -re ".\[0-9\]* = \\(short unsigned int &\\) @$hex: 7.*$gdb_prompt $" { 586 pass "print value of rUS" 587 } 588 -re ".*$gdb_prompt $" { fail "print value of rUS" } 589 timeout { fail "(timeout) print value of rUS" } 590 } 591 592 593send_gdb "print rI\n" 594gdb_expect { 595 -re ".\[0-9\]* = \\(int &\\) @$hex: 102.*$gdb_prompt $" { 596 pass "print value of rI" 597 } 598 -re ".*$gdb_prompt $" { fail "print value of rI" } 599 timeout { fail "(timeout) print value of rI" } 600 } 601 602 603send_gdb "print rUI\n" 604gdb_expect { 605 -re ".\[0-9\]* = \\(unsigned int &\\) @$hex: 1002.*$gdb_prompt $" { 606 pass "print value of UI" 607 } 608 -re ".*$gdb_prompt $" { fail "print value of rUI" } 609 timeout { fail "(timeout) print value of rUI" } 610 } 611 612 613send_gdb "print rL\n" 614gdb_expect { 615 -re ".\[0-9\]* = \\(long &\\) @$hex: -234.*$gdb_prompt $" { 616 pass "print value of rL" 617 } 618 -re ".\[0-9\]* = \\(long int &\\) @$hex: -234.*$gdb_prompt $" { 619 pass "print value of rL" 620 } 621 -re ".*$gdb_prompt $" { fail "print value of rL" } 622 timeout { fail "(timeout) print value of rL" } 623 } 624 625 626 627send_gdb "print rUL\n" 628gdb_expect { 629 -re ".\[0-9\]* = \\(unsigned long &\\) @$hex: 234.*$gdb_prompt $" { 630 pass "print value of rUL" 631 } 632 -re ".\[0-9\]* = \\(long unsigned int &\\) @$hex: 234.*$gdb_prompt $" { 633 pass "print value of rUL" 634 } 635 -re ".*$gdb_prompt $" { fail "print value of rUL" } 636 timeout { fail "(timeout) print value of rUL" } 637 } 638 639 640send_gdb "print rF\n" 641gdb_expect { 642 -re ".\[0-9\]* = \\(float &\\) @$hex: 1.2\[0-9\]*e\\+10.*$gdb_prompt $" { 643 pass "print value of rF" 644 } 645 -re ".*$gdb_prompt $" { fail "print value of rF" } 646 timeout { fail "(timeout) print value of rF" } 647 } 648 649 650send_gdb "print rD\n" 651gdb_expect { 652 -re ".\[0-9\]* = \\(double &\\) @$hex: -1.375e-123.*$gdb_prompt $" { 653 pass "print value of rD" 654 } 655 -re ".*$gdb_prompt $" { fail "print value of rD" } 656 timeout { fail "(timeout) print value of rD" } 657 } 658 659