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