]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/cvexpr.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / cvexpr.exp
1 # Copyright (C) 2001-2024 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # Written by Michael Snyder, Red Hat, Inc., 9/20/2001
17
18 # This file is part of the gdb testsuite
19 # Tests for type expressions using const and volatile keywords.
20
21 standard_testfile .c
22
23 # Compile the test using OPTIONS into a sub-directory DIR, and then
24 # run the test.
25 proc do_test {dir options} {
26 global srcfile testfile
27
28 set binfile [standard_output_file ${dir}/${testfile}]
29 if { [build_executable "failed to prepare" ${binfile} \
30 [list $srcfile] $options] } {
31 return 0
32 }
33
34 clean_restart
35 gdb_test_no_output "set always-read-ctf on"
36 gdb_load $binfile
37
38 gdb_test_no_output "set print sevenbit-strings"
39 gdb_test_no_output "set print address off"
40 gdb_test_no_output "set width 0"
41
42 set ws "\[ \t\]*"
43
44 #
45 # Test casting a scalar to const
46 #
47
48 gdb_test "whatis (const char) v_char" \
49 "type = const char" \
50 "(const char)"
51 gdb_test "whatis (const signed char) v_signed_char" \
52 "type = const signed char" \
53 "(const signed char)"
54 gdb_test "whatis (const unsigned char) v_unsigned_char" \
55 "type = const (unsigned char|char)" \
56 "(const unsigned char)"
57 gdb_test "whatis (const short) v_short" \
58 "type = const (short|short int)" \
59 "(const short)"
60 gdb_test "whatis (const signed short) v_signed_short" \
61 "type = const (short|short int|signed short|signed short int)" \
62 "(const signed short)"
63 gdb_test "whatis (const unsigned short) v_unsigned_short" \
64 "type = const (unsigned short|short unsigned int)" \
65 "(const unsigned short)"
66 gdb_test "whatis (const int) v_int" \
67 "type = const int" \
68 "(const int)"
69 gdb_test "whatis (const signed int) v_signed_int" \
70 "type = const (signed int|int)" \
71 "(const signed int)"
72 gdb_test "whatis (const unsigned int) v_unsigned_int" \
73 "type = const unsigned int" \
74 "(const unsigned int)"
75 gdb_test "whatis (const long) v_long" \
76 "type = const (long|long int)" \
77 "(const long)"
78 gdb_test "whatis (const signed long) v_signed_long" \
79 "type = const (signed |)long( int|)" \
80 "(const signed long)"
81 gdb_test "whatis (const unsigned long) v_unsigned_long" \
82 "type = const (unsigned long|long unsigned int)" \
83 "(const unsigned long)"
84 gdb_test "whatis (const long long) v_long_long" \
85 "type = const long long( int|)" \
86 "(const long long)"
87 gdb_test "whatis (const signed long long) v_signed_long_long" \
88 "type = const (signed |)long long( int|)" \
89 "(const signed long long)"
90 gdb_test "whatis (const unsigned long long) v_unsigned_long_long" \
91 "type = const (unsigned long long|long long unsigned int)" \
92 "(const unsigned long long)"
93 gdb_test "whatis (const float) v_float" \
94 "type = const float" \
95 "(const float)"
96 gdb_test "whatis (const double) v_double" \
97 "type = const double" \
98 "(const double)"
99
100 #
101 # Test casting a scalar to volatile
102 #
103
104 gdb_test "whatis (volatile char) v_char" \
105 "type = volatile char" \
106 "(volatile char)"
107 gdb_test "whatis (volatile signed char) v_signed_char" \
108 "type = volatile signed char" \
109 "(volatile signed char)"
110 gdb_test "whatis (volatile unsigned char) v_unsigned_char" \
111 "type = volatile (unsigned char|char)" \
112 "(volatile unsigned char)"
113 gdb_test "whatis (volatile short) v_short" \
114 "type = volatile (short|short int)" \
115 "(volatile short)"
116 gdb_test "whatis (volatile signed short) v_signed_short" \
117 "type = volatile (short|short int|signed short|signed short int)" \
118 "(volatile signed short)"
119 gdb_test "whatis (volatile unsigned short) v_unsigned_short" \
120 "type = volatile (unsigned short|short unsigned int)" \
121 "(volatile unsigned short)"
122 gdb_test "whatis (volatile int) v_int" \
123 "type = volatile int" \
124 "(volatile int)"
125 gdb_test "whatis (volatile signed int) v_signed_int" \
126 "type = volatile (signed int|int)" \
127 "(volatile signed int)"
128 gdb_test "whatis (volatile unsigned int) v_unsigned_int" \
129 "type = volatile unsigned int" \
130 "(volatile unsigned int)"
131 gdb_test "whatis (volatile long) v_long" \
132 "type = volatile (long|long int)" \
133 "(volatile long)"
134 gdb_test "whatis (volatile signed long) v_signed_long" \
135 "type = volatile (signed |)long( int|)" \
136 "(volatile signed long)"
137 gdb_test "whatis (volatile unsigned long) v_unsigned_long" \
138 "type = volatile (unsigned long|long unsigned int)" \
139 "(volatile unsigned long)"
140 gdb_test "whatis (volatile long long) v_long_long" \
141 "type = volatile long long( int|)" \
142 "(volatile long long)"
143 gdb_test "whatis (volatile signed long long) v_signed_long_long" \
144 "type = volatile (signed |)long long( int|)" \
145 "(volatile signed long long)"
146 gdb_test "whatis (volatile unsigned long long) v_unsigned_long_long" \
147 "type = volatile (unsigned long long|long long unsigned int)" \
148 "(volatile unsigned long long)"
149 gdb_test "whatis (volatile float) v_float" \
150 "type = volatile float" \
151 "(volatile float)"
152 gdb_test "whatis (volatile double) v_double" \
153 "type = volatile double" \
154 "(volatile double)"
155
156 #
157 # Combine const and volatile
158 #
159
160 gdb_test "whatis (const volatile int) v_int" \
161 "type = const volatile int" \
162 "(const volatile int)"
163 gdb_test "whatis (volatile const int) v_int" \
164 "type = const volatile int" \
165 "(volatile const int)"
166 gdb_test "whatis (const int volatile) v_int" \
167 "type = const volatile int" \
168 "(const int volatile)"
169 gdb_test "whatis (volatile int const) v_int" \
170 "type = const volatile int" \
171 "(volatile int const)"
172 gdb_test "whatis (int const volatile) v_int" \
173 "type = const volatile int" \
174 "(int const volatile)"
175 gdb_test "whatis (int volatile const) v_int" \
176 "type = const volatile int" \
177 "(int volatile const)"
178
179 gdb_test "whatis (const volatile int *) v_int_pointer" \
180 "type = const volatile int${ws}\\*" \
181 "(const volatile int *)"
182 gdb_test "whatis (volatile const int *) v_int_pointer" \
183 "type = const volatile int${ws}\\*" \
184 "(volatile const int *)"
185 gdb_test "whatis (const int volatile *) v_int_pointer" \
186 "type = const volatile int${ws}\\*" \
187 "(const int volatile *)"
188 gdb_test "whatis (volatile int const *) v_int_pointer" \
189 "type = const volatile int${ws}\\*" \
190 "(volatile int const *)"
191 gdb_test "whatis (int const volatile *) v_int_pointer" \
192 "type = const volatile int${ws}\\*" \
193 "(int const volatile *)"
194 gdb_test "whatis (int volatile const *) v_int_pointer" \
195 "type = const volatile int${ws}\\*" \
196 "(int volatile const *)"
197 gdb_test "whatis (int * const volatile) v_int_pointer" \
198 "type = int${ws}\\*${ws}const volatile" \
199 "(int * const volatile)"
200 gdb_test "whatis (int * volatile const) v_int_pointer" \
201 "type = int${ws}\\*${ws}const volatile" \
202 "(int * volatile const)"
203
204
205 #
206 # Put 'signed' and 'unsigned' before const/volatile
207 #
208
209 #gdb_test "whatis (signed const char) v_signed_char" \
210 # "type = const char" \
211 # "(signed const char)"
212 #gdb_test "whatis (unsigned const char) v_unsigned_char" \
213 # "type = const (unsigned char|char)" \
214 # "(unsigned const char)"
215 #gdb_test "whatis (signed const short) v_signed_short" \
216 # "type = const (short|short int|signed short|signed short int)" \
217 # "(signed const short)"
218 #gdb_test "whatis (unsigned const short) v_unsigned_short" \
219 # "type = const (unsigned short|short unsigned int)" \
220 # "(unsigned const short)"
221 #gdb_test "whatis (signed const int) v_signed_int" \
222 # "type = const (signed int|int)" \
223 # "(signed const int)"
224 #gdb_test "whatis (unsigned const int) v_unsigned_int" \
225 # "type = const unsigned int" \
226 # "(unsigned const int)"
227 #gdb_test "whatis (signed const long) v_signed_long" \
228 # "type = const (signed |)long( int|)" \
229 # "(signed const long)"
230 #gdb_test "whatis (unsigned const long) v_unsigned_long" \
231 # "type = const (unsigned long|long unsigned int)" \
232 # "(unsigned const long)"
233 #gdb_test "whatis (signed const long long) v_signed_long_long" \
234 # "type = const (signed |)long long( int|)" \
235 # "(signed const long long)"
236 #gdb_test "whatis (unsigned const long long) v_unsigned_long_long" \
237 # "type = const (unsigned long long|long long unsigned int)" \
238 # "(const unsigned long long)"
239
240 #gdb_test "whatis (signed volatile char) v_signed_char" \
241 # "type = volatile char" \
242 # "(signed volatile char)"
243 #gdb_test "whatis (unsigned volatile char) v_unsigned_char" \
244 # "type = volatile (unsigned char|char)" \
245 # "(unsigned volatile char)"
246 #gdb_test "whatis (signed volatile short) v_signed_short" \
247 # "type = volatile (short|short int|signed short|signed short int)" \
248 # "(signed volatile short)"
249 #gdb_test "whatis (unsigned volatile short) v_unsigned_short" \
250 # "type = volatile (unsigned short|short unsigned int)" \
251 # "(unsigned volatile short)"
252 #gdb_test "whatis (signed volatile int) v_signed_int" \
253 # "type = volatile (signed int|int)" \
254 # "(signed volatile int)"
255 #gdb_test "whatis (unsigned volatile int) v_unsigned_int" \
256 # "type = volatile unsigned int" \
257 # "(unsigned volatile int)"
258 #gdb_test "whatis (signed volatile long) v_signed_long" \
259 # "type = volatile (signed |)long( int|)" \
260 # "(signed volatile long)"
261 #gdb_test "whatis (unsigned volatile long) v_unsigned_long" \
262 # "type = volatile (unsigned long|long unsigned int)" \
263 # "(unsigned volatile long)"
264 #gdb_test "whatis (signed volatile long long) v_signed_long_long" \
265 # "type = volatile (signed |)long long( int|)" \
266 # "(signed volatile long long)"
267 #gdb_test "whatis (unsigned volatile long long) v_unsigned_long_long" \
268 # "type = volatile (unsigned long long|long long unsigned int)" \
269 # "(unsigned volatile long long)"
270
271 #
272 # Now put the 'const' and 'volatile' keywords after the base type.
273 #
274
275 gdb_test "whatis (char const) v_char" \
276 "type = const char" \
277 "(char const)"
278 gdb_test "whatis (signed char const) v_signed_char" \
279 "type = const signed char" \
280 "(signed char const)"
281 gdb_test "whatis (unsigned char const) v_unsigned_char" \
282 "type = const (unsigned char|char)" \
283 "(unsigned char const)"
284 gdb_test "whatis (short const) v_short" \
285 "type = const (short|short int)" \
286 "(short const)"
287 gdb_test "whatis (signed short const) v_signed_short" \
288 "type = const (short|short int|signed short|signed short int)" \
289 "(signed short const)"
290 gdb_test "whatis (unsigned short const) v_unsigned_short" \
291 "type = const (unsigned short|short unsigned int)" \
292 "(unsigned short const)"
293 gdb_test "whatis (int const) v_int" \
294 "type = const int" \
295 "(int const)"
296 gdb_test "whatis (signed int const) v_signed_int" \
297 "type = const (signed int|int)" \
298 "(signed int const)"
299 gdb_test "whatis (unsigned int const) v_unsigned_int" \
300 "type = const unsigned int" \
301 "(unsigned int const)"
302 gdb_test "whatis (long const) v_long" \
303 "type = const (long|long int)" \
304 "(long const)"
305 gdb_test "whatis (signed long const) v_signed_long" \
306 "type = const (signed |)long( int|)" \
307 "(signed long const)"
308 gdb_test "whatis (unsigned long const) v_unsigned_long" \
309 "type = const (unsigned long|long unsigned int)" \
310 "(unsigned long const)"
311 gdb_test "whatis (long long const) v_long_long" \
312 "type = const long long( int|)" \
313 "(long long const)"
314 gdb_test "whatis (signed long long const) v_signed_long_long" \
315 "type = const (signed |)long long( int|)" \
316 "(signed long long const)"
317 gdb_test "whatis (unsigned long long const) v_unsigned_long_long" \
318 "type = const (unsigned long long|long long unsigned int)" \
319 "(unsigned long long const)"
320 gdb_test "whatis (float const) v_float" \
321 "type = const float" \
322 "(float const)"
323 gdb_test "whatis (double const) v_double" \
324 "type = const double" \
325 "(double const)"
326
327 gdb_test "whatis (char volatile) v_char" \
328 "type = volatile char" \
329 "(char volatile)"
330 gdb_test "whatis (signed char volatile) v_signed_char" \
331 "type = volatile signed char" \
332 "(signed char volatile)"
333 gdb_test "whatis (unsigned char volatile) v_unsigned_char" \
334 "type = volatile (unsigned char|char)" \
335 "(unsigned char volatile)"
336 gdb_test "whatis (short volatile) v_short" \
337 "type = volatile (short|short int)" \
338 "(short volatile)"
339 gdb_test "whatis (signed short volatile) v_signed_short" \
340 "type = volatile (short|short int|signed short|signed short int)" \
341 "(signed short volatile)"
342 gdb_test "whatis (unsigned short volatile) v_unsigned_short" \
343 "type = volatile (unsigned short|short unsigned int)" \
344 "(unsigned short volatile)"
345 gdb_test "whatis (int volatile) v_int" \
346 "type = volatile int" \
347 "(int volatile)"
348 gdb_test "whatis (signed int volatile) v_signed_int" \
349 "type = volatile (signed int|int)" \
350 "(signed int volatile)"
351 gdb_test "whatis (unsigned int volatile) v_unsigned_int" \
352 "type = volatile unsigned int" \
353 "(unsigned int volatile)"
354 gdb_test "whatis (long volatile) v_long" \
355 "type = volatile (long|long int)" \
356 "(long volatile)"
357 gdb_test "whatis (signed long volatile) v_signed_long" \
358 "type = volatile (signed |)long( int|)" \
359 "(signed long volatile)"
360 gdb_test "whatis (unsigned long volatile) v_unsigned_long" \
361 "type = volatile (unsigned long|long unsigned int)" \
362 "(unsigned long volatile)"
363 gdb_test "whatis (long long volatile) v_long_long" \
364 "type = volatile long long( int|)" \
365 "(long long volatile)"
366 gdb_test "whatis (signed long long volatile) v_signed_long_long" \
367 "type = volatile (signed |)long long( int|)" \
368 "(signed long long volatile)"
369 gdb_test "whatis (unsigned long long volatile) v_unsigned_long_long" \
370 "type = volatile (unsigned long long|long long unsigned int)" \
371 "(unsigned long long volatile)"
372 gdb_test "whatis (float volatile) v_float" \
373 "type = volatile float" \
374 "(float volatile)"
375 gdb_test "whatis (double volatile) v_double" \
376 "type = volatile double" \
377 "(double volatile)"
378
379 #
380 # enums
381 #
382
383 gdb_test "whatis (const enum misordered) v_misordered" \
384 "type = const enum misordered" \
385 "(const enum misordered)"
386 gdb_test "whatis (enum misordered const) v_misordered" \
387 "type = const enum misordered" \
388 "(enum misordered const)"
389 gdb_test "whatis (volatile enum misordered) v_misordered" \
390 "type = volatile enum misordered" \
391 "(volatile enum misordered)"
392 gdb_test "whatis (enum misordered volatile) v_misordered" \
393 "type = volatile enum misordered" \
394 "(enum misordered volatile)"
395
396 #
397 # Pointers
398 #
399
400 gdb_test "whatis (const int *) v_int_pointer" \
401 "type = const int${ws}\\*" \
402 "(const int *)"
403 gdb_test "whatis (int const *) v_int_pointer" \
404 "type = const int${ws}\\*" \
405 "(int const *)"
406 gdb_test "whatis (int * const) v_int_pointer" \
407 "type = int \\*${ws}const" \
408 "(int * const)"
409 gdb_test "whatis (const int * const) v_int_pointer" \
410 "type = const int${ws}\\*${ws}const" \
411 "(const int * const)"
412 gdb_test "whatis (int const * const) v_int_pointer" \
413 "type = const int${ws}\\*${ws}const" \
414 "(int const * const)"
415
416 gdb_test "whatis (const int **) v_int_pointer_pointer" \
417 "type = const int${ws}\\*${ws}\\*" \
418 "(const int **)"
419 gdb_test "whatis (int const **) v_int_pointer_pointer" \
420 "type = const int${ws}\\*${ws}\\*" \
421 "(int const **)"
422 gdb_test "whatis (int ** const) v_int_pointer_pointer" \
423 "type = int \\*${ws}\\*${ws}const" \
424 "(int ** const)"
425 gdb_test "whatis (const int * const *) v_int_pointer_pointer" \
426 "type = const int${ws}\\*${ws}const${ws}\\*" \
427 "(const int * const *)"
428 gdb_test "whatis (int const * const *) v_int_pointer_pointer" \
429 "type = const int${ws}\\*${ws}const${ws}\\*" \
430 "(int const * const *)"
431 gdb_test "whatis (const int * const * const) v_int_pointer_pointer" \
432 "type = const int${ws}\\*${ws}const${ws}\\*${ws}const" \
433 "(const int * const * const)"
434 gdb_test "whatis (int const * const * const) v_int_pointer_pointer" \
435 "type = const int${ws}\\*${ws}const${ws}\\*${ws}const" \
436 "(int const * const * const)"
437
438 #
439 # Arrays TODO
440 #
441
442 #
443 # Pointers to arrays, arrays of pointers TODO
444 #
445
446 #
447 # Structs and Unions
448 #
449
450 gdb_test "whatis (const struct t_struct) v_struct1" \
451 "type = const struct t_struct" \
452 "(const struct t_struct)"
453 gdb_test "whatis (const union t_union) v_union" \
454 "type = const union t_union" \
455 "(const union t_union)"
456 gdb_test "whatis (struct t_struct const) v_struct1" \
457 "type = const struct t_struct" \
458 "(struct t_struct const)"
459 gdb_test "whatis (union t_union const) v_union" \
460 "type = const union t_union" \
461 "(union t_union const)"
462 gdb_test "whatis (const struct t_struct *) &v_struct1" \
463 "type = const struct t_struct${ws}\\*" \
464 "(const struct t_struct *)"
465 gdb_test "whatis (const union t_union *) &v_union" \
466 "type = const union t_union${ws}\\*" \
467 "(const union t_union *)"
468 gdb_test "whatis (struct t_struct const *) &v_struct1" \
469 "type = const struct t_struct${ws}\\*" \
470 "(struct t_struct const *)"
471 gdb_test "whatis (union t_union const *) &v_union" \
472 "type = const union t_union${ws}\\*" \
473 "(union t_union const *)"
474 gdb_test "whatis (struct t_struct * const) &v_struct1" \
475 "type = struct t_struct${ws}\\*${ws}const" \
476 "(struct t_struct * const)"
477 gdb_test "whatis (union t_union * const) &v_union" \
478 "type = union t_union${ws}\\*${ws}const" \
479 "(union t_union * const)"
480 gdb_test "whatis (const struct t_struct * const) &v_struct1" \
481 "type = const struct t_struct${ws}\\*${ws}const" \
482 "(const struct t_struct * const)"
483 gdb_test "whatis (const union t_union * const) &v_union" \
484 "type = const union t_union${ws}\\*${ws}const" \
485 "(const union t_union * const)"
486 gdb_test "whatis (struct t_struct const * const) &v_struct1" \
487 "type = const struct t_struct${ws}\\*${ws}const" \
488 "(struct t_struct const * const)"
489 gdb_test "whatis (union t_union const * const) &v_union" \
490 "type = const union t_union${ws}\\*${ws}const" \
491 "(union t_union const * const)"
492
493 #
494 # Function pointers TODO
495 #
496 }
497
498 set ctf_opts {}
499 lappend ctf_opts additional_flags=-gctf
500
501 # Build up the set of debug formats for which we will run this test.
502 set specs { {dwarf {debug}} }
503 if {[allow_ctf_tests]} {
504 lappend specs [list ctf $ctf_opts]
505 }
506
507 # Setup and run the test for each debug format.
508 foreach testspec $specs {
509 set prefix [lindex $testspec 0]
510 set opts [lindex $testspec 1]
511
512 with_test_prefix $prefix {
513 remote_exec host "mkdir -p [standard_output_file ${prefix}]"
514 do_test $prefix $opts
515 }
516 }
517
518 # These tests don't rely on the debug format.
519 with_test_prefix nodebug {
520 if { [prepare_for_testing "failed to prepare" $binfile $srcfile {nodebug}] } {
521 return 0
522 }
523
524 gdb_test "ptype _Atomic int" "type = _Atomic int"
525 gdb_test "ptype int * restrict" "type = int \\* restrict"
526
527 # C++ does not have "restrict".
528 gdb_test_no_output "set lang c++"
529 with_test_prefix c++ {
530 gdb_test "ptype int * restrict" "A syntax error in expression.*"
531
532 # There is a GCC extension for __restrict__, though.
533 gdb_test "ptype int * __restrict__" "type = int \\* __restrict__"
534 }
535 }