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