gdb/doc/
[external/binutils.git] / gdb / testsuite / gdb.base / code-expr.exp
1 #   Copyright (C) 2001, 2007, 2008, 2009, 2010, 2011
2 #   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 3 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, see <http://www.gnu.org/licenses/>.
16
17 # Written by Michael Snyder, Red Hat, Inc., 9/20/2001
18
19 # This file is part of the gdb testsuite
20 # Tests for type expressions using the new "@code" and "@data" modifiers.
21
22 if $tracelevel then {
23         strace $tracelevel
24         }
25
26 #
27 # test running programs
28 #
29
30 set testfile "cvexpr"
31 set srcfile ${testfile}.c
32 set binfile ${objdir}/${subdir}/${testfile}
33
34 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
35      untested code-expr.exp
36      return -1
37 }
38
39 gdb_exit
40 gdb_start
41 gdb_reinitialize_dir $srcdir/$subdir
42 gdb_load ${binfile}
43
44 gdb_test_no_output "set print sevenbit-strings"
45 gdb_test_no_output "set print address off"
46 gdb_test_no_output "set width 0"
47
48 set ws  "\[ \t\]*"
49
50 #
51 # Test casting a scalar to const
52 #
53
54 gdb_test "whatis (@code char) v_char" \
55         "type = @code char" \
56         "(@code char)"
57 gdb_test "whatis (@code signed char) v_signed_char" \
58         "type = @code signed char" \
59         "(@code signed char)"
60 gdb_test "whatis (@code unsigned char) v_unsigned_char" \
61         "type = @code (unsigned char|char)" \
62         "(@code unsigned char)"
63 gdb_test "whatis (@code short) v_short" \
64         "type = @code (short|short int)" \
65         "(@code short)"
66 gdb_test "whatis (@code signed short) v_signed_short" \
67         "type = @code (short|short int|signed short|signed short int)" \
68         "(@code signed short)"
69 gdb_test "whatis (@code unsigned short) v_unsigned_short" \
70         "type = @code (unsigned short|short unsigned int)" \
71         "(@code unsigned short)"
72 gdb_test "whatis (@code int) v_int" \
73         "type = @code int" \
74         "(@code int)"
75 gdb_test "whatis (@code signed int) v_signed_int" \
76         "type = @code (signed int|int)" \
77         "(@code signed int)"
78 gdb_test "whatis (@code unsigned int) v_unsigned_int" \
79         "type = @code unsigned int" \
80         "(@code unsigned int)"
81 gdb_test "whatis (@code long) v_long" \
82         "type = @code (long|long int)" \
83         "(@code long)"
84 gdb_test "whatis (@code signed long) v_signed_long" \
85         "type = @code (signed |)long( int|)" \
86         "(@code signed long)"
87 gdb_test "whatis (@code unsigned long) v_unsigned_long" \
88         "type = @code (unsigned long|long unsigned int)" \
89         "(@code unsigned long)"
90 gdb_test "whatis (@code long long) v_long_long" \
91         "type = @code long long( int|)" \
92         "(@code long long)"
93 gdb_test "whatis (@code signed long long) v_signed_long_long" \
94         "type = @code (signed |)long long( int|)" \
95         "(@code signed long long)"
96 gdb_test "whatis (@code unsigned long long) v_unsigned_long_long" \
97         "type = @code (unsigned long long|long long unsigned int)" \
98         "(@code unsigned long long)"
99 gdb_test "whatis (@code float) v_float" \
100         "type = @code float" \
101         "(@code float)"
102 gdb_test "whatis (@code double) v_double" \
103         "type = @code double" \
104         "(@code double)"
105
106 #
107 # Test casting a scalar to @data
108 #
109
110 gdb_test "whatis (@data char) v_char" \
111         "type = @data char" \
112         "(@data char)"
113 gdb_test "whatis (@data signed char) v_signed_char" \
114         "type = @data signed char" \
115         "(@data signed char)"
116 gdb_test "whatis (@data unsigned char) v_unsigned_char" \
117         "type = @data (unsigned char|char)" \
118         "(@data unsigned char)"
119 gdb_test "whatis (@data short) v_short" \
120         "type = @data (short|short int)" \
121         "(@data short)"
122 gdb_test "whatis (@data signed short) v_signed_short" \
123         "type = @data (short|short int|signed short|signed short int)" \
124         "(@data signed short)"
125 gdb_test "whatis (@data unsigned short) v_unsigned_short" \
126         "type = @data (unsigned short|short unsigned int)" \
127         "(@data unsigned short)"
128 gdb_test "whatis (@data int) v_int" \
129         "type = @data int" \
130         "(@data int)"
131 gdb_test "whatis (@data signed int) v_signed_int" \
132         "type = @data (signed int|int)" \
133         "(@data signed int)"
134 gdb_test "whatis (@data unsigned int) v_unsigned_int" \
135         "type = @data unsigned int" \
136         "(@data unsigned int)"
137 gdb_test "whatis (@data long) v_long" \
138         "type = @data (long|long int)" \
139         "(@data long)"
140 gdb_test "whatis (@data signed long) v_signed_long" \
141         "type = @data (signed |)long( int|)" \
142         "(@data signed long)"
143 gdb_test "whatis (@data unsigned long) v_unsigned_long" \
144         "type = @data (unsigned long|long unsigned int)" \
145         "(@data unsigned long)"
146 gdb_test "whatis (@data long long) v_long_long" \
147         "type = @data long long( int|)" \
148         "(@data long long)"
149 gdb_test "whatis (@data signed long long) v_signed_long_long" \
150         "type = @data (signed |)long long( int|)" \
151         "(@data signed long long)"
152 gdb_test "whatis (@data unsigned long long) v_unsigned_long_long" \
153         "type = @data (unsigned long long|long long unsigned int)" \
154         "(@data unsigned long long)"
155 gdb_test "whatis (@data float) v_float" \
156         "type = @data float" \
157         "(@data float)"
158 gdb_test "whatis (@data double) v_double" \
159         "type = @data double" \
160         "(@data double)"
161
162 #
163 # Now put the '@code' and '@data' keywords after the base type.
164 #
165
166 gdb_test "whatis (char @code) v_char" \
167         "type = @code char" \
168         "(char @code)"
169 gdb_test "whatis (signed char @code) v_signed_char" \
170         "type = @code signed char" \
171         "(signed char @code)"
172 gdb_test "whatis (unsigned char @code) v_unsigned_char" \
173         "type = @code (unsigned char|char)" \
174         "(unsigned char @code)"
175 gdb_test "whatis (short @code) v_short" \
176         "type = @code (short|short int)" \
177         "(short @code)"
178 gdb_test "whatis (signed short @code) v_signed_short" \
179         "type = @code (short|short int|signed short|signed short int)" \
180         "(signed short @code)"
181 gdb_test "whatis (unsigned short @code) v_unsigned_short" \
182         "type = @code (unsigned short|short unsigned int)" \
183         "(unsigned short @code)"
184 gdb_test "whatis (int @code) v_int" \
185         "type = @code int" \
186         "(int @code)"
187 gdb_test "whatis (signed int @code) v_signed_int" \
188         "type = @code (signed int|int)" \
189         "(signed int @code)"
190 gdb_test "whatis (unsigned int @code) v_unsigned_int" \
191         "type = @code unsigned int" \
192         "(unsigned int @code)"
193 gdb_test "whatis (long @code) v_long" \
194         "type = @code (long|long int)" \
195         "(long @code)"
196 gdb_test "whatis (signed long @code) v_signed_long" \
197         "type = @code (signed |)long( int|)" \
198         "(signed long @code)"
199 gdb_test "whatis (unsigned long @code) v_unsigned_long" \
200         "type = @code (unsigned long|long unsigned int)" \
201         "(unsigned long @code)"
202 gdb_test "whatis (long long @code) v_long_long" \
203         "type = @code long long( int|)" \
204         "(long long @code)"
205 gdb_test "whatis (signed long long @code) v_signed_long_long" \
206         "type = @code (signed |)long long( int|)" \
207         "(signed long long @code)"
208 gdb_test "whatis (unsigned long long @code) v_unsigned_long_long" \
209         "type = @code (unsigned long long|long long unsigned int)" \
210         "(unsigned long long @code)"
211 gdb_test "whatis (float @code) v_float" \
212         "type = @code float" \
213         "(float @code)"
214 gdb_test "whatis (double @code) v_double" \
215         "type = @code double" \
216         "(double @code)"
217
218 gdb_test "whatis (char @data) v_char" \
219         "type = @data char" \
220         "(char @data)"
221 gdb_test "whatis (signed char @data) v_signed_char" \
222         "type = @data signed char" \
223         "(signed char @data)"
224 gdb_test "whatis (unsigned char @data) v_unsigned_char" \
225         "type = @data (unsigned char|char)" \
226         "(unsigned char @data)"
227 gdb_test "whatis (short @data) v_short" \
228         "type = @data (short|short int)" \
229         "(short @data)"
230 gdb_test "whatis (signed short @data) v_signed_short" \
231         "type = @data (short|short int|signed short|signed short int)" \
232         "(signed short @data)"
233 gdb_test "whatis (unsigned short @data) v_unsigned_short" \
234         "type = @data (unsigned short|short unsigned int)" \
235         "(unsigned short @data)"
236 gdb_test "whatis (int @data) v_int" \
237         "type = @data int" \
238         "(int @data)"
239 gdb_test "whatis (signed int @data) v_signed_int" \
240         "type = @data (signed int|int)" \
241         "(signed int @data)"
242 gdb_test "whatis (unsigned int @data) v_unsigned_int" \
243         "type = @data unsigned int" \
244         "(unsigned int @data)"
245 gdb_test "whatis (long @data) v_long" \
246         "type = @data (long|long int)" \
247         "(long @data)"
248 gdb_test "whatis (signed long @data) v_signed_long" \
249         "type = @data (signed |)long( int|)" \
250         "(signed long @data)"
251 gdb_test "whatis (unsigned long @data) v_unsigned_long" \
252         "type = @data (unsigned long|long unsigned int)" \
253         "(unsigned long @data)"
254 gdb_test "whatis (long long @data) v_long_long" \
255         "type = @data long long( int|)" \
256         "(long long @data)"
257 gdb_test "whatis (signed long long @data) v_signed_long_long" \
258         "type = @data (signed |)long long( int|)" \
259         "(signed long long @data)"
260 gdb_test "whatis (unsigned long long @data) v_unsigned_long_long" \
261         "type = @data (unsigned long long|long long unsigned int)" \
262         "(unsigned long long @data)"
263 gdb_test "whatis (float @data) v_float" \
264         "type = @data float" \
265         "(float @data)"
266 gdb_test "whatis (double @data) v_double" \
267         "type = @data double" \
268         "(double @data)"
269
270 #
271 # enums
272 #
273
274 gdb_test "whatis (@code enum misordered) v_misordered" \
275         "type = @code enum misordered" \
276         "(@code enum misordered)"
277 gdb_test "whatis (enum misordered @code) v_misordered" \
278         "type = @code enum misordered" \
279         "(enum misordered @code)"
280 gdb_test "whatis (@data enum misordered) v_misordered" \
281         "type = @data enum misordered" \
282         "(@data enum misordered)"
283 gdb_test "whatis (enum misordered @data) v_misordered" \
284         "type = @data enum misordered" \
285         "(enum misordered @data)"
286
287
288 # Pointers
289 #
290
291 gdb_test "whatis (@code int *) v_int_pointer" \
292         "type = @code int${ws}\\*" \
293         "(@code int *)"
294 gdb_test "whatis (int @code *) v_int_pointer" \
295         "type = @code int${ws}\\*" \
296         "(int @code *)"
297 gdb_test "whatis (int * @code) v_int_pointer" \
298         "type = int \\*${ws}@code" \
299         "(int * @code)"
300 gdb_test "whatis (@code int * @code) v_int_pointer" \
301         "type = @code int${ws}\\*${ws}@code" \
302         "(@code int * @code)"
303 gdb_test "whatis (int @code * @code) v_int_pointer" \
304         "type = @code int${ws}\\*${ws}@code" \
305         "(int @code * @code)"
306
307 gdb_test "whatis (@code int **) v_int_pointer_pointer" \
308         "type = @code int${ws}\\*${ws}\\*" \
309         "(@code int **)"
310 gdb_test "whatis (int @code **) v_int_pointer_pointer" \
311         "type = @code int${ws}\\*${ws}\\*" \
312         "(int @code **)"
313 gdb_test "whatis (int ** @code) v_int_pointer_pointer" \
314         "type = int \\*${ws}\\*${ws}@code" \
315         "(int ** @code)"
316 gdb_test "whatis (@code int * @code *) v_int_pointer_pointer" \
317         "type = @code int${ws}\\*${ws}@code${ws}\\*" \
318         "(@code int * @code *)"
319 gdb_test "whatis (int @code * @code *) v_int_pointer_pointer" \
320         "type = @code int${ws}\\*${ws}@code${ws}\\*" \
321         "(int @code * @code *)"
322 gdb_test "whatis (@code int * @code * @code) v_int_pointer_pointer" \
323         "type = @code int${ws}\\*${ws}@code${ws}\\*${ws}@code" \
324         "(@code int * @code * @code)"
325 gdb_test "whatis (int @code * @code * @code) v_int_pointer_pointer" \
326         "type = @code int${ws}\\*${ws}@code${ws}\\*${ws}@code" \
327         "(int @code * @code * @code)"
328
329 #
330 # Arrays TODO
331 #
332
333 #
334 # Pointers to arrays, arrays of pointers TODO
335 #
336
337 #
338 # Structs and Unions
339 #
340
341 gdb_test "whatis (@code struct t_struct) v_struct1" \
342         "type = @code struct t_struct" \
343         "(@code struct t_struct)"
344 gdb_test "whatis (@code union t_union) v_union" \
345         "type = @code union t_union" \
346         "(@code union t_union)"
347 gdb_test "whatis (struct t_struct @code) v_struct1" \
348         "type = @code struct t_struct" \
349         "(struct t_struct @code)"
350 gdb_test "whatis (union t_union @code) v_union" \
351         "type = @code union t_union" \
352         "(union t_union @code)"
353 gdb_test "whatis (@code struct t_struct *) &v_struct1" \
354         "type = @code struct t_struct${ws}\\*" \
355         "(@code struct t_struct *)"
356 gdb_test "whatis (@code union t_union *) &v_union" \
357         "type = @code union t_union${ws}\\*" \
358         "(@code union t_union *)"
359 gdb_test "whatis (struct t_struct @code *) &v_struct1" \
360         "type = @code struct t_struct${ws}\\*" \
361         "(struct t_struct @code *)"
362 gdb_test "whatis (union t_union @code *) &v_union" \
363         "type = @code union t_union${ws}\\*" \
364         "(union t_union @code *)"
365 gdb_test "whatis (struct t_struct * @code) &v_struct1" \
366         "type = struct t_struct${ws}\\*${ws}@code" \
367         "(struct t_struct * @code)"
368 gdb_test "whatis (union t_union * @code) &v_union" \
369         "type = union t_union${ws}\\*${ws}@code" \
370         "(union t_union * @code)"
371 gdb_test "whatis (@code struct t_struct * @code) &v_struct1" \
372         "type = @code struct t_struct${ws}\\*${ws}@code" \
373         "(@code struct t_struct * @code)"
374 gdb_test "whatis (@code union t_union * @code) &v_union" \
375         "type = @code union t_union${ws}\\*${ws}@code" \
376         "(@code union t_union * @code)"
377 gdb_test "whatis (struct t_struct @code * @code) &v_struct1" \
378         "type = @code struct t_struct${ws}\\*${ws}@code" \
379         "(struct t_struct @code * @code)"
380 gdb_test "whatis (union t_union @code * @code) &v_union" \
381         "type = @code union t_union${ws}\\*${ws}@code" \
382         "(union t_union @code * @code)"
383
384 #
385 # Function pointers TODO
386 #
387