From 030197b43cd8ccfe6869f798dd39fa27a29c0e01 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Fri, 12 Apr 2019 14:25:32 +0100 Subject: [PATCH] gdb/arm: Use type_align instead of arm_type_align Replaces use of arm_type_align with common type_align function. Doing this fixes a bug in arm_type_align where static fields are considered as part of the alignment calculation of a struct, which results in arguments passed on the stack being misaligned, this bug was causing a failure in gdb.cp/many-args.exp. Part of the old arm_type_align is retained and used as the gdbarch type align callback in order to correctly align vectors. gdb/ChangeLog: * arm-tdep.c (arm_type_align): Only handle vector override case. (arm_push_dummy_call): Use type_align. (arm_gdbarch_init): Register arm_type_align gdbarch function. --- gdb/ChangeLog | 6 +++++ gdb/arm-tdep.c | 68 +++++++++++++------------------------------------- 2 files changed, 23 insertions(+), 51 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6918644f14e..99f67d89432 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2019-04-23 Andrew Burgess + + * arm-tdep.c (arm_type_align): Only handle vector override case. + (arm_push_dummy_call): Use type_align. + (arm_gdbarch_init): Register arm_type_align gdbarch function. + 2019-04-23 Andrew Burgess * aarch64-tdep.c (aarch64_type_align): Only handle vector override diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 599f785b349..742bfa57069 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -3314,62 +3314,25 @@ pop_stack_item (struct stack_item *si) return si; } +/* Implement the gdbarch type alignment method, overrides the generic + alignment algorithm for anything that is arm specific. */ -/* Return the alignment (in bytes) of the given type. */ - -static int -arm_type_align (struct type *t) +static ULONGEST +arm_type_align (gdbarch *gdbarch, struct type *t) { - int n; - int align; - int falign; - t = check_typedef (t); - switch (TYPE_CODE (t)) + if (TYPE_CODE (t) == TYPE_CODE_ARRAY && TYPE_VECTOR (t)) { - default: - /* Should never happen. */ - internal_error (__FILE__, __LINE__, _("unknown type alignment")); - return 4; - - case TYPE_CODE_PTR: - case TYPE_CODE_ENUM: - case TYPE_CODE_INT: - case TYPE_CODE_FLT: - case TYPE_CODE_SET: - case TYPE_CODE_RANGE: - case TYPE_CODE_REF: - case TYPE_CODE_RVALUE_REF: - case TYPE_CODE_CHAR: - case TYPE_CODE_BOOL: - return TYPE_LENGTH (t); - - case TYPE_CODE_ARRAY: - if (TYPE_VECTOR (t)) - { - /* Use the natural alignment for vector types (the same for - scalar type), but the maximum alignment is 64-bit. */ - if (TYPE_LENGTH (t) > 8) - return 8; - else - return TYPE_LENGTH (t); - } + /* Use the natural alignment for vector types (the same for + scalar type), but the maximum alignment is 64-bit. */ + if (TYPE_LENGTH (t) > 8) + return 8; else - return arm_type_align (TYPE_TARGET_TYPE (t)); - case TYPE_CODE_COMPLEX: - return arm_type_align (TYPE_TARGET_TYPE (t)); - - case TYPE_CODE_STRUCT: - case TYPE_CODE_UNION: - align = 1; - for (n = 0; n < TYPE_NFIELDS (t); n++) - { - falign = arm_type_align (TYPE_FIELD_TYPE (t, n)); - if (falign > align) - align = falign; - } - return align; + return TYPE_LENGTH (t); } + + /* Allow the common code to calculate the alignment. */ + return 0; } /* Possible base types for a candidate for passing and returning in @@ -3715,7 +3678,7 @@ arm_push_dummy_call (struct gdbarch *gdbarch, struct value *function, typecode = TYPE_CODE (arg_type); val = value_contents (args[argnum]); - align = arm_type_align (arg_type); + align = type_align (arg_type); /* Round alignment up to a whole number of words. */ align = (align + INT_REGISTER_SIZE - 1) & ~(INT_REGISTER_SIZE - 1); /* Different ABIs have different maximum alignments. */ @@ -9309,6 +9272,9 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) else set_gdbarch_wchar_signed (gdbarch, 1); + /* Compute type alignment. */ + set_gdbarch_type_align (gdbarch, arm_type_align); + /* Note: for displaced stepping, this includes the breakpoint, and one word of additional scratch space. This setting isn't used for anything beside displaced stepping at present. */ -- 2.30.2