1 # Tests for reference types with short type variables in GDB.
2 # Copyright (C) 1998, 1999 Free Software Foundation, Inc.
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.
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.
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.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # written by Elena Zannoni (ezannoni@cygnus.com)
28 # test running programs
33 set testfile "ref-types"
34 set srcfile ${testfile}.cc
35 set binfile ${objdir}/${subdir}/${testfile}
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
38 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
43 gdb_reinitialize_dir $srcdir/$subdir
48 # set it up at a breakpoint so we can play with the variable values
50 if ![runto_main] then {
51 perror "couldn't run to breakpoint"
55 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
59 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
62 -re ".*$gdb_prompt $" {}
63 timeout { fail "up from marker1" }
66 -re "$gdb_prompt $" { fail "continue to marker1" }
67 timeout { fail "(timeout) continue to marker1" }
71 proc gdb_start_again {} {
79 gdb_reinitialize_dir $srcdir/$subdir
85 # set it up at a breakpoint so we can play with the variable values
87 if ![runto_main] then {
88 perror "couldn't run to breakpoint"
92 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
96 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
99 -re ".*$gdb_prompt $" {}
100 timeout { fail "up from marker1" }
103 -re "$gdb_prompt $" { fail "continue to marker1" }
104 timeout { fail "(timeout) continue to marker1" }
114 -re ".\[0-9\]* = -1.*$gdb_prompt $" {
115 pass "print value of s"
117 -re ".*$gdb_prompt $" { fail "print value of s" }
118 timeout { fail "(timeout) print value of s" }
124 -re "type = short.*$gdb_prompt $" { pass "ptype s" }
125 -re ".*$gdb_prompt $" { fail "ptype s" }
126 timeout { fail "(timeout) ptype s" }
130 send_gdb "print *ps\n"
132 -re ".\[0-9\]* = -1.*$gdb_prompt $" {
133 pass "print value of ps"
135 -re ".*$gdb_prompt $" { fail "print value of ps" }
136 timeout { fail "(timeout) print value of ps" }
140 send_gdb "ptype ps\n"
142 -re "type = short \*.*$gdb_prompt $" { pass "ptype ps" }
143 -re ".*$gdb_prompt $" { fail "ptype ps" }
144 timeout { fail "(timeout) ptype ps" }
147 send_gdb "print as\[0\]\n"
149 -re ".\[0-9\]* = 0.*$gdb_prompt $" {
150 pass "print value of as\[0\]"
152 -re ".*$gdb_prompt $" { fail "print value of as\[0\]" }
153 timeout { fail "(timeout) print value of as\[0\]" }
157 send_gdb "ptype as\n"
159 -re "type = short \\\[4\\\].*$gdb_prompt $" { pass "ptype as" }
160 -re "type = short int \\\[4\\\].*$gdb_prompt $" { pass "ptype as" }
161 -re ".*$gdb_prompt $" { fail "ptype as" }
162 timeout { fail "(timeout) ptype as" }
165 send_gdb "print as\[1\]\n"
167 -re ".\[0-9\]* = 1.*$gdb_prompt $" {
168 pass "print value of as\[1\]"
170 -re ".*$gdb_prompt $" { fail "print value of as\[1\]" }
171 timeout { fail "(timeout) print value of as\[1\]" }
174 send_gdb "print as\[2\]\n"
176 -re ".\[0-9\]* = 2.*$gdb_prompt $" {
177 pass "print value of as\[2\]"
179 -re ".*$gdb_prompt $" { fail "print value of as\[2\]" }
180 timeout { fail "(timeout) print value of as\[2\]" }
183 send_gdb "print as\[3\]\n"
185 -re ".\[0-9\]* = 3.*$gdb_prompt $" {
186 pass "print value of as\[3\]"
188 -re ".*$gdb_prompt $" { fail "print value of as\[3\]" }
189 timeout { fail "(timeout) print value of as\[3\]" }
192 send_gdb "print rs\n"
194 -re ".\[0-9\]* = \\(short &\\) @$hex: -1.*$gdb_prompt $" {
195 pass "print value of rs"
197 -re ".\[0-9\]* = \\(short int &\\) @$hex: -1.*$gdb_prompt $" {
198 pass "print value of rs"
200 -re ".*$gdb_prompt $" { fail "print value of rs" }
201 timeout { fail "(timeout) print value of rs" }
202 eof { fail "print rs ($GDB dumped core) (FIXME)" ; gdb_start_again ; }
206 send_gdb "ptype rs\n"
208 -re "type = short &.*$gdb_prompt $" { pass "ptype rs" }
209 -re "type = short int &.*$gdb_prompt $" { pass "ptype rs" }
210 -re ".*$gdb_prompt $" { fail "ptype rs" }
211 timeout { fail "(timeout) ptype rs" }
215 send_gdb "print *rps\n"
217 -re ".\[0-9\]* = -1.*$gdb_prompt $" {
218 pass "print value of *rps"
220 -re ".*$gdb_prompt $" { fail "print value of *rps" }
221 timeout { fail "(timeout) print value of *rps" }
225 send_gdb "ptype rps\n"
227 -re "type = short \\*&.*$gdb_prompt $" { pass "ptype rps" }
228 -re "type = short int \\*&.*$gdb_prompt $" { pass "ptype rps" }
229 -re ".*$gdb_prompt $" { fail "ptype rps" }
230 timeout { fail "(timeout) ptype rps" }
235 send_gdb "print ras\[0\]\n"
237 -re ".\[0-9\]* = 0.*$gdb_prompt $" {
238 pass "print value of ras\[0\]"
240 -re ".*$gdb_prompt $" { fail "print value of ras\[0\]" }
241 timeout { fail "(timeout) print value of ras\[0\]" }
245 send_gdb "ptype ras\n"
247 -re "type = short \\\(&\\\)\\\[4\\\].*$gdb_prompt $" { pass "ptype ras" }
248 -re "type = short int \\\(&\\\)\\\[4\\\].*$gdb_prompt $" { pass "ptype ras" }
249 -re ".*$gdb_prompt $" { fail "ptype ras" }
250 timeout { fail "(timeout) ptype ras" }
253 send_gdb "print ras\[1\]\n"
255 -re ".\[0-9\]* = 1.*$gdb_prompt $" {
256 pass "print value of ras\[1\]"
258 -re ".*$gdb_prompt $" { fail "print value of ras\[1\]" }
259 timeout { fail "(timeout) print value of ras\[1\]" }
262 send_gdb "print ras\[2\]\n"
264 -re ".\[0-9\]* = 2.*$gdb_prompt $" {
265 pass "print value of ras\[2\]"
267 -re ".*$gdb_prompt $" { fail "print value of ras\[2\]" }
268 timeout { fail "(timeout) print value of ras\[2\]" }
271 send_gdb "print ras\[3\]\n"
273 -re ".\[0-9\]* = 3.*$gdb_prompt $" {
274 pass "print value of ras\[3\]"
276 -re ".*$gdb_prompt $" { fail "print value of ras\[3\]" }
277 timeout { fail "(timeout) print value of ras\[3\]" }
281 send_gdb "break f\n" ; gdb_expect -re ".*$gdb_prompt $"
285 -re "Break.* f \\(\\) at .*:$decimal.*$gdb_prompt $" {
288 -re ".*$gdb_prompt $" {}
289 timeout { fail "up from f" }
292 -re "$gdb_prompt $" { fail "continue to f" }
293 timeout { fail "(timeout) continue to f" }
299 -re ".\[0-9\]* = 65 \'A\'.*$gdb_prompt $" {
300 pass "print value of C"
302 -re ".*$gdb_prompt $" { fail "print value of C" }
303 timeout { fail "(timeout) print value of C" }
309 -re "type = char.*$gdb_prompt $" { pass "ptype C" }
310 -re ".*$gdb_prompt $" { fail "ptype C" }
311 timeout { fail "(timeout) ptype C" }
315 send_gdb "print UC\n"
317 -re ".\[0-9\]* = 21 '\.025'\.*$gdb_prompt $" {
318 pass "print value of UC"
320 -re ".*$gdb_prompt $" { fail "print value of UC" }
321 timeout { fail "(timeout) print value of UC" }
325 send_gdb "ptype UC\n"
327 -re "type = unsigned char.*$gdb_prompt $" { pass "ptype UC" }
328 -re ".*$gdb_prompt $" { fail "ptype UC" }
329 timeout { fail "(timeout) ptype UC" }
335 -re ".\[0-9\]* = -14.*$gdb_prompt $" {
336 pass "print value of S"
338 -re ".*$gdb_prompt $" { fail "print value of S" }
339 timeout { fail "(timeout) print value of S" }
345 -re "type = short.*$gdb_prompt $" { pass "ptype S" }
346 -re ".*$gdb_prompt $" { fail "ptype S" }
347 timeout { fail "(timeout) ptype S" }
351 send_gdb "print US\n"
353 -re ".\[0-9\]* = 7.*$gdb_prompt $" {
354 pass "print value of US"
356 -re ".*$gdb_prompt $" { fail "print value of US" }
357 timeout { fail "(timeout) print value of US" }
361 send_gdb "ptype US\n"
363 -re "type = unsigned short.*$gdb_prompt $" { pass "ptype US" }
364 -re "type = short unsigned.*$gdb_prompt $" { pass "ptype US" }
365 -re ".*$gdb_prompt $" { fail "ptype US" }
366 timeout { fail "(timeout) ptype US" }
372 -re ".\[0-9\]* = 102.*$gdb_prompt $" {
373 pass "print value of I"
375 -re ".*$gdb_prompt $" { fail "print value of I" }
376 timeout { fail "(timeout) print value of I" }
382 -re "type = int.*$gdb_prompt $" { pass "ptype I" }
383 -re ".*$gdb_prompt $" { fail "ptype I" }
384 timeout { fail "(timeout) ptype I" }
388 send_gdb "print UI\n"
390 -re ".\[0-9\]* = 1002.*$gdb_prompt $" {
391 pass "print value of UI"
393 -re ".*$gdb_prompt $" { fail "print value of UI" }
394 timeout { fail "(timeout) print value of UI" }
398 send_gdb "ptype UI\n"
400 -re "type = unsigned int.*$gdb_prompt $" { pass "ptype UI" }
401 -re ".*$gdb_prompt $" { fail "ptype UI" }
402 timeout { fail "(timeout) ptype UI" }
408 -re ".\[0-9\]* = -234.*$gdb_prompt $" {
409 pass "print value of L"
411 -re ".*$gdb_prompt $" { fail "print value of L" }
412 timeout { fail "(timeout) print value of L" }
418 -re "type = long.*$gdb_prompt $" { pass "ptype L" }
419 -re ".*$gdb_prompt $" { fail "ptype L" }
420 timeout { fail "(timeout) ptype L" }
424 send_gdb "print UL\n"
426 -re ".\[0-9\]* = 234.*$gdb_prompt $" {
427 pass "print value of UL"
429 -re ".*$gdb_prompt $" { fail "print value of UL" }
430 timeout { fail "(timeout) print value of UL" }
434 send_gdb "ptype UL\n"
436 -re "type = unsigned long.*$gdb_prompt $" { pass "ptype UL" }
437 -re "type = long unsigned.*$gdb_prompt $" { pass "ptype UL" }
438 -re ".*$gdb_prompt $" { fail "ptype UL" }
439 timeout { fail "(timeout) ptype UL" }
445 -re ".\[0-9\]* = 1.2\[0-9\]*e\\+10.*$gdb_prompt $" {
446 pass "print value of F"
448 -re ".*$gdb_prompt $" { fail "print value of F" }
449 timeout { fail "(timeout) print value of F" }
456 -re "type = float.*$gdb_prompt $" { pass "ptype F" }
457 -re ".*$gdb_prompt $" { fail "ptype F" }
458 timeout { fail "(timeout) ptype F" }
464 -re ".\[0-9\]* = -1.375e-123.*$gdb_prompt $" {
465 pass "print value of D"
467 -re ".*$gdb_prompt $" { fail "print value of D" }
468 timeout { fail "(timeout) print value of D" }
474 -re "type = double.*$gdb_prompt $" { pass "ptype D" }
475 -re ".*$gdb_prompt $" { fail "ptype D" }
476 timeout { fail "(timeout) ptype D" }
482 # test reference types
488 send_gdb "ptype rC\n"
490 -re "type = char &.*$gdb_prompt $" { pass "ptype rC" }
491 -re ".*$gdb_prompt $" { fail "ptype rC" }
492 timeout { fail "(timeout) ptype rC" }
498 send_gdb "ptype rUC\n"
500 -re "type = unsigned char &.*$gdb_prompt $" { pass "ptype rUC" }
501 -re ".*$gdb_prompt $" { fail "ptype rUC" }
502 timeout { fail "(timeout) ptype rUC" }
507 send_gdb "ptype rS\n"
509 -re "type = short &.*$gdb_prompt $" { pass "ptype rS" }
510 -re "type = short int &.*$gdb_prompt $" { pass "ptype rS" }
511 -re ".*$gdb_prompt $" { fail "ptype rS" }
512 timeout { fail "(timeout) ptype rS" }
517 send_gdb "ptype rUS\n"
519 -re "type = unsigned short &.*$gdb_prompt $" { pass "ptype rUS" }
520 -re "type = short unsigned int &.*$gdb_prompt $" { pass "ptype rUS" }
521 -re ".*$gdb_prompt $" { fail "ptype rUS" }
522 timeout { fail "(timeout) ptype rUS" }
526 send_gdb "ptype rI\n"
528 -re "type = int &.*$gdb_prompt $" { pass "ptype rI" }
529 -re ".*$gdb_prompt $" { fail "ptype rI" }
530 timeout { fail "(timeout) ptype rI" }
535 send_gdb "ptype rUI\n"
537 -re "type = unsigned int &.*$gdb_prompt $" { pass "ptype rUI" }
538 -re ".*$gdb_prompt $" { fail "ptype rUI" }
539 timeout { fail "(timeout) ptype rUI" }
544 send_gdb "ptype rL\n"
546 -re "type = long &.*$gdb_prompt $" { pass "ptype rL" }
547 -re "type = long int &.*$gdb_prompt $" { pass "ptype rL" }
548 -re ".*$gdb_prompt $" { fail "ptype rL" }
549 timeout { fail "(timeout) ptype rL" }
553 send_gdb "ptype rUL\n"
555 -re "type = unsigned long &.*$gdb_prompt $" { pass "ptype rUL" }
556 -re "type = long unsigned int &.*$gdb_prompt $" { pass "ptype rUL" }
557 -re ".*$gdb_prompt $" { fail "ptype rUL" }
558 timeout { fail "(timeout) ptype rUL" }
562 send_gdb "ptype rF\n"
564 -re "type = float &.*$gdb_prompt $" { pass "ptype rF" }
565 -re ".*$gdb_prompt $" { fail "ptype rF" }
566 timeout { fail "(timeout) ptype rF" }
570 send_gdb "ptype rD\n"
572 -re "type = double &.*$gdb_prompt $" { pass "ptype rD" }
573 -re ".*$gdb_prompt $" { fail "ptype rD" }
574 timeout { fail "(timeout) ptype rD" }
578 send_gdb "print rC\n"
580 -re ".\[0-9\]* = \\(char &\\) @$hex: 65 \'A\'.*$gdb_prompt $" {
581 pass "print value of rC"
583 -re ".*$gdb_prompt $" { fail "print value of rC" }
584 timeout { fail "(timeout) print value of rC" }
588 send_gdb "print rUC\n"
590 -re ".\[0-9\]* = \\(unsigned char &\\) @$hex: 21 \'.025\'.*$gdb_prompt $" {
591 pass "print value of rUC"
593 -re ".*$gdb_prompt $" { fail "print value of rUC" }
594 timeout { fail "(timeout) print value of rUC" }
598 send_gdb "print rS\n"
600 -re ".\[0-9\]* = \\(short &\\) @$hex: -14.*$gdb_prompt $" {
601 pass "print value of rS"
603 -re ".\[0-9\]* = \\(short int &\\) @$hex: -14.*$gdb_prompt $" {
604 pass "print value of rS"
606 -re ".*$gdb_prompt $" { fail "print value of rS" }
607 timeout { fail "(timeout) print value of rS" }
611 send_gdb "print rUS\n"
613 -re ".\[0-9\]* = \\(unsigned short &\\) @$hex: 7.*$gdb_prompt $" {
614 pass "print value of rUS"
616 -re ".\[0-9\]* = \\(short unsigned int &\\) @$hex: 7.*$gdb_prompt $" {
617 pass "print value of rUS"
619 -re ".*$gdb_prompt $" { fail "print value of rUS" }
620 timeout { fail "(timeout) print value of rUS" }
624 send_gdb "print rI\n"
626 -re ".\[0-9\]* = \\(int &\\) @$hex: 102.*$gdb_prompt $" {
627 pass "print value of rI"
629 -re ".*$gdb_prompt $" { fail "print value of rI" }
630 timeout { fail "(timeout) print value of rI" }
634 send_gdb "print rUI\n"
636 -re ".\[0-9\]* = \\(unsigned int &\\) @$hex: 1002.*$gdb_prompt $" {
637 pass "print value of UI"
639 -re ".*$gdb_prompt $" { fail "print value of rUI" }
640 timeout { fail "(timeout) print value of rUI" }
644 send_gdb "print rL\n"
646 -re ".\[0-9\]* = \\(long &\\) @$hex: -234.*$gdb_prompt $" {
647 pass "print value of rL"
649 -re ".\[0-9\]* = \\(long int &\\) @$hex: -234.*$gdb_prompt $" {
650 pass "print value of rL"
652 -re ".*$gdb_prompt $" { fail "print value of rL" }
653 timeout { fail "(timeout) print value of rL" }
658 send_gdb "print rUL\n"
660 -re ".\[0-9\]* = \\(unsigned long &\\) @$hex: 234.*$gdb_prompt $" {
661 pass "print value of rUL"
663 -re ".\[0-9\]* = \\(long unsigned int &\\) @$hex: 234.*$gdb_prompt $" {
664 pass "print value of rUL"
666 -re ".*$gdb_prompt $" { fail "print value of rUL" }
667 timeout { fail "(timeout) print value of rUL" }
671 send_gdb "print rF\n"
673 -re ".\[0-9\]* = \\(float &\\) @$hex: 1.2\[0-9\]*e\\+10.*$gdb_prompt $" {
674 pass "print value of rF"
676 -re ".*$gdb_prompt $" { fail "print value of rF" }
677 timeout { fail "(timeout) print value of rF" }
681 send_gdb "print rD\n"
683 -re ".\[0-9\]* = \\(double &\\) @$hex: -1.375e-123.*$gdb_prompt $" {
684 pass "print value of rD"
686 -re ".*$gdb_prompt $" { fail "print value of rD" }
687 timeout { fail "(timeout) print value of rD" }