From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: alan.hayward@arm.com, Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PATCH 2/3] gdb/arm: Use type_align instead of arm_type_align
Date: Fri, 12 Apr 2019 23:25:00 -0000 [thread overview]
Message-ID: <dc5518dbbe014bf6b4b594246c01a8fe7ede14fa.1555111225.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1555111225.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1555111225.git.andrew.burgess@embecosm.com>
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/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.14.5
next prev parent reply other threads:[~2019-04-12 23:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-12 23:25 [PATCH 0/3] More use of type_align function Andrew Burgess
2019-04-12 23:25 ` Andrew Burgess [this message]
2019-04-14 18:56 ` [PATCH 2/3] gdb/arm: Use type_align instead of arm_type_align Kevin Buettner
2019-04-12 23:25 ` [PATCH 3/3] gdb/nds32: Use type_align instead of nds32_type_align Andrew Burgess
2019-04-14 18:53 ` Kevin Buettner
2019-04-17 20:59 ` Andrew Burgess
2019-04-18 0:02 ` Kevin Buettner
2019-04-12 23:25 ` [PATCH 1/3] gdb/aarch64: Use type_align instead of aarch64_type_align Andrew Burgess
2019-04-14 18:54 ` Kevin Buettner
2019-04-23 21:08 ` [PATCH 0/3] More use of type_align function Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dc5518dbbe014bf6b4b594246c01a8fe7ede14fa.1555111225.git.andrew.burgess@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=alan.hayward@arm.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox