]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright (C) 2009-2024 Free Software Foundation, Inc. |
bfd31e71 PM |
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 part of the GDB testsuite. It tests the mechanism | |
17 | # of exposing types to Python. | |
18 | ||
a2c09bd0 DE |
19 | load_lib gdb-python.exp |
20 | ||
b4a58790 | 21 | standard_testfile |
bfd31e71 PM |
22 | |
23 | # Build inferior to language specification. | |
db8e4570 UW |
24 | proc build_inferior {exefile lang} { |
25 | global srcdir subdir srcfile testfile hex | |
bfd31e71 | 26 | |
db8e4570 | 27 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${exefile}" executable "debug $lang"] != "" } { |
84c93cd5 | 28 | untested "failed to compile in $lang mode" |
bfd31e71 PM |
29 | return -1 |
30 | } | |
e019fd1d SM |
31 | |
32 | return 0 | |
bfd31e71 PM |
33 | } |
34 | ||
f6bbabf0 | 35 | # Restart GDB. |
db8e4570 | 36 | proc restart_gdb {exefile} { |
9b2234b0 | 37 | clean_restart $exefile |
bfd31e71 | 38 | |
b0e16ca5 | 39 | if {![runto_main]} { |
bfd31e71 PM |
40 | return |
41 | } | |
f6bbabf0 | 42 | } |
bfd31e71 | 43 | |
f6bbabf0 PM |
44 | # Set breakpoint and run to that breakpoint. |
45 | proc runto_bp {bp} { | |
bfd31e71 PM |
46 | gdb_breakpoint [gdb_get_line_number $bp] |
47 | gdb_continue_to_breakpoint $bp | |
48 | } | |
49 | ||
bfd31e71 | 50 | proc test_fields {lang} { |
6d67b990 AB |
51 | with_test_prefix "test_fields" { |
52 | global gdb_prompt | |
bfd31e71 | 53 | |
6d67b990 | 54 | # .fields() of a typedef should still return the underlying field list |
9325cb04 | 55 | gdb_test "python print (len(gdb.parse_and_eval('ts').type.fields()))" "2" \ |
6d67b990 | 56 | "$lang typedef field list" |
f6b47be4 | 57 | |
6d67b990 | 58 | if {$lang == "c++"} { |
bfd31e71 | 59 | # Test usage with a class |
8f28f522 | 60 | gdb_py_test_silent_cmd "print (c)" "print value (c)" 1 |
6d67b990 AB |
61 | gdb_py_test_silent_cmd "python c = gdb.history (0)" "get value (c) from history" 1 |
62 | gdb_py_test_silent_cmd "python fields = c.type.fields()" "get fields from c.type" 1 | |
cdc7edd7 LM |
63 | gdb_test "python print (len(fields))" "2" "check number of fields (c)" |
64 | gdb_test "python print (fields\[0\].name)" "c" "check class field c name" | |
65 | gdb_test "python print (fields\[1\].name)" "d" "check class field d name" | |
d839c8a4 | 66 | |
9325cb04 PK |
67 | gdb_test "python print (c.type == gdb.parse_and_eval('d').type)" "False" |
68 | gdb_test "python print (c.type == gdb.parse_and_eval('d').type.fields()\[0\].type)" \ | |
d839c8a4 | 69 | "True" |
bed91f4d SM |
70 | |
71 | # Test fields of a method (its parameters) | |
72 | gdb_test "python print (len (gdb.parse_and_eval ('C::a_method').type.fields ()))" "3" | |
73 | gdb_test "python print (gdb.parse_and_eval ('C::a_method').type.fields ()\[0\].type)" "C \\* const" | |
74 | gdb_test "python print (gdb.parse_and_eval ('C::a_method').type.fields ()\[1\].type)" "int" | |
75 | gdb_test "python print (gdb.parse_and_eval ('C::a_method').type.fields ()\[2\].type)" "char" | |
b3f9469b | 76 | gdb_test "python print (gdb.parse_and_eval ('c')\['a_method'\].type.fields ()\[0\].type)" "C \\* const" |
bed91f4d SM |
77 | |
78 | gdb_test "python print (len (gdb.parse_and_eval ('C::a_const_method').type.fields ()))" "3" | |
79 | gdb_test "python print (gdb.parse_and_eval ('C::a_const_method').type.fields ()\[0\].type)" "const C \\* const" | |
80 | gdb_test "python print (gdb.parse_and_eval ('C::a_const_method').type.fields ()\[1\].type)" "int" | |
81 | gdb_test "python print (gdb.parse_and_eval ('C::a_const_method').type.fields ()\[2\].type)" "char" | |
b3f9469b | 82 | gdb_test "python print (gdb.parse_and_eval ('c')\['a_const_method'\].type.fields ()\[0\].type)" "const C \\* const" |
bed91f4d SM |
83 | |
84 | gdb_test "python print (len (gdb.parse_and_eval ('C::a_static_method').type.fields ()))" "2" | |
85 | gdb_test "python print (gdb.parse_and_eval ('C::a_static_method').type.fields ()\[0\].type)" "int" | |
86 | gdb_test "python print (gdb.parse_and_eval ('C::a_static_method').type.fields ()\[1\].type)" "char" | |
b3f9469b | 87 | gdb_test "python print (gdb.parse_and_eval ('c')\['a_static_method'\].type.fields ()\[0\].type)" "int" |
6d67b990 | 88 | } |
bfd31e71 | 89 | |
6d67b990 | 90 | # Test normal fields usage in structs. |
8f28f522 | 91 | gdb_py_test_silent_cmd "print (st)" "print value (st)" 1 |
6d67b990 AB |
92 | gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value (st) from history" 1 |
93 | gdb_py_test_silent_cmd "python fields = st.type.fields()" "get fields from st.type" 1 | |
e1f2e1a2 CB |
94 | gdb_test "python print (st.type.objfile.filename == gdb.current_progspace ().filename)" "True" \ |
95 | "check type.objfile" | |
cdc7edd7 LM |
96 | gdb_test "python print (len(fields))" "2" "check number of fields (st)" |
97 | gdb_test "python print (fields\[0\].name)" "a" "check structure field a name" | |
98 | gdb_test "python print (fields\[1\].name)" "b" "check structure field b name" | |
6d67b990 | 99 | |
b5b08fb4 SC |
100 | # Test that unamed fields have 'None' for name. |
101 | gdb_py_test_silent_cmd "python ss = gdb.parse_and_eval('ss')" "init ss" 1 | |
102 | gdb_py_test_silent_cmd "python ss_fields = ss.type.fields()" \ | |
103 | "get fields from ss.type" 1 | |
cdc7edd7 | 104 | gdb_test "python print(len(ss_fields))" "2" "check length of ss_fields" |
d7fc3181 | 105 | gdb_test "python print(ss_fields\[0\].name is None)" "True" \ |
b5b08fb4 | 106 | "Check ss_fields\[0\].name" |
d7fc3181 | 107 | gdb_test "python print(ss_fields\[1\].name is None)" "True" \ |
b5b08fb4 | 108 | "Check ss_fields\[1\].name" |
6d67b990 AB |
109 | # Regression test for |
110 | # http://sourceware.org/bugzilla/show_bug.cgi?id=12070. | |
9325cb04 | 111 | gdb_test "python print ('type' in dir(fields\[0\]))" "True" \ |
6d67b990 AB |
112 | "Check that dir includes name" |
113 | ||
114 | # Test Python mapping behavior of gdb.Type for structs/classes | |
cdc7edd7 LM |
115 | gdb_test "python print (len(st.type))" "2" "check number of fields (st.type)" |
116 | gdb_test "python print (st.type\['a'\].name)" "a" "check fields lookup by name" | |
9325cb04 PK |
117 | gdb_test "python print (\[v.bitpos for v in st.type.itervalues()\])" {\[0L?, 32L?\]} "Check fields iteration over values" |
118 | gdb_test "python print (\[(n, v.bitpos) for (n, v) in st.type.items()\])" {\[\('a', 0L?\), \('b', 32L?\)\]} "Check fields items list" | |
cdc7edd7 LM |
119 | gdb_test "python print ('a' in st.type)" "True" "check field name exists test" |
120 | gdb_test "python print ('nosuch' in st.type)" "False" "check field name nonexists test" | |
121 | gdb_test "python print (not not st.type)" "True" "check conversion to bool" | |
6d67b990 AB |
122 | |
123 | # Test rejection of mapping operations on scalar types | |
bed91f4d SM |
124 | gdb_test "python print (len (st.type\['a'\].type))" "TypeError: Type is not a structure, union, enum, or function type.*" |
125 | gdb_test "python print (st.type\['a'\].type.has_key ('x'))" "TypeError: Type is not a structure, union, enum, or function type.*" | |
126 | gdb_test "python print (st.type\['a'\].type\['x'\])" "TypeError: Type is not a structure, union, enum, or function type.*" | |
127 | gdb_test "python print (st.type\['a'\].type.keys ())" "TypeError: Type is not a structure, union, enum, or function type.*" | |
6d67b990 AB |
128 | |
129 | # Test conversion to bool on scalar types | |
9325cb04 | 130 | gdb_test "python print (not not st.type\['a'\].type)" "True" |
7a81bdbf | 131 | |
6d67b990 | 132 | # Test regression PR python/10805 |
8f28f522 | 133 | gdb_py_test_silent_cmd "print (ar)" "print value (ar)" 1 |
6d67b990 AB |
134 | gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value (ar) from history" 1 |
135 | gdb_test "python fields = ar.type.fields()" | |
cdc7edd7 LM |
136 | gdb_test "python print (len(fields))" "1" "check the number of fields" |
137 | gdb_test "python print (fields\[0\].type)" "<range type>" "check array field type" | |
6d67b990 AB |
138 | |
139 | # Test gdb.Type.array. | |
9325cb04 | 140 | gdb_test "python print (ar\[0\].cast(ar\[0\].type.array(1)))" \ |
6d67b990 | 141 | ".1, 2." "cast to array with one argument" |
8f28f522 | 142 | gdb_test "python print (ar\[0\].cast(ar\[0\].type.array(0, 1)))" \ |
6d67b990 AB |
143 | ".1, 2." "cast to array with two arguments" |
144 | ||
9325cb04 | 145 | gdb_test "python print (ar\[0\].type == ar\[0\].type)" "True" |
6d67b990 AB |
146 | |
147 | # Test gdb.Type.vector. | |
148 | # Note: vectors cast differently than arrays. Here ar[0] is replicated | |
149 | # for the size of the vector. | |
8f28f522 | 150 | gdb_py_test_silent_cmd "print (vec_data_1)" "print value (vec_data_1)" 1 |
8954db33 AB |
151 | gdb_py_test_silent_cmd "python vec_data_1 = gdb.history (0)" "get value (vec_data_1) from history" 1 |
152 | ||
8f28f522 | 153 | gdb_py_test_silent_cmd "print (vec_data_2)" "print value (vec_data_2)" 1 |
8954db33 AB |
154 | gdb_py_test_silent_cmd "python vec_data_2 = gdb.history (0)" "get value (vec_data_2) from history" 1 |
155 | ||
156 | gdb_py_test_silent_cmd "python vec1 = vec_data_1.cast(ar\[0\].type.vector(1))" "set vec1" 1 | |
8f28f522 | 157 | gdb_test "python print (vec1)" ".1, 1." "cast to vector with one argument" |
8954db33 | 158 | gdb_py_test_silent_cmd "python vec2 = vec_data_1.cast(ar\[0\].type.vector(0, 1))" "set vec2" 1 |
8f28f522 PM |
159 | gdb_test "python print (vec2)" ".1, 1." "cast to vector with two arguments" |
160 | gdb_test "python print (vec1 == vec2)" "True" | |
8954db33 | 161 | gdb_py_test_silent_cmd "python vec3 = vec_data_2.cast(ar\[0\].type.vector(1))" "set vec3" 1 |
8f28f522 | 162 | gdb_test "python print (vec1 == vec3)" "False" |
bed91f4d SM |
163 | |
164 | # Test fields of a function (its parameters) | |
165 | gdb_test "python print (len (gdb.parse_and_eval ('a_function').type.fields ()))" "2" | |
166 | gdb_test "python print (gdb.parse_and_eval ('a_function').type.fields ()\[0\].type)" "int" | |
167 | gdb_test "python print (gdb.parse_and_eval ('a_function').type.fields ()\[1\].type)" "char" | |
fa94b3a7 SM |
168 | |
169 | # Test calling `fields` on a non-aggregate type. | |
170 | gdb_test "python gdb.lookup_type('int').fields()" "TypeError: Type is not a structure, union, enum, or function type.*" | |
6d67b990 | 171 | } |
bfd31e71 PM |
172 | } |
173 | ||
7a81bdbf | 174 | proc test_enums {} { |
6d67b990 | 175 | with_test_prefix "test_enum" { |
8f28f522 PM |
176 | gdb_py_test_silent_cmd "print (e)" "print value (e)" 1 |
177 | gdb_py_test_silent_cmd "python (e) = gdb.history (0)" "get value (e) from history" 1 | |
6d67b990 | 178 | gdb_py_test_silent_cmd "python fields = e.type.fields()" "extract type fields from e" 1 |
cdc7edd7 LM |
179 | gdb_test "python print (len(fields))" "3" "check the number of enum fields" |
180 | gdb_test "python print (fields\[0\].name)" "v1" "check enum field\[0\] name" | |
181 | gdb_test "python print (fields\[1\].name)" "v2" "check enum field\[1\]name" | |
6d67b990 AB |
182 | |
183 | # Ditto but by mapping operations | |
cdc7edd7 LM |
184 | gdb_test "python print (len(e.type))" "3" "check the number of type fields" |
185 | gdb_test "python print (e.type\['v1'\].name)" "v1" "check enum field lookup by name (v1)" | |
186 | gdb_test "python print (e.type\['v3'\].name)" "v3" "check enum field lookup by name (v3)" | |
9325cb04 PK |
187 | gdb_test "python print (\[v.enumval for v in e.type.itervalues()\])" {\[0L?, 1L?, 2L?\]} "Check num fields iteration over values" |
188 | gdb_test "python print (\[(n, v.enumval) for (n, v) in e.type.items()\])" {\[\('v1', 0L?\), \('v2', 1L?\), \('v3', 2L?\)\]} "Check enum fields items list" | |
6d67b990 | 189 | } |
7a81bdbf | 190 | } |
3cd14e45 | 191 | |
bfd31e71 | 192 | proc test_base_class {} { |
6d67b990 | 193 | with_test_prefix "test_base_class" { |
8f28f522 | 194 | gdb_py_test_silent_cmd "print (d)" "print value (d)" 1 |
6d67b990 AB |
195 | gdb_py_test_silent_cmd "python d = gdb.history (0)" "get value (d) from history" 1 |
196 | gdb_py_test_silent_cmd "python fields = d.type.fields()" "extract type fields from d" 1 | |
cdc7edd7 LM |
197 | gdb_test "python print (len(fields))" "3" "check the number of fields" |
198 | gdb_test "python print (fields\[0\].is_base_class)" "True" "check base class (fields\[0\])" | |
199 | gdb_test "python print (fields\[1\].is_base_class)" "False" "check base class (fields\[1\])" | |
6d67b990 | 200 | } |
bfd31e71 PM |
201 | } |
202 | ||
361ae042 | 203 | proc test_range {} { |
6d67b990 AB |
204 | with_test_prefix "test_range" { |
205 | with_test_prefix "on ranged value" { | |
206 | # Test a valid range request. | |
8f28f522 | 207 | gdb_py_test_silent_cmd "print (ar)" "print value (ar)" 1 |
6d67b990 | 208 | gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value (ar) from history" 1 |
cdc7edd7 LM |
209 | gdb_test "python print (len(ar.type.range()))" "2" "check correct tuple length" |
210 | gdb_test "python print (ar.type.range()\[0\])" "0" "check range low bound" | |
211 | gdb_test "python print (ar.type.range()\[1\])" "1" "check range high bound" | |
6d67b990 AB |
212 | } |
213 | ||
214 | with_test_prefix "on ranged type" { | |
215 | # Test a range request on a ranged type. | |
8f28f522 | 216 | gdb_py_test_silent_cmd "print (ar)" "print value (ar)" 1 |
6d67b990 AB |
217 | gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value (ar) from history" 1 |
218 | gdb_py_test_silent_cmd "python fields = ar.type.fields()" "get fields" 1 | |
cdc7edd7 LM |
219 | gdb_test "python print (fields\[0\].type.range()\[0\])" "0" "check range low bound" |
220 | gdb_test "python print (fields\[0\].type.range()\[1\])" "1" "check range high bound" | |
6d67b990 | 221 | } |
361ae042 | 222 | |
6d67b990 AB |
223 | with_test_prefix "on unranged value" { |
224 | # Test where a range does not exist. | |
8f28f522 | 225 | gdb_py_test_silent_cmd "print (st)" "print value (st)" 1 |
6d67b990 | 226 | gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value (st) from history" 1 |
cdc7edd7 | 227 | gdb_test "python print (st.type.range())" "RuntimeError: This type does not have a range.*" "check range for non ranged type." |
6d67b990 AB |
228 | } |
229 | } | |
361ae042 PM |
230 | } |
231 | ||
326fd672 TT |
232 | # Some tests of template arguments. |
233 | proc test_template {} { | |
234 | gdb_py_test_silent_cmd \ | |
235 | "python ttype = gdb.parse_and_eval('temvar').type" \ | |
236 | "get type of temvar" \ | |
237 | 1 | |
238 | ||
9325cb04 PK |
239 | gdb_test "python print (ttype.template_argument(0))" "D" |
240 | gdb_test "python print (isinstance(ttype.template_argument(0), gdb.Type))" \ | |
326fd672 | 241 | "True" |
999adef4 | 242 | |
326fd672 | 243 | # The next two tests require a GCC that emits DW_TAG_template_*. |
999adef4 DE |
244 | # GCC 4.4 does not emit it, 4.5 and 6 do emit it. |
245 | set have_older_gcc 0 | |
246 | if {[test_compiler_info {gcc-[0-3]-*}] | |
247 | || [test_compiler_info {gcc-4-[0-4]-*}]} { | |
248 | set have_older_gcc 1 | |
249 | } | |
250 | if $have_older_gcc { setup_xfail *-*-* } | |
9325cb04 | 251 | gdb_test "python print (ttype.template_argument(1))" "23" |
999adef4 | 252 | if $have_older_gcc { setup_xfail *-*-* } |
9325cb04 | 253 | gdb_test "python print (isinstance(ttype.template_argument(1), gdb.Value))" \ |
326fd672 | 254 | "True" |
999adef4 | 255 | |
72225e17 JK |
256 | if {[test_compiler_info {gcc-[0-3]-*}] |
257 | || [test_compiler_info {gcc-4-[0-5]-*}]} { | |
258 | setup_xfail "gcc/46955" *-*-* | |
259 | } | |
9325cb04 | 260 | gdb_test "python print (ttype.template_argument(2))" "&C::c" |
326fd672 | 261 | } |
361ae042 | 262 | |
551b380f AB |
263 | # Check the is_signed property of some types. |
264 | proc test_is_signed {lang} { | |
265 | if {$lang == "c++"} { | |
266 | gdb_test "python print(gdb.parse_and_eval ('c').type.is_signed)" \ | |
267 | "ValueError: Type must be a scalar type.*" | |
268 | gdb_test "python print(gdb.parse_and_eval ('&c').type.is_signed == False)" "True" | |
269 | } | |
270 | ||
271 | gdb_test "python print(gdb.parse_and_eval('global_unsigned_char').type.is_signed == False)" "True" | |
272 | gdb_test "python print(gdb.parse_and_eval('global_char').type.is_signed)" "True|False" | |
273 | gdb_test "python print(gdb.parse_and_eval('global_signed_char').type.is_signed == True)" "True" | |
274 | ||
275 | gdb_test "python print(gdb.parse_and_eval ('ss.x').type.is_signed == True)" "True" | |
276 | gdb_test "python print(gdb.parse_and_eval ('ss').type.is_signed)" \ | |
277 | "ValueError: Type must be a scalar type.*" | |
278 | gdb_test "python print(gdb.parse_and_eval ('uu').type.is_signed)" \ | |
279 | "ValueError: Type must be a scalar type.*" | |
280 | gdb_test "python print(gdb.parse_and_eval ('uu.i').type.is_signed == True)" "True" | |
281 | gdb_test "python print(gdb.parse_and_eval ('uu.f').type.is_signed == True)" "True" | |
282 | gdb_test "python print(gdb.parse_and_eval ('uu.a').type.is_signed)" \ | |
283 | "ValueError: Type must be a scalar type.*" | |
284 | ||
285 | gdb_test "python print(gdb.parse_and_eval ('&ss.x').type.is_signed == False)" "True" | |
286 | gdb_test "python print(gdb.parse_and_eval ('&uu').type.is_signed == False)" "True" | |
287 | } | |
288 | ||
f99e1c6d AB |
289 | # Compare the types of different symbols from the inferior, we're |
290 | # checking that the types of different sybols of the same declared | |
291 | # type, are equal (in Python). | |
292 | proc test_type_equality {} { | |
293 | ||
294 | foreach_with_prefix type { char int } { | |
295 | gdb_test_no_output "python v1 = gdb.parse_and_eval('global_unsigned_${type}')" | |
296 | gdb_test_no_output "python v2 = gdb.parse_and_eval('global_${type}')" | |
297 | gdb_test_no_output "python v3 = gdb.parse_and_eval('global_signed_${type}')" | |
298 | ||
299 | gdb_test_no_output "python t1 = v1.type" | |
300 | gdb_test_no_output "python t2 = v2.type" | |
301 | gdb_test_no_output "python t3 = v3.type" | |
302 | ||
303 | if { $type == "char" } { | |
304 | # In C/C++ there's an interesting property of 'char' based types; | |
305 | # 'signed char', 'unsigned char', and 'char' are all distinct | |
306 | # types. Weird, right? Here we check that this property is | |
307 | # visible to Python code. | |
308 | gdb_test "python print(t1 != t2)" "True" | |
309 | gdb_test "python print(t1 != t3)" "True" | |
310 | gdb_test "python print(t2 != t3)" "True" | |
311 | } else { | |
312 | # For 'int' type, when neither signed or unsigned is given | |
313 | # we expect the type to be signed by default. | |
314 | gdb_test "python print(t1 != t2)" "True" | |
315 | gdb_test "python print(t1 != t3)" "True" | |
316 | gdb_test "python print(t2 == t3)" "True" | |
317 | } | |
318 | } | |
319 | } | |
320 | ||
ee6a3d9e AB |
321 | # Test the gdb.Type.is_scalar property. |
322 | proc test_is_scalar { lang } { | |
323 | if {$lang == "c++"} { | |
324 | gdb_test "python print(gdb.parse_and_eval ('c').type.is_scalar)" "False" | |
325 | gdb_test "python print(gdb.parse_and_eval ('&c').type.is_scalar)" "True" | |
326 | } | |
327 | ||
328 | foreach type { char int } { | |
329 | gdb_test "python print(gdb.parse_and_eval('global_unsigned_${type}').type.is_scalar)" "True" | |
330 | gdb_test "python print(gdb.parse_and_eval('global_${type}').type.is_scalar)" "True" | |
331 | gdb_test "python print(gdb.parse_and_eval('global_signed_${type}').type.is_scalar)" "True" | |
332 | } | |
333 | ||
334 | gdb_test "python print(gdb.parse_and_eval ('ss.x').type.is_scalar)" "True" | |
335 | gdb_test "python print(gdb.parse_and_eval ('ss').type.is_scalar)" "False" | |
336 | gdb_test "python print(gdb.parse_and_eval ('uu').type.is_scalar)" "False" | |
337 | ||
338 | gdb_test "python print(gdb.parse_and_eval ('uu.i').type.is_scalar)" "True" | |
339 | gdb_test "python print(gdb.parse_and_eval ('uu.f').type.is_scalar)" "True" | |
340 | gdb_test "python print(gdb.parse_and_eval ('uu.a').type.is_scalar)" "False" | |
341 | gdb_test "python print(gdb.parse_and_eval ('&ss.x').type.is_scalar)" "True" | |
342 | } | |
343 | ||
bfd31e71 | 344 | # Perform C Tests. |
e019fd1d SM |
345 | if { [build_inferior "${binfile}" "c"] == 0 } { |
346 | restart_gdb "${binfile}" | |
7d1bf85c | 347 | |
e019fd1d | 348 | # Skip all tests if Python scripting is not enabled. |
d82e5429 | 349 | if { ![allow_python_tests] } { continue } |
7d1bf85c | 350 | |
e1f2e1a2 CB |
351 | gdb_test "python print (gdb.lookup_type ('char').objfile)" "None" |
352 | ||
e019fd1d SM |
353 | gdb_test "python print(gdb.lookup_type('char').array(1, 0))" \ |
354 | "char \\\[0\\\]" | |
8503d6e1 | 355 | |
e019fd1d SM |
356 | gdb_test "python print(gdb.lookup_type('char').array(1, -1))" \ |
357 | "Array length must not be negative.*" | |
8503d6e1 | 358 | |
e019fd1d SM |
359 | gdb_test "python print(gdb.lookup_type('int').optimized_out())" \ |
360 | "<optimized out>" | |
59fb7612 | 361 | |
6d7bb824 TT |
362 | set sint [get_sizeof int 0] |
363 | gdb_test "python print(gdb.parse_and_eval('aligncheck').type.alignof)" \ | |
364 | $sint | |
365 | ||
e019fd1d SM |
366 | with_test_prefix "lang_c" { |
367 | runto_bp "break to inspect struct and array." | |
368 | test_fields "c" | |
369 | test_enums | |
ee6a3d9e | 370 | test_is_scalar "c" |
551b380f | 371 | test_is_signed "c" |
f99e1c6d | 372 | test_type_equality |
e019fd1d | 373 | } |
6d67b990 | 374 | } |
bfd31e71 PM |
375 | |
376 | # Perform C++ Tests. | |
e019fd1d SM |
377 | if { [build_inferior "${binfile}-cxx" "c++"] == 0 } { |
378 | restart_gdb "${binfile}-cxx" | |
379 | with_test_prefix "lang_cpp" { | |
380 | runto_bp "break to inspect struct and array." | |
381 | test_fields "c++" | |
382 | test_base_class | |
383 | test_range | |
384 | test_template | |
385 | test_enums | |
ee6a3d9e | 386 | test_is_scalar "c++" |
551b380f | 387 | test_is_signed "c++" |
f99e1c6d | 388 | test_type_equality |
e019fd1d | 389 | } |
6d67b990 | 390 | } |
bb2bd584 MBB |
391 | |
392 | # Test __repr__(). | |
393 | gdb_test "python print (repr (gdb.lookup_type ('char')))" \ | |
394 | "<gdb.Type code=TYPE_CODE_INT name=char>" "test __repr__()" |