]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/whatis.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / whatis.exp
1 # Copyright 1988-2023 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
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]
26 }
27
28 # Some tests require GCC.
29 set gcc_compiled [is_c_compiler_gcc]
30
31 standard_testfile .c
32
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.
37
38 proc setup_xfail_on_long_vs_int {} {
39 global gcc_compiled
40
41 if {!$gcc_compiled} {
42 setup_xfail "*-sun-sunos4*" "i*86-sequent-bsd*"
43 }
44 }
45
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
50
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 }
56
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 #
64
65 gdb_test "whatis v_char" \
66 "type = (unsigned char|char)" \
67 "whatis char"
68
69 gdb_test "whatis v_signed_char" \
70 "type = (signed char|char)" \
71 "whatis signed char"
72
73 gdb_test "whatis v_unsigned_char" \
74 "type = unsigned char" \
75 "whatis unsigned char"
76
77 gdb_test "whatis v_short" \
78 "type = (short|short int)" \
79 "whatis short"
80
81 gdb_test "whatis v_signed_short" \
82 "type = (short|short int|signed short|signed short int)" \
83 "whatis signed short"
84
85 gdb_test "whatis v_unsigned_short" \
86 "type = (unsigned short|short unsigned int)" \
87 "whatis unsigned short"
88
89 gdb_test "whatis v_int" \
90 "type = int" \
91 "whatis int"
92
93 gdb_test "whatis v_signed_int" \
94 "type = (signed |)int" \
95 "whatis signed int"
96
97 gdb_test "whatis v_unsigned_int" \
98 "type = unsigned int" \
99 "whatis unsigned int"
100
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"
107
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"
114
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"
119
120
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 }
126
127 gdb_test "whatis v_float" \
128 "type = float" \
129 "whatis float"
130
131 gdb_test "whatis v_double" \
132 "type = double" \
133 "whatis double"
134
135
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"
144
145 gdb_test "whatis v_signed_char_array" \
146 "type = (signed |unsigned |)char \\\[2\\\]" \
147 "whatis signed char array"
148
149 gdb_test "whatis v_unsigned_char_array" \
150 "type = unsigned char \\\[2\\\]" \
151 "whatis unsigned char array"
152
153 gdb_test "whatis v_short_array" \
154 "type = (short|short int) \\\[2\\\]" \
155 "whatis short array"
156
157 gdb_test "whatis v_signed_short_array" \
158 "type = (signed |)(short|short int) \\\[2\\\]" \
159 "whatis signed short array"
160
161 gdb_test "whatis v_unsigned_short_array" \
162 "type = (unsigned short|short unsigned int) \\\[2\\\]" \
163 "whatis unsigned short array"
164
165 gdb_test "whatis v_int_array" \
166 "type = int \\\[2\\\]" \
167 "whatis int array"
168
169 gdb_test "whatis v_signed_int_array" \
170 "type = (signed |)int \\\[2\\\]" \
171 "whatis signed int array"
172
173 gdb_test "whatis v_unsigned_int_array" \
174 "type = unsigned int \\\[2\\\]" \
175 "whatis unsigned int array"
176
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"
182
183 gdb_test "whatis v_signed_long_array" \
184 "type = (signed |)(int|long|long int) \\\[2\\\]" \
185 "whatis signed long array"
186
187 gdb_test "whatis v_unsigned_long_array" \
188 "type = (unsigned (int|long|long int)|long unsigned int) \\\[2\\\]" \
189 "whatis unsigned long array"
190
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 }
196
197 gdb_test "whatis v_float_array" \
198 "type = float \\\[2\\\]" \
199 "whatis float array"
200
201 gdb_test "whatis v_double_array" \
202 "type = double \\\[2\\\]" \
203 "whatis double array"
204
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"
213
214 gdb_test "whatis v_signed_char_pointer" \
215 "type = (unsigned |signed |)char \\*" \
216 "whatis signed char pointer"
217
218 gdb_test "whatis v_unsigned_char_pointer" \
219 "type = unsigned char \\*" \
220 "whatis unsigned char pointer"
221
222 gdb_test "whatis v_short_pointer" \
223 "type = (short|short int) \\*" \
224 "whatis short pointer"
225
226 gdb_test "whatis v_signed_short_pointer" \
227 "type = (signed |)(short|short int) \\*" \
228 "whatis signed short pointer"
229
230 gdb_test "whatis v_unsigned_short_pointer" \
231 "type = (unsigned short|short unsigned int) \\*" \
232 "whatis unsigned short pointer"
233
234 gdb_test "whatis v_int_pointer" \
235 "type = int \\*" \
236 "whatis int pointer"
237
238 gdb_test "whatis v_signed_int_pointer" \
239 "type = (signed |)int \\*" \
240 "whatis signed int pointer"
241
242 gdb_test "whatis v_unsigned_int_pointer" \
243 "type = unsigned int \\*" \
244 "whatis unsigned int pointer"
245
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"
250
251 gdb_test "whatis v_signed_long_pointer" \
252 "type = (signed |)(long|int|long int) \\*" \
253 "whatis signed long pointer"
254
255 gdb_test "whatis v_unsigned_long_pointer" \
256 "type = (unsigned (int|long|long int)|long unsigned int) \\*" \
257 "whatis unsigned long pointer"
258
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"
263
264 gdb_test "whatis v_signed_long_long_pointer" \
265 "type = (signed |)long long(| int) \\*" \
266 "whatis signed long long pointer"
267
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 }
272
273 gdb_test "whatis v_float_pointer" \
274 "type = float \\*" \
275 "whatis float pointer"
276
277 gdb_test "whatis v_double_pointer" \
278 "type = double \\*" \
279 "whatis double pointer"
280
281
282 # test whatis command with structure types
283
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"
288
289 gdb_test "whatis struct t_struct" \
290 "type = struct t_struct" \
291 "whatis named structure using type name"
292
293 gdb_test "whatis struct t_struct *" \
294 "type = struct t_struct \\*" \
295 "whatis named structure using type name and pointer"
296
297 gdb_test "whatis struct t_struct &" \
298 "type = struct t_struct &" \
299 "whatis named structure using type name and reference"
300 }
301
302 # Now with an expression argument.
303
304 gdb_test "whatis v_struct1" \
305 "type = struct t_struct" \
306 "whatis named structure"
307
308 gdb_test "whatis v_struct2" \
309 "type = struct \{\.\.\.\}" \
310 "whatis unnamed structure"
311
312 gdb_test "whatis &v_struct1" \
313 "type = struct t_struct \\*"
314
315 gdb_test "whatis &v_struct2" \
316 "type = struct {\\.\\.\\.} \\*"
317
318 gdb_test "whatis v_struct_ptr1" \
319 "type = struct t_struct \\*"
320
321 gdb_test "whatis v_struct_ptr2" \
322 "type = struct {\\.\\.\\.} \\*"
323
324 gdb_test "whatis &v_struct_ptr1" \
325 "type = struct t_struct \\*\\*"
326
327 gdb_test "whatis &v_struct_ptr2" \
328 "type = struct {\\.\\.\\.} \\*\\*"
329
330 gdb_test "whatis v_struct1.v_char_member" \
331 "type = char"
332
333 gdb_test "whatis v_struct2.v_char_member" \
334 "type = char"
335
336 gdb_test "whatis v_struct_ptr1->v_char_member" \
337 "type = char"
338
339 gdb_test "whatis v_struct_ptr2->v_char_member" \
340 "type = char"
341
342 gdb_test "whatis &(v_struct1.v_char_member)" \
343 "type = char \\*"
344
345 gdb_test "whatis &(v_struct2.v_char_member)" \
346 "type = char \\*"
347
348 gdb_test "whatis &(v_struct_ptr1->v_char_member)" \
349 "type = char \\*"
350
351 gdb_test "whatis &(v_struct_ptr2->v_char_member)" \
352 "type = char \\*"
353
354 # test whatis command with union types
355 gdb_test "whatis v_union" \
356 "type = union t_union" \
357 "whatis named union"
358
359 gdb_test "whatis union t_union" \
360 "type = union t_union" \
361 "whatis named union using type name"
362
363 gdb_test "whatis v_union2" \
364 "type = union \{\.\.\.\}" \
365 "whatis unnamed union"
366
367 gdb_test "whatis &v_union" \
368 "type = union t_union \\*"
369
370 gdb_test "whatis &v_union2" \
371 "type = union {\\.\\.\\.} \\*"
372
373 gdb_test "whatis v_union_ptr" \
374 "type = union t_union \\*"
375
376 gdb_test "whatis v_union_ptr2" \
377 "type = union {\\.\\.\\.} \\*"
378
379 gdb_test "whatis &v_union_ptr" \
380 "type = union t_union \\*\\*"
381
382 gdb_test "whatis &v_union_ptr2" \
383 "type = union {\\.\\.\\.} \\*\\*"
384
385 gdb_test "whatis v_union.v_char_member" \
386 "type = char"
387
388 gdb_test "whatis v_union2.v_char_member" \
389 "type = char"
390
391 gdb_test "whatis v_union_ptr->v_char_member" \
392 "type = char"
393
394 gdb_test "whatis v_union_ptr2->v_char_member" \
395 "type = char"
396
397 gdb_test "whatis &(v_union.v_char_member)" \
398 "type = char \\*"
399
400 gdb_test "whatis &(v_union2.v_char_member)" \
401 "type = char \\*"
402
403 gdb_test "whatis &(v_union_ptr->v_char_member)" \
404 "type = char \\*"
405
406 gdb_test "whatis &(v_union_ptr2->v_char_member)" \
407 "type = char \\*"
408
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|)"
413
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"
418
419 gdb_test "whatis v_signed_char_func" \
420 "type = (signed |unsigned |)char \\($void\\)" \
421 "whatis signed char function"
422
423 gdb_test "whatis v_unsigned_char_func" \
424 "type = unsigned char \\($void\\)" \
425 "whatis unsigned char function"
426
427 gdb_test "whatis v_short_func" \
428 "type = short (int |)\\($void\\)" \
429 "whatis short function"
430
431 gdb_test "whatis v_signed_short_func" \
432 "type = (signed |)short (int |)\\($void\\)" \
433 "whatis signed short function"
434
435 gdb_test "whatis v_unsigned_short_func" \
436 "type = (unsigned short|short unsigned int) \\($void\\)" \
437 "whatis unsigned short function"
438
439 gdb_test "whatis v_int_func" \
440 "type = int \\($void\\)" \
441 "whatis int function"
442
443 gdb_test "whatis v_signed_int_func" \
444 "type = (signed |)int \\($void\\)" \
445 "whatis signed int function"
446
447 gdb_test "whatis v_unsigned_int_func" \
448 "type = unsigned int \\($void\\)" \
449 "whatis unsigned int function"
450
451 gdb_test "whatis v_long_func" \
452 "type = (long|int|long int) \\($void\\)" \
453 "whatis long function"
454
455 gdb_test "whatis v_signed_long_func" \
456 "type = (signed |)(int|long|long int) \\($void\\)" \
457 "whatis signed long function"
458
459 gdb_test "whatis v_unsigned_long_func" \
460 "type = (unsigned (int|long|long int)|long unsigned int) \\($void\\)" \
461 "whatis unsigned long function"
462
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"
467
468 gdb_test "whatis v_signed_long_long_func" \
469 "type = (signed |)long long(| int) \\($void\\)" \
470 "whatis signed long long function"
471
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 }
476
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"
482
483 gdb_test "whatis v_double_func" \
484 "type = double \\($void\\)" \
485 "whatis double function" \
486 }
487
488 # test whatis command with some misc complicated types
489 gdb_test "whatis s_link" \
490 "type = struct link \\*" \
491 "whatis complicated structure"
492
493 gdb_test "whatis u_link" \
494 "type = union tu_link" \
495 "whatis complicated union"
496
497
498 # test whatis command with enumerations
499 gdb_test "whatis clunker" \
500 "type = enum cars" \
501 "whatis enumeration"
502
503 gdb_test "whatis enum cars" \
504 "type = enum cars" \
505 "whatis enumeration using type name"
506
507
508 # test whatis command with nested struct and union
509 gdb_test "whatis nested_su" \
510 "type = struct outer_struct" \
511 "whatis outer structure"
512
513 gdb_test "whatis nested_su.outer_int" \
514 "type = int" \
515 "whatis outer structure member"
516
517 gdb_test "whatis nested_su.inner_struct_instance" \
518 "type = struct inner_struct" \
519 "whatis inner structure"
520
521 gdb_test "whatis nested_su.inner_struct_instance.inner_int" \
522 "type = int" \
523 "whatis inner structure member"
524
525 gdb_test "whatis nested_su.inner_union_instance" \
526 "type = union inner_union" \
527 "whatis inner union"
528
529 gdb_test "whatis nested_su.inner_union_instance.inner_union_int" \
530 "type = int" \
531 "whatis inner union member"
532
533 # test whatis command with typedefs
534
535 gdb_test "whatis char_addr" \
536 "type = char \\*" \
537 "whatis using typedef type name"
538
539 if { $dir == "dwarf" } {
540 gdb_test "whatis a_char_addr" \
541 "type = char_addr" \
542 "whatis applied to variable defined by typedef"
543 }
544
545 # Regression tests for PR 9514.
546
547 gdb_test "whatis void (**)()" \
548 "type = void \\(\\*\\*\\)\\(\\)" \
549 "whatis applied to pointer to pointer to function"
550
551 gdb_test "whatis void (** const)()" \
552 "type = void \\(\\*\\* const\\)\\(\\)" \
553 "whatis applied to const pointer to pointer to function"
554
555 gdb_test "whatis void (* const *)()" \
556 "type = void \\(\\* const \\*\\)\\(\\)" \
557 "whatis applied to pointer to const pointer to function"
558
559 gdb_test "whatis int *(*)()" \
560 "type = int \\*\\(\\*\\)\\(\\)" \
561 "whatis applied to pointer to function returning pointer to int"
562
563 gdb_test "whatis int *(**)()" \
564 "type = int \\*\\(\\*\\*\\)\\(\\)" \
565 "whatis applied to pointer to pointer to function returning pointer to int"
566
567 gdb_test "whatis char (*(*)())\[23\]" \
568 "type = char \\(\\*\\(\\*\\)\\(\\)\\)\\\[23\\\]" \
569 "whatis applied to pointer to function returning pointer to array"
570
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"
574
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"
578
579 gdb_test "whatis int (*)(void, int, int)" \
580 "parameter types following 'void'" \
581 "whatis applied to function with types trailing 'void'"
582
583 gdb_test "whatis int (*)(int, void, int)" \
584 "'void' invalid as parameter type" \
585 "whatis applied to function with 'void' parameter type"
586 }
587
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
592
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]
597 }
598
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]
603
604 with_test_prefix $prefix {
605 remote_exec host "mkdir -p [standard_output_file ${prefix}]"
606 do_test $prefix $opts
607 }
608 }