Move vptr_{fieldno,basetype} out of main_type, and update everything accordingly.

Every type has to pay the price in memory usage for their presence.
The proper place for them is in the type_specific field which exists
for this purpose.

gdb/ChangeLog:

	* dwarf2read.c (process_structure_scope): Update setting of
	TYPE_VPTR_BASETYPE, TYPE_VPTR_FIELDNO.
	* gdbtypes.c (internal_type_vptr_fieldno): New function.
	(set_type_vptr_fieldno): New function.
	(internal_type_vptr_basetype): New function.
	(set_type_vptr_basetype): New function.
	(get_vptr_fieldno): Update setting of TYPE_VPTR_FIELDNO,
	TYPE_VPTR_BASETYPE.
	(allocate_cplus_struct_type): Initialize vptr_fieldno.
	(recursive_dump_type): Printing of vptr_fieldno, vptr_basetype ...
	(print_cplus_stuff): ... moved here.
	(copy_type_recursive): Don't copy TYPE_VPTR_BASETYPE.
	* gdbtypes.h (struct main_type): Members vptr_fieldno, vptr_basetype
	moved to ...
	(struct cplus_struct_type): ... here.  All uses updated.
	(TYPE_VPTR_FIELDNO, TYPE_VPTR_BASETYPE): Rewrite.
	(internal_type_vptr_fieldno, set_type_vptr_fieldno): Declare.
	(internal_type_vptr_basetype, set_type_vptr_basetype): Declare.
	* stabsread.c (read_tilde_fields): Update setting of
	TYPE_VPTR_FIELDNO, TYPE_VPTR_BASETYPE.

gdb/testsuite/ChangeLog:

	* gdb.base/maint.exp <maint print type argc>: Update expected output.
This commit is contained in:
Doug Evans 2015-01-31 21:40:57 -08:00
parent 09e2d7c720
commit ae6ae97502
9 changed files with 126 additions and 53 deletions

View file

@ -1,3 +1,26 @@
2015-01-31 Doug Evans <xdje42@gmail.com>
* dwarf2read.c (process_structure_scope): Update setting of
TYPE_VPTR_BASETYPE, TYPE_VPTR_FIELDNO.
* gdbtypes.c (internal_type_vptr_fieldno): New function.
(set_type_vptr_fieldno): New function.
(internal_type_vptr_basetype): New function.
(set_type_vptr_basetype): New function.
(get_vptr_fieldno): Update setting of TYPE_VPTR_FIELDNO,
TYPE_VPTR_BASETYPE.
(allocate_cplus_struct_type): Initialize vptr_fieldno.
(recursive_dump_type): Printing of vptr_fieldno, vptr_basetype ...
(print_cplus_stuff): ... moved here.
(copy_type_recursive): Don't copy TYPE_VPTR_BASETYPE.
* gdbtypes.h (struct main_type): Members vptr_fieldno, vptr_basetype
moved to ...
(struct cplus_struct_type): ... here. All uses updated.
(TYPE_VPTR_FIELDNO, TYPE_VPTR_BASETYPE): Rewrite.
(internal_type_vptr_fieldno, set_type_vptr_fieldno): Declare.
(internal_type_vptr_basetype, set_type_vptr_basetype): Declare.
* stabsread.c (read_tilde_fields): Update setting of
TYPE_VPTR_FIELDNO, TYPE_VPTR_BASETYPE.
2015-01-31 Doug Evans <xdje42@gmail.com> 2015-01-31 Doug Evans <xdje42@gmail.com>
* cp-valprint.c (cp_find_class_member): Rename parameter domain_p * cp-valprint.c (cp_find_class_member): Rename parameter domain_p

View file

