]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright (C) 2010-2024 Free Software Foundation, Inc. |
0e3509db DE |
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. | |
17 | # It tests the types.py module. | |
18 | ||
0e3509db DE |
19 | load_lib gdb-python.exp |
20 | ||
d82e5429 | 21 | require allow_python_tests |
79749205 | 22 | |
b4a58790 TT |
23 | standard_testfile .cc |
24 | ||
5b362f04 | 25 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { |
0e3509db DE |
26 | return -1 |
27 | } | |
28 | ||
b0e16ca5 | 29 | if {![runto_main]} { |
0e3509db DE |
30 | return 0 |
31 | } | |
32 | ||
0e3509db DE |
33 | gdb_test_no_output "python import gdb.types" |
34 | ||
35 | # test get_basic_type const stripping | |
36 | gdb_test_no_output "python const_class1_obj = gdb.parse_and_eval ('const_class1_obj')" | |
37 | gdb_test_no_output "python basic_type_const_class1_obj = gdb.types.get_basic_type (const_class1_obj.type)" | |
9325cb04 | 38 | gdb_test "python print (str (const_class1_obj.type))" "const class1" |
0e3509db | 39 | set test "const stripping" |
9325cb04 | 40 | gdb_test_multiple "python print (str (basic_type_const_class1_obj))" $test { |
0e3509db DE |
41 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
42 | pass $test | |
43 | } | |
44 | } | |
45 | ||
46 | # test get_basic_type volatile stripping | |
47 | gdb_test_no_output "python volatile_class1_obj = gdb.parse_and_eval ('volatile_class1_obj')" | |
48 | gdb_test_no_output "python basic_type_volatile_class1_obj = gdb.types.get_basic_type (volatile_class1_obj.type)" | |
9325cb04 | 49 | gdb_test "python print (str (volatile_class1_obj.type))" "volatile class1" |
0e3509db | 50 | set test "volatile stripping" |
9325cb04 | 51 | gdb_test_multiple "python print (str (basic_type_volatile_class1_obj))" $test { |
0e3509db DE |
52 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
53 | pass $test | |
54 | } | |
55 | } | |
56 | ||
57 | # test get_basic_type volatile+const stripping | |
58 | gdb_test_no_output "python const_volatile_class1_obj = gdb.parse_and_eval ('const_volatile_class1_obj')" | |
59 | gdb_test_no_output "python basic_type_const_volatile_class1_obj = gdb.types.get_basic_type (const_volatile_class1_obj.type)" | |
9325cb04 | 60 | gdb_test "python print (str (const_volatile_class1_obj.type))" "const volatile class1" |
0e3509db | 61 | set test "volatile+const stripping" |
9325cb04 | 62 | gdb_test_multiple "python print (str (basic_type_const_volatile_class1_obj))" $test { |
0e3509db DE |
63 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
64 | pass $test | |
65 | } | |
66 | } | |
67 | ||
68 | # test get_basic_type typedef stripping | |
69 | gdb_test_no_output "python typedef_class1_obj = gdb.parse_and_eval ('typedef_class1_obj')" | |
70 | gdb_test_no_output "python basic_type_typedef_class1_obj = gdb.types.get_basic_type (typedef_class1_obj.type)" | |
9325cb04 | 71 | gdb_test "python print (str (typedef_class1_obj.type))" "typedef_class1" |
0e3509db | 72 | set test "typedef stripping" |
9325cb04 | 73 | gdb_test_multiple "python print (str (basic_type_typedef_class1_obj))" $test { |
0e3509db DE |
74 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
75 | pass $test | |
76 | } | |
77 | } | |
78 | ||
79 | # test get_basic_type reference stripping | |
80 | gdb_test_no_output "python class1_ref_obj = gdb.parse_and_eval ('class1_ref_obj')" | |
81 | gdb_test_no_output "python basic_type_class1_ref_obj = gdb.types.get_basic_type (class1_ref_obj.type)" | |
9325cb04 | 82 | gdb_test "python print (str (class1_ref_obj.type))" "class1 &" |
0e3509db | 83 | set test "reference stripping" |
9325cb04 | 84 | gdb_test_multiple "python print (str (basic_type_class1_ref_obj))" $test { |
0e3509db DE |
85 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
86 | pass $test | |
87 | } | |
88 | } | |
89 | ||
90 | # test nested typedef stripping | |
91 | gdb_test_no_output "python typedef_const_typedef_class1_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_obj')" | |
92 | gdb_test_no_output "python basic_type_typedef_const_typedef_class1_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_obj.type)" | |
8a4efb36 | 93 | gdb_test "python print (str (typedef_const_typedef_class1_obj.type))" "typedef_class1" |
0e3509db | 94 | set test "nested typedef stripping" |
9325cb04 | 95 | gdb_test_multiple "python print (str (basic_type_typedef_const_typedef_class1_obj))" $test { |
0e3509db DE |
96 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
97 | pass $test | |
98 | } | |
99 | } | |
100 | ||
101 | # test nested typedef/reference stripping | |
102 | gdb_test_no_output "python typedef_const_typedef_class1_ref_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_ref_obj')" | |
103 | gdb_test_no_output "python basic_type_typedef_const_typedef_class1_ref_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_ref_obj.type)" | |
c9c41e6d TV |
104 | gdb_test_multiple "python print (str (typedef_const_typedef_class1_ref_obj.type))" "" { |
105 | -re -wrap "\[\r\n\]+const typedef_const_typedef_class1_ref" { | |
106 | # Compiler with PR gcc/55641. | |
107 | xfail $gdb_test_name | |
108 | } | |
109 | -re -wrap "\[\r\n\]+typedef_const_typedef_class1_ref" { | |
110 | pass $gdb_test_name | |
111 | } | |
112 | } | |
0e3509db | 113 | set test "nested typedef/ref stripping" |
9325cb04 | 114 | gdb_test_multiple "python print (str (basic_type_typedef_const_typedef_class1_ref_obj))" $test { |
0e3509db DE |
115 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
116 | pass $test | |
117 | } | |
118 | } | |
119 | ||
120 | # test has_field on simple class | |
121 | gdb_test_no_output "python class1_obj = gdb.parse_and_eval ('class1_obj')" | |
9325cb04 PK |
122 | gdb_test "python print (gdb.types.has_field (class1_obj.type, 'x'))" "True" |
123 | gdb_test "python print (gdb.types.has_field (class1_obj.type, 'nope'))" "False" | |
0e3509db DE |
124 | |
125 | # test has_field in base class | |
126 | gdb_test_no_output "python subclass1_obj = gdb.parse_and_eval ('subclass1_obj')" | |
9325cb04 | 127 | gdb_test "python print (gdb.types.has_field (subclass1_obj.type, 'x'))" "True" |
0e3509db DE |
128 | |
129 | # test make_enum_dict | |
130 | gdb_test_no_output "python enum1_obj = gdb.parse_and_eval ('enum1_obj')" | |
131 | gdb_test_no_output "python enum1_dict = gdb.types.make_enum_dict (enum1_obj.type)" | |
9325cb04 PK |
132 | gdb_test_no_output "python enum1_list = sorted (enum1_dict.items ())" |
133 | gdb_test "python print (enum1_list)" {\[\('A', 0L?\), \('B', 1L?\), \('C', 2L?\)\]} | |
ab964825 | 134 | |
d6a5d40c | 135 | # test deep_items |
ab964825 | 136 | gdb_test_no_output "python struct_a = gdb.lookup_type ('struct A')" |
9325cb04 PK |
137 | gdb_test "python print (struct_a.keys ())" {\['a', '', 'c', ''\]} |
138 | gdb_test "python print (\[k for k,v in gdb.types.deep_items(struct_a)\])" {\['a', 'b0', 'b1', 'bb0', 'bb1', 'bbb0', 'bbb1', 'c', 'dd0', 'dd1', 'd2', 'd3'\]} |