1 /* Abstraction of GNU v3 abi.
2 Contributed by Jim Blandy <jimb@redhat.com>
4 Copyright (C) 2001-2020 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "cp-support.h"
30 #include "typeprint.h"
32 #include "cli/cli-style.h"
34 static struct cp_abi_ops gnu_v3_abi_ops
;
36 /* A gdbarch key for std::type_info, in the event that it can't be
37 found in the debug info. */
39 static struct gdbarch_data
*std_type_info_gdbarch_data
;
43 gnuv3_is_vtable_name (const char *name
)
45 return startswith (name
, "_ZTV");
49 gnuv3_is_operator_name (const char *name
)
51 return startswith (name
, CP_OPERATOR_STR
);
55 /* To help us find the components of a vtable, we build ourselves a
56 GDB type object representing the vtable structure. Following the
57 V3 ABI, it goes something like this:
59 struct gdb_gnu_v3_abi_vtable {
61 / * An array of virtual call and virtual base offsets. The real
62 length of this array depends on the class hierarchy; we use
63 negative subscripts to access the elements. Yucky, but
64 better than the alternatives. * /
65 ptrdiff_t vcall_and_vbase_offsets[0];
67 / * The offset from a virtual pointer referring to this table
68 to the top of the complete object. * /
69 ptrdiff_t offset_to_top;
71 / * The type_info pointer for this class. This is really a
72 std::type_info *, but GDB doesn't really look at the
73 type_info object itself, so we don't bother to get the type
77 / * Virtual table pointers in objects point here. * /
79 / * Virtual function pointers. Like the vcall/vbase array, the
80 real length of this table depends on the class hierarchy. * /
81 void (*virtual_functions[0]) ();
85 The catch, of course, is that the exact layout of this table
86 depends on the ABI --- word size, endianness, alignment, etc. So
87 the GDB type object is actually a per-architecture kind of thing.
89 vtable_type_gdbarch_data is a gdbarch per-architecture data pointer
90 which refers to the struct type * for this structure, laid out
91 appropriately for the architecture. */
92 static struct gdbarch_data
*vtable_type_gdbarch_data
;
95 /* Human-readable names for the numbers of the fields above. */
97 vtable_field_vcall_and_vbase_offsets
,
98 vtable_field_offset_to_top
,
99 vtable_field_type_info
,
100 vtable_field_virtual_functions
104 /* Return a GDB type representing `struct gdb_gnu_v3_abi_vtable',
105 described above, laid out appropriately for ARCH.
107 We use this function as the gdbarch per-architecture data
108 initialization function. */
110 build_gdb_vtable_type (struct gdbarch
*arch
)
113 struct field
*field_list
, *field
;
116 struct type
*void_ptr_type
117 = builtin_type (arch
)->builtin_data_ptr
;
118 struct type
*ptr_to_void_fn_type
119 = builtin_type (arch
)->builtin_func_ptr
;
121 /* ARCH can't give us the true ptrdiff_t type, so we guess. */
122 struct type
*ptrdiff_type
123 = arch_integer_type (arch
, gdbarch_ptr_bit (arch
), 0, "ptrdiff_t");
125 /* We assume no padding is necessary, since GDB doesn't know
126 anything about alignment at the moment. If this assumption bites
127 us, we should add a gdbarch method which, given a type, returns
128 the alignment that type requires, and then use that here. */
130 /* Build the field list. */
131 field_list
= XCNEWVEC (struct field
, 4);
132 field
= &field_list
[0];
135 /* ptrdiff_t vcall_and_vbase_offsets[0]; */
136 FIELD_NAME (*field
) = "vcall_and_vbase_offsets";
137 FIELD_TYPE (*field
) = lookup_array_range_type (ptrdiff_type
, 0, -1);
138 SET_FIELD_BITPOS (*field
, offset
* TARGET_CHAR_BIT
);
139 offset
+= TYPE_LENGTH (FIELD_TYPE (*field
));
142 /* ptrdiff_t offset_to_top; */
143 FIELD_NAME (*field
) = "offset_to_top";
144 FIELD_TYPE (*field
) = ptrdiff_type
;
145 SET_FIELD_BITPOS (*field
, offset
* TARGET_CHAR_BIT
);
146 offset
+= TYPE_LENGTH (FIELD_TYPE (*field
));
149 /* void *type_info; */
150 FIELD_NAME (*field
) = "type_info";
151 FIELD_TYPE (*field
) = void_ptr_type
;
152 SET_FIELD_BITPOS (*field
, offset
* TARGET_CHAR_BIT
);
153 offset
+= TYPE_LENGTH (FIELD_TYPE (*field
));
156 /* void (*virtual_functions[0]) (); */
157 FIELD_NAME (*field
) = "virtual_functions";
158 FIELD_TYPE (*field
) = lookup_array_range_type (ptr_to_void_fn_type
, 0, -1);
159 SET_FIELD_BITPOS (*field
, offset
* TARGET_CHAR_BIT
);
160 offset
+= TYPE_LENGTH (FIELD_TYPE (*field
));
163 /* We assumed in the allocation above that there were four fields. */
164 gdb_assert (field
== (field_list
+ 4));
166 t
= arch_type (arch
, TYPE_CODE_STRUCT
, offset
* TARGET_CHAR_BIT
, NULL
);
167 TYPE_NFIELDS (t
) = field
- field_list
;
168 TYPE_FIELDS (t
) = field_list
;
169 TYPE_NAME (t
) = "gdb_gnu_v3_abi_vtable";
170 INIT_CPLUS_SPECIFIC (t
);
172 return make_type_with_address_space (t
, TYPE_INSTANCE_FLAG_CODE_SPACE
);
176 /* Return the ptrdiff_t type used in the vtable type. */
178 vtable_ptrdiff_type (struct gdbarch
*gdbarch
)
180 struct type
*vtable_type
181 = (struct type
*) gdbarch_data (gdbarch
, vtable_type_gdbarch_data
);
183 /* The "offset_to_top" field has the appropriate (ptrdiff_t) type. */
184 return TYPE_FIELD_TYPE (vtable_type
, vtable_field_offset_to_top
);
187 /* Return the offset from the start of the imaginary `struct
188 gdb_gnu_v3_abi_vtable' object to the vtable's "address point"
189 (i.e., where objects' virtual table pointers point). */
191 vtable_address_point_offset (struct gdbarch
*gdbarch
)
193 struct type
*vtable_type
194 = (struct type
*) gdbarch_data (gdbarch
, vtable_type_gdbarch_data
);
196 return (TYPE_FIELD_BITPOS (vtable_type
, vtable_field_virtual_functions
)
201 /* Determine whether structure TYPE is a dynamic class. Cache the
205 gnuv3_dynamic_class (struct type
*type
)
207 int fieldnum
, fieldelem
;
209 type
= check_typedef (type
);
210 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_STRUCT
211 || TYPE_CODE (type
) == TYPE_CODE_UNION
);
213 if (TYPE_CODE (type
) == TYPE_CODE_UNION
)
216 if (TYPE_CPLUS_DYNAMIC (type
))
217 return TYPE_CPLUS_DYNAMIC (type
) == 1;
219 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
221 for (fieldnum
= 0; fieldnum
< TYPE_N_BASECLASSES (type
); fieldnum
++)
222 if (BASETYPE_VIA_VIRTUAL (type
, fieldnum
)
223 || gnuv3_dynamic_class (TYPE_FIELD_TYPE (type
, fieldnum
)))
225 TYPE_CPLUS_DYNAMIC (type
) = 1;
229 for (fieldnum
= 0; fieldnum
< TYPE_NFN_FIELDS (type
); fieldnum
++)
230 for (fieldelem
= 0; fieldelem
< TYPE_FN_FIELDLIST_LENGTH (type
, fieldnum
);
233 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, fieldnum
);
235 if (TYPE_FN_FIELD_VIRTUAL_P (f
, fieldelem
))
237 TYPE_CPLUS_DYNAMIC (type
) = 1;
242 TYPE_CPLUS_DYNAMIC (type
) = -1;
246 /* Find the vtable for a value of CONTAINER_TYPE located at
247 CONTAINER_ADDR. Return a value of the correct vtable type for this
248 architecture, or NULL if CONTAINER does not have a vtable. */
250 static struct value
*
251 gnuv3_get_vtable (struct gdbarch
*gdbarch
,
252 struct type
*container_type
, CORE_ADDR container_addr
)
254 struct type
*vtable_type
255 = (struct type
*) gdbarch_data (gdbarch
, vtable_type_gdbarch_data
);
256 struct type
*vtable_pointer_type
;
257 struct value
*vtable_pointer
;
258 CORE_ADDR vtable_address
;
260 container_type
= check_typedef (container_type
);
261 gdb_assert (TYPE_CODE (container_type
) == TYPE_CODE_STRUCT
);
263 /* If this type does not have a virtual table, don't read the first
265 if (!gnuv3_dynamic_class (container_type
))
268 /* We do not consult the debug information to find the virtual table.
269 The ABI specifies that it is always at offset zero in any class,
270 and debug information may not represent it.
272 We avoid using value_contents on principle, because the object might
275 /* Find the type "pointer to virtual table". */
276 vtable_pointer_type
= lookup_pointer_type (vtable_type
);
278 /* Load it from the start of the class. */
279 vtable_pointer
= value_at (vtable_pointer_type
, container_addr
);
280 vtable_address
= value_as_address (vtable_pointer
);
282 /* Correct it to point at the start of the virtual table, rather
283 than the address point. */
284 return value_at_lazy (vtable_type
,
286 - vtable_address_point_offset (gdbarch
));
291 gnuv3_rtti_type (struct value
*value
,
292 int *full_p
, LONGEST
*top_p
, int *using_enc_p
)
294 struct gdbarch
*gdbarch
;
295 struct type
*values_type
= check_typedef (value_type (value
));
296 struct value
*vtable
;
297 struct minimal_symbol
*vtable_symbol
;
298 const char *vtable_symbol_name
;
299 const char *class_name
;
300 struct type
*run_time_type
;
301 LONGEST offset_to_top
;
304 /* We only have RTTI for dynamic class objects. */
305 if (TYPE_CODE (values_type
) != TYPE_CODE_STRUCT
306 || !gnuv3_dynamic_class (values_type
))
309 /* Determine architecture. */
310 gdbarch
= get_type_arch (values_type
);
315 vtable
= gnuv3_get_vtable (gdbarch
, values_type
,
316 value_as_address (value_addr (value
)));
320 /* Find the linker symbol for this vtable. */
322 = lookup_minimal_symbol_by_pc (value_address (vtable
)
323 + value_embedded_offset (vtable
)).minsym
;
327 /* The symbol's demangled name should be something like "vtable for
328 CLASS", where CLASS is the name of the run-time type of VALUE.
329 If we didn't like this approach, we could instead look in the
330 type_info object itself to get the class name. But this way
331 should work just as well, and doesn't read target memory. */
332 vtable_symbol_name
= vtable_symbol
->demangled_name ();
333 if (vtable_symbol_name
== NULL
334 || !startswith (vtable_symbol_name
, "vtable for "))
336 warning (_("can't find linker symbol for virtual table for `%s' value"),
337 TYPE_SAFE_NAME (values_type
));
338 if (vtable_symbol_name
)
339 warning (_(" found `%s' instead"), vtable_symbol_name
);
342 class_name
= vtable_symbol_name
+ 11;
344 /* Strip off @plt and version suffixes. */
345 atsign
= strchr (class_name
, '@');
350 copy
= (char *) alloca (atsign
- class_name
+ 1);
351 memcpy (copy
, class_name
, atsign
- class_name
);
352 copy
[atsign
- class_name
] = '\0';
356 /* Try to look up the class name as a type name. */
357 /* FIXME: chastain/2003-11-26: block=NULL is bogus. See pr gdb/1465. */
358 run_time_type
= cp_lookup_rtti_type (class_name
, NULL
);
359 if (run_time_type
== NULL
)
362 /* Get the offset from VALUE to the top of the complete object.
363 NOTE: this is the reverse of the meaning of *TOP_P. */
365 = value_as_long (value_field (vtable
, vtable_field_offset_to_top
));
368 *full_p
= (- offset_to_top
== value_embedded_offset (value
)
369 && (TYPE_LENGTH (value_enclosing_type (value
))
370 >= TYPE_LENGTH (run_time_type
)));
372 *top_p
= - offset_to_top
;
373 return run_time_type
;
376 /* Return a function pointer for CONTAINER's VTABLE_INDEX'th virtual
377 function, of type FNTYPE. */
379 static struct value
*
380 gnuv3_get_virtual_fn (struct gdbarch
*gdbarch
, struct value
*container
,
381 struct type
*fntype
, int vtable_index
)
383 struct value
*vtable
, *vfn
;
385 /* Every class with virtual functions must have a vtable. */
386 vtable
= gnuv3_get_vtable (gdbarch
, value_type (container
),
387 value_as_address (value_addr (container
)));
388 gdb_assert (vtable
!= NULL
);
390 /* Fetch the appropriate function pointer from the vtable. */
391 vfn
= value_subscript (value_field (vtable
, vtable_field_virtual_functions
),
394 /* If this architecture uses function descriptors directly in the vtable,
395 then the address of the vtable entry is actually a "function pointer"
396 (i.e. points to the descriptor). We don't need to scale the index
397 by the size of a function descriptor; GCC does that before outputting
398 debug information. */
399 if (gdbarch_vtable_function_descriptors (gdbarch
))
400 vfn
= value_addr (vfn
);
402 /* Cast the function pointer to the appropriate type. */
403 vfn
= value_cast (lookup_pointer_type (fntype
), vfn
);
408 /* GNU v3 implementation of value_virtual_fn_field. See cp-abi.h
409 for a description of the arguments. */
411 static struct value
*
412 gnuv3_virtual_fn_field (struct value
**value_p
,
413 struct fn_field
*f
, int j
,
414 struct type
*vfn_base
, int offset
)
416 struct type
*values_type
= check_typedef (value_type (*value_p
));
417 struct gdbarch
*gdbarch
;
419 /* Some simple sanity checks. */
420 if (TYPE_CODE (values_type
) != TYPE_CODE_STRUCT
)
421 error (_("Only classes can have virtual functions."));
423 /* Determine architecture. */
424 gdbarch
= get_type_arch (values_type
);
426 /* Cast our value to the base class which defines this virtual
427 function. This takes care of any necessary `this'
429 if (vfn_base
!= values_type
)
430 *value_p
= value_cast (vfn_base
, *value_p
);
432 return gnuv3_get_virtual_fn (gdbarch
, *value_p
, TYPE_FN_FIELD_TYPE (f
, j
),
433 TYPE_FN_FIELD_VOFFSET (f
, j
));
436 /* Compute the offset of the baseclass which is
437 the INDEXth baseclass of class TYPE,
438 for value at VALADDR (in host) at ADDRESS (in target).
439 The result is the offset of the baseclass value relative
440 to (the address of)(ARG) + OFFSET.
442 -1 is returned on error. */
445 gnuv3_baseclass_offset (struct type
*type
, int index
,
446 const bfd_byte
*valaddr
, LONGEST embedded_offset
,
447 CORE_ADDR address
, const struct value
*val
)
449 struct gdbarch
*gdbarch
;
450 struct type
*ptr_type
;
451 struct value
*vtable
;
452 struct value
*vbase_array
;
453 long int cur_base_offset
, base_offset
;
455 /* Determine architecture. */
456 gdbarch
= get_type_arch (type
);
457 ptr_type
= builtin_type (gdbarch
)->builtin_data_ptr
;
459 /* If it isn't a virtual base, this is easy. The offset is in the
461 if (!BASETYPE_VIA_VIRTUAL (type
, index
))
462 return TYPE_BASECLASS_BITPOS (type
, index
) / 8;
464 /* To access a virtual base, we need to use the vbase offset stored in
465 our vtable. Recent GCC versions provide this information. If it isn't
466 available, we could get what we needed from RTTI, or from drawing the
467 complete inheritance graph based on the debug info. Neither is
469 cur_base_offset
= TYPE_BASECLASS_BITPOS (type
, index
) / 8;
470 if (cur_base_offset
>= - vtable_address_point_offset (gdbarch
))
471 error (_("Expected a negative vbase offset (old compiler?)"));
473 cur_base_offset
= cur_base_offset
+ vtable_address_point_offset (gdbarch
);
474 if ((- cur_base_offset
) % TYPE_LENGTH (ptr_type
) != 0)
475 error (_("Misaligned vbase offset."));
476 cur_base_offset
= cur_base_offset
/ ((int) TYPE_LENGTH (ptr_type
));
478 vtable
= gnuv3_get_vtable (gdbarch
, type
, address
+ embedded_offset
);
479 gdb_assert (vtable
!= NULL
);
480 vbase_array
= value_field (vtable
, vtable_field_vcall_and_vbase_offsets
);
481 base_offset
= value_as_long (value_subscript (vbase_array
, cur_base_offset
));
485 /* Locate a virtual method in DOMAIN or its non-virtual base classes
486 which has virtual table index VOFFSET. The method has an associated
487 "this" adjustment of ADJUSTMENT bytes. */
490 gnuv3_find_method_in (struct type
*domain
, CORE_ADDR voffset
,
495 /* Search this class first. */
500 len
= TYPE_NFN_FIELDS (domain
);
501 for (i
= 0; i
< len
; i
++)
506 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
507 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
509 check_stub_method_group (domain
, i
);
510 for (j
= 0; j
< len2
; j
++)
511 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == voffset
)
512 return TYPE_FN_FIELD_PHYSNAME (f
, j
);
516 /* Next search non-virtual bases. If it's in a virtual base,
517 we're out of luck. */
518 for (i
= 0; i
< TYPE_N_BASECLASSES (domain
); i
++)
521 struct type
*basetype
;
523 if (BASETYPE_VIA_VIRTUAL (domain
, i
))
526 pos
= TYPE_BASECLASS_BITPOS (domain
, i
) / 8;
527 basetype
= TYPE_FIELD_TYPE (domain
, i
);
528 /* Recurse with a modified adjustment. We don't need to adjust
530 if (adjustment
>= pos
&& adjustment
< pos
+ TYPE_LENGTH (basetype
))
531 return gnuv3_find_method_in (basetype
, voffset
, adjustment
- pos
);
537 /* Decode GNU v3 method pointer. */
540 gnuv3_decode_method_ptr (struct gdbarch
*gdbarch
,
541 const gdb_byte
*contents
,
543 LONGEST
*adjustment_p
)
545 struct type
*funcptr_type
= builtin_type (gdbarch
)->builtin_func_ptr
;
546 struct type
*offset_type
= vtable_ptrdiff_type (gdbarch
);
547 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
549 LONGEST voffset
, adjustment
;
552 /* Extract the pointer to member. The first element is either a pointer
553 or a vtable offset. For pointers, we need to use extract_typed_address
554 to allow the back-end to convert the pointer to a GDB address -- but
555 vtable offsets we must handle as integers. At this point, we do not
556 yet know which case we have, so we extract the value under both
557 interpretations and choose the right one later on. */
558 ptr_value
= extract_typed_address (contents
, funcptr_type
);
559 voffset
= extract_signed_integer (contents
,
560 TYPE_LENGTH (funcptr_type
), byte_order
);
561 contents
+= TYPE_LENGTH (funcptr_type
);
562 adjustment
= extract_signed_integer (contents
,
563 TYPE_LENGTH (offset_type
), byte_order
);
565 if (!gdbarch_vbit_in_delta (gdbarch
))
568 voffset
= voffset
^ vbit
;
572 vbit
= adjustment
& 1;
573 adjustment
= adjustment
>> 1;
576 *value_p
= vbit
? voffset
: ptr_value
;
577 *adjustment_p
= adjustment
;
581 /* GNU v3 implementation of cplus_print_method_ptr. */
584 gnuv3_print_method_ptr (const gdb_byte
*contents
,
586 struct ui_file
*stream
)
588 struct type
*self_type
= TYPE_SELF_TYPE (type
);
589 struct gdbarch
*gdbarch
= get_type_arch (self_type
);
594 /* Extract the pointer to member. */
595 vbit
= gnuv3_decode_method_ptr (gdbarch
, contents
, &ptr_value
, &adjustment
);
597 /* Check for NULL. */
598 if (ptr_value
== 0 && vbit
== 0)
600 fprintf_filtered (stream
, "NULL");
604 /* Search for a virtual method. */
608 const char *physname
;
610 /* It's a virtual table offset, maybe in this class. Search
611 for a field with the correct vtable offset. First convert it
612 to an index, as used in TYPE_FN_FIELD_VOFFSET. */
613 voffset
= ptr_value
/ TYPE_LENGTH (vtable_ptrdiff_type (gdbarch
));
615 physname
= gnuv3_find_method_in (self_type
, voffset
, adjustment
);
617 /* If we found a method, print that. We don't bother to disambiguate
618 possible paths to the method based on the adjustment. */
621 char *demangled_name
= gdb_demangle (physname
,
622 DMGL_ANSI
| DMGL_PARAMS
);
624 fprintf_filtered (stream
, "&virtual ");
625 if (demangled_name
== NULL
)
626 fputs_filtered (physname
, stream
);
629 fputs_filtered (demangled_name
, stream
);
630 xfree (demangled_name
);
635 else if (ptr_value
!= 0)
637 /* Found a non-virtual function: print out the type. */
638 fputs_filtered ("(", stream
);
639 c_print_type (type
, "", stream
, -1, 0, &type_print_raw_options
);
640 fputs_filtered (") ", stream
);
643 /* We didn't find it; print the raw data. */
646 fprintf_filtered (stream
, "&virtual table offset ");
647 print_longest (stream
, 'd', 1, ptr_value
);
651 struct value_print_options opts
;
653 get_user_print_options (&opts
);
654 print_address_demangle (&opts
, gdbarch
, ptr_value
, stream
, demangle
);
659 fprintf_filtered (stream
, ", this adjustment ");
660 print_longest (stream
, 'd', 1, adjustment
);
664 /* GNU v3 implementation of cplus_method_ptr_size. */
667 gnuv3_method_ptr_size (struct type
*type
)
669 struct gdbarch
*gdbarch
= get_type_arch (type
);
671 return 2 * TYPE_LENGTH (builtin_type (gdbarch
)->builtin_data_ptr
);
674 /* GNU v3 implementation of cplus_make_method_ptr. */
677 gnuv3_make_method_ptr (struct type
*type
, gdb_byte
*contents
,
678 CORE_ADDR value
, int is_virtual
)
680 struct gdbarch
*gdbarch
= get_type_arch (type
);
681 int size
= TYPE_LENGTH (builtin_type (gdbarch
)->builtin_data_ptr
);
682 enum bfd_endian byte_order
= type_byte_order (type
);
684 /* FIXME drow/2006-12-24: The adjustment of "this" is currently
685 always zero, since the method pointer is of the correct type.
686 But if the method pointer came from a base class, this is
687 incorrect - it should be the offset to the base. The best
688 fix might be to create the pointer to member pointing at the
689 base class and cast it to the derived class, but that requires
690 support for adjusting pointers to members when casting them -
691 not currently supported by GDB. */
693 if (!gdbarch_vbit_in_delta (gdbarch
))
695 store_unsigned_integer (contents
, size
, byte_order
, value
| is_virtual
);
696 store_unsigned_integer (contents
+ size
, size
, byte_order
, 0);
700 store_unsigned_integer (contents
, size
, byte_order
, value
);
701 store_unsigned_integer (contents
+ size
, size
, byte_order
, is_virtual
);
705 /* GNU v3 implementation of cplus_method_ptr_to_value. */
707 static struct value
*
708 gnuv3_method_ptr_to_value (struct value
**this_p
, struct value
*method_ptr
)
710 struct gdbarch
*gdbarch
;
711 const gdb_byte
*contents
= value_contents (method_ptr
);
713 struct type
*self_type
, *final_type
, *method_type
;
717 self_type
= TYPE_SELF_TYPE (check_typedef (value_type (method_ptr
)));
718 final_type
= lookup_pointer_type (self_type
);
720 method_type
= TYPE_TARGET_TYPE (check_typedef (value_type (method_ptr
)));
722 /* Extract the pointer to member. */
723 gdbarch
= get_type_arch (self_type
);
724 vbit
= gnuv3_decode_method_ptr (gdbarch
, contents
, &ptr_value
, &adjustment
);
726 /* First convert THIS to match the containing type of the pointer to
727 member. This cast may adjust the value of THIS. */
728 *this_p
= value_cast (final_type
, *this_p
);
730 /* Then apply whatever adjustment is necessary. This creates a somewhat
731 strange pointer: it claims to have type FINAL_TYPE, but in fact it
732 might not be a valid FINAL_TYPE. For instance, it might be a
733 base class of FINAL_TYPE. And if it's not the primary base class,
734 then printing it out as a FINAL_TYPE object would produce some pretty
737 But we don't really know the type of the first argument in
738 METHOD_TYPE either, which is why this happens. We can't
739 dereference this later as a FINAL_TYPE, but once we arrive in the
740 called method we'll have debugging information for the type of
741 "this" - and that'll match the value we produce here.
743 You can provoke this case by casting a Base::* to a Derived::*, for
745 *this_p
= value_cast (builtin_type (gdbarch
)->builtin_data_ptr
, *this_p
);
746 *this_p
= value_ptradd (*this_p
, adjustment
);
747 *this_p
= value_cast (final_type
, *this_p
);
753 voffset
= ptr_value
/ TYPE_LENGTH (vtable_ptrdiff_type (gdbarch
));
754 return gnuv3_get_virtual_fn (gdbarch
, value_ind (*this_p
),
755 method_type
, voffset
);
758 return value_from_pointer (lookup_pointer_type (method_type
), ptr_value
);
761 /* Objects of this type are stored in a hash table and a vector when
762 printing the vtables for a class. */
764 struct value_and_voffset
766 /* The value representing the object. */
769 /* The maximum vtable offset we've found for any object at this
770 offset in the outermost object. */
774 /* Hash function for value_and_voffset. */
777 hash_value_and_voffset (const void *p
)
779 const struct value_and_voffset
*o
= (const struct value_and_voffset
*) p
;
781 return value_address (o
->value
) + value_embedded_offset (o
->value
);
784 /* Equality function for value_and_voffset. */
787 eq_value_and_voffset (const void *a
, const void *b
)
789 const struct value_and_voffset
*ova
= (const struct value_and_voffset
*) a
;
790 const struct value_and_voffset
*ovb
= (const struct value_and_voffset
*) b
;
792 return (value_address (ova
->value
) + value_embedded_offset (ova
->value
)
793 == value_address (ovb
->value
) + value_embedded_offset (ovb
->value
));
796 /* Comparison function for value_and_voffset. */
799 compare_value_and_voffset (const struct value_and_voffset
*va
,
800 const struct value_and_voffset
*vb
)
802 CORE_ADDR addra
= (value_address (va
->value
)
803 + value_embedded_offset (va
->value
));
804 CORE_ADDR addrb
= (value_address (vb
->value
)
805 + value_embedded_offset (vb
->value
));
807 return addra
< addrb
;
810 /* A helper function used when printing vtables. This determines the
811 key (most derived) sub-object at each address and also computes the
812 maximum vtable offset seen for the corresponding vtable. Updates
813 OFFSET_HASH and OFFSET_VEC with a new value_and_voffset object, if
814 needed. VALUE is the object to examine. */
817 compute_vtable_size (htab_t offset_hash
,
818 std::vector
<value_and_voffset
*> *offset_vec
,
822 struct type
*type
= check_typedef (value_type (value
));
824 struct value_and_voffset search_vo
, *current_vo
;
826 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_STRUCT
);
828 /* If the object is not dynamic, then we are done; as it cannot have
829 dynamic base types either. */
830 if (!gnuv3_dynamic_class (type
))
833 /* Update the hash and the vec, if needed. */
834 search_vo
.value
= value
;
835 slot
= htab_find_slot (offset_hash
, &search_vo
, INSERT
);
837 current_vo
= (struct value_and_voffset
*) *slot
;
840 current_vo
= XNEW (struct value_and_voffset
);
841 current_vo
->value
= value
;
842 current_vo
->max_voffset
= -1;
844 offset_vec
->push_back (current_vo
);
847 /* Update the value_and_voffset object with the highest vtable
848 offset from this class. */
849 for (i
= 0; i
< TYPE_NFN_FIELDS (type
); ++i
)
852 struct fn_field
*fn
= TYPE_FN_FIELDLIST1 (type
, i
);
854 for (j
= 0; j
< TYPE_FN_FIELDLIST_LENGTH (type
, i
); ++j
)
856 if (TYPE_FN_FIELD_VIRTUAL_P (fn
, j
))
858 int voffset
= TYPE_FN_FIELD_VOFFSET (fn
, j
);
860 if (voffset
> current_vo
->max_voffset
)
861 current_vo
->max_voffset
= voffset
;
866 /* Recurse into base classes. */
867 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
868 compute_vtable_size (offset_hash
, offset_vec
, value_field (value
, i
));
871 /* Helper for gnuv3_print_vtable that prints a single vtable. */
874 print_one_vtable (struct gdbarch
*gdbarch
, struct value
*value
,
876 struct value_print_options
*opts
)
879 struct type
*type
= check_typedef (value_type (value
));
880 struct value
*vtable
;
883 vtable
= gnuv3_get_vtable (gdbarch
, type
,
884 value_address (value
)
885 + value_embedded_offset (value
));
886 vt_addr
= value_address (value_field (vtable
,
887 vtable_field_virtual_functions
));
889 printf_filtered (_("vtable for '%s' @ %s (subobject @ %s):\n"),
890 TYPE_SAFE_NAME (type
),
891 paddress (gdbarch
, vt_addr
),
892 paddress (gdbarch
, (value_address (value
)
893 + value_embedded_offset (value
))));
895 for (i
= 0; i
<= max_voffset
; ++i
)
897 /* Initialize it just to avoid a GCC false warning. */
902 printf_filtered ("[%d]: ", i
);
904 vfn
= value_subscript (value_field (vtable
,
905 vtable_field_virtual_functions
),
908 if (gdbarch_vtable_function_descriptors (gdbarch
))
909 vfn
= value_addr (vfn
);
913 addr
= value_as_address (vfn
);
915 catch (const gdb_exception_error
&ex
)
917 fprintf_styled (gdb_stdout
, metadata_style
.style (),
918 _("<error: %s>"), ex
.what ());
923 print_function_pointer_address (opts
, gdbarch
, addr
, gdb_stdout
);
924 printf_filtered ("\n");
928 /* Implementation of the print_vtable method. */
931 gnuv3_print_vtable (struct value
*value
)
933 struct gdbarch
*gdbarch
;
935 struct value
*vtable
;
936 struct value_print_options opts
;
939 value
= coerce_ref (value
);
940 type
= check_typedef (value_type (value
));
941 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
943 value
= value_ind (value
);
944 type
= check_typedef (value_type (value
));
947 get_user_print_options (&opts
);
949 /* Respect 'set print object'. */
950 if (opts
.objectprint
)
952 value
= value_full_object (value
, NULL
, 0, 0, 0);
953 type
= check_typedef (value_type (value
));
956 gdbarch
= get_type_arch (type
);
959 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
960 vtable
= gnuv3_get_vtable (gdbarch
, type
,
961 value_as_address (value_addr (value
)));
965 printf_filtered (_("This object does not have a virtual function table\n"));
969 htab_up
offset_hash (htab_create_alloc (1, hash_value_and_voffset
,
970 eq_value_and_voffset
,
971 xfree
, xcalloc
, xfree
));
972 std::vector
<value_and_voffset
*> result_vec
;
974 compute_vtable_size (offset_hash
.get (), &result_vec
, value
);
975 std::sort (result_vec
.begin (), result_vec
.end (),
976 compare_value_and_voffset
);
979 for (value_and_voffset
*iter
: result_vec
)
981 if (iter
->max_voffset
>= 0)
984 printf_filtered ("\n");
985 print_one_vtable (gdbarch
, iter
->value
, iter
->max_voffset
, &opts
);
991 /* Return a GDB type representing `struct std::type_info', laid out
992 appropriately for ARCH.
994 We use this function as the gdbarch per-architecture data
995 initialization function. */
998 build_std_type_info_type (struct gdbarch
*arch
)
1001 struct field
*field_list
, *field
;
1003 struct type
*void_ptr_type
1004 = builtin_type (arch
)->builtin_data_ptr
;
1005 struct type
*char_type
1006 = builtin_type (arch
)->builtin_char
;
1007 struct type
*char_ptr_type
1008 = make_pointer_type (make_cv_type (1, 0, char_type
, NULL
), NULL
);
1010 field_list
= XCNEWVEC (struct field
, 2);
1011 field
= &field_list
[0];
1015 FIELD_NAME (*field
) = "_vptr.type_info";
1016 FIELD_TYPE (*field
) = void_ptr_type
;
1017 SET_FIELD_BITPOS (*field
, offset
* TARGET_CHAR_BIT
);
1018 offset
+= TYPE_LENGTH (FIELD_TYPE (*field
));
1022 FIELD_NAME (*field
) = "__name";
1023 FIELD_TYPE (*field
) = char_ptr_type
;
1024 SET_FIELD_BITPOS (*field
, offset
* TARGET_CHAR_BIT
);
1025 offset
+= TYPE_LENGTH (FIELD_TYPE (*field
));
1028 gdb_assert (field
== (field_list
+ 2));
1030 t
= arch_type (arch
, TYPE_CODE_STRUCT
, offset
* TARGET_CHAR_BIT
, NULL
);
1031 TYPE_NFIELDS (t
) = field
- field_list
;
1032 TYPE_FIELDS (t
) = field_list
;
1033 TYPE_NAME (t
) = "gdb_gnu_v3_type_info";
1034 INIT_CPLUS_SPECIFIC (t
);
1039 /* Implement the 'get_typeid_type' method. */
1041 static struct type
*
1042 gnuv3_get_typeid_type (struct gdbarch
*gdbarch
)
1044 struct symbol
*typeinfo
;
1045 struct type
*typeinfo_type
;
1047 typeinfo
= lookup_symbol ("std::type_info", NULL
, STRUCT_DOMAIN
,
1049 if (typeinfo
== NULL
)
1051 = (struct type
*) gdbarch_data (gdbarch
, std_type_info_gdbarch_data
);
1053 typeinfo_type
= SYMBOL_TYPE (typeinfo
);
1055 return typeinfo_type
;
1058 /* Implement the 'get_typeid' method. */
1060 static struct value
*
1061 gnuv3_get_typeid (struct value
*value
)
1063 struct type
*typeinfo_type
;
1065 struct gdbarch
*gdbarch
;
1066 struct value
*result
;
1067 std::string type_name
, canonical
;
1069 /* We have to handle values a bit trickily here, to allow this code
1070 to work properly with non_lvalue values that are really just
1072 if (value_lval_const (value
) == lval_memory
)
1073 value
= coerce_ref (value
);
1075 type
= check_typedef (value_type (value
));
1077 /* In the non_lvalue case, a reference might have slipped through
1079 if (TYPE_CODE (type
) == TYPE_CODE_REF
)
1080 type
= check_typedef (TYPE_TARGET_TYPE (type
));
1082 /* Ignore top-level cv-qualifiers. */
1083 type
= make_cv_type (0, 0, type
, NULL
);
1084 gdbarch
= get_type_arch (type
);
1086 type_name
= type_to_string (type
);
1087 if (type_name
.empty ())
1088 error (_("cannot find typeinfo for unnamed type"));
1090 /* We need to canonicalize the type name here, because we do lookups
1091 using the demangled name, and so we must match the format it
1092 uses. E.g., GDB tends to use "const char *" as a type name, but
1093 the demangler uses "char const *". */
1094 canonical
= cp_canonicalize_string (type_name
.c_str ());
1095 if (!canonical
.empty ())
1096 type_name
= canonical
;
1098 typeinfo_type
= gnuv3_get_typeid_type (gdbarch
);
1100 /* We check for lval_memory because in the "typeid (type-id)" case,
1101 the type is passed via a not_lval value object. */
1102 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1103 && value_lval_const (value
) == lval_memory
1104 && gnuv3_dynamic_class (type
))
1106 struct value
*vtable
, *typeinfo_value
;
1107 CORE_ADDR address
= value_address (value
) + value_embedded_offset (value
);
1109 vtable
= gnuv3_get_vtable (gdbarch
, type
, address
);
1111 error (_("cannot find typeinfo for object of type '%s'"),
1112 type_name
.c_str ());
1113 typeinfo_value
= value_field (vtable
, vtable_field_type_info
);
1114 result
= value_ind (value_cast (make_pointer_type (typeinfo_type
, NULL
),
1119 std::string sym_name
= std::string ("typeinfo for ") + type_name
;
1120 bound_minimal_symbol minsym
1121 = lookup_minimal_symbol (sym_name
.c_str (), NULL
, NULL
);
1123 if (minsym
.minsym
== NULL
)
1124 error (_("could not find typeinfo symbol for '%s'"), type_name
.c_str ());
1126 result
= value_at_lazy (typeinfo_type
, BMSYMBOL_VALUE_ADDRESS (minsym
));
1132 /* Implement the 'get_typename_from_type_info' method. */
1135 gnuv3_get_typename_from_type_info (struct value
*type_info_ptr
)
1137 struct gdbarch
*gdbarch
= get_type_arch (value_type (type_info_ptr
));
1138 struct bound_minimal_symbol typeinfo_sym
;
1140 const char *symname
;
1141 const char *class_name
;
1144 addr
= value_as_address (type_info_ptr
);
1145 typeinfo_sym
= lookup_minimal_symbol_by_pc (addr
);
1146 if (typeinfo_sym
.minsym
== NULL
)
1147 error (_("could not find minimal symbol for typeinfo address %s"),
1148 paddress (gdbarch
, addr
));
1150 #define TYPEINFO_PREFIX "typeinfo for "
1151 #define TYPEINFO_PREFIX_LEN (sizeof (TYPEINFO_PREFIX) - 1)
1152 symname
= typeinfo_sym
.minsym
->demangled_name ();
1153 if (symname
== NULL
|| strncmp (symname
, TYPEINFO_PREFIX
,
1154 TYPEINFO_PREFIX_LEN
))
1155 error (_("typeinfo symbol '%s' has unexpected name"),
1156 typeinfo_sym
.minsym
->linkage_name ());
1157 class_name
= symname
+ TYPEINFO_PREFIX_LEN
;
1159 /* Strip off @plt and version suffixes. */
1160 atsign
= strchr (class_name
, '@');
1162 return std::string (class_name
, atsign
- class_name
);
1166 /* Implement the 'get_type_from_type_info' method. */
1168 static struct type
*
1169 gnuv3_get_type_from_type_info (struct value
*type_info_ptr
)
1171 /* We have to parse the type name, since in general there is not a
1172 symbol for a type. This is somewhat bogus since there may be a
1173 mis-parse. Another approach might be to re-use the demangler's
1174 internal form to reconstruct the type somehow. */
1175 std::string type_name
= gnuv3_get_typename_from_type_info (type_info_ptr
);
1176 expression_up
expr (parse_expression (type_name
.c_str ()));
1177 struct value
*type_val
= evaluate_type (expr
.get ());
1178 return value_type (type_val
);
1181 /* Determine if we are currently in a C++ thunk. If so, get the address
1182 of the routine we are thunking to and continue to there instead. */
1185 gnuv3_skip_trampoline (struct frame_info
*frame
, CORE_ADDR stop_pc
)
1187 CORE_ADDR real_stop_pc
, method_stop_pc
, func_addr
;
1188 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1189 struct bound_minimal_symbol thunk_sym
, fn_sym
;
1190 struct obj_section
*section
;
1191 const char *thunk_name
, *fn_name
;
1193 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
1194 if (real_stop_pc
== 0)
1195 real_stop_pc
= stop_pc
;
1197 /* Find the linker symbol for this potential thunk. */
1198 thunk_sym
= lookup_minimal_symbol_by_pc (real_stop_pc
);
1199 section
= find_pc_section (real_stop_pc
);
1200 if (thunk_sym
.minsym
== NULL
|| section
== NULL
)
1203 /* The symbol's demangled name should be something like "virtual
1204 thunk to FUNCTION", where FUNCTION is the name of the function
1205 being thunked to. */
1206 thunk_name
= thunk_sym
.minsym
->demangled_name ();
1207 if (thunk_name
== NULL
|| strstr (thunk_name
, " thunk to ") == NULL
)
1210 fn_name
= strstr (thunk_name
, " thunk to ") + strlen (" thunk to ");
1211 fn_sym
= lookup_minimal_symbol (fn_name
, NULL
, section
->objfile
);
1212 if (fn_sym
.minsym
== NULL
)
1215 method_stop_pc
= BMSYMBOL_VALUE_ADDRESS (fn_sym
);
1217 /* Some targets have minimal symbols pointing to function descriptors
1218 (powerpc 64 for example). Make sure to retrieve the address
1219 of the real function from the function descriptor before passing on
1220 the address to other layers of GDB. */
1221 func_addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, method_stop_pc
,
1222 current_top_target ());
1224 method_stop_pc
= func_addr
;
1226 real_stop_pc
= gdbarch_skip_trampoline_code
1227 (gdbarch
, frame
, method_stop_pc
);
1228 if (real_stop_pc
== 0)
1229 real_stop_pc
= method_stop_pc
;
1231 return real_stop_pc
;
1234 /* A member function is in one these states. */
1236 enum definition_style
1238 DOES_NOT_EXIST_IN_SOURCE
,
1245 /* Return how the given field is defined. */
1247 static definition_style
1248 get_def_style (struct fn_field
*fn
, int fieldelem
)
1250 if (TYPE_FN_FIELD_DELETED (fn
, fieldelem
))
1253 if (TYPE_FN_FIELD_ARTIFICIAL (fn
, fieldelem
))
1254 return DOES_NOT_EXIST_IN_SOURCE
;
1256 switch (TYPE_FN_FIELD_DEFAULTED (fn
, fieldelem
))
1258 case DW_DEFAULTED_no
:
1260 case DW_DEFAULTED_in_class
:
1261 return DEFAULTED_INSIDE
;
1262 case DW_DEFAULTED_out_of_class
:
1263 return DEFAULTED_OUTSIDE
;
1271 /* Helper functions to determine whether the given definition style
1272 denotes that the definition is user-provided or implicit.
1273 Being defaulted outside the class decl counts as an explicit
1274 user-definition, while being defaulted inside is implicit. */
1277 is_user_provided_def (definition_style def
)
1279 return def
== EXPLICIT
|| def
== DEFAULTED_OUTSIDE
;
1283 is_implicit_def (definition_style def
)
1285 return def
== DOES_NOT_EXIST_IN_SOURCE
|| def
== DEFAULTED_INSIDE
;
1288 /* Helper function to decide if METHOD_TYPE is a copy/move
1289 constructor type for CLASS_TYPE. EXPECTED is the expected
1290 type code for the "right-hand-side" argument.
1291 This function is supposed to be used by the IS_COPY_CONSTRUCTOR_TYPE
1292 and IS_MOVE_CONSTRUCTOR_TYPE functions below. Normally, you should
1293 not need to call this directly. */
1296 is_copy_or_move_constructor_type (struct type
*class_type
,
1297 struct type
*method_type
,
1300 /* The method should take at least two arguments... */
1301 if (TYPE_NFIELDS (method_type
) < 2)
1304 /* ...and the second argument should be the same as the class
1305 type, with the expected type code... */
1306 struct type
*arg_type
= TYPE_FIELD_TYPE (method_type
, 1);
1308 if (TYPE_CODE (arg_type
) != expected
)
1311 struct type
*target
= check_typedef (TYPE_TARGET_TYPE (arg_type
));
1312 if (!(class_types_same_p (target
, class_type
)))
1315 /* ...and if any of the remaining arguments don't have a default value
1316 then this is not a copy or move constructor, but just a
1318 for (int i
= 2; i
< TYPE_NFIELDS (method_type
); i
++)
1320 arg_type
= TYPE_FIELD_TYPE (method_type
, i
);
1321 /* FIXME aktemur/2019-10-31: As of this date, neither
1322 clang++-7.0.0 nor g++-8.2.0 produce a DW_AT_default_value
1323 attribute. GDB is also not set to read this attribute, yet.
1324 Hence, we immediately return false if there are more than
1327 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42959
1335 /* Return true if METHOD_TYPE is a copy ctor type for CLASS_TYPE. */
1338 is_copy_constructor_type (struct type
*class_type
,
1339 struct type
*method_type
)
1341 return is_copy_or_move_constructor_type (class_type
, method_type
,
1345 /* Return true if METHOD_TYPE is a move ctor type for CLASS_TYPE. */
1348 is_move_constructor_type (struct type
*class_type
,
1349 struct type
*method_type
)
1351 return is_copy_or_move_constructor_type (class_type
, method_type
,
1352 TYPE_CODE_RVALUE_REF
);
1355 /* Return pass-by-reference information for the given TYPE.
1357 The rule in the v3 ABI document comes from section 3.1.1. If the
1358 type has a non-trivial copy constructor or destructor, then the
1359 caller must make a copy (by calling the copy constructor if there
1360 is one or perform the copy itself otherwise), pass the address of
1361 the copy, and then destroy the temporary (if necessary).
1363 For return values with non-trivial copy/move constructors or
1364 destructors, space will be allocated in the caller, and a pointer
1365 will be passed as the first argument (preceding "this").
1367 We don't have a bulletproof mechanism for determining whether a
1368 constructor or destructor is trivial. For GCC and DWARF5 debug
1369 information, we can check the calling_convention attribute,
1370 the 'artificial' flag, the 'defaulted' attribute, and the
1371 'deleted' attribute. */
1373 static struct language_pass_by_ref_info
1374 gnuv3_pass_by_reference (struct type
*type
)
1376 int fieldnum
, fieldelem
;
1378 type
= check_typedef (type
);
1380 /* Start with the default values. */
1381 struct language_pass_by_ref_info info
1382 = default_pass_by_reference (type
);
1384 bool has_cc_attr
= false;
1385 bool is_pass_by_value
= false;
1386 bool is_dynamic
= false;
1387 definition_style cctor_def
= DOES_NOT_EXIST_IN_SOURCE
;
1388 definition_style dtor_def
= DOES_NOT_EXIST_IN_SOURCE
;
1389 definition_style mctor_def
= DOES_NOT_EXIST_IN_SOURCE
;
1391 /* We're only interested in things that can have methods. */
1392 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
1393 && TYPE_CODE (type
) != TYPE_CODE_UNION
)
1396 /* The compiler may have emitted the calling convention attribute.
1397 Note: GCC does not produce this attribute as of version 9.2.1.
1398 Bug link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92418 */
1399 if (TYPE_CPLUS_CALLING_CONVENTION (type
) == DW_CC_pass_by_value
)
1402 is_pass_by_value
= true;
1403 /* Do not return immediately. We have to find out if this type
1404 is copy_constructible and destructible. */
1407 if (TYPE_CPLUS_CALLING_CONVENTION (type
) == DW_CC_pass_by_reference
)
1410 is_pass_by_value
= false;
1413 /* A dynamic class has a non-trivial copy constructor.
1414 See c++98 section 12.8 Copying class objects [class.copy]. */
1415 if (gnuv3_dynamic_class (type
))
1418 for (fieldnum
= 0; fieldnum
< TYPE_NFN_FIELDS (type
); fieldnum
++)
1419 for (fieldelem
= 0; fieldelem
< TYPE_FN_FIELDLIST_LENGTH (type
, fieldnum
);
1422 struct fn_field
*fn
= TYPE_FN_FIELDLIST1 (type
, fieldnum
);
1423 const char *name
= TYPE_FN_FIELDLIST_NAME (type
, fieldnum
);
1424 struct type
*fieldtype
= TYPE_FN_FIELD_TYPE (fn
, fieldelem
);
1428 /* We've found a destructor.
1429 There should be at most one dtor definition. */
1430 gdb_assert (dtor_def
== DOES_NOT_EXIST_IN_SOURCE
);
1431 dtor_def
= get_def_style (fn
, fieldelem
);
1433 else if (is_constructor_name (TYPE_FN_FIELD_PHYSNAME (fn
, fieldelem
))
1434 || TYPE_FN_FIELD_CONSTRUCTOR (fn
, fieldelem
))
1436 /* FIXME drow/2007-09-23: We could do this using the name of
1437 the method and the name of the class instead of dealing
1438 with the mangled name. We don't have a convenient function
1439 to strip off both leading scope qualifiers and trailing
1440 template arguments yet. */
1441 if (is_copy_constructor_type (type
, fieldtype
))
1443 /* There may be more than one cctors. E.g.: one that
1444 take a const parameter and another that takes a
1445 non-const parameter. Such as:
1452 It is sufficient for the type to be non-trivial
1453 even only one of the cctors is explicit.
1454 Therefore, update the cctor_def value in the
1455 implicit -> explicit direction, not backwards. */
1457 if (is_implicit_def (cctor_def
))
1458 cctor_def
= get_def_style (fn
, fieldelem
);
1460 else if (is_move_constructor_type (type
, fieldtype
))
1462 /* Again, there may be multiple move ctors. Update the
1463 mctor_def value if we found an explicit def and the
1464 existing one is not explicit. Otherwise retain the
1466 if (is_implicit_def (mctor_def
))
1467 mctor_def
= get_def_style (fn
, fieldelem
);
1472 bool cctor_implicitly_deleted
1473 = (mctor_def
!= DOES_NOT_EXIST_IN_SOURCE
1474 && cctor_def
== DOES_NOT_EXIST_IN_SOURCE
);
1476 bool cctor_explicitly_deleted
= (cctor_def
== DELETED
);
1478 if (cctor_implicitly_deleted
|| cctor_explicitly_deleted
)
1479 info
.copy_constructible
= false;
1481 if (dtor_def
== DELETED
)
1482 info
.destructible
= false;
1484 info
.trivially_destructible
= is_implicit_def (dtor_def
);
1486 info
.trivially_copy_constructible
1487 = (is_implicit_def (cctor_def
)
1490 info
.trivially_copyable
1491 = (info
.trivially_copy_constructible
1492 && info
.trivially_destructible
1493 && !is_user_provided_def (mctor_def
));
1495 /* Even if all the constructors and destructors were artificial, one
1496 of them may have invoked a non-artificial constructor or
1497 destructor in a base class. If any base class needs to be passed
1498 by reference, so does this class. Similarly for members, which
1499 are constructed whenever this class is. We do not need to worry
1500 about recursive loops here, since we are only looking at members
1501 of complete class type. Also ignore any static members. */
1502 for (fieldnum
= 0; fieldnum
< TYPE_NFIELDS (type
); fieldnum
++)
1503 if (!field_is_static (&TYPE_FIELD (type
, fieldnum
)))
1505 struct type
*field_type
= TYPE_FIELD_TYPE (type
, fieldnum
);
1507 /* For arrays, make the decision based on the element type. */
1508 if (TYPE_CODE (field_type
) == TYPE_CODE_ARRAY
)
1509 field_type
= check_typedef (TYPE_TARGET_TYPE (field_type
));
1511 struct language_pass_by_ref_info field_info
1512 = gnuv3_pass_by_reference (field_type
);
1514 if (!field_info
.copy_constructible
)
1515 info
.copy_constructible
= false;
1516 if (!field_info
.destructible
)
1517 info
.destructible
= false;
1518 if (!field_info
.trivially_copyable
)
1519 info
.trivially_copyable
= false;
1520 if (!field_info
.trivially_copy_constructible
)
1521 info
.trivially_copy_constructible
= false;
1522 if (!field_info
.trivially_destructible
)
1523 info
.trivially_destructible
= false;
1526 /* Consistency check. */
1527 if (has_cc_attr
&& info
.trivially_copyable
!= is_pass_by_value
)
1529 /* DWARF CC attribute is not the same as the inferred value;
1530 use the DWARF attribute. */
1531 info
.trivially_copyable
= is_pass_by_value
;
1538 init_gnuv3_ops (void)
1540 vtable_type_gdbarch_data
1541 = gdbarch_data_register_post_init (build_gdb_vtable_type
);
1542 std_type_info_gdbarch_data
1543 = gdbarch_data_register_post_init (build_std_type_info_type
);
1545 gnu_v3_abi_ops
.shortname
= "gnu-v3";
1546 gnu_v3_abi_ops
.longname
= "GNU G++ Version 3 ABI";
1547 gnu_v3_abi_ops
.doc
= "G++ Version 3 ABI";
1548 gnu_v3_abi_ops
.is_destructor_name
=
1549 (enum dtor_kinds (*) (const char *))is_gnu_v3_mangled_dtor
;
1550 gnu_v3_abi_ops
.is_constructor_name
=
1551 (enum ctor_kinds (*) (const char *))is_gnu_v3_mangled_ctor
;
1552 gnu_v3_abi_ops
.is_vtable_name
= gnuv3_is_vtable_name
;
1553 gnu_v3_abi_ops
.is_operator_name
= gnuv3_is_operator_name
;
1554 gnu_v3_abi_ops
.rtti_type
= gnuv3_rtti_type
;
1555 gnu_v3_abi_ops
.virtual_fn_field
= gnuv3_virtual_fn_field
;
1556 gnu_v3_abi_ops
.baseclass_offset
= gnuv3_baseclass_offset
;
1557 gnu_v3_abi_ops
.print_method_ptr
= gnuv3_print_method_ptr
;
1558 gnu_v3_abi_ops
.method_ptr_size
= gnuv3_method_ptr_size
;
1559 gnu_v3_abi_ops
.make_method_ptr
= gnuv3_make_method_ptr
;
1560 gnu_v3_abi_ops
.method_ptr_to_value
= gnuv3_method_ptr_to_value
;
1561 gnu_v3_abi_ops
.print_vtable
= gnuv3_print_vtable
;
1562 gnu_v3_abi_ops
.get_typeid
= gnuv3_get_typeid
;
1563 gnu_v3_abi_ops
.get_typeid_type
= gnuv3_get_typeid_type
;
1564 gnu_v3_abi_ops
.get_type_from_type_info
= gnuv3_get_type_from_type_info
;
1565 gnu_v3_abi_ops
.get_typename_from_type_info
1566 = gnuv3_get_typename_from_type_info
;
1567 gnu_v3_abi_ops
.skip_trampoline
= gnuv3_skip_trampoline
;
1568 gnu_v3_abi_ops
.pass_by_reference
= gnuv3_pass_by_reference
;
1572 _initialize_gnu_v3_abi (void)
1576 register_cp_abi (&gnu_v3_abi_ops
);
1577 set_cp_abi_as_auto_default (gnu_v3_abi_ops
.shortname
);