1 # Copyright (C) 2001, 2007, 2008, 2009, 2010 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 if [target_info exists gdb_stub] {
47 gdb_test_no_output "set print sevenbit-strings"
48 gdb_test_no_output "set print address off"
49 gdb_test_no_output "set width 0"
54 # Test casting a scalar to const
57 gdb_test "whatis (const char) v_char" \
60 gdb_test "whatis (const signed char) v_signed_char" \
61 "type = const signed char" \
63 gdb_test "whatis (const unsigned char) v_unsigned_char" \
64 "type = const (unsigned char|char)" \
65 "(const unsigned char)"
66 gdb_test "whatis (const short) v_short" \
67 "type = const (short|short int)" \
69 gdb_test "whatis (const signed short) v_signed_short" \
70 "type = const (short|short int|signed short|signed short int)" \
71 "(const signed short)"
72 gdb_test "whatis (const unsigned short) v_unsigned_short" \
73 "type = const (unsigned short|short unsigned int)" \
74 "(const unsigned short)"
75 gdb_test "whatis (const int) v_int" \
78 gdb_test "whatis (const signed int) v_signed_int" \
79 "type = const (signed int|int)" \
81 gdb_test "whatis (const unsigned int) v_unsigned_int" \
82 "type = const unsigned int" \
83 "(const unsigned int)"
84 gdb_test "whatis (const long) v_long" \
85 "type = const (long|long int)" \
87 gdb_test "whatis (const signed long) v_signed_long" \
88 "type = const (signed |)long( int|)" \
90 gdb_test "whatis (const unsigned long) v_unsigned_long" \
91 "type = const (unsigned long|long unsigned int)" \
92 "(const unsigned long)"
93 gdb_test "whatis (const long long) v_long_long" \
94 "type = const long long( int|)" \
96 gdb_test "whatis (const signed long long) v_signed_long_long" \
97 "type = const (signed |)long long( int|)" \
98 "(const signed long long)"
99 gdb_test "whatis (const unsigned long long) v_unsigned_long_long" \
100 "type = const (unsigned long long|long long unsigned int)" \
101 "(const unsigned long long)"
102 gdb_test "whatis (const float) v_float" \
103 "type = const float" \
105 gdb_test "whatis (const double) v_double" \
106 "type = const double" \
110 # Test casting a scalar to volatile
113 gdb_test "whatis (volatile char) v_char" \
114 "type = volatile char" \
116 gdb_test "whatis (volatile signed char) v_signed_char" \
117 "type = volatile signed char" \
118 "(volatile signed char)"
119 gdb_test "whatis (volatile unsigned char) v_unsigned_char" \
120 "type = volatile (unsigned char|char)" \
121 "(volatile unsigned char)"
122 gdb_test "whatis (volatile short) v_short" \
123 "type = volatile (short|short int)" \
125 gdb_test "whatis (volatile signed short) v_signed_short" \
126 "type = volatile (short|short int|signed short|signed short int)" \
127 "(volatile signed short)"
128 gdb_test "whatis (volatile unsigned short) v_unsigned_short" \
129 "type = volatile (unsigned short|short unsigned int)" \
130 "(volatile unsigned short)"
131 gdb_test "whatis (volatile int) v_int" \
132 "type = volatile int" \
134 gdb_test "whatis (volatile signed int) v_signed_int" \
135 "type = volatile (signed int|int)" \
136 "(volatile signed int)"
137 gdb_test "whatis (volatile unsigned int) v_unsigned_int" \
138 "type = volatile unsigned int" \
139 "(volatile unsigned int)"
140 gdb_test "whatis (volatile long) v_long" \
141 "type = volatile (long|long int)" \
143 gdb_test "whatis (volatile signed long) v_signed_long" \
144 "type = volatile (signed |)long( int|)" \
145 "(volatile signed long)"
146 gdb_test "whatis (volatile unsigned long) v_unsigned_long" \
147 "type = volatile (unsigned long|long unsigned int)" \
148 "(volatile unsigned long)"
149 gdb_test "whatis (volatile long long) v_long_long" \
150 "type = volatile long long( int|)" \
151 "(volatile long long)"
152 gdb_test "whatis (volatile signed long long) v_signed_long_long" \
153 "type = volatile (signed |)long long( int|)" \
154 "(volatile signed long long)"
155 gdb_test "whatis (volatile unsigned long long) v_unsigned_long_long" \
156 "type = volatile (unsigned long long|long long unsigned int)" \
157 "(volatile unsigned long long)"
158 gdb_test "whatis (volatile float) v_float" \
159 "type = volatile float" \
161 gdb_test "whatis (volatile double) v_double" \
162 "type = volatile double" \
166 # Combine const and volatile
169 gdb_test "whatis (const volatile int) v_int" \
170 "type = const volatile int" \
171 "(const volatile int)"
172 gdb_test "whatis (volatile const int) v_int" \
173 "type = const volatile int" \
174 "(volatile const int)"
175 gdb_test "whatis (const int volatile) v_int" \
176 "type = const volatile int" \
177 "(const int volatile)"
178 gdb_test "whatis (volatile int const) v_int" \
179 "type = const volatile int" \
180 "(volatile int const)"
181 gdb_test "whatis (int const volatile) v_int" \
182 "type = const volatile int" \
183 "(int const volatile)"
184 gdb_test "whatis (int volatile const) v_int" \
185 "type = const volatile int" \
186 "(int volatile const)"
188 gdb_test "whatis (const volatile int *) v_int_pointer" \
189 "type = const volatile int${ws}\\*" \
190 "(const volatile int *)"
191 gdb_test "whatis (volatile const int *) v_int_pointer" \
192 "type = const volatile int${ws}\\*" \
193 "(volatile const int *)"
194 gdb_test "whatis (const int volatile *) v_int_pointer" \
195 "type = const volatile int${ws}\\*" \
196 "(const int volatile)"
197 gdb_test "whatis (volatile int const *) v_int_pointer" \
198 "type = const volatile int${ws}\\*" \
199 "(volatile int const *)"
200 gdb_test "whatis (int const volatile *) v_int_pointer" \
201 "type = const volatile int${ws}\\*" \
202 "(int const volatile *)"
203 gdb_test "whatis (int volatile const *) v_int_pointer" \
204 "type = const volatile int${ws}\\*" \
205 "(int volatile const *)"
206 gdb_test "whatis (int * const volatile) v_int_pointer" \
207 "type = int${ws}\\*${ws}const volatile" \
208 "(int * const volatile)"
209 gdb_test "whatis (int * volatile const) v_int_pointer" \
210 "type = int${ws}\\*${ws}const volatile" \
211 "(int * volatile const)"
215 # Put 'signed' and 'unsigned' before const/volatile (FIXME)
218 #gdb_test "whatis (signed const char) v_signed_char" \
219 # "type = const char" \
220 # "(signed const char)"
221 #gdb_test "whatis (unsigned const char) v_unsigned_char" \
222 # "type = const (unsigned char|char)" \
223 # "(unsigned const char)"
224 #gdb_test "whatis (signed const short) v_signed_short" \
225 # "type = const (short|short int|signed short|signed short int)" \
226 # "(signed const short)"
227 #gdb_test "whatis (unsigned const short) v_unsigned_short" \
228 # "type = const (unsigned short|short unsigned int)" \
229 # "(unsigned const short)"
230 #gdb_test "whatis (signed const int) v_signed_int" \
231 # "type = const (signed int|int)" \
232 # "(signed const int)"
233 #gdb_test "whatis (unsigned const int) v_unsigned_int" \
234 # "type = const unsigned int" \
235 # "(unsigned const int)"
236 #gdb_test "whatis (signed const long) v_signed_long" \
237 # "type = const (signed |)long( int|)" \
238 # "(signed const long)"
239 #gdb_test "whatis (unsigned const long) v_unsigned_long" \
240 # "type = const (unsigned long|long unsigned int)" \
241 # "(unsigned const long)"
242 #gdb_test "whatis (signed const long long) v_signed_long_long" \
243 # "type = const (signed |)long long( int|)" \
244 # "(signed const long long)"
245 #gdb_test "whatis (unsigned const long long) v_unsigned_long_long" \
246 # "type = const (unsigned long long|long long unsigned int)" \
247 # "(const unsigned long long)"
249 #gdb_test "whatis (signed volatile char) v_signed_char" \
250 # "type = volatile char" \
251 # "(signed volatile char)"
252 #gdb_test "whatis (unsigned volatile char) v_unsigned_char" \
253 # "type = volatile (unsigned char|char)" \
254 # "(unsigned volatile char)"
255 #gdb_test "whatis (signed volatile short) v_signed_short" \
256 # "type = volatile (short|short int|signed short|signed short int)" \
257 # "(signed volatile short)"
258 #gdb_test "whatis (unsigned volatile short) v_unsigned_short" \
259 # "type = volatile (unsigned short|short unsigned int)" \
260 # "(unsigned volatile short)"
261 #gdb_test "whatis (signed volatile int) v_signed_int" \
262 # "type = volatile (signed int|int)" \
263 # "(signed volatile int)"
264 #gdb_test "whatis (unsigned volatile int) v_unsigned_int" \
265 # "type = volatile unsigned int" \
266 # "(unsigned volatile int)"
267 #gdb_test "whatis (signed volatile long) v_signed_long" \
268 # "type = volatile (signed |)long( int|)" \
269 # "(signed volatile long)"
270 #gdb_test "whatis (unsigned volatile long) v_unsigned_long" \
271 # "type = volatile (unsigned long|long unsigned int)" \
272 # "(unsigned volatile long)"
273 #gdb_test "whatis (signed volatile long long) v_signed_long_long" \
274 # "type = volatile (signed |)long long( int|)" \
275 # "(signed volatile long long)"
276 #gdb_test "whatis (unsigned volatile long long) v_unsigned_long_long" \
277 # "type = volatile (unsigned long long|long long unsigned int)" \
278 # "(unsigned volatile long long)"
281 # Now put the 'const' and 'volatile' keywords after the base type.
284 gdb_test "whatis (char const) v_char" \
285 "type = const char" \
287 gdb_test "whatis (signed char const) v_signed_char" \
288 "type = const signed char" \
289 "(signed char const)"
290 gdb_test "whatis (unsigned char const) v_unsigned_char" \
291 "type = const (unsigned char|char)" \
292 "(unsigned char const)"
293 gdb_test "whatis (short const) v_short" \
294 "type = const (short|short int)" \
296 gdb_test "whatis (signed short const) v_signed_short" \
297 "type = const (short|short int|signed short|signed short int)" \
298 "(signed short const)"
299 gdb_test "whatis (unsigned short const) v_unsigned_short" \
300 "type = const (unsigned short|short unsigned int)" \
301 "(unsigned short const)"
302 gdb_test "whatis (int const) v_int" \
305 gdb_test "whatis (signed int const) v_signed_int" \
306 "type = const (signed int|int)" \
308 gdb_test "whatis (unsigned int const) v_unsigned_int" \
309 "type = const unsigned int" \
310 "(unsigned int const)"
311 gdb_test "whatis (long const) v_long" \
312 "type = const (long|long int)" \
314 gdb_test "whatis (signed long const) v_signed_long" \
315 "type = const (signed |)long( int|)" \
316 "(signed long const)"
317 gdb_test "whatis (unsigned long const) v_unsigned_long" \
318 "type = const (unsigned long|long unsigned int)" \
319 "(unsigned long const)"
320 gdb_test "whatis (long long const) v_long_long" \
321 "type = const long long( int|)" \
323 gdb_test "whatis (signed long long const) v_signed_long_long" \
324 "type = const (signed |)long long( int|)" \
325 "(signed long long const)"
326 gdb_test "whatis (unsigned long long const) v_unsigned_long_long" \
327 "type = const (unsigned long long|long long unsigned int)" \
328 "(unsigned long long const)"
329 gdb_test "whatis (float const) v_float" \
330 "type = const float" \
332 gdb_test "whatis (double const) v_double" \
333 "type = const double" \
336 gdb_test "whatis (char volatile) v_char" \
337 "type = volatile char" \
339 gdb_test "whatis (signed char volatile) v_signed_char" \
340 "type = volatile signed char" \
341 "(signed char volatile)"
342 gdb_test "whatis (unsigned char volatile) v_unsigned_char" \
343 "type = volatile (unsigned char|char)" \
344 "(unsigned char volatile)"
345 gdb_test "whatis (short volatile) v_short" \
346 "type = volatile (short|short int)" \
348 gdb_test "whatis (signed short volatile) v_signed_short" \
349 "type = volatile (short|short int|signed short|signed short int)" \
350 "(signed short volatile)"
351 gdb_test "whatis (unsigned short volatile) v_unsigned_short" \
352 "type = volatile (unsigned short|short unsigned int)" \
353 "(unsigned short volatile)"
354 gdb_test "whatis (int volatile) v_int" \
355 "type = volatile int" \
357 gdb_test "whatis (signed int volatile) v_signed_int" \
358 "type = volatile (signed int|int)" \
359 "(signed int volatile)"
360 gdb_test "whatis (unsigned int volatile) v_unsigned_int" \
361 "type = volatile unsigned int" \
362 "(unsigned int volatile)"
363 gdb_test "whatis (long volatile) v_long" \
364 "type = volatile (long|long int)" \
366 gdb_test "whatis (signed long volatile) v_signed_long" \
367 "type = volatile (signed |)long( int|)" \
368 "(signed long volatile)"
369 gdb_test "whatis (unsigned long volatile) v_unsigned_long" \
370 "type = volatile (unsigned long|long unsigned int)" \
371 "(unsigned long volatile)"
372 gdb_test "whatis (long long volatile) v_long_long" \
373 "type = volatile long long( int|)" \
374 "(long long volatile)"
375 gdb_test "whatis (signed long long volatile) v_signed_long_long" \
376 "type = volatile (signed |)long long( int|)" \
377 "(signed long long volatile)"
378 gdb_test "whatis (unsigned long long volatile) v_unsigned_long_long" \
379 "type = volatile (unsigned long long|long long unsigned int)" \
380 "(unsigned long long volatile)"
381 gdb_test "whatis (float volatile) v_float" \
382 "type = volatile float" \
384 gdb_test "whatis (double volatile) v_double" \
385 "type = volatile double" \
392 gdb_test "whatis (const enum misordered) v_misordered" \
393 "type = const enum misordered" \
394 "(const enum misordered)"
395 gdb_test "whatis (enum misordered const) v_misordered" \
396 "type = const enum misordered" \
397 "(enum misordered const)"
398 gdb_test "whatis (volatile enum misordered) v_misordered" \
399 "type = volatile enum misordered" \
400 "(volatile enum misordered)"
401 gdb_test "whatis (enum misordered volatile) v_misordered" \
402 "type = volatile enum misordered" \
403 "(enum misordered volatile)"
409 gdb_test "whatis (const int *) v_int_pointer" \
410 "type = const int${ws}\\*" \
412 gdb_test "whatis (int const *) v_int_pointer" \
413 "type = const int${ws}\\*" \
415 gdb_test "whatis (int * const) v_int_pointer" \
416 "type = int \\*${ws}const" \
418 gdb_test "whatis (const int * const) v_int_pointer" \
419 "type = const int${ws}\\*${ws}const" \
420 "(const int * const)"
421 gdb_test "whatis (int const * const) v_int_pointer" \
422 "type = const int${ws}\\*${ws}const" \
423 "(int const * const)"
425 gdb_test "whatis (const int **) v_int_pointer_pointer" \
426 "type = const int${ws}\\*${ws}\\*" \
428 gdb_test "whatis (int const **) v_int_pointer_pointer" \
429 "type = const int${ws}\\*${ws}\\*" \
431 gdb_test "whatis (int ** const) v_int_pointer_pointer" \
432 "type = int \\*${ws}\\*${ws}const" \
434 gdb_test "whatis (const int * const *) v_int_pointer_pointer" \
435 "type = const int${ws}\\*${ws}const${ws}\\*" \
436 "(const int * const *)"
437 gdb_test "whatis (int const * const *) v_int_pointer_pointer" \
438 "type = const int${ws}\\*${ws}const${ws}\\*" \
439 "(int const * const *)"
440 gdb_test "whatis (const int * const * const) v_int_pointer_pointer" \
441 "type = const int${ws}\\*${ws}const${ws}\\*${ws}const" \
442 "(const int * const * const)"
443 gdb_test "whatis (int const * const * const) v_int_pointer_pointer" \
444 "type = const int${ws}\\*${ws}const${ws}\\*${ws}const" \
445 "(int const * const * const)"
452 # Pointers to arrays, arrays of pointers TODO
459 gdb_test "whatis (const struct t_struct) v_struct1" \
460 "type = const struct t_struct" \
461 "(const struct t_struct)"
462 gdb_test "whatis (const union t_union) v_union" \
463 "type = const union t_union" \
464 "(const union t_union)"
465 gdb_test "whatis (struct t_struct const) v_struct1" \
466 "type = const struct t_struct" \
467 "(struct t_struct const)"
468 gdb_test "whatis (union t_union const) v_union" \
469 "type = const union t_union" \
470 "(union t_union const)"
471 gdb_test "whatis (const struct t_struct *) &v_struct1" \
472 "type = const struct t_struct${ws}\\*" \
473 "(const struct t_struct *)"
474 gdb_test "whatis (const union t_union *) &v_union" \
475 "type = const union t_union${ws}\\*" \
476 "(const union t_union *)"
477 gdb_test "whatis (struct t_struct const *) &v_struct1" \
478 "type = const struct t_struct${ws}\\*" \
479 "(struct t_struct const *)"
480 gdb_test "whatis (union t_union const *) &v_union" \
481 "type = const union t_union${ws}\\*" \
482 "(union t_union const *)"
483 gdb_test "whatis (struct t_struct * const) &v_struct1" \
484 "type = struct t_struct${ws}\\*${ws}const" \
485 "(struct t_struct * const)"
486 gdb_test "whatis (union t_union * const) &v_union" \
487 "type = union t_union${ws}\\*${ws}const" \
488 "(union t_union * const)"
489 gdb_test "whatis (const struct t_struct * const) &v_struct1" \
490 "type = const struct t_struct${ws}\\*${ws}const" \
491 "(const struct t_struct * const)"
492 gdb_test "whatis (const union t_union * const) &v_union" \
493 "type = const union t_union${ws}\\*${ws}const" \
494 "(const union t_union * const)"
495 gdb_test "whatis (struct t_struct const * const) &v_struct1" \
496 "type = const struct t_struct${ws}\\*${ws}const" \
497 "(struct t_struct const * const)"
498 gdb_test "whatis (union t_union const * const) &v_union" \
499 "type = const union t_union${ws}\\*${ws}const" \
500 "(union t_union const * const)"
503 # Function pointers TODO