1 |
24 |
jeremybenn |
/* Support routines for manipulating internal types for GDB.
|
2 |
|
|
|
3 |
|
|
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
|
4 |
|
|
2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
5 |
|
|
|
6 |
|
|
Contributed by Cygnus Support, using pieces from other GDB modules.
|
7 |
|
|
|
8 |
|
|
This file is part of GDB.
|
9 |
|
|
|
10 |
|
|
This program is free software; you can redistribute it and/or modify
|
11 |
|
|
it under the terms of the GNU General Public License as published by
|
12 |
|
|
the Free Software Foundation; either version 3 of the License, or
|
13 |
|
|
(at your option) any later version.
|
14 |
|
|
|
15 |
|
|
This program is distributed in the hope that it will be useful,
|
16 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
GNU General Public License for more details.
|
19 |
|
|
|
20 |
|
|
You should have received a copy of the GNU General Public License
|
21 |
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
22 |
|
|
|
23 |
|
|
#include "defs.h"
|
24 |
|
|
#include "gdb_string.h"
|
25 |
|
|
#include "bfd.h"
|
26 |
|
|
#include "symtab.h"
|
27 |
|
|
#include "symfile.h"
|
28 |
|
|
#include "objfiles.h"
|
29 |
|
|
#include "gdbtypes.h"
|
30 |
|
|
#include "expression.h"
|
31 |
|
|
#include "language.h"
|
32 |
|
|
#include "target.h"
|
33 |
|
|
#include "value.h"
|
34 |
|
|
#include "demangle.h"
|
35 |
|
|
#include "complaints.h"
|
36 |
|
|
#include "gdbcmd.h"
|
37 |
|
|
#include "wrapper.h"
|
38 |
|
|
#include "cp-abi.h"
|
39 |
|
|
#include "gdb_assert.h"
|
40 |
|
|
#include "hashtab.h"
|
41 |
|
|
|
42 |
|
|
/* These variables point to the objects
|
43 |
|
|
representing the predefined C data types. */
|
44 |
|
|
|
45 |
|
|
struct type *builtin_type_int0;
|
46 |
|
|
struct type *builtin_type_int8;
|
47 |
|
|
struct type *builtin_type_uint8;
|
48 |
|
|
struct type *builtin_type_int16;
|
49 |
|
|
struct type *builtin_type_uint16;
|
50 |
|
|
struct type *builtin_type_int32;
|
51 |
|
|
struct type *builtin_type_uint32;
|
52 |
|
|
struct type *builtin_type_int64;
|
53 |
|
|
struct type *builtin_type_uint64;
|
54 |
|
|
struct type *builtin_type_int128;
|
55 |
|
|
struct type *builtin_type_uint128;
|
56 |
|
|
|
57 |
|
|
/* Floatformat pairs. */
|
58 |
|
|
const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = {
|
59 |
|
|
&floatformat_ieee_single_big,
|
60 |
|
|
&floatformat_ieee_single_little
|
61 |
|
|
};
|
62 |
|
|
const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = {
|
63 |
|
|
&floatformat_ieee_double_big,
|
64 |
|
|
&floatformat_ieee_double_little
|
65 |
|
|
};
|
66 |
|
|
const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = {
|
67 |
|
|
&floatformat_ieee_double_big,
|
68 |
|
|
&floatformat_ieee_double_littlebyte_bigword
|
69 |
|
|
};
|
70 |
|
|
const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = {
|
71 |
|
|
&floatformat_i387_ext,
|
72 |
|
|
&floatformat_i387_ext
|
73 |
|
|
};
|
74 |
|
|
const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = {
|
75 |
|
|
&floatformat_m68881_ext,
|
76 |
|
|
&floatformat_m68881_ext
|
77 |
|
|
};
|
78 |
|
|
const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = {
|
79 |
|
|
&floatformat_arm_ext_big,
|
80 |
|
|
&floatformat_arm_ext_littlebyte_bigword
|
81 |
|
|
};
|
82 |
|
|
const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = {
|
83 |
|
|
&floatformat_ia64_spill_big,
|
84 |
|
|
&floatformat_ia64_spill_little
|
85 |
|
|
};
|
86 |
|
|
const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = {
|
87 |
|
|
&floatformat_ia64_quad_big,
|
88 |
|
|
&floatformat_ia64_quad_little
|
89 |
|
|
};
|
90 |
|
|
const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = {
|
91 |
|
|
&floatformat_vax_f,
|
92 |
|
|
&floatformat_vax_f
|
93 |
|
|
};
|
94 |
|
|
const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = {
|
95 |
|
|
&floatformat_vax_d,
|
96 |
|
|
&floatformat_vax_d
|
97 |
|
|
};
|
98 |
|
|
const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN] = {
|
99 |
|
|
&floatformat_ibm_long_double,
|
100 |
|
|
&floatformat_ibm_long_double
|
101 |
|
|
};
|
102 |
|
|
|
103 |
|
|
struct type *builtin_type_ieee_single;
|
104 |
|
|
struct type *builtin_type_ieee_double;
|
105 |
|
|
struct type *builtin_type_i387_ext;
|
106 |
|
|
struct type *builtin_type_m68881_ext;
|
107 |
|
|
struct type *builtin_type_arm_ext;
|
108 |
|
|
struct type *builtin_type_ia64_spill;
|
109 |
|
|
struct type *builtin_type_ia64_quad;
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
int opaque_type_resolution = 1;
|
113 |
|
|
static void
|
114 |
|
|
show_opaque_type_resolution (struct ui_file *file, int from_tty,
|
115 |
|
|
struct cmd_list_element *c,
|
116 |
|
|
const char *value)
|
117 |
|
|
{
|
118 |
|
|
fprintf_filtered (file, _("\
|
119 |
|
|
Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"),
|
120 |
|
|
value);
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
int overload_debug = 0;
|
124 |
|
|
static void
|
125 |
|
|
show_overload_debug (struct ui_file *file, int from_tty,
|
126 |
|
|
struct cmd_list_element *c, const char *value)
|
127 |
|
|
{
|
128 |
|
|
fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"),
|
129 |
|
|
value);
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
struct extra
|
133 |
|
|
{
|
134 |
|
|
char str[128];
|
135 |
|
|
int len;
|
136 |
|
|
}; /* Maximum extension is 128! FIXME */
|
137 |
|
|
|
138 |
|
|
static void print_bit_vector (B_TYPE *, int);
|
139 |
|
|
static void print_arg_types (struct field *, int, int);
|
140 |
|
|
static void dump_fn_fieldlists (struct type *, int);
|
141 |
|
|
static void print_cplus_stuff (struct type *, int);
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
/* Alloc a new type structure and fill it with some defaults. If
|
145 |
|
|
OBJFILE is non-NULL, then allocate the space for the type structure
|
146 |
|
|
in that objfile's objfile_obstack. Otherwise allocate the new type
|
147 |
|
|
structure by xmalloc () (for permanent types). */
|
148 |
|
|
|
149 |
|
|
struct type *
|
150 |
|
|
alloc_type (struct objfile *objfile)
|
151 |
|
|
{
|
152 |
|
|
struct type *type;
|
153 |
|
|
|
154 |
|
|
/* Alloc the structure and start off with all fields zeroed. */
|
155 |
|
|
|
156 |
|
|
if (objfile == NULL)
|
157 |
|
|
{
|
158 |
|
|
type = xmalloc (sizeof (struct type));
|
159 |
|
|
memset (type, 0, sizeof (struct type));
|
160 |
|
|
TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
|
161 |
|
|
}
|
162 |
|
|
else
|
163 |
|
|
{
|
164 |
|
|
type = obstack_alloc (&objfile->objfile_obstack,
|
165 |
|
|
sizeof (struct type));
|
166 |
|
|
memset (type, 0, sizeof (struct type));
|
167 |
|
|
TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack,
|
168 |
|
|
sizeof (struct main_type));
|
169 |
|
|
OBJSTAT (objfile, n_types++);
|
170 |
|
|
}
|
171 |
|
|
memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
|
172 |
|
|
|
173 |
|
|
/* Initialize the fields that might not be zero. */
|
174 |
|
|
|
175 |
|
|
TYPE_CODE (type) = TYPE_CODE_UNDEF;
|
176 |
|
|
TYPE_OBJFILE (type) = objfile;
|
177 |
|
|
TYPE_VPTR_FIELDNO (type) = -1;
|
178 |
|
|
TYPE_CHAIN (type) = type; /* Chain back to itself. */
|
179 |
|
|
|
180 |
|
|
return (type);
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
/* Alloc a new type instance structure, fill it with some defaults,
|
184 |
|
|
and point it at OLDTYPE. Allocate the new type instance from the
|
185 |
|
|
same place as OLDTYPE. */
|
186 |
|
|
|
187 |
|
|
static struct type *
|
188 |
|
|
alloc_type_instance (struct type *oldtype)
|
189 |
|
|
{
|
190 |
|
|
struct type *type;
|
191 |
|
|
|
192 |
|
|
/* Allocate the structure. */
|
193 |
|
|
|
194 |
|
|
if (TYPE_OBJFILE (oldtype) == NULL)
|
195 |
|
|
{
|
196 |
|
|
type = xmalloc (sizeof (struct type));
|
197 |
|
|
memset (type, 0, sizeof (struct type));
|
198 |
|
|
}
|
199 |
|
|
else
|
200 |
|
|
{
|
201 |
|
|
type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack,
|
202 |
|
|
sizeof (struct type));
|
203 |
|
|
memset (type, 0, sizeof (struct type));
|
204 |
|
|
}
|
205 |
|
|
TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
|
206 |
|
|
|
207 |
|
|
TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
|
208 |
|
|
|
209 |
|
|
return (type);
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
/* Clear all remnants of the previous type at TYPE, in preparation for
|
213 |
|
|
replacing it with something else. */
|
214 |
|
|
static void
|
215 |
|
|
smash_type (struct type *type)
|
216 |
|
|
{
|
217 |
|
|
memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
|
218 |
|
|
|
219 |
|
|
/* For now, delete the rings. */
|
220 |
|
|
TYPE_CHAIN (type) = type;
|
221 |
|
|
|
222 |
|
|
/* For now, leave the pointer/reference types alone. */
|
223 |
|
|
}
|
224 |
|
|
|
225 |
|
|
/* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
|
226 |
|
|
to a pointer to memory where the pointer type should be stored.
|
227 |
|
|
If *TYPEPTR is zero, update it to point to the pointer type we return.
|
228 |
|
|
We allocate new memory if needed. */
|
229 |
|
|
|
230 |
|
|
struct type *
|
231 |
|
|
make_pointer_type (struct type *type, struct type **typeptr)
|
232 |
|
|
{
|
233 |
|
|
struct type *ntype; /* New type */
|
234 |
|
|
struct objfile *objfile;
|
235 |
|
|
struct type *chain;
|
236 |
|
|
|
237 |
|
|
ntype = TYPE_POINTER_TYPE (type);
|
238 |
|
|
|
239 |
|
|
if (ntype)
|
240 |
|
|
{
|
241 |
|
|
if (typeptr == 0)
|
242 |
|
|
return ntype; /* Don't care about alloc,
|
243 |
|
|
and have new type. */
|
244 |
|
|
else if (*typeptr == 0)
|
245 |
|
|
{
|
246 |
|
|
*typeptr = ntype; /* Tracking alloc, and have new type. */
|
247 |
|
|
return ntype;
|
248 |
|
|
}
|
249 |
|
|
}
|
250 |
|
|
|
251 |
|
|
if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
|
252 |
|
|
{
|
253 |
|
|
ntype = alloc_type (TYPE_OBJFILE (type));
|
254 |
|
|
if (typeptr)
|
255 |
|
|
*typeptr = ntype;
|
256 |
|
|
}
|
257 |
|
|
else /* We have storage, but need to reset it. */
|
258 |
|
|
{
|
259 |
|
|
ntype = *typeptr;
|
260 |
|
|
objfile = TYPE_OBJFILE (ntype);
|
261 |
|
|
chain = TYPE_CHAIN (ntype);
|
262 |
|
|
smash_type (ntype);
|
263 |
|
|
TYPE_CHAIN (ntype) = chain;
|
264 |
|
|
TYPE_OBJFILE (ntype) = objfile;
|
265 |
|
|
}
|
266 |
|
|
|
267 |
|
|
TYPE_TARGET_TYPE (ntype) = type;
|
268 |
|
|
TYPE_POINTER_TYPE (type) = ntype;
|
269 |
|
|
|
270 |
|
|
/* FIXME! Assume the machine has only one representation for
|
271 |
|
|
pointers! */
|
272 |
|
|
|
273 |
|
|
TYPE_LENGTH (ntype) =
|
274 |
|
|
gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
|
275 |
|
|
TYPE_CODE (ntype) = TYPE_CODE_PTR;
|
276 |
|
|
|
277 |
|
|
/* Mark pointers as unsigned. The target converts between pointers
|
278 |
|
|
and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
|
279 |
|
|
gdbarch_address_to_pointer. */
|
280 |
|
|
TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
|
281 |
|
|
|
282 |
|
|
if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
|
283 |
|
|
TYPE_POINTER_TYPE (type) = ntype;
|
284 |
|
|
|
285 |
|
|
/* Update the length of all the other variants of this type. */
|
286 |
|
|
chain = TYPE_CHAIN (ntype);
|
287 |
|
|
while (chain != ntype)
|
288 |
|
|
{
|
289 |
|
|
TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
|
290 |
|
|
chain = TYPE_CHAIN (chain);
|
291 |
|
|
}
|
292 |
|
|
|
293 |
|
|
return ntype;
|
294 |
|
|
}
|
295 |
|
|
|
296 |
|
|
/* Given a type TYPE, return a type of pointers to that type.
|
297 |
|
|
May need to construct such a type if this is the first use. */
|
298 |
|
|
|
299 |
|
|
struct type *
|
300 |
|
|
lookup_pointer_type (struct type *type)
|
301 |
|
|
{
|
302 |
|
|
return make_pointer_type (type, (struct type **) 0);
|
303 |
|
|
}
|
304 |
|
|
|
305 |
|
|
/* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero,
|
306 |
|
|
points to a pointer to memory where the reference type should be
|
307 |
|
|
stored. If *TYPEPTR is zero, update it to point to the reference
|
308 |
|
|
type we return. We allocate new memory if needed. */
|
309 |
|
|
|
310 |
|
|
struct type *
|
311 |
|
|
make_reference_type (struct type *type, struct type **typeptr)
|
312 |
|
|
{
|
313 |
|
|
struct type *ntype; /* New type */
|
314 |
|
|
struct objfile *objfile;
|
315 |
|
|
struct type *chain;
|
316 |
|
|
|
317 |
|
|
ntype = TYPE_REFERENCE_TYPE (type);
|
318 |
|
|
|
319 |
|
|
if (ntype)
|
320 |
|
|
{
|
321 |
|
|
if (typeptr == 0)
|
322 |
|
|
return ntype; /* Don't care about alloc,
|
323 |
|
|
and have new type. */
|
324 |
|
|
else if (*typeptr == 0)
|
325 |
|
|
{
|
326 |
|
|
*typeptr = ntype; /* Tracking alloc, and have new type. */
|
327 |
|
|
return ntype;
|
328 |
|
|
}
|
329 |
|
|
}
|
330 |
|
|
|
331 |
|
|
if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
|
332 |
|
|
{
|
333 |
|
|
ntype = alloc_type (TYPE_OBJFILE (type));
|
334 |
|
|
if (typeptr)
|
335 |
|
|
*typeptr = ntype;
|
336 |
|
|
}
|
337 |
|
|
else /* We have storage, but need to reset it. */
|
338 |
|
|
{
|
339 |
|
|
ntype = *typeptr;
|
340 |
|
|
objfile = TYPE_OBJFILE (ntype);
|
341 |
|
|
chain = TYPE_CHAIN (ntype);
|
342 |
|
|
smash_type (ntype);
|
343 |
|
|
TYPE_CHAIN (ntype) = chain;
|
344 |
|
|
TYPE_OBJFILE (ntype) = objfile;
|
345 |
|
|
}
|
346 |
|
|
|
347 |
|
|
TYPE_TARGET_TYPE (ntype) = type;
|
348 |
|
|
TYPE_REFERENCE_TYPE (type) = ntype;
|
349 |
|
|
|
350 |
|
|
/* FIXME! Assume the machine has only one representation for
|
351 |
|
|
references, and that it matches the (only) representation for
|
352 |
|
|
pointers! */
|
353 |
|
|
|
354 |
|
|
TYPE_LENGTH (ntype) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
|
355 |
|
|
TYPE_CODE (ntype) = TYPE_CODE_REF;
|
356 |
|
|
|
357 |
|
|
if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
|
358 |
|
|
TYPE_REFERENCE_TYPE (type) = ntype;
|
359 |
|
|
|
360 |
|
|
/* Update the length of all the other variants of this type. */
|
361 |
|
|
chain = TYPE_CHAIN (ntype);
|
362 |
|
|
while (chain != ntype)
|
363 |
|
|
{
|
364 |
|
|
TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
|
365 |
|
|
chain = TYPE_CHAIN (chain);
|
366 |
|
|
}
|
367 |
|
|
|
368 |
|
|
return ntype;
|
369 |
|
|
}
|
370 |
|
|
|
371 |
|
|
/* Same as above, but caller doesn't care about memory allocation
|
372 |
|
|
details. */
|
373 |
|
|
|
374 |
|
|
struct type *
|
375 |
|
|
lookup_reference_type (struct type *type)
|
376 |
|
|
{
|
377 |
|
|
return make_reference_type (type, (struct type **) 0);
|
378 |
|
|
}
|
379 |
|
|
|
380 |
|
|
/* Lookup a function type that returns type TYPE. TYPEPTR, if
|
381 |
|
|
nonzero, points to a pointer to memory where the function type
|
382 |
|
|
should be stored. If *TYPEPTR is zero, update it to point to the
|
383 |
|
|
function type we return. We allocate new memory if needed. */
|
384 |
|
|
|
385 |
|
|
struct type *
|
386 |
|
|
make_function_type (struct type *type, struct type **typeptr)
|
387 |
|
|
{
|
388 |
|
|
struct type *ntype; /* New type */
|
389 |
|
|
struct objfile *objfile;
|
390 |
|
|
|
391 |
|
|
if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
|
392 |
|
|
{
|
393 |
|
|
ntype = alloc_type (TYPE_OBJFILE (type));
|
394 |
|
|
if (typeptr)
|
395 |
|
|
*typeptr = ntype;
|
396 |
|
|
}
|
397 |
|
|
else /* We have storage, but need to reset it. */
|
398 |
|
|
{
|
399 |
|
|
ntype = *typeptr;
|
400 |
|
|
objfile = TYPE_OBJFILE (ntype);
|
401 |
|
|
smash_type (ntype);
|
402 |
|
|
TYPE_OBJFILE (ntype) = objfile;
|
403 |
|
|
}
|
404 |
|
|
|
405 |
|
|
TYPE_TARGET_TYPE (ntype) = type;
|
406 |
|
|
|
407 |
|
|
TYPE_LENGTH (ntype) = 1;
|
408 |
|
|
TYPE_CODE (ntype) = TYPE_CODE_FUNC;
|
409 |
|
|
|
410 |
|
|
return ntype;
|
411 |
|
|
}
|
412 |
|
|
|
413 |
|
|
|
414 |
|
|
/* Given a type TYPE, return a type of functions that return that type.
|
415 |
|
|
May need to construct such a type if this is the first use. */
|
416 |
|
|
|
417 |
|
|
struct type *
|
418 |
|
|
lookup_function_type (struct type *type)
|
419 |
|
|
{
|
420 |
|
|
return make_function_type (type, (struct type **) 0);
|
421 |
|
|
}
|
422 |
|
|
|
423 |
|
|
/* Identify address space identifier by name --
|
424 |
|
|
return the integer flag defined in gdbtypes.h. */
|
425 |
|
|
extern int
|
426 |
|
|
address_space_name_to_int (char *space_identifier)
|
427 |
|
|
{
|
428 |
|
|
struct gdbarch *gdbarch = current_gdbarch;
|
429 |
|
|
int type_flags;
|
430 |
|
|
/* Check for known address space delimiters. */
|
431 |
|
|
if (!strcmp (space_identifier, "code"))
|
432 |
|
|
return TYPE_FLAG_CODE_SPACE;
|
433 |
|
|
else if (!strcmp (space_identifier, "data"))
|
434 |
|
|
return TYPE_FLAG_DATA_SPACE;
|
435 |
|
|
else if (gdbarch_address_class_name_to_type_flags_p (gdbarch)
|
436 |
|
|
&& gdbarch_address_class_name_to_type_flags (gdbarch,
|
437 |
|
|
space_identifier,
|
438 |
|
|
&type_flags))
|
439 |
|
|
return type_flags;
|
440 |
|
|
else
|
441 |
|
|
error (_("Unknown address space specifier: \"%s\""), space_identifier);
|
442 |
|
|
}
|
443 |
|
|
|
444 |
|
|
/* Identify address space identifier by integer flag as defined in
|
445 |
|
|
gdbtypes.h -- return the string version of the adress space name. */
|
446 |
|
|
|
447 |
|
|
const char *
|
448 |
|
|
address_space_int_to_name (int space_flag)
|
449 |
|
|
{
|
450 |
|
|
struct gdbarch *gdbarch = current_gdbarch;
|
451 |
|
|
if (space_flag & TYPE_FLAG_CODE_SPACE)
|
452 |
|
|
return "code";
|
453 |
|
|
else if (space_flag & TYPE_FLAG_DATA_SPACE)
|
454 |
|
|
return "data";
|
455 |
|
|
else if ((space_flag & TYPE_FLAG_ADDRESS_CLASS_ALL)
|
456 |
|
|
&& gdbarch_address_class_type_flags_to_name_p (gdbarch))
|
457 |
|
|
return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag);
|
458 |
|
|
else
|
459 |
|
|
return NULL;
|
460 |
|
|
}
|
461 |
|
|
|
462 |
|
|
/* Create a new type with instance flags NEW_FLAGS, based on TYPE.
|
463 |
|
|
|
464 |
|
|
If STORAGE is non-NULL, create the new type instance there.
|
465 |
|
|
STORAGE must be in the same obstack as TYPE. */
|
466 |
|
|
|
467 |
|
|
static struct type *
|
468 |
|
|
make_qualified_type (struct type *type, int new_flags,
|
469 |
|
|
struct type *storage)
|
470 |
|
|
{
|
471 |
|
|
struct type *ntype;
|
472 |
|
|
|
473 |
|
|
ntype = type;
|
474 |
|
|
do {
|
475 |
|
|
if (TYPE_INSTANCE_FLAGS (ntype) == new_flags)
|
476 |
|
|
return ntype;
|
477 |
|
|
ntype = TYPE_CHAIN (ntype);
|
478 |
|
|
} while (ntype != type);
|
479 |
|
|
|
480 |
|
|
/* Create a new type instance. */
|
481 |
|
|
if (storage == NULL)
|
482 |
|
|
ntype = alloc_type_instance (type);
|
483 |
|
|
else
|
484 |
|
|
{
|
485 |
|
|
/* If STORAGE was provided, it had better be in the same objfile
|
486 |
|
|
as TYPE. Otherwise, we can't link it into TYPE's cv chain:
|
487 |
|
|
if one objfile is freed and the other kept, we'd have
|
488 |
|
|
dangling pointers. */
|
489 |
|
|
gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
|
490 |
|
|
|
491 |
|
|
ntype = storage;
|
492 |
|
|
TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
|
493 |
|
|
TYPE_CHAIN (ntype) = ntype;
|
494 |
|
|
}
|
495 |
|
|
|
496 |
|
|
/* Pointers or references to the original type are not relevant to
|
497 |
|
|
the new type. */
|
498 |
|
|
TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
|
499 |
|
|
TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
|
500 |
|
|
|
501 |
|
|
/* Chain the new qualified type to the old type. */
|
502 |
|
|
TYPE_CHAIN (ntype) = TYPE_CHAIN (type);
|
503 |
|
|
TYPE_CHAIN (type) = ntype;
|
504 |
|
|
|
505 |
|
|
/* Now set the instance flags and return the new type. */
|
506 |
|
|
TYPE_INSTANCE_FLAGS (ntype) = new_flags;
|
507 |
|
|
|
508 |
|
|
/* Set length of new type to that of the original type. */
|
509 |
|
|
TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
|
510 |
|
|
|
511 |
|
|
return ntype;
|
512 |
|
|
}
|
513 |
|
|
|
514 |
|
|
/* Make an address-space-delimited variant of a type -- a type that
|
515 |
|
|
is identical to the one supplied except that it has an address
|
516 |
|
|
space attribute attached to it (such as "code" or "data").
|
517 |
|
|
|
518 |
|
|
The space attributes "code" and "data" are for Harvard
|
519 |
|
|
architectures. The address space attributes are for architectures
|
520 |
|
|
which have alternately sized pointers or pointers with alternate
|
521 |
|
|
representations. */
|
522 |
|
|
|
523 |
|
|
struct type *
|
524 |
|
|
make_type_with_address_space (struct type *type, int space_flag)
|
525 |
|
|
{
|
526 |
|
|
struct type *ntype;
|
527 |
|
|
int new_flags = ((TYPE_INSTANCE_FLAGS (type)
|
528 |
|
|
& ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE
|
529 |
|
|
| TYPE_FLAG_ADDRESS_CLASS_ALL))
|
530 |
|
|
| space_flag);
|
531 |
|
|
|
532 |
|
|
return make_qualified_type (type, new_flags, NULL);
|
533 |
|
|
}
|
534 |
|
|
|
535 |
|
|
/* Make a "c-v" variant of a type -- a type that is identical to the
|
536 |
|
|
one supplied except that it may have const or volatile attributes
|
537 |
|
|
CNST is a flag for setting the const attribute
|
538 |
|
|
VOLTL is a flag for setting the volatile attribute
|
539 |
|
|
TYPE is the base type whose variant we are creating.
|
540 |
|
|
|
541 |
|
|
If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
|
542 |
|
|
storage to hold the new qualified type; *TYPEPTR and TYPE must be
|
543 |
|
|
in the same objfile. Otherwise, allocate fresh memory for the new
|
544 |
|
|
type whereever TYPE lives. If TYPEPTR is non-zero, set it to the
|
545 |
|
|
new type we construct. */
|
546 |
|
|
struct type *
|
547 |
|
|
make_cv_type (int cnst, int voltl,
|
548 |
|
|
struct type *type,
|
549 |
|
|
struct type **typeptr)
|
550 |
|
|
{
|
551 |
|
|
struct type *ntype; /* New type */
|
552 |
|
|
struct type *tmp_type = type; /* tmp type */
|
553 |
|
|
struct objfile *objfile;
|
554 |
|
|
|
555 |
|
|
int new_flags = (TYPE_INSTANCE_FLAGS (type)
|
556 |
|
|
& ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE));
|
557 |
|
|
|
558 |
|
|
if (cnst)
|
559 |
|
|
new_flags |= TYPE_FLAG_CONST;
|
560 |
|
|
|
561 |
|
|
if (voltl)
|
562 |
|
|
new_flags |= TYPE_FLAG_VOLATILE;
|
563 |
|
|
|
564 |
|
|
if (typeptr && *typeptr != NULL)
|
565 |
|
|
{
|
566 |
|
|
/* TYPE and *TYPEPTR must be in the same objfile. We can't have
|
567 |
|
|
a C-V variant chain that threads across objfiles: if one
|
568 |
|
|
objfile gets freed, then the other has a broken C-V chain.
|
569 |
|
|
|
570 |
|
|
This code used to try to copy over the main type from TYPE to
|
571 |
|
|
*TYPEPTR if they were in different objfiles, but that's
|
572 |
|
|
wrong, too: TYPE may have a field list or member function
|
573 |
|
|
lists, which refer to types of their own, etc. etc. The
|
574 |
|
|
whole shebang would need to be copied over recursively; you
|
575 |
|
|
can't have inter-objfile pointers. The only thing to do is
|
576 |
|
|
to leave stub types as stub types, and look them up afresh by
|
577 |
|
|
name each time you encounter them. */
|
578 |
|
|
gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
|
579 |
|
|
}
|
580 |
|
|
|
581 |
|
|
ntype = make_qualified_type (type, new_flags,
|
582 |
|
|
typeptr ? *typeptr : NULL);
|
583 |
|
|
|
584 |
|
|
if (typeptr != NULL)
|
585 |
|
|
*typeptr = ntype;
|
586 |
|
|
|
587 |
|
|
return ntype;
|
588 |
|
|
}
|
589 |
|
|
|
590 |
|
|
/* Replace the contents of ntype with the type *type. This changes the
|
591 |
|
|
contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus
|
592 |
|
|
the changes are propogated to all types in the TYPE_CHAIN.
|
593 |
|
|
|
594 |
|
|
In order to build recursive types, it's inevitable that we'll need
|
595 |
|
|
to update types in place --- but this sort of indiscriminate
|
596 |
|
|
smashing is ugly, and needs to be replaced with something more
|
597 |
|
|
controlled. TYPE_MAIN_TYPE is a step in this direction; it's not
|
598 |
|
|
clear if more steps are needed. */
|
599 |
|
|
void
|
600 |
|
|
replace_type (struct type *ntype, struct type *type)
|
601 |
|
|
{
|
602 |
|
|
struct type *chain;
|
603 |
|
|
|
604 |
|
|
/* These two types had better be in the same objfile. Otherwise,
|
605 |
|
|
the assignment of one type's main type structure to the other
|
606 |
|
|
will produce a type with references to objects (names; field
|
607 |
|
|
lists; etc.) allocated on an objfile other than its own. */
|
608 |
|
|
gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype));
|
609 |
|
|
|
610 |
|
|
*TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
|
611 |
|
|
|
612 |
|
|
/* The type length is not a part of the main type. Update it for
|
613 |
|
|
each type on the variant chain. */
|
614 |
|
|
chain = ntype;
|
615 |
|
|
do {
|
616 |
|
|
/* Assert that this element of the chain has no address-class bits
|
617 |
|
|
set in its flags. Such type variants might have type lengths
|
618 |
|
|
which are supposed to be different from the non-address-class
|
619 |
|
|
variants. This assertion shouldn't ever be triggered because
|
620 |
|
|
symbol readers which do construct address-class variants don't
|
621 |
|
|
call replace_type(). */
|
622 |
|
|
gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
|
623 |
|
|
|
624 |
|
|
TYPE_LENGTH (chain) = TYPE_LENGTH (type);
|
625 |
|
|
chain = TYPE_CHAIN (chain);
|
626 |
|
|
} while (ntype != chain);
|
627 |
|
|
|
628 |
|
|
/* Assert that the two types have equivalent instance qualifiers.
|
629 |
|
|
This should be true for at least all of our debug readers. */
|
630 |
|
|
gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type));
|
631 |
|
|
}
|
632 |
|
|
|
633 |
|
|
/* Implement direct support for MEMBER_TYPE in GNU C++.
|
634 |
|
|
May need to construct such a type if this is the first use.
|
635 |
|
|
The TYPE is the type of the member. The DOMAIN is the type
|
636 |
|
|
of the aggregate that the member belongs to. */
|
637 |
|
|
|
638 |
|
|
struct type *
|
639 |
|
|
lookup_memberptr_type (struct type *type, struct type *domain)
|
640 |
|
|
{
|
641 |
|
|
struct type *mtype;
|
642 |
|
|
|
643 |
|
|
mtype = alloc_type (TYPE_OBJFILE (type));
|
644 |
|
|
smash_to_memberptr_type (mtype, domain, type);
|
645 |
|
|
return (mtype);
|
646 |
|
|
}
|
647 |
|
|
|
648 |
|
|
/* Return a pointer-to-method type, for a method of type TO_TYPE. */
|
649 |
|
|
|
650 |
|
|
struct type *
|
651 |
|
|
lookup_methodptr_type (struct type *to_type)
|
652 |
|
|
{
|
653 |
|
|
struct type *mtype;
|
654 |
|
|
|
655 |
|
|
mtype = alloc_type (TYPE_OBJFILE (to_type));
|
656 |
|
|
TYPE_TARGET_TYPE (mtype) = to_type;
|
657 |
|
|
TYPE_DOMAIN_TYPE (mtype) = TYPE_DOMAIN_TYPE (to_type);
|
658 |
|
|
TYPE_LENGTH (mtype) = cplus_method_ptr_size ();
|
659 |
|
|
TYPE_CODE (mtype) = TYPE_CODE_METHODPTR;
|
660 |
|
|
return mtype;
|
661 |
|
|
}
|
662 |
|
|
|
663 |
|
|
/* Allocate a stub method whose return type is TYPE. This apparently
|
664 |
|
|
happens for speed of symbol reading, since parsing out the
|
665 |
|
|
arguments to the method is cpu-intensive, the way we are doing it.
|
666 |
|
|
So, we will fill in arguments later. This always returns a fresh
|
667 |
|
|
type. */
|
668 |
|
|
|
669 |
|
|
struct type *
|
670 |
|
|
allocate_stub_method (struct type *type)
|
671 |
|
|
{
|
672 |
|
|
struct type *mtype;
|
673 |
|
|
|
674 |
|
|
mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
|
675 |
|
|
TYPE_OBJFILE (type));
|
676 |
|
|
TYPE_TARGET_TYPE (mtype) = type;
|
677 |
|
|
/* _DOMAIN_TYPE (mtype) = unknown yet */
|
678 |
|
|
return (mtype);
|
679 |
|
|
}
|
680 |
|
|
|
681 |
|
|
/* Create a range type using either a blank type supplied in
|
682 |
|
|
RESULT_TYPE, or creating a new type, inheriting the objfile from
|
683 |
|
|
INDEX_TYPE.
|
684 |
|
|
|
685 |
|
|
Indices will be of type INDEX_TYPE, and will range from LOW_BOUND
|
686 |
|
|
to HIGH_BOUND, inclusive.
|
687 |
|
|
|
688 |
|
|
FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
|
689 |
|
|
sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
|
690 |
|
|
|
691 |
|
|
struct type *
|
692 |
|
|
create_range_type (struct type *result_type, struct type *index_type,
|
693 |
|
|
int low_bound, int high_bound)
|
694 |
|
|
{
|
695 |
|
|
if (result_type == NULL)
|
696 |
|
|
{
|
697 |
|
|
result_type = alloc_type (TYPE_OBJFILE (index_type));
|
698 |
|
|
}
|
699 |
|
|
TYPE_CODE (result_type) = TYPE_CODE_RANGE;
|
700 |
|
|
TYPE_TARGET_TYPE (result_type) = index_type;
|
701 |
|
|
if (TYPE_STUB (index_type))
|
702 |
|
|
TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
|
703 |
|
|
else
|
704 |
|
|
TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
|
705 |
|
|
TYPE_NFIELDS (result_type) = 2;
|
706 |
|
|
TYPE_FIELDS (result_type) = (struct field *)
|
707 |
|
|
TYPE_ALLOC (result_type, 2 * sizeof (struct field));
|
708 |
|
|
memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
|
709 |
|
|
TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
|
710 |
|
|
TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
|
711 |
|
|
|
712 |
|
|
if (low_bound >= 0)
|
713 |
|
|
TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
|
714 |
|
|
|
715 |
|
|
return (result_type);
|
716 |
|
|
}
|
717 |
|
|
|
718 |
|
|
/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
|
719 |
|
|
TYPE. Return 1 if type is a range type, 0 if it is discrete (and
|
720 |
|
|
bounds will fit in LONGEST), or -1 otherwise. */
|
721 |
|
|
|
722 |
|
|
int
|
723 |
|
|
get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
|
724 |
|
|
{
|
725 |
|
|
CHECK_TYPEDEF (type);
|
726 |
|
|
switch (TYPE_CODE (type))
|
727 |
|
|
{
|
728 |
|
|
case TYPE_CODE_RANGE:
|
729 |
|
|
*lowp = TYPE_LOW_BOUND (type);
|
730 |
|
|
*highp = TYPE_HIGH_BOUND (type);
|
731 |
|
|
return 1;
|
732 |
|
|
case TYPE_CODE_ENUM:
|
733 |
|
|
if (TYPE_NFIELDS (type) > 0)
|
734 |
|
|
{
|
735 |
|
|
/* The enums may not be sorted by value, so search all
|
736 |
|
|
entries */
|
737 |
|
|
int i;
|
738 |
|
|
|
739 |
|
|
*lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
|
740 |
|
|
for (i = 0; i < TYPE_NFIELDS (type); i++)
|
741 |
|
|
{
|
742 |
|
|
if (TYPE_FIELD_BITPOS (type, i) < *lowp)
|
743 |
|
|
*lowp = TYPE_FIELD_BITPOS (type, i);
|
744 |
|
|
if (TYPE_FIELD_BITPOS (type, i) > *highp)
|
745 |
|
|
*highp = TYPE_FIELD_BITPOS (type, i);
|
746 |
|
|
}
|
747 |
|
|
|
748 |
|
|
/* Set unsigned indicator if warranted. */
|
749 |
|
|
if (*lowp >= 0)
|
750 |
|
|
{
|
751 |
|
|
TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
|
752 |
|
|
}
|
753 |
|
|
}
|
754 |
|
|
else
|
755 |
|
|
{
|
756 |
|
|
*lowp = 0;
|
757 |
|
|
*highp = -1;
|
758 |
|
|
}
|
759 |
|
|
return 0;
|
760 |
|
|
case TYPE_CODE_BOOL:
|
761 |
|
|
*lowp = 0;
|
762 |
|
|
*highp = 1;
|
763 |
|
|
return 0;
|
764 |
|
|
case TYPE_CODE_INT:
|
765 |
|
|
if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
|
766 |
|
|
return -1;
|
767 |
|
|
if (!TYPE_UNSIGNED (type))
|
768 |
|
|
{
|
769 |
|
|
*lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
|
770 |
|
|
*highp = -*lowp - 1;
|
771 |
|
|
return 0;
|
772 |
|
|
}
|
773 |
|
|
/* ... fall through for unsigned ints ... */
|
774 |
|
|
case TYPE_CODE_CHAR:
|
775 |
|
|
*lowp = 0;
|
776 |
|
|
/* This round-about calculation is to avoid shifting by
|
777 |
|
|
TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
|
778 |
|
|
if TYPE_LENGTH (type) == sizeof (LONGEST). */
|
779 |
|
|
*highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
|
780 |
|
|
*highp = (*highp - 1) | *highp;
|
781 |
|
|
return 0;
|
782 |
|
|
default:
|
783 |
|
|
return -1;
|
784 |
|
|
}
|
785 |
|
|
}
|
786 |
|
|
|
787 |
|
|
/* Create an array type using either a blank type supplied in
|
788 |
|
|
RESULT_TYPE, or creating a new type, inheriting the objfile from
|
789 |
|
|
RANGE_TYPE.
|
790 |
|
|
|
791 |
|
|
Elements will be of type ELEMENT_TYPE, the indices will be of type
|
792 |
|
|
RANGE_TYPE.
|
793 |
|
|
|
794 |
|
|
FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
|
795 |
|
|
sure it is TYPE_CODE_UNDEF before we bash it into an array
|
796 |
|
|
type? */
|
797 |
|
|
|
798 |
|
|
struct type *
|
799 |
|
|
create_array_type (struct type *result_type,
|
800 |
|
|
struct type *element_type,
|
801 |
|
|
struct type *range_type)
|
802 |
|
|
{
|
803 |
|
|
LONGEST low_bound, high_bound;
|
804 |
|
|
|
805 |
|
|
if (result_type == NULL)
|
806 |
|
|
{
|
807 |
|
|
result_type = alloc_type (TYPE_OBJFILE (range_type));
|
808 |
|
|
}
|
809 |
|
|
TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
|
810 |
|
|
TYPE_TARGET_TYPE (result_type) = element_type;
|
811 |
|
|
if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
|
812 |
|
|
low_bound = high_bound = 0;
|
813 |
|
|
CHECK_TYPEDEF (element_type);
|
814 |
|
|
/* Be careful when setting the array length. Ada arrays can be
|
815 |
|
|
empty arrays with the high_bound being smaller than the low_bound.
|
816 |
|
|
In such cases, the array length should be zero. */
|
817 |
|
|
if (high_bound < low_bound)
|
818 |
|
|
TYPE_LENGTH (result_type) = 0;
|
819 |
|
|
else
|
820 |
|
|
TYPE_LENGTH (result_type) =
|
821 |
|
|
TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
|
822 |
|
|
TYPE_NFIELDS (result_type) = 1;
|
823 |
|
|
TYPE_FIELDS (result_type) =
|
824 |
|
|
(struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
|
825 |
|
|
memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
|
826 |
|
|
TYPE_FIELD_TYPE (result_type, 0) = range_type;
|
827 |
|
|
TYPE_VPTR_FIELDNO (result_type) = -1;
|
828 |
|
|
|
829 |
|
|
/* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
|
830 |
|
|
if (TYPE_LENGTH (result_type) == 0)
|
831 |
|
|
TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
|
832 |
|
|
|
833 |
|
|
return (result_type);
|
834 |
|
|
}
|
835 |
|
|
|
836 |
|
|
/* Create a string type using either a blank type supplied in
|
837 |
|
|
RESULT_TYPE, or creating a new type. String types are similar
|
838 |
|
|
enough to array of char types that we can use create_array_type to
|
839 |
|
|
build the basic type and then bash it into a string type.
|
840 |
|
|
|
841 |
|
|
For fixed length strings, the range type contains 0 as the lower
|
842 |
|
|
bound and the length of the string minus one as the upper bound.
|
843 |
|
|
|
844 |
|
|
FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
|
845 |
|
|
sure it is TYPE_CODE_UNDEF before we bash it into a string
|
846 |
|
|
type? */
|
847 |
|
|
|
848 |
|
|
struct type *
|
849 |
|
|
create_string_type (struct type *result_type,
|
850 |
|
|
struct type *range_type)
|
851 |
|
|
{
|
852 |
|
|
struct type *string_char_type;
|
853 |
|
|
|
854 |
|
|
string_char_type = language_string_char_type (current_language,
|
855 |
|
|
current_gdbarch);
|
856 |
|
|
result_type = create_array_type (result_type,
|
857 |
|
|
string_char_type,
|
858 |
|
|
range_type);
|
859 |
|
|
TYPE_CODE (result_type) = TYPE_CODE_STRING;
|
860 |
|
|
return (result_type);
|
861 |
|
|
}
|
862 |
|
|
|
863 |
|
|
struct type *
|
864 |
|
|
create_set_type (struct type *result_type, struct type *domain_type)
|
865 |
|
|
{
|
866 |
|
|
if (result_type == NULL)
|
867 |
|
|
{
|
868 |
|
|
result_type = alloc_type (TYPE_OBJFILE (domain_type));
|
869 |
|
|
}
|
870 |
|
|
TYPE_CODE (result_type) = TYPE_CODE_SET;
|
871 |
|
|
TYPE_NFIELDS (result_type) = 1;
|
872 |
|
|
TYPE_FIELDS (result_type) = (struct field *)
|
873 |
|
|
TYPE_ALLOC (result_type, 1 * sizeof (struct field));
|
874 |
|
|
memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
|
875 |
|
|
|
876 |
|
|
if (!TYPE_STUB (domain_type))
|
877 |
|
|
{
|
878 |
|
|
LONGEST low_bound, high_bound, bit_length;
|
879 |
|
|
if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
|
880 |
|
|
low_bound = high_bound = 0;
|
881 |
|
|
bit_length = high_bound - low_bound + 1;
|
882 |
|
|
TYPE_LENGTH (result_type)
|
883 |
|
|
= (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
|
884 |
|
|
if (low_bound >= 0)
|
885 |
|
|
TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
|
886 |
|
|
}
|
887 |
|
|
TYPE_FIELD_TYPE (result_type, 0) = domain_type;
|
888 |
|
|
|
889 |
|
|
return (result_type);
|
890 |
|
|
}
|
891 |
|
|
|
892 |
|
|
void
|
893 |
|
|
append_flags_type_flag (struct type *type, int bitpos, char *name)
|
894 |
|
|
{
|
895 |
|
|
gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
|
896 |
|
|
gdb_assert (bitpos < TYPE_NFIELDS (type));
|
897 |
|
|
gdb_assert (bitpos >= 0);
|
898 |
|
|
|
899 |
|
|
if (name)
|
900 |
|
|
{
|
901 |
|
|
TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
|
902 |
|
|
TYPE_FIELD_BITPOS (type, bitpos) = bitpos;
|
903 |
|
|
}
|
904 |
|
|
else
|
905 |
|
|
{
|
906 |
|
|
/* Don't show this field to the user. */
|
907 |
|
|
TYPE_FIELD_BITPOS (type, bitpos) = -1;
|
908 |
|
|
}
|
909 |
|
|
}
|
910 |
|
|
|
911 |
|
|
struct type *
|
912 |
|
|
init_flags_type (char *name, int length)
|
913 |
|
|
{
|
914 |
|
|
int nfields = length * TARGET_CHAR_BIT;
|
915 |
|
|
struct type *type;
|
916 |
|
|
|
917 |
|
|
type = init_type (TYPE_CODE_FLAGS, length,
|
918 |
|
|
TYPE_FLAG_UNSIGNED, name, NULL);
|
919 |
|
|
TYPE_NFIELDS (type) = nfields;
|
920 |
|
|
TYPE_FIELDS (type) = TYPE_ALLOC (type,
|
921 |
|
|
nfields * sizeof (struct field));
|
922 |
|
|
memset (TYPE_FIELDS (type), 0, nfields * sizeof (struct field));
|
923 |
|
|
|
924 |
|
|
return type;
|
925 |
|
|
}
|
926 |
|
|
|
927 |
|
|
/* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE
|
928 |
|
|
and any array types nested inside it. */
|
929 |
|
|
|
930 |
|
|
void
|
931 |
|
|
make_vector_type (struct type *array_type)
|
932 |
|
|
{
|
933 |
|
|
struct type *inner_array, *elt_type;
|
934 |
|
|
int flags;
|
935 |
|
|
|
936 |
|
|
/* Find the innermost array type, in case the array is
|
937 |
|
|
multi-dimensional. */
|
938 |
|
|
inner_array = array_type;
|
939 |
|
|
while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
|
940 |
|
|
inner_array = TYPE_TARGET_TYPE (inner_array);
|
941 |
|
|
|
942 |
|
|
elt_type = TYPE_TARGET_TYPE (inner_array);
|
943 |
|
|
if (TYPE_CODE (elt_type) == TYPE_CODE_INT)
|
944 |
|
|
{
|
945 |
|
|
flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_FLAG_NOTTEXT;
|
946 |
|
|
elt_type = make_qualified_type (elt_type, flags, NULL);
|
947 |
|
|
TYPE_TARGET_TYPE (inner_array) = elt_type;
|
948 |
|
|
}
|
949 |
|
|
|
950 |
|
|
TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR;
|
951 |
|
|
}
|
952 |
|
|
|
953 |
|
|
struct type *
|
954 |
|
|
init_vector_type (struct type *elt_type, int n)
|
955 |
|
|
{
|
956 |
|
|
struct type *array_type;
|
957 |
|
|
|
958 |
|
|
array_type = create_array_type (0, elt_type,
|
959 |
|
|
create_range_type (0,
|
960 |
|
|
builtin_type_int32,
|
961 |
|
|
0, n-1));
|
962 |
|
|
make_vector_type (array_type);
|
963 |
|
|
return array_type;
|
964 |
|
|
}
|
965 |
|
|
|
966 |
|
|
/* Smash TYPE to be a type of pointers to members of DOMAIN with type
|
967 |
|
|
TO_TYPE. A member pointer is a wierd thing -- it amounts to a
|
968 |
|
|
typed offset into a struct, e.g. "an int at offset 8". A MEMBER
|
969 |
|
|
TYPE doesn't include the offset (that's the value of the MEMBER
|
970 |
|
|
itself), but does include the structure type into which it points
|
971 |
|
|
(for some reason).
|
972 |
|
|
|
973 |
|
|
When "smashing" the type, we preserve the objfile that the old type
|
974 |
|
|
pointed to, since we aren't changing where the type is actually
|
975 |
|
|
allocated. */
|
976 |
|
|
|
977 |
|
|
void
|
978 |
|
|
smash_to_memberptr_type (struct type *type, struct type *domain,
|
979 |
|
|
struct type *to_type)
|
980 |
|
|
{
|
981 |
|
|
struct objfile *objfile;
|
982 |
|
|
|
983 |
|
|
objfile = TYPE_OBJFILE (type);
|
984 |
|
|
|
985 |
|
|
smash_type (type);
|
986 |
|
|
TYPE_OBJFILE (type) = objfile;
|
987 |
|
|
TYPE_TARGET_TYPE (type) = to_type;
|
988 |
|
|
TYPE_DOMAIN_TYPE (type) = domain;
|
989 |
|
|
/* Assume that a data member pointer is the same size as a normal
|
990 |
|
|
pointer. */
|
991 |
|
|
TYPE_LENGTH (type) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT;
|
992 |
|
|
TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
|
993 |
|
|
}
|
994 |
|
|
|
995 |
|
|
/* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
|
996 |
|
|
METHOD just means `function that gets an extra "this" argument'.
|
997 |
|
|
|
998 |
|
|
When "smashing" the type, we preserve the objfile that the old type
|
999 |
|
|
pointed to, since we aren't changing where the type is actually
|
1000 |
|
|
allocated. */
|
1001 |
|
|
|
1002 |
|
|
void
|
1003 |
|
|
smash_to_method_type (struct type *type, struct type *domain,
|
1004 |
|
|
struct type *to_type, struct field *args,
|
1005 |
|
|
int nargs, int varargs)
|
1006 |
|
|
{
|
1007 |
|
|
struct objfile *objfile;
|
1008 |
|
|
|
1009 |
|
|
objfile = TYPE_OBJFILE (type);
|
1010 |
|
|
|
1011 |
|
|
smash_type (type);
|
1012 |
|
|
TYPE_OBJFILE (type) = objfile;
|
1013 |
|
|
TYPE_TARGET_TYPE (type) = to_type;
|
1014 |
|
|
TYPE_DOMAIN_TYPE (type) = domain;
|
1015 |
|
|
TYPE_FIELDS (type) = args;
|
1016 |
|
|
TYPE_NFIELDS (type) = nargs;
|
1017 |
|
|
if (varargs)
|
1018 |
|
|
TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS;
|
1019 |
|
|
TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
|
1020 |
|
|
TYPE_CODE (type) = TYPE_CODE_METHOD;
|
1021 |
|
|
}
|
1022 |
|
|
|
1023 |
|
|
/* Return a typename for a struct/union/enum type without "struct ",
|
1024 |
|
|
"union ", or "enum ". If the type has a NULL name, return NULL. */
|
1025 |
|
|
|
1026 |
|
|
char *
|
1027 |
|
|
type_name_no_tag (const struct type *type)
|
1028 |
|
|
{
|
1029 |
|
|
if (TYPE_TAG_NAME (type) != NULL)
|
1030 |
|
|
return TYPE_TAG_NAME (type);
|
1031 |
|
|
|
1032 |
|
|
/* Is there code which expects this to return the name if there is
|
1033 |
|
|
no tag name? My guess is that this is mainly used for C++ in
|
1034 |
|
|
cases where the two will always be the same. */
|
1035 |
|
|
return TYPE_NAME (type);
|
1036 |
|
|
}
|
1037 |
|
|
|
1038 |
|
|
/* Lookup a typedef or primitive type named NAME, visible in lexical
|
1039 |
|
|
block BLOCK. If NOERR is nonzero, return zero if NAME is not
|
1040 |
|
|
suitably defined. */
|
1041 |
|
|
|
1042 |
|
|
struct type *
|
1043 |
|
|
lookup_typename (char *name, struct block *block, int noerr)
|
1044 |
|
|
{
|
1045 |
|
|
struct symbol *sym;
|
1046 |
|
|
struct type *tmp;
|
1047 |
|
|
|
1048 |
|
|
sym = lookup_symbol (name, block, VAR_DOMAIN, 0,
|
1049 |
|
|
(struct symtab **) NULL);
|
1050 |
|
|
if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
|
1051 |
|
|
{
|
1052 |
|
|
tmp = language_lookup_primitive_type_by_name (current_language,
|
1053 |
|
|
current_gdbarch,
|
1054 |
|
|
name);
|
1055 |
|
|
if (tmp)
|
1056 |
|
|
{
|
1057 |
|
|
return (tmp);
|
1058 |
|
|
}
|
1059 |
|
|
else if (!tmp && noerr)
|
1060 |
|
|
{
|
1061 |
|
|
return (NULL);
|
1062 |
|
|
}
|
1063 |
|
|
else
|
1064 |
|
|
{
|
1065 |
|
|
error (_("No type named %s."), name);
|
1066 |
|
|
}
|
1067 |
|
|
}
|
1068 |
|
|
return (SYMBOL_TYPE (sym));
|
1069 |
|
|
}
|
1070 |
|
|
|
1071 |
|
|
struct type *
|
1072 |
|
|
lookup_unsigned_typename (char *name)
|
1073 |
|
|
{
|
1074 |
|
|
char *uns = alloca (strlen (name) + 10);
|
1075 |
|
|
|
1076 |
|
|
strcpy (uns, "unsigned ");
|
1077 |
|
|
strcpy (uns + 9, name);
|
1078 |
|
|
return (lookup_typename (uns, (struct block *) NULL, 0));
|
1079 |
|
|
}
|
1080 |
|
|
|
1081 |
|
|
struct type *
|
1082 |
|
|
lookup_signed_typename (char *name)
|
1083 |
|
|
{
|
1084 |
|
|
struct type *t;
|
1085 |
|
|
char *uns = alloca (strlen (name) + 8);
|
1086 |
|
|
|
1087 |
|
|
strcpy (uns, "signed ");
|
1088 |
|
|
strcpy (uns + 7, name);
|
1089 |
|
|
t = lookup_typename (uns, (struct block *) NULL, 1);
|
1090 |
|
|
/* If we don't find "signed FOO" just try again with plain "FOO". */
|
1091 |
|
|
if (t != NULL)
|
1092 |
|
|
return t;
|
1093 |
|
|
return lookup_typename (name, (struct block *) NULL, 0);
|
1094 |
|
|
}
|
1095 |
|
|
|
1096 |
|
|
/* Lookup a structure type named "struct NAME",
|
1097 |
|
|
visible in lexical block BLOCK. */
|
1098 |
|
|
|
1099 |
|
|
struct type *
|
1100 |
|
|
lookup_struct (char *name, struct block *block)
|
1101 |
|
|
{
|
1102 |
|
|
struct symbol *sym;
|
1103 |
|
|
|
1104 |
|
|
sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
|
1105 |
|
|
(struct symtab **) NULL);
|
1106 |
|
|
|
1107 |
|
|
if (sym == NULL)
|
1108 |
|
|
{
|
1109 |
|
|
error (_("No struct type named %s."), name);
|
1110 |
|
|
}
|
1111 |
|
|
if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
|
1112 |
|
|
{
|
1113 |
|
|
error (_("This context has class, union or enum %s, not a struct."),
|
1114 |
|
|
name);
|
1115 |
|
|
}
|
1116 |
|
|
return (SYMBOL_TYPE (sym));
|
1117 |
|
|
}
|
1118 |
|
|
|
1119 |
|
|
/* Lookup a union type named "union NAME",
|
1120 |
|
|
visible in lexical block BLOCK. */
|
1121 |
|
|
|
1122 |
|
|
struct type *
|
1123 |
|
|
lookup_union (char *name, struct block *block)
|
1124 |
|
|
{
|
1125 |
|
|
struct symbol *sym;
|
1126 |
|
|
struct type *t;
|
1127 |
|
|
|
1128 |
|
|
sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
|
1129 |
|
|
(struct symtab **) NULL);
|
1130 |
|
|
|
1131 |
|
|
if (sym == NULL)
|
1132 |
|
|
error (_("No union type named %s."), name);
|
1133 |
|
|
|
1134 |
|
|
t = SYMBOL_TYPE (sym);
|
1135 |
|
|
|
1136 |
|
|
if (TYPE_CODE (t) == TYPE_CODE_UNION)
|
1137 |
|
|
return (t);
|
1138 |
|
|
|
1139 |
|
|
/* C++ unions may come out with TYPE_CODE_CLASS, but we look at
|
1140 |
|
|
* a further "declared_type" field to discover it is really a union.
|
1141 |
|
|
*/
|
1142 |
|
|
if (HAVE_CPLUS_STRUCT (t))
|
1143 |
|
|
if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
|
1144 |
|
|
return (t);
|
1145 |
|
|
|
1146 |
|
|
/* If we get here, it's not a union. */
|
1147 |
|
|
error (_("This context has class, struct or enum %s, not a union."),
|
1148 |
|
|
name);
|
1149 |
|
|
}
|
1150 |
|
|
|
1151 |
|
|
|
1152 |
|
|
/* Lookup an enum type named "enum NAME",
|
1153 |
|
|
visible in lexical block BLOCK. */
|
1154 |
|
|
|
1155 |
|
|
struct type *
|
1156 |
|
|
lookup_enum (char *name, struct block *block)
|
1157 |
|
|
{
|
1158 |
|
|
struct symbol *sym;
|
1159 |
|
|
|
1160 |
|
|
sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0,
|
1161 |
|
|
(struct symtab **) NULL);
|
1162 |
|
|
if (sym == NULL)
|
1163 |
|
|
{
|
1164 |
|
|
error (_("No enum type named %s."), name);
|
1165 |
|
|
}
|
1166 |
|
|
if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
|
1167 |
|
|
{
|
1168 |
|
|
error (_("This context has class, struct or union %s, not an enum."),
|
1169 |
|
|
name);
|
1170 |
|
|
}
|
1171 |
|
|
return (SYMBOL_TYPE (sym));
|
1172 |
|
|
}
|
1173 |
|
|
|
1174 |
|
|
/* Lookup a template type named "template NAME<TYPE>",
|
1175 |
|
|
visible in lexical block BLOCK. */
|
1176 |
|
|
|
1177 |
|
|
struct type *
|
1178 |
|
|
lookup_template_type (char *name, struct type *type,
|
1179 |
|
|
struct block *block)
|
1180 |
|
|
{
|
1181 |
|
|
struct symbol *sym;
|
1182 |
|
|
char *nam = (char *)
|
1183 |
|
|
alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4);
|
1184 |
|
|
strcpy (nam, name);
|
1185 |
|
|
strcat (nam, "<");
|
1186 |
|
|
strcat (nam, TYPE_NAME (type));
|
1187 |
|
|
strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
|
1188 |
|
|
|
1189 |
|
|
sym = lookup_symbol (nam, block, VAR_DOMAIN, 0,
|
1190 |
|
|
(struct symtab **) NULL);
|
1191 |
|
|
|
1192 |
|
|
if (sym == NULL)
|
1193 |
|
|
{
|
1194 |
|
|
error (_("No template type named %s."), name);
|
1195 |
|
|
}
|
1196 |
|
|
if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
|
1197 |
|
|
{
|
1198 |
|
|
error (_("This context has class, union or enum %s, not a struct."),
|
1199 |
|
|
name);
|
1200 |
|
|
}
|
1201 |
|
|
return (SYMBOL_TYPE (sym));
|
1202 |
|
|
}
|
1203 |
|
|
|
1204 |
|
|
/* Given a type TYPE, lookup the type of the component of type named
|
1205 |
|
|
NAME.
|
1206 |
|
|
|
1207 |
|
|
TYPE can be either a struct or union, or a pointer or reference to
|
1208 |
|
|
a struct or union. If it is a pointer or reference, its target
|
1209 |
|
|
type is automatically used. Thus '.' and '->' are interchangable,
|
1210 |
|
|
as specified for the definitions of the expression element types
|
1211 |
|
|
STRUCTOP_STRUCT and STRUCTOP_PTR.
|
1212 |
|
|
|
1213 |
|
|
If NOERR is nonzero, return zero if NAME is not suitably defined.
|
1214 |
|
|
If NAME is the name of a baseclass type, return that type. */
|
1215 |
|
|
|
1216 |
|
|
struct type *
|
1217 |
|
|
lookup_struct_elt_type (struct type *type, char *name, int noerr)
|
1218 |
|
|
{
|
1219 |
|
|
int i;
|
1220 |
|
|
|
1221 |
|
|
for (;;)
|
1222 |
|
|
{
|
1223 |
|
|
CHECK_TYPEDEF (type);
|
1224 |
|
|
if (TYPE_CODE (type) != TYPE_CODE_PTR
|
1225 |
|
|
&& TYPE_CODE (type) != TYPE_CODE_REF)
|
1226 |
|
|
break;
|
1227 |
|
|
type = TYPE_TARGET_TYPE (type);
|
1228 |
|
|
}
|
1229 |
|
|
|
1230 |
|
|
if (TYPE_CODE (type) != TYPE_CODE_STRUCT
|
1231 |
|
|
&& TYPE_CODE (type) != TYPE_CODE_UNION)
|
1232 |
|
|
{
|
1233 |
|
|
target_terminal_ours ();
|
1234 |
|
|
gdb_flush (gdb_stdout);
|
1235 |
|
|
fprintf_unfiltered (gdb_stderr, "Type ");
|
1236 |
|
|
type_print (type, "", gdb_stderr, -1);
|
1237 |
|
|
error (_(" is not a structure or union type."));
|
1238 |
|
|
}
|
1239 |
|
|
|
1240 |
|
|
#if 0
|
1241 |
|
|
/* FIXME: This change put in by Michael seems incorrect for the case
|
1242 |
|
|
where the structure tag name is the same as the member name.
|
1243 |
|
|
I.E. when doing "ptype bell->bar" for "struct foo { int bar; int
|
1244 |
|
|
foo; } bell;" Disabled by fnf. */
|
1245 |
|
|
{
|
1246 |
|
|
char *typename;
|
1247 |
|
|
|
1248 |
|
|
typename = type_name_no_tag (type);
|
1249 |
|
|
if (typename != NULL && strcmp (typename, name) == 0)
|
1250 |
|
|
return type;
|
1251 |
|
|
}
|
1252 |
|
|
#endif
|
1253 |
|
|
|
1254 |
|
|
for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
|
1255 |
|
|
{
|
1256 |
|
|
char *t_field_name = TYPE_FIELD_NAME (type, i);
|
1257 |
|
|
|
1258 |
|
|
if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
|
1259 |
|
|
{
|
1260 |
|
|
return TYPE_FIELD_TYPE (type, i);
|
1261 |
|
|
}
|
1262 |
|
|
}
|
1263 |
|
|
|
1264 |
|
|
/* OK, it's not in this class. Recursively check the baseclasses. */
|
1265 |
|
|
for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
|
1266 |
|
|
{
|
1267 |
|
|
struct type *t;
|
1268 |
|
|
|
1269 |
|
|
t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1);
|
1270 |
|
|
if (t != NULL)
|
1271 |
|
|
{
|
1272 |
|
|
return t;
|
1273 |
|
|
}
|
1274 |
|
|
}
|
1275 |
|
|
|
1276 |
|
|
if (noerr)
|
1277 |
|
|
{
|
1278 |
|
|
return NULL;
|
1279 |
|
|
}
|
1280 |
|
|
|
1281 |
|
|
target_terminal_ours ();
|
1282 |
|
|
gdb_flush (gdb_stdout);
|
1283 |
|
|
fprintf_unfiltered (gdb_stderr, "Type ");
|
1284 |
|
|
type_print (type, "", gdb_stderr, -1);
|
1285 |
|
|
fprintf_unfiltered (gdb_stderr, " has no component named ");
|
1286 |
|
|
fputs_filtered (name, gdb_stderr);
|
1287 |
|
|
error (("."));
|
1288 |
|
|
return (struct type *) -1; /* For lint */
|
1289 |
|
|
}
|
1290 |
|
|
|
1291 |
|
|
/* Lookup the vptr basetype/fieldno values for TYPE.
|
1292 |
|
|
If found store vptr_basetype in *BASETYPEP if non-NULL, and return
|
1293 |
|
|
vptr_fieldno. Also, if found and basetype is from the same objfile,
|
1294 |
|
|
cache the results.
|
1295 |
|
|
If not found, return -1 and ignore BASETYPEP.
|
1296 |
|
|
Callers should be aware that in some cases (for example,
|
1297 |
|
|
the type or one of its baseclasses is a stub type and we are
|
1298 |
|
|
debugging a .o file), this function will not be able to find the
|
1299 |
|
|
virtual function table pointer, and vptr_fieldno will remain -1 and
|
1300 |
|
|
vptr_basetype will remain NULL or incomplete. */
|
1301 |
|
|
|
1302 |
|
|
int
|
1303 |
|
|
get_vptr_fieldno (struct type *type, struct type **basetypep)
|
1304 |
|
|
{
|
1305 |
|
|
CHECK_TYPEDEF (type);
|
1306 |
|
|
|
1307 |
|
|
if (TYPE_VPTR_FIELDNO (type) < 0)
|
1308 |
|
|
{
|
1309 |
|
|
int i;
|
1310 |
|
|
|
1311 |
|
|
/* We must start at zero in case the first (and only) baseclass
|
1312 |
|
|
is virtual (and hence we cannot share the table pointer). */
|
1313 |
|
|
for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
|
1314 |
|
|
{
|
1315 |
|
|
struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
|
1316 |
|
|
int fieldno;
|
1317 |
|
|
struct type *basetype;
|
1318 |
|
|
|
1319 |
|
|
fieldno = get_vptr_fieldno (baseclass, &basetype);
|
1320 |
|
|
if (fieldno >= 0)
|
1321 |
|
|
{
|
1322 |
|
|
/* If the type comes from a different objfile we can't cache
|
1323 |
|
|
it, it may have a different lifetime. PR 2384 */
|
1324 |
|
|
if (TYPE_OBJFILE (type) == TYPE_OBJFILE (baseclass))
|
1325 |
|
|
{
|
1326 |
|
|
TYPE_VPTR_FIELDNO (type) = fieldno;
|
1327 |
|
|
TYPE_VPTR_BASETYPE (type) = basetype;
|
1328 |
|
|
}
|
1329 |
|
|
if (basetypep)
|
1330 |
|
|
*basetypep = basetype;
|
1331 |
|
|
return fieldno;
|
1332 |
|
|
}
|
1333 |
|
|
}
|
1334 |
|
|
|
1335 |
|
|
/* Not found. */
|
1336 |
|
|
return -1;
|
1337 |
|
|
}
|
1338 |
|
|
else
|
1339 |
|
|
{
|
1340 |
|
|
if (basetypep)
|
1341 |
|
|
*basetypep = TYPE_VPTR_BASETYPE (type);
|
1342 |
|
|
return TYPE_VPTR_FIELDNO (type);
|
1343 |
|
|
}
|
1344 |
|
|
}
|
1345 |
|
|
|
1346 |
|
|
/* Find the method and field indices for the destructor in class type T.
|
1347 |
|
|
Return 1 if the destructor was found, otherwise, return 0. */
|
1348 |
|
|
|
1349 |
|
|
int
|
1350 |
|
|
get_destructor_fn_field (struct type *t,
|
1351 |
|
|
int *method_indexp,
|
1352 |
|
|
int *field_indexp)
|
1353 |
|
|
{
|
1354 |
|
|
int i;
|
1355 |
|
|
|
1356 |
|
|
for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
|
1357 |
|
|
{
|
1358 |
|
|
int j;
|
1359 |
|
|
struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
|
1360 |
|
|
|
1361 |
|
|
for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
|
1362 |
|
|
{
|
1363 |
|
|
if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
|
1364 |
|
|
{
|
1365 |
|
|
*method_indexp = i;
|
1366 |
|
|
*field_indexp = j;
|
1367 |
|
|
return 1;
|
1368 |
|
|
}
|
1369 |
|
|
}
|
1370 |
|
|
}
|
1371 |
|
|
return 0;
|
1372 |
|
|
}
|
1373 |
|
|
|
1374 |
|
|
static void
|
1375 |
|
|
stub_noname_complaint (void)
|
1376 |
|
|
{
|
1377 |
|
|
complaint (&symfile_complaints, _("stub type has NULL name"));
|
1378 |
|
|
}
|
1379 |
|
|
|
1380 |
|
|
/* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
|
1381 |
|
|
|
1382 |
|
|
If this is a stubbed struct (i.e. declared as struct foo *), see if
|
1383 |
|
|
we can find a full definition in some other file. If so, copy this
|
1384 |
|
|
definition, so we can use it in future. There used to be a comment
|
1385 |
|
|
(but not any code) that if we don't find a full definition, we'd
|
1386 |
|
|
set a flag so we don't spend time in the future checking the same
|
1387 |
|
|
type. That would be a mistake, though--we might load in more
|
1388 |
|
|
symbols which contain a full definition for the type.
|
1389 |
|
|
|
1390 |
|
|
This used to be coded as a macro, but I don't think it is called
|
1391 |
|
|
often enough to merit such treatment. */
|
1392 |
|
|
|
1393 |
|
|
/* Find the real type of TYPE. This function returns the real type,
|
1394 |
|
|
after removing all layers of typedefs and completing opaque or stub
|
1395 |
|
|
types. Completion changes the TYPE argument, but stripping of
|
1396 |
|
|
typedefs does not. */
|
1397 |
|
|
|
1398 |
|
|
struct type *
|
1399 |
|
|
check_typedef (struct type *type)
|
1400 |
|
|
{
|
1401 |
|
|
struct type *orig_type = type;
|
1402 |
|
|
int is_const, is_volatile;
|
1403 |
|
|
|
1404 |
|
|
gdb_assert (type);
|
1405 |
|
|
|
1406 |
|
|
while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
|
1407 |
|
|
{
|
1408 |
|
|
if (!TYPE_TARGET_TYPE (type))
|
1409 |
|
|
{
|
1410 |
|
|
char *name;
|
1411 |
|
|
struct symbol *sym;
|
1412 |
|
|
|
1413 |
|
|
/* It is dangerous to call lookup_symbol if we are currently
|
1414 |
|
|
reading a symtab. Infinite recursion is one danger. */
|
1415 |
|
|
if (currently_reading_symtab)
|
1416 |
|
|
return type;
|
1417 |
|
|
|
1418 |
|
|
name = type_name_no_tag (type);
|
1419 |
|
|
/* FIXME: shouldn't we separately check the TYPE_NAME and
|
1420 |
|
|
the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or
|
1421 |
|
|
VAR_DOMAIN as appropriate? (this code was written before
|
1422 |
|
|
TYPE_NAME and TYPE_TAG_NAME were separate). */
|
1423 |
|
|
if (name == NULL)
|
1424 |
|
|
{
|
1425 |
|
|
stub_noname_complaint ();
|
1426 |
|
|
return type;
|
1427 |
|
|
}
|
1428 |
|
|
sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0,
|
1429 |
|
|
(struct symtab **) NULL);
|
1430 |
|
|
if (sym)
|
1431 |
|
|
TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
|
1432 |
|
|
else /* TYPE_CODE_UNDEF */
|
1433 |
|
|
TYPE_TARGET_TYPE (type) = alloc_type (NULL);
|
1434 |
|
|
}
|
1435 |
|
|
type = TYPE_TARGET_TYPE (type);
|
1436 |
|
|
}
|
1437 |
|
|
|
1438 |
|
|
is_const = TYPE_CONST (type);
|
1439 |
|
|
is_volatile = TYPE_VOLATILE (type);
|
1440 |
|
|
|
1441 |
|
|
/* If this is a struct/class/union with no fields, then check
|
1442 |
|
|
whether a full definition exists somewhere else. This is for
|
1443 |
|
|
systems where a type definition with no fields is issued for such
|
1444 |
|
|
types, instead of identifying them as stub types in the first
|
1445 |
|
|
place. */
|
1446 |
|
|
|
1447 |
|
|
if (TYPE_IS_OPAQUE (type)
|
1448 |
|
|
&& opaque_type_resolution
|
1449 |
|
|
&& !currently_reading_symtab)
|
1450 |
|
|
{
|
1451 |
|
|
char *name = type_name_no_tag (type);
|
1452 |
|
|
struct type *newtype;
|
1453 |
|
|
if (name == NULL)
|
1454 |
|
|
{
|
1455 |
|
|
stub_noname_complaint ();
|
1456 |
|
|
return type;
|
1457 |
|
|
}
|
1458 |
|
|
newtype = lookup_transparent_type (name);
|
1459 |
|
|
|
1460 |
|
|
if (newtype)
|
1461 |
|
|
{
|
1462 |
|
|
/* If the resolved type and the stub are in the same
|
1463 |
|
|
objfile, then replace the stub type with the real deal.
|
1464 |
|
|
But if they're in separate objfiles, leave the stub
|
1465 |
|
|
alone; we'll just look up the transparent type every time
|
1466 |
|
|
we call check_typedef. We can't create pointers between
|
1467 |
|
|
types allocated to different objfiles, since they may
|
1468 |
|
|
have different lifetimes. Trying to copy NEWTYPE over to
|
1469 |
|
|
TYPE's objfile is pointless, too, since you'll have to
|
1470 |
|
|
move over any other types NEWTYPE refers to, which could
|
1471 |
|
|
be an unbounded amount of stuff. */
|
1472 |
|
|
if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
|
1473 |
|
|
make_cv_type (is_const, is_volatile, newtype, &type);
|
1474 |
|
|
else
|
1475 |
|
|
type = newtype;
|
1476 |
|
|
}
|
1477 |
|
|
}
|
1478 |
|
|
/* Otherwise, rely on the stub flag being set for opaque/stubbed
|
1479 |
|
|
types. */
|
1480 |
|
|
else if (TYPE_STUB (type) && !currently_reading_symtab)
|
1481 |
|
|
{
|
1482 |
|
|
char *name = type_name_no_tag (type);
|
1483 |
|
|
/* FIXME: shouldn't we separately check the TYPE_NAME and the
|
1484 |
|
|
TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
|
1485 |
|
|
as appropriate? (this code was written before TYPE_NAME and
|
1486 |
|
|
TYPE_TAG_NAME were separate). */
|
1487 |
|
|
struct symbol *sym;
|
1488 |
|
|
if (name == NULL)
|
1489 |
|
|
{
|
1490 |
|
|
stub_noname_complaint ();
|
1491 |
|
|
return type;
|
1492 |
|
|
}
|
1493 |
|
|
sym = lookup_symbol (name, 0, STRUCT_DOMAIN,
|
1494 |
|
|
0, (struct symtab **) NULL);
|
1495 |
|
|
if (sym)
|
1496 |
|
|
{
|
1497 |
|
|
/* Same as above for opaque types, we can replace the stub
|
1498 |
|
|
with the complete type only if they are int the same
|
1499 |
|
|
objfile. */
|
1500 |
|
|
if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type))
|
1501 |
|
|
make_cv_type (is_const, is_volatile,
|
1502 |
|
|
SYMBOL_TYPE (sym), &type);
|
1503 |
|
|
else
|
1504 |
|
|
type = SYMBOL_TYPE (sym);
|
1505 |
|
|
}
|
1506 |
|
|
}
|
1507 |
|
|
|
1508 |
|
|
if (TYPE_TARGET_STUB (type))
|
1509 |
|
|
{
|
1510 |
|
|
struct type *range_type;
|
1511 |
|
|
struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
|
1512 |
|
|
|
1513 |
|
|
if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
|
1514 |
|
|
{
|
1515 |
|
|
/* Empty. */
|
1516 |
|
|
}
|
1517 |
|
|
else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
|
1518 |
|
|
&& TYPE_NFIELDS (type) == 1
|
1519 |
|
|
&& (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
|
1520 |
|
|
== TYPE_CODE_RANGE))
|
1521 |
|
|
{
|
1522 |
|
|
/* Now recompute the length of the array type, based on its
|
1523 |
|
|
number of elements and the target type's length.
|
1524 |
|
|
Watch out for Ada null Ada arrays where the high bound
|
1525 |
|
|
is smaller than the low bound. */
|
1526 |
|
|
const int low_bound = TYPE_FIELD_BITPOS (range_type, 0);
|
1527 |
|
|
const int high_bound = TYPE_FIELD_BITPOS (range_type, 1);
|
1528 |
|
|
int nb_elements;
|
1529 |
|
|
|
1530 |
|
|
if (high_bound < low_bound)
|
1531 |
|
|
nb_elements = 0;
|
1532 |
|
|
else
|
1533 |
|
|
nb_elements = high_bound - low_bound + 1;
|
1534 |
|
|
|
1535 |
|
|
TYPE_LENGTH (type) = nb_elements * TYPE_LENGTH (target_type);
|
1536 |
|
|
TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
|
1537 |
|
|
}
|
1538 |
|
|
else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
|
1539 |
|
|
{
|
1540 |
|
|
TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
|
1541 |
|
|
TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
|
1542 |
|
|
}
|
1543 |
|
|
}
|
1544 |
|
|
/* Cache TYPE_LENGTH for future use. */
|
1545 |
|
|
TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
|
1546 |
|
|
return type;
|
1547 |
|
|
}
|
1548 |
|
|
|
1549 |
|
|
/* Parse a type expression in the string [P..P+LENGTH). If an error
|
1550 |
|
|
occurs, silently return builtin_type_void. */
|
1551 |
|
|
|
1552 |
|
|
static struct type *
|
1553 |
|
|
safe_parse_type (char *p, int length)
|
1554 |
|
|
{
|
1555 |
|
|
struct ui_file *saved_gdb_stderr;
|
1556 |
|
|
struct type *type;
|
1557 |
|
|
|
1558 |
|
|
/* Suppress error messages. */
|
1559 |
|
|
saved_gdb_stderr = gdb_stderr;
|
1560 |
|
|
gdb_stderr = ui_file_new ();
|
1561 |
|
|
|
1562 |
|
|
/* Call parse_and_eval_type() without fear of longjmp()s. */
|
1563 |
|
|
if (!gdb_parse_and_eval_type (p, length, &type))
|
1564 |
|
|
type = builtin_type_void;
|
1565 |
|
|
|
1566 |
|
|
/* Stop suppressing error messages. */
|
1567 |
|
|
ui_file_delete (gdb_stderr);
|
1568 |
|
|
gdb_stderr = saved_gdb_stderr;
|
1569 |
|
|
|
1570 |
|
|
return type;
|
1571 |
|
|
}
|
1572 |
|
|
|
1573 |
|
|
/* Ugly hack to convert method stubs into method types.
|
1574 |
|
|
|
1575 |
|
|
He ain't kiddin'. This demangles the name of the method into a
|
1576 |
|
|
string including argument types, parses out each argument type,
|
1577 |
|
|
generates a string casting a zero to that type, evaluates the
|
1578 |
|
|
string, and stuffs the resulting type into an argtype vector!!!
|
1579 |
|
|
Then it knows the type of the whole function (including argument
|
1580 |
|
|
types for overloading), which info used to be in the stab's but was
|
1581 |
|
|
removed to hack back the space required for them. */
|
1582 |
|
|
|
1583 |
|
|
static void
|
1584 |
|
|
check_stub_method (struct type *type, int method_id, int signature_id)
|
1585 |
|
|
{
|
1586 |
|
|
struct fn_field *f;
|
1587 |
|
|
char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
|
1588 |
|
|
char *demangled_name = cplus_demangle (mangled_name,
|
1589 |
|
|
DMGL_PARAMS | DMGL_ANSI);
|
1590 |
|
|
char *argtypetext, *p;
|
1591 |
|
|
int depth = 0, argcount = 1;
|
1592 |
|
|
struct field *argtypes;
|
1593 |
|
|
struct type *mtype;
|
1594 |
|
|
|
1595 |
|
|
/* Make sure we got back a function string that we can use. */
|
1596 |
|
|
if (demangled_name)
|
1597 |
|
|
p = strchr (demangled_name, '(');
|
1598 |
|
|
else
|
1599 |
|
|
p = NULL;
|
1600 |
|
|
|
1601 |
|
|
if (demangled_name == NULL || p == NULL)
|
1602 |
|
|
error (_("Internal: Cannot demangle mangled name `%s'."),
|
1603 |
|
|
mangled_name);
|
1604 |
|
|
|
1605 |
|
|
/* Now, read in the parameters that define this type. */
|
1606 |
|
|
p += 1;
|
1607 |
|
|
argtypetext = p;
|
1608 |
|
|
while (*p)
|
1609 |
|
|
{
|
1610 |
|
|
if (*p == '(' || *p == '<')
|
1611 |
|
|
{
|
1612 |
|
|
depth += 1;
|
1613 |
|
|
}
|
1614 |
|
|
else if (*p == ')' || *p == '>')
|
1615 |
|
|
{
|
1616 |
|
|
depth -= 1;
|
1617 |
|
|
}
|
1618 |
|
|
else if (*p == ',' && depth == 0)
|
1619 |
|
|
{
|
1620 |
|
|
argcount += 1;
|
1621 |
|
|
}
|
1622 |
|
|
|
1623 |
|
|
p += 1;
|
1624 |
|
|
}
|
1625 |
|
|
|
1626 |
|
|
/* If we read one argument and it was ``void'', don't count it. */
|
1627 |
|
|
if (strncmp (argtypetext, "(void)", 6) == 0)
|
1628 |
|
|
argcount -= 1;
|
1629 |
|
|
|
1630 |
|
|
/* We need one extra slot, for the THIS pointer. */
|
1631 |
|
|
|
1632 |
|
|
argtypes = (struct field *)
|
1633 |
|
|
TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field));
|
1634 |
|
|
p = argtypetext;
|
1635 |
|
|
|
1636 |
|
|
/* Add THIS pointer for non-static methods. */
|
1637 |
|
|
f = TYPE_FN_FIELDLIST1 (type, method_id);
|
1638 |
|
|
if (TYPE_FN_FIELD_STATIC_P (f, signature_id))
|
1639 |
|
|
argcount = 0;
|
1640 |
|
|
else
|
1641 |
|
|
{
|
1642 |
|
|
argtypes[0].type = lookup_pointer_type (type);
|
1643 |
|
|
argcount = 1;
|
1644 |
|
|
}
|
1645 |
|
|
|
1646 |
|
|
if (*p != ')') /* () means no args, skip while */
|
1647 |
|
|
{
|
1648 |
|
|
depth = 0;
|
1649 |
|
|
while (*p)
|
1650 |
|
|
{
|
1651 |
|
|
if (depth <= 0 && (*p == ',' || *p == ')'))
|
1652 |
|
|
{
|
1653 |
|
|
/* Avoid parsing of ellipsis, they will be handled below.
|
1654 |
|
|
Also avoid ``void'' as above. */
|
1655 |
|
|
if (strncmp (argtypetext, "...", p - argtypetext) != 0
|
1656 |
|
|
&& strncmp (argtypetext, "void", p - argtypetext) != 0)
|
1657 |
|
|
{
|
1658 |
|
|
argtypes[argcount].type =
|
1659 |
|
|
safe_parse_type (argtypetext, p - argtypetext);
|
1660 |
|
|
argcount += 1;
|
1661 |
|
|
}
|
1662 |
|
|
argtypetext = p + 1;
|
1663 |
|
|
}
|
1664 |
|
|
|
1665 |
|
|
if (*p == '(' || *p == '<')
|
1666 |
|
|
{
|
1667 |
|
|
depth += 1;
|
1668 |
|
|
}
|
1669 |
|
|
else if (*p == ')' || *p == '>')
|
1670 |
|
|
{
|
1671 |
|
|
depth -= 1;
|
1672 |
|
|
}
|
1673 |
|
|
|
1674 |
|
|
p += 1;
|
1675 |
|
|
}
|
1676 |
|
|
}
|
1677 |
|
|
|
1678 |
|
|
TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
|
1679 |
|
|
|
1680 |
|
|
/* Now update the old "stub" type into a real type. */
|
1681 |
|
|
mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
|
1682 |
|
|
TYPE_DOMAIN_TYPE (mtype) = type;
|
1683 |
|
|
TYPE_FIELDS (mtype) = argtypes;
|
1684 |
|
|
TYPE_NFIELDS (mtype) = argcount;
|
1685 |
|
|
TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
|
1686 |
|
|
TYPE_FN_FIELD_STUB (f, signature_id) = 0;
|
1687 |
|
|
if (p[-2] == '.')
|
1688 |
|
|
TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS;
|
1689 |
|
|
|
1690 |
|
|
xfree (demangled_name);
|
1691 |
|
|
}
|
1692 |
|
|
|
1693 |
|
|
/* This is the external interface to check_stub_method, above. This
|
1694 |
|
|
function unstubs all of the signatures for TYPE's METHOD_ID method
|
1695 |
|
|
name. After calling this function TYPE_FN_FIELD_STUB will be
|
1696 |
|
|
cleared for each signature and TYPE_FN_FIELDLIST_NAME will be
|
1697 |
|
|
correct.
|
1698 |
|
|
|
1699 |
|
|
This function unfortunately can not die until stabs do. */
|
1700 |
|
|
|
1701 |
|
|
void
|
1702 |
|
|
check_stub_method_group (struct type *type, int method_id)
|
1703 |
|
|
{
|
1704 |
|
|
int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
|
1705 |
|
|
struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
|
1706 |
|
|
int j, found_stub = 0;
|
1707 |
|
|
|
1708 |
|
|
for (j = 0; j < len; j++)
|
1709 |
|
|
if (TYPE_FN_FIELD_STUB (f, j))
|
1710 |
|
|
{
|
1711 |
|
|
found_stub = 1;
|
1712 |
|
|
check_stub_method (type, method_id, j);
|
1713 |
|
|
}
|
1714 |
|
|
|
1715 |
|
|
/* GNU v3 methods with incorrect names were corrected when we read
|
1716 |
|
|
in type information, because it was cheaper to do it then. The
|
1717 |
|
|
only GNU v2 methods with incorrect method names are operators and
|
1718 |
|
|
destructors; destructors were also corrected when we read in type
|
1719 |
|
|
information.
|
1720 |
|
|
|
1721 |
|
|
Therefore the only thing we need to handle here are v2 operator
|
1722 |
|
|
names. */
|
1723 |
|
|
if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0)
|
1724 |
|
|
{
|
1725 |
|
|
int ret;
|
1726 |
|
|
char dem_opname[256];
|
1727 |
|
|
|
1728 |
|
|
ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
|
1729 |
|
|
method_id),
|
1730 |
|
|
dem_opname, DMGL_ANSI);
|
1731 |
|
|
if (!ret)
|
1732 |
|
|
ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
|
1733 |
|
|
method_id),
|
1734 |
|
|
dem_opname, 0);
|
1735 |
|
|
if (ret)
|
1736 |
|
|
TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
|
1737 |
|
|
}
|
1738 |
|
|
}
|
1739 |
|
|
|
1740 |
|
|
const struct cplus_struct_type cplus_struct_default;
|
1741 |
|
|
|
1742 |
|
|
void
|
1743 |
|
|
allocate_cplus_struct_type (struct type *type)
|
1744 |
|
|
{
|
1745 |
|
|
if (!HAVE_CPLUS_STRUCT (type))
|
1746 |
|
|
{
|
1747 |
|
|
TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
|
1748 |
|
|
TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
|
1749 |
|
|
*(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
|
1750 |
|
|
}
|
1751 |
|
|
}
|
1752 |
|
|
|
1753 |
|
|
/* Helper function to initialize the standard scalar types.
|
1754 |
|
|
|
1755 |
|
|
If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy of
|
1756 |
|
|
the string pointed to by name in the objfile_obstack for that
|
1757 |
|
|
objfile, and initialize the type name to that copy. There are
|
1758 |
|
|
places (mipsread.c in particular, where init_type is called with a
|
1759 |
|
|
NULL value for NAME). */
|
1760 |
|
|
|
1761 |
|
|
struct type *
|
1762 |
|
|
init_type (enum type_code code, int length, int flags,
|
1763 |
|
|
char *name, struct objfile *objfile)
|
1764 |
|
|
{
|
1765 |
|
|
struct type *type;
|
1766 |
|
|
|
1767 |
|
|
type = alloc_type (objfile);
|
1768 |
|
|
TYPE_CODE (type) = code;
|
1769 |
|
|
TYPE_LENGTH (type) = length;
|
1770 |
|
|
TYPE_FLAGS (type) |= flags;
|
1771 |
|
|
if ((name != NULL) && (objfile != NULL))
|
1772 |
|
|
{
|
1773 |
|
|
TYPE_NAME (type) = obsavestring (name, strlen (name),
|
1774 |
|
|
&objfile->objfile_obstack);
|
1775 |
|
|
}
|
1776 |
|
|
else
|
1777 |
|
|
{
|
1778 |
|
|
TYPE_NAME (type) = name;
|
1779 |
|
|
}
|
1780 |
|
|
|
1781 |
|
|
/* C++ fancies. */
|
1782 |
|
|
|
1783 |
|
|
if (name && strcmp (name, "char") == 0)
|
1784 |
|
|
TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
|
1785 |
|
|
|
1786 |
|
|
if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
|
1787 |
|
|
|| code == TYPE_CODE_NAMESPACE)
|
1788 |
|
|
{
|
1789 |
|
|
INIT_CPLUS_SPECIFIC (type);
|
1790 |
|
|
}
|
1791 |
|
|
return (type);
|
1792 |
|
|
}
|
1793 |
|
|
|
1794 |
|
|
/* Helper function. Create an empty composite type. */
|
1795 |
|
|
|
1796 |
|
|
struct type *
|
1797 |
|
|
init_composite_type (char *name, enum type_code code)
|
1798 |
|
|
{
|
1799 |
|
|
struct type *t;
|
1800 |
|
|
gdb_assert (code == TYPE_CODE_STRUCT
|
1801 |
|
|
|| code == TYPE_CODE_UNION);
|
1802 |
|
|
t = init_type (code, 0, 0, NULL, NULL);
|
1803 |
|
|
TYPE_TAG_NAME (t) = name;
|
1804 |
|
|
return t;
|
1805 |
|
|
}
|
1806 |
|
|
|
1807 |
|
|
/* Helper function. Append a field to a composite type. */
|
1808 |
|
|
|
1809 |
|
|
void
|
1810 |
|
|
append_composite_type_field (struct type *t, char *name,
|
1811 |
|
|
struct type *field)
|
1812 |
|
|
{
|
1813 |
|
|
struct field *f;
|
1814 |
|
|
TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
|
1815 |
|
|
TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t),
|
1816 |
|
|
sizeof (struct field) * TYPE_NFIELDS (t));
|
1817 |
|
|
f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
|
1818 |
|
|
memset (f, 0, sizeof f[0]);
|
1819 |
|
|
FIELD_TYPE (f[0]) = field;
|
1820 |
|
|
FIELD_NAME (f[0]) = name;
|
1821 |
|
|
if (TYPE_CODE (t) == TYPE_CODE_UNION)
|
1822 |
|
|
{
|
1823 |
|
|
if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
|
1824 |
|
|
TYPE_LENGTH (t) = TYPE_LENGTH (field);
|
1825 |
|
|
}
|
1826 |
|
|
else if (TYPE_CODE (t) == TYPE_CODE_STRUCT)
|
1827 |
|
|
{
|
1828 |
|
|
TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
|
1829 |
|
|
if (TYPE_NFIELDS (t) > 1)
|
1830 |
|
|
{
|
1831 |
|
|
FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
|
1832 |
|
|
+ TYPE_LENGTH (field) * TARGET_CHAR_BIT);
|
1833 |
|
|
}
|
1834 |
|
|
}
|
1835 |
|
|
}
|
1836 |
|
|
|
1837 |
|
|
int
|
1838 |
|
|
can_dereference (struct type *t)
|
1839 |
|
|
{
|
1840 |
|
|
/* FIXME: Should we return true for references as well as
|
1841 |
|
|
pointers? */
|
1842 |
|
|
CHECK_TYPEDEF (t);
|
1843 |
|
|
return
|
1844 |
|
|
(t != NULL
|
1845 |
|
|
&& TYPE_CODE (t) == TYPE_CODE_PTR
|
1846 |
|
|
&& TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
|
1847 |
|
|
}
|
1848 |
|
|
|
1849 |
|
|
int
|
1850 |
|
|
is_integral_type (struct type *t)
|
1851 |
|
|
{
|
1852 |
|
|
CHECK_TYPEDEF (t);
|
1853 |
|
|
return
|
1854 |
|
|
((t != NULL)
|
1855 |
|
|
&& ((TYPE_CODE (t) == TYPE_CODE_INT)
|
1856 |
|
|
|| (TYPE_CODE (t) == TYPE_CODE_ENUM)
|
1857 |
|
|
|| (TYPE_CODE (t) == TYPE_CODE_FLAGS)
|
1858 |
|
|
|| (TYPE_CODE (t) == TYPE_CODE_CHAR)
|
1859 |
|
|
|| (TYPE_CODE (t) == TYPE_CODE_RANGE)
|
1860 |
|
|
|| (TYPE_CODE (t) == TYPE_CODE_BOOL)));
|
1861 |
|
|
}
|
1862 |
|
|
|
1863 |
|
|
/* Check whether BASE is an ancestor or base class or DCLASS
|
1864 |
|
|
Return 1 if so, and 0 if not.
|
1865 |
|
|
Note: callers may want to check for identity of the types before
|
1866 |
|
|
calling this function -- identical types are considered to satisfy
|
1867 |
|
|
the ancestor relationship even if they're identical. */
|
1868 |
|
|
|
1869 |
|
|
int
|
1870 |
|
|
is_ancestor (struct type *base, struct type *dclass)
|
1871 |
|
|
{
|
1872 |
|
|
int i;
|
1873 |
|
|
|
1874 |
|
|
CHECK_TYPEDEF (base);
|
1875 |
|
|
CHECK_TYPEDEF (dclass);
|
1876 |
|
|
|
1877 |
|
|
if (base == dclass)
|
1878 |
|
|
return 1;
|
1879 |
|
|
if (TYPE_NAME (base) && TYPE_NAME (dclass)
|
1880 |
|
|
&& !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
|
1881 |
|
|
return 1;
|
1882 |
|
|
|
1883 |
|
|
for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
|
1884 |
|
|
if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
|
1885 |
|
|
return 1;
|
1886 |
|
|
|
1887 |
|
|
return 0;
|
1888 |
|
|
}
|
1889 |
|
|
|
1890 |
|
|
|
1891 |
|
|
|
1892 |
|
|
/* Functions for overload resolution begin here */
|
1893 |
|
|
|
1894 |
|
|
/* Compare two badness vectors A and B and return the result.
|
1895 |
|
|
|
1896 |
|
|
1 => A and B are incomparable
|
1897 |
|
|
2 => A is better than B
|
1898 |
|
|
3 => A is worse than B */
|
1899 |
|
|
|
1900 |
|
|
int
|
1901 |
|
|
compare_badness (struct badness_vector *a, struct badness_vector *b)
|
1902 |
|
|
{
|
1903 |
|
|
int i;
|
1904 |
|
|
int tmp;
|
1905 |
|
|
short found_pos = 0; /* any positives in c? */
|
1906 |
|
|
short found_neg = 0; /* any negatives in c? */
|
1907 |
|
|
|
1908 |
|
|
/* differing lengths => incomparable */
|
1909 |
|
|
if (a->length != b->length)
|
1910 |
|
|
return 1;
|
1911 |
|
|
|
1912 |
|
|
/* Subtract b from a */
|
1913 |
|
|
for (i = 0; i < a->length; i++)
|
1914 |
|
|
{
|
1915 |
|
|
tmp = a->rank[i] - b->rank[i];
|
1916 |
|
|
if (tmp > 0)
|
1917 |
|
|
found_pos = 1;
|
1918 |
|
|
else if (tmp < 0)
|
1919 |
|
|
found_neg = 1;
|
1920 |
|
|
}
|
1921 |
|
|
|
1922 |
|
|
if (found_pos)
|
1923 |
|
|
{
|
1924 |
|
|
if (found_neg)
|
1925 |
|
|
return 1; /* incomparable */
|
1926 |
|
|
else
|
1927 |
|
|
return 3; /* A > B */
|
1928 |
|
|
}
|
1929 |
|
|
else
|
1930 |
|
|
/* no positives */
|
1931 |
|
|
{
|
1932 |
|
|
if (found_neg)
|
1933 |
|
|
return 2; /* A < B */
|
1934 |
|
|
else
|
1935 |
|
|
return 0; /* A == B */
|
1936 |
|
|
}
|
1937 |
|
|
}
|
1938 |
|
|
|
1939 |
|
|
/* Rank a function by comparing its parameter types (PARMS, length
|
1940 |
|
|
NPARMS), to the types of an argument list (ARGS, length NARGS).
|
1941 |
|
|
Return a pointer to a badness vector. This has NARGS + 1
|
1942 |
|
|
entries. */
|
1943 |
|
|
|
1944 |
|
|
struct badness_vector *
|
1945 |
|
|
rank_function (struct type **parms, int nparms,
|
1946 |
|
|
struct type **args, int nargs)
|
1947 |
|
|
{
|
1948 |
|
|
int i;
|
1949 |
|
|
struct badness_vector *bv;
|
1950 |
|
|
int min_len = nparms < nargs ? nparms : nargs;
|
1951 |
|
|
|
1952 |
|
|
bv = xmalloc (sizeof (struct badness_vector));
|
1953 |
|
|
bv->length = nargs + 1; /* add 1 for the length-match rank */
|
1954 |
|
|
bv->rank = xmalloc ((nargs + 1) * sizeof (int));
|
1955 |
|
|
|
1956 |
|
|
/* First compare the lengths of the supplied lists.
|
1957 |
|
|
If there is a mismatch, set it to a high value. */
|
1958 |
|
|
|
1959 |
|
|
/* pai/1997-06-03 FIXME: when we have debug info about default
|
1960 |
|
|
arguments and ellipsis parameter lists, we should consider those
|
1961 |
|
|
and rank the length-match more finely. */
|
1962 |
|
|
|
1963 |
|
|
LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
|
1964 |
|
|
|
1965 |
|
|
/* Now rank all the parameters of the candidate function */
|
1966 |
|
|
for (i = 1; i <= min_len; i++)
|
1967 |
|
|
bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
|
1968 |
|
|
|
1969 |
|
|
/* If more arguments than parameters, add dummy entries */
|
1970 |
|
|
for (i = min_len + 1; i <= nargs; i++)
|
1971 |
|
|
bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
|
1972 |
|
|
|
1973 |
|
|
return bv;
|
1974 |
|
|
}
|
1975 |
|
|
|
1976 |
|
|
/* Compare the names of two integer types, assuming that any sign
|
1977 |
|
|
qualifiers have been checked already. We do it this way because
|
1978 |
|
|
there may be an "int" in the name of one of the types. */
|
1979 |
|
|
|
1980 |
|
|
static int
|
1981 |
|
|
integer_types_same_name_p (const char *first, const char *second)
|
1982 |
|
|
{
|
1983 |
|
|
int first_p, second_p;
|
1984 |
|
|
|
1985 |
|
|
/* If both are shorts, return 1; if neither is a short, keep
|
1986 |
|
|
checking. */
|
1987 |
|
|
first_p = (strstr (first, "short") != NULL);
|
1988 |
|
|
second_p = (strstr (second, "short") != NULL);
|
1989 |
|
|
if (first_p && second_p)
|
1990 |
|
|
return 1;
|
1991 |
|
|
if (first_p || second_p)
|
1992 |
|
|
return 0;
|
1993 |
|
|
|
1994 |
|
|
/* Likewise for long. */
|
1995 |
|
|
first_p = (strstr (first, "long") != NULL);
|
1996 |
|
|
second_p = (strstr (second, "long") != NULL);
|
1997 |
|
|
if (first_p && second_p)
|
1998 |
|
|
return 1;
|
1999 |
|
|
if (first_p || second_p)
|
2000 |
|
|
return 0;
|
2001 |
|
|
|
2002 |
|
|
/* Likewise for char. */
|
2003 |
|
|
first_p = (strstr (first, "char") != NULL);
|
2004 |
|
|
second_p = (strstr (second, "char") != NULL);
|
2005 |
|
|
if (first_p && second_p)
|
2006 |
|
|
return 1;
|
2007 |
|
|
if (first_p || second_p)
|
2008 |
|
|
return 0;
|
2009 |
|
|
|
2010 |
|
|
/* They must both be ints. */
|
2011 |
|
|
return 1;
|
2012 |
|
|
}
|
2013 |
|
|
|
2014 |
|
|
/* Compare one type (PARM) for compatibility with another (ARG).
|
2015 |
|
|
* PARM is intended to be the parameter type of a function; and
|
2016 |
|
|
* ARG is the supplied argument's type. This function tests if
|
2017 |
|
|
* the latter can be converted to the former.
|
2018 |
|
|
*
|
2019 |
|
|
* Return 0 if they are identical types;
|
2020 |
|
|
* Otherwise, return an integer which corresponds to how compatible
|
2021 |
|
|
* PARM is to ARG. The higher the return value, the worse the match.
|
2022 |
|
|
* Generally the "bad" conversions are all uniformly assigned a 100. */
|
2023 |
|
|
|
2024 |
|
|
int
|
2025 |
|
|
rank_one_type (struct type *parm, struct type *arg)
|
2026 |
|
|
{
|
2027 |
|
|
/* Identical type pointers. */
|
2028 |
|
|
/* However, this still doesn't catch all cases of same type for arg
|
2029 |
|
|
and param. The reason is that builtin types are different from
|
2030 |
|
|
the same ones constructed from the object. */
|
2031 |
|
|
if (parm == arg)
|
2032 |
|
|
return 0;
|
2033 |
|
|
|
2034 |
|
|
/* Resolve typedefs */
|
2035 |
|
|
if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
|
2036 |
|
|
parm = check_typedef (parm);
|
2037 |
|
|
if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
|
2038 |
|
|
arg = check_typedef (arg);
|
2039 |
|
|
|
2040 |
|
|
/*
|
2041 |
|
|
Well, damnit, if the names are exactly the same, I'll say they
|
2042 |
|
|
are exactly the same. This happens when we generate method
|
2043 |
|
|
stubs. The types won't point to the same address, but they
|
2044 |
|
|
really are the same.
|
2045 |
|
|
*/
|
2046 |
|
|
|
2047 |
|
|
if (TYPE_NAME (parm) && TYPE_NAME (arg)
|
2048 |
|
|
&& !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
|
2049 |
|
|
return 0;
|
2050 |
|
|
|
2051 |
|
|
/* Check if identical after resolving typedefs. */
|
2052 |
|
|
if (parm == arg)
|
2053 |
|
|
return 0;
|
2054 |
|
|
|
2055 |
|
|
/* See through references, since we can almost make non-references
|
2056 |
|
|
references. */
|
2057 |
|
|
if (TYPE_CODE (arg) == TYPE_CODE_REF)
|
2058 |
|
|
return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
|
2059 |
|
|
+ REFERENCE_CONVERSION_BADNESS);
|
2060 |
|
|
if (TYPE_CODE (parm) == TYPE_CODE_REF)
|
2061 |
|
|
return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
|
2062 |
|
|
+ REFERENCE_CONVERSION_BADNESS);
|
2063 |
|
|
if (overload_debug)
|
2064 |
|
|
/* Debugging only. */
|
2065 |
|
|
fprintf_filtered (gdb_stderr,
|
2066 |
|
|
"------ Arg is %s [%d], parm is %s [%d]\n",
|
2067 |
|
|
TYPE_NAME (arg), TYPE_CODE (arg),
|
2068 |
|
|
TYPE_NAME (parm), TYPE_CODE (parm));
|
2069 |
|
|
|
2070 |
|
|
/* x -> y means arg of type x being supplied for parameter of type y */
|
2071 |
|
|
|
2072 |
|
|
switch (TYPE_CODE (parm))
|
2073 |
|
|
{
|
2074 |
|
|
case TYPE_CODE_PTR:
|
2075 |
|
|
switch (TYPE_CODE (arg))
|
2076 |
|
|
{
|
2077 |
|
|
case TYPE_CODE_PTR:
|
2078 |
|
|
if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
|
2079 |
|
|
return VOID_PTR_CONVERSION_BADNESS;
|
2080 |
|
|
else
|
2081 |
|
|
return rank_one_type (TYPE_TARGET_TYPE (parm),
|
2082 |
|
|
TYPE_TARGET_TYPE (arg));
|
2083 |
|
|
case TYPE_CODE_ARRAY:
|
2084 |
|
|
return rank_one_type (TYPE_TARGET_TYPE (parm),
|
2085 |
|
|
TYPE_TARGET_TYPE (arg));
|
2086 |
|
|
case TYPE_CODE_FUNC:
|
2087 |
|
|
return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
|
2088 |
|
|
case TYPE_CODE_INT:
|
2089 |
|
|
case TYPE_CODE_ENUM:
|
2090 |
|
|
case TYPE_CODE_FLAGS:
|
2091 |
|
|
case TYPE_CODE_CHAR:
|
2092 |
|
|
case TYPE_CODE_RANGE:
|
2093 |
|
|
case TYPE_CODE_BOOL:
|
2094 |
|
|
return POINTER_CONVERSION_BADNESS;
|
2095 |
|
|
default:
|
2096 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2097 |
|
|
}
|
2098 |
|
|
case TYPE_CODE_ARRAY:
|
2099 |
|
|
switch (TYPE_CODE (arg))
|
2100 |
|
|
{
|
2101 |
|
|
case TYPE_CODE_PTR:
|
2102 |
|
|
case TYPE_CODE_ARRAY:
|
2103 |
|
|
return rank_one_type (TYPE_TARGET_TYPE (parm),
|
2104 |
|
|
TYPE_TARGET_TYPE (arg));
|
2105 |
|
|
default:
|
2106 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2107 |
|
|
}
|
2108 |
|
|
case TYPE_CODE_FUNC:
|
2109 |
|
|
switch (TYPE_CODE (arg))
|
2110 |
|
|
{
|
2111 |
|
|
case TYPE_CODE_PTR: /* funcptr -> func */
|
2112 |
|
|
return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
|
2113 |
|
|
default:
|
2114 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2115 |
|
|
}
|
2116 |
|
|
case TYPE_CODE_INT:
|
2117 |
|
|
switch (TYPE_CODE (arg))
|
2118 |
|
|
{
|
2119 |
|
|
case TYPE_CODE_INT:
|
2120 |
|
|
if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
|
2121 |
|
|
{
|
2122 |
|
|
/* Deal with signed, unsigned, and plain chars and
|
2123 |
|
|
signed and unsigned ints. */
|
2124 |
|
|
if (TYPE_NOSIGN (parm))
|
2125 |
|
|
{
|
2126 |
|
|
/* This case only for character types */
|
2127 |
|
|
if (TYPE_NOSIGN (arg))
|
2128 |
|
|
return 0; /* plain char -> plain char */
|
2129 |
|
|
else /* signed/unsigned char -> plain char */
|
2130 |
|
|
return INTEGER_CONVERSION_BADNESS;
|
2131 |
|
|
}
|
2132 |
|
|
else if (TYPE_UNSIGNED (parm))
|
2133 |
|
|
{
|
2134 |
|
|
if (TYPE_UNSIGNED (arg))
|
2135 |
|
|
{
|
2136 |
|
|
/* unsigned int -> unsigned int, or
|
2137 |
|
|
unsigned long -> unsigned long */
|
2138 |
|
|
if (integer_types_same_name_p (TYPE_NAME (parm),
|
2139 |
|
|
TYPE_NAME (arg)))
|
2140 |
|
|
return 0;
|
2141 |
|
|
else if (integer_types_same_name_p (TYPE_NAME (arg),
|
2142 |
|
|
"int")
|
2143 |
|
|
&& integer_types_same_name_p (TYPE_NAME (parm),
|
2144 |
|
|
"long"))
|
2145 |
|
|
return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
|
2146 |
|
|
else
|
2147 |
|
|
return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */
|
2148 |
|
|
}
|
2149 |
|
|
else
|
2150 |
|
|
{
|
2151 |
|
|
if (integer_types_same_name_p (TYPE_NAME (arg),
|
2152 |
|
|
"long")
|
2153 |
|
|
&& integer_types_same_name_p (TYPE_NAME (parm),
|
2154 |
|
|
"int"))
|
2155 |
|
|
return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */
|
2156 |
|
|
else
|
2157 |
|
|
return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
|
2158 |
|
|
}
|
2159 |
|
|
}
|
2160 |
|
|
else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
|
2161 |
|
|
{
|
2162 |
|
|
if (integer_types_same_name_p (TYPE_NAME (parm),
|
2163 |
|
|
TYPE_NAME (arg)))
|
2164 |
|
|
return 0;
|
2165 |
|
|
else if (integer_types_same_name_p (TYPE_NAME (arg),
|
2166 |
|
|
"int")
|
2167 |
|
|
&& integer_types_same_name_p (TYPE_NAME (parm),
|
2168 |
|
|
"long"))
|
2169 |
|
|
return INTEGER_PROMOTION_BADNESS;
|
2170 |
|
|
else
|
2171 |
|
|
return INTEGER_CONVERSION_BADNESS;
|
2172 |
|
|
}
|
2173 |
|
|
else
|
2174 |
|
|
return INTEGER_CONVERSION_BADNESS;
|
2175 |
|
|
}
|
2176 |
|
|
else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
|
2177 |
|
|
return INTEGER_PROMOTION_BADNESS;
|
2178 |
|
|
else
|
2179 |
|
|
return INTEGER_CONVERSION_BADNESS;
|
2180 |
|
|
case TYPE_CODE_ENUM:
|
2181 |
|
|
case TYPE_CODE_FLAGS:
|
2182 |
|
|
case TYPE_CODE_CHAR:
|
2183 |
|
|
case TYPE_CODE_RANGE:
|
2184 |
|
|
case TYPE_CODE_BOOL:
|
2185 |
|
|
return INTEGER_PROMOTION_BADNESS;
|
2186 |
|
|
case TYPE_CODE_FLT:
|
2187 |
|
|
return INT_FLOAT_CONVERSION_BADNESS;
|
2188 |
|
|
case TYPE_CODE_PTR:
|
2189 |
|
|
return NS_POINTER_CONVERSION_BADNESS;
|
2190 |
|
|
default:
|
2191 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2192 |
|
|
}
|
2193 |
|
|
break;
|
2194 |
|
|
case TYPE_CODE_ENUM:
|
2195 |
|
|
switch (TYPE_CODE (arg))
|
2196 |
|
|
{
|
2197 |
|
|
case TYPE_CODE_INT:
|
2198 |
|
|
case TYPE_CODE_CHAR:
|
2199 |
|
|
case TYPE_CODE_RANGE:
|
2200 |
|
|
case TYPE_CODE_BOOL:
|
2201 |
|
|
case TYPE_CODE_ENUM:
|
2202 |
|
|
return INTEGER_CONVERSION_BADNESS;
|
2203 |
|
|
case TYPE_CODE_FLT:
|
2204 |
|
|
return INT_FLOAT_CONVERSION_BADNESS;
|
2205 |
|
|
default:
|
2206 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2207 |
|
|
}
|
2208 |
|
|
break;
|
2209 |
|
|
case TYPE_CODE_CHAR:
|
2210 |
|
|
switch (TYPE_CODE (arg))
|
2211 |
|
|
{
|
2212 |
|
|
case TYPE_CODE_RANGE:
|
2213 |
|
|
case TYPE_CODE_BOOL:
|
2214 |
|
|
case TYPE_CODE_ENUM:
|
2215 |
|
|
return INTEGER_CONVERSION_BADNESS;
|
2216 |
|
|
case TYPE_CODE_FLT:
|
2217 |
|
|
return INT_FLOAT_CONVERSION_BADNESS;
|
2218 |
|
|
case TYPE_CODE_INT:
|
2219 |
|
|
if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
|
2220 |
|
|
return INTEGER_CONVERSION_BADNESS;
|
2221 |
|
|
else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
|
2222 |
|
|
return INTEGER_PROMOTION_BADNESS;
|
2223 |
|
|
/* >>> !! else fall through !! <<< */
|
2224 |
|
|
case TYPE_CODE_CHAR:
|
2225 |
|
|
/* Deal with signed, unsigned, and plain chars for C++ and
|
2226 |
|
|
with int cases falling through from previous case. */
|
2227 |
|
|
if (TYPE_NOSIGN (parm))
|
2228 |
|
|
{
|
2229 |
|
|
if (TYPE_NOSIGN (arg))
|
2230 |
|
|
return 0;
|
2231 |
|
|
else
|
2232 |
|
|
return INTEGER_CONVERSION_BADNESS;
|
2233 |
|
|
}
|
2234 |
|
|
else if (TYPE_UNSIGNED (parm))
|
2235 |
|
|
{
|
2236 |
|
|
if (TYPE_UNSIGNED (arg))
|
2237 |
|
|
return 0;
|
2238 |
|
|
else
|
2239 |
|
|
return INTEGER_PROMOTION_BADNESS;
|
2240 |
|
|
}
|
2241 |
|
|
else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
|
2242 |
|
|
return 0;
|
2243 |
|
|
else
|
2244 |
|
|
return INTEGER_CONVERSION_BADNESS;
|
2245 |
|
|
default:
|
2246 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2247 |
|
|
}
|
2248 |
|
|
break;
|
2249 |
|
|
case TYPE_CODE_RANGE:
|
2250 |
|
|
switch (TYPE_CODE (arg))
|
2251 |
|
|
{
|
2252 |
|
|
case TYPE_CODE_INT:
|
2253 |
|
|
case TYPE_CODE_CHAR:
|
2254 |
|
|
case TYPE_CODE_RANGE:
|
2255 |
|
|
case TYPE_CODE_BOOL:
|
2256 |
|
|
case TYPE_CODE_ENUM:
|
2257 |
|
|
return INTEGER_CONVERSION_BADNESS;
|
2258 |
|
|
case TYPE_CODE_FLT:
|
2259 |
|
|
return INT_FLOAT_CONVERSION_BADNESS;
|
2260 |
|
|
default:
|
2261 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2262 |
|
|
}
|
2263 |
|
|
break;
|
2264 |
|
|
case TYPE_CODE_BOOL:
|
2265 |
|
|
switch (TYPE_CODE (arg))
|
2266 |
|
|
{
|
2267 |
|
|
case TYPE_CODE_INT:
|
2268 |
|
|
case TYPE_CODE_CHAR:
|
2269 |
|
|
case TYPE_CODE_RANGE:
|
2270 |
|
|
case TYPE_CODE_ENUM:
|
2271 |
|
|
case TYPE_CODE_FLT:
|
2272 |
|
|
case TYPE_CODE_PTR:
|
2273 |
|
|
return BOOLEAN_CONVERSION_BADNESS;
|
2274 |
|
|
case TYPE_CODE_BOOL:
|
2275 |
|
|
return 0;
|
2276 |
|
|
default:
|
2277 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2278 |
|
|
}
|
2279 |
|
|
break;
|
2280 |
|
|
case TYPE_CODE_FLT:
|
2281 |
|
|
switch (TYPE_CODE (arg))
|
2282 |
|
|
{
|
2283 |
|
|
case TYPE_CODE_FLT:
|
2284 |
|
|
if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
|
2285 |
|
|
return FLOAT_PROMOTION_BADNESS;
|
2286 |
|
|
else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
|
2287 |
|
|
return 0;
|
2288 |
|
|
else
|
2289 |
|
|
return FLOAT_CONVERSION_BADNESS;
|
2290 |
|
|
case TYPE_CODE_INT:
|
2291 |
|
|
case TYPE_CODE_BOOL:
|
2292 |
|
|
case TYPE_CODE_ENUM:
|
2293 |
|
|
case TYPE_CODE_RANGE:
|
2294 |
|
|
case TYPE_CODE_CHAR:
|
2295 |
|
|
return INT_FLOAT_CONVERSION_BADNESS;
|
2296 |
|
|
default:
|
2297 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2298 |
|
|
}
|
2299 |
|
|
break;
|
2300 |
|
|
case TYPE_CODE_COMPLEX:
|
2301 |
|
|
switch (TYPE_CODE (arg))
|
2302 |
|
|
{ /* Strictly not needed for C++, but... */
|
2303 |
|
|
case TYPE_CODE_FLT:
|
2304 |
|
|
return FLOAT_PROMOTION_BADNESS;
|
2305 |
|
|
case TYPE_CODE_COMPLEX:
|
2306 |
|
|
return 0;
|
2307 |
|
|
default:
|
2308 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2309 |
|
|
}
|
2310 |
|
|
break;
|
2311 |
|
|
case TYPE_CODE_STRUCT:
|
2312 |
|
|
/* currently same as TYPE_CODE_CLASS */
|
2313 |
|
|
switch (TYPE_CODE (arg))
|
2314 |
|
|
{
|
2315 |
|
|
case TYPE_CODE_STRUCT:
|
2316 |
|
|
/* Check for derivation */
|
2317 |
|
|
if (is_ancestor (parm, arg))
|
2318 |
|
|
return BASE_CONVERSION_BADNESS;
|
2319 |
|
|
/* else fall through */
|
2320 |
|
|
default:
|
2321 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2322 |
|
|
}
|
2323 |
|
|
break;
|
2324 |
|
|
case TYPE_CODE_UNION:
|
2325 |
|
|
switch (TYPE_CODE (arg))
|
2326 |
|
|
{
|
2327 |
|
|
case TYPE_CODE_UNION:
|
2328 |
|
|
default:
|
2329 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2330 |
|
|
}
|
2331 |
|
|
break;
|
2332 |
|
|
case TYPE_CODE_MEMBERPTR:
|
2333 |
|
|
switch (TYPE_CODE (arg))
|
2334 |
|
|
{
|
2335 |
|
|
default:
|
2336 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2337 |
|
|
}
|
2338 |
|
|
break;
|
2339 |
|
|
case TYPE_CODE_METHOD:
|
2340 |
|
|
switch (TYPE_CODE (arg))
|
2341 |
|
|
{
|
2342 |
|
|
|
2343 |
|
|
default:
|
2344 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2345 |
|
|
}
|
2346 |
|
|
break;
|
2347 |
|
|
case TYPE_CODE_REF:
|
2348 |
|
|
switch (TYPE_CODE (arg))
|
2349 |
|
|
{
|
2350 |
|
|
|
2351 |
|
|
default:
|
2352 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2353 |
|
|
}
|
2354 |
|
|
|
2355 |
|
|
break;
|
2356 |
|
|
case TYPE_CODE_SET:
|
2357 |
|
|
switch (TYPE_CODE (arg))
|
2358 |
|
|
{
|
2359 |
|
|
/* Not in C++ */
|
2360 |
|
|
case TYPE_CODE_SET:
|
2361 |
|
|
return rank_one_type (TYPE_FIELD_TYPE (parm, 0),
|
2362 |
|
|
TYPE_FIELD_TYPE (arg, 0));
|
2363 |
|
|
default:
|
2364 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2365 |
|
|
}
|
2366 |
|
|
break;
|
2367 |
|
|
case TYPE_CODE_VOID:
|
2368 |
|
|
default:
|
2369 |
|
|
return INCOMPATIBLE_TYPE_BADNESS;
|
2370 |
|
|
} /* switch (TYPE_CODE (arg)) */
|
2371 |
|
|
}
|
2372 |
|
|
|
2373 |
|
|
|
2374 |
|
|
/* End of functions for overload resolution */
|
2375 |
|
|
|
2376 |
|
|
static void
|
2377 |
|
|
print_bit_vector (B_TYPE *bits, int nbits)
|
2378 |
|
|
{
|
2379 |
|
|
int bitno;
|
2380 |
|
|
|
2381 |
|
|
for (bitno = 0; bitno < nbits; bitno++)
|
2382 |
|
|
{
|
2383 |
|
|
if ((bitno % 8) == 0)
|
2384 |
|
|
{
|
2385 |
|
|
puts_filtered (" ");
|
2386 |
|
|
}
|
2387 |
|
|
if (B_TST (bits, bitno))
|
2388 |
|
|
printf_filtered (("1"));
|
2389 |
|
|
else
|
2390 |
|
|
printf_filtered (("0"));
|
2391 |
|
|
}
|
2392 |
|
|
}
|
2393 |
|
|
|
2394 |
|
|
/* Note the first arg should be the "this" pointer, we may not want to
|
2395 |
|
|
include it since we may get into a infinitely recursive
|
2396 |
|
|
situation. */
|
2397 |
|
|
|
2398 |
|
|
static void
|
2399 |
|
|
print_arg_types (struct field *args, int nargs, int spaces)
|
2400 |
|
|
{
|
2401 |
|
|
if (args != NULL)
|
2402 |
|
|
{
|
2403 |
|
|
int i;
|
2404 |
|
|
|
2405 |
|
|
for (i = 0; i < nargs; i++)
|
2406 |
|
|
recursive_dump_type (args[i].type, spaces + 2);
|
2407 |
|
|
}
|
2408 |
|
|
}
|
2409 |
|
|
|
2410 |
|
|
static void
|
2411 |
|
|
dump_fn_fieldlists (struct type *type, int spaces)
|
2412 |
|
|
{
|
2413 |
|
|
int method_idx;
|
2414 |
|
|
int overload_idx;
|
2415 |
|
|
struct fn_field *f;
|
2416 |
|
|
|
2417 |
|
|
printfi_filtered (spaces, "fn_fieldlists ");
|
2418 |
|
|
gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
|
2419 |
|
|
printf_filtered ("\n");
|
2420 |
|
|
for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
|
2421 |
|
|
{
|
2422 |
|
|
f = TYPE_FN_FIELDLIST1 (type, method_idx);
|
2423 |
|
|
printfi_filtered (spaces + 2, "[%d] name '%s' (",
|
2424 |
|
|
method_idx,
|
2425 |
|
|
TYPE_FN_FIELDLIST_NAME (type, method_idx));
|
2426 |
|
|
gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
|
2427 |
|
|
gdb_stdout);
|
2428 |
|
|
printf_filtered (_(") length %d\n"),
|
2429 |
|
|
TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
|
2430 |
|
|
for (overload_idx = 0;
|
2431 |
|
|
overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
|
2432 |
|
|
overload_idx++)
|
2433 |
|
|
{
|
2434 |
|
|
printfi_filtered (spaces + 4, "[%d] physname '%s' (",
|
2435 |
|
|
overload_idx,
|
2436 |
|
|
TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
|
2437 |
|
|
gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
|
2438 |
|
|
gdb_stdout);
|
2439 |
|
|
printf_filtered (")\n");
|
2440 |
|
|
printfi_filtered (spaces + 8, "type ");
|
2441 |
|
|
gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx),
|
2442 |
|
|
gdb_stdout);
|
2443 |
|
|
printf_filtered ("\n");
|
2444 |
|
|
|
2445 |
|
|
recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
|
2446 |
|
|
spaces + 8 + 2);
|
2447 |
|
|
|
2448 |
|
|
printfi_filtered (spaces + 8, "args ");
|
2449 |
|
|
gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx),
|
2450 |
|
|
gdb_stdout);
|
2451 |
|
|
printf_filtered ("\n");
|
2452 |
|
|
|
2453 |
|
|
print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx),
|
2454 |
|
|
TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f,
|
2455 |
|
|
overload_idx)),
|
2456 |
|
|
spaces);
|
2457 |
|
|
printfi_filtered (spaces + 8, "fcontext ");
|
2458 |
|
|
gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
|
2459 |
|
|
gdb_stdout);
|
2460 |
|
|
printf_filtered ("\n");
|
2461 |
|
|
|
2462 |
|
|
printfi_filtered (spaces + 8, "is_const %d\n",
|
2463 |
|
|
TYPE_FN_FIELD_CONST (f, overload_idx));
|
2464 |
|
|
printfi_filtered (spaces + 8, "is_volatile %d\n",
|
2465 |
|
|
TYPE_FN_FIELD_VOLATILE (f, overload_idx));
|
2466 |
|
|
printfi_filtered (spaces + 8, "is_private %d\n",
|
2467 |
|
|
TYPE_FN_FIELD_PRIVATE (f, overload_idx));
|
2468 |
|
|
printfi_filtered (spaces + 8, "is_protected %d\n",
|
2469 |
|
|
TYPE_FN_FIELD_PROTECTED (f, overload_idx));
|
2470 |
|
|
printfi_filtered (spaces + 8, "is_stub %d\n",
|
2471 |
|
|
TYPE_FN_FIELD_STUB (f, overload_idx));
|
2472 |
|
|
printfi_filtered (spaces + 8, "voffset %u\n",
|
2473 |
|
|
TYPE_FN_FIELD_VOFFSET (f, overload_idx));
|
2474 |
|
|
}
|
2475 |
|
|
}
|
2476 |
|
|
}
|
2477 |
|
|
|
2478 |
|
|
static void
|
2479 |
|
|
print_cplus_stuff (struct type *type, int spaces)
|
2480 |
|
|
{
|
2481 |
|
|
printfi_filtered (spaces, "n_baseclasses %d\n",
|
2482 |
|
|
TYPE_N_BASECLASSES (type));
|
2483 |
|
|
printfi_filtered (spaces, "nfn_fields %d\n",
|
2484 |
|
|
TYPE_NFN_FIELDS (type));
|
2485 |
|
|
printfi_filtered (spaces, "nfn_fields_total %d\n",
|
2486 |
|
|
TYPE_NFN_FIELDS_TOTAL (type));
|
2487 |
|
|
if (TYPE_N_BASECLASSES (type) > 0)
|
2488 |
|
|
{
|
2489 |
|
|
printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
|
2490 |
|
|
TYPE_N_BASECLASSES (type));
|
2491 |
|
|
gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type),
|
2492 |
|
|
gdb_stdout);
|
2493 |
|
|
printf_filtered (")");
|
2494 |
|
|
|
2495 |
|
|
print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
|
2496 |
|
|
TYPE_N_BASECLASSES (type));
|
2497 |
|
|
puts_filtered ("\n");
|
2498 |
|
|
}
|
2499 |
|
|
if (TYPE_NFIELDS (type) > 0)
|
2500 |
|
|
{
|
2501 |
|
|
if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
|
2502 |
|
|
{
|
2503 |
|
|
printfi_filtered (spaces,
|
2504 |
|
|
"private_field_bits (%d bits at *",
|
2505 |
|
|
TYPE_NFIELDS (type));
|
2506 |
|
|
gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type),
|
2507 |
|
|
gdb_stdout);
|
2508 |
|
|
printf_filtered (")");
|
2509 |
|
|
print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
|
2510 |
|
|
TYPE_NFIELDS (type));
|
2511 |
|
|
puts_filtered ("\n");
|
2512 |
|
|
}
|
2513 |
|
|
if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
|
2514 |
|
|
{
|
2515 |
|
|
printfi_filtered (spaces,
|
2516 |
|
|
"protected_field_bits (%d bits at *",
|
2517 |
|
|
TYPE_NFIELDS (type));
|
2518 |
|
|
gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type),
|
2519 |
|
|
gdb_stdout);
|
2520 |
|
|
printf_filtered (")");
|
2521 |
|
|
print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
|
2522 |
|
|
TYPE_NFIELDS (type));
|
2523 |
|
|
puts_filtered ("\n");
|
2524 |
|
|
}
|
2525 |
|
|
}
|
2526 |
|
|
if (TYPE_NFN_FIELDS (type) > 0)
|
2527 |
|
|
{
|
2528 |
|
|
dump_fn_fieldlists (type, spaces);
|
2529 |
|
|
}
|
2530 |
|
|
}
|
2531 |
|
|
|
2532 |
|
|
static void
|
2533 |
|
|
print_bound_type (int bt)
|
2534 |
|
|
{
|
2535 |
|
|
switch (bt)
|
2536 |
|
|
{
|
2537 |
|
|
case BOUND_CANNOT_BE_DETERMINED:
|
2538 |
|
|
printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
|
2539 |
|
|
break;
|
2540 |
|
|
case BOUND_BY_REF_ON_STACK:
|
2541 |
|
|
printf_filtered ("(BOUND_BY_REF_ON_STACK)");
|
2542 |
|
|
break;
|
2543 |
|
|
case BOUND_BY_VALUE_ON_STACK:
|
2544 |
|
|
printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
|
2545 |
|
|
break;
|
2546 |
|
|
case BOUND_BY_REF_IN_REG:
|
2547 |
|
|
printf_filtered ("(BOUND_BY_REF_IN_REG)");
|
2548 |
|
|
break;
|
2549 |
|
|
case BOUND_BY_VALUE_IN_REG:
|
2550 |
|
|
printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
|
2551 |
|
|
break;
|
2552 |
|
|
case BOUND_SIMPLE:
|
2553 |
|
|
printf_filtered ("(BOUND_SIMPLE)");
|
2554 |
|
|
break;
|
2555 |
|
|
default:
|
2556 |
|
|
printf_filtered (_("(unknown bound type)"));
|
2557 |
|
|
break;
|
2558 |
|
|
}
|
2559 |
|
|
}
|
2560 |
|
|
|
2561 |
|
|
static struct obstack dont_print_type_obstack;
|
2562 |
|
|
|
2563 |
|
|
void
|
2564 |
|
|
recursive_dump_type (struct type *type, int spaces)
|
2565 |
|
|
{
|
2566 |
|
|
int idx;
|
2567 |
|
|
|
2568 |
|
|
if (spaces == 0)
|
2569 |
|
|
obstack_begin (&dont_print_type_obstack, 0);
|
2570 |
|
|
|
2571 |
|
|
if (TYPE_NFIELDS (type) > 0
|
2572 |
|
|
|| (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
|
2573 |
|
|
{
|
2574 |
|
|
struct type **first_dont_print
|
2575 |
|
|
= (struct type **) obstack_base (&dont_print_type_obstack);
|
2576 |
|
|
|
2577 |
|
|
int i = (struct type **)
|
2578 |
|
|
obstack_next_free (&dont_print_type_obstack) - first_dont_print;
|
2579 |
|
|
|
2580 |
|
|
while (--i >= 0)
|
2581 |
|
|
{
|
2582 |
|
|
if (type == first_dont_print[i])
|
2583 |
|
|
{
|
2584 |
|
|
printfi_filtered (spaces, "type node ");
|
2585 |
|
|
gdb_print_host_address (type, gdb_stdout);
|
2586 |
|
|
printf_filtered (_(" <same as already seen type>\n"));
|
2587 |
|
|
return;
|
2588 |
|
|
}
|
2589 |
|
|
}
|
2590 |
|
|
|
2591 |
|
|
obstack_ptr_grow (&dont_print_type_obstack, type);
|
2592 |
|
|
}
|
2593 |
|
|
|
2594 |
|
|
printfi_filtered (spaces, "type node ");
|
2595 |
|
|
gdb_print_host_address (type, gdb_stdout);
|
2596 |
|
|
printf_filtered ("\n");
|
2597 |
|
|
printfi_filtered (spaces, "name '%s' (",
|
2598 |
|
|
TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
|
2599 |
|
|
gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
|
2600 |
|
|
printf_filtered (")\n");
|
2601 |
|
|
printfi_filtered (spaces, "tagname '%s' (",
|
2602 |
|
|
TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
|
2603 |
|
|
gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
|
2604 |
|
|
printf_filtered (")\n");
|
2605 |
|
|
printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
|
2606 |
|
|
switch (TYPE_CODE (type))
|
2607 |
|
|
{
|
2608 |
|
|
case TYPE_CODE_UNDEF:
|
2609 |
|
|
printf_filtered ("(TYPE_CODE_UNDEF)");
|
2610 |
|
|
break;
|
2611 |
|
|
case TYPE_CODE_PTR:
|
2612 |
|
|
printf_filtered ("(TYPE_CODE_PTR)");
|
2613 |
|
|
break;
|
2614 |
|
|
case TYPE_CODE_ARRAY:
|
2615 |
|
|
printf_filtered ("(TYPE_CODE_ARRAY)");
|
2616 |
|
|
break;
|
2617 |
|
|
case TYPE_CODE_STRUCT:
|
2618 |
|
|
printf_filtered ("(TYPE_CODE_STRUCT)");
|
2619 |
|
|
break;
|
2620 |
|
|
case TYPE_CODE_UNION:
|
2621 |
|
|
printf_filtered ("(TYPE_CODE_UNION)");
|
2622 |
|
|
break;
|
2623 |
|
|
case TYPE_CODE_ENUM:
|
2624 |
|
|
printf_filtered ("(TYPE_CODE_ENUM)");
|
2625 |
|
|
break;
|
2626 |
|
|
case TYPE_CODE_FLAGS:
|
2627 |
|
|
printf_filtered ("(TYPE_CODE_FLAGS)");
|
2628 |
|
|
break;
|
2629 |
|
|
case TYPE_CODE_FUNC:
|
2630 |
|
|
printf_filtered ("(TYPE_CODE_FUNC)");
|
2631 |
|
|
break;
|
2632 |
|
|
case TYPE_CODE_INT:
|
2633 |
|
|
printf_filtered ("(TYPE_CODE_INT)");
|
2634 |
|
|
break;
|
2635 |
|
|
case TYPE_CODE_FLT:
|
2636 |
|
|
printf_filtered ("(TYPE_CODE_FLT)");
|
2637 |
|
|
break;
|
2638 |
|
|
case TYPE_CODE_VOID:
|
2639 |
|
|
printf_filtered ("(TYPE_CODE_VOID)");
|
2640 |
|
|
break;
|
2641 |
|
|
case TYPE_CODE_SET:
|
2642 |
|
|
printf_filtered ("(TYPE_CODE_SET)");
|
2643 |
|
|
break;
|
2644 |
|
|
case TYPE_CODE_RANGE:
|
2645 |
|
|
printf_filtered ("(TYPE_CODE_RANGE)");
|
2646 |
|
|
break;
|
2647 |
|
|
case TYPE_CODE_STRING:
|
2648 |
|
|
printf_filtered ("(TYPE_CODE_STRING)");
|
2649 |
|
|
break;
|
2650 |
|
|
case TYPE_CODE_BITSTRING:
|
2651 |
|
|
printf_filtered ("(TYPE_CODE_BITSTRING)");
|
2652 |
|
|
break;
|
2653 |
|
|
case TYPE_CODE_ERROR:
|
2654 |
|
|
printf_filtered ("(TYPE_CODE_ERROR)");
|
2655 |
|
|
break;
|
2656 |
|
|
case TYPE_CODE_MEMBERPTR:
|
2657 |
|
|
printf_filtered ("(TYPE_CODE_MEMBERPTR)");
|
2658 |
|
|
break;
|
2659 |
|
|
case TYPE_CODE_METHODPTR:
|
2660 |
|
|
printf_filtered ("(TYPE_CODE_METHODPTR)");
|
2661 |
|
|
break;
|
2662 |
|
|
case TYPE_CODE_METHOD:
|
2663 |
|
|
printf_filtered ("(TYPE_CODE_METHOD)");
|
2664 |
|
|
break;
|
2665 |
|
|
case TYPE_CODE_REF:
|
2666 |
|
|
printf_filtered ("(TYPE_CODE_REF)");
|
2667 |
|
|
break;
|
2668 |
|
|
case TYPE_CODE_CHAR:
|
2669 |
|
|
printf_filtered ("(TYPE_CODE_CHAR)");
|
2670 |
|
|
break;
|
2671 |
|
|
case TYPE_CODE_BOOL:
|
2672 |
|
|
printf_filtered ("(TYPE_CODE_BOOL)");
|
2673 |
|
|
break;
|
2674 |
|
|
case TYPE_CODE_COMPLEX:
|
2675 |
|
|
printf_filtered ("(TYPE_CODE_COMPLEX)");
|
2676 |
|
|
break;
|
2677 |
|
|
case TYPE_CODE_TYPEDEF:
|
2678 |
|
|
printf_filtered ("(TYPE_CODE_TYPEDEF)");
|
2679 |
|
|
break;
|
2680 |
|
|
case TYPE_CODE_TEMPLATE:
|
2681 |
|
|
printf_filtered ("(TYPE_CODE_TEMPLATE)");
|
2682 |
|
|
break;
|
2683 |
|
|
case TYPE_CODE_TEMPLATE_ARG:
|
2684 |
|
|
printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
|
2685 |
|
|
break;
|
2686 |
|
|
case TYPE_CODE_NAMESPACE:
|
2687 |
|
|
printf_filtered ("(TYPE_CODE_NAMESPACE)");
|
2688 |
|
|
break;
|
2689 |
|
|
default:
|
2690 |
|
|
printf_filtered ("(UNKNOWN TYPE CODE)");
|
2691 |
|
|
break;
|
2692 |
|
|
}
|
2693 |
|
|
puts_filtered ("\n");
|
2694 |
|
|
printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
|
2695 |
|
|
printfi_filtered (spaces, "upper_bound_type 0x%x ",
|
2696 |
|
|
TYPE_ARRAY_UPPER_BOUND_TYPE (type));
|
2697 |
|
|
print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
|
2698 |
|
|
puts_filtered ("\n");
|
2699 |
|
|
printfi_filtered (spaces, "lower_bound_type 0x%x ",
|
2700 |
|
|
TYPE_ARRAY_LOWER_BOUND_TYPE (type));
|
2701 |
|
|
print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
|
2702 |
|
|
puts_filtered ("\n");
|
2703 |
|
|
printfi_filtered (spaces, "objfile ");
|
2704 |
|
|
gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
|
2705 |
|
|
printf_filtered ("\n");
|
2706 |
|
|
printfi_filtered (spaces, "target_type ");
|
2707 |
|
|
gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
|
2708 |
|
|
printf_filtered ("\n");
|
2709 |
|
|
if (TYPE_TARGET_TYPE (type) != NULL)
|
2710 |
|
|
{
|
2711 |
|
|
recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
|
2712 |
|
|
}
|
2713 |
|
|
printfi_filtered (spaces, "pointer_type ");
|
2714 |
|
|
gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
|
2715 |
|
|
printf_filtered ("\n");
|
2716 |
|
|
printfi_filtered (spaces, "reference_type ");
|
2717 |
|
|
gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
|
2718 |
|
|
printf_filtered ("\n");
|
2719 |
|
|
printfi_filtered (spaces, "type_chain ");
|
2720 |
|
|
gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout);
|
2721 |
|
|
printf_filtered ("\n");
|
2722 |
|
|
printfi_filtered (spaces, "instance_flags 0x%x",
|
2723 |
|
|
TYPE_INSTANCE_FLAGS (type));
|
2724 |
|
|
if (TYPE_CONST (type))
|
2725 |
|
|
{
|
2726 |
|
|
puts_filtered (" TYPE_FLAG_CONST");
|
2727 |
|
|
}
|
2728 |
|
|
if (TYPE_VOLATILE (type))
|
2729 |
|
|
{
|
2730 |
|
|
puts_filtered (" TYPE_FLAG_VOLATILE");
|
2731 |
|
|
}
|
2732 |
|
|
if (TYPE_CODE_SPACE (type))
|
2733 |
|
|
{
|
2734 |
|
|
puts_filtered (" TYPE_FLAG_CODE_SPACE");
|
2735 |
|
|
}
|
2736 |
|
|
if (TYPE_DATA_SPACE (type))
|
2737 |
|
|
{
|
2738 |
|
|
puts_filtered (" TYPE_FLAG_DATA_SPACE");
|
2739 |
|
|
}
|
2740 |
|
|
if (TYPE_ADDRESS_CLASS_1 (type))
|
2741 |
|
|
{
|
2742 |
|
|
puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1");
|
2743 |
|
|
}
|
2744 |
|
|
if (TYPE_ADDRESS_CLASS_2 (type))
|
2745 |
|
|
{
|
2746 |
|
|
puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2");
|
2747 |
|
|
}
|
2748 |
|
|
puts_filtered ("\n");
|
2749 |
|
|
printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
|
2750 |
|
|
if (TYPE_UNSIGNED (type))
|
2751 |
|
|
{
|
2752 |
|
|
puts_filtered (" TYPE_FLAG_UNSIGNED");
|
2753 |
|
|
}
|
2754 |
|
|
if (TYPE_NOSIGN (type))
|
2755 |
|
|
{
|
2756 |
|
|
puts_filtered (" TYPE_FLAG_NOSIGN");
|
2757 |
|
|
}
|
2758 |
|
|
if (TYPE_STUB (type))
|
2759 |
|
|
{
|
2760 |
|
|
puts_filtered (" TYPE_FLAG_STUB");
|
2761 |
|
|
}
|
2762 |
|
|
if (TYPE_TARGET_STUB (type))
|
2763 |
|
|
{
|
2764 |
|
|
puts_filtered (" TYPE_FLAG_TARGET_STUB");
|
2765 |
|
|
}
|
2766 |
|
|
if (TYPE_STATIC (type))
|
2767 |
|
|
{
|
2768 |
|
|
puts_filtered (" TYPE_FLAG_STATIC");
|
2769 |
|
|
}
|
2770 |
|
|
if (TYPE_PROTOTYPED (type))
|
2771 |
|
|
{
|
2772 |
|
|
puts_filtered (" TYPE_FLAG_PROTOTYPED");
|
2773 |
|
|
}
|
2774 |
|
|
if (TYPE_INCOMPLETE (type))
|
2775 |
|
|
{
|
2776 |
|
|
puts_filtered (" TYPE_FLAG_INCOMPLETE");
|
2777 |
|
|
}
|
2778 |
|
|
if (TYPE_VARARGS (type))
|
2779 |
|
|
{
|
2780 |
|
|
puts_filtered (" TYPE_FLAG_VARARGS");
|
2781 |
|
|
}
|
2782 |
|
|
/* This is used for things like AltiVec registers on ppc. Gcc emits
|
2783 |
|
|
an attribute for the array type, which tells whether or not we
|
2784 |
|
|
have a vector, instead of a regular array. */
|
2785 |
|
|
if (TYPE_VECTOR (type))
|
2786 |
|
|
{
|
2787 |
|
|
puts_filtered (" TYPE_FLAG_VECTOR");
|
2788 |
|
|
}
|
2789 |
|
|
puts_filtered ("\n");
|
2790 |
|
|
printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
|
2791 |
|
|
gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
|
2792 |
|
|
puts_filtered ("\n");
|
2793 |
|
|
for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
|
2794 |
|
|
{
|
2795 |
|
|
printfi_filtered (spaces + 2,
|
2796 |
|
|
"[%d] bitpos %d bitsize %d type ",
|
2797 |
|
|
idx, TYPE_FIELD_BITPOS (type, idx),
|
2798 |
|
|
TYPE_FIELD_BITSIZE (type, idx));
|
2799 |
|
|
gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
|
2800 |
|
|
printf_filtered (" name '%s' (",
|
2801 |
|
|
TYPE_FIELD_NAME (type, idx) != NULL
|
2802 |
|
|
? TYPE_FIELD_NAME (type, idx)
|
2803 |
|
|
: "<NULL>");
|
2804 |
|
|
gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
|
2805 |
|
|
printf_filtered (")\n");
|
2806 |
|
|
if (TYPE_FIELD_TYPE (type, idx) != NULL)
|
2807 |
|
|
{
|
2808 |
|
|
recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
|
2809 |
|
|
}
|
2810 |
|
|
}
|
2811 |
|
|
printfi_filtered (spaces, "vptr_basetype ");
|
2812 |
|
|
gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
|
2813 |
|
|
puts_filtered ("\n");
|
2814 |
|
|
if (TYPE_VPTR_BASETYPE (type) != NULL)
|
2815 |
|
|
{
|
2816 |
|
|
recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
|
2817 |
|
|
}
|
2818 |
|
|
printfi_filtered (spaces, "vptr_fieldno %d\n",
|
2819 |
|
|
TYPE_VPTR_FIELDNO (type));
|
2820 |
|
|
switch (TYPE_CODE (type))
|
2821 |
|
|
{
|
2822 |
|
|
case TYPE_CODE_STRUCT:
|
2823 |
|
|
printfi_filtered (spaces, "cplus_stuff ");
|
2824 |
|
|
gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type),
|
2825 |
|
|
gdb_stdout);
|
2826 |
|
|
puts_filtered ("\n");
|
2827 |
|
|
print_cplus_stuff (type, spaces);
|
2828 |
|
|
break;
|
2829 |
|
|
|
2830 |
|
|
case TYPE_CODE_FLT:
|
2831 |
|
|
printfi_filtered (spaces, "floatformat ");
|
2832 |
|
|
if (TYPE_FLOATFORMAT (type) == NULL)
|
2833 |
|
|
puts_filtered ("(null)");
|
2834 |
|
|
else
|
2835 |
|
|
{
|
2836 |
|
|
puts_filtered ("{ ");
|
2837 |
|
|
if (TYPE_FLOATFORMAT (type)[0] == NULL
|
2838 |
|
|
|| TYPE_FLOATFORMAT (type)[0]->name == NULL)
|
2839 |
|
|
puts_filtered ("(null)");
|
2840 |
|
|
else
|
2841 |
|
|
puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
|
2842 |
|
|
|
2843 |
|
|
puts_filtered (", ");
|
2844 |
|
|
if (TYPE_FLOATFORMAT (type)[1] == NULL
|
2845 |
|
|
|| TYPE_FLOATFORMAT (type)[1]->name == NULL)
|
2846 |
|
|
puts_filtered ("(null)");
|
2847 |
|
|
else
|
2848 |
|
|
puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
|
2849 |
|
|
|
2850 |
|
|
puts_filtered (" }");
|
2851 |
|
|
}
|
2852 |
|
|
puts_filtered ("\n");
|
2853 |
|
|
break;
|
2854 |
|
|
|
2855 |
|
|
default:
|
2856 |
|
|
/* We have to pick one of the union types to be able print and
|
2857 |
|
|
test the value. Pick cplus_struct_type, even though we know
|
2858 |
|
|
it isn't any particular one. */
|
2859 |
|
|
printfi_filtered (spaces, "type_specific ");
|
2860 |
|
|
gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
|
2861 |
|
|
if (TYPE_CPLUS_SPECIFIC (type) != NULL)
|
2862 |
|
|
{
|
2863 |
|
|
printf_filtered (_(" (unknown data form)"));
|
2864 |
|
|
}
|
2865 |
|
|
printf_filtered ("\n");
|
2866 |
|
|
break;
|
2867 |
|
|
|
2868 |
|
|
}
|
2869 |
|
|
if (spaces == 0)
|
2870 |
|
|
obstack_free (&dont_print_type_obstack, NULL);
|
2871 |
|
|
}
|
2872 |
|
|
|
2873 |
|
|
/* Trivial helpers for the libiberty hash table, for mapping one
|
2874 |
|
|
type to another. */
|
2875 |
|
|
|
2876 |
|
|
struct type_pair
|
2877 |
|
|
{
|
2878 |
|
|
struct type *old, *new;
|
2879 |
|
|
};
|
2880 |
|
|
|
2881 |
|
|
static hashval_t
|
2882 |
|
|
type_pair_hash (const void *item)
|
2883 |
|
|
{
|
2884 |
|
|
const struct type_pair *pair = item;
|
2885 |
|
|
return htab_hash_pointer (pair->old);
|
2886 |
|
|
}
|
2887 |
|
|
|
2888 |
|
|
static int
|
2889 |
|
|
type_pair_eq (const void *item_lhs, const void *item_rhs)
|
2890 |
|
|
{
|
2891 |
|
|
const struct type_pair *lhs = item_lhs, *rhs = item_rhs;
|
2892 |
|
|
return lhs->old == rhs->old;
|
2893 |
|
|
}
|
2894 |
|
|
|
2895 |
|
|
/* Allocate the hash table used by copy_type_recursive to walk
|
2896 |
|
|
types without duplicates. We use OBJFILE's obstack, because
|
2897 |
|
|
OBJFILE is about to be deleted. */
|
2898 |
|
|
|
2899 |
|
|
htab_t
|
2900 |
|
|
create_copied_types_hash (struct objfile *objfile)
|
2901 |
|
|
{
|
2902 |
|
|
return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq,
|
2903 |
|
|
NULL, &objfile->objfile_obstack,
|
2904 |
|
|
hashtab_obstack_allocate,
|
2905 |
|
|
dummy_obstack_deallocate);
|
2906 |
|
|
}
|
2907 |
|
|
|
2908 |
|
|
/* Recursively copy (deep copy) TYPE, if it is associated with
|
2909 |
|
|
OBJFILE. Return a new type allocated using malloc, a saved type if
|
2910 |
|
|
we have already visited TYPE (using COPIED_TYPES), or TYPE if it is
|
2911 |
|
|
not associated with OBJFILE. */
|
2912 |
|
|
|
2913 |
|
|
struct type *
|
2914 |
|
|
copy_type_recursive (struct objfile *objfile,
|
2915 |
|
|
struct type *type,
|
2916 |
|
|
htab_t copied_types)
|
2917 |
|
|
{
|
2918 |
|
|
struct type_pair *stored, pair;
|
2919 |
|
|
void **slot;
|
2920 |
|
|
struct type *new_type;
|
2921 |
|
|
|
2922 |
|
|
if (TYPE_OBJFILE (type) == NULL)
|
2923 |
|
|
return type;
|
2924 |
|
|
|
2925 |
|
|
/* This type shouldn't be pointing to any types in other objfiles;
|
2926 |
|
|
if it did, the type might disappear unexpectedly. */
|
2927 |
|
|
gdb_assert (TYPE_OBJFILE (type) == objfile);
|
2928 |
|
|
|
2929 |
|
|
pair.old = type;
|
2930 |
|
|
slot = htab_find_slot (copied_types, &pair, INSERT);
|
2931 |
|
|
if (*slot != NULL)
|
2932 |
|
|
return ((struct type_pair *) *slot)->new;
|
2933 |
|
|
|
2934 |
|
|
new_type = alloc_type (NULL);
|
2935 |
|
|
|
2936 |
|
|
/* We must add the new type to the hash table immediately, in case
|
2937 |
|
|
we encounter this type again during a recursive call below. */
|
2938 |
|
|
stored = xmalloc (sizeof (struct type_pair));
|
2939 |
|
|
stored->old = type;
|
2940 |
|
|
stored->new = new_type;
|
2941 |
|
|
*slot = stored;
|
2942 |
|
|
|
2943 |
|
|
/* Copy the common fields of types. */
|
2944 |
|
|
TYPE_CODE (new_type) = TYPE_CODE (type);
|
2945 |
|
|
TYPE_ARRAY_UPPER_BOUND_TYPE (new_type) =
|
2946 |
|
|
TYPE_ARRAY_UPPER_BOUND_TYPE (type);
|
2947 |
|
|
TYPE_ARRAY_LOWER_BOUND_TYPE (new_type) =
|
2948 |
|
|
TYPE_ARRAY_LOWER_BOUND_TYPE (type);
|
2949 |
|
|
if (TYPE_NAME (type))
|
2950 |
|
|
TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
|
2951 |
|
|
if (TYPE_TAG_NAME (type))
|
2952 |
|
|
TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type));
|
2953 |
|
|
TYPE_FLAGS (new_type) = TYPE_FLAGS (type);
|
2954 |
|
|
TYPE_VPTR_FIELDNO (new_type) = TYPE_VPTR_FIELDNO (type);
|
2955 |
|
|
|
2956 |
|
|
TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
|
2957 |
|
|
TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
|
2958 |
|
|
|
2959 |
|
|
/* Copy the fields. */
|
2960 |
|
|
TYPE_NFIELDS (new_type) = TYPE_NFIELDS (type);
|
2961 |
|
|
if (TYPE_NFIELDS (type))
|
2962 |
|
|
{
|
2963 |
|
|
int i, nfields;
|
2964 |
|
|
|
2965 |
|
|
nfields = TYPE_NFIELDS (type);
|
2966 |
|
|
TYPE_FIELDS (new_type) = xmalloc (sizeof (struct field) * nfields);
|
2967 |
|
|
for (i = 0; i < nfields; i++)
|
2968 |
|
|
{
|
2969 |
|
|
TYPE_FIELD_ARTIFICIAL (new_type, i) =
|
2970 |
|
|
TYPE_FIELD_ARTIFICIAL (type, i);
|
2971 |
|
|
TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i);
|
2972 |
|
|
if (TYPE_FIELD_TYPE (type, i))
|
2973 |
|
|
TYPE_FIELD_TYPE (new_type, i)
|
2974 |
|
|
= copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i),
|
2975 |
|
|
copied_types);
|
2976 |
|
|
if (TYPE_FIELD_NAME (type, i))
|
2977 |
|
|
TYPE_FIELD_NAME (new_type, i) =
|
2978 |
|
|
xstrdup (TYPE_FIELD_NAME (type, i));
|
2979 |
|
|
if (TYPE_FIELD_STATIC_HAS_ADDR (type, i))
|
2980 |
|
|
SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
|
2981 |
|
|
TYPE_FIELD_STATIC_PHYSADDR (type, i));
|
2982 |
|
|
else if (TYPE_FIELD_STATIC (type, i))
|
2983 |
|
|
SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i),
|
2984 |
|
|
xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type,
|
2985 |
|
|
i)));
|
2986 |
|
|
else
|
2987 |
|
|
{
|
2988 |
|
|
TYPE_FIELD_BITPOS (new_type, i) =
|
2989 |
|
|
TYPE_FIELD_BITPOS (type, i);
|
2990 |
|
|
TYPE_FIELD_STATIC_KIND (new_type, i) = 0;
|
2991 |
|
|
}
|
2992 |
|
|
}
|
2993 |
|
|
}
|
2994 |
|
|
|
2995 |
|
|
/* Copy pointers to other types. */
|
2996 |
|
|
if (TYPE_TARGET_TYPE (type))
|
2997 |
|
|
TYPE_TARGET_TYPE (new_type) =
|
2998 |
|
|
copy_type_recursive (objfile,
|
2999 |
|
|
TYPE_TARGET_TYPE (type),
|
3000 |
|
|
copied_types);
|
3001 |
|
|
if (TYPE_VPTR_BASETYPE (type))
|
3002 |
|
|
TYPE_VPTR_BASETYPE (new_type) =
|
3003 |
|
|
copy_type_recursive (objfile,
|
3004 |
|
|
TYPE_VPTR_BASETYPE (type),
|
3005 |
|
|
copied_types);
|
3006 |
|
|
/* Maybe copy the type_specific bits.
|
3007 |
|
|
|
3008 |
|
|
NOTE drow/2005-12-09: We do not copy the C++-specific bits like
|
3009 |
|
|
base classes and methods. There's no fundamental reason why we
|
3010 |
|
|
can't, but at the moment it is not needed. */
|
3011 |
|
|
|
3012 |
|
|
if (TYPE_CODE (type) == TYPE_CODE_FLT)
|
3013 |
|
|
TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type);
|
3014 |
|
|
else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
|
3015 |
|
|
|| TYPE_CODE (type) == TYPE_CODE_UNION
|
3016 |
|
|
|| TYPE_CODE (type) == TYPE_CODE_TEMPLATE
|
3017 |
|
|
|| TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
|
3018 |
|
|
INIT_CPLUS_SPECIFIC (new_type);
|
3019 |
|
|
|
3020 |
|
|
return new_type;
|
3021 |
|
|
}
|
3022 |
|
|
|
3023 |
|
|
static struct type *
|
3024 |
|
|
build_flt (int bit, char *name, const struct floatformat **floatformats)
|
3025 |
|
|
{
|
3026 |
|
|
struct type *t;
|
3027 |
|
|
|
3028 |
|
|
if (bit == -1)
|
3029 |
|
|
{
|
3030 |
|
|
gdb_assert (floatformats != NULL);
|
3031 |
|
|
gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
|
3032 |
|
|
bit = floatformats[0]->totalsize;
|
3033 |
|
|
}
|
3034 |
|
|
gdb_assert (bit >= 0);
|
3035 |
|
|
|
3036 |
|
|
t = init_type (TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, 0, name, NULL);
|
3037 |
|
|
TYPE_FLOATFORMAT (t) = floatformats;
|
3038 |
|
|
return t;
|
3039 |
|
|
}
|
3040 |
|
|
|
3041 |
|
|
static struct gdbarch_data *gdbtypes_data;
|
3042 |
|
|
|
3043 |
|
|
const struct builtin_type *
|
3044 |
|
|
builtin_type (struct gdbarch *gdbarch)
|
3045 |
|
|
{
|
3046 |
|
|
return gdbarch_data (gdbarch, gdbtypes_data);
|
3047 |
|
|
}
|
3048 |
|
|
|
3049 |
|
|
|
3050 |
|
|
static struct type *
|
3051 |
|
|
build_complex (int bit, char *name, struct type *target_type)
|
3052 |
|
|
{
|
3053 |
|
|
struct type *t;
|
3054 |
|
|
if (bit <= 0 || target_type == builtin_type_error)
|
3055 |
|
|
{
|
3056 |
|
|
gdb_assert (builtin_type_error != NULL);
|
3057 |
|
|
return builtin_type_error;
|
3058 |
|
|
}
|
3059 |
|
|
t = init_type (TYPE_CODE_COMPLEX, 2 * bit / TARGET_CHAR_BIT,
|
3060 |
|
|
0, name, (struct objfile *) NULL);
|
3061 |
|
|
TYPE_TARGET_TYPE (t) = target_type;
|
3062 |
|
|
return t;
|
3063 |
|
|
}
|
3064 |
|
|
|
3065 |
|
|
static void *
|
3066 |
|
|
gdbtypes_post_init (struct gdbarch *gdbarch)
|
3067 |
|
|
{
|
3068 |
|
|
struct builtin_type *builtin_type
|
3069 |
|
|
= GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type);
|
3070 |
|
|
|
3071 |
|
|
builtin_type->builtin_void =
|
3072 |
|
|
init_type (TYPE_CODE_VOID, 1,
|
3073 |
|
|
0,
|
3074 |
|
|
"void", (struct objfile *) NULL);
|
3075 |
|
|
builtin_type->builtin_char =
|
3076 |
|
|
init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
|
3077 |
|
|
(TYPE_FLAG_NOSIGN
|
3078 |
|
|
| (gdbarch_char_signed (gdbarch) ? 0 : TYPE_FLAG_UNSIGNED)),
|
3079 |
|
|
"char", (struct objfile *) NULL);
|
3080 |
|
|
builtin_type->builtin_true_char =
|
3081 |
|
|
init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
|
3082 |
|
|
0,
|
3083 |
|
|
"true character", (struct objfile *) NULL);
|
3084 |
|
|
builtin_type->builtin_true_unsigned_char =
|
3085 |
|
|
init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
|
3086 |
|
|
TYPE_FLAG_UNSIGNED,
|
3087 |
|
|
"true character", (struct objfile *) NULL);
|
3088 |
|
|
builtin_type->builtin_signed_char =
|
3089 |
|
|
init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
|
3090 |
|
|
0,
|
3091 |
|
|
"signed char", (struct objfile *) NULL);
|
3092 |
|
|
builtin_type->builtin_unsigned_char =
|
3093 |
|
|
init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
|
3094 |
|
|
TYPE_FLAG_UNSIGNED,
|
3095 |
|
|
"unsigned char", (struct objfile *) NULL);
|
3096 |
|
|
builtin_type->builtin_short =
|
3097 |
|
|
init_type (TYPE_CODE_INT,
|
3098 |
|
|
gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
|
3099 |
|
|
0, "short", (struct objfile *) NULL);
|
3100 |
|
|
builtin_type->builtin_unsigned_short =
|
3101 |
|
|
init_type (TYPE_CODE_INT,
|
3102 |
|
|
gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
|
3103 |
|
|
TYPE_FLAG_UNSIGNED, "unsigned short",
|
3104 |
|
|
(struct objfile *) NULL);
|
3105 |
|
|
builtin_type->builtin_int =
|
3106 |
|
|
init_type (TYPE_CODE_INT,
|
3107 |
|
|
gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
|
3108 |
|
|
0, "int", (struct objfile *) NULL);
|
3109 |
|
|
builtin_type->builtin_unsigned_int =
|
3110 |
|
|
init_type (TYPE_CODE_INT,
|
3111 |
|
|
gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
|
3112 |
|
|
TYPE_FLAG_UNSIGNED, "unsigned int",
|
3113 |
|
|
(struct objfile *) NULL);
|
3114 |
|
|
builtin_type->builtin_long =
|
3115 |
|
|
init_type (TYPE_CODE_INT,
|
3116 |
|
|
gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
|
3117 |
|
|
0, "long", (struct objfile *) NULL);
|
3118 |
|
|
builtin_type->builtin_unsigned_long =
|
3119 |
|
|
init_type (TYPE_CODE_INT,
|
3120 |
|
|
gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
|
3121 |
|
|
TYPE_FLAG_UNSIGNED, "unsigned long",
|
3122 |
|
|
(struct objfile *) NULL);
|
3123 |
|
|
builtin_type->builtin_long_long =
|
3124 |
|
|
init_type (TYPE_CODE_INT,
|
3125 |
|
|
gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
|
3126 |
|
|
0, "long long", (struct objfile *) NULL);
|
3127 |
|
|
builtin_type->builtin_unsigned_long_long =
|
3128 |
|
|
init_type (TYPE_CODE_INT,
|
3129 |
|
|
gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
|
3130 |
|
|
TYPE_FLAG_UNSIGNED, "unsigned long long",
|
3131 |
|
|
(struct objfile *) NULL);
|
3132 |
|
|
builtin_type->builtin_float
|
3133 |
|
|
= build_flt (gdbarch_float_bit (gdbarch), "float",
|
3134 |
|
|
gdbarch_float_format (gdbarch));
|
3135 |
|
|
builtin_type->builtin_double
|
3136 |
|
|
= build_flt (gdbarch_double_bit (gdbarch), "double",
|
3137 |
|
|
gdbarch_double_format (gdbarch));
|
3138 |
|
|
builtin_type->builtin_long_double
|
3139 |
|
|
= build_flt (gdbarch_long_double_bit (gdbarch), "long double",
|
3140 |
|
|
gdbarch_long_double_format (gdbarch));
|
3141 |
|
|
builtin_type->builtin_complex
|
3142 |
|
|
= build_complex (gdbarch_float_bit (gdbarch), "complex",
|
3143 |
|
|
builtin_type->builtin_float);
|
3144 |
|
|
builtin_type->builtin_double_complex
|
3145 |
|
|
= build_complex (gdbarch_double_bit (gdbarch), "double complex",
|
3146 |
|
|
builtin_type->builtin_double);
|
3147 |
|
|
builtin_type->builtin_string =
|
3148 |
|
|
init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
|
3149 |
|
|
0,
|
3150 |
|
|
"string", (struct objfile *) NULL);
|
3151 |
|
|
builtin_type->builtin_bool =
|
3152 |
|
|
init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
|
3153 |
|
|
0,
|
3154 |
|
|
"bool", (struct objfile *) NULL);
|
3155 |
|
|
|
3156 |
|
|
/* The following three are about decimal floating point types, which
|
3157 |
|
|
are 32-bits, 64-bits and 128-bits respectively. */
|
3158 |
|
|
builtin_type->builtin_decfloat
|
3159 |
|
|
= init_type (TYPE_CODE_DECFLOAT, 32 / 8,
|
3160 |
|
|
0,
|
3161 |
|
|
"_Decimal32", (struct objfile *) NULL);
|
3162 |
|
|
builtin_type->builtin_decdouble
|
3163 |
|
|
= init_type (TYPE_CODE_DECFLOAT, 64 / 8,
|
3164 |
|
|
0,
|
3165 |
|
|
"_Decimal64", (struct objfile *) NULL);
|
3166 |
|
|
builtin_type->builtin_declong
|
3167 |
|
|
= init_type (TYPE_CODE_DECFLOAT, 128 / 8,
|
3168 |
|
|
0,
|
3169 |
|
|
"_Decimal128", (struct objfile *) NULL);
|
3170 |
|
|
|
3171 |
|
|
/* Pointer/Address types. */
|
3172 |
|
|
|
3173 |
|
|
/* NOTE: on some targets, addresses and pointers are not necessarily
|
3174 |
|
|
the same --- for example, on the D10V, pointers are 16 bits long,
|
3175 |
|
|
but addresses are 32 bits long. See doc/gdbint.texinfo,
|
3176 |
|
|
``Pointers Are Not Always Addresses''.
|
3177 |
|
|
|
3178 |
|
|
The upshot is:
|
3179 |
|
|
- gdb's `struct type' always describes the target's
|
3180 |
|
|
representation.
|
3181 |
|
|
- gdb's `struct value' objects should always hold values in
|
3182 |
|
|
target form.
|
3183 |
|
|
- gdb's CORE_ADDR values are addresses in the unified virtual
|
3184 |
|
|
address space that the assembler and linker work with. Thus,
|
3185 |
|
|
since target_read_memory takes a CORE_ADDR as an argument, it
|
3186 |
|
|
can access any memory on the target, even if the processor has
|
3187 |
|
|
separate code and data address spaces.
|
3188 |
|
|
|
3189 |
|
|
So, for example:
|
3190 |
|
|
- If v is a value holding a D10V code pointer, its contents are
|
3191 |
|
|
in target form: a big-endian address left-shifted two bits.
|
3192 |
|
|
- If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
|
3193 |
|
|
sizeof (void *) == 2 on the target.
|
3194 |
|
|
|
3195 |
|
|
In this context, builtin_type->CORE_ADDR is a bit odd: it's a
|
3196 |
|
|
target type for a value the target will never see. It's only
|
3197 |
|
|
used to hold the values of (typeless) linker symbols, which are
|
3198 |
|
|
indeed in the unified virtual address space. */
|
3199 |
|
|
|
3200 |
|
|
builtin_type->builtin_data_ptr =
|
3201 |
|
|
make_pointer_type (builtin_type->builtin_void, NULL);
|
3202 |
|
|
builtin_type->builtin_func_ptr =
|
3203 |
|
|
lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
|
3204 |
|
|
builtin_type->builtin_core_addr =
|
3205 |
|
|
init_type (TYPE_CODE_INT,
|
3206 |
|
|
gdbarch_addr_bit (gdbarch) / 8,
|
3207 |
|
|
TYPE_FLAG_UNSIGNED,
|
3208 |
|
|
"__CORE_ADDR", (struct objfile *) NULL);
|
3209 |
|
|
|
3210 |
|
|
|
3211 |
|
|
/* The following set of types is used for symbols with no
|
3212 |
|
|
debug information. */
|
3213 |
|
|
builtin_type->nodebug_text_symbol =
|
3214 |
|
|
init_type (TYPE_CODE_FUNC, 1, 0,
|
3215 |
|
|
"<text variable, no debug info>", NULL);
|
3216 |
|
|
TYPE_TARGET_TYPE (builtin_type->nodebug_text_symbol) =
|
3217 |
|
|
builtin_type->builtin_int;
|
3218 |
|
|
builtin_type->nodebug_data_symbol =
|
3219 |
|
|
init_type (TYPE_CODE_INT,
|
3220 |
|
|
gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
|
3221 |
|
|
"<data variable, no debug info>", NULL);
|
3222 |
|
|
builtin_type->nodebug_unknown_symbol =
|
3223 |
|
|
init_type (TYPE_CODE_INT, 1, 0,
|
3224 |
|
|
"<variable (not text or data), no debug info>", NULL);
|
3225 |
|
|
builtin_type->nodebug_tls_symbol =
|
3226 |
|
|
init_type (TYPE_CODE_INT,
|
3227 |
|
|
gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
|
3228 |
|
|
"<thread local variable, no debug info>", NULL);
|
3229 |
|
|
|
3230 |
|
|
return builtin_type;
|
3231 |
|
|
}
|
3232 |
|
|
|
3233 |
|
|
extern void _initialize_gdbtypes (void);
|
3234 |
|
|
void
|
3235 |
|
|
_initialize_gdbtypes (void)
|
3236 |
|
|
{
|
3237 |
|
|
gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
|
3238 |
|
|
|
3239 |
|
|
/* FIXME: The following types are architecture-neutral. However,
|
3240 |
|
|
they contain pointer_type and reference_type fields potentially
|
3241 |
|
|
caching pointer or reference types that *are* architecture
|
3242 |
|
|
dependent. */
|
3243 |
|
|
|
3244 |
|
|
builtin_type_int0 =
|
3245 |
|
|
init_type (TYPE_CODE_INT, 0 / 8,
|
3246 |
|
|
0,
|
3247 |
|
|
"int0_t", (struct objfile *) NULL);
|
3248 |
|
|
builtin_type_int8 =
|
3249 |
|
|
init_type (TYPE_CODE_INT, 8 / 8,
|
3250 |
|
|
TYPE_FLAG_NOTTEXT,
|
3251 |
|
|
"int8_t", (struct objfile *) NULL);
|
3252 |
|
|
builtin_type_uint8 =
|
3253 |
|
|
init_type (TYPE_CODE_INT, 8 / 8,
|
3254 |
|
|
TYPE_FLAG_UNSIGNED | TYPE_FLAG_NOTTEXT,
|
3255 |
|
|
"uint8_t", (struct objfile *) NULL);
|
3256 |
|
|
builtin_type_int16 =
|
3257 |
|
|
init_type (TYPE_CODE_INT, 16 / 8,
|
3258 |
|
|
0,
|
3259 |
|
|
"int16_t", (struct objfile *) NULL);
|
3260 |
|
|
builtin_type_uint16 =
|
3261 |
|
|
init_type (TYPE_CODE_INT, 16 / 8,
|
3262 |
|
|
TYPE_FLAG_UNSIGNED,
|
3263 |
|
|
"uint16_t", (struct objfile *) NULL);
|
3264 |
|
|
builtin_type_int32 =
|
3265 |
|
|
init_type (TYPE_CODE_INT, 32 / 8,
|
3266 |
|
|
0,
|
3267 |
|
|
"int32_t", (struct objfile *) NULL);
|
3268 |
|
|
builtin_type_uint32 =
|
3269 |
|
|
init_type (TYPE_CODE_INT, 32 / 8,
|
3270 |
|
|
TYPE_FLAG_UNSIGNED,
|
3271 |
|
|
"uint32_t", (struct objfile *) NULL);
|
3272 |
|
|
builtin_type_int64 =
|
3273 |
|
|
init_type (TYPE_CODE_INT, 64 / 8,
|
3274 |
|
|
0,
|
3275 |
|
|
"int64_t", (struct objfile *) NULL);
|
3276 |
|
|
builtin_type_uint64 =
|
3277 |
|
|
init_type (TYPE_CODE_INT, 64 / 8,
|
3278 |
|
|
TYPE_FLAG_UNSIGNED,
|
3279 |
|
|
"uint64_t", (struct objfile *) NULL);
|
3280 |
|
|
builtin_type_int128 =
|
3281 |
|
|
init_type (TYPE_CODE_INT, 128 / 8,
|
3282 |
|
|
0,
|
3283 |
|
|
"int128_t", (struct objfile *) NULL);
|
3284 |
|
|
builtin_type_uint128 =
|
3285 |
|
|
init_type (TYPE_CODE_INT, 128 / 8,
|
3286 |
|
|
TYPE_FLAG_UNSIGNED,
|
3287 |
|
|
"uint128_t", (struct objfile *) NULL);
|
3288 |
|
|
|
3289 |
|
|
builtin_type_ieee_single =
|
3290 |
|
|
build_flt (-1, "builtin_type_ieee_single", floatformats_ieee_single);
|
3291 |
|
|
builtin_type_ieee_double =
|
3292 |
|
|
build_flt (-1, "builtin_type_ieee_double", floatformats_ieee_double);
|
3293 |
|
|
builtin_type_i387_ext =
|
3294 |
|
|
build_flt (-1, "builtin_type_i387_ext", floatformats_i387_ext);
|
3295 |
|
|
builtin_type_m68881_ext =
|
3296 |
|
|
build_flt (-1, "builtin_type_m68881_ext", floatformats_m68881_ext);
|
3297 |
|
|
builtin_type_arm_ext =
|
3298 |
|
|
build_flt (-1, "builtin_type_arm_ext", floatformats_arm_ext);
|
3299 |
|
|
builtin_type_ia64_spill =
|
3300 |
|
|
build_flt (-1, "builtin_type_ia64_spill", floatformats_ia64_spill);
|
3301 |
|
|
builtin_type_ia64_quad =
|
3302 |
|
|
build_flt (-1, "builtin_type_ia64_quad", floatformats_ia64_quad);
|
3303 |
|
|
|
3304 |
|
|
add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
|
3305 |
|
|
Set debugging of C++ overloading."), _("\
|
3306 |
|
|
Show debugging of C++ overloading."), _("\
|
3307 |
|
|
When enabled, ranking of the functions is displayed."),
|
3308 |
|
|
NULL,
|
3309 |
|
|
show_overload_debug,
|
3310 |
|
|
&setdebuglist, &showdebuglist);
|
3311 |
|
|
|
3312 |
|
|
/* Add user knob for controlling resolution of opaque types. */
|
3313 |
|
|
add_setshow_boolean_cmd ("opaque-type-resolution", class_support,
|
3314 |
|
|
&opaque_type_resolution, _("\
|
3315 |
|
|
Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\
|
3316 |
|
|
Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL,
|
3317 |
|
|
NULL,
|
3318 |
|
|
show_opaque_type_resolution,
|
3319 |
|
|
&setlist, &showlist);
|
3320 |
|
|
}
|