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