@ -13255,7 +13255,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
{ {
struct type *t = die_containing_type (die, cu); struct type *t = die_containing_type (die, cu);
TYPE_VPTR_BASETYPE (type) = t; set_type_vptr_basetype (type, t);
if (type == t) if (type == t)
{ {
int i; int i;
@ -13269,7 +13269,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
if (is_vtable_name (fieldname, cu)) if (is_vtable_name (fieldname, cu))
{ {
TYPE_VPTR_FIELDNO (type) = i; set_type_vptr_fieldno (type, i);
break; break;
} }
} }
@ -13284,7 +13284,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
} }
else else
{ {
TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); set_type_vptr_fieldno (type, TYPE_VPTR_FIELDNO (t));
} }
} }
else if (cu->producer else if (cu->producer
@ -13303,8 +13303,8 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
{ {
if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
{ {
TYPE_VPTR_FIELDNO (type) = i; set_type_vptr_fieldno (type, i);
TYPE_VPTR_BASETYPE (type) = type; set_type_vptr_basetype (type, type);
break; break;
} }
} }

View file

@ -664,7 +664,6 @@ make_params (int num_types, struct type **param_types)
TYPE_MAIN_TYPE (type) = XCNEW (struct main_type); TYPE_MAIN_TYPE (type) = XCNEW (struct main_type);
TYPE_LENGTH (type) = 1; TYPE_LENGTH (type) = 1;
TYPE_CODE (type) = TYPE_CODE_METHOD; TYPE_CODE (type) = TYPE_CODE_METHOD;
TYPE_VPTR_FIELDNO (type) = -1;
TYPE_CHAIN (type) = type; TYPE_CHAIN (type) = type;
if (num_types > 0) if (num_types > 0)
{ {

View file

@ -226,7 +226,6 @@ class StructMainTypePrettyPrinter:
fields.append("flags = [%s]" % self.flags_to_string()) fields.append("flags = [%s]" % self.flags_to_string())
fields.append("owner = %s" % self.owner_to_string()) fields.append("owner = %s" % self.owner_to_string())
fields.append("target_type = %s" % self.val['target_type']) fields.append("target_type = %s" % self.val['target_type'])
fields.append("vptr_basetype = %s" % self.val['vptr_basetype'])
if self.val['nfields'] > 0: if self.val['nfields'] > 0:
for fieldno in range(self.val['nfields']): for fieldno in range(self.val['nfields']):
fields.append(self.struct_field_img(fieldno)) fields.append(self.struct_field_img(fieldno))

View file

@ -180,7 +180,6 @@ alloc_type (struct objfile *objfile)
/* Initialize the fields that might not be zero. */ /* Initialize the fields that might not be zero. */
TYPE_CODE (type) = TYPE_CODE_UNDEF; TYPE_CODE (type) = TYPE_CODE_UNDEF;
TYPE_VPTR_FIELDNO (type) = -1;
TYPE_CHAIN (type) = type; /* Chain back to itself. */ TYPE_CHAIN (type) = type; /* Chain back to itself. */
return type; return type;
@ -208,7 +207,6 @@ alloc_type_arch (struct gdbarch *gdbarch)
/* Initialize the fields that might not be zero. */ /* Initialize the fields that might not be zero. */
TYPE_CODE (type) = TYPE_CODE_UNDEF; TYPE_CODE (type) = TYPE_CODE_UNDEF;
TYPE_VPTR_FIELDNO (type) = -1;
TYPE_CHAIN (type) = type; /* Chain back to itself. */ TYPE_CHAIN (type) = type; /* Chain back to itself. */
return type; return type;
@ -1054,7 +1052,6 @@ create_array_type_with_stride (struct type *result_type,
TYPE_FIELDS (result_type) = TYPE_FIELDS (result_type) =
(struct field *) TYPE_ZALLOC (result_type, sizeof (struct field)); (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
TYPE_INDEX_TYPE (result_type) = range_type; TYPE_INDEX_TYPE (result_type) = range_type;
TYPE_VPTR_FIELDNO (result_type) = -1;
if (bit_stride > 0) if (bit_stride > 0)
TYPE_FIELD_BITSIZE (result_type, 0) = bit_stride; TYPE_FIELD_BITSIZE (result_type, 0) = bit_stride;
@ -1614,6 +1611,59 @@ get_signed_type_minmax (struct type *type, LONGEST *min, LONGEST *max)
*max = ((ULONGEST) 1 << (n - 1)) - 1; *max = ((ULONGEST) 1 << (n - 1)) - 1;
} }
/* Internal routine called by TYPE_VPTR_FIELDNO to return the value of
cplus_stuff.vptr_fieldno.
cplus_stuff is initialized to cplus_struct_default which does not
set vptr_fieldno to -1 for portability reasons (IWBN to use C99
designated initializers). We cope with that here. */
int
internal_type_vptr_fieldno (struct type *type)
{
gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
|| TYPE_CODE (type) == TYPE_CODE_UNION);
if (!HAVE_CPLUS_STRUCT (type))
return -1;
return TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_fieldno;
}
/* Set the value of cplus_stuff.vptr_fieldno. */
void
set_type_vptr_fieldno (struct type *type, int fieldno)
{
gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
|| TYPE_CODE (type) == TYPE_CODE_UNION);
if (!HAVE_CPLUS_STRUCT (type))
ALLOCATE_CPLUS_STRUCT_TYPE (type);
TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_fieldno = fieldno;
}
/* Internal routine called by TYPE_VPTR_BASETYPE to return the value of
cplus_stuff.vptr_basetype. */
struct type *
internal_type_vptr_basetype (struct type *type)
{
gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
|| TYPE_CODE (type) == TYPE_CODE_UNION);
gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_CPLUS_STUFF);
return TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_basetype;
}
/* Set the value of cplus_stuff.vptr_basetype. */
void
set_type_vptr_basetype (struct type *type, struct type *basetype)
{
gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
|| TYPE_CODE (type) == TYPE_CODE_UNION);
if (!HAVE_CPLUS_STRUCT (type))
ALLOCATE_CPLUS_STRUCT_TYPE (type);
TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_basetype = basetype;
}
/* Lookup the vptr basetype/fieldno values for TYPE. /* Lookup the vptr basetype/fieldno values for TYPE.
If found store vptr_basetype in *BASETYPEP if non-NULL, and return If found store vptr_basetype in *BASETYPEP if non-NULL, and return
vptr_fieldno. Also, if found and basetype is from the same objfile, vptr_fieldno. Also, if found and basetype is from the same objfile,
@ -1650,8 +1700,8 @@ get_vptr_fieldno (struct type *type, struct type **basetypep)
it, it may have a different lifetime. PR 2384 */ it, it may have a different lifetime. PR 2384 */
if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype)) if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
{ {
TYPE_VPTR_FIELDNO (type) = fieldno; set_type_vptr_fieldno (type, fieldno);
TYPE_VPTR_BASETYPE (type) = basetype; set_type_vptr_basetype (type, basetype);
} }
if (basetypep) if (basetypep)
*basetypep = basetype; *basetypep = basetype;
@ -2433,6 +2483,7 @@ allocate_cplus_struct_type (struct type *type)
TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
TYPE_ALLOC (type, sizeof (struct cplus_struct_type)); TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
*(TYPE_RAW_CPLUS_SPECIFIC (type)) = cplus_struct_default; *(TYPE_RAW_CPLUS_SPECIFIC (type)) = cplus_struct_default;
set_type_vptr_fieldno (type, -1);
} }
const struct gnat_aux_type gnat_aux_default = const struct gnat_aux_type gnat_aux_default =
@ -3712,6 +3763,13 @@ dump_fn_fieldlists (struct type *type, int spaces)
static void static void
print_cplus_stuff (struct type *type, int spaces) print_cplus_stuff (struct type *type, int spaces)
{ {
printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
printfi_filtered (spaces, "vptr_basetype ");
gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
puts_filtered ("\n");
if (TYPE_VPTR_BASETYPE (type) != NULL)
recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
printfi_filtered (spaces, "n_baseclasses %d\n", printfi_filtered (spaces, "n_baseclasses %d\n",
TYPE_N_BASECLASSES (type)); TYPE_N_BASECLASSES (type));
printfi_filtered (spaces, "nfn_fields %d\n", printfi_filtered (spaces, "nfn_fields %d\n",
@ -4044,15 +4102,6 @@ recursive_dump_type (struct type *type, int spaces)
TYPE_HIGH_BOUND_UNDEFINED (type) TYPE_HIGH_BOUND_UNDEFINED (type)
? " (undefined)" : ""); ? " (undefined)" : "");
} }
printfi_filtered (spaces, "vptr_basetype ");
gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
puts_filtered ("\n");
if (TYPE_VPTR_BASETYPE (type) != NULL)
{
recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
}
printfi_filtered (spaces, "vptr_fieldno %d\n",
TYPE_VPTR_FIELDNO (type));
switch (TYPE_SPECIFIC_FIELD (type)) switch (TYPE_SPECIFIC_FIELD (type))
{ {
@ -4268,11 +4317,6 @@ copy_type_recursive (struct objfile *objfile,
copy_type_recursive (objfile, copy_type_recursive (objfile,
TYPE_TARGET_TYPE (type), TYPE_TARGET_TYPE (type),
copied_types); copied_types);
if (TYPE_VPTR_BASETYPE (type))
TYPE_VPTR_BASETYPE (new_type) =
copy_type_recursive (objfile,
TYPE_VPTR_BASETYPE (type),
copied_types);
/* Maybe copy the type_specific bits. /* Maybe copy the type_specific bits.

View file

@ -507,19 +507,6 @@ struct main_type
short nfields; short nfields;
/* * Field number of the virtual function table pointer in
VPTR_BASETYPE. If -1, we were unable to find the virtual
function table pointer in initial symbol reading, and
get_vptr_fieldno should be called to find it if possible.
get_vptr_fieldno will update this field if possible. Otherwise
the value is left at -1.
Unused if this type does not have virtual functions.
This field appears at this location because it packs nicely here. */
short vptr_fieldno;
/* * Name of this type, or NULL if none. /* * Name of this type, or NULL if none.
This is used for printing only, except by poorly designed C++ This is used for printing only, except by poorly designed C++
@ -676,14 +663,6 @@ struct main_type
} flds_bnds; } flds_bnds;
/* * For types with virtual functions (TYPE_CODE_STRUCT),
VPTR_BASETYPE is the base class which defined the virtual
function table pointer.
Unused otherwise. */
struct type *vptr_basetype;
/* * Slot to point to additional language-specific fields of this /* * Slot to point to additional language-specific fields of this
type. */ type. */
@ -806,6 +785,22 @@ struct cplus_struct_type
short n_baseclasses; short n_baseclasses;
/* * Field number of the virtual function table pointer in VPTR_BASETYPE.
All access to this field must be through TYPE_VPTR_FIELDNO as one
thing it does is check whether the field has been initialized.
Initially TYPE_RAW_CPLUS_SPECIFIC has the value of cplus_struct_default,
which for portability reasons doesn't initialize this field.
TYPE_VPTR_FIELDNO returns -1 for this case.
If -1, we were unable to find the virtual function table pointer in
initial symbol reading, and get_vptr_fieldno should be called to find
it if possible. get_vptr_fieldno will update this field if possible.
Otherwise the value is left at -1.
Unused if this type does not have virtual functions. */
short vptr_fieldno;
/* * Number of methods with unique names. All overloaded methods /* * Number of methods with unique names. All overloaded methods
with the same name count only once. */ with the same name count only once. */
@ -827,6 +822,10 @@ struct cplus_struct_type
unsigned int is_java : 1; unsigned int is_java : 1;
/* * The base class which defined the virtual function table pointer. */
struct type *vptr_basetype;
/* * For derived classes, the number of base classes is given by /* * For derived classes, the number of base classes is given by
n_baseclasses and virtual_field_bits is a bit vector containing n_baseclasses and virtual_field_bits is a bit vector containing
one bit per base class. If the base class is virtual, the one bit per base class. If the base class is virtual, the
@ -1243,8 +1242,13 @@ extern void allocate_gnat_aux_type (struct type *);
extern struct type *internal_type_self_type (struct type *); extern struct type *internal_type_self_type (struct type *);
extern void set_type_self_type (struct type *, struct type *); extern void set_type_self_type (struct type *, struct type *);
#define TYPE_VPTR_BASETYPE(thistype) TYPE_MAIN_TYPE(thistype)->vptr_basetype extern int internal_type_vptr_fieldno (struct type *);
#define TYPE_VPTR_FIELDNO(thistype) TYPE_MAIN_TYPE(thistype)->vptr_fieldno extern void set_type_vptr_fieldno (struct type *, int);
extern struct type *internal_type_vptr_basetype (struct type *);
extern void set_type_vptr_basetype (struct type *, struct type *);
#define TYPE_VPTR_FIELDNO(thistype) internal_type_vptr_fieldno (thistype)
#define TYPE_VPTR_BASETYPE(thistype) internal_type_vptr_basetype (thistype)
#define TYPE_NFN_FIELDS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->nfn_fields #define TYPE_NFN_FIELDS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->nfn_fields
#define TYPE_SPECIFIC_FIELD(thistype) \ #define TYPE_SPECIFIC_FIELD(thistype) \
TYPE_MAIN_TYPE(thistype)->type_specific_field TYPE_MAIN_TYPE(thistype)->type_specific_field

View file

@ -3267,7 +3267,7 @@ read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
return 0; return 0;
} }
TYPE_VPTR_BASETYPE (type) = t; set_type_vptr_basetype (type, t);
if (type == t) /* Our own class provides vtbl ptr. */ if (type == t) /* Our own class provides vtbl ptr. */
{ {
for (i = TYPE_NFIELDS (t) - 1; for (i = TYPE_NFIELDS (t) - 1;
@ -3279,7 +3279,7 @@ read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2) if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2)
&& is_cplus_marker (name[sizeof (vptr_name) - 2])) && is_cplus_marker (name[sizeof (vptr_name) - 2]))
{ {
TYPE_VPTR_FIELDNO (type) = i; set_type_vptr_fieldno (type, i);
goto gotit; goto gotit;
} }
} }
@ -3292,7 +3292,7 @@ read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
} }
else else
{ {
TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); set_type_vptr_fieldno (type, TYPE_VPTR_FIELDNO (t));
} }
gotit: gotit:

