]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/ctf-ptype.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / ctf-ptype.exp
1 # Copyright 2019-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 is a subset of ptype.exp written by Rob Savoye. (rob@cygnus.com)
17
18 if [skip_ctf_tests] {
19 unsupported "no CTF debug format support, or CTF disabled in GDB"
20 return 0
21 }
22
23 # Some tests require GCC.
24 set gcc_compiled [is_c_compiler_gcc]
25
26 standard_testfile .c
27
28 # Using `-gctf` generates full-fledged CTF debug information.
29 set opts {}
30 lappend opts additional_flags=-gctf
31 lappend opts ldflags=-Wl,--strip-debug
32 lappend opts ldflags=-Wl,--ctf-variables
33 lappend opts nowarnings
34
35 if { [prepare_for_testing "failed to prepare" ${testfile} \
36 [list $srcfile] $opts] } {
37 return 0
38 }
39
40 # Test ptype of unnamed enumeration members before any action causes
41 # the partial symbol table to be expanded to full symbols. This fails
42 # with stabs compilers which fail to use a nameless stab (such as
43 # pre-2.4.5 versions of gcc and most non-gcc compilers).
44
45 gdb_test_multiple "ptype red1" "ptype unnamed enumeration member" {
46 -re "type = enum primary1_tag \{red1, green1, blue1\}.*$gdb_prompt $" {
47 # The workaround is in effect. As this is a compiler, not GDB,
48 # bug, we'll make it a PASS but perhaps it should be an XFAIL.
49 pass "ptype unnamed enumeration member (worked around)"
50 }
51 -re "type = enum \{red1, green1, blue1\}.*$gdb_prompt $" {
52 pass "ptype unnamed enumeration member"
53 }
54 }
55
56 #
57 # test ptype command with structures
58 #
59 # Here and elsewhere, we accept
60 # "long", "long int", or "int" for long variables (whatis.exp already
61 # has an XFAIL for "int" (Sun cc bug), so no need to fail it here).
62 gdb_test "ptype struct t_struct" "type = struct t_struct \{.*\[\r\n\] (unsigned |)char v_char_member;.*\[\r\n\] (short|short int) v_short_member;.*\[\r\n\] int v_int_member;.*\[\r\n\] (long|long int|int) v_long_member;.*\[\r\n\] float v_float_member;.*\[\r\n\] double v_double_member;.*\[\r\n\]\}.*" "ptype structure"
63
64
65 # Test the equivalence between '.' and '->' for struct member references.
66
67 if {[gdb_test "ptype v_struct1.v_float_member" "type = float"] < 0} {
68 return -1
69 }
70 if {[gdb_test "ptype v_struct1->v_float_member" "type = float"] < 0} {
71 return -1
72 }
73 if {[gdb_test "ptype v_t_struct_p.v_float_member" "type = float"] < 0} {
74 return -1
75 }
76 if {[gdb_test "ptype v_t_struct_p->v_float_member" "type = float"] < 0} {
77 return -1
78 }
79
80 gdb_test "ptype struct link" "type = struct link \{\[\r\n\]+\[ \t\]+struct link \\*next;\[\r\n\]+\[ \t\]+struct link \\*\\(\\*linkfunc\\)\\((struct link \\*, int|void|)\\);\[\r\n\]+\[ \t\]+struct t_struct stuff.3.;\[\r\n\]+\}.*" "ptype linked list structure"
81
82 #
83 # test ptype command with unions
84 #
85 gdb_test "ptype union t_union" "type = union t_union \{.*\[\r\n\] (unsigned |)char v_char_member;.*\[\r\n\] (short|short int) v_short_member;.*\[\r\n\] int v_int_member;.*\[\r\n\] (long|long int|int) v_long_member;.*\[\r\n\] float v_float_member;.*\[\r\n\] double v_double_member;.*\[\r\n\]\}.*" "ptype union"
86
87 #
88 # test ptype command with enums
89 #
90
91 gdb_test "ptype primary" "type = enum .red, green, blue.*" "ptype unnamed enumeration"
92
93 gdb_test "ptype enum colors" "type = enum colors \{yellow, purple, pink\}.*" "ptype named enumeration"
94
95
96 #
97 # test ptype command with enums as typedef
98 #
99 gdb_test "ptype boolean" "type = enum (boolean |)\{FALSE, TRUE\}.*" "ptype unnamed typedef'd enumeration"
100
101 gdb_test "list -q main" ".*"
102
103 # Same thing with struct and union.
104 gdb_test "ptype t_struct3" "type = struct (t_struct3 |)\{.*
105 *double v_double_member;.*
106 *int v_int_member;.*\}" "printing typedef'd struct"
107
108 gdb_test "ptype t_union3" "type = union (t_union3 |)\{.*
109 *double v_double_member;.*
110 *int v_int_member;.*\}" "printing typedef'd union"
111
112 gdb_test "ptype enum bvals" "type = enum bvals \{my_false, my_true\}.*" "ptype named typedef'd enumf'd enum"
113
114 #
115 # test ptype command with out-of-order enum values
116 #
117 gdb_test "ptype enum misordered" "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*" "ptype misordered enumeration"
118
119 #
120 # test ptype command with a named enum's value
121 #
122 gdb_test "ptype three" "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*" "ptype named enumeration member"
123
124 gdb_test "ptype red" "type = enum \{red, green, blue\}.*" "ptype unnamed enumeration member #2"
125
126 #
127 # test ptype command with arrays
128 #
129 gdb_test "ptype v_char_array" "type = char .2..*" "ptype char array"
130
131 gdb_test "ptype v_signed_char_array" "type = (|signed )char .2..*" "ptype signed char array"
132
133 gdb_test "ptype v_unsigned_char_array" "type = unsigned char .2..*" "ptype unsigned char array"
134
135 gdb_test "ptype v_int_array" "type = int .2..*" "ptype int array"
136
137 gdb_test "ptype v_signed_int_array" "type = int .2..*" "ptype signed int array"
138
139 gdb_test "ptype v_unsigned_int_array" "type = unsigned int .2..*" "ptype unsigned int array"
140
141 gdb_test "ptype v_long_array" "type = (long|int|long int) .2..*" "ptype long array"
142
143 gdb_test "ptype v_signed_long_array" "type = (long|int|long int) .2..*" "ptype signed long array"
144
145 gdb_test "ptype v_unsigned_long_array" "type = unsigned long .2..*" "ptype unsigned long array"
146
147 gdb_test "ptype v_float_array" "type = float .2..*" "ptype float array"
148
149 gdb_test "ptype v_double_array" "type = double .2..*" "ptype double array"
150
151 gdb_test "ptype pv_char_array" "type = (|unsigned )char \\(\\*\\)\\\[0?\\\]"
152
153 #
154 # test ptype command with pointers
155 #
156 gdb_test "ptype v_char_pointer" "type = char \*.*" "ptype char pointer"
157
158 gdb_test "ptype v_short_pointer" "type = short \*.*" "ptype short pointer"
159
160 gdb_test "ptype v_long_pointer" "type = long \*.*" "ptype long pointer"
161
162 gdb_test "ptype v_int_pointer" "type = int \*.*" "ptype int pointer"
163
164 gdb_test "ptype v_signed_long_pointer" "type = long \*.*" "ptype signed long pointer"
165
166 gdb_test "ptype v_unsigned_long_pointer" "type = unsigned long \*.*" "ptype unsigned long pointer"
167
168 gdb_test "ptype v_float_pointer" "type = float \*.*" "ptype float pointer"
169
170 gdb_test "ptype v_double_pointer" "type = double \*.*" "ptype double pointer"
171
172 #
173 # test ptype command with basic C types
174 #
175 gdb_test "ptype v_short" "type = short(| int).*" "ptype short"
176
177 gdb_test "ptype v_int" "type = int.*" "ptype int"
178
179 #
180 # test ptype command with nested structure and union
181 #
182 gdb_test "ptype struct outer_struct" "type = struct outer_struct \{.*\[\r\n\]+\
183 .*int outer_int;.*\[\r\n\]+\
184 .*(struct|) inner_struct inner_struct_instance;.*\[\r\n\]+\
185 .*(union|) inner_union inner_union_instance;.*\[\r\n\]+\
186 .*(long|long int|int) outer_long;.*\[\r\n\]\}.*" "ptype outer structure"
187
188 gdb_test "ptype struct inner_struct" "type = struct inner_struct \{.*\[\r\n\] int inner_int;.*\[\r\n\] (long|long int|int) inner_long;.*\[\r\n\]\}.*" "ptype inner structure"
189
190 gdb_test "ptype union inner_union" "type = union inner_union \{.*\[\r\n\] int inner_union_int;.*\[\r\n\] (long|long int|int) inner_union_long;.*\[\r\n\]\}.*" "ptype inner union"
191
192 gdb_test "ptype nested_su" "type = struct outer_struct \{.*\[\r\n\] int outer_int;.*\[\r\n\] (struct |)inner_struct inner_struct_instance;.*\[\r\n\] (union |)inner_union inner_union_instance;.*\[\r\n\] (long|long int|int) outer_long;.*\[\r\n\]\}.*" "ptype nested structure"
193
194 gdb_test "ptype nested_su.outer_int" "type = int.*" "ptype outer int"
195
196 gdb_test "ptype nested_su.inner_struct_instance" "type = struct inner_struct \{.*\[\r\n\] int inner_int;.*\[\r\n\] (long|long int|int) inner_long;.*\[\r\n\]\}.*" "ptype nested structure #2"
197
198 gdb_test "ptype nested_su.inner_struct_instance.inner_int" "type = int.*" "ptype inner int"
199
200 gdb_test "ptype nested_su.inner_union_instance" "type = union inner_union \{.*\[\r\n\] int inner_union_int;.*\[\r\n\] (long|long int|int) inner_union_long;.*\[\r\n\]\}.*" "ptype nested union"
201
202 # Print the type description of variable the_highest, and verify that
203 # the type description for the fields whose type is anonymous are
204 # correctly printed (at nesting level 1 and 2).
205
206 gdb_test "ptype the_highest" \
207 "type = struct highest \{.*\[\r\n\] *int a;.*\[\r\n\] *struct \{.*\[\r\n\] *int b;.*\[\r\n\] *struct \{\.\.\.\} anonymous_level_2;.*\[\r\n\] *\} anonymous_level_1;.*\[\r\n\]}.*" \
208 "ptype the_highest"
209
210 # Print the type descrption for one of the fields of variable the_highest.
211 # The purpose is to verify that the type of a field that was printed above
212 # as "struct {...}" is now printed in a more descriptive way (because the
213 # nesting level is now one level less).
214
215 gdb_test "ptype the_highest.anonymous_level_1" \
216 "type = struct \{.*\[\r\n\] *int b;.*\[\r\n\] *struct \{.*\[\r\n\] *int c;.*\[\r\n\] *\} anonymous_level_2;.*\[\r\n\]}.*" \
217 "ptype the_highest.anonymous_level_1"
218
219 # Print the type of the identifier ID, and check the response:
220 # - Expect to see PROTOTYPED as the type. PROTOTYPED is not a regular
221 # expression; it's a literal string.
222 # - If we instead see the unprototyped type PLAIN, and we're using STABS
223 # generated by GCC, that's an xfail; as of 9 Feb 2002, GCC never emits
224 # prototyped function types in STABS. Like PROTOTYPED, PLAIN is a
225 # literal string, not a regular expression.
226 # - If we see OVERPROTOTYPED, it's an xfail for RealView; RealView
227 # does not distinguish prototyped and unprototyped functions, and
228 # GDB defaults to prototyped.
229 # - Otherwise, it's a failure.
230 proc ptype_maybe_prototyped { id prototyped plain { overprototyped "NO-MATCH" } } {
231 global gdb_prompt
232 global gcc_compiled
233
234 # Turn the arguments, which are literal strings, into
235 # regular expressions by quoting any special characters they contain.
236 foreach var { prototyped plain overprototyped } {
237 eval "set val \$$var"
238 regsub -all "\[\]\[*()\]" $val "\\\\&" val
239 regsub -all "short int" $val "short( int)?" val
240 regsub -all "long int" $val "long( int)?" val
241 eval "set $var \$val"
242 }
243
244 gdb_test_multiple "ptype $id" "ptype $id" {
245 -re "type = $prototyped\[\r\n\]+$gdb_prompt $" {
246 pass "ptype $id"
247 }
248 -re "type = $plain\[\r\n\]+$gdb_prompt $" {
249 if {$gcc_compiled} { setup_xfail_format "stabs" }
250 fail "ptype $id (compiler doesn't emit prototyped types)"
251 }
252 -re "type = $overprototyped\[\r\n\]+$gdb_prompt $" {
253 if { [test_compiler_info "armcc-*"] } {
254 setup_xfail "*-*-*"
255 }
256 fail "ptype $id (compiler doesn't emit unprototyped types)"
257 }
258 }
259 }
260
261 ptype_maybe_prototyped "func_type" "int (*)(int (*)(int, float), float)" \
262 "int (*)()"
263 ptype_maybe_prototyped "old_fptr" "double (*)()" "double (*)()" \
264 "double (*)(void)"
265 ptype_maybe_prototyped "new_fptr" "double (*)()" "double (*)()"
266 ptype_maybe_prototyped "fptr" "int (*)(int, float)" "int (*)()"
267 ptype_maybe_prototyped "fptr2" "int *(*)(int (*)(int, float), float)" \
268 "int *(*)()"
269 ptype_maybe_prototyped "xptr" "int (*)(int (*)(), int (*)(), int)" \
270 "int (*)()" \
271 "int (*)(int (*)(void), int (*)(void), int)"
272 ptype_maybe_prototyped "ffptr" "int (*(*)(char))(short int)" \
273 "int (*(*)())()"
274 ptype_maybe_prototyped "fffptr" "int (*(*(*)(char))(short int))(long int)" \
275 "int (*(*(*)())())()"
276
277 # Test printing type of string constants and array constants, but
278 # requires a running process. These call malloc, and can take a long
279 # time to execute over a slow serial link, so increase the timeout.
280
281 if {[runto_main]} {
282
283 if [target_info exists gdb,cannot_call_functions] {
284 unsupported "this target can not call functions"
285 return
286 }
287
288 # We need to up this because this can be really slow on some boards.
289 # (malloc() is called as part of the test).
290 set prev_timeout $timeout
291 set timeout 60
292
293 gdb_test "ptype \"abc\"" "type = char \\\[4\\\]"
294 gdb_test "ptype {'a','b','c'}" "type = char \\\[3\\\]"
295 gdb_test "ptype {0,1,2}" "type = int \\\[3\\\]"
296 gdb_test "ptype {(long)0,(long)1,(long)2}" "type = long \\\[3\\\]"
297 gdb_test "ptype {(float)0,(float)1,(float)2}" "type = float \\\[3\\\]"
298 gdb_test "ptype {{0,1,2},{3,4,5}}" "type = int \\\[2\\\]\\\[3\\\]"
299 gdb_test "ptype {4,5,6}\[2\]" "type = int"
300 gdb_test "ptype *&{4,5,6}\[1\]" "Attempt to take address of value not located in memory."
301
302 set timeout $prev_timeout
303
304 # Test ptype of user register
305 gdb_test "ptype \$pc" "void \\(\\*\\)\\(\\)" "ptype \$pc"
306 }