daily update
[external/binutils.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, 2008, 2009, 2010, 2011
3 # Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 # written by Elena Zannoni (ezannoni@cygnus.com)
19
20 if $tracelevel then {
21         strace $tracelevel
22         }
23
24 #
25 # test running programs
26 #
27
28 if { [skip_cplus_tests] } { continue }
29
30 set testfile "ref-types"
31 set srcfile ${testfile}.cc
32 set binfile ${objdir}/${subdir}/${testfile}
33
34 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
35      untested ref-types.exp
36      return -1
37 }
38
39 gdb_exit
40 gdb_start
41 gdb_reinitialize_dir $srcdir/$subdir
42 gdb_load ${binfile}
43
44
45 #
46 # set it up at a breakpoint so we can play with the variable values
47 #
48 if ![runto_main] then {
49     perror "couldn't run to breakpoint"
50     continue
51 }
52
53 if ![runto 'marker1'] then {
54     perror "couldn't run to marker1"
55     continue
56 }
57
58 gdb_test "up" ".*main.*" "up from marker1 1"
59
60 proc gdb_start_again {} {
61     global srcdir
62     global subdir
63     global binfile
64     global gdb_prompt
65     global decimal
66
67     gdb_start
68     gdb_reinitialize_dir $srcdir/$subdir
69     gdb_load ${binfile}
70
71     #
72     # set it up at a breakpoint so we can play with the variable values
73     #
74     if ![runto_main] then {
75         perror "couldn't run to breakpoint"
76         continue
77     }
78
79     if ![runto 'marker1'] then {
80         perror "couldn't run to marker1"
81         continue
82     }
83
84     gdb_test "up" ".*main.*" "up from marker1 2"
85 }
86
87
88 gdb_test "print s" ".\[0-9\]* = -1" "print value of s"
89 gdb_test "ptype s" "type = short"
90
91 gdb_test "print *ps" ".\[0-9\]* = -1" "print value of ps"
92 gdb_test "ptype ps" "type = short \\*"
93
94 gdb_test "print as\[0\]" ".\[0-9\]* = 0" "print value of as\[0\]"
95 gdb_test_multiple "ptype as" "ptype as" {
96     -re "type = short \\\[4\\\].*$gdb_prompt $"  { pass "ptype as" }
97     -re "type = short int \\\[4\\\].*$gdb_prompt $"  { pass "ptype as" }
98 }
99
100 gdb_test "print as\[1\]" ".\[0-9\]* = 1" "print value of as\[1\]"
101 gdb_test "print as\[2\]" ".\[0-9\]* = 2" "print value of as\[2\]"
102 gdb_test "print as\[3\]" ".\[0-9\]* = 3" "print value of as\[3\]"
103
104 gdb_test_multiple "print rs" "print value of rs" {
105     -re ".\[0-9\]* = \\(short &\\) @$hex: -1.*$gdb_prompt $" {
106         pass "print value of rs"
107     }
108     -re ".\[0-9\]* = \\(short int &\\) @$hex: -1.*$gdb_prompt $" {
109         pass "print value of rs"
110     }
111     eof { fail "print rs ($GDB dumped core) (FIXME)" ; gdb_start_again ; }
112 }
113
114 gdb_test_multiple "ptype rs" "ptype rs" {
115     -re "type = short &.*$gdb_prompt $"  { pass "ptype rs" }
116     -re "type = short int &.*$gdb_prompt $"  { pass "ptype rs" }
117 }
118
119 gdb_test "print *rps" ".\[0-9\]* = -1" "print value of *rps"
120
121 # GDB had a bug about dereferencing a pointer type
122 # that would lead to wrong results
123 # if we try to examine memory at pointer value.
124
125 gdb_test "x /hd rps" "$hex:\[ \t\]*-1" "examine value at rps"
126
127 gdb_test_multiple "ptype rps" "ptype rps" {
128     -re "type = short \\*&.*$gdb_prompt $"  { pass "ptype rps" }
129     -re "type = short int \\*&.*$gdb_prompt $"  { pass "ptype rps" }
130 }
131
132
133 gdb_test "print ras\[0\]" ".\[0-9\]* = 0" "print value of ras\[0\]"
134
135 gdb_test_multiple "ptype ras" "ptype ras" {
136     -re "type = short \\\(&\\\)\\\[4\\\].*$gdb_prompt $"  { pass "ptype ras" }
137     -re "type = short int \\\(&\\\)\\\[4\\\].*$gdb_prompt $"  { pass "ptype ras" }
138 }
139
140 gdb_test "print ras\[1\]" ".\[0-9\]* = 1" "print value of ras\[1\]"
141 gdb_test "print ras\[2\]" ".\[0-9\]* = 2" "print value of ras\[2\]"
142 gdb_test "print ras\[3\]" ".\[0-9\]* = 3" "print value of ras\[3\]"
143
144
145 if ![runto 'f'] then {
146     perror "couldn't run to f"
147     continue
148 }
149
150 gdb_test "up" ".main2.*" "up from f"
151
152 gdb_test "print C" ".\[0-9\]* = 65 \'A\'" "print value of C"
153 gdb_test "ptype C" "type = char"
154
155 gdb_test "print UC" ".\[0-9\]* = 21 '\.025'" "print value of UC"
156 gdb_test "ptype UC" "type = unsigned char"
157
158 gdb_test "print S" ".\[0-9\]* = -14" "print value of S"
159 gdb_test "ptype S" "type = short.*"
160
161 gdb_test "print US" ".\[0-9\]* = 7" "print value of US"
162 gdb_test_multiple "ptype US" "ptype US" {
163     -re "type = unsigned short.*$gdb_prompt $"  { pass "ptype US" }
164     -re "type = short unsigned.*$gdb_prompt $"  { pass "ptype US" }
165 }
166
167 gdb_test "print I" ".\[0-9\]* = 102" "print value of I"
168 gdb_test "ptype I" "type = int"
169
170 gdb_test "print UI" ".\[0-9\]* = 1002" "print value of UI"
171 gdb_test "ptype UI" "type = unsigned int"
172
173 gdb_test "print L" ".\[0-9\]* = -234" "print value of L"
174 gdb_test "ptype L" "type = long.*"
175
176 gdb_test "print UL" ".\[0-9\]* = 234" "print value of UL"
177 gdb_test_multiple "ptype UL" "ptype UL" {
178     -re "type = unsigned long.*$gdb_prompt $"  { pass "ptype UL" }
179     -re "type = long unsigned.*$gdb_prompt $"  { pass "ptype UL" }
180 }
181
182 gdb_test "print F" ".\[0-9\]* = 1.2\[0-9\]*e\\+0?10.*" \
183     "print value of F"
184
185 gdb_test "ptype F" "type = float.*"
186
187 gdb_test "print D" ".\[0-9\]* = -1.375e-123.*" \
188     "print value of D"
189
190 gdb_test "ptype D" "type = double.*"
191
192
193 #
194 # test reference types
195 #
196
197 gdb_test "ptype rC" "type = char &"
198
199 gdb_test "ptype rUC" "type = unsigned char &"
200
201 gdb_test_multiple "ptype rS" "ptype rS" {
202     -re "type = short &.*$gdb_prompt $"  { pass "ptype rS" }
203     -re "type = short int &.*$gdb_prompt $"  { pass "ptype rS" }
204 }
205
206 gdb_test_multiple "ptype rUS" "ptype rUS" {
207     -re "type = unsigned short &.*$gdb_prompt $"  { pass "ptype rUS" }
208     -re "type = short unsigned int &.*$gdb_prompt $"  { pass "ptype rUS" }
209 }
210
211 gdb_test "ptype rI" "type = int &"
212
213 gdb_test "ptype rUI" "type = unsigned int &"
214
215 gdb_test_multiple "ptype rL" "ptype rL" {
216     -re "type = long &.*$gdb_prompt $"  { pass "ptype rL" }
217     -re "type = long int &.*$gdb_prompt $"  { pass "ptype rL" }
218 }
219
220 gdb_test_multiple "ptype rUL" "ptype rUL" {
221     -re "type = unsigned long &.*$gdb_prompt $"  { pass "ptype rUL" }
222     -re "type = long unsigned int &.*$gdb_prompt $"  { pass "ptype rUL" }
223 }
224
225 gdb_test "ptype rF" "type = float &"
226
227 gdb_test "ptype rD" "type = double &"
228
229 gdb_test "print rC" ".\[0-9\]* = \\(char &\\) @$hex: 65 \'A\'" \
230     "print value of rC"
231
232 gdb_test "print rUC" \
233     ".\[0-9\]* = \\(unsigned char &\\) @$hex: 21 \'.025\'" \
234     "print value of rUC"
235
236 gdb_test_multiple "print rS" "print value of rS" {
237     -re ".\[0-9\]* = \\(short &\\) @$hex: -14.*$gdb_prompt $" {
238         pass "print value of rS"
239     }
240     -re ".\[0-9\]* = \\(short int &\\) @$hex: -14.*$gdb_prompt $" {
241         pass "print value of rS"
242     }
243 }
244
245 gdb_test_multiple "print rUS" "print value of rUS" {
246     -re ".\[0-9\]* = \\(unsigned short &\\) @$hex: 7.*$gdb_prompt $" {
247         pass "print value of rUS"
248     }
249     -re ".\[0-9\]* = \\(short unsigned int &\\) @$hex: 7.*$gdb_prompt $" {
250         pass "print value of rUS"
251     }
252 }
253
254 gdb_test "print rI" ".\[0-9\]* = \\(int &\\) @$hex: 102" \
255         "print value of rI"
256
257 gdb_test "print rUI" \
258     ".\[0-9\]* = \\(unsigned int &\\) @$hex: 1002" \
259         "print value of UI"
260
261 gdb_test_multiple "print rL" "print value of rL" {
262     -re ".\[0-9\]* = \\(long &\\) @$hex: -234.*$gdb_prompt $" {
263         pass "print value of rL"
264     }
265     -re ".\[0-9\]* = \\(long int &\\) @$hex: -234.*$gdb_prompt $" {
266         pass "print value of rL"
267     }
268 }
269
270 gdb_test_multiple "print rUL" "print value of rUL" {
271     -re ".\[0-9\]* = \\(unsigned long &\\) @$hex: 234.*$gdb_prompt $" {
272         pass "print value of rUL"
273     }
274     -re ".\[0-9\]* = \\(long unsigned int &\\) @$hex: 234.*$gdb_prompt $" {
275         pass "print value of rUL"
276     }
277 }
278
279 gdb_test "print rF" \
280     ".\[0-9\]* = \\(float &\\) @$hex: 1.2\[0-9\]*e\\+0?10.*" \
281     "print value of rF"
282
283 gdb_test "print rD" \
284     ".\[0-9\]* = \\(double &\\) @$hex: -1.375e-123.*" \
285     "print value of rD"
286