View file

@ -1,3 +1,7 @@
2015-01-31 Doug Evans <xdje42@gmail.com>
* gdb.base/maint.exp <maint print type argc>: Update expected output.
2015-01-31 Gary Benson <gbenson@redhat.com> 2015-01-31 Gary Benson <gbenson@redhat.com>
* gdb.base/completion.exp: Disable completion limiting for * gdb.base/completion.exp: Disable completion limiting for

View file

@ -359,7 +359,7 @@ gdb_expect {
set msg "maint print type" set msg "maint print type"
gdb_test_multiple "maint print type argc" $msg { gdb_test_multiple "maint print type argc" $msg {
-re "type node $hex\r\nname .int. \\($hex\\)\r\ntagname .<NULL>. \\($hex\\)\r\ncode $hex \\(TYPE_CODE_INT\\)\r\nlength \[24\]\r\nobjfile $hex\r\ntarget_type $hex\r\npointer_type $hex\r\nreference_type $hex\r\ntype_chain $hex\r\ninstance_flags $hex\r\nflags\r\nnfields 0 $hex\r\nvptr_basetype $hex\r\nvptr_fieldno -1\r\n$gdb_prompt $" { -re "type node $hex\r\nname .int. \\($hex\\)\r\ntagname .<NULL>. \\($hex\\)\r\ncode $hex \\(TYPE_CODE_INT\\)\r\nlength \[24\]\r\nobjfile $hex\r\ntarget_type $hex\r\npointer_type $hex\r\nreference_type $hex\r\ntype_chain $hex\r\ninstance_flags $hex\r\nflags\r\nnfields 0 $hex\r\n$gdb_prompt $" {
pass $msg pass $msg
} }
} }