Commit | Line | Data |
---|---|---|
0e3509db DE |
1 | # Copyright (C) 2010 Free Software Foundation, Inc. |
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 | ||
19 | if $tracelevel then { | |
20 | strace $tracelevel | |
21 | } | |
22 | ||
23 | load_lib gdb-python.exp | |
24 | ||
25 | set testfile "lib-types" | |
26 | set srcfile ${testfile}.cc | |
27 | set binfile ${objdir}/${subdir}/${testfile} | |
28 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { | |
29 | untested "Couldn't compile ${srcfile}" | |
30 | return -1 | |
31 | } | |
32 | ||
33 | # Start with a fresh gdb. | |
34 | gdb_exit | |
35 | gdb_start | |
36 | gdb_reinitialize_dir $srcdir/$subdir | |
37 | gdb_load ${binfile} | |
38 | ||
39 | # Skip all tests if Python scripting is not enabled. | |
40 | if { [skip_python_tests] } { continue } | |
41 | ||
42 | if ![runto_main] then { | |
43 | fail "Can't run to main" | |
44 | return 0 | |
45 | } | |
46 | ||
47 | # Ensure sys.path, et.al. are initialized properly. | |
48 | gdb_check_python_config | |
49 | ||
50 | gdb_test_no_output "python import gdb.types" | |
51 | ||
52 | # test get_basic_type const stripping | |
53 | gdb_test_no_output "python const_class1_obj = gdb.parse_and_eval ('const_class1_obj')" | |
54 | gdb_test_no_output "python basic_type_const_class1_obj = gdb.types.get_basic_type (const_class1_obj.type)" | |
55 | gdb_test "python print str (const_class1_obj.type)" "const class1" | |
56 | set test "const stripping" | |
57 | gdb_test_multiple "python print str (basic_type_const_class1_obj)" $test { | |
58 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
59 | pass $test | |
60 | } | |
61 | } | |
62 | ||
63 | # test get_basic_type volatile stripping | |
64 | gdb_test_no_output "python volatile_class1_obj = gdb.parse_and_eval ('volatile_class1_obj')" | |
65 | gdb_test_no_output "python basic_type_volatile_class1_obj = gdb.types.get_basic_type (volatile_class1_obj.type)" | |
66 | gdb_test "python print str (volatile_class1_obj.type)" "volatile class1" | |
67 | set test "volatile stripping" | |
68 | gdb_test_multiple "python print str (basic_type_volatile_class1_obj)" $test { | |
69 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
70 | pass $test | |
71 | } | |
72 | } | |
73 | ||
74 | # test get_basic_type volatile+const stripping | |
75 | gdb_test_no_output "python const_volatile_class1_obj = gdb.parse_and_eval ('const_volatile_class1_obj')" | |
76 | gdb_test_no_output "python basic_type_const_volatile_class1_obj = gdb.types.get_basic_type (const_volatile_class1_obj.type)" | |
77 | gdb_test "python print str (const_volatile_class1_obj.type)" "const volatile class1" | |
78 | set test "volatile+const stripping" | |
79 | gdb_test_multiple "python print str (basic_type_const_volatile_class1_obj)" $test { | |
80 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
81 | pass $test | |
82 | } | |
83 | } | |
84 | ||
85 | # test get_basic_type typedef stripping | |
86 | gdb_test_no_output "python typedef_class1_obj = gdb.parse_and_eval ('typedef_class1_obj')" | |
87 | gdb_test_no_output "python basic_type_typedef_class1_obj = gdb.types.get_basic_type (typedef_class1_obj.type)" | |
88 | gdb_test "python print str (typedef_class1_obj.type)" "typedef_class1" | |
89 | set test "typedef stripping" | |
90 | gdb_test_multiple "python print str (basic_type_typedef_class1_obj)" $test { | |
91 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
92 | pass $test | |
93 | } | |
94 | } | |
95 | ||
96 | # test get_basic_type reference stripping | |
97 | gdb_test_no_output "python class1_ref_obj = gdb.parse_and_eval ('class1_ref_obj')" | |
98 | gdb_test_no_output "python basic_type_class1_ref_obj = gdb.types.get_basic_type (class1_ref_obj.type)" | |
99 | gdb_test "python print str (class1_ref_obj.type)" "class1 &" | |
100 | set test "reference stripping" | |
101 | gdb_test_multiple "python print str (basic_type_class1_ref_obj)" $test { | |
102 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
103 | pass $test | |
104 | } | |
105 | } | |
106 | ||
107 | # test nested typedef stripping | |
108 | gdb_test_no_output "python typedef_const_typedef_class1_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_obj')" | |
109 | gdb_test_no_output "python basic_type_typedef_const_typedef_class1_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_obj.type)" | |
110 | gdb_test "python print str (typedef_class1_obj.type)" "typedef_class1" | |
111 | set test "nested typedef stripping" | |
112 | gdb_test_multiple "python print str (basic_type_typedef_const_typedef_class1_obj)" $test { | |
113 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
114 | pass $test | |
115 | } | |
116 | } | |
117 | ||
118 | # test nested typedef/reference stripping | |
119 | gdb_test_no_output "python typedef_const_typedef_class1_ref_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_ref_obj')" | |
120 | 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)" | |
121 | gdb_test "python print str (typedef_const_typedef_class1_ref_obj.type)" "const typedef_const_typedef_class1_ref" | |
122 | set test "nested typedef/ref stripping" | |
123 | gdb_test_multiple "python print str (basic_type_typedef_const_typedef_class1_ref_obj)" $test { | |
124 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
125 | pass $test | |
126 | } | |
127 | } | |
128 | ||
129 | # test has_field on simple class | |
130 | gdb_test_no_output "python class1_obj = gdb.parse_and_eval ('class1_obj')" | |
131 | gdb_test "python print gdb.types.has_field (class1_obj.type, 'x')" "True" | |
132 | gdb_test "python print gdb.types.has_field (class1_obj.type, 'nope')" "False" | |
133 | ||
134 | # test has_field in base class | |
135 | gdb_test_no_output "python subclass1_obj = gdb.parse_and_eval ('subclass1_obj')" | |
136 | gdb_test "python print gdb.types.has_field (subclass1_obj.type, 'x')" "True" | |
137 | ||
138 | # test make_enum_dict | |
139 | gdb_test_no_output "python enum1_obj = gdb.parse_and_eval ('enum1_obj')" | |
140 | gdb_test_no_output "python enum1_dict = gdb.types.make_enum_dict (enum1_obj.type)" | |
141 | gdb_test_no_output "python enum1_list = enum1_dict.items ()" | |
142 | gdb_test_no_output "python enum1_list.sort ()" | |
143 | gdb_test "python print enum1_list" {\[\('A', 0L\), \('B', 1L\), \('C', 2L\)\]} |