2004-02-07 Elena Zannoni <ezannoni@redhat.com>
[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 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 #
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
81 }
82
83 if ![runto 'marker1'] then {
84 perror "couldn't run to marker1"
85 continue
86 }
87
88 gdb_test "up" ".*main.*" "up from marker1 2"
89 }
90
91
92
93 send_gdb "print s\n"
94 gdb_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
103 send_gdb "ptype s\n"
104 gdb_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
111 send_gdb "print *ps\n"
112 gdb_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
121 send_gdb "ptype ps\n"
122 gdb_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
128 send_gdb "print as\[0\]\n"
129 gdb_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
138 send_gdb "ptype as\n"
139 gdb_expect {
140 -re "type = short \\\[4\\\].*$gdb_prompt $" { pass "ptype as" }
141 -re "type = short int \\\[4\\\].*$gdb_prompt $" { pass "ptype as" }
142 -re ".*$gdb_prompt $" { fail "ptype as" }
143 timeout { fail "(timeout) ptype as" }
144 }
145
146 send_gdb "print as\[1\]\n"
147 gdb_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
155 send_gdb "print as\[2\]\n"
156 gdb_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
164 send_gdb "print as\[3\]\n"
165 gdb_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
173 send_gdb "print rs\n"
174 gdb_expect {
175 -re ".\[0-9\]* = \\(short &\\) @$hex: -1.*$gdb_prompt $" {
176 pass "print value of rs"
177 }
178 -re ".\[0-9\]* = \\(short int &\\) @$hex: -1.*$gdb_prompt $" {
179 pass "print value of rs"
180 }
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
187 send_gdb "ptype rs\n"
188 gdb_expect {
189 -re "type = short &.*$gdb_prompt $" { pass "ptype rs" }
190 -re "type = short int &.*$gdb_prompt $" { pass "ptype rs" }
191 -re ".*$gdb_prompt $" { fail "ptype rs" }
192 timeout { fail "(timeout) ptype rs" }
193 }
194
195
196 send_gdb "print *rps\n"
197 gdb_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
206 send_gdb "ptype rps\n"
207 gdb_expect {
208 -re "type = short \\*&.*$gdb_prompt $" { pass "ptype rps" }
209 -re "type = short int \\*&.*$gdb_prompt $" { pass "ptype rps" }
210 -re ".*$gdb_prompt $" { fail "ptype rps" }
211 timeout { fail "(timeout) ptype rps" }
212 }
213
214
215
216 send_gdb "print ras\[0\]\n"
217 gdb_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
226 send_gdb "ptype ras\n"
227 gdb_expect {
228 -re "type = short \\\(&\\\)\\\[4\\\].*$gdb_prompt $" { pass "ptype ras" }
229 -re "type = short int \\\(&\\\)\\\[4\\\].*$gdb_prompt $" { pass "ptype ras" }
230 -re ".*$gdb_prompt $" { fail "ptype ras" }
231 timeout { fail "(timeout) ptype ras" }
232 }
233
234 send_gdb "print ras\[1\]\n"
235 gdb_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
243 send_gdb "print ras\[2\]\n"
244 gdb_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
252 send_gdb "print ras\[3\]\n"
253 gdb_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 }
260
261
262 if ![runto 'f'] then {
263 perror "couldn't run to f"
264 continue
265 }
266
267 gdb_test "up" ".main2.*" "up from f"
268
269 send_gdb "print C\n"
270 gdb_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
279 send_gdb "ptype C\n"
280 gdb_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
287 send_gdb "print UC\n"
288 gdb_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
297 send_gdb "ptype UC\n"
298 gdb_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
305 send_gdb "print S\n"
306 gdb_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
315 send_gdb "ptype S\n"
316 gdb_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
323 send_gdb "print US\n"
324 gdb_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
333 send_gdb "ptype US\n"
334 gdb_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
342 send_gdb "print I\n"
343 gdb_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
352 send_gdb "ptype I\n"
353 gdb_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
360 send_gdb "print UI\n"
361 gdb_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
370 send_gdb "ptype UI\n"
371 gdb_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
378 send_gdb "print L\n"
379 gdb_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
388 send_gdb "ptype L\n"
389 gdb_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
396 send_gdb "print UL\n"
397 gdb_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
406 send_gdb "ptype UL\n"
407 gdb_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
415 send_gdb "print F\n"
416 gdb_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
426 send_gdb "ptype F\n"
427 gdb_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
434 send_gdb "print D\n"
435 gdb_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
444 send_gdb "ptype D\n"
445 gdb_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
460 send_gdb "ptype rC\n"
461 gdb_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
470 send_gdb "ptype rUC\n"
471 gdb_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
479 send_gdb "ptype rS\n"
480 gdb_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
489 send_gdb "ptype rUS\n"
490 gdb_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
498 send_gdb "ptype rI\n"
499 gdb_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
507 send_gdb "ptype rUI\n"
508 gdb_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
516 send_gdb "ptype rL\n"
517 gdb_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
525 send_gdb "ptype rUL\n"
526 gdb_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
534 send_gdb "ptype rF\n"
535 gdb_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
542 send_gdb "ptype rD\n"
543 gdb_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
550 send_gdb "print rC\n"
551 gdb_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
560 send_gdb "print rUC\n"
561 gdb_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
570 send_gdb "print rS\n"
571 gdb_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
583 send_gdb "print rUS\n"
584 gdb_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
596 send_gdb "print rI\n"
597 gdb_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
606 send_gdb "print rUI\n"
607 gdb_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
616 send_gdb "print rL\n"
617 gdb_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
630 send_gdb "print rUL\n"
631 gdb_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
643 send_gdb "print rF\n"
644 gdb_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
653 send_gdb "print rD\n"
654 gdb_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.058843 seconds and 4 git commands to generate.