OLD | NEW |
1 # Copyright (C) 2009-2012 Free Software Foundation, Inc. | 1 # Copyright (C) 2009-2012 Free Software Foundation, Inc. |
2 | 2 |
3 # This program is free software; you can redistribute it and/or modify | 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 | 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 | 5 # the Free Software Foundation; either version 3 of the License, or |
6 # (at your option) any later version. | 6 # (at your option) any later version. |
7 # | 7 # |
8 # This program is distributed in the hope that it will be useful, | 8 # This program is distributed in the hope that it will be useful, |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
12 # | 12 # |
13 # You should have received a copy of the GNU General Public License | 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/>. | 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 |
16 # This file is part of the GDB testsuite. It tests the mechanism | 16 # This file is part of the GDB testsuite. It tests the mechanism |
17 # of exposing types to Python. | 17 # of exposing types to Python. |
18 | 18 |
19 if $tracelevel then { | |
20 strace $tracelevel | |
21 } | |
22 | |
23 load_lib gdb-python.exp | 19 load_lib gdb-python.exp |
24 | 20 |
25 set testfile "py-type" | 21 standard_testfile |
26 set srcfile ${testfile}.c | |
27 set binfile ${objdir}/${subdir}/${testfile} | |
28 | 22 |
29 if [get_compiler_info not-used c++] { | 23 if [get_compiler_info c++] { |
30 return -1; | 24 return -1; |
31 } | 25 } |
32 | 26 |
33 # Build inferior to language specification. | 27 # Build inferior to language specification. |
34 proc build_inferior {exefile lang} { | 28 proc build_inferior {exefile lang} { |
35 global srcdir subdir srcfile testfile hex | 29 global srcdir subdir srcfile testfile hex |
36 | 30 |
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${exefile}" executable "de
bug $lang"] != "" } { | 31 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${exefile}" executable "de
bug $lang"] != "" } { |
38 untested "Couldn't compile ${srcfile} in $lang mode" | 32 untested "Couldn't compile ${srcfile} in $lang mode" |
39 return -1 | 33 return -1 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 77 } |
84 | 78 |
85 # Test normal fields usage in structs. | 79 # Test normal fields usage in structs. |
86 gdb_py_test_silent_cmd "print st" "print value" 1 | 80 gdb_py_test_silent_cmd "print st" "print value" 1 |
87 gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history"
1 | 81 gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value from history"
1 |
88 gdb_py_test_silent_cmd "python fields = st.type.fields()" "get fields" 1 | 82 gdb_py_test_silent_cmd "python fields = st.type.fields()" "get fields" 1 |
89 gdb_test "python print len(fields)" "2" "Check number of fields" | 83 gdb_test "python print len(fields)" "2" "Check number of fields" |
90 gdb_test "python print fields\[0\].name" "a" "Check structure field a name" | 84 gdb_test "python print fields\[0\].name" "a" "Check structure field a name" |
91 gdb_test "python print fields\[1\].name" "b" "Check structure field b name" | 85 gdb_test "python print fields\[1\].name" "b" "Check structure field b name" |
92 | 86 |
| 87 # Regression test for |
| 88 # http://sourceware.org/bugzilla/show_bug.cgi?id=12070. |
| 89 gdb_test "python print 'type' in dir(fields\[0\])" "True" \ |
| 90 "Check that dir includes name" |
| 91 |
93 # Test Python mapping behavior of gdb.Type for structs/classes | 92 # Test Python mapping behavior of gdb.Type for structs/classes |
94 gdb_test "python print len(st.type)" "2" "Check number of fields" | 93 gdb_test "python print len(st.type)" "2" "Check number of fields" |
95 gdb_test "python print st.type\['a'\].name" "a" "Check fields lookup by name" | 94 gdb_test "python print st.type\['a'\].name" "a" "Check fields lookup by name" |
96 gdb_test "python print \[v.bitpos for v in st.type.itervalues()\]" {\[0L, 32
L\]} "Check fields iteration over values" | 95 gdb_test "python print \[v.bitpos for v in st.type.itervalues()\]" {\[0L, 32
L\]} "Check fields iteration over values" |
97 gdb_test "python print \[(n, v.bitpos) for (n, v) in st.type.items()\]" {\[\
('a', 0L\), \('b', 32L\)\]} "Check fields items list" | 96 gdb_test "python print \[(n, v.bitpos) for (n, v) in st.type.items()\]" {\[\
('a', 0L\), \('b', 32L\)\]} "Check fields items list" |
98 gdb_test "python print 'a' in st.type" "True" "Check field name exists test" | 97 gdb_test "python print 'a' in st.type" "True" "Check field name exists test" |
99 gdb_test "python print 'nosuch' in st.type" "False" "Check field name nonexist
s test" | 98 gdb_test "python print 'nosuch' in st.type" "False" "Check field name nonexist
s test" |
100 gdb_test "python print not not st.type" "True" "Check conversion to bool" | 99 gdb_test "python print not not st.type" "True" "Check conversion to bool" |
101 | 100 |
102 # Test rejection of mapping operations on scalar types | 101 # Test rejection of mapping operations on scalar types |
(...skipping 25 matching lines...) Expand all Loading... |
128 gdb_py_test_silent_cmd "python e = gdb.history (0)" "get value from history"
1 | 127 gdb_py_test_silent_cmd "python e = gdb.history (0)" "get value from history"
1 |
129 gdb_py_test_silent_cmd "python fields = e.type.fields()" "get value from histo
ry" 1 | 128 gdb_py_test_silent_cmd "python fields = e.type.fields()" "get value from histo
ry" 1 |
130 gdb_test "python print len(fields)" "3" "Check the number of enum fields" | 129 gdb_test "python print len(fields)" "3" "Check the number of enum fields" |
131 gdb_test "python print fields\[0\].name" "v1" "Check enum field name" | 130 gdb_test "python print fields\[0\].name" "v1" "Check enum field name" |
132 gdb_test "python print fields\[1\].name" "v2" "Check enum field name" | 131 gdb_test "python print fields\[1\].name" "v2" "Check enum field name" |
133 | 132 |
134 # Ditto but by mapping operations | 133 # Ditto but by mapping operations |
135 gdb_test "python print len(e.type)" "3" "Check the number of enum fields" | 134 gdb_test "python print len(e.type)" "3" "Check the number of enum fields" |
136 gdb_test "python print e.type\['v1'\].name" "v1" "Check enum field lookup by n
ame" | 135 gdb_test "python print e.type\['v1'\].name" "v1" "Check enum field lookup by n
ame" |
137 gdb_test "python print e.type\['v3'\].name" "v3" "Check enum field lookup by n
ame" | 136 gdb_test "python print e.type\['v3'\].name" "v3" "Check enum field lookup by n
ame" |
138 gdb_test "python print \[v.bitpos for v in e.type.itervalues()\]" {\[0L, 1L,
2L\]} "Check num fields iteration over values" | 137 gdb_test "python print \[v.enumval for v in e.type.itervalues()\]" {\[0L, 1L
, 2L\]} "Check num fields iteration over values" |
139 gdb_test "python print \[(n, v.bitpos) for (n, v) in e.type.items()\]" {\[\(
'v1', 0L\), \('v2', 1L\), \('v3', 2L\)\]} "Check enum fields items list" | 138 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" |
140 } | 139 } |
141 proc test_base_class {} { | 140 proc test_base_class {} { |
142 gdb_py_test_silent_cmd "print d" "print value" 1 | 141 gdb_py_test_silent_cmd "print d" "print value" 1 |
143 gdb_py_test_silent_cmd "python d = gdb.history (0)" "get value from history"
1 | 142 gdb_py_test_silent_cmd "python d = gdb.history (0)" "get value from history"
1 |
144 gdb_py_test_silent_cmd "python fields = d.type.fields()" "get value from histo
ry" 1 | 143 gdb_py_test_silent_cmd "python fields = d.type.fields()" "get value from histo
ry" 1 |
145 gdb_test "python print len(fields)" "3" "Check the number of fields" | 144 gdb_test "python print len(fields)" "3" "Check the number of fields" |
146 gdb_test "python print fields\[0\].is_base_class" "True" "Check base class" | 145 gdb_test "python print fields\[0\].is_base_class" "True" "Check base class" |
147 gdb_test "python print fields\[1\].is_base_class" "False" "Check base class" | 146 gdb_test "python print fields\[1\].is_base_class" "False" "Check base class" |
148 } | 147 } |
149 | 148 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 if {[test_compiler_info {gcc-[0-3]-*}] | 185 if {[test_compiler_info {gcc-[0-3]-*}] |
187 || [test_compiler_info {gcc-4-[0-4]-*}]} { | 186 || [test_compiler_info {gcc-4-[0-4]-*}]} { |
188 set have_older_gcc 1 | 187 set have_older_gcc 1 |
189 } | 188 } |
190 if $have_older_gcc { setup_xfail *-*-* } | 189 if $have_older_gcc { setup_xfail *-*-* } |
191 gdb_test "python print ttype.template_argument(1)" "23" | 190 gdb_test "python print ttype.template_argument(1)" "23" |
192 if $have_older_gcc { setup_xfail *-*-* } | 191 if $have_older_gcc { setup_xfail *-*-* } |
193 gdb_test "python print isinstance(ttype.template_argument(1), gdb.Value)" \ | 192 gdb_test "python print isinstance(ttype.template_argument(1), gdb.Value)" \ |
194 "True" | 193 "True" |
195 | 194 |
196 setup_kfail "gcc/41736" *-*-* | 195 if {[test_compiler_info {gcc-[0-3]-*}] |
| 196 » || [test_compiler_info {gcc-4-[0-5]-*}]} { |
| 197 » setup_xfail "gcc/46955" *-*-* |
| 198 } |
197 gdb_test "python print ttype.template_argument(2)" "&C::c" | 199 gdb_test "python print ttype.template_argument(2)" "&C::c" |
198 } | 200 } |
199 | 201 |
200 # Perform C Tests. | 202 # Perform C Tests. |
201 build_inferior "${binfile}" "c" | 203 build_inferior "${binfile}" "c" |
202 restart_gdb "${binfile}" | 204 restart_gdb "${binfile}" |
203 | 205 |
204 # Skip all tests if Python scripting is not enabled. | 206 # Skip all tests if Python scripting is not enabled. |
205 if { [skip_python_tests] } { continue } | 207 if { [skip_python_tests] } { continue } |
206 | 208 |
207 runto_bp "break to inspect struct and array." | 209 runto_bp "break to inspect struct and array." |
208 test_fields "c" | 210 test_fields "c" |
209 test_enums | 211 test_enums |
210 | 212 |
211 # Perform C++ Tests. | 213 # Perform C++ Tests. |
212 build_inferior "${binfile}-cxx" "c++" | 214 build_inferior "${binfile}-cxx" "c++" |
213 restart_gdb "${binfile}-cxx" | 215 restart_gdb "${binfile}-cxx" |
214 runto_bp "break to inspect struct and array." | 216 runto_bp "break to inspect struct and array." |
215 test_fields "c++" | 217 test_fields "c++" |
216 test_base_class | 218 test_base_class |
217 test_range | 219 test_range |
218 test_template | 220 test_template |
219 test_enums | 221 test_enums |
OLD | NEW |