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