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