* gdb.texinfo (gdb.types): Rename deepitems to deep_items.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / lib-types.exp
CommitLineData
7b6bb8da 1# Copyright (C) 2010, 2011 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
19if $tracelevel then {
20 strace $tracelevel
21}
22
23load_lib gdb-python.exp
24
25set testfile "lib-types"
26set srcfile ${testfile}.cc
27set binfile ${objdir}/${subdir}/${testfile}
28if { [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.
34gdb_exit
35gdb_start
36gdb_reinitialize_dir $srcdir/$subdir
37gdb_load ${binfile}
38
39# Skip all tests if Python scripting is not enabled.
40if { [skip_python_tests] } { continue }
41
42if ![runto_main] then {
43 fail "Can't run to main"
44 return 0
45}
46
0e3509db
DE
47gdb_test_no_output "python import gdb.types"
48
49# test get_basic_type const stripping
50gdb_test_no_output "python const_class1_obj = gdb.parse_and_eval ('const_class1_obj')"
51gdb_test_no_output "python basic_type_const_class1_obj = gdb.types.get_basic_type (const_class1_obj.type)"
52gdb_test "python print str (const_class1_obj.type)" "const class1"
53set test "const stripping"
54gdb_test_multiple "python print str (basic_type_const_class1_obj)" $test {
55 -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
56 pass $test
57 }
58}
59
60# test get_basic_type volatile stripping
61gdb_test_no_output "python volatile_class1_obj = gdb.parse_and_eval ('volatile_class1_obj')"
62gdb_test_no_output "python basic_type_volatile_class1_obj = gdb.types.get_basic_type (volatile_class1_obj.type)"
63gdb_test "python print str (volatile_class1_obj.type)" "volatile class1"
64set test "volatile stripping"
65gdb_test_multiple "python print str (basic_type_volatile_class1_obj)" $test {
66 -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
67 pass $test
68 }
69}
70
71# test get_basic_type volatile+const stripping
72gdb_test_no_output "python const_volatile_class1_obj = gdb.parse_and_eval ('const_volatile_class1_obj')"
73gdb_test_no_output "python basic_type_const_volatile_class1_obj = gdb.types.get_basic_type (const_volatile_class1_obj.type)"
74gdb_test "python print str (const_volatile_class1_obj.type)" "const volatile class1"
75set test "volatile+const stripping"
76gdb_test_multiple "python print str (basic_type_const_volatile_class1_obj)" $test {
77 -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
78 pass $test
79 }
80}
81
82# test get_basic_type typedef stripping
83gdb_test_no_output "python typedef_class1_obj = gdb.parse_and_eval ('typedef_class1_obj')"
84gdb_test_no_output "python basic_type_typedef_class1_obj = gdb.types.get_basic_type (typedef_class1_obj.type)"
85gdb_test "python print str (typedef_class1_obj.type)" "typedef_class1"
86set test "typedef stripping"
87gdb_test_multiple "python print str (basic_type_typedef_class1_obj)" $test {
88 -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
89 pass $test
90 }
91}
92
93# test get_basic_type reference stripping
94gdb_test_no_output "python class1_ref_obj = gdb.parse_and_eval ('class1_ref_obj')"
95gdb_test_no_output "python basic_type_class1_ref_obj = gdb.types.get_basic_type (class1_ref_obj.type)"
96gdb_test "python print str (class1_ref_obj.type)" "class1 &"
97set test "reference stripping"
98gdb_test_multiple "python print str (basic_type_class1_ref_obj)" $test {
99 -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
100 pass $test
101 }
102}
103
104# test nested typedef stripping
105gdb_test_no_output "python typedef_const_typedef_class1_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_obj')"
106gdb_test_no_output "python basic_type_typedef_const_typedef_class1_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_obj.type)"
107gdb_test "python print str (typedef_class1_obj.type)" "typedef_class1"
108set test "nested typedef stripping"
109gdb_test_multiple "python print str (basic_type_typedef_const_typedef_class1_obj)" $test {
110 -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
111 pass $test
112 }
113}
114
115# test nested typedef/reference stripping
116gdb_test_no_output "python typedef_const_typedef_class1_ref_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_ref_obj')"
117gdb_test_no_output "python basic_type_typedef_const_typedef_class1_ref_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_ref_obj.type)"
118gdb_test "python print str (typedef_const_typedef_class1_ref_obj.type)" "const typedef_const_typedef_class1_ref"
119set test "nested typedef/ref stripping"
120gdb_test_multiple "python print str (basic_type_typedef_const_typedef_class1_ref_obj)" $test {
121 -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" {
122 pass $test
123 }
124}
125
126# test has_field on simple class
127gdb_test_no_output "python class1_obj = gdb.parse_and_eval ('class1_obj')"
128gdb_test "python print gdb.types.has_field (class1_obj.type, 'x')" "True"
129gdb_test "python print gdb.types.has_field (class1_obj.type, 'nope')" "False"
130
131# test has_field in base class
132gdb_test_no_output "python subclass1_obj = gdb.parse_and_eval ('subclass1_obj')"
133gdb_test "python print gdb.types.has_field (subclass1_obj.type, 'x')" "True"
134
135# test make_enum_dict
136gdb_test_no_output "python enum1_obj = gdb.parse_and_eval ('enum1_obj')"
137gdb_test_no_output "python enum1_dict = gdb.types.make_enum_dict (enum1_obj.type)"
138gdb_test_no_output "python enum1_list = enum1_dict.items ()"
139gdb_test_no_output "python enum1_list.sort ()"
140gdb_test "python print enum1_list" {\[\('A', 0L\), \('B', 1L\), \('C', 2L\)\]}
ab964825
PK
141
142# test deepitems
143gdb_test_no_output "python struct_a = gdb.lookup_type ('struct A')"
144gdb_test "python print struct_a.keys ()" {\['a', '', 'c', ''\]}
145gdb_test "python print \[k for k,v in gdb.types.deepitems(struct_a)\]" {\['a', 'b0', 'b1', 'bb0', 'bb1', 'bbb0', 'bbb1', 'c', 'dd0', 'dd1', 'd2', 'd3'\]}
This page took 0.16788 seconds and 4 git commands to generate.