diff options
author | Daniel Jacobowitz <drow@false.org> | 2002-01-04 18:20:19 +0000 |
---|---|---|
committer | Daniel Jacobowitz <drow@false.org> | 2002-01-04 18:20:19 +0000 |
commit | 1514d34ee09f4a99b7f87f308c642a8df525255a (patch) | |
tree | fa06aad2b28c05567871a7a4c3febd83d623bd98 /gdb/gnu-v3-abi.c | |
parent | 7f8c9282581cbc3f7e13d8c5a6f20e086bf2ad7b (diff) | |
download | gdb-1514d34ee09f4a99b7f87f308c642a8df525255a.zip gdb-1514d34ee09f4a99b7f87f308c642a8df525255a.tar.gz gdb-1514d34ee09f4a99b7f87f308c642a8df525255a.tar.bz2 |
2002-01-04 Daniel Jacobowitz <drow@mvista.com>
* cp-abi.c: Fix whitespace.
(baseclass_offset): New wrapper function.
* cp-abi.h (baseclass_offset): Add prototype.
(struct cp_abi_ops): Add baseclass_offset pointer.
* valops.c (vb_match): Move to...
* gnu-v2-abi.c (vb_match): here.
* valops.c (baseclass_offset): Move to...
* gnu-v2-abi.c (gnuv2_baseclass_offset): here, and rename.
* gnu-v3-abi.c (gnuv3_baseclass_offset): New function.
* gnu-v2-abi.c (init_gnuv2_ops): Initialize baseclass_offset.
* gnu-v3-abi.c (init_gnuv3_ops): Likewise.
* hpacc-abi.c (init_hpacc_ops): Likewise.
Diffstat (limited to 'gdb/gnu-v3-abi.c')
-rw-r--r-- | gdb/gnu-v3-abi.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c index b9cc0db..93bc995 100644 --- a/gdb/gnu-v3-abi.c +++ b/gdb/gnu-v3-abi.c @@ -339,6 +339,66 @@ gnuv3_virtual_fn_field (struct value **value_p, return vfn; } +/* Compute the offset of the baseclass which is + the INDEXth baseclass of class TYPE, + for value at VALADDR (in host) at ADDRESS (in target). + The result is the offset of the baseclass value relative + to (the address of)(ARG) + OFFSET. + + -1 is returned on error. */ +int +gnuv3_baseclass_offset (struct type *type, int index, char *valaddr, + CORE_ADDR address) +{ + struct type *vtable_type = gdbarch_data (vtable_type_gdbarch_data); + struct type *basetype = TYPE_BASECLASS (type, index); + struct value *full_object, *vbase_object, *orig_object; + struct value *vtable, *orig_typeinfo, *orig_base_info; + struct type *orig_type, *vbasetype; + struct value *offset_val, *vbase_array; + CORE_ADDR vtable_address; + long int cur_base_offset, base_offset; + int to_top; + int baseclasses, i; + + /* If it isn't a virtual base, this is easy. The offset is in the + type definition. */ + if (!BASETYPE_VIA_VIRTUAL (type, index)) + return TYPE_BASECLASS_BITPOS (type, index) / 8; + + /* To access a virtual base, we need to use the vbase offset stored in + our vtable. Recent GCC versions provide this information. If it isn't + available, we could get what we needed from RTTI, or from drawing the + complete inheritance graph based on the debug info. Neither is + worthwhile. */ + cur_base_offset = TYPE_BASECLASS_BITPOS (type, index) / 8; + if (cur_base_offset >= - vtable_address_point_offset ()) + error ("Expected a negative vbase offset (old compiler?)"); + + cur_base_offset = cur_base_offset + vtable_address_point_offset (); + if ((- cur_base_offset) % TYPE_LENGTH (builtin_type_void_data_ptr) != 0) + error ("Misaligned vbase offset."); + cur_base_offset = cur_base_offset + / ((int) TYPE_LENGTH (builtin_type_void_data_ptr)); + + /* We're now looking for the cur_base_offset'th entry (negative index) + in the vcall_and_vbase_offsets array. */ + + orig_object = value_at_lazy (type, address, NULL); + vbasetype = TYPE_VPTR_BASETYPE (VALUE_TYPE (orig_object)); + vbase_object = value_cast (vbasetype, orig_object); + + vtable_address + = value_as_address (value_field (vbase_object, + TYPE_VPTR_FIELDNO (vbasetype))); + vtable = value_at_lazy (vtable_type, + vtable_address - vtable_address_point_offset (), + NULL); + offset_val = value_from_longest(builtin_type_int, cur_base_offset); + vbase_array = value_field (vtable, vtable_field_vcall_and_vbase_offsets); + base_offset = value_as_long (value_subscript (vbase_array, offset_val)); + return base_offset; +} static void init_gnuv3_ops (void) @@ -354,6 +414,7 @@ init_gnuv3_ops (void) gnu_v3_abi_ops.is_operator_name = gnuv3_is_operator_name; gnu_v3_abi_ops.rtti_type = gnuv3_rtti_type; gnu_v3_abi_ops.virtual_fn_field = gnuv3_virtual_fn_field; + gnu_v3_abi_ops.baseclass_offset = gnuv3_baseclass_offset; } |