1# Copyright 1988-2016 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# This file was written by Rob Savoye. (rob@cygnus.com) 17 18# 19# test running programs 20# 21 22if [target_info exists no_long_long] { 23 set exec_opts [list debug additional_flags=-DNO_LONG_LONG] 24} else { 25 set exec_opts [list debug] 26} 27 28standard_testfile .c 29 30if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $exec_opts] != "" } { 31 untested whatis.exp 32 return -1 33} 34 35# Create and source the file that provides information about the compiler 36# used to compile the test case. 37if [get_compiler_info] { 38 return -1 39} 40 41# Start with a fresh gdb. 42 43clean_restart $binfile 44 45# Define a procedure to set up an xfail for all targets that put out a 46# `long' type as an `int' type. 47# Sun cc has this problem. 48# It was said that COFF targets can not distinguish int from long either. 49 50proc setup_xfail_on_long_vs_int {} { 51 global gcc_compiled 52 53 if {!$gcc_compiled} { 54 setup_xfail "*-sun-sunos4*" "i*86-sequent-bsd*" 55 } 56} 57 58# 59# Test whatis command with basic C types 60# 61# The name printed now (as of 23 May 1993) is whatever name the compiler 62# uses in the stabs. So we need to deal with names both from gcc and 63# native compilers. 64# 65 66gdb_test "whatis v_char" \ 67 "type = (unsigned char|char)" \ 68 "whatis char" 69 70gdb_test "whatis v_signed_char" \ 71 "type = (signed char|char)" \ 72 "whatis signed char" 73 74gdb_test "whatis v_unsigned_char" \ 75 "type = unsigned char" \ 76 "whatis unsigned char" 77 78gdb_test "whatis v_short" \ 79 "type = (short|short int)" \ 80 "whatis short" 81 82gdb_test "whatis v_signed_short" \ 83 "type = (short|short int|signed short|signed short int)" \ 84 "whatis signed short" 85 86gdb_test "whatis v_unsigned_short" \ 87 "type = (unsigned short|short unsigned int)" \ 88 "whatis unsigned short" 89 90gdb_test "whatis v_int" \ 91 "type = int" \ 92 "whatis int" 93 94gdb_test "whatis v_signed_int" \ 95 "type = (signed |)int" \ 96 "whatis signed int" 97 98gdb_test "whatis v_unsigned_int" \ 99 "type = unsigned int" \ 100 "whatis unsigned int" 101 102setup_xfail_on_long_vs_int 103# AIX xlc gets this wrong and unsigned long right. Go figure. 104if {!$gcc_compiled} then {setup_xfail "rs6000-*-aix*"} 105gdb_test "whatis v_long" \ 106 "type = (long|long int)" \ 107 "whatis long" 108 109setup_xfail_on_long_vs_int 110# AIX xlc gets this wrong and unsigned long right. Go figure. 111if {!$gcc_compiled} then {setup_xfail "rs6000-*-aix*"} 112gdb_test "whatis v_signed_long" \ 113 "type = (signed |)(long|long int)" \ 114 "whatis signed long" 115 116setup_xfail_on_long_vs_int 117gdb_test "whatis v_unsigned_long" \ 118 "type = (unsigned long|long unsigned int)" \ 119 "whatis unsigned long" 120 121 122if ![target_info exists no_long_long] { 123 gdb_test "whatis v_unsigned_long_long" \ 124 "type = (unsigned long long|long long unsigned int)" \ 125 "whatis unsigned long long" 126} 127 128gdb_test "whatis v_float" \ 129 "type = float" \ 130 "whatis float" 131 132gdb_test "whatis v_double" \ 133 "type = double" \ 134 "whatis double" 135 136 137# test whatis command with arrays 138# 139# We already tested whether char prints as "char", so here we accept 140# "unsigned char", "signed char", and other perversions. No need for more 141# than one xfail for the same thing. 142gdb_test "whatis v_char_array" \ 143 "type = (signed |unsigned |)char \\\[2\\\]" \ 144 "whatis char array" 145 146gdb_test "whatis v_signed_char_array" \ 147 "type = (signed |unsigned |)char \\\[2\\\]" \ 148 "whatis signed char array" 149 150gdb_test "whatis v_unsigned_char_array" \ 151 "type = unsigned char \\\[2\\\]" \ 152 "whatis unsigned char array" 153 154gdb_test "whatis v_short_array" \ 155 "type = (short|short int) \\\[2\\\]" \ 156 "whatis short array" 157 158gdb_test "whatis v_signed_short_array" \ 159 "type = (signed |)(short|short int) \\\[2\\\]" \ 160 "whatis signed short array" 161 162gdb_test "whatis v_unsigned_short_array" \ 163 "type = (unsigned short|short unsigned int) \\\[2\\\]" \ 164 "whatis unsigned short array" 165 166gdb_test "whatis v_int_array" \ 167 "type = int \\\[2\\\]" \ 168 "whatis int array" 169 170gdb_test "whatis v_signed_int_array" \ 171 "type = (signed |)int \\\[2\\\]" \ 172 "whatis signed int array" 173 174gdb_test "whatis v_unsigned_int_array" \ 175 "type = unsigned int \\\[2\\\]" \ 176 "whatis unsigned int array" 177 178# We already tested whether long prints as long, so here we accept int 179# No need for more than one xfail for the same thing. 180gdb_test "whatis v_long_array" \ 181 "type = (int|long|long int) \\\[2\\\]" \ 182 "whatis long array" 183 184gdb_test "whatis v_signed_long_array" \ 185 "type = (signed |)(int|long|long int) \\\[2\\\]" \ 186 "whatis signed long array" 187 188gdb_test "whatis v_unsigned_long_array" \ 189 "type = (unsigned (int|long|long int)|long unsigned int) \\\[2\\\]" \ 190 "whatis unsigned long array" 191 192if ![target_info exists no_long_long] { 193 gdb_test "whatis v_unsigned_long_long_array" \ 194 "type = (unsigned long long|long long unsigned int) \\\[2\\\]" \ 195 "whatis unsigned long array" 196} 197 198gdb_test "whatis v_float_array" \ 199 "type = float \\\[2\\\]" \ 200 "whatis float array" 201 202gdb_test "whatis v_double_array" \ 203 "type = double \\\[2\\\]" \ 204 "whatis double array" 205 206 207# test whatis command with pointers 208# 209# We already tested whether char prints as char, so accept various perversions 210# here. We especially want to make sure we test that it doesn't print as 211# caddr_t. 212gdb_test "whatis v_char_pointer" \ 213 "type = (unsigned |signed |)char \\*" \ 214 "whatis char pointer" 215 216gdb_test "whatis v_signed_char_pointer" \ 217 "type = (unsigned |signed |)char \\*" \ 218 "whatis signed char pointer" 219 220gdb_test "whatis v_unsigned_char_pointer" \ 221 "type = unsigned char \\*" \ 222 "whatis unsigned char pointer" 223 224gdb_test "whatis v_short_pointer" \ 225 "type = (short|short int) \\*" \ 226 "whatis short pointer" 227 228gdb_test "whatis v_signed_short_pointer" \ 229 "type = (signed |)(short|short int) \\*" \ 230 "whatis signed short pointer" 231 232gdb_test "whatis v_unsigned_short_pointer" \ 233 "type = (unsigned short|short unsigned int) \\*" \ 234 "whatis unsigned short pointer" 235 236gdb_test "whatis v_int_pointer" \ 237 "type = int \\*" \ 238 "whatis int pointer" 239 240gdb_test "whatis v_signed_int_pointer" \ 241 "type = (signed |)int \\*" \ 242 "whatis signed int pointer" 243 244gdb_test "whatis v_unsigned_int_pointer" \ 245 "type = unsigned int \\*" \ 246 "whatis unsigned int pointer" 247 248# We already tested whether long prints as long, so here we accept int 249gdb_test "whatis v_long_pointer" \ 250 "type = (long|int|long int) \\*" \ 251 "whatis long pointer" 252 253gdb_test "whatis v_signed_long_pointer" \ 254 "type = (signed |)(long|int|long int) \\*" \ 255 "whatis signed long pointer" 256 257gdb_test "whatis v_unsigned_long_pointer" \ 258 "type = (unsigned (int|long|long int)|long unsigned int) \\*" \ 259 "whatis unsigned long pointer" 260 261if ![target_info exists no_long_long] { 262 gdb_test "whatis v_long_long_pointer" \ 263 "type = long long(| int) \\*" \ 264 "whatis long long pointer" 265 266 gdb_test "whatis v_signed_long_long_pointer" \ 267 "type = (signed |)long long(| int) \\*" \ 268 "whatis signed long long pointer" 269 270 gdb_test "whatis v_unsigned_long_long_pointer" \ 271 "type = (unsigned long long|long long unsigned int) \\*" \ 272 "whatis unsigned long long pointer" 273} 274 275gdb_test "whatis v_float_pointer" \ 276 "type = float \\*" \ 277 "whatis float pointer" 278 279gdb_test "whatis v_double_pointer" \ 280 "type = double \\*" \ 281 "whatis double pointer" 282 283 284# test whatis command with structure types 285gdb_test "whatis v_struct1" \ 286 "type = struct t_struct" \ 287 "whatis named structure" 288 289gdb_test "whatis struct t_struct" \ 290 "type = struct t_struct" \ 291 "whatis named structure using type name" 292 293gdb_test "whatis v_struct2" \ 294 "type = struct \{\.\.\.\}" \ 295 "whatis unnamed structure" 296 297gdb_test "whatis &v_struct1" \ 298 "type = struct t_struct \\*" 299 300gdb_test "whatis &v_struct2" \ 301 "type = struct {\\.\\.\\.} \\*" 302 303gdb_test "whatis v_struct_ptr1" \ 304 "type = struct t_struct \\*" 305 306gdb_test "whatis v_struct_ptr2" \ 307 "type = struct {\\.\\.\\.} \\*" 308 309gdb_test "whatis &v_struct_ptr1" \ 310 "type = struct t_struct \\*\\*" 311 312gdb_test "whatis &v_struct_ptr2" \ 313 "type = struct {\\.\\.\\.} \\*\\*" 314 315gdb_test "whatis v_struct1.v_char_member" \ 316 "type = char" 317 318gdb_test "whatis v_struct2.v_char_member" \ 319 "type = char" 320 321gdb_test "whatis v_struct_ptr1->v_char_member" \ 322 "type = char" 323 324gdb_test "whatis v_struct_ptr2->v_char_member" \ 325 "type = char" 326 327gdb_test "whatis &(v_struct1.v_char_member)" \ 328 "type = char \\*" 329 330gdb_test "whatis &(v_struct2.v_char_member)" \ 331 "type = char \\*" 332 333gdb_test "whatis &(v_struct_ptr1->v_char_member)" \ 334 "type = char \\*" 335 336gdb_test "whatis &(v_struct_ptr2->v_char_member)" \ 337 "type = char \\*" 338 339# test whatis command with union types 340gdb_test "whatis v_union" \ 341 "type = union t_union" \ 342 "whatis named union" 343 344gdb_test "whatis union t_union" \ 345 "type = union t_union" \ 346 "whatis named union using type name" 347 348gdb_test "whatis v_union2" \ 349 "type = union \{\.\.\.\}" \ 350 "whatis unnamed union" 351 352gdb_test "whatis &v_union" \ 353 "type = union t_union \\*" 354 355gdb_test "whatis &v_union2" \ 356 "type = union {\\.\\.\\.} \\*" 357 358gdb_test "whatis v_union_ptr" \ 359 "type = union t_union \\*" 360 361gdb_test "whatis v_union_ptr2" \ 362 "type = union {\\.\\.\\.} \\*" 363 364gdb_test "whatis &v_union_ptr" \ 365 "type = union t_union \\*\\*" 366 367gdb_test "whatis &v_union_ptr2" \ 368 "type = union {\\.\\.\\.} \\*\\*" 369 370gdb_test "whatis v_union.v_char_member" \ 371 "type = char" 372 373gdb_test "whatis v_union2.v_char_member" \ 374 "type = char" 375 376gdb_test "whatis v_union_ptr->v_char_member" \ 377 "type = char" 378 379gdb_test "whatis v_union_ptr2->v_char_member" \ 380 "type = char" 381 382gdb_test "whatis &(v_union.v_char_member)" \ 383 "type = char \\*" 384 385gdb_test "whatis &(v_union2.v_char_member)" \ 386 "type = char \\*" 387 388gdb_test "whatis &(v_union_ptr->v_char_member)" \ 389 "type = char \\*" 390 391gdb_test "whatis &(v_union_ptr2->v_char_member)" \ 392 "type = char \\*" 393 394 395# Using stabs we will mark these functions as prototyped. This 396# is harmless but causes an extra VOID to be printed. 397set void "(void|)" 398 399# test whatis command with functions return type 400gdb_test "whatis v_char_func" \ 401 "type = (signed |unsigned |)char \\($void\\)" \ 402 "whatis char function" 403 404gdb_test "whatis v_signed_char_func" \ 405 "type = (signed |unsigned |)char \\($void\\)" \ 406 "whatis signed char function" 407 408gdb_test "whatis v_unsigned_char_func" \ 409 "type = unsigned char \\($void\\)" \ 410 "whatis unsigned char function" 411 412gdb_test "whatis v_short_func" \ 413 "type = short (int |)\\($void\\)" \ 414 "whatis short function" 415 416gdb_test "whatis v_signed_short_func" \ 417 "type = (signed |)short (int |)\\($void\\)" \ 418 "whatis signed short function" 419 420gdb_test "whatis v_unsigned_short_func" \ 421 "type = (unsigned short|short unsigned int) \\($void\\)" \ 422 "whatis unsigned short function" 423 424gdb_test "whatis v_int_func" \ 425 "type = int \\($void\\)" \ 426 "whatis int function" 427 428gdb_test "whatis v_signed_int_func" \ 429 "type = (signed |)int \\($void\\)" \ 430 "whatis signed int function" 431 432gdb_test "whatis v_unsigned_int_func" \ 433 "type = unsigned int \\($void\\)" \ 434 "whatis unsigned int function" 435 436gdb_test "whatis v_long_func" \ 437 "type = (long|int|long int) \\($void\\)" \ 438 "whatis long function" 439 440gdb_test "whatis v_signed_long_func" \ 441 "type = (signed |)(int|long|long int) \\($void\\)" \ 442 "whatis signed long function" 443 444gdb_test "whatis v_unsigned_long_func" \ 445 "type = (unsigned (int|long|long int)|long unsigned int) \\($void\\)" \ 446 "whatis unsigned long function" 447 448if ![target_info exists no_long_long] { 449 gdb_test "whatis v_long_long_func" \ 450 "type = long long(| int) \\($void\\)" \ 451 "whatis long long function" 452 453 gdb_test "whatis v_signed_long_long_func" \ 454 "type = (signed |)long long(| int) \\($void\\)" \ 455 "whatis signed long long function" 456 457 gdb_test "whatis v_unsigned_long_long_func" \ 458 "type = (unsigned long long(| int)|long long unsigned int) \\($void\\)" \ 459 "whatis unsigned long long function" 460} 461 462# Sun /bin/cc calls this a function returning double. 463if {!$gcc_compiled} then {setup_xfail "*-sun-sunos4*"} 464gdb_test "whatis v_float_func" \ 465 "type = float \\($void\\)" \ 466 "whatis float function" 467 468gdb_test "whatis v_double_func" \ 469 "type = double \\($void\\)" \ 470 "whatis double function" \ 471 472 473# test whatis command with some misc complicated types 474gdb_test "whatis s_link" \ 475 "type = struct link \\*" \ 476 "whatis complicated structure" 477 478gdb_test "whatis u_link" \ 479 "type = union tu_link" \ 480 "whatis complicated union" 481 482 483# test whatis command with enumerations 484gdb_test "whatis clunker" \ 485 "type = enum cars" \ 486 "whatis enumeration" 487 488gdb_test "whatis enum cars" \ 489 "type = enum cars" \ 490 "whatis enumeration using type name" 491 492 493# test whatis command with nested struct and union 494gdb_test "whatis nested_su" \ 495 "type = struct outer_struct" \ 496 "whatis outer structure" 497 498gdb_test "whatis nested_su.outer_int" \ 499 "type = int" \ 500 "whatis outer structure member" 501 502gdb_test "whatis nested_su.inner_struct_instance" \ 503 "type = struct inner_struct" \ 504 "whatis inner structure" 505 506gdb_test "whatis nested_su.inner_struct_instance.inner_int" \ 507 "type = int" \ 508 "whatis inner structure member" 509 510gdb_test "whatis nested_su.inner_union_instance" \ 511 "type = union inner_union" \ 512 "whatis inner union" 513 514gdb_test "whatis nested_su.inner_union_instance.inner_union_int" \ 515 "type = int" \ 516 "whatis inner union member" 517 518# test whatis command with typedefs 519 520gdb_test "whatis char_addr" \ 521 "type = char \\*" \ 522 "whatis using typedef type name" 523 524gdb_test "whatis a_char_addr" \ 525 "type = char_addr" \ 526 "whatis applied to variable defined by typedef" 527 528# Regression tests for PR 9514. 529 530gdb_test "whatis void (**)()" \ 531 "type = void \\(\\*\\*\\)\\(\\)" \ 532 "whatis applied to pointer to pointer to function" 533 534gdb_test "whatis void (** const)()" \ 535 "type = void \\(\\*\\* const\\)\\(\\)" \ 536 "whatis applied to const pointer to pointer to function" 537 538gdb_test "whatis void (* const *)()" \ 539 "type = void \\(\\* const \\*\\)\\(\\)" \ 540 "whatis applied to pointer to const pointer to function" 541 542gdb_test "whatis int *(*)()" \ 543 "type = int \\*\\(\\*\\)\\(\\)" \ 544 "whatis applied to pointer to function returning pointer to int" 545 546gdb_test "whatis int *(**)()" \ 547 "type = int \\*\\(\\*\\*\\)\\(\\)" \ 548 "whatis applied to pointer to pointer to function returning pointer to int" 549 550gdb_test "whatis char (*(*)())\[23\]" \ 551 "type = char \\(\\*\\(\\*\\)\\(\\)\\)\\\[23\\\]" \ 552 "whatis applied to pointer to function returning pointer to array" 553 554gdb_test "whatis int (*)(int, int)" \ 555 "type = int \\(\\*\\)\\(int, int\\)" \ 556 "whatis applied to pointer to function taking int,int and returning int" 557 558gdb_test "whatis int (*)(const int *, ...)" \ 559 "type = int \\(\\*\\)\\(const int \\*, \\.\\.\\.\\)" \ 560 "whatis applied to pointer to function taking const int ptr and varargs and returning int" 561 562gdb_test "whatis int (*)(void, int, int)" \ 563 "parameter types following 'void'" \ 564 "whatis applied to function with types trailing 'void'" 565 566gdb_test "whatis int (*)(int, void, int)" \ 567 "'void' invalid as parameter type" \ 568 "whatis applied to function with 'void' parameter type" 569