1 # Copyright 1988-2014 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Rob Savoye. (rob@cygnus.com)
19 # test running programs
22 if [target_info exists no_long_long] {
23 set exec_opts [list debug additional_flags=-DNO_LONG_LONG]
25 set exec_opts [list debug]
30 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $exec_opts] != "" } {
35 # Create and source the file that provides information about the compiler
36 # used to compile the test case.
37 if [get_compiler_info] {
41 # Start with a fresh gdb.
43 clean_restart $binfile
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/Ultrix cc have this problem.
48 # It was said that COFF targets can not distinguish int from long either.
50 proc setup_xfail_on_long_vs_int {} {
54 setup_xfail "*-sun-sunos4*" "*-*-ultrix*" "i*86-sequent-bsd*"
59 # Test whatis command with basic C types
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
66 gdb_test "whatis v_char" \
67 "type = (unsigned char|char)" \
70 gdb_test "whatis v_signed_char" \
71 "type = (signed char|char)" \
74 gdb_test "whatis v_unsigned_char" \
75 "type = unsigned char" \
76 "whatis unsigned char"
78 gdb_test "whatis v_short" \
79 "type = (short|short int)" \
82 gdb_test "whatis v_signed_short" \
83 "type = (short|short int|signed short|signed short int)" \
86 gdb_test "whatis v_unsigned_short" \
87 "type = (unsigned short|short unsigned int)" \
88 "whatis unsigned short"
90 gdb_test "whatis v_int" \
94 gdb_test "whatis v_signed_int" \
95 "type = (signed |)int" \
98 gdb_test "whatis v_unsigned_int" \
99 "type = unsigned int" \
100 "whatis unsigned int"
102 setup_xfail_on_long_vs_int
103 # AIX xlc gets this wrong and unsigned long right. Go figure.
104 if {!$gcc_compiled} then {setup_xfail "rs6000-*-aix*"}
105 gdb_test "whatis v_long" \
106 "type = (long|long int)" \
109 setup_xfail_on_long_vs_int
110 # AIX xlc gets this wrong and unsigned long right. Go figure.
111 if {!$gcc_compiled} then {setup_xfail "rs6000-*-aix*"}
112 gdb_test "whatis v_signed_long" \
113 "type = (signed |)(long|long int)" \
116 setup_xfail_on_long_vs_int
117 gdb_test "whatis v_unsigned_long" \
118 "type = (unsigned long|long unsigned int)" \
119 "whatis unsigned long"
122 if ![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"
128 gdb_test "whatis v_float" \
132 gdb_test "whatis v_double" \
137 # test whatis command with arrays
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.
142 gdb_test "whatis v_char_array" \
143 "type = (signed |unsigned |)char \\\[2\\\]" \
146 gdb_test "whatis v_signed_char_array" \
147 "type = (signed |unsigned |)char \\\[2\\\]" \
148 "whatis signed char array"
150 gdb_test "whatis v_unsigned_char_array" \
151 "type = unsigned char \\\[2\\\]" \
152 "whatis unsigned char array"
154 gdb_test "whatis v_short_array" \
155 "type = (short|short int) \\\[2\\\]" \
158 gdb_test "whatis v_signed_short_array" \
159 "type = (signed |)(short|short int) \\\[2\\\]" \
160 "whatis signed short array"
162 gdb_test "whatis v_unsigned_short_array" \
163 "type = (unsigned short|short unsigned int) \\\[2\\\]" \
164 "whatis unsigned short array"
166 gdb_test "whatis v_int_array" \
167 "type = int \\\[2\\\]" \
170 gdb_test "whatis v_signed_int_array" \
171 "type = (signed |)int \\\[2\\\]" \
172 "whatis signed int array"
174 gdb_test "whatis v_unsigned_int_array" \
175 "type = unsigned int \\\[2\\\]" \
176 "whatis unsigned int array"
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.
180 gdb_test "whatis v_long_array" \
181 "type = (int|long|long int) \\\[2\\\]" \
184 gdb_test "whatis v_signed_long_array" \
185 "type = (signed |)(int|long|long int) \\\[2\\\]" \
186 "whatis signed long array"
188 gdb_test "whatis v_unsigned_long_array" \
189 "type = (unsigned (int|long|long int)|long unsigned int) \\\[2\\\]" \
190 "whatis unsigned long array"
192 if ![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"
198 gdb_test "whatis v_float_array" \
199 "type = float \\\[2\\\]" \
202 gdb_test "whatis v_double_array" \
203 "type = double \\\[2\\\]" \
204 "whatis double array"
207 # test whatis command with pointers
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
212 gdb_test "whatis v_char_pointer" \
213 "type = (unsigned |signed |)char \\*" \
214 "whatis char pointer"
216 gdb_test "whatis v_signed_char_pointer" \
217 "type = (unsigned |signed |)char \\*" \
218 "whatis signed char pointer"
220 gdb_test "whatis v_unsigned_char_pointer" \
221 "type = unsigned char \\*" \
222 "whatis unsigned char pointer"
224 gdb_test "whatis v_short_pointer" \
225 "type = (short|short int) \\*" \
226 "whatis short pointer"
228 gdb_test "whatis v_signed_short_pointer" \
229 "type = (signed |)(short|short int) \\*" \
230 "whatis signed short pointer"
232 gdb_test "whatis v_unsigned_short_pointer" \
233 "type = (unsigned short|short unsigned int) \\*" \
234 "whatis unsigned short pointer"
236 gdb_test "whatis v_int_pointer" \
240 gdb_test "whatis v_signed_int_pointer" \
241 "type = (signed |)int \\*" \
242 "whatis signed int pointer"
244 gdb_test "whatis v_unsigned_int_pointer" \
245 "type = unsigned int \\*" \
246 "whatis unsigned int pointer"
248 # We already tested whether long prints as long, so here we accept int
249 gdb_test "whatis v_long_pointer" \
250 "type = (long|int|long int) \\*" \
251 "whatis long pointer"
253 gdb_test "whatis v_signed_long_pointer" \
254 "type = (signed |)(long|int|long int) \\*" \
255 "whatis signed long pointer"
257 gdb_test "whatis v_unsigned_long_pointer" \
258 "type = (unsigned (int|long|long int)|long unsigned int) \\*" \
259 "whatis unsigned long pointer"
261 if ![target_info exists no_long_long] {
262 gdb_test "whatis v_long_long_pointer" \
263 "type = long long(| int) \\*" \
264 "whatis long long pointer"
266 gdb_test "whatis v_signed_long_long_pointer" \
267 "type = (signed |)long long(| int) \\*" \
268 "whatis signed long long pointer"
270 gdb_test "whatis v_unsigned_long_long_pointer" \
271 "type = (unsigned long long|long long unsigned int) \\*" \
272 "whatis unsigned long long pointer"
275 gdb_test "whatis v_float_pointer" \
277 "whatis float pointer"
279 gdb_test "whatis v_double_pointer" \
280 "type = double \\*" \
281 "whatis double pointer"
284 if { $hp_aCC_compiler } {
285 set unstruct "unnamed\.struct\..*"
286 set ununion "unnamed\.union\..*"
288 set unstruct "\.\.\."
292 # test whatis command with structure types
293 gdb_test "whatis v_struct1" \
294 "type = struct t_struct" \
295 "whatis named structure"
297 gdb_test "whatis struct t_struct" \
298 "type = struct t_struct" \
299 "whatis named structure using type name"
301 gdb_test "whatis v_struct2" \
302 "type = struct \{$unstruct\}" \
303 "whatis unnamed structure"
306 # test whatis command with union types
307 gdb_test "whatis v_union" \
308 "type = union t_union" \
311 gdb_test "whatis union t_union" \
312 "type = union t_union" \
313 "whatis named union using type name"
315 gdb_test "whatis v_union2" \
316 "type = union \{$ununion\}" \
317 "whatis unnamed union"
320 # HP-UX: HP aCC compiler w/ +objdebug option detects language as
321 # c++, so we need the 'void' pattern here.
322 # Without +objdebug compilation option we still need to match ''.
324 # Also, using stabs we will mark these functions as prototyped. This
325 # is harmless but causes an extra VOID to be printed.
328 # test whatis command with functions return type
329 gdb_test "whatis v_char_func" \
330 "type = (signed |unsigned |)char \\($void\\)" \
331 "whatis char function"
333 gdb_test "whatis v_signed_char_func" \
334 "type = (signed |unsigned |)char \\($void\\)" \
335 "whatis signed char function"
337 gdb_test "whatis v_unsigned_char_func" \
338 "type = unsigned char \\($void\\)" \
339 "whatis unsigned char function"
341 gdb_test "whatis v_short_func" \
342 "type = short (int |)\\($void\\)" \
343 "whatis short function"
345 gdb_test "whatis v_signed_short_func" \
346 "type = (signed |)short (int |)\\($void\\)" \
347 "whatis signed short function"
349 gdb_test "whatis v_unsigned_short_func" \
350 "type = (unsigned short|short unsigned int) \\($void\\)" \
351 "whatis unsigned short function"
353 gdb_test "whatis v_int_func" \
354 "type = int \\($void\\)" \
355 "whatis int function"
357 gdb_test "whatis v_signed_int_func" \
358 "type = (signed |)int \\($void\\)" \
359 "whatis signed int function"
361 gdb_test "whatis v_unsigned_int_func" \
362 "type = unsigned int \\($void\\)" \
363 "whatis unsigned int function"
365 gdb_test "whatis v_long_func" \
366 "type = (long|int|long int) \\($void\\)" \
367 "whatis long function"
369 gdb_test "whatis v_signed_long_func" \
370 "type = (signed |)(int|long|long int) \\($void\\)" \
371 "whatis signed long function"
373 gdb_test "whatis v_unsigned_long_func" \
374 "type = (unsigned (int|long|long int)|long unsigned int) \\($void\\)" \
375 "whatis unsigned long function"
377 if ![target_info exists no_long_long] {
378 gdb_test "whatis v_long_long_func" \
379 "type = long long(| int) \\($void\\)" \
380 "whatis long long function"
382 gdb_test "whatis v_signed_long_long_func" \
383 "type = (signed |)long long(| int) \\($void\\)" \
384 "whatis signed long long function"
386 gdb_test "whatis v_unsigned_long_long_func" \
387 "type = (unsigned long long(| int)|long long unsigned int) \\($void\\)" \
388 "whatis unsigned long long function"
391 # Sun /bin/cc calls this a function returning double.
392 if {!$gcc_compiled} then {setup_xfail "*-sun-sunos4*"}
393 gdb_test "whatis v_float_func" \
394 "type = float \\($void\\)" \
395 "whatis float function"
397 gdb_test "whatis v_double_func" \
398 "type = double \\($void\\)" \
399 "whatis double function" \
402 # test whatis command with some misc complicated types
403 gdb_test "whatis s_link" \
404 "type = struct link \\*" \
405 "whatis complicated structure"
407 gdb_test "whatis u_link" \
408 "type = union tu_link" \
409 "whatis complicated union"
412 # test whatis command with enumerations
413 gdb_test "whatis clunker" \
417 gdb_test "whatis enum cars" \
419 "whatis enumeration using type name"
422 # test whatis command with nested struct and union
423 gdb_test "whatis nested_su" \
424 "type = struct outer_struct" \
425 "whatis outer structure"
427 gdb_test "whatis nested_su.outer_int" \
429 "whatis outer structure member"
431 if {$hp_aCC_compiler} {
432 set outer "outer_struct::"
437 gdb_test "whatis nested_su.inner_struct_instance" \
438 "type = struct ${outer}inner_struct" \
439 "whatis inner structure"
441 gdb_test "whatis nested_su.inner_struct_instance.inner_int" \
443 "whatis inner structure member"
445 gdb_test "whatis nested_su.inner_union_instance" \
446 "type = union ${outer}inner_union" \
449 gdb_test "whatis nested_su.inner_union_instance.inner_union_int" \
451 "whatis inner union member"
453 # test whatis command with typedefs
455 gdb_test "whatis char_addr" \
457 "whatis using typedef type name"
459 gdb_test "whatis a_char_addr" \
461 "whatis applied to variable defined by typedef"
463 # Regression tests for PR 9514.
465 gdb_test "whatis void (**)()" \
466 "type = void \\(\\*\\*\\)\\(\\)" \
467 "whatis applied to pointer to pointer to function"
469 gdb_test "whatis void (** const)()" \
470 "type = void \\(\\*\\* const\\)\\(\\)" \
471 "whatis applied to const pointer to pointer to function"
473 gdb_test "whatis void (* const *)()" \
474 "type = void \\(\\* const \\*\\)\\(\\)" \
475 "whatis applied to pointer to const pointer to function"
477 gdb_test "whatis int *(*)()" \
478 "type = int \\*\\(\\*\\)\\(\\)" \
479 "whatis applied to pointer to function returning pointer to int"
481 gdb_test "whatis int *(**)()" \
482 "type = int \\*\\(\\*\\*\\)\\(\\)" \
483 "whatis applied to pointer to pointer to function returning pointer to int"
485 gdb_test "whatis char (*(*)())\[23\]" \
486 "type = char \\(\\*\\(\\*\\)\\(\\)\\)\\\[23\\\]" \
487 "whatis applied to pointer to function returning pointer to array"
489 gdb_test "whatis int (*)(int, int)" \
490 "type = int \\(\\*\\)\\(int, int\\)" \
491 "whatis applied to pointer to function taking int,int and returning int"
493 gdb_test "whatis int (*)(const int *, ...)" \
494 "type = int \\(\\*\\)\\(const int \\*, \\.\\.\\.\\)" \
495 "whatis applied to pointer to function taking const int ptr and varargs and returning int"
497 gdb_test "whatis int (*)(void, int, int)" \
498 "parameter types following 'void'" \
499 "whatis applied to function with types trailing 'void'"
501 gdb_test "whatis int (*)(int, void, int)" \
502 "'void' invalid as parameter type" \
503 "whatis applied to function with 'void' parameter type"