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