1 # Copyright (C) 2001, 2007-2012 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Written by Michael Snyder, Red Hat, Inc., 9/20/2001
18 # This file is part of the gdb testsuite
19 # Tests for type expressions using const and volatile keywords.
26 # test running programs
30 set srcfile ${testfile}.c
31 set binfile ${objdir}/${subdir}/${testfile}
33 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40 gdb_reinitialize_dir $srcdir/$subdir
43 gdb_test_no_output "set print sevenbit-strings"
44 gdb_test_no_output "set print address off"
45 gdb_test_no_output "set width 0"
50 # Test casting a scalar to const
53 gdb_test "whatis (const char) v_char" \
56 gdb_test "whatis (const signed char) v_signed_char" \
57 "type = const signed char" \
59 gdb_test "whatis (const unsigned char) v_unsigned_char" \
60 "type = const (unsigned char|char)" \
61 "(const unsigned char)"
62 gdb_test "whatis (const short) v_short" \
63 "type = const (short|short int)" \
65 gdb_test "whatis (const signed short) v_signed_short" \
66 "type = const (short|short int|signed short|signed short int)" \
67 "(const signed short)"
68 gdb_test "whatis (const unsigned short) v_unsigned_short" \
69 "type = const (unsigned short|short unsigned int)" \
70 "(const unsigned short)"
71 gdb_test "whatis (const int) v_int" \
74 gdb_test "whatis (const signed int) v_signed_int" \
75 "type = const (signed int|int)" \
77 gdb_test "whatis (const unsigned int) v_unsigned_int" \
78 "type = const unsigned int" \
79 "(const unsigned int)"
80 gdb_test "whatis (const long) v_long" \
81 "type = const (long|long int)" \
83 gdb_test "whatis (const signed long) v_signed_long" \
84 "type = const (signed |)long( int|)" \
86 gdb_test "whatis (const unsigned long) v_unsigned_long" \
87 "type = const (unsigned long|long unsigned int)" \
88 "(const unsigned long)"
89 gdb_test "whatis (const long long) v_long_long" \
90 "type = const long long( int|)" \
92 gdb_test "whatis (const signed long long) v_signed_long_long" \
93 "type = const (signed |)long long( int|)" \
94 "(const signed long long)"
95 gdb_test "whatis (const unsigned long long) v_unsigned_long_long" \
96 "type = const (unsigned long long|long long unsigned int)" \
97 "(const unsigned long long)"
98 gdb_test "whatis (const float) v_float" \
99 "type = const float" \
101 gdb_test "whatis (const double) v_double" \
102 "type = const double" \
106 # Test casting a scalar to volatile
109 gdb_test "whatis (volatile char) v_char" \
110 "type = volatile char" \
112 gdb_test "whatis (volatile signed char) v_signed_char" \
113 "type = volatile signed char" \
114 "(volatile signed char)"
115 gdb_test "whatis (volatile unsigned char) v_unsigned_char" \
116 "type = volatile (unsigned char|char)" \
117 "(volatile unsigned char)"
118 gdb_test "whatis (volatile short) v_short" \
119 "type = volatile (short|short int)" \
121 gdb_test "whatis (volatile signed short) v_signed_short" \
122 "type = volatile (short|short int|signed short|signed short int)" \
123 "(volatile signed short)"
124 gdb_test "whatis (volatile unsigned short) v_unsigned_short" \
125 "type = volatile (unsigned short|short unsigned int)" \
126 "(volatile unsigned short)"
127 gdb_test "whatis (volatile int) v_int" \
128 "type = volatile int" \
130 gdb_test "whatis (volatile signed int) v_signed_int" \
131 "type = volatile (signed int|int)" \
132 "(volatile signed int)"
133 gdb_test "whatis (volatile unsigned int) v_unsigned_int" \
134 "type = volatile unsigned int" \
135 "(volatile unsigned int)"
136 gdb_test "whatis (volatile long) v_long" \
137 "type = volatile (long|long int)" \
139 gdb_test "whatis (volatile signed long) v_signed_long" \
140 "type = volatile (signed |)long( int|)" \
141 "(volatile signed long)"
142 gdb_test "whatis (volatile unsigned long) v_unsigned_long" \
143 "type = volatile (unsigned long|long unsigned int)" \
144 "(volatile unsigned long)"
145 gdb_test "whatis (volatile long long) v_long_long" \
146 "type = volatile long long( int|)" \
147 "(volatile long long)"
148 gdb_test "whatis (volatile signed long long) v_signed_long_long" \
149 "type = volatile (signed |)long long( int|)" \
150 "(volatile signed long long)"
151 gdb_test "whatis (volatile unsigned long long) v_unsigned_long_long" \
152 "type = volatile (unsigned long long|long long unsigned int)" \
153 "(volatile unsigned long long)"
154 gdb_test "whatis (volatile float) v_float" \
155 "type = volatile float" \
157 gdb_test "whatis (volatile double) v_double" \
158 "type = volatile double" \
162 # Combine const and volatile
165 gdb_test "whatis (const volatile int) v_int" \
166 "type = const volatile int" \
167 "(const volatile int)"
168 gdb_test "whatis (volatile const int) v_int" \
169 "type = const volatile int" \
170 "(volatile const int)"
171 gdb_test "whatis (const int volatile) v_int" \
172 "type = const volatile int" \
173 "(const int volatile)"
174 gdb_test "whatis (volatile int const) v_int" \
175 "type = const volatile int" \
176 "(volatile int const)"
177 gdb_test "whatis (int const volatile) v_int" \
178 "type = const volatile int" \
179 "(int const volatile)"
180 gdb_test "whatis (int volatile const) v_int" \
181 "type = const volatile int" \
182 "(int volatile const)"
184 gdb_test "whatis (const volatile int *) v_int_pointer" \
185 "type = const volatile int${ws}\\*" \
186 "(const volatile int *)"
187 gdb_test "whatis (volatile const int *) v_int_pointer" \
188 "type = const volatile int${ws}\\*" \
189 "(volatile const int *)"
190 gdb_test "whatis (const int volatile *) v_int_pointer" \
191 "type = const volatile int${ws}\\*" \
192 "(const int volatile)"
193 gdb_test "whatis (volatile int const *) v_int_pointer" \
194 "type = const volatile int${ws}\\*" \
195 "(volatile int const *)"
196 gdb_test "whatis (int const volatile *) v_int_pointer" \
197 "type = const volatile int${ws}\\*" \
198 "(int const volatile *)"
199 gdb_test "whatis (int volatile const *) v_int_pointer" \
200 "type = const volatile int${ws}\\*" \
201 "(int volatile const *)"
202 gdb_test "whatis (int * const volatile) v_int_pointer" \
203 "type = int${ws}\\*${ws}const volatile" \
204 "(int * const volatile)"
205 gdb_test "whatis (int * volatile const) v_int_pointer" \
206 "type = int${ws}\\*${ws}const volatile" \
207 "(int * volatile const)"
211 # Put 'signed' and 'unsigned' before const/volatile (FIXME)
214 #gdb_test "whatis (signed const char) v_signed_char" \
215 # "type = const char" \
216 # "(signed const char)"
217 #gdb_test "whatis (unsigned const char) v_unsigned_char" \
218 # "type = const (unsigned char|char)" \
219 # "(unsigned const char)"
220 #gdb_test "whatis (signed const short) v_signed_short" \
221 # "type = const (short|short int|signed short|signed short int)" \
222 # "(signed const short)"
223 #gdb_test "whatis (unsigned const short) v_unsigned_short" \
224 # "type = const (unsigned short|short unsigned int)" \
225 # "(unsigned const short)"
226 #gdb_test "whatis (signed const int) v_signed_int" \
227 # "type = const (signed int|int)" \
228 # "(signed const int)"
229 #gdb_test "whatis (unsigned const int) v_unsigned_int" \
230 # "type = const unsigned int" \
231 # "(unsigned const int)"
232 #gdb_test "whatis (signed const long) v_signed_long" \
233 # "type = const (signed |)long( int|)" \
234 # "(signed const long)"
235 #gdb_test "whatis (unsigned const long) v_unsigned_long" \
236 # "type = const (unsigned long|long unsigned int)" \
237 # "(unsigned const long)"
238 #gdb_test "whatis (signed const long long) v_signed_long_long" \
239 # "type = const (signed |)long long( int|)" \
240 # "(signed const long long)"
241 #gdb_test "whatis (unsigned const long long) v_unsigned_long_long" \
242 # "type = const (unsigned long long|long long unsigned int)" \
243 # "(const unsigned long long)"
245 #gdb_test "whatis (signed volatile char) v_signed_char" \
246 # "type = volatile char" \
247 # "(signed volatile char)"
248 #gdb_test "whatis (unsigned volatile char) v_unsigned_char" \
249 # "type = volatile (unsigned char|char)" \
250 # "(unsigned volatile char)"
251 #gdb_test "whatis (signed volatile short) v_signed_short" \
252 # "type = volatile (short|short int|signed short|signed short int)" \
253 # "(signed volatile short)"
254 #gdb_test "whatis (unsigned volatile short) v_unsigned_short" \
255 # "type = volatile (unsigned short|short unsigned int)" \
256 # "(unsigned volatile short)"
257 #gdb_test "whatis (signed volatile int) v_signed_int" \
258 # "type = volatile (signed int|int)" \
259 # "(signed volatile int)"
260 #gdb_test "whatis (unsigned volatile int) v_unsigned_int" \
261 # "type = volatile unsigned int" \
262 # "(unsigned volatile int)"
263 #gdb_test "whatis (signed volatile long) v_signed_long" \
264 # "type = volatile (signed |)long( int|)" \
265 # "(signed volatile long)"
266 #gdb_test "whatis (unsigned volatile long) v_unsigned_long" \
267 # "type = volatile (unsigned long|long unsigned int)" \
268 # "(unsigned volatile long)"
269 #gdb_test "whatis (signed volatile long long) v_signed_long_long" \
270 # "type = volatile (signed |)long long( int|)" \
271 # "(signed volatile long long)"
272 #gdb_test "whatis (unsigned volatile long long) v_unsigned_long_long" \
273 # "type = volatile (unsigned long long|long long unsigned int)" \
274 # "(unsigned volatile long long)"
277 # Now put the 'const' and 'volatile' keywords after the base type.
280 gdb_test "whatis (char const) v_char" \
281 "type = const char" \
283 gdb_test "whatis (signed char const) v_signed_char" \
284 "type = const signed char" \
285 "(signed char const)"
286 gdb_test "whatis (unsigned char const) v_unsigned_char" \
287 "type = const (unsigned char|char)" \
288 "(unsigned char const)"
289 gdb_test "whatis (short const) v_short" \
290 "type = const (short|short int)" \
292 gdb_test "whatis (signed short const) v_signed_short" \
293 "type = const (short|short int|signed short|signed short int)" \
294 "(signed short const)"
295 gdb_test "whatis (unsigned short const) v_unsigned_short" \
296 "type = const (unsigned short|short unsigned int)" \
297 "(unsigned short const)"
298 gdb_test "whatis (int const) v_int" \
301 gdb_test "whatis (signed int const) v_signed_int" \
302 "type = const (signed int|int)" \
304 gdb_test "whatis (unsigned int const) v_unsigned_int" \
305 "type = const unsigned int" \
306 "(unsigned int const)"
307 gdb_test "whatis (long const) v_long" \
308 "type = const (long|long int)" \
310 gdb_test "whatis (signed long const) v_signed_long" \
311 "type = const (signed |)long( int|)" \
312 "(signed long const)"
313 gdb_test "whatis (unsigned long const) v_unsigned_long" \
314 "type = const (unsigned long|long unsigned int)" \
315 "(unsigned long const)"
316 gdb_test "whatis (long long const) v_long_long" \
317 "type = const long long( int|)" \
319 gdb_test "whatis (signed long long const) v_signed_long_long" \
320 "type = const (signed |)long long( int|)" \
321 "(signed long long const)"
322 gdb_test "whatis (unsigned long long const) v_unsigned_long_long" \
323 "type = const (unsigned long long|long long unsigned int)" \
324 "(unsigned long long const)"
325 gdb_test "whatis (float const) v_float" \
326 "type = const float" \
328 gdb_test "whatis (double const) v_double" \
329 "type = const double" \
332 gdb_test "whatis (char volatile) v_char" \
333 "type = volatile char" \
335 gdb_test "whatis (signed char volatile) v_signed_char" \
336 "type = volatile signed char" \
337 "(signed char volatile)"
338 gdb_test "whatis (unsigned char volatile) v_unsigned_char" \
339 "type = volatile (unsigned char|char)" \
340 "(unsigned char volatile)"
341 gdb_test "whatis (short volatile) v_short" \
342 "type = volatile (short|short int)" \
344 gdb_test "whatis (signed short volatile) v_signed_short" \
345 "type = volatile (short|short int|signed short|signed short int)" \
346 "(signed short volatile)"
347 gdb_test "whatis (unsigned short volatile) v_unsigned_short" \
348 "type = volatile (unsigned short|short unsigned int)" \
349 "(unsigned short volatile)"
350 gdb_test "whatis (int volatile) v_int" \
351 "type = volatile int" \
353 gdb_test "whatis (signed int volatile) v_signed_int" \
354 "type = volatile (signed int|int)" \
355 "(signed int volatile)"
356 gdb_test "whatis (unsigned int volatile) v_unsigned_int" \
357 "type = volatile unsigned int" \
358 "(unsigned int volatile)"
359 gdb_test "whatis (long volatile) v_long" \
360 "type = volatile (long|long int)" \
362 gdb_test "whatis (signed long volatile) v_signed_long" \
363 "type = volatile (signed |)long( int|)" \
364 "(signed long volatile)"
365 gdb_test "whatis (unsigned long volatile) v_unsigned_long" \
366 "type = volatile (unsigned long|long unsigned int)" \
367 "(unsigned long volatile)"
368 gdb_test "whatis (long long volatile) v_long_long" \
369 "type = volatile long long( int|)" \
370 "(long long volatile)"
371 gdb_test "whatis (signed long long volatile) v_signed_long_long" \
372 "type = volatile (signed |)long long( int|)" \
373 "(signed long long volatile)"
374 gdb_test "whatis (unsigned long long volatile) v_unsigned_long_long" \
375 "type = volatile (unsigned long long|long long unsigned int)" \
376 "(unsigned long long volatile)"
377 gdb_test "whatis (float volatile) v_float" \
378 "type = volatile float" \
380 gdb_test "whatis (double volatile) v_double" \
381 "type = volatile double" \
388 gdb_test "whatis (const enum misordered) v_misordered" \
389 "type = const enum misordered" \
390 "(const enum misordered)"
391 gdb_test "whatis (enum misordered const) v_misordered" \
392 "type = const enum misordered" \
393 "(enum misordered const)"
394 gdb_test "whatis (volatile enum misordered) v_misordered" \
395 "type = volatile enum misordered" \
396 "(volatile enum misordered)"
397 gdb_test "whatis (enum misordered volatile) v_misordered" \
398 "type = volatile enum misordered" \
399 "(enum misordered volatile)"
405 gdb_test "whatis (const int *) v_int_pointer" \
406 "type = const int${ws}\\*" \
408 gdb_test "whatis (int const *) v_int_pointer" \
409 "type = const int${ws}\\*" \
411 gdb_test "whatis (int * const) v_int_pointer" \
412 "type = int \\*${ws}const" \
414 gdb_test "whatis (const int * const) v_int_pointer" \
415 "type = const int${ws}\\*${ws}const" \
416 "(const int * const)"
417 gdb_test "whatis (int const * const) v_int_pointer" \
418 "type = const int${ws}\\*${ws}const" \
419 "(int const * const)"
421 gdb_test "whatis (const int **) v_int_pointer_pointer" \
422 "type = const int${ws}\\*${ws}\\*" \
424 gdb_test "whatis (int const **) v_int_pointer_pointer" \
425 "type = const int${ws}\\*${ws}\\*" \
427 gdb_test "whatis (int ** const) v_int_pointer_pointer" \
428 "type = int \\*${ws}\\*${ws}const" \
430 gdb_test "whatis (const int * const *) v_int_pointer_pointer" \
431 "type = const int${ws}\\*${ws}const${ws}\\*" \
432 "(const int * const *)"
433 gdb_test "whatis (int const * const *) v_int_pointer_pointer" \
434 "type = const int${ws}\\*${ws}const${ws}\\*" \
435 "(int const * const *)"
436 gdb_test "whatis (const int * const * const) v_int_pointer_pointer" \
437 "type = const int${ws}\\*${ws}const${ws}\\*${ws}const" \
438 "(const int * const * const)"
439 gdb_test "whatis (int const * const * const) v_int_pointer_pointer" \
440 "type = const int${ws}\\*${ws}const${ws}\\*${ws}const" \
441 "(int const * const * const)"
448 # Pointers to arrays, arrays of pointers TODO
455 gdb_test "whatis (const struct t_struct) v_struct1" \
456 "type = const struct t_struct" \
457 "(const struct t_struct)"
458 gdb_test "whatis (const union t_union) v_union" \
459 "type = const union t_union" \
460 "(const union t_union)"
461 gdb_test "whatis (struct t_struct const) v_struct1" \
462 "type = const struct t_struct" \
463 "(struct t_struct const)"
464 gdb_test "whatis (union t_union const) v_union" \
465 "type = const union t_union" \
466 "(union t_union const)"
467 gdb_test "whatis (const struct t_struct *) &v_struct1" \
468 "type = const struct t_struct${ws}\\*" \
469 "(const struct t_struct *)"
470 gdb_test "whatis (const union t_union *) &v_union" \
471 "type = const union t_union${ws}\\*" \
472 "(const union t_union *)"
473 gdb_test "whatis (struct t_struct const *) &v_struct1" \
474 "type = const struct t_struct${ws}\\*" \
475 "(struct t_struct const *)"
476 gdb_test "whatis (union t_union const *) &v_union" \
477 "type = const union t_union${ws}\\*" \
478 "(union t_union const *)"
479 gdb_test "whatis (struct t_struct * const) &v_struct1" \
480 "type = struct t_struct${ws}\\*${ws}const" \
481 "(struct t_struct * const)"
482 gdb_test "whatis (union t_union * const) &v_union" \
483 "type = union t_union${ws}\\*${ws}const" \
484 "(union t_union * const)"
485 gdb_test "whatis (const struct t_struct * const) &v_struct1" \
486 "type = const struct t_struct${ws}\\*${ws}const" \
487 "(const struct t_struct * const)"
488 gdb_test "whatis (const union t_union * const) &v_union" \
489 "type = const union t_union${ws}\\*${ws}const" \
490 "(const union t_union * const)"
491 gdb_test "whatis (struct t_struct const * const) &v_struct1" \
492 "type = const struct t_struct${ws}\\*${ws}const" \
493 "(struct t_struct const * const)"
494 gdb_test "whatis (union t_union const * const) &v_union" \
495 "type = const union t_union${ws}\\*${ws}const" \
496 "(union t_union const * const)"
499 # Function pointers TODO