1# Copyright 1988-2020 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
22if [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
28standard_testfile .c
29
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.
34
35proc setup_xfail_on_long_vs_int {} {
36    global gcc_compiled
37
38    if {!$gcc_compiled} {
39	setup_xfail "*-sun-sunos4*" "i*86-sequent-bsd*"
40    }
41}
42
43# Compile the test using OPTIONS into a sub-directory DIR, and then
44# run the test.
45proc do_test {dir options} {
46    global srcfile testfile gcc_compiled
47
48    set binfile [standard_output_file ${dir}/${testfile}]
49    if { [prepare_for_testing "failed to prepare" ${binfile} \
50	      [list $srcfile] $options] } {
51	return 0
52    }
53
54    clean_restart ${binfile}
55
56    #
57    # Test whatis command with basic C types
58    #
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
61    # native compilers.
62    #
63
64    gdb_test "whatis v_char" \
65	"type = (unsigned char|char)" \
66	"whatis char"
67
68    gdb_test "whatis v_signed_char" \
69	"type = (signed char|char)" \
70	"whatis signed char"
71
72    gdb_test "whatis v_unsigned_char" \
73	"type = unsigned char" \
74	"whatis unsigned char"
75
76    gdb_test "whatis v_short" \
77	"type = (short|short int)" \
78	"whatis short"
79
80    gdb_test "whatis v_signed_short" \
81	"type = (short|short int|signed short|signed short int)" \
82	"whatis signed short"
83
84    gdb_test "whatis v_unsigned_short" \
85	"type = (unsigned short|short unsigned int)" \
86	"whatis unsigned short"
87
88    gdb_test "whatis v_int" \
89	"type = int" \
90	"whatis int"
91
92    gdb_test "whatis v_signed_int" \
93	"type = (signed |)int" \
94	"whatis signed int"
95
96    gdb_test "whatis v_unsigned_int" \
97	"type = unsigned int" \
98	"whatis unsigned int"
99
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)" \
105	"whatis long"
106
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)" \
112	"whatis signed long"
113
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"
118
119
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"
124    }
125
126    gdb_test "whatis v_float" \
127	"type = float" \
128	"whatis float"
129
130    gdb_test "whatis v_double" \
131	"type = double" \
132	"whatis double"
133
134
135    # test whatis command with arrays
136    #
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\\\]" \
142	"whatis char array"
143
144    gdb_test "whatis v_signed_char_array" \
145	"type = (signed |unsigned |)char \\\[2\\\]" \
146	"whatis signed char array"
147
148    gdb_test "whatis v_unsigned_char_array" \
149	"type = unsigned char \\\[2\\\]" \
150	"whatis unsigned char array"
151
152    gdb_test "whatis v_short_array" \
153	"type = (short|short int) \\\[2\\\]" \
154	"whatis short array"
155
156    gdb_test "whatis v_signed_short_array" \
157	"type = (signed |)(short|short int) \\\[2\\\]" \
158	"whatis signed short array"
159
160    gdb_test "whatis v_unsigned_short_array" \
161	"type = (unsigned short|short unsigned int) \\\[2\\\]" \
162	"whatis unsigned short array"
163
164    gdb_test "whatis v_int_array" \
165	"type = int \\\[2\\\]" \
166	"whatis int array"
167
168    gdb_test "whatis v_signed_int_array" \
169	"type = (signed |)int \\\[2\\\]" \
170	"whatis signed int array"
171
172    gdb_test "whatis v_unsigned_int_array" \
173	"type = unsigned int \\\[2\\\]" \
174	"whatis unsigned int array"
175
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\\\]" \
180	"whatis long array"
181
182    gdb_test "whatis v_signed_long_array" \
183	"type = (signed |)(int|long|long int) \\\[2\\\]" \
184	"whatis signed long array"
185
186    gdb_test "whatis v_unsigned_long_array" \
187	"type = (unsigned (int|long|long int)|long unsigned int) \\\[2\\\]" \
188	"whatis unsigned long array"
189
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"
194    }
195
196    gdb_test "whatis v_float_array" \
197	"type = float \\\[2\\\]" \
198	"whatis float array"
199
200    gdb_test "whatis v_double_array" \
201	"type = double \\\[2\\\]" \
202	"whatis double array"
203
204    # test whatis command with pointers
205    #
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
208    # caddr_t.
209    gdb_test "whatis v_char_pointer" \
210	"type = (unsigned |signed |)char \\*" \
211	"whatis char pointer"
212
213    gdb_test "whatis v_signed_char_pointer" \
214	"type = (unsigned |signed |)char \\*" \
215	"whatis signed char pointer"
216
217    gdb_test "whatis v_unsigned_char_pointer" \
218	"type = unsigned char \\*" \
219	"whatis unsigned char pointer"
220
221    gdb_test "whatis v_short_pointer" \
222	"type = (short|short int) \\*" \
223	"whatis short pointer"
224
225    gdb_test "whatis v_signed_short_pointer" \
226	"type = (signed |)(short|short int) \\*" \
227	"whatis signed short pointer"
228
229    gdb_test "whatis v_unsigned_short_pointer" \
230	"type = (unsigned short|short unsigned int) \\*" \
231	"whatis unsigned short pointer"
232
233    gdb_test "whatis v_int_pointer" \
234	"type = int \\*" \
235	"whatis int pointer"
236
237    gdb_test "whatis v_signed_int_pointer" \
238	"type = (signed |)int \\*" \
239	"whatis signed int pointer"
240
241    gdb_test "whatis v_unsigned_int_pointer" \
242	"type = unsigned int \\*" \
243	"whatis unsigned int pointer"
244
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"
249
250    gdb_test "whatis v_signed_long_pointer" \
251	"type = (signed |)(long|int|long int) \\*" \
252	"whatis signed long pointer"
253
254    gdb_test "whatis v_unsigned_long_pointer" \
255	"type = (unsigned (int|long|long int)|long unsigned int) \\*" \
256	"whatis unsigned long pointer"
257
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"
262
263	gdb_test "whatis v_signed_long_long_pointer" \
264	    "type = (signed |)long long(| int) \\*" \
265	    "whatis signed long long pointer"
266
267	gdb_test "whatis v_unsigned_long_long_pointer" \
268	    "type = (unsigned long long|long long unsigned int) \\*" \
269	    "whatis unsigned long long pointer"
270    }
271
272    gdb_test "whatis v_float_pointer" \
273	"type = float \\*" \
274	"whatis float pointer"
275
276    gdb_test "whatis v_double_pointer" \
277	"type = double \\*" \
278	"whatis double pointer"
279
280
281    # test whatis command with structure types
282
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"
287
288	gdb_test "whatis struct t_struct" \
289	    "type = struct t_struct" \
290	    "whatis named structure using type name"
291
292	gdb_test "whatis struct t_struct *" \
293	    "type = struct t_struct \\*" \
294	    "whatis named structure using type name and pointer"
295
296	gdb_test "whatis struct t_struct &" \
297	    "type = struct t_struct &" \
298	    "whatis named structure using type name and reference"
299    }
300
301    # Now with an expression argument.
302
303    gdb_test "whatis v_struct1" \
304	"type = struct t_struct" \
305	"whatis named structure"
306
307    gdb_test "whatis v_struct2" \
308	"type = struct \{\.\.\.\}" \
309	"whatis unnamed structure"
310
311    gdb_test "whatis &v_struct1" \
312	"type = struct t_struct \\*"
313
314    gdb_test "whatis &v_struct2" \
315	"type = struct {\\.\\.\\.} \\*"
316
317    gdb_test "whatis v_struct_ptr1" \
318	"type = struct t_struct \\*"
319
320    gdb_test "whatis v_struct_ptr2" \
321	"type = struct {\\.\\.\\.} \\*"
322
323    gdb_test "whatis &v_struct_ptr1" \
324	"type = struct t_struct \\*\\*"
325
326    gdb_test "whatis &v_struct_ptr2" \
327	"type = struct {\\.\\.\\.} \\*\\*"
328
329    gdb_test "whatis v_struct1.v_char_member" \
330	"type = char"
331
332    gdb_test "whatis v_struct2.v_char_member" \
333	"type = char"
334
335    gdb_test "whatis v_struct_ptr1->v_char_member" \
336	"type = char"
337
338    gdb_test "whatis v_struct_ptr2->v_char_member" \
339	"type = char"
340
341    gdb_test "whatis &(v_struct1.v_char_member)" \
342	"type = char \\*"
343
344    gdb_test "whatis &(v_struct2.v_char_member)" \
345	"type = char \\*"
346
347    gdb_test "whatis &(v_struct_ptr1->v_char_member)" \
348	"type = char \\*"
349
350    gdb_test "whatis &(v_struct_ptr2->v_char_member)" \
351	"type = char \\*"
352
353    # test whatis command with union types
354    gdb_test "whatis v_union" \
355	"type = union t_union" \
356	"whatis named union"
357
358    gdb_test "whatis union t_union" \
359	"type = union t_union" \
360	"whatis named union using type name"
361
362    gdb_test "whatis v_union2" \
363	"type = union \{\.\.\.\}" \
364	"whatis unnamed union"
365
366    gdb_test "whatis &v_union" \
367	"type = union t_union \\*"
368
369    gdb_test "whatis &v_union2" \
370	"type = union {\\.\\.\\.} \\*"
371
372    gdb_test "whatis v_union_ptr" \
373	"type = union t_union \\*"
374
375    gdb_test "whatis v_union_ptr2" \
376	"type = union {\\.\\.\\.} \\*"
377
378    gdb_test "whatis &v_union_ptr" \
379	"type = union t_union \\*\\*"
380
381    gdb_test "whatis &v_union_ptr2" \
382	"type = union {\\.\\.\\.} \\*\\*"
383
384    gdb_test "whatis v_union.v_char_member" \
385	"type = char"
386
387    gdb_test "whatis v_union2.v_char_member" \
388	"type = char"
389
390    gdb_test "whatis v_union_ptr->v_char_member" \
391	"type = char"
392
393    gdb_test "whatis v_union_ptr2->v_char_member" \
394	"type = char"
395
396    gdb_test "whatis &(v_union.v_char_member)" \
397	"type = char \\*"
398
399    gdb_test "whatis &(v_union2.v_char_member)" \
400	"type = char \\*"
401
402    gdb_test "whatis &(v_union_ptr->v_char_member)" \
403	"type = char \\*"
404
405    gdb_test "whatis &(v_union_ptr2->v_char_member)" \
406	"type = char \\*"
407
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.
411	set void "(void|)"
412
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"
417
418	gdb_test "whatis v_signed_char_func" \
419	    "type = (signed |unsigned |)char \\($void\\)" \
420	    "whatis signed char function"
421
422	gdb_test "whatis v_unsigned_char_func" \
423	    "type = unsigned char \\($void\\)"	\
424	    "whatis unsigned char function"
425
426	gdb_test "whatis v_short_func" \
427	    "type = short (int |)\\($void\\)" \
428	    "whatis short function"
429
430	gdb_test "whatis v_signed_short_func" \
431	    "type = (signed |)short (int |)\\($void\\)" \
432	    "whatis signed short function"
433
434	gdb_test "whatis v_unsigned_short_func" \
435	    "type = (unsigned short|short unsigned int) \\($void\\)" \
436	    "whatis unsigned short function"
437
438	gdb_test "whatis v_int_func" \
439	    "type = int \\($void\\)" \
440	    "whatis int function"
441
442	gdb_test "whatis v_signed_int_func" \
443	    "type = (signed |)int \\($void\\)" \
444	    "whatis signed int function"
445
446	gdb_test "whatis v_unsigned_int_func" \
447	    "type = unsigned int \\($void\\)" \
448	    "whatis unsigned int function"
449
450	gdb_test "whatis v_long_func" \
451	    "type = (long|int|long int) \\($void\\)" \
452	    "whatis long function"
453
454	gdb_test "whatis v_signed_long_func" \
455	    "type = (signed |)(int|long|long int) \\($void\\)" \
456	    "whatis signed long function"
457
458	gdb_test "whatis v_unsigned_long_func" \
459	    "type = (unsigned (int|long|long int)|long unsigned int) \\($void\\)" \
460	    "whatis unsigned long function"
461
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"
466
467	    gdb_test "whatis v_signed_long_long_func" \
468		"type = (signed |)long long(| int) \\($void\\)" \
469		"whatis signed long long function"
470
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"
474	}
475
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"
481
482	gdb_test "whatis v_double_func" \
483	    "type = double \\($void\\)" \
484	    "whatis double function" \
485	}
486
487    # test whatis command with some misc complicated types
488    gdb_test "whatis s_link" \
489	"type = struct link \\*" \
490	"whatis complicated structure"
491
492    gdb_test "whatis u_link" \
493	"type = union tu_link" \
494	"whatis complicated union"
495
496
497    # test whatis command with enumerations
498    gdb_test "whatis clunker" \
499	"type = enum cars" \
500	"whatis enumeration"
501
502    gdb_test "whatis enum cars" \
503	"type = enum cars" \
504	"whatis enumeration using type name"
505
506
507    # test whatis command with nested struct and union
508    gdb_test "whatis nested_su" \
509	"type = struct outer_struct" \
510	"whatis outer structure"
511
512    gdb_test "whatis nested_su.outer_int" \
513	"type = int" \
514	"whatis outer structure member"
515
516    gdb_test "whatis nested_su.inner_struct_instance" \
517	"type = struct inner_struct" \
518	"whatis inner structure"
519
520    gdb_test "whatis nested_su.inner_struct_instance.inner_int" \
521	"type = int" \
522	"whatis inner structure member"
523
524    gdb_test "whatis nested_su.inner_union_instance" \
525	"type = union inner_union" \
526	"whatis inner union"
527
528    gdb_test "whatis nested_su.inner_union_instance.inner_union_int" \
529	"type = int" \
530	"whatis inner union member"
531
532    # test whatis command with typedefs
533
534    gdb_test "whatis char_addr" \
535	"type = char \\*" \
536	"whatis using typedef type name"
537
538    if { $dir == "dwarf" } {
539	gdb_test "whatis a_char_addr" \
540	    "type = char_addr" \
541	    "whatis applied to variable defined by typedef"
542    }
543
544    # Regression tests for PR 9514.
545
546    gdb_test "whatis void (**)()" \
547	"type = void \\(\\*\\*\\)\\(\\)" \
548	"whatis applied to pointer to pointer to function"
549
550    gdb_test "whatis void (** const)()" \
551	"type = void \\(\\*\\* const\\)\\(\\)" \
552	"whatis applied to const pointer to pointer to function"
553
554    gdb_test "whatis void (* const *)()" \
555	"type = void \\(\\* const \\*\\)\\(\\)" \
556	"whatis applied to pointer to const pointer to function"
557
558    gdb_test "whatis int *(*)()" \
559	"type = int \\*\\(\\*\\)\\(\\)" \
560	"whatis applied to pointer to function returning pointer to int"
561
562    gdb_test "whatis int *(**)()" \
563	"type = int \\*\\(\\*\\*\\)\\(\\)" \
564	"whatis applied to pointer to pointer to function returning pointer to int"
565
566    gdb_test "whatis char (*(*)())\[23\]" \
567	"type = char \\(\\*\\(\\*\\)\\(\\)\\)\\\[23\\\]" \
568	"whatis applied to pointer to function returning pointer to array"
569
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"
573
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"
577
578    gdb_test "whatis int (*)(void, int, int)" \
579	"parameter types following 'void'" \
580	"whatis applied to function with types trailing 'void'"
581
582    gdb_test "whatis int (*)(int, void, int)" \
583	"'void' invalid as parameter type" \
584	"whatis applied to function with 'void' parameter type"
585}
586
587# Build up the set of debug formats for which we will run this test.
588set specs { {dwarf {debug}} }
589if ![skip_ctf_tests] {
590    lappend specs {ctf {"additional_flags=-gt"}}
591}
592
593# Setup and run the test for each debug format.
594foreach testspec $specs {
595    set prefix [lindex $testspec 0]
596    set opts [lindex $testspec 1]
597
598    with_test_prefix $prefix {
599	remote_exec host "mkdir -p [standard_output_file ${prefix}]"
600	do_test $prefix $opts
601    }
602}
603