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