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