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