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