gdb/doc/
[binutils-gdb.git] / gdb / testsuite / gdb.base / cvexpr.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 const and volatile keywords.
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 cvexpr.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 (const char) v_char" \
55 "type = const char" \
56 "(const char)"
57 gdb_test "whatis (const signed char) v_signed_char" \
58 "type = const signed char" \
59 "(const signed char)"
60 gdb_test "whatis (const unsigned char) v_unsigned_char" \
61 "type = const (unsigned char|char)" \
62 "(const unsigned char)"
63 gdb_test "whatis (const short) v_short" \
64 "type = const (short|short int)" \
65 "(const short)"
66 gdb_test "whatis (const signed short) v_signed_short" \
67 "type = const (short|short int|signed short|signed short int)" \
68 "(const signed short)"
69 gdb_test "whatis (const unsigned short) v_unsigned_short" \
70 "type = const (unsigned short|short unsigned int)" \
71 "(const unsigned short)"
72 gdb_test "whatis (const int) v_int" \
73 "type = const int" \
74 "(const int)"
75 gdb_test "whatis (const signed int) v_signed_int" \
76 "type = const (signed int|int)" \
77 "(const signed int)"
78 gdb_test "whatis (const unsigned int) v_unsigned_int" \
79 "type = const unsigned int" \
80 "(const unsigned int)"
81 gdb_test "whatis (const long) v_long" \
82 "type = const (long|long int)" \
83 "(const long)"
84 gdb_test "whatis (const signed long) v_signed_long" \
85 "type = const (signed |)long( int|)" \
86 "(const signed long)"
87 gdb_test "whatis (const unsigned long) v_unsigned_long" \
88 "type = const (unsigned long|long unsigned int)" \
89 "(const unsigned long)"
90 gdb_test "whatis (const long long) v_long_long" \
91 "type = const long long( int|)" \
92 "(const long long)"
93 gdb_test "whatis (const signed long long) v_signed_long_long" \
94 "type = const (signed |)long long( int|)" \
95 "(const signed long long)"
96 gdb_test "whatis (const unsigned long long) v_unsigned_long_long" \
97 "type = const (unsigned long long|long long unsigned int)" \
98 "(const unsigned long long)"
99 gdb_test "whatis (const float) v_float" \
100 "type = const float" \
101 "(const float)"
102 gdb_test "whatis (const double) v_double" \
103 "type = const double" \
104 "(const double)"
105
106 #
107 # Test casting a scalar to volatile
108 #
109
110 gdb_test "whatis (volatile char) v_char" \
111 "type = volatile char" \
112 "(volatile char)"
113 gdb_test "whatis (volatile signed char) v_signed_char" \
114 "type = volatile signed char" \
115 "(volatile signed char)"
116 gdb_test "whatis (volatile unsigned char) v_unsigned_char" \
117 "type = volatile (unsigned char|char)" \
118 "(volatile unsigned char)"
119 gdb_test "whatis (volatile short) v_short" \
120 "type = volatile (short|short int)" \
121 "(volatile short)"
122 gdb_test "whatis (volatile signed short) v_signed_short" \
123 "type = volatile (short|short int|signed short|signed short int)" \
124 "(volatile signed short)"
125 gdb_test "whatis (volatile unsigned short) v_unsigned_short" \
126 "type = volatile (unsigned short|short unsigned int)" \
127 "(volatile unsigned short)"
128 gdb_test "whatis (volatile int) v_int" \
129 "type = volatile int" \
130 "(volatile int)"
131 gdb_test "whatis (volatile signed int) v_signed_int" \
132 "type = volatile (signed int|int)" \
133 "(volatile signed int)"
134 gdb_test "whatis (volatile unsigned int) v_unsigned_int" \
135 "type = volatile unsigned int" \
136 "(volatile unsigned int)"
137 gdb_test "whatis (volatile long) v_long" \
138 "type = volatile (long|long int)" \
139 "(volatile long)"
140 gdb_test "whatis (volatile signed long) v_signed_long" \
141 "type = volatile (signed |)long( int|)" \
142 "(volatile signed long)"
143 gdb_test "whatis (volatile unsigned long) v_unsigned_long" \
144 "type = volatile (unsigned long|long unsigned int)" \
145 "(volatile unsigned long)"
146 gdb_test "whatis (volatile long long) v_long_long" \
147 "type = volatile long long( int|)" \
148 "(volatile long long)"
149 gdb_test "whatis (volatile signed long long) v_signed_long_long" \
150 "type = volatile (signed |)long long( int|)" \
151 "(volatile signed long long)"
152 gdb_test "whatis (volatile unsigned long long) v_unsigned_long_long" \
153 "type = volatile (unsigned long long|long long unsigned int)" \
154 "(volatile unsigned long long)"
155 gdb_test "whatis (volatile float) v_float" \
156 "type = volatile float" \
157 "(volatile float)"
158 gdb_test "whatis (volatile double) v_double" \
159 "type = volatile double" \
160 "(volatile double)"
161
162 #
163 # Combine const and volatile
164 #
165
166 gdb_test "whatis (const volatile int) v_int" \
167 "type = const volatile int" \
168 "(const volatile int)"
169 gdb_test "whatis (volatile const int) v_int" \
170 "type = const volatile int" \
171 "(volatile const int)"
172 gdb_test "whatis (const int volatile) v_int" \
173 "type = const volatile int" \
174 "(const int volatile)"
175 gdb_test "whatis (volatile int const) v_int" \
176 "type = const volatile int" \
177 "(volatile int const)"
178 gdb_test "whatis (int const volatile) v_int" \
179 "type = const volatile int" \
180 "(int const volatile)"
181 gdb_test "whatis (int volatile const) v_int" \
182 "type = const volatile int" \
183 "(int volatile const)"
184
185 gdb_test "whatis (const volatile int *) v_int_pointer" \
186 "type = const volatile int${ws}\\*" \
187 "(const volatile int *)"
188 gdb_test "whatis (volatile const int *) v_int_pointer" \
189 "type = const volatile int${ws}\\*" \
190 "(volatile const int *)"
191 gdb_test "whatis (const int volatile *) v_int_pointer" \
192 "type = const volatile int${ws}\\*" \
193 "(const int volatile)"
194 gdb_test "whatis (volatile int const *) v_int_pointer" \
195 "type = const volatile int${ws}\\*" \
196 "(volatile int const *)"
197 gdb_test "whatis (int const volatile *) v_int_pointer" \
198 "type = const volatile int${ws}\\*" \
199 "(int const volatile *)"
200 gdb_test "whatis (int volatile const *) v_int_pointer" \
201 "type = const volatile int${ws}\\*" \
202 "(int volatile const *)"
203 gdb_test "whatis (int * const volatile) v_int_pointer" \
204 "type = int${ws}\\*${ws}const volatile" \
205 "(int * const volatile)"
206 gdb_test "whatis (int * volatile const) v_int_pointer" \
207 "type = int${ws}\\*${ws}const volatile" \
208 "(int * volatile const)"
209
210
211 #
212 # Put 'signed' and 'unsigned' before const/volatile (FIXME)
213 #
214
215 #gdb_test "whatis (signed const char) v_signed_char" \
216 # "type = const char" \
217 # "(signed const char)"
218 #gdb_test "whatis (unsigned const char) v_unsigned_char" \
219 # "type = const (unsigned char|char)" \
220 # "(unsigned const char)"
221 #gdb_test "whatis (signed const short) v_signed_short" \
222 # "type = const (short|short int|signed short|signed short int)" \
223 # "(signed const short)"
224 #gdb_test "whatis (unsigned const short) v_unsigned_short" \
225 # "type = const (unsigned short|short unsigned int)" \
226 # "(unsigned const short)"
227 #gdb_test "whatis (signed const int) v_signed_int" \
228 # "type = const (signed int|int)" \
229 # "(signed const int)"
230 #gdb_test "whatis (unsigned const int) v_unsigned_int" \
231 # "type = const unsigned int" \
232 # "(unsigned const int)"
233 #gdb_test "whatis (signed const long) v_signed_long" \
234 # "type = const (signed |)long( int|)" \
235 # "(signed const long)"
236 #gdb_test "whatis (unsigned const long) v_unsigned_long" \
237 # "type = const (unsigned long|long unsigned int)" \
238 # "(unsigned const long)"
239 #gdb_test "whatis (signed const long long) v_signed_long_long" \
240 # "type = const (signed |)long long( int|)" \
241 # "(signed const long long)"
242 #gdb_test "whatis (unsigned const long long) v_unsigned_long_long" \
243 # "type = const (unsigned long long|long long unsigned int)" \
244 # "(const unsigned long long)"
245
246 #gdb_test "whatis (signed volatile char) v_signed_char" \
247 # "type = volatile char" \
248 # "(signed volatile char)"
249 #gdb_test "whatis (unsigned volatile char) v_unsigned_char" \
250 # "type = volatile (unsigned char|char)" \
251 # "(unsigned volatile char)"
252 #gdb_test "whatis (signed volatile short) v_signed_short" \
253 # "type = volatile (short|short int|signed short|signed short int)" \
254 # "(signed volatile short)"
255 #gdb_test "whatis (unsigned volatile short) v_unsigned_short" \
256 # "type = volatile (unsigned short|short unsigned int)" \
257 # "(unsigned volatile short)"
258 #gdb_test "whatis (signed volatile int) v_signed_int" \
259 # "type = volatile (signed int|int)" \
260 # "(signed volatile int)"
261 #gdb_test "whatis (unsigned volatile int) v_unsigned_int" \
262 # "type = volatile unsigned int" \
263 # "(unsigned volatile int)"
264 #gdb_test "whatis (signed volatile long) v_signed_long" \
265 # "type = volatile (signed |)long( int|)" \
266 # "(signed volatile long)"
267 #gdb_test "whatis (unsigned volatile long) v_unsigned_long" \
268 # "type = volatile (unsigned long|long unsigned int)" \
269 # "(unsigned volatile long)"
270 #gdb_test "whatis (signed volatile long long) v_signed_long_long" \
271 # "type = volatile (signed |)long long( int|)" \
272 # "(signed volatile long long)"
273 #gdb_test "whatis (unsigned volatile long long) v_unsigned_long_long" \
274 # "type = volatile (unsigned long long|long long unsigned int)" \
275 # "(unsigned volatile long long)"
276
277 #
278 # Now put the 'const' and 'volatile' keywords after the base type.
279 #
280
281 gdb_test "whatis (char const) v_char" \
282 "type = const char" \
283 "(char const)"
284 gdb_test "whatis (signed char const) v_signed_char" \
285 "type = const signed char" \
286 "(signed char const)"
287 gdb_test "whatis (unsigned char const) v_unsigned_char" \
288 "type = const (unsigned char|char)" \
289 "(unsigned char const)"
290 gdb_test "whatis (short const) v_short" \
291 "type = const (short|short int)" \
292 "(short const)"
293 gdb_test "whatis (signed short const) v_signed_short" \
294 "type = const (short|short int|signed short|signed short int)" \
295 "(signed short const)"
296 gdb_test "whatis (unsigned short const) v_unsigned_short" \
297 "type = const (unsigned short|short unsigned int)" \
298 "(unsigned short const)"
299 gdb_test "whatis (int const) v_int" \
300 "type = const int" \
301 "(int const)"
302 gdb_test "whatis (signed int const) v_signed_int" \
303 "type = const (signed int|int)" \
304 "(signed int const)"
305 gdb_test "whatis (unsigned int const) v_unsigned_int" \
306 "type = const unsigned int" \
307 "(unsigned int const)"
308 gdb_test "whatis (long const) v_long" \
309 "type = const (long|long int)" \
310 "(long const)"
311 gdb_test "whatis (signed long const) v_signed_long" \
312 "type = const (signed |)long( int|)" \
313 "(signed long const)"
314 gdb_test "whatis (unsigned long const) v_unsigned_long" \
315 "type = const (unsigned long|long unsigned int)" \
316 "(unsigned long const)"
317 gdb_test "whatis (long long const) v_long_long" \
318 "type = const long long( int|)" \
319 "(long long const)"
320 gdb_test "whatis (signed long long const) v_signed_long_long" \
321 "type = const (signed |)long long( int|)" \
322 "(signed long long const)"
323 gdb_test "whatis (unsigned long long const) v_unsigned_long_long" \
324 "type = const (unsigned long long|long long unsigned int)" \
325 "(unsigned long long const)"
326 gdb_test "whatis (float const) v_float" \
327 "type = const float" \
328 "(float const)"
329 gdb_test "whatis (double const) v_double" \
330 "type = const double" \
331 "(double const)"
332
333 gdb_test "whatis (char volatile) v_char" \
334 "type = volatile char" \
335 "(char volatile)"
336 gdb_test "whatis (signed char volatile) v_signed_char" \
337 "type = volatile signed char" \
338 "(signed char volatile)"
339 gdb_test "whatis (unsigned char volatile) v_unsigned_char" \
340 "type = volatile (unsigned char|char)" \
341 "(unsigned char volatile)"
342 gdb_test "whatis (short volatile) v_short" \
343 "type = volatile (short|short int)" \
344 "(short volatile)"
345 gdb_test "whatis (signed short volatile) v_signed_short" \
346 "type = volatile (short|short int|signed short|signed short int)" \
347 "(signed short volatile)"
348 gdb_test "whatis (unsigned short volatile) v_unsigned_short" \
349 "type = volatile (unsigned short|short unsigned int)" \
350 "(unsigned short volatile)"
351 gdb_test "whatis (int volatile) v_int" \
352 "type = volatile int" \
353 "(int volatile)"
354 gdb_test "whatis (signed int volatile) v_signed_int" \
355 "type = volatile (signed int|int)" \
356 "(signed int volatile)"
357 gdb_test "whatis (unsigned int volatile) v_unsigned_int" \
358 "type = volatile unsigned int" \
359 "(unsigned int volatile)"
360 gdb_test "whatis (long volatile) v_long" \
361 "type = volatile (long|long int)" \
362 "(long volatile)"
363 gdb_test "whatis (signed long volatile) v_signed_long" \
364 "type = volatile (signed |)long( int|)" \
365 "(signed long volatile)"
366 gdb_test "whatis (unsigned long volatile) v_unsigned_long" \
367 "type = volatile (unsigned long|long unsigned int)" \
368 "(unsigned long volatile)"
369 gdb_test "whatis (long long volatile) v_long_long" \
370 "type = volatile long long( int|)" \
371 "(long long volatile)"
372 gdb_test "whatis (signed long long volatile) v_signed_long_long" \
373 "type = volatile (signed |)long long( int|)" \
374 "(signed long long volatile)"
375 gdb_test "whatis (unsigned long long volatile) v_unsigned_long_long" \
376 "type = volatile (unsigned long long|long long unsigned int)" \
377 "(unsigned long long volatile)"
378 gdb_test "whatis (float volatile) v_float" \
379 "type = volatile float" \
380 "(float volatile)"
381 gdb_test "whatis (double volatile) v_double" \
382 "type = volatile double" \
383 "(double volatile)"
384
385 #
386 # enums
387 #
388
389 gdb_test "whatis (const enum misordered) v_misordered" \
390 "type = const enum misordered" \
391 "(const enum misordered)"
392 gdb_test "whatis (enum misordered const) v_misordered" \
393 "type = const enum misordered" \
394 "(enum misordered const)"
395 gdb_test "whatis (volatile enum misordered) v_misordered" \
396 "type = volatile enum misordered" \
397 "(volatile enum misordered)"
398 gdb_test "whatis (enum misordered volatile) v_misordered" \
399 "type = volatile enum misordered" \
400 "(enum misordered volatile)"
401
402 #
403 # Pointers
404 #
405
406 gdb_test "whatis (const int *) v_int_pointer" \
407 "type = const int${ws}\\*" \
408 "(const int *)"
409 gdb_test "whatis (int const *) v_int_pointer" \
410 "type = const int${ws}\\*" \
411 "(int const *)"
412 gdb_test "whatis (int * const) v_int_pointer" \
413 "type = int \\*${ws}const" \
414 "(int * const)"
415 gdb_test "whatis (const int * const) v_int_pointer" \
416 "type = const int${ws}\\*${ws}const" \
417 "(const int * const)"
418 gdb_test "whatis (int const * const) v_int_pointer" \
419 "type = const int${ws}\\*${ws}const" \
420 "(int const * const)"
421
422 gdb_test "whatis (const int **) v_int_pointer_pointer" \
423 "type = const int${ws}\\*${ws}\\*" \
424 "(const int **)"
425 gdb_test "whatis (int const **) v_int_pointer_pointer" \
426 "type = const int${ws}\\*${ws}\\*" \
427 "(int const **)"
428 gdb_test "whatis (int ** const) v_int_pointer_pointer" \
429 "type = int \\*${ws}\\*${ws}const" \
430 "(int ** const)"
431 gdb_test "whatis (const int * const *) v_int_pointer_pointer" \
432 "type = const int${ws}\\*${ws}const${ws}\\*" \
433 "(const int * const *)"
434 gdb_test "whatis (int const * const *) v_int_pointer_pointer" \
435 "type = const int${ws}\\*${ws}const${ws}\\*" \
436 "(int const * const *)"
437 gdb_test "whatis (const int * const * const) v_int_pointer_pointer" \
438 "type = const int${ws}\\*${ws}const${ws}\\*${ws}const" \
439 "(const int * const * const)"
440 gdb_test "whatis (int const * const * const) v_int_pointer_pointer" \
441 "type = const int${ws}\\*${ws}const${ws}\\*${ws}const" \
442 "(int const * const * const)"
443
444 #
445 # Arrays TODO
446 #
447
448 #
449 # Pointers to arrays, arrays of pointers TODO
450 #
451
452 #
453 # Structs and Unions
454 #
455
456 gdb_test "whatis (const struct t_struct) v_struct1" \
457 "type = const struct t_struct" \
458 "(const struct t_struct)"
459 gdb_test "whatis (const union t_union) v_union" \
460 "type = const union t_union" \
461 "(const union t_union)"
462 gdb_test "whatis (struct t_struct const) v_struct1" \
463 "type = const struct t_struct" \
464 "(struct t_struct const)"
465 gdb_test "whatis (union t_union const) v_union" \
466 "type = const union t_union" \
467 "(union t_union const)"
468 gdb_test "whatis (const struct t_struct *) &v_struct1" \
469 "type = const struct t_struct${ws}\\*" \
470 "(const struct t_struct *)"
471 gdb_test "whatis (const union t_union *) &v_union" \
472 "type = const union t_union${ws}\\*" \
473 "(const union t_union *)"
474 gdb_test "whatis (struct t_struct const *) &v_struct1" \
475 "type = const struct t_struct${ws}\\*" \
476 "(struct t_struct const *)"
477 gdb_test "whatis (union t_union const *) &v_union" \
478 "type = const union t_union${ws}\\*" \
479 "(union t_union const *)"
480 gdb_test "whatis (struct t_struct * const) &v_struct1" \
481 "type = struct t_struct${ws}\\*${ws}const" \
482 "(struct t_struct * const)"
483 gdb_test "whatis (union t_union * const) &v_union" \
484 "type = union t_union${ws}\\*${ws}const" \
485 "(union t_union * const)"
486 gdb_test "whatis (const struct t_struct * const) &v_struct1" \
487 "type = const struct t_struct${ws}\\*${ws}const" \
488 "(const struct t_struct * const)"
489 gdb_test "whatis (const union t_union * const) &v_union" \
490 "type = const union t_union${ws}\\*${ws}const" \
491 "(const union t_union * const)"
492 gdb_test "whatis (struct t_struct const * const) &v_struct1" \
493 "type = const struct t_struct${ws}\\*${ws}const" \
494 "(struct t_struct const * const)"
495 gdb_test "whatis (union t_union const * const) &v_union" \
496 "type = const union t_union${ws}\\*${ws}const" \
497 "(union t_union const * const)"
498
499 #
500 # Function pointers TODO
501 #
502