New python module gdb.types.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / lib-types.exp
CommitLineData
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
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
47# Ensure sys.path, et.al. are initialized properly.
48gdb_check_python_config
49
50gdb_test_no_output "python import gdb.types"
51
52# test get_basic_type const stripping
53gdb_test_no_output "python const_class1_obj = gdb.parse_and_eval ('const_class1_obj')"
54gdb_test_no_output "python basic_type_const_class1_obj = gdb.types.get_basic_type (const_class1_obj.type)"
55gdb_test "python print str (const_class1_obj.type)" "const class1"
56set test "const stripping"
57gdb_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
64gdb_test_no_output "python volatile_class1_obj = gdb.parse_and_eval ('volatile_class1_obj')"
65gdb_test_no_output "python basic_type_volatile_class1_obj = gdb.types.get_basic_type (volatile_class1_obj.type)"
66gdb_test "python print str (volatile_class1_obj.type)" "volatile class1"
67set test "volatile stripping"
68gdb_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
75gdb_test_no_output "python const_volatile_class1_obj = gdb.parse_and_eval ('const_volatile_class1_obj')"
76gdb_test_no_output "python basic_type_const_volatile_class1_obj = gdb.types.get_basic_type (const_volatile_class1_obj.type)"
77gdb_test "python print str (const_volatile_class1_obj.type)" "const volatile class1"
78set test "volatile+const stripping"
79gdb_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
86gdb_test_no_output "python typedef_class1_obj = gdb.parse_and_eval ('typedef_class1_obj')"
87gdb_test_no_output "python basic_type_typedef_class1_obj = gdb.types.get_basic_type (typedef_class1_obj.type)"
88gdb_test "python print str (typedef_class1_obj.type)" "typedef_class1"
89set test "typedef stripping"
90gdb_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
97gdb_test_no_output "python class1_ref_obj = gdb.parse_and_eval ('class1_ref_obj')"
98gdb_test_no_output "python basic_type_class1_ref_obj = gdb.types.get_basic_type (class1_ref_obj.type)"
99gdb_test "python print str (class1_ref_obj.type)" "class1 &"
100set test "reference stripping"
101gdb_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
108gdb_test_no_output "python typedef_const_typedef_class1_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_obj')"
109gdb_test_no_output "python basic_type_typedef_const_typedef_class1_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_obj.type)"
110gdb_test "python print str (typedef_class1_obj.type)" "typedef_class1"
111set test "nested typedef stripping"
112gdb_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
119gdb_test_no_output "python typedef_const_typedef_class1_ref_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_ref_obj')"
120gdb_test_no_output "python basic_type_typedef_const_typedef_class1_ref_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_ref_obj.type)"
121gdb_test "python print str (typedef_const_typedef_class1_ref_obj.type)" "const typedef_const_typedef_class1_ref"
122set test "nested typedef/ref stripping"
123gdb_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
130gdb_test_no_output "python class1_obj = gdb.parse_and_eval ('class1_obj')"
131gdb_test "python print gdb.types.has_field (class1_obj.type, 'x')" "True"
132gdb_test "python print gdb.types.has_field (class1_obj.type, 'nope')" "False"
133
134# test has_field in base class
135gdb_test_no_output "python subclass1_obj = gdb.parse_and_eval ('subclass1_obj')"
136gdb_test "python print gdb.types.has_field (subclass1_obj.type, 'x')" "True"
137
138# test make_enum_dict
139gdb_test_no_output "python enum1_obj = gdb.parse_and_eval ('enum1_obj')"
140gdb_test_no_output "python enum1_dict = gdb.types.make_enum_dict (enum1_obj.type)"
141gdb_test_no_output "python enum1_list = enum1_dict.items ()"
142gdb_test_no_output "python enum1_list.sort ()"
143gdb_test "python print enum1_list" {\[\('A', 0L\), \('B', 1L\), \('C', 2L\)\]}
This page took 0.029758 seconds and 4 git commands to generate.