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