1 # Tests for reference types with short type variables in GDB.
2 # Copyright 1998, 1999, 2000, 2004, 2007, 2008, 2009
3 # Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # written by Elena Zannoni (ezannoni@cygnus.com)
25 # test running programs
30 if { [skip_cplus_tests] } { continue }
32 set testfile "ref-types"
33 set srcfile ${testfile}.cc
34 set binfile ${objdir}/${subdir}/${testfile}
36 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
37 untested ref-types.exp
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 if ![runto 'marker1'] then {
56 perror "couldn't run to marker1"
60 gdb_test "up" ".*main.*" "up from marker1 1"
62 proc gdb_start_again {} {
70 gdb_reinitialize_dir $srcdir/$subdir
74 # set it up at a breakpoint so we can play with the variable values
76 if ![runto_main] then {
77 perror "couldn't run to breakpoint"
81 if ![runto 'marker1'] then {
82 perror "couldn't run to marker1"
86 gdb_test "up" ".*main.*" "up from marker1 2"
93 -re ".\[0-9\]* = -1.*$gdb_prompt $" {
94 pass "print value of s"
96 -re ".*$gdb_prompt $" { fail "print value of s" }
97 timeout { fail "(timeout) print value of s" }
103 -re "type = short.*$gdb_prompt $" { pass "ptype s" }
104 -re ".*$gdb_prompt $" { fail "ptype s" }
105 timeout { fail "(timeout) ptype s" }
109 send_gdb "print *ps\n"
111 -re ".\[0-9\]* = -1.*$gdb_prompt $" {
112 pass "print value of ps"
114 -re ".*$gdb_prompt $" { fail "print value of ps" }
115 timeout { fail "(timeout) print value of ps" }
119 send_gdb "ptype ps\n"
121 -re "type = short \*.*$gdb_prompt $" { pass "ptype ps" }
122 -re ".*$gdb_prompt $" { fail "ptype ps" }
123 timeout { fail "(timeout) ptype ps" }
126 send_gdb "print as\[0\]\n"
128 -re ".\[0-9\]* = 0.*$gdb_prompt $" {
129 pass "print value of as\[0\]"
131 -re ".*$gdb_prompt $" { fail "print value of as\[0\]" }
132 timeout { fail "(timeout) print value of as\[0\]" }
136 send_gdb "ptype as\n"
138 -re "type = short \\\[4\\\].*$gdb_prompt $" { pass "ptype as" }
139 -re "type = short int \\\[4\\\].*$gdb_prompt $" { pass "ptype as" }
140 -re ".*$gdb_prompt $" { fail "ptype as" }
141 timeout { fail "(timeout) ptype as" }
144 send_gdb "print as\[1\]\n"
146 -re ".\[0-9\]* = 1.*$gdb_prompt $" {
147 pass "print value of as\[1\]"
149 -re ".*$gdb_prompt $" { fail "print value of as\[1\]" }
150 timeout { fail "(timeout) print value of as\[1\]" }
153 send_gdb "print as\[2\]\n"
155 -re ".\[0-9\]* = 2.*$gdb_prompt $" {
156 pass "print value of as\[2\]"
158 -re ".*$gdb_prompt $" { fail "print value of as\[2\]" }
159 timeout { fail "(timeout) print value of as\[2\]" }
162 send_gdb "print as\[3\]\n"
164 -re ".\[0-9\]* = 3.*$gdb_prompt $" {
165 pass "print value of as\[3\]"
167 -re ".*$gdb_prompt $" { fail "print value of as\[3\]" }
168 timeout { fail "(timeout) print value of as\[3\]" }
171 send_gdb "print rs\n"
173 -re ".\[0-9\]* = \\(short &\\) @$hex: -1.*$gdb_prompt $" {
174 pass "print value of rs"
176 -re ".\[0-9\]* = \\(short int &\\) @$hex: -1.*$gdb_prompt $" {
177 pass "print value of rs"
179 -re ".*$gdb_prompt $" { fail "print value of rs" }
180 timeout { fail "(timeout) print value of rs" }
181 eof { fail "print rs ($GDB dumped core) (FIXME)" ; gdb_start_again ; }
185 send_gdb "ptype rs\n"
187 -re "type = short &.*$gdb_prompt $" { pass "ptype rs" }
188 -re "type = short int &.*$gdb_prompt $" { pass "ptype rs" }
189 -re ".*$gdb_prompt $" { fail "ptype rs" }
190 timeout { fail "(timeout) ptype rs" }
194 send_gdb "print *rps\n"
196 -re ".\[0-9\]* = -1.*$gdb_prompt $" {
197 pass "print value of *rps"
199 -re ".*$gdb_prompt $" { fail "print value of *rps" }
200 timeout { fail "(timeout) print value of *rps" }
204 send_gdb "ptype rps\n"
206 -re "type = short \\*&.*$gdb_prompt $" { pass "ptype rps" }
207 -re "type = short int \\*&.*$gdb_prompt $" { pass "ptype rps" }
208 -re ".*$gdb_prompt $" { fail "ptype rps" }
209 timeout { fail "(timeout) ptype rps" }
214 send_gdb "print ras\[0\]\n"
216 -re ".\[0-9\]* = 0.*$gdb_prompt $" {
217 pass "print value of ras\[0\]"
219 -re ".*$gdb_prompt $" { fail "print value of ras\[0\]" }
220 timeout { fail "(timeout) print value of ras\[0\]" }
224 send_gdb "ptype ras\n"
226 -re "type = short \\\(&\\\)\\\[4\\\].*$gdb_prompt $" { pass "ptype ras" }
227 -re "type = short int \\\(&\\\)\\\[4\\\].*$gdb_prompt $" { pass "ptype ras" }
228 -re ".*$gdb_prompt $" { fail "ptype ras" }
229 timeout { fail "(timeout) ptype ras" }
232 send_gdb "print ras\[1\]\n"
234 -re ".\[0-9\]* = 1.*$gdb_prompt $" {
235 pass "print value of ras\[1\]"
237 -re ".*$gdb_prompt $" { fail "print value of ras\[1\]" }
238 timeout { fail "(timeout) print value of ras\[1\]" }
241 send_gdb "print ras\[2\]\n"
243 -re ".\[0-9\]* = 2.*$gdb_prompt $" {
244 pass "print value of ras\[2\]"
246 -re ".*$gdb_prompt $" { fail "print value of ras\[2\]" }
247 timeout { fail "(timeout) print value of ras\[2\]" }
250 send_gdb "print ras\[3\]\n"
252 -re ".\[0-9\]* = 3.*$gdb_prompt $" {
253 pass "print value of ras\[3\]"
255 -re ".*$gdb_prompt $" { fail "print value of ras\[3\]" }
256 timeout { fail "(timeout) print value of ras\[3\]" }
260 if ![runto 'f'] then {
261 perror "couldn't run to f"
265 gdb_test "up" ".main2.*" "up from f"
269 -re ".\[0-9\]* = 65 \'A\'.*$gdb_prompt $" {
270 pass "print value of C"
272 -re ".*$gdb_prompt $" { fail "print value of C" }
273 timeout { fail "(timeout) print value of C" }
279 -re "type = char.*$gdb_prompt $" { pass "ptype C" }
280 -re ".*$gdb_prompt $" { fail "ptype C" }
281 timeout { fail "(timeout) ptype C" }
285 send_gdb "print UC\n"
287 -re ".\[0-9\]* = 21 '\.025'\.*$gdb_prompt $" {
288 pass "print value of UC"
290 -re ".*$gdb_prompt $" { fail "print value of UC" }
291 timeout { fail "(timeout) print value of UC" }
295 send_gdb "ptype UC\n"
297 -re "type = unsigned char.*$gdb_prompt $" { pass "ptype UC" }
298 -re ".*$gdb_prompt $" { fail "ptype UC" }
299 timeout { fail "(timeout) ptype UC" }
305 -re ".\[0-9\]* = -14.*$gdb_prompt $" {
306 pass "print value of S"
308 -re ".*$gdb_prompt $" { fail "print value of S" }
309 timeout { fail "(timeout) print value of S" }
315 -re "type = short.*$gdb_prompt $" { pass "ptype S" }
316 -re ".*$gdb_prompt $" { fail "ptype S" }
317 timeout { fail "(timeout) ptype S" }
321 send_gdb "print US\n"
323 -re ".\[0-9\]* = 7.*$gdb_prompt $" {
324 pass "print value of US"
326 -re ".*$gdb_prompt $" { fail "print value of US" }
327 timeout { fail "(timeout) print value of US" }
331 send_gdb "ptype US\n"
333 -re "type = unsigned short.*$gdb_prompt $" { pass "ptype US" }
334 -re "type = short unsigned.*$gdb_prompt $" { pass "ptype US" }
335 -re ".*$gdb_prompt $" { fail "ptype US" }
336 timeout { fail "(timeout) ptype US" }
342 -re ".\[0-9\]* = 102.*$gdb_prompt $" {
343 pass "print value of I"
345 -re ".*$gdb_prompt $" { fail "print value of I" }
346 timeout { fail "(timeout) print value of I" }
352 -re "type = int.*$gdb_prompt $" { pass "ptype I" }
353 -re ".*$gdb_prompt $" { fail "ptype I" }
354 timeout { fail "(timeout) ptype I" }
358 send_gdb "print UI\n"
360 -re ".\[0-9\]* = 1002.*$gdb_prompt $" {
361 pass "print value of UI"
363 -re ".*$gdb_prompt $" { fail "print value of UI" }
364 timeout { fail "(timeout) print value of UI" }
368 send_gdb "ptype UI\n"
370 -re "type = unsigned int.*$gdb_prompt $" { pass "ptype UI" }
371 -re ".*$gdb_prompt $" { fail "ptype UI" }
372 timeout { fail "(timeout) ptype UI" }
378 -re ".\[0-9\]* = -234.*$gdb_prompt $" {
379 pass "print value of L"
381 -re ".*$gdb_prompt $" { fail "print value of L" }
382 timeout { fail "(timeout) print value of L" }
388 -re "type = long.*$gdb_prompt $" { pass "ptype L" }
389 -re ".*$gdb_prompt $" { fail "ptype L" }
390 timeout { fail "(timeout) ptype L" }
394 send_gdb "print UL\n"
396 -re ".\[0-9\]* = 234.*$gdb_prompt $" {
397 pass "print value of UL"
399 -re ".*$gdb_prompt $" { fail "print value of UL" }
400 timeout { fail "(timeout) print value of UL" }
404 send_gdb "ptype UL\n"
406 -re "type = unsigned long.*$gdb_prompt $" { pass "ptype UL" }
407 -re "type = long unsigned.*$gdb_prompt $" { pass "ptype UL" }
408 -re ".*$gdb_prompt $" { fail "ptype UL" }
409 timeout { fail "(timeout) ptype UL" }
415 -re ".\[0-9\]* = 1.2\[0-9\]*e\\+10.*$gdb_prompt $" {
416 pass "print value of F"
418 -re ".*$gdb_prompt $" { fail "print value of F" }
419 timeout { fail "(timeout) print value of F" }
426 -re "type = float.*$gdb_prompt $" { pass "ptype F" }
427 -re ".*$gdb_prompt $" { fail "ptype F" }
428 timeout { fail "(timeout) ptype F" }
434 -re ".\[0-9\]* = -1.375e-123.*$gdb_prompt $" {
435 pass "print value of D"
437 -re ".*$gdb_prompt $" { fail "print value of D" }
438 timeout { fail "(timeout) print value of D" }
444 -re "type = double.*$gdb_prompt $" { pass "ptype D" }
445 -re ".*$gdb_prompt $" { fail "ptype D" }
446 timeout { fail "(timeout) ptype D" }
452 # test reference types
458 send_gdb "ptype rC\n"
460 -re "type = char &.*$gdb_prompt $" { pass "ptype rC" }
461 -re ".*$gdb_prompt $" { fail "ptype rC" }
462 timeout { fail "(timeout) ptype rC" }
468 send_gdb "ptype rUC\n"
470 -re "type = unsigned char &.*$gdb_prompt $" { pass "ptype rUC" }
471 -re ".*$gdb_prompt $" { fail "ptype rUC" }
472 timeout { fail "(timeout) ptype rUC" }
477 send_gdb "ptype rS\n"
479 -re "type = short &.*$gdb_prompt $" { pass "ptype rS" }
480 -re "type = short int &.*$gdb_prompt $" { pass "ptype rS" }
481 -re ".*$gdb_prompt $" { fail "ptype rS" }
482 timeout { fail "(timeout) ptype rS" }
487 send_gdb "ptype rUS\n"
489 -re "type = unsigned short &.*$gdb_prompt $" { pass "ptype rUS" }
490 -re "type = short unsigned int &.*$gdb_prompt $" { pass "ptype rUS" }
491 -re ".*$gdb_prompt $" { fail "ptype rUS" }
492 timeout { fail "(timeout) ptype rUS" }
496 send_gdb "ptype rI\n"
498 -re "type = int &.*$gdb_prompt $" { pass "ptype rI" }
499 -re ".*$gdb_prompt $" { fail "ptype rI" }
500 timeout { fail "(timeout) ptype rI" }
505 send_gdb "ptype rUI\n"
507 -re "type = unsigned int &.*$gdb_prompt $" { pass "ptype rUI" }
508 -re ".*$gdb_prompt $" { fail "ptype rUI" }
509 timeout { fail "(timeout) ptype rUI" }
514 send_gdb "ptype rL\n"
516 -re "type = long &.*$gdb_prompt $" { pass "ptype rL" }
517 -re "type = long int &.*$gdb_prompt $" { pass "ptype rL" }
518 -re ".*$gdb_prompt $" { fail "ptype rL" }
519 timeout { fail "(timeout) ptype rL" }
523 send_gdb "ptype rUL\n"
525 -re "type = unsigned long &.*$gdb_prompt $" { pass "ptype rUL" }
526 -re "type = long unsigned int &.*$gdb_prompt $" { pass "ptype rUL" }
527 -re ".*$gdb_prompt $" { fail "ptype rUL" }
528 timeout { fail "(timeout) ptype rUL" }
532 send_gdb "ptype rF\n"
534 -re "type = float &.*$gdb_prompt $" { pass "ptype rF" }
535 -re ".*$gdb_prompt $" { fail "ptype rF" }
536 timeout { fail "(timeout) ptype rF" }
540 send_gdb "ptype rD\n"
542 -re "type = double &.*$gdb_prompt $" { pass "ptype rD" }
543 -re ".*$gdb_prompt $" { fail "ptype rD" }
544 timeout { fail "(timeout) ptype rD" }
548 send_gdb "print rC\n"
550 -re ".\[0-9\]* = \\(char &\\) @$hex: 65 \'A\'.*$gdb_prompt $" {
551 pass "print value of rC"
553 -re ".*$gdb_prompt $" { fail "print value of rC" }
554 timeout { fail "(timeout) print value of rC" }
558 send_gdb "print rUC\n"
560 -re ".\[0-9\]* = \\(unsigned char &\\) @$hex: 21 \'.025\'.*$gdb_prompt $" {
561 pass "print value of rUC"
563 -re ".*$gdb_prompt $" { fail "print value of rUC" }
564 timeout { fail "(timeout) print value of rUC" }
568 send_gdb "print rS\n"
570 -re ".\[0-9\]* = \\(short &\\) @$hex: -14.*$gdb_prompt $" {
571 pass "print value of rS"
573 -re ".\[0-9\]* = \\(short int &\\) @$hex: -14.*$gdb_prompt $" {
574 pass "print value of rS"
576 -re ".*$gdb_prompt $" { fail "print value of rS" }
577 timeout { fail "(timeout) print value of rS" }
581 send_gdb "print rUS\n"
583 -re ".\[0-9\]* = \\(unsigned short &\\) @$hex: 7.*$gdb_prompt $" {
584 pass "print value of rUS"
586 -re ".\[0-9\]* = \\(short unsigned int &\\) @$hex: 7.*$gdb_prompt $" {
587 pass "print value of rUS"
589 -re ".*$gdb_prompt $" { fail "print value of rUS" }
590 timeout { fail "(timeout) print value of rUS" }
594 send_gdb "print rI\n"
596 -re ".\[0-9\]* = \\(int &\\) @$hex: 102.*$gdb_prompt $" {
597 pass "print value of rI"
599 -re ".*$gdb_prompt $" { fail "print value of rI" }
600 timeout { fail "(timeout) print value of rI" }
604 send_gdb "print rUI\n"
606 -re ".\[0-9\]* = \\(unsigned int &\\) @$hex: 1002.*$gdb_prompt $" {
607 pass "print value of UI"
609 -re ".*$gdb_prompt $" { fail "print value of rUI" }
610 timeout { fail "(timeout) print value of rUI" }
614 send_gdb "print rL\n"
616 -re ".\[0-9\]* = \\(long &\\) @$hex: -234.*$gdb_prompt $" {
617 pass "print value of rL"
619 -re ".\[0-9\]* = \\(long int &\\) @$hex: -234.*$gdb_prompt $" {
620 pass "print value of rL"
622 -re ".*$gdb_prompt $" { fail "print value of rL" }
623 timeout { fail "(timeout) print value of rL" }
628 send_gdb "print rUL\n"
630 -re ".\[0-9\]* = \\(unsigned long &\\) @$hex: 234.*$gdb_prompt $" {
631 pass "print value of rUL"
633 -re ".\[0-9\]* = \\(long unsigned int &\\) @$hex: 234.*$gdb_prompt $" {
634 pass "print value of rUL"
636 -re ".*$gdb_prompt $" { fail "print value of rUL" }
637 timeout { fail "(timeout) print value of rUL" }
641 send_gdb "print rF\n"
643 -re ".\[0-9\]* = \\(float &\\) @$hex: 1.2\[0-9\]*e\\+10.*$gdb_prompt $" {
644 pass "print value of rF"
646 -re ".*$gdb_prompt $" { fail "print value of rF" }
647 timeout { fail "(timeout) print value of rF" }
651 send_gdb "print rD\n"
653 -re ".\[0-9\]* = \\(double &\\) @$hex: -1.375e-123.*$gdb_prompt $" {
654 pass "print value of rD"
656 -re ".*$gdb_prompt $" { fail "print value of rD" }
657 timeout { fail "(timeout) print value of rD" }