1 # Copyright 1988-2020 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 # Define a procedure to set up an xfail for all targets that put out a
31 # `long' type as an `int' type.
32 # Sun cc has this problem.
33 # It was said that COFF targets can not distinguish int from long either.
35 proc setup_xfail_on_long_vs_int {} {
39 setup_xfail "*-sun-sunos4*" "i*86-sequent-bsd*"
43 # Compile the test using OPTIONS into a sub-directory DIR, and then
45 proc do_test {dir options} {
46 global srcfile testfile gcc_compiled
48 set binfile [standard_output_file ${dir}/${testfile}]
49 if { [prepare_for_testing "failed to prepare" ${binfile} \
50 [list $srcfile] $options] } {
54 clean_restart ${binfile}
57 # Test whatis command with basic C types
59 # The name printed now (as of 23 May 1993) is whatever name the compiler
60 # uses in the stabs. So we need to deal with names both from gcc and
64 gdb_test "whatis v_char" \
65 "type = (unsigned char|char)" \
68 gdb_test "whatis v_signed_char" \
69 "type = (signed char|char)" \
72 gdb_test "whatis v_unsigned_char" \
73 "type = unsigned char" \
74 "whatis unsigned char"
76 gdb_test "whatis v_short" \
77 "type = (short|short int)" \
80 gdb_test "whatis v_signed_short" \
81 "type = (short|short int|signed short|signed short int)" \
84 gdb_test "whatis v_unsigned_short" \
85 "type = (unsigned short|short unsigned int)" \
86 "whatis unsigned short"
88 gdb_test "whatis v_int" \
92 gdb_test "whatis v_signed_int" \
93 "type = (signed |)int" \
96 gdb_test "whatis v_unsigned_int" \
97 "type = unsigned int" \
100 setup_xfail_on_long_vs_int
101 # AIX xlc gets this wrong and unsigned long right. Go figure.
102 if {!$gcc_compiled} then {setup_xfail "rs6000-*-aix*"}
103 gdb_test "whatis v_long" \
104 "type = (long|long int)" \
107 setup_xfail_on_long_vs_int
108 # AIX xlc gets this wrong and unsigned long right. Go figure.
109 if {!$gcc_compiled} then {setup_xfail "rs6000-*-aix*"}
110 gdb_test "whatis v_signed_long" \
111 "type = (signed |)(long|long int)" \
114 setup_xfail_on_long_vs_int
115 gdb_test "whatis v_unsigned_long" \
116 "type = (unsigned long|long unsigned int)" \
117 "whatis unsigned long"
120 if ![target_info exists no_long_long] {
121 gdb_test "whatis v_unsigned_long_long" \
122 "type = (unsigned long long|long long unsigned int)" \
123 "whatis unsigned long long"
126 gdb_test "whatis v_float" \
130 gdb_test "whatis v_double" \
135 # test whatis command with arrays
137 # We already tested whether char prints as "char", so here we accept
138 # "unsigned char", "signed char", and other perversions. No need for more
139 # than one xfail for the same thing.
140 gdb_test "whatis v_char_array" \
141 "type = (signed |unsigned |)char \\\[2\\\]" \
144 gdb_test "whatis v_signed_char_array" \
145 "type = (signed |unsigned |)char \\\[2\\\]" \
146 "whatis signed char array"
148 gdb_test "whatis v_unsigned_char_array" \
149 "type = unsigned char \\\[2\\\]" \
150 "whatis unsigned char array"
152 gdb_test "whatis v_short_array" \
153 "type = (short|short int) \\\[2\\\]" \
156 gdb_test "whatis v_signed_short_array" \
157 "type = (signed |)(short|short int) \\\[2\\\]" \
158 "whatis signed short array"
160 gdb_test "whatis v_unsigned_short_array" \
161 "type = (unsigned short|short unsigned int) \\\[2\\\]" \
162 "whatis unsigned short array"
164 gdb_test "whatis v_int_array" \
165 "type = int \\\[2\\\]" \
168 gdb_test "whatis v_signed_int_array" \
169 "type = (signed |)int \\\[2\\\]" \
170 "whatis signed int array"
172 gdb_test "whatis v_unsigned_int_array" \
173 "type = unsigned int \\\[2\\\]" \
174 "whatis unsigned int array"
176 # We already tested whether long prints as long, so here we accept int
177 # No need for more than one xfail for the same thing.
178 gdb_test "whatis v_long_array" \
179 "type = (int|long|long int) \\\[2\\\]" \
182 gdb_test "whatis v_signed_long_array" \
183 "type = (signed |)(int|long|long int) \\\[2\\\]" \
184 "whatis signed long array"
186 gdb_test "whatis v_unsigned_long_array" \
187 "type = (unsigned (int|long|long int)|long unsigned int) \\\[2\\\]" \
188 "whatis unsigned long array"
190 if ![target_info exists no_long_long] {
191 gdb_test "whatis v_unsigned_long_long_array" \
192 "type = (unsigned long long|long long unsigned int) \\\[2\\\]" \
193 "whatis unsigned long long array"
196 gdb_test "whatis v_float_array" \
197 "type = float \\\[2\\\]" \
200 gdb_test "whatis v_double_array" \
201 "type = double \\\[2\\\]" \
202 "whatis double array"
204 # test whatis command with pointers
206 # We already tested whether char prints as char, so accept various perversions
207 # here. We especially want to make sure we test that it doesn't print as
209 gdb_test "whatis v_char_pointer" \
210 "type = (unsigned |signed |)char \\*" \
211 "whatis char pointer"
213 gdb_test "whatis v_signed_char_pointer" \
214 "type = (unsigned |signed |)char \\*" \
215 "whatis signed char pointer"
217 gdb_test "whatis v_unsigned_char_pointer" \
218 "type = unsigned char \\*" \
219 "whatis unsigned char pointer"
221 gdb_test "whatis v_short_pointer" \
222 "type = (short|short int) \\*" \
223 "whatis short pointer"
225 gdb_test "whatis v_signed_short_pointer" \
226 "type = (signed |)(short|short int) \\*" \
227 "whatis signed short pointer"
229 gdb_test "whatis v_unsigned_short_pointer" \
230 "type = (unsigned short|short unsigned int) \\*" \
231 "whatis unsigned short pointer"
233 gdb_test "whatis v_int_pointer" \
237 gdb_test "whatis v_signed_int_pointer" \
238 "type = (signed |)int \\*" \
239 "whatis signed int pointer"
241 gdb_test "whatis v_unsigned_int_pointer" \
242 "type = unsigned int \\*" \
243 "whatis unsigned int pointer"
245 # We already tested whether long prints as long, so here we accept int
246 gdb_test "whatis v_long_pointer" \
247 "type = (long|int|long int) \\*" \
248 "whatis long pointer"
250 gdb_test "whatis v_signed_long_pointer" \
251 "type = (signed |)(long|int|long int) \\*" \
252 "whatis signed long pointer"
254 gdb_test "whatis v_unsigned_long_pointer" \
255 "type = (unsigned (int|long|long int)|long unsigned int) \\*" \
256 "whatis unsigned long pointer"
258 if ![target_info exists no_long_long] {
259 gdb_test "whatis v_long_long_pointer" \
260 "type = long long(| int) \\*" \
261 "whatis long long pointer"
263 gdb_test "whatis v_signed_long_long_pointer" \
264 "type = (signed |)long long(| int) \\*" \
265 "whatis signed long long pointer"
267 gdb_test "whatis v_unsigned_long_long_pointer" \
268 "type = (unsigned long long|long long unsigned int) \\*" \
269 "whatis unsigned long long pointer"
272 gdb_test "whatis v_float_pointer" \
274 "whatis float pointer"
276 gdb_test "whatis v_double_pointer" \
277 "type = double \\*" \
278 "whatis double pointer"
281 # test whatis command with structure types
283 # First with a type argument, with both "set print object" set to "on"
284 # and "off", ending with "off" for the following tests.
285 foreach_with_prefix print_object {"on" "off"} {
286 gdb_test_no_output "set print object $print_object"
288 gdb_test "whatis struct t_struct" \
289 "type = struct t_struct" \
290 "whatis named structure using type name"
292 gdb_test "whatis struct t_struct *" \
293 "type = struct t_struct \\*" \
294 "whatis named structure using type name and pointer"
296 gdb_test "whatis struct t_struct &" \
297 "type = struct t_struct &" \
298 "whatis named structure using type name and reference"
301 # Now with an expression argument.
303 gdb_test "whatis v_struct1" \
304 "type = struct t_struct" \
305 "whatis named structure"
307 gdb_test "whatis v_struct2" \
308 "type = struct \{\.\.\.\}" \
309 "whatis unnamed structure"
311 gdb_test "whatis &v_struct1" \
312 "type = struct t_struct \\*"
314 gdb_test "whatis &v_struct2" \
315 "type = struct {\\.\\.\\.} \\*"
317 gdb_test "whatis v_struct_ptr1" \
318 "type = struct t_struct \\*"
320 gdb_test "whatis v_struct_ptr2" \
321 "type = struct {\\.\\.\\.} \\*"
323 gdb_test "whatis &v_struct_ptr1" \
324 "type = struct t_struct \\*\\*"
326 gdb_test "whatis &v_struct_ptr2" \
327 "type = struct {\\.\\.\\.} \\*\\*"
329 gdb_test "whatis v_struct1.v_char_member" \
332 gdb_test "whatis v_struct2.v_char_member" \
335 gdb_test "whatis v_struct_ptr1->v_char_member" \
338 gdb_test "whatis v_struct_ptr2->v_char_member" \
341 gdb_test "whatis &(v_struct1.v_char_member)" \
344 gdb_test "whatis &(v_struct2.v_char_member)" \
347 gdb_test "whatis &(v_struct_ptr1->v_char_member)" \
350 gdb_test "whatis &(v_struct_ptr2->v_char_member)" \
353 # test whatis command with union types
354 gdb_test "whatis v_union" \
355 "type = union t_union" \
358 gdb_test "whatis union t_union" \
359 "type = union t_union" \
360 "whatis named union using type name"
362 gdb_test "whatis v_union2" \
363 "type = union \{\.\.\.\}" \
364 "whatis unnamed union"
366 gdb_test "whatis &v_union" \
367 "type = union t_union \\*"
369 gdb_test "whatis &v_union2" \
370 "type = union {\\.\\.\\.} \\*"
372 gdb_test "whatis v_union_ptr" \
373 "type = union t_union \\*"
375 gdb_test "whatis v_union_ptr2" \
376 "type = union {\\.\\.\\.} \\*"
378 gdb_test "whatis &v_union_ptr" \
379 "type = union t_union \\*\\*"
381 gdb_test "whatis &v_union_ptr2" \
382 "type = union {\\.\\.\\.} \\*\\*"
384 gdb_test "whatis v_union.v_char_member" \
387 gdb_test "whatis v_union2.v_char_member" \
390 gdb_test "whatis v_union_ptr->v_char_member" \
393 gdb_test "whatis v_union_ptr2->v_char_member" \
396 gdb_test "whatis &(v_union.v_char_member)" \
399 gdb_test "whatis &(v_union2.v_char_member)" \
402 gdb_test "whatis &(v_union_ptr->v_char_member)" \
405 gdb_test "whatis &(v_union_ptr2->v_char_member)" \
408 if { $dir == "dwarf" } {
409 # Using stabs we will mark these functions as prototyped. This
410 # is harmless but causes an extra VOID to be printed.
413 # test whatis command with functions return type
414 gdb_test "whatis v_char_func" \
415 "type = (signed |unsigned |)char \\($void\\)" \
416 "whatis char function"
418 gdb_test "whatis v_signed_char_func" \
419 "type = (signed |unsigned |)char \\($void\\)" \
420 "whatis signed char function"
422 gdb_test "whatis v_unsigned_char_func" \
423 "type = unsigned char \\($void\\)" \
424 "whatis unsigned char function"
426 gdb_test "whatis v_short_func" \
427 "type = short (int |)\\($void\\)" \
428 "whatis short function"
430 gdb_test "whatis v_signed_short_func" \
431 "type = (signed |)short (int |)\\($void\\)" \
432 "whatis signed short function"
434 gdb_test "whatis v_unsigned_short_func" \
435 "type = (unsigned short|short unsigned int) \\($void\\)" \
436 "whatis unsigned short function"
438 gdb_test "whatis v_int_func" \
439 "type = int \\($void\\)" \
440 "whatis int function"
442 gdb_test "whatis v_signed_int_func" \
443 "type = (signed |)int \\($void\\)" \
444 "whatis signed int function"
446 gdb_test "whatis v_unsigned_int_func" \
447 "type = unsigned int \\($void\\)" \
448 "whatis unsigned int function"
450 gdb_test "whatis v_long_func" \
451 "type = (long|int|long int) \\($void\\)" \
452 "whatis long function"
454 gdb_test "whatis v_signed_long_func" \
455 "type = (signed |)(int|long|long int) \\($void\\)" \
456 "whatis signed long function"
458 gdb_test "whatis v_unsigned_long_func" \
459 "type = (unsigned (int|long|long int)|long unsigned int) \\($void\\)" \
460 "whatis unsigned long function"
462 if ![target_info exists no_long_long] {
463 gdb_test "whatis v_long_long_func" \
464 "type = long long(| int) \\($void\\)" \
465 "whatis long long function"
467 gdb_test "whatis v_signed_long_long_func" \
468 "type = (signed |)long long(| int) \\($void\\)" \
469 "whatis signed long long function"
471 gdb_test "whatis v_unsigned_long_long_func" \
472 "type = (unsigned long long(| int)|long long unsigned int) \\($void\\)" \
473 "whatis unsigned long long function"
476 # Sun /bin/cc calls this a function returning double.
477 if {!$gcc_compiled} then {setup_xfail "*-sun-sunos4*"}
478 gdb_test "whatis v_float_func" \
479 "type = float \\($void\\)" \
480 "whatis float function"
482 gdb_test "whatis v_double_func" \
483 "type = double \\($void\\)" \
484 "whatis double function" \
487 # test whatis command with some misc complicated types
488 gdb_test "whatis s_link" \
489 "type = struct link \\*" \
490 "whatis complicated structure"
492 gdb_test "whatis u_link" \
493 "type = union tu_link" \
494 "whatis complicated union"
497 # test whatis command with enumerations
498 gdb_test "whatis clunker" \
502 gdb_test "whatis enum cars" \
504 "whatis enumeration using type name"
507 # test whatis command with nested struct and union
508 gdb_test "whatis nested_su" \
509 "type = struct outer_struct" \
510 "whatis outer structure"
512 gdb_test "whatis nested_su.outer_int" \
514 "whatis outer structure member"
516 gdb_test "whatis nested_su.inner_struct_instance" \
517 "type = struct inner_struct" \
518 "whatis inner structure"
520 gdb_test "whatis nested_su.inner_struct_instance.inner_int" \
522 "whatis inner structure member"
524 gdb_test "whatis nested_su.inner_union_instance" \
525 "type = union inner_union" \
528 gdb_test "whatis nested_su.inner_union_instance.inner_union_int" \
530 "whatis inner union member"
532 # test whatis command with typedefs
534 gdb_test "whatis char_addr" \
536 "whatis using typedef type name"
538 if { $dir == "dwarf" } {
539 gdb_test "whatis a_char_addr" \
541 "whatis applied to variable defined by typedef"
544 # Regression tests for PR 9514.
546 gdb_test "whatis void (**)()" \
547 "type = void \\(\\*\\*\\)\\(\\)" \
548 "whatis applied to pointer to pointer to function"
550 gdb_test "whatis void (** const)()" \
551 "type = void \\(\\*\\* const\\)\\(\\)" \
552 "whatis applied to const pointer to pointer to function"
554 gdb_test "whatis void (* const *)()" \
555 "type = void \\(\\* const \\*\\)\\(\\)" \
556 "whatis applied to pointer to const pointer to function"
558 gdb_test "whatis int *(*)()" \
559 "type = int \\*\\(\\*\\)\\(\\)" \
560 "whatis applied to pointer to function returning pointer to int"
562 gdb_test "whatis int *(**)()" \
563 "type = int \\*\\(\\*\\*\\)\\(\\)" \
564 "whatis applied to pointer to pointer to function returning pointer to int"
566 gdb_test "whatis char (*(*)())\[23\]" \
567 "type = char \\(\\*\\(\\*\\)\\(\\)\\)\\\[23\\\]" \
568 "whatis applied to pointer to function returning pointer to array"
570 gdb_test "whatis int (*)(int, int)" \
571 "type = int \\(\\*\\)\\(int, int\\)" \
572 "whatis applied to pointer to function taking int,int and returning int"
574 gdb_test "whatis int (*)(const int *, ...)" \
575 "type = int \\(\\*\\)\\(const int \\*, \\.\\.\\.\\)" \
576 "whatis applied to pointer to function taking const int ptr and varargs and returning int"
578 gdb_test "whatis int (*)(void, int, int)" \
579 "parameter types following 'void'" \
580 "whatis applied to function with types trailing 'void'"
582 gdb_test "whatis int (*)(int, void, int)" \
583 "'void' invalid as parameter type" \
584 "whatis applied to function with 'void' parameter type"
587 # Build up the set of debug formats for which we will run this test.
588 set specs { {dwarf {debug}} }
589 if ![skip_ctf_tests] {
590 lappend specs {ctf {"additional_flags=-gt"}}
593 # Setup and run the test for each debug format.
594 foreach testspec $specs {
595 set prefix [lindex $testspec 0]
596 set opts [lindex $testspec 1]
598 with_test_prefix $prefix {
599 remote_exec host "mkdir -p [standard_output_file ${prefix}]"
600 do_test $prefix $opts