1 # Copyright 1988-2024 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]
28 # Some tests require GCC.
29 set gcc_compiled [is_c_compiler_gcc]
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 {} {
42 setup_xfail "*-sun-sunos4*" "i*86-sequent-bsd*"
46 # Compile the test using OPTIONS into a sub-directory DIR, and then
48 proc do_test {dir options} {
49 global srcfile testfile gcc_compiled
51 set binfile [standard_output_file ${dir}/${testfile}]
52 if { [build_executable "failed to prepare" ${binfile} \
53 [list $srcfile] $options] } {
58 gdb_test_no_output "set always-read-ctf on"
62 # Test whatis command with basic C types
64 # The name printed now (as of 23 May 1993) is whatever name the compiler
65 # uses in the stabs. So we need to deal with names both from gcc and
69 gdb_test "whatis v_char" \
70 "type = (unsigned char|char)" \
73 gdb_test "whatis v_signed_char" \
74 "type = (signed char|char)" \
77 gdb_test "whatis v_unsigned_char" \
78 "type = unsigned char" \
79 "whatis unsigned char"
81 gdb_test "whatis v_short" \
82 "type = (short|short int)" \
85 gdb_test "whatis v_signed_short" \
86 "type = (short|short int|signed short|signed short int)" \
89 gdb_test "whatis v_unsigned_short" \
90 "type = (unsigned short|short unsigned int)" \
91 "whatis unsigned short"
93 gdb_test "whatis v_int" \
97 gdb_test "whatis v_signed_int" \
98 "type = (signed |)int" \
101 gdb_test "whatis v_unsigned_int" \
102 "type = unsigned int" \
103 "whatis unsigned int"
105 setup_xfail_on_long_vs_int
106 # AIX xlc gets this wrong and unsigned long right. Go figure.
107 if {!$gcc_compiled} {setup_xfail "rs6000-*-aix*"}
108 gdb_test "whatis v_long" \
109 "type = (long|long int)" \
112 setup_xfail_on_long_vs_int
113 # AIX xlc gets this wrong and unsigned long right. Go figure.
114 if {!$gcc_compiled} {setup_xfail "rs6000-*-aix*"}
115 gdb_test "whatis v_signed_long" \
116 "type = (signed |)(long|long int)" \
119 setup_xfail_on_long_vs_int
120 gdb_test "whatis v_unsigned_long" \
121 "type = (unsigned long|long unsigned int)" \
122 "whatis unsigned long"
125 if ![target_info exists no_long_long] {
126 gdb_test "whatis v_unsigned_long_long" \
127 "type = (unsigned long long|long long unsigned int)" \
128 "whatis unsigned long long"
131 gdb_test "whatis v_float" \
135 gdb_test "whatis v_double" \
140 # test whatis command with arrays
142 # We already tested whether char prints as "char", so here we accept
143 # "unsigned char", "signed char", and other perversions. No need for more
144 # than one xfail for the same thing.
145 gdb_test "whatis v_char_array" \
146 "type = (signed |unsigned |)char \\\[2\\\]" \
149 gdb_test "whatis v_signed_char_array" \
150 "type = (signed |unsigned |)char \\\[2\\\]" \
151 "whatis signed char array"
153 gdb_test "whatis v_unsigned_char_array" \
154 "type = unsigned char \\\[2\\\]" \
155 "whatis unsigned char array"
157 gdb_test "whatis v_short_array" \
158 "type = (short|short int) \\\[2\\\]" \
161 gdb_test "whatis v_signed_short_array" \
162 "type = (signed |)(short|short int) \\\[2\\\]" \
163 "whatis signed short array"
165 gdb_test "whatis v_unsigned_short_array" \
166 "type = (unsigned short|short unsigned int) \\\[2\\\]" \
167 "whatis unsigned short array"
169 gdb_test "whatis v_int_array" \
170 "type = int \\\[2\\\]" \
173 gdb_test "whatis v_signed_int_array" \
174 "type = (signed |)int \\\[2\\\]" \
175 "whatis signed int array"
177 gdb_test "whatis v_unsigned_int_array" \
178 "type = unsigned int \\\[2\\\]" \
179 "whatis unsigned int array"
181 # We already tested whether long prints as long, so here we accept int
182 # No need for more than one xfail for the same thing.
183 gdb_test "whatis v_long_array" \
184 "type = (int|long|long int) \\\[2\\\]" \
187 gdb_test "whatis v_signed_long_array" \
188 "type = (signed |)(int|long|long int) \\\[2\\\]" \
189 "whatis signed long array"
191 gdb_test "whatis v_unsigned_long_array" \
192 "type = (unsigned (int|long|long int)|long unsigned int) \\\[2\\\]" \
193 "whatis unsigned long array"
195 if ![target_info exists no_long_long] {
196 gdb_test "whatis v_unsigned_long_long_array" \
197 "type = (unsigned long long|long long unsigned int) \\\[2\\\]" \
198 "whatis unsigned long long array"
201 gdb_test "whatis v_float_array" \
202 "type = float \\\[2\\\]" \
205 gdb_test "whatis v_double_array" \
206 "type = double \\\[2\\\]" \
207 "whatis double array"
209 # test whatis command with pointers
211 # We already tested whether char prints as char, so accept various perversions
212 # here. We especially want to make sure we test that it doesn't print as
214 gdb_test "whatis v_char_pointer" \
215 "type = (unsigned |signed |)char \\*" \
216 "whatis char pointer"
218 gdb_test "whatis v_signed_char_pointer" \
219 "type = (unsigned |signed |)char \\*" \
220 "whatis signed char pointer"
222 gdb_test "whatis v_unsigned_char_pointer" \
223 "type = unsigned char \\*" \
224 "whatis unsigned char pointer"
226 gdb_test "whatis v_short_pointer" \
227 "type = (short|short int) \\*" \
228 "whatis short pointer"
230 gdb_test "whatis v_signed_short_pointer" \
231 "type = (signed |)(short|short int) \\*" \
232 "whatis signed short pointer"
234 gdb_test "whatis v_unsigned_short_pointer" \
235 "type = (unsigned short|short unsigned int) \\*" \
236 "whatis unsigned short pointer"
238 gdb_test "whatis v_int_pointer" \
242 gdb_test "whatis v_signed_int_pointer" \
243 "type = (signed |)int \\*" \
244 "whatis signed int pointer"
246 gdb_test "whatis v_unsigned_int_pointer" \
247 "type = unsigned int \\*" \
248 "whatis unsigned int pointer"
250 # We already tested whether long prints as long, so here we accept int
251 gdb_test "whatis v_long_pointer" \
252 "type = (long|int|long int) \\*" \
253 "whatis long pointer"
255 gdb_test "whatis v_signed_long_pointer" \
256 "type = (signed |)(long|int|long int) \\*" \
257 "whatis signed long pointer"
259 gdb_test "whatis v_unsigned_long_pointer" \
260 "type = (unsigned (int|long|long int)|long unsigned int) \\*" \
261 "whatis unsigned long pointer"
263 if ![target_info exists no_long_long] {
264 gdb_test "whatis v_long_long_pointer" \
265 "type = long long(| int) \\*" \
266 "whatis long long pointer"
268 gdb_test "whatis v_signed_long_long_pointer" \
269 "type = (signed |)long long(| int) \\*" \
270 "whatis signed long long pointer"
272 gdb_test "whatis v_unsigned_long_long_pointer" \
273 "type = (unsigned long long|long long unsigned int) \\*" \
274 "whatis unsigned long long pointer"
277 gdb_test "whatis v_float_pointer" \
279 "whatis float pointer"
281 gdb_test "whatis v_double_pointer" \
282 "type = double \\*" \
283 "whatis double pointer"
286 # test whatis command with structure types
288 # First with a type argument, with both "set print object" set to "on"
289 # and "off", ending with "off" for the following tests.
290 foreach_with_prefix print_object {"on" "off"} {
291 gdb_test_no_output "set print object $print_object"
293 gdb_test "whatis struct t_struct" \
294 "type = struct t_struct" \
295 "whatis named structure using type name"
297 gdb_test "whatis struct t_struct *" \
298 "type = struct t_struct \\*" \
299 "whatis named structure using type name and pointer"
301 gdb_test "whatis struct t_struct &" \
302 "type = struct t_struct &" \
303 "whatis named structure using type name and reference"
306 # Now with an expression argument.
308 gdb_test "whatis v_struct1" \
309 "type = struct t_struct" \
310 "whatis named structure"
312 gdb_test "whatis v_struct2" \
313 "type = struct \{\.\.\.\}" \
314 "whatis unnamed structure"
316 gdb_test "whatis &v_struct1" \
317 "type = struct t_struct \\*"
319 gdb_test "whatis &v_struct2" \
320 "type = struct {\\.\\.\\.} \\*"
322 gdb_test "whatis v_struct_ptr1" \
323 "type = struct t_struct \\*"
325 gdb_test "whatis v_struct_ptr2" \
326 "type = struct {\\.\\.\\.} \\*"
328 gdb_test "whatis &v_struct_ptr1" \
329 "type = struct t_struct \\*\\*"
331 gdb_test "whatis &v_struct_ptr2" \
332 "type = struct {\\.\\.\\.} \\*\\*"
334 gdb_test "whatis v_struct1.v_char_member" \
337 gdb_test "whatis v_struct2.v_char_member" \
340 gdb_test "whatis v_struct_ptr1->v_char_member" \
343 gdb_test "whatis v_struct_ptr2->v_char_member" \
346 gdb_test "whatis &(v_struct1.v_char_member)" \
349 gdb_test "whatis &(v_struct2.v_char_member)" \
352 gdb_test "whatis &(v_struct_ptr1->v_char_member)" \
355 gdb_test "whatis &(v_struct_ptr2->v_char_member)" \
358 # test whatis command with union types
359 gdb_test "whatis v_union" \
360 "type = union t_union" \
363 gdb_test "whatis union t_union" \
364 "type = union t_union" \
365 "whatis named union using type name"
367 gdb_test "whatis v_union2" \
368 "type = union \{\.\.\.\}" \
369 "whatis unnamed union"
371 gdb_test "whatis &v_union" \
372 "type = union t_union \\*"
374 gdb_test "whatis &v_union2" \
375 "type = union {\\.\\.\\.} \\*"
377 gdb_test "whatis v_union_ptr" \
378 "type = union t_union \\*"
380 gdb_test "whatis v_union_ptr2" \
381 "type = union {\\.\\.\\.} \\*"
383 gdb_test "whatis &v_union_ptr" \
384 "type = union t_union \\*\\*"
386 gdb_test "whatis &v_union_ptr2" \
387 "type = union {\\.\\.\\.} \\*\\*"
389 gdb_test "whatis v_union.v_char_member" \
392 gdb_test "whatis v_union2.v_char_member" \
395 gdb_test "whatis v_union_ptr->v_char_member" \
398 gdb_test "whatis v_union_ptr2->v_char_member" \
401 gdb_test "whatis &(v_union.v_char_member)" \
404 gdb_test "whatis &(v_union2.v_char_member)" \
407 gdb_test "whatis &(v_union_ptr->v_char_member)" \
410 gdb_test "whatis &(v_union_ptr2->v_char_member)" \
413 if { $dir == "dwarf" } {
414 # Using stabs we will mark these functions as prototyped. This
415 # is harmless but causes an extra VOID to be printed.
418 # test whatis command with functions return type
419 gdb_test "whatis v_char_func" \
420 "type = (signed |unsigned |)char \\($void\\)" \
421 "whatis char function"
423 gdb_test "whatis v_signed_char_func" \
424 "type = (signed |unsigned |)char \\($void\\)" \
425 "whatis signed char function"
427 gdb_test "whatis v_unsigned_char_func" \
428 "type = unsigned char \\($void\\)" \
429 "whatis unsigned char function"
431 gdb_test "whatis v_short_func" \
432 "type = short (int |)\\($void\\)" \
433 "whatis short function"
435 gdb_test "whatis v_signed_short_func" \
436 "type = (signed |)short (int |)\\($void\\)" \
437 "whatis signed short function"
439 gdb_test "whatis v_unsigned_short_func" \
440 "type = (unsigned short|short unsigned int) \\($void\\)" \
441 "whatis unsigned short function"
443 gdb_test "whatis v_int_func" \
444 "type = int \\($void\\)" \
445 "whatis int function"
447 gdb_test "whatis v_signed_int_func" \
448 "type = (signed |)int \\($void\\)" \
449 "whatis signed int function"
451 gdb_test "whatis v_unsigned_int_func" \
452 "type = unsigned int \\($void\\)" \
453 "whatis unsigned int function"
455 gdb_test "whatis v_long_func" \
456 "type = (long|int|long int) \\($void\\)" \
457 "whatis long function"
459 gdb_test "whatis v_signed_long_func" \
460 "type = (signed |)(int|long|long int) \\($void\\)" \
461 "whatis signed long function"
463 gdb_test "whatis v_unsigned_long_func" \
464 "type = (unsigned (int|long|long int)|long unsigned int) \\($void\\)" \
465 "whatis unsigned long function"
467 if ![target_info exists no_long_long] {
468 gdb_test "whatis v_long_long_func" \
469 "type = long long(| int) \\($void\\)" \
470 "whatis long long function"
472 gdb_test "whatis v_signed_long_long_func" \
473 "type = (signed |)long long(| int) \\($void\\)" \
474 "whatis signed long long function"
476 gdb_test "whatis v_unsigned_long_long_func" \
477 "type = (unsigned long long(| int)|long long unsigned int) \\($void\\)" \
478 "whatis unsigned long long function"
481 # Sun /bin/cc calls this a function returning double.
482 if {!$gcc_compiled} {setup_xfail "*-sun-sunos4*"}
483 gdb_test "whatis v_float_func" \
484 "type = float \\($void\\)" \
485 "whatis float function"
487 gdb_test "whatis v_double_func" \
488 "type = double \\($void\\)" \
489 "whatis double function" \
492 # test whatis command with some misc complicated types
493 gdb_test "whatis s_link" \
494 "type = struct link \\*" \
495 "whatis complicated structure"
497 gdb_test "whatis u_link" \
498 "type = union tu_link" \
499 "whatis complicated union"
502 # test whatis command with enumerations
503 gdb_test "whatis clunker" \
507 gdb_test "whatis enum cars" \
509 "whatis enumeration using type name"
512 # test whatis command with nested struct and union
513 gdb_test "whatis nested_su" \
514 "type = struct outer_struct" \
515 "whatis outer structure"
517 gdb_test "whatis nested_su.outer_int" \
519 "whatis outer structure member"
521 gdb_test "whatis nested_su.inner_struct_instance" \
522 "type = struct inner_struct" \
523 "whatis inner structure"
525 gdb_test "whatis nested_su.inner_struct_instance.inner_int" \
527 "whatis inner structure member"
529 gdb_test "whatis nested_su.inner_union_instance" \
530 "type = union inner_union" \
533 gdb_test "whatis nested_su.inner_union_instance.inner_union_int" \
535 "whatis inner union member"
537 # test whatis command with typedefs
539 gdb_test "whatis char_addr" \
541 "whatis using typedef type name"
543 if { $dir == "dwarf" } {
544 gdb_test "whatis a_char_addr" \
546 "whatis applied to variable defined by typedef"
549 # Regression tests for PR 9514.
551 gdb_test "whatis void (**)()" \
552 "type = void \\(\\*\\*\\)\\(\\)" \
553 "whatis applied to pointer to pointer to function"
555 gdb_test "whatis void (** const)()" \
556 "type = void \\(\\*\\* const\\)\\(\\)" \
557 "whatis applied to const pointer to pointer to function"
559 gdb_test "whatis void (* const *)()" \
560 "type = void \\(\\* const \\*\\)\\(\\)" \
561 "whatis applied to pointer to const pointer to function"
563 gdb_test "whatis int *(*)()" \
564 "type = int \\*\\(\\*\\)\\(\\)" \
565 "whatis applied to pointer to function returning pointer to int"
567 gdb_test "whatis int *(**)()" \
568 "type = int \\*\\(\\*\\*\\)\\(\\)" \
569 "whatis applied to pointer to pointer to function returning pointer to int"
571 gdb_test "whatis char (*(*)())\[23\]" \
572 "type = char \\(\\*\\(\\*\\)\\(\\)\\)\\\[23\\\]" \
573 "whatis applied to pointer to function returning pointer to array"
575 gdb_test "whatis int (*)(int, int)" \
576 "type = int \\(\\*\\)\\(int, int\\)" \
577 "whatis applied to pointer to function taking int,int and returning int"
579 gdb_test "whatis int (*)(const int *, ...)" \
580 "type = int \\(\\*\\)\\(const int \\*, \\.\\.\\.\\)" \
581 "whatis applied to pointer to function taking const int ptr and varargs and returning int"
583 gdb_test "whatis int (*)(void, int, int)" \
584 "parameter types following 'void'" \
585 "whatis applied to function with types trailing 'void'"
587 gdb_test "whatis int (*)(int, void, int)" \
588 "'void' invalid as parameter type" \
589 "whatis applied to function with 'void' parameter type"
593 lappend ctf_opts additional_flags=-gctf
594 lappend ctf_opts ldflags=-Wl,--ctf-variables
596 # Build up the set of debug formats for which we will run this test.
597 set specs { {dwarf {debug}} }
598 if {[allow_ctf_tests]} {
599 lappend specs [list ctf $ctf_opts]
602 # Setup and run the test for each debug format.
603 foreach testspec $specs {
604 set prefix [lindex $testspec 0]
605 set opts [lindex $testspec 1]
607 with_test_prefix $prefix {
608 remote_exec host "mkdir -p [standard_output_file ${prefix}]"
609 do_test $prefix $opts