Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright (C) 2010-2016 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 | ||
b4a58790 TT |
21 | standard_testfile .cc |
22 | ||
1c06bd58 | 23 | if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { |
0e3509db DE |
24 | return -1 |
25 | } | |
26 | ||
0e3509db DE |
27 | # Skip all tests if Python scripting is not enabled. |
28 | if { [skip_python_tests] } { continue } | |
29 | ||
30 | if ![runto_main] then { | |
31 | fail "Can't run to main" | |
32 | return 0 | |
33 | } | |
34 | ||
0e3509db DE |
35 | gdb_test_no_output "python import gdb.types" |
36 | ||
37 | # test get_basic_type const stripping | |
38 | gdb_test_no_output "python const_class1_obj = gdb.parse_and_eval ('const_class1_obj')" | |
39 | gdb_test_no_output "python basic_type_const_class1_obj = gdb.types.get_basic_type (const_class1_obj.type)" | |
9325cb04 | 40 | gdb_test "python print (str (const_class1_obj.type))" "const class1" |
0e3509db | 41 | set test "const stripping" |
9325cb04 | 42 | gdb_test_multiple "python print (str (basic_type_const_class1_obj))" $test { |
0e3509db DE |
43 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
44 | pass $test | |
45 | } | |
46 | } | |
47 | ||
48 | # test get_basic_type volatile stripping | |
49 | gdb_test_no_output "python volatile_class1_obj = gdb.parse_and_eval ('volatile_class1_obj')" | |
50 | gdb_test_no_output "python basic_type_volatile_class1_obj = gdb.types.get_basic_type (volatile_class1_obj.type)" | |
9325cb04 | 51 | gdb_test "python print (str (volatile_class1_obj.type))" "volatile class1" |
0e3509db | 52 | set test "volatile stripping" |
9325cb04 | 53 | gdb_test_multiple "python print (str (basic_type_volatile_class1_obj))" $test { |
0e3509db DE |
54 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
55 | pass $test | |
56 | } | |
57 | } | |
58 | ||
59 | # test get_basic_type volatile+const stripping | |
60 | gdb_test_no_output "python const_volatile_class1_obj = gdb.parse_and_eval ('const_volatile_class1_obj')" | |
61 | gdb_test_no_output "python basic_type_const_volatile_class1_obj = gdb.types.get_basic_type (const_volatile_class1_obj.type)" | |
9325cb04 | 62 | gdb_test "python print (str (const_volatile_class1_obj.type))" "const volatile class1" |
0e3509db | 63 | set test "volatile+const stripping" |
9325cb04 | 64 | gdb_test_multiple "python print (str (basic_type_const_volatile_class1_obj))" $test { |
0e3509db DE |
65 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
66 | pass $test | |
67 | } | |
68 | } | |
69 | ||
70 | # test get_basic_type typedef stripping | |
71 | gdb_test_no_output "python typedef_class1_obj = gdb.parse_and_eval ('typedef_class1_obj')" | |
72 | gdb_test_no_output "python basic_type_typedef_class1_obj = gdb.types.get_basic_type (typedef_class1_obj.type)" | |
9325cb04 | 73 | gdb_test "python print (str (typedef_class1_obj.type))" "typedef_class1" |
0e3509db | 74 | set test "typedef stripping" |
9325cb04 | 75 | gdb_test_multiple "python print (str (basic_type_typedef_class1_obj))" $test { |
0e3509db DE |
76 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
77 | pass $test | |
78 | } | |
79 | } | |
80 | ||
81 | # test get_basic_type reference stripping | |
82 | gdb_test_no_output "python class1_ref_obj = gdb.parse_and_eval ('class1_ref_obj')" | |
83 | gdb_test_no_output "python basic_type_class1_ref_obj = gdb.types.get_basic_type (class1_ref_obj.type)" | |
9325cb04 | 84 | gdb_test "python print (str (class1_ref_obj.type))" "class1 &" |
0e3509db | 85 | set test "reference stripping" |
9325cb04 | 86 | gdb_test_multiple "python print (str (basic_type_class1_ref_obj))" $test { |
0e3509db DE |
87 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
88 | pass $test | |
89 | } | |
90 | } | |
91 | ||
92 | # test nested typedef stripping | |
93 | gdb_test_no_output "python typedef_const_typedef_class1_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_obj')" | |
94 | gdb_test_no_output "python basic_type_typedef_const_typedef_class1_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_obj.type)" | |
9325cb04 | 95 | gdb_test "python print (str (typedef_class1_obj.type))" "typedef_class1" |
0e3509db | 96 | set test "nested typedef stripping" |
9325cb04 | 97 | gdb_test_multiple "python print (str (basic_type_typedef_const_typedef_class1_obj))" $test { |
0e3509db DE |
98 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
99 | pass $test | |
100 | } | |
101 | } | |
102 | ||
103 | # test nested typedef/reference stripping | |
104 | gdb_test_no_output "python typedef_const_typedef_class1_ref_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_ref_obj')" | |
105 | 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)" | |
56083b99 DB |
106 | if {[test_compiler_info {gcc-*-*}]} { setup_xfail gcc/55641 *-*-* } |
107 | gdb_test "python print (str (typedef_const_typedef_class1_ref_obj.type))" "\[\r\n\]+typedef_const_typedef_class1_ref" | |
0e3509db | 108 | set test "nested typedef/ref stripping" |
9325cb04 | 109 | gdb_test_multiple "python print (str (basic_type_typedef_const_typedef_class1_ref_obj))" $test { |
0e3509db DE |
110 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { |
111 | pass $test | |
112 | } | |
113 | } | |
114 | ||
115 | # test has_field on simple class | |
116 | gdb_test_no_output "python class1_obj = gdb.parse_and_eval ('class1_obj')" | |
9325cb04 PK |
117 | gdb_test "python print (gdb.types.has_field (class1_obj.type, 'x'))" "True" |
118 | gdb_test "python print (gdb.types.has_field (class1_obj.type, 'nope'))" "False" | |
0e3509db DE |
119 | |
120 | # test has_field in base class | |
121 | gdb_test_no_output "python subclass1_obj = gdb.parse_and_eval ('subclass1_obj')" | |
9325cb04 | 122 | gdb_test "python print (gdb.types.has_field (subclass1_obj.type, 'x'))" "True" |
0e3509db DE |
123 | |
124 | # test make_enum_dict | |
125 | gdb_test_no_output "python enum1_obj = gdb.parse_and_eval ('enum1_obj')" | |
126 | gdb_test_no_output "python enum1_dict = gdb.types.make_enum_dict (enum1_obj.type)" | |
9325cb04 PK |
127 | gdb_test_no_output "python enum1_list = sorted (enum1_dict.items ())" |
128 | gdb_test "python print (enum1_list)" {\[\('A', 0L?\), \('B', 1L?\), \('C', 2L?\)\]} | |
ab964825 | 129 | |
d6a5d40c | 130 | # test deep_items |
ab964825 | 131 | gdb_test_no_output "python struct_a = gdb.lookup_type ('struct A')" |
9325cb04 PK |
132 | gdb_test "python print (struct_a.keys ())" {\['a', '', 'c', ''\]} |
133 | 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'\]} |