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

@ -353,6 +353,7 @@ struct gdbarch
gdbarch_addressable_memory_unit_size_ftype *addressable_memory_unit_size;
char ** disassembler_options;
const disasm_options_t * valid_disassembler_options;
gdbarch_type_align_ftype *type_align;
};
/* Create a new ``struct gdbarch'' based on information provided by
@ -465,6 +466,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
gdbarch->gcc_target_options = default_gcc_target_options;
gdbarch->gnu_triplet_regexp = default_gnu_triplet_regexp;
gdbarch->addressable_memory_unit_size = default_addressable_memory_unit_size;
gdbarch->type_align = default_type_align;
/* gdbarch_alloc() */
return gdbarch;
@ -716,6 +718,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of addressable_memory_unit_size, invalid_p == 0 */
/* Skip verify of disassembler_options, invalid_p == 0 */
/* Skip verify of valid_disassembler_options, invalid_p == 0 */
/* Skip verify of type_align, invalid_p == 0 */
if (!log.empty ())
internal_error (__FILE__, __LINE__,
_("verify_gdbarch: the following are invalid ...%s"),
@ -1441,6 +1444,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
fprintf_unfiltered (file,
"gdbarch_dump: target_desc = %s\n",
host_address_to_string (gdbarch->target_desc));
fprintf_unfiltered (file,
"gdbarch_dump: type_align = <%s>\n",
host_address_to_string (gdbarch->type_align));
fprintf_unfiltered (file,
"gdbarch_dump: gdbarch_unwind_pc_p() = %d\n",
gdbarch_unwind_pc_p (gdbarch));
@ -5100,6 +5106,23 @@ set_gdbarch_valid_disassembler_options (struct gdbarch *gdbarch,
gdbarch->valid_disassembler_options = valid_disassembler_options;
}
ULONGEST
gdbarch_type_align (struct gdbarch *gdbarch, struct type *type)
{
gdb_assert (gdbarch != NULL);
gdb_assert (gdbarch->type_align != NULL);
if (gdbarch_debug >= 2)
fprintf_unfiltered (gdb_stdlog, "gdbarch_type_align called\n");
return gdbarch->type_align (gdbarch, type);
}
void
set_gdbarch_type_align (struct gdbarch *gdbarch,
gdbarch_type_align_ftype type_align)
{
gdbarch->type_align = type_align;
}
/* Keep a registry of per-architecture data-pointers required by GDB
modules. */