gdb
[deliverable/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
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
204 send_gdb "ptype rps\n"
205 gdb_expect {
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" }
210 }
211
212
213
214 send_gdb "print ras\[0\]\n"
215 gdb_expect {
216 -re ".\[0-9\]* = 0.*$gdb_prompt $" {
217 pass "print value of ras\[0\]"
218 }
219 -re ".*$gdb_prompt $" { fail "print value of ras\[0\]" }
220 timeout { fail "(timeout) print value of ras\[0\]" }
221 }
222
223
224 send_gdb "ptype ras\n"
225 gdb_expect {
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" }
230 }
231
232 send_gdb "print ras\[1\]\n"
233 gdb_expect {
234 -re ".\[0-9\]* = 1.*$gdb_prompt $" {
235 pass "print value of ras\[1\]"
236 }
237 -re ".*$gdb_prompt $" { fail "print value of ras\[1\]" }
238 timeout { fail "(timeout) print value of ras\[1\]" }
239 }
240
241 send_gdb "print ras\[2\]\n"
242 gdb_expect {
243 -re ".\[0-9\]* = 2.*$gdb_prompt $" {
244 pass "print value of ras\[2\]"
245 }
246 -re ".*$gdb_prompt $" { fail "print value of ras\[2\]" }
247 timeout { fail "(timeout) print value of ras\[2\]" }
248 }
249
250 send_gdb "print ras\[3\]\n"
251 gdb_expect {
252 -re ".\[0-9\]* = 3.*$gdb_prompt $" {
253 pass "print value of ras\[3\]"
254 }
255 -re ".*$gdb_prompt $" { fail "print value of ras\[3\]" }
256 timeout { fail "(timeout) print value of ras\[3\]" }
257 }
258
259
260 if ![runto 'f'] then {
261 perror "couldn't run to f"
262 continue
263 }
264
265 gdb_test "up" ".main2.*" "up from f"
266
267 send_gdb "print C\n"
268 gdb_expect {
269 -re ".\[0-9\]* = 65 \'A\'.*$gdb_prompt $" {
270 pass "print value of C"
271 }
272 -re ".*$gdb_prompt $" { fail "print value of C" }
273 timeout { fail "(timeout) print value of C" }
274 }
275
276
277 send_gdb "ptype C\n"
278 gdb_expect {
279 -re "type = char.*$gdb_prompt $" { pass "ptype C" }
280 -re ".*$gdb_prompt $" { fail "ptype C" }
281 timeout { fail "(timeout) ptype C" }
282 }
283
284
285 send_gdb "print UC\n"
286 gdb_expect {
287 -re ".\[0-9\]* = 21 '\.025'\.*$gdb_prompt $" {
288 pass "print value of UC"
289 }
290 -re ".*$gdb_prompt $" { fail "print value of UC" }
291 timeout { fail "(timeout) print value of UC" }
292 }
293
294
295 send_gdb "ptype UC\n"
296 gdb_expect {
297 -re "type = unsigned char.*$gdb_prompt $" { pass "ptype UC" }
298 -re ".*$gdb_prompt $" { fail "ptype UC" }
299 timeout { fail "(timeout) ptype UC" }
300 }
301
302
303 send_gdb "print S\n"
304 gdb_expect {
305 -re ".\[0-9\]* = -14.*$gdb_prompt $" {
306 pass "print value of S"
307 }
308 -re ".*$gdb_prompt $" { fail "print value of S" }
309 timeout { fail "(timeout) print value of S" }
310 }
311
312
313 send_gdb "ptype S\n"
314 gdb_expect {
315 -re "type = short.*$gdb_prompt $" { pass "ptype S" }
316 -re ".*$gdb_prompt $" { fail "ptype S" }
317 timeout { fail "(timeout) ptype S" }
318 }
319
320
321 send_gdb "print US\n"
322 gdb_expect {
323 -re ".\[0-9\]* = 7.*$gdb_prompt $" {
324 pass "print value of US"
325 }
326 -re ".*$gdb_prompt $" { fail "print value of US" }
327 timeout { fail "(timeout) print value of US" }
328 }
329
330
331 send_gdb "ptype US\n"
332 gdb_expect {
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" }
337 }
338
339
340 send_gdb "print I\n"
341 gdb_expect {
342 -re ".\[0-9\]* = 102.*$gdb_prompt $" {
343 pass "print value of I"
344 }
345 -re ".*$gdb_prompt $" { fail "print value of I" }
346 timeout { fail "(timeout) print value of I" }
347 }
348
349
350 send_gdb "ptype I\n"
351 gdb_expect {
352 -re "type = int.*$gdb_prompt $" { pass "ptype I" }
353 -re ".*$gdb_prompt $" { fail "ptype I" }
354 timeout { fail "(timeout) ptype I" }
355 }
356
357
358 send_gdb "print UI\n"
359 gdb_expect {
360 -re ".\[0-9\]* = 1002.*$gdb_prompt $" {
361 pass "print value of UI"
362 }
363 -re ".*$gdb_prompt $" { fail "print value of UI" }
364 timeout { fail "(timeout) print value of UI" }
365 }
366
367
368 send_gdb "ptype UI\n"
369 gdb_expect {
370 -re "type = unsigned int.*$gdb_prompt $" { pass "ptype UI" }
371 -re ".*$gdb_prompt $" { fail "ptype UI" }
372 timeout { fail "(timeout) ptype UI" }
373 }
374
375
376 send_gdb "print L\n"
377 gdb_expect {
378 -re ".\[0-9\]* = -234.*$gdb_prompt $" {
379 pass "print value of L"
380 }
381 -re ".*$gdb_prompt $" { fail "print value of L" }
382 timeout { fail "(timeout) print value of L" }
383 }
384
385
386 send_gdb "ptype L\n"
387 gdb_expect {
388 -re "type = long.*$gdb_prompt $" { pass "ptype L" }
389 -re ".*$gdb_prompt $" { fail "ptype L" }
390 timeout { fail "(timeout) ptype L" }
391 }
392
393
394 send_gdb "print UL\n"
395 gdb_expect {
396 -re ".\[0-9\]* = 234.*$gdb_prompt $" {
397 pass "print value of UL"
398 }
399 -re ".*$gdb_prompt $" { fail "print value of UL" }
400 timeout { fail "(timeout) print value of UL" }
401 }
402
403
404 send_gdb "ptype UL\n"
405 gdb_expect {
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" }
410 }
411
412
413 send_gdb "print F\n"
414 gdb_expect {
415 -re ".\[0-9\]* = 1.2\[0-9\]*e\\+10.*$gdb_prompt $" {
416 pass "print value of F"
417 }
418 -re ".*$gdb_prompt $" { fail "print value of F" }
419 timeout { fail "(timeout) print value of F" }
420 }
421
422
423
424 send_gdb "ptype F\n"
425 gdb_expect {
426 -re "type = float.*$gdb_prompt $" { pass "ptype F" }
427 -re ".*$gdb_prompt $" { fail "ptype F" }
428 timeout { fail "(timeout) ptype F" }
429 }
430
431
432 send_gdb "print D\n"
433 gdb_expect {
434 -re ".\[0-9\]* = -1.375e-123.*$gdb_prompt $" {
435 pass "print value of D"
436 }
437 -re ".*$gdb_prompt $" { fail "print value of D" }
438 timeout { fail "(timeout) print value of D" }
439 }
440
441
442 send_gdb "ptype D\n"
443 gdb_expect {
444 -re "type = double.*$gdb_prompt $" { pass "ptype D" }
445 -re ".*$gdb_prompt $" { fail "ptype D" }
446 timeout { fail "(timeout) ptype D" }
447 }
448
449
450
451 #
452 # test reference types
453 #
454
455
456
457
458 send_gdb "ptype rC\n"
459 gdb_expect {
460 -re "type = char &.*$gdb_prompt $" { pass "ptype rC" }
461 -re ".*$gdb_prompt $" { fail "ptype rC" }
462 timeout { fail "(timeout) ptype rC" }
463 }
464
465
466
467
468 send_gdb "ptype rUC\n"
469 gdb_expect {
470 -re "type = unsigned char &.*$gdb_prompt $" { pass "ptype rUC" }
471 -re ".*$gdb_prompt $" { fail "ptype rUC" }
472 timeout { fail "(timeout) ptype rUC" }
473 }
474
475
476
477 send_gdb "ptype rS\n"
478 gdb_expect {
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" }
483 }
484
485
486
487 send_gdb "ptype rUS\n"
488 gdb_expect {
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" }
493 }
494
495
496 send_gdb "ptype rI\n"
497 gdb_expect {
498 -re "type = int &.*$gdb_prompt $" { pass "ptype rI" }
499 -re ".*$gdb_prompt $" { fail "ptype rI" }
500 timeout { fail "(timeout) ptype rI" }
501 }
502
503
504
505 send_gdb "ptype rUI\n"
506 gdb_expect {
507 -re "type = unsigned int &.*$gdb_prompt $" { pass "ptype rUI" }
508 -re ".*$gdb_prompt $" { fail "ptype rUI" }
509 timeout { fail "(timeout) ptype rUI" }
510 }
511
512
513
514 send_gdb "ptype rL\n"
515 gdb_expect {
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" }
520 }
521
522
523 send_gdb "ptype rUL\n"
524 gdb_expect {
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" }
529 }
530
531
532 send_gdb "ptype rF\n"
533 gdb_expect {
534 -re "type = float &.*$gdb_prompt $" { pass "ptype rF" }
535 -re ".*$gdb_prompt $" { fail "ptype rF" }
536 timeout { fail "(timeout) ptype rF" }
537 }
538
539
540 send_gdb "ptype rD\n"
541 gdb_expect {
542 -re "type = double &.*$gdb_prompt $" { pass "ptype rD" }
543 -re ".*$gdb_prompt $" { fail "ptype rD" }
544 timeout { fail "(timeout) ptype rD" }
545 }
546
547
548 send_gdb "print rC\n"
549 gdb_expect {
550 -re ".\[0-9\]* = \\(char &\\) @$hex: 65 \'A\'.*$gdb_prompt $" {
551 pass "print value of rC"
552 }
553 -re ".*$gdb_prompt $" { fail "print value of rC" }
554 timeout { fail "(timeout) print value of rC" }
555 }
556
557
558 send_gdb "print rUC\n"
559 gdb_expect {
560 -re ".\[0-9\]* = \\(unsigned char &\\) @$hex: 21 \'.025\'.*$gdb_prompt $" {
561 pass "print value of rUC"
562 }
563 -re ".*$gdb_prompt $" { fail "print value of rUC" }
564 timeout { fail "(timeout) print value of rUC" }
565 }
566
567
568 send_gdb "print rS\n"
569 gdb_expect {
570 -re ".\[0-9\]* = \\(short &\\) @$hex: -14.*$gdb_prompt $" {
571 pass "print value of rS"
572 }
573 -re ".\[0-9\]* = \\(short int &\\) @$hex: -14.*$gdb_prompt $" {
574 pass "print value of rS"
575 }
576 -re ".*$gdb_prompt $" { fail "print value of rS" }
577 timeout { fail "(timeout) print value of rS" }
578 }
579
580
581 send_gdb "print rUS\n"
582 gdb_expect {
583 -re ".\[0-9\]* = \\(unsigned short &\\) @$hex: 7.*$gdb_prompt $" {
584 pass "print value of rUS"
585 }
586 -re ".\[0-9\]* = \\(short unsigned int &\\) @$hex: 7.*$gdb_prompt $" {
587 pass "print value of rUS"
588 }
589 -re ".*$gdb_prompt $" { fail "print value of rUS" }
590 timeout { fail "(timeout) print value of rUS" }
591 }
592
593
594 send_gdb "print rI\n"
595 gdb_expect {
596 -re ".\[0-9\]* = \\(int &\\) @$hex: 102.*$gdb_prompt $" {
597 pass "print value of rI"
598 }
599 -re ".*$gdb_prompt $" { fail "print value of rI" }
600 timeout { fail "(timeout) print value of rI" }
601 }
602
603
604 send_gdb "print rUI\n"
605 gdb_expect {
606 -re ".\[0-9\]* = \\(unsigned int &\\) @$hex: 1002.*$gdb_prompt $" {
607 pass "print value of UI"
608 }
609 -re ".*$gdb_prompt $" { fail "print value of rUI" }
610 timeout { fail "(timeout) print value of rUI" }
611 }
612
613
614 send_gdb "print rL\n"
615 gdb_expect {
616 -re ".\[0-9\]* = \\(long &\\) @$hex: -234.*$gdb_prompt $" {
617 pass "print value of rL"
618 }
619 -re ".\[0-9\]* = \\(long int &\\) @$hex: -234.*$gdb_prompt $" {
620 pass "print value of rL"
621 }
622 -re ".*$gdb_prompt $" { fail "print value of rL" }
623 timeout { fail "(timeout) print value of rL" }
624 }
625
626
627
628 send_gdb "print rUL\n"
629 gdb_expect {
630 -re ".\[0-9\]* = \\(unsigned long &\\) @$hex: 234.*$gdb_prompt $" {
631 pass "print value of rUL"
632 }
633 -re ".\[0-9\]* = \\(long unsigned int &\\) @$hex: 234.*$gdb_prompt $" {
634 pass "print value of rUL"
635 }
636 -re ".*$gdb_prompt $" { fail "print value of rUL" }
637 timeout { fail "(timeout) print value of rUL" }
638 }
639
640
641 send_gdb "print rF\n"
642 gdb_expect {
643 -re ".\[0-9\]* = \\(float &\\) @$hex: 1.2\[0-9\]*e\\+10.*$gdb_prompt $" {
644 pass "print value of rF"
645 }
646 -re ".*$gdb_prompt $" { fail "print value of rF" }
647 timeout { fail "(timeout) print value of rF" }
648 }
649
650
651 send_gdb "print rD\n"
652 gdb_expect {
653 -re ".\[0-9\]* = \\(double &\\) @$hex: -1.375e-123.*$gdb_prompt $" {
654 pass "print value of rD"
655 }
656 -re ".*$gdb_prompt $" { fail "print value of rD" }
657 timeout { fail "(timeout) print value of rD" }
658 }
659
This page took 0.052754 seconds and 4 git commands to generate.