Add initial type alignment support

This adds some basic type alignment support to gdb.  It changes struct
type to store the alignment, and updates dwarf2read.c to handle
DW_AT_alignment.  It also adds a new gdbarch method and updates
i386-tdep.c.

None of this new functionality is used anywhere yet, so tests will
wait until the next patch.

2018-04-30  Tom Tromey  <tom@tromey.com>

	* i386-tdep.c (i386_type_align): New function.
	(i386_gdbarch_init): Update.
	* gdbarch.sh (type_align): New method.
	* gdbarch.c, gdbarch.h: Rebuild.
	* arch-utils.h (default_type_align): Declare.
	* arch-utils.c (default_type_align): New function.
	* gdbtypes.h (TYPE_ALIGN_BITS): New define.
	(struct type) <align_log2>: New field.
	<instance_flags>: Now a bitfield.
	(TYPE_RAW_ALIGN): New macro.
	(type_align, type_raw_align, set_type_align): Declare.
	* gdbtypes.c (type_align, type_raw_align, set_type_align): New
	functions.
	* dwarf2read.c (quirk_rust_enum): Set type alignment.
	(get_alignment, maybe_set_alignment): New functions.
	(read_structure_type, read_enumeration_type, read_array_type)
	(read_set_type, read_tag_pointer_type, read_tag_reference_type)
	(read_subrange_type, read_base_type): Set type alignment.
This commit is contained in:
Tom Tromey
2018-04-20 11:50:09 -06:00
parent fe944acf8f
commit 2b4424c35b
10 changed files with 359 additions and 5 deletions

View File

@@ -802,6 +802,10 @@ struct main_type
struct dynamic_prop_list *dyn_prop_list;
};
/* * Number of bits allocated for alignment. */
#define TYPE_ALIGN_BITS 8
/* * A ``struct type'' describes a particular instance of a type, with
some particular qualification. */
@@ -831,6 +835,14 @@ struct type
struct type *chain;
/* * The alignment for this type. Zero means that the alignment was
not specified in the debug info. Note that this is stored in a
funny way: as the log base 2 (plus 1) of the alignment; so a
value of 1 means the alignment is 1, and a value of 9 means the
alignment is 256. */
unsigned align_log2 : TYPE_ALIGN_BITS;
/* * Flags specific to this instance of the type, indicating where
on the ring we are.
@@ -841,7 +853,7 @@ struct type
instance flags are completely inherited from the target type. No
qualifiers can be cleared by the typedef. See also
check_typedef. */
int instance_flags;
unsigned instance_flags : 9;
/* * Length of storage for a value of this type. The value is the
expression in host bytes of what sizeof(type) would return. This
@@ -1292,6 +1304,26 @@ extern void allocate_gnat_aux_type (struct type *);
so you only have to call check_typedef once. Since allocate_value
calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe. */
#define TYPE_LENGTH(thistype) (thistype)->length
/* * Return the alignment of the type in target addressable memory
units, or 0 if no alignment was specified. */
#define TYPE_RAW_ALIGN(thistype) type_raw_align (thistype)
/* * Return the alignment of the type in target addressable memory
units, or 0 if no alignment was specified. */
extern unsigned type_raw_align (struct type *);
/* * Return the alignment of the type in target addressable memory
units. Return 0 if the alignment cannot be determined; but note
that this makes an effort to compute the alignment even it it was
not specified in the debug info. */
extern unsigned type_align (struct type *);
/* * Set the alignment of the type. The alignment must be a power of
2. Returns false if the given value does not fit in the available
space in struct type. */
extern bool set_type_align (struct type *, ULONGEST);
/* * Note that TYPE_CODE can be TYPE_CODE_TYPEDEF, so if you want the real
type, you need to do TYPE_CODE (check_type (this_type)). */
#define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code