Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / ptype-offsets.cc
CommitLineData
7c161838
SDJ
1/* This testcase is part of GDB, the GNU debugger.
2
88b9d363 3 Copyright 2017-2022 Free Software Foundation, Inc.
7c161838
SDJ
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#include <stdint.h>
19
20/* A struct with many types of fields, in order to test 'ptype
21 /o'. */
22
23struct abc
24{
25 /* Virtual destructor. */
26 virtual ~abc ()
27 {}
28
29 /* 8-byte address. Because of the virtual destructor above, this
30 field's offset will be 8. */
31 void *field1;
32
33 /* No hole here. */
34
35 /* 4-byte int bitfield of 1-bit. */
36 unsigned int field2 : 1;
37
38 /* 31-bit hole here. */
39
40 /* 4-byte int. */
41 signed int field3;
42
43 /* No hole here. */
44
45 /* 1-byte char. */
46 signed char field4;
47
48 /* 7-byte hole here. */
49
50 /* 8-byte int. */
51 uint64_t field5;
52
53 /* We just print the offset and size of a union, ignoring its
54 fields. */
55 union
56 {
57 /* 8-byte address. */
58 void *field6;
59
60 /* 4-byte int. */
61 signed int field7;
62 } field8;
63
64 /* Empty constructor. */
65 abc ()
66 {}
67
68 /* Typedef defined in-struct. */
844333e2 69 typedef short my_int_type;
7c161838
SDJ
70
71 my_int_type field9;
72};
73
74/* This struct will be nested inside 'struct xyz'. */
75
76struct tuv
77{
78 signed int a1;
79
80 signed char *a2;
81
82 signed int a3;
83};
84
85/* This struct will be nested inside 'struct pqr'. */
86
87struct xyz
88{
89 signed int f1;
90
91 signed char f2;
92
93 void *f3;
94
95 struct tuv f4;
96};
97
98/* A struct with a nested struct. */
99
100struct pqr
101{
102 signed int ff1;
103
104 struct xyz ff2;
105
106 signed char ff3;
107};
108
109/* A union with two nested structs. */
110
111union qwe
112{
113 struct tuv fff1;
114
115 struct xyz fff2;
116};
117
118/* A struct with an union. */
119
120struct poi
121{
122 signed int f1;
123
124 union qwe f2;
125
126 uint16_t f3;
127
128 struct pqr f4;
129};
130
131/* A struct with bitfields. */
132
133struct tyu
134{
135 signed int a1 : 1;
136
137 signed int a2 : 3;
138
139 signed int a3 : 23;
140
141 signed char a4 : 2;
142
143 int64_t a5;
144
145 signed int a6 : 5;
146
147 int64_t a7 : 3;
148};
149
150/* A struct with structs and unions. */
151
152struct asd
153{
154 struct jkl
155 {
156 signed char *f1;
157 union
158 {
159 void *ff1;
160 } f2;
161 union
162 {
163 signed char *ff2;
164 } f3;
165 int f4 : 5;
166 unsigned int f5 : 1;
167 short f6;
168 } f7;
169 unsigned long f8;
170 signed char *f9;
171 int f10 : 4;
172 unsigned int f11 : 1;
173 unsigned int f12 : 1;
174 unsigned int f13 : 1;
175 unsigned int f14 : 1;
176 void *f15;
177 void *f16;
178};
179
16ff70dd
SDJ
180/* See PR c++/23373. */
181
182struct static_member
183{
184 static static_member Empty;
185 int abc;
186};
7c161838 187
0e9c2a33
TV
188/* Work around PR gcc/101452. */
189static_member static_member::Empty;
190
432ce4cf
TT
191struct empty_member
192{
193 struct { } empty;
194 int an_int;
195};
196
7c161838
SDJ
197int
198main (int argc, char *argv[])
199{
200 struct abc foo;
201 struct pqr bar;
202 union qwe c;
203 struct poi d;
204 struct tyu e;
205 struct asd f;
206 uint8_t i;
16ff70dd 207 static_member stmember;
432ce4cf 208 empty_member emember;
7c161838
SDJ
209
210 return 0;
211}
This page took 0.612403 seconds and 4 git commands to generate.