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