Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.base / whatis.exp
blob2da9aecc600fb99da14946f80cc298c744f3b903
1 # Copyright 1988-2023 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]
24 } else {
25     set exec_opts [list debug]
28 # Some tests require GCC.
29 set gcc_compiled [is_c_compiler_gcc]
31 standard_testfile .c
33 # Define a procedure to set up an xfail for all targets that put out a
34 # `long' type as an `int' type.
35 # Sun cc has this problem.
36 # It was said that COFF targets can not distinguish int from long either.
38 proc setup_xfail_on_long_vs_int {} {
39     global gcc_compiled
41     if {!$gcc_compiled} {
42         setup_xfail "*-sun-sunos4*" "i*86-sequent-bsd*"
43     }
46 # Compile the test using OPTIONS into a sub-directory DIR, and then
47 # run the test.
48 proc do_test {dir options} {
49     global srcfile testfile gcc_compiled
51     set binfile [standard_output_file ${dir}/${testfile}]
52     if { [prepare_for_testing "failed to prepare" ${binfile} \
53               [list $srcfile] $options] } {
54         return 0
55     }
57     #
58     # Test whatis command with basic C types
59     #
60     # The name printed now (as of 23 May 1993) is whatever name the compiler
61     # uses in the stabs.  So we need to deal with names both from gcc and
62     # native compilers.
63     #
65     gdb_test "whatis v_char" \
66         "type = (unsigned char|char)" \
67         "whatis char"
69     gdb_test "whatis v_signed_char" \
70         "type = (signed char|char)" \
71         "whatis signed char"
73     gdb_test "whatis v_unsigned_char" \
74         "type = unsigned char" \
75         "whatis unsigned char"
77     gdb_test "whatis v_short" \
78         "type = (short|short int)" \
79         "whatis short"
81     gdb_test "whatis v_signed_short" \
82         "type = (short|short int|signed short|signed short int)" \
83         "whatis signed short"
85     gdb_test "whatis v_unsigned_short" \
86         "type = (unsigned short|short unsigned int)" \
87         "whatis unsigned short"
89     gdb_test "whatis v_int" \
90         "type = int" \
91         "whatis int"
93     gdb_test "whatis v_signed_int" \
94         "type = (signed |)int" \
95         "whatis signed int"
97     gdb_test "whatis v_unsigned_int" \
98         "type = unsigned int" \
99         "whatis unsigned int"
101     setup_xfail_on_long_vs_int
102     # AIX xlc gets this wrong and unsigned long right.  Go figure.
103     if {!$gcc_compiled} {setup_xfail "rs6000-*-aix*"}
104     gdb_test "whatis v_long" \
105         "type = (long|long int)" \
106         "whatis long"
108     setup_xfail_on_long_vs_int
109     # AIX xlc gets this wrong and unsigned long right.  Go figure.
110     if {!$gcc_compiled} {setup_xfail "rs6000-*-aix*"}
111     gdb_test "whatis v_signed_long" \
112         "type = (signed |)(long|long int)" \
113         "whatis signed long"
115     setup_xfail_on_long_vs_int
116     gdb_test "whatis v_unsigned_long" \
117         "type = (unsigned long|long unsigned int)" \
118         "whatis unsigned long"
121     if ![target_info exists no_long_long] {
122         gdb_test "whatis v_unsigned_long_long" \
123             "type = (unsigned long long|long long unsigned int)" \
124             "whatis unsigned long long"
125     }
127     gdb_test "whatis v_float" \
128         "type = float" \
129         "whatis float"
131     gdb_test "whatis v_double" \
132         "type = double" \
133         "whatis double"
136     # test whatis command with arrays
137     #
138     # We already tested whether char prints as "char", so here we accept
139     # "unsigned char", "signed char", and other perversions.  No need for more
140     # than one xfail for the same thing.
141     gdb_test "whatis v_char_array" \
142         "type = (signed |unsigned |)char \\\[2\\\]" \
143         "whatis char array"
145     gdb_test "whatis v_signed_char_array" \
146         "type = (signed |unsigned |)char \\\[2\\\]" \
147         "whatis signed char array"
149     gdb_test "whatis v_unsigned_char_array" \
150         "type = unsigned char \\\[2\\\]" \
151         "whatis unsigned char array"
153     gdb_test "whatis v_short_array" \
154         "type = (short|short int) \\\[2\\\]" \
155         "whatis short array"
157     gdb_test "whatis v_signed_short_array" \
158         "type = (signed |)(short|short int) \\\[2\\\]" \
159         "whatis signed short array"
161     gdb_test "whatis v_unsigned_short_array" \
162         "type = (unsigned short|short unsigned int) \\\[2\\\]" \
163         "whatis unsigned short array"
165     gdb_test "whatis v_int_array" \
166         "type = int \\\[2\\\]" \
167         "whatis int array"
169     gdb_test "whatis v_signed_int_array" \
170         "type = (signed |)int \\\[2\\\]" \
171         "whatis signed int array"
173     gdb_test "whatis v_unsigned_int_array" \
174         "type = unsigned int \\\[2\\\]" \
175         "whatis unsigned int array"
177     # We already tested whether long prints as long, so here we accept int
178     # No need for more than one xfail for the same thing.
179     gdb_test "whatis v_long_array" \
180         "type = (int|long|long int) \\\[2\\\]" \
181         "whatis long array"
183     gdb_test "whatis v_signed_long_array" \
184         "type = (signed |)(int|long|long int) \\\[2\\\]" \
185         "whatis signed long array"
187     gdb_test "whatis v_unsigned_long_array" \
188         "type = (unsigned (int|long|long int)|long unsigned int) \\\[2\\\]" \
189         "whatis unsigned long array"
191     if ![target_info exists no_long_long] {
192         gdb_test "whatis v_unsigned_long_long_array" \
193             "type = (unsigned long long|long long unsigned int) \\\[2\\\]" \
194             "whatis unsigned long long array"
195     }
197     gdb_test "whatis v_float_array" \
198         "type = float \\\[2\\\]" \
199         "whatis float array"
201     gdb_test "whatis v_double_array" \
202         "type = double \\\[2\\\]" \
203         "whatis double array"
205     # test whatis command with pointers
206     #
207     # We already tested whether char prints as char, so accept various perversions
208     # here.  We especially want to make sure we test that it doesn't print as
209     # caddr_t.
210     gdb_test "whatis v_char_pointer" \
211         "type = (unsigned |signed |)char \\*" \
212         "whatis char pointer"
214     gdb_test "whatis v_signed_char_pointer" \
215         "type = (unsigned |signed |)char \\*" \
216         "whatis signed char pointer"
218     gdb_test "whatis v_unsigned_char_pointer" \
219         "type = unsigned char \\*" \
220         "whatis unsigned char pointer"
222     gdb_test "whatis v_short_pointer" \
223         "type = (short|short int) \\*" \
224         "whatis short pointer"
226     gdb_test "whatis v_signed_short_pointer" \
227         "type = (signed |)(short|short int) \\*" \
228         "whatis signed short pointer"
230     gdb_test "whatis v_unsigned_short_pointer" \
231         "type = (unsigned short|short unsigned int) \\*" \
232         "whatis unsigned short pointer"
234     gdb_test "whatis v_int_pointer" \
235         "type = int \\*" \
236         "whatis int pointer"
238     gdb_test "whatis v_signed_int_pointer" \
239         "type = (signed |)int \\*" \
240         "whatis signed int pointer"
242     gdb_test "whatis v_unsigned_int_pointer" \
243         "type = unsigned int \\*" \
244         "whatis unsigned int pointer"
246     # We already tested whether long prints as long, so here we accept int
247     gdb_test "whatis v_long_pointer" \
248         "type = (long|int|long int) \\*" \
249         "whatis long pointer"
251     gdb_test "whatis v_signed_long_pointer" \
252         "type = (signed |)(long|int|long int) \\*" \
253         "whatis signed long pointer"
255     gdb_test "whatis v_unsigned_long_pointer" \
256         "type = (unsigned (int|long|long int)|long unsigned int) \\*" \
257         "whatis unsigned long pointer"
259     if ![target_info exists no_long_long] {
260         gdb_test "whatis v_long_long_pointer" \
261             "type = long long(| int) \\*" \
262             "whatis long long pointer"
264         gdb_test "whatis v_signed_long_long_pointer" \
265             "type = (signed |)long long(| int) \\*" \
266             "whatis signed long long pointer"
268         gdb_test "whatis v_unsigned_long_long_pointer" \
269             "type = (unsigned long long|long long unsigned int) \\*" \
270             "whatis unsigned long long pointer"
271     }
273     gdb_test "whatis v_float_pointer" \
274         "type = float \\*" \
275         "whatis float pointer"
277     gdb_test "whatis v_double_pointer" \
278         "type = double \\*" \
279         "whatis double pointer"
282     # test whatis command with structure types
284     # First with a type argument, with both "set print object" set to "on"
285     # and "off", ending with "off" for the following tests.
286     foreach_with_prefix print_object {"on" "off"} {
287         gdb_test_no_output "set print object $print_object"
289         gdb_test "whatis struct t_struct" \
290             "type = struct t_struct" \
291             "whatis named structure using type name"
293         gdb_test "whatis struct t_struct *" \
294             "type = struct t_struct \\*" \
295             "whatis named structure using type name and pointer"
297         gdb_test "whatis struct t_struct &" \
298             "type = struct t_struct &" \
299             "whatis named structure using type name and reference"
300     }
302     # Now with an expression argument.
304     gdb_test "whatis v_struct1" \
305         "type = struct t_struct" \
306         "whatis named structure"
308     gdb_test "whatis v_struct2" \
309         "type = struct \{\.\.\.\}" \
310         "whatis unnamed structure"
312     gdb_test "whatis &v_struct1" \
313         "type = struct t_struct \\*"
315     gdb_test "whatis &v_struct2" \
316         "type = struct {\\.\\.\\.} \\*"
318     gdb_test "whatis v_struct_ptr1" \
319         "type = struct t_struct \\*"
321     gdb_test "whatis v_struct_ptr2" \
322         "type = struct {\\.\\.\\.} \\*"
324     gdb_test "whatis &v_struct_ptr1" \
325         "type = struct t_struct \\*\\*"
327     gdb_test "whatis &v_struct_ptr2" \
328         "type = struct {\\.\\.\\.} \\*\\*"
330     gdb_test "whatis v_struct1.v_char_member" \
331         "type = char"
333     gdb_test "whatis v_struct2.v_char_member" \
334         "type = char"
336     gdb_test "whatis v_struct_ptr1->v_char_member" \
337         "type = char"
339     gdb_test "whatis v_struct_ptr2->v_char_member" \
340         "type = char"
342     gdb_test "whatis &(v_struct1.v_char_member)" \
343         "type = char \\*"
345     gdb_test "whatis &(v_struct2.v_char_member)" \
346         "type = char \\*"
348     gdb_test "whatis &(v_struct_ptr1->v_char_member)" \
349         "type = char \\*"
351     gdb_test "whatis &(v_struct_ptr2->v_char_member)" \
352         "type = char \\*"
354     # test whatis command with union types
355     gdb_test "whatis v_union" \
356         "type = union t_union" \
357         "whatis named union"
359     gdb_test "whatis union t_union" \
360         "type = union t_union" \
361         "whatis named union using type name"
363     gdb_test "whatis v_union2" \
364         "type = union \{\.\.\.\}" \
365         "whatis unnamed union"
367     gdb_test "whatis &v_union" \
368         "type = union t_union \\*"
370     gdb_test "whatis &v_union2" \
371         "type = union {\\.\\.\\.} \\*"
373     gdb_test "whatis v_union_ptr" \
374         "type = union t_union \\*"
376     gdb_test "whatis v_union_ptr2" \
377         "type = union {\\.\\.\\.} \\*"
379     gdb_test "whatis &v_union_ptr" \
380         "type = union t_union \\*\\*"
382     gdb_test "whatis &v_union_ptr2" \
383         "type = union {\\.\\.\\.} \\*\\*"
385     gdb_test "whatis v_union.v_char_member" \
386         "type = char"
388     gdb_test "whatis v_union2.v_char_member" \
389         "type = char"
391     gdb_test "whatis v_union_ptr->v_char_member" \
392         "type = char"
394     gdb_test "whatis v_union_ptr2->v_char_member" \
395         "type = char"
397     gdb_test "whatis &(v_union.v_char_member)" \
398         "type = char \\*"
400     gdb_test "whatis &(v_union2.v_char_member)" \
401         "type = char \\*"
403     gdb_test "whatis &(v_union_ptr->v_char_member)" \
404         "type = char \\*"
406     gdb_test "whatis &(v_union_ptr2->v_char_member)" \
407         "type = char \\*"
409     if { $dir == "dwarf" } {
410         # Using stabs we will mark these functions as prototyped.  This
411         # is harmless but causes an extra VOID to be printed.
412         set void "(void|)"
414         # test whatis command with functions return type
415         gdb_test "whatis v_char_func" \
416             "type = (signed |unsigned |)char \\($void\\)" \
417             "whatis char function"
419         gdb_test "whatis v_signed_char_func" \
420             "type = (signed |unsigned |)char \\($void\\)" \
421             "whatis signed char function"
423         gdb_test "whatis v_unsigned_char_func" \
424             "type = unsigned char \\($void\\)"  \
425             "whatis unsigned char function"
427         gdb_test "whatis v_short_func" \
428             "type = short (int |)\\($void\\)" \
429             "whatis short function"
431         gdb_test "whatis v_signed_short_func" \
432             "type = (signed |)short (int |)\\($void\\)" \
433             "whatis signed short function"
435         gdb_test "whatis v_unsigned_short_func" \
436             "type = (unsigned short|short unsigned int) \\($void\\)" \
437             "whatis unsigned short function"
439         gdb_test "whatis v_int_func" \
440             "type = int \\($void\\)" \
441             "whatis int function"
443         gdb_test "whatis v_signed_int_func" \
444             "type = (signed |)int \\($void\\)" \
445             "whatis signed int function"
447         gdb_test "whatis v_unsigned_int_func" \
448             "type = unsigned int \\($void\\)" \
449             "whatis unsigned int function"
451         gdb_test "whatis v_long_func" \
452             "type = (long|int|long int) \\($void\\)" \
453             "whatis long function"
455         gdb_test "whatis v_signed_long_func" \
456             "type = (signed |)(int|long|long int) \\($void\\)" \
457             "whatis signed long function"
459         gdb_test "whatis v_unsigned_long_func" \
460             "type = (unsigned (int|long|long int)|long unsigned int) \\($void\\)" \
461             "whatis unsigned long function"
463         if ![target_info exists no_long_long] {
464             gdb_test "whatis v_long_long_func" \
465                 "type = long long(| int) \\($void\\)" \
466                 "whatis long long function"
468             gdb_test "whatis v_signed_long_long_func" \
469                 "type = (signed |)long long(| int) \\($void\\)" \
470                 "whatis signed long long function"
472             gdb_test "whatis v_unsigned_long_long_func" \
473                 "type = (unsigned long long(| int)|long long unsigned int) \\($void\\)" \
474                 "whatis unsigned long long function"
475         }
477         # Sun /bin/cc calls this a function returning double.
478         if {!$gcc_compiled} {setup_xfail "*-sun-sunos4*"}
479         gdb_test "whatis v_float_func" \
480             "type = float \\($void\\)" \
481             "whatis float function"
483         gdb_test "whatis v_double_func" \
484             "type = double \\($void\\)" \
485             "whatis double function" \
486         }
488     # test whatis command with some misc complicated types
489     gdb_test "whatis s_link" \
490         "type = struct link \\*" \
491         "whatis complicated structure"
493     gdb_test "whatis u_link" \
494         "type = union tu_link" \
495         "whatis complicated union"
498     # test whatis command with enumerations
499     gdb_test "whatis clunker" \
500         "type = enum cars" \
501         "whatis enumeration"
503     gdb_test "whatis enum cars" \
504         "type = enum cars" \
505         "whatis enumeration using type name"
508     # test whatis command with nested struct and union
509     gdb_test "whatis nested_su" \
510         "type = struct outer_struct" \
511         "whatis outer structure"
513     gdb_test "whatis nested_su.outer_int" \
514         "type = int" \
515         "whatis outer structure member"
517     gdb_test "whatis nested_su.inner_struct_instance" \
518         "type = struct inner_struct" \
519         "whatis inner structure"
521     gdb_test "whatis nested_su.inner_struct_instance.inner_int" \
522         "type = int" \
523         "whatis inner structure member"
525     gdb_test "whatis nested_su.inner_union_instance" \
526         "type = union inner_union" \
527         "whatis inner union"
529     gdb_test "whatis nested_su.inner_union_instance.inner_union_int" \
530         "type = int" \
531         "whatis inner union member"
533     # test whatis command with typedefs
535     gdb_test "whatis char_addr" \
536         "type = char \\*" \
537         "whatis using typedef type name"
539     if { $dir == "dwarf" } {
540         gdb_test "whatis a_char_addr" \
541             "type = char_addr" \
542             "whatis applied to variable defined by typedef"
543     }
545     # Regression tests for PR 9514.
547     gdb_test "whatis void (**)()" \
548         "type = void \\(\\*\\*\\)\\(\\)" \
549         "whatis applied to pointer to pointer to function"
551     gdb_test "whatis void (** const)()" \
552         "type = void \\(\\*\\* const\\)\\(\\)" \
553         "whatis applied to const pointer to pointer to function"
555     gdb_test "whatis void (* const *)()" \
556         "type = void \\(\\* const \\*\\)\\(\\)" \
557         "whatis applied to pointer to const pointer to function"
559     gdb_test "whatis int *(*)()" \
560         "type = int \\*\\(\\*\\)\\(\\)" \
561         "whatis applied to pointer to function returning pointer to int"
563     gdb_test "whatis int *(**)()" \
564         "type = int \\*\\(\\*\\*\\)\\(\\)" \
565         "whatis applied to pointer to pointer to function returning pointer to int"
567     gdb_test "whatis char (*(*)())\[23\]" \
568         "type = char \\(\\*\\(\\*\\)\\(\\)\\)\\\[23\\\]" \
569         "whatis applied to pointer to function returning pointer to array"
571     gdb_test "whatis int (*)(int, int)" \
572         "type = int \\(\\*\\)\\(int, int\\)" \
573         "whatis applied to pointer to function taking int,int and returning int"
575     gdb_test "whatis int (*)(const int *, ...)" \
576         "type = int \\(\\*\\)\\(const int \\*, \\.\\.\\.\\)" \
577         "whatis applied to pointer to function taking const int ptr and varargs and returning int"
579     gdb_test "whatis int (*)(void, int, int)" \
580         "parameter types following 'void'" \
581         "whatis applied to function with types trailing 'void'"
583     gdb_test "whatis int (*)(int, void, int)" \
584         "'void' invalid as parameter type" \
585         "whatis applied to function with 'void' parameter type"
588 set ctf_opts {}
589 lappend ctf_opts additional_flags=-gctf
590 lappend ctf_opts ldflags=-Wl,--strip-debug
591 lappend ctf_opts ldflags=-Wl,--ctf-variables
593 # Build up the set of debug formats for which we will run this test.
594 set specs { {dwarf {debug}} }
595 if ![skip_ctf_tests] {
596     lappend specs [list ctf $ctf_opts]
599 # Setup and run the test for each debug format.
600 foreach testspec $specs {
601     set prefix [lindex $testspec 0]
602     set opts [lindex $testspec 1]
604     with_test_prefix $prefix {
605         remote_exec host "mkdir -p [standard_output_file ${prefix}]"
606         do_test $prefix $opts
607     }