From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Jim Wilson <jimw@sifive.com>, John Baldwin <jhb@freebsd.org>,
Palmer Dabbelt <palmer@sifive.com>, Tom Tromey <tom@tromey.com>,
Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PATCH 2/2] gdb/riscv: Remove riscv_type_alignment function
Date: Sun, 07 Apr 2019 21:38:00 -0000 [thread overview]
Message-ID: <39e3d1f6667eddb68b5c5df74197ea6461e3d858.1554672870.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1554672869.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1554672869.git.andrew.burgess@embecosm.com>
Make use of the type_align function and remove riscv_type_alignment as
it is no longer needed. I tested this against a number of RV32 and
RV64 targets, and I also ran the tests with an assertion in place
checking that the old riscv_type_alignment function gives the same
answer as the common type_align function - it does, and all the tests
still pass.
gdb/ChangeLog:
* riscv-tdep.c (riscv_type_align): New function.
(riscv_type_alignment): Delete.
(riscv_arg_location): Use 'type_align'.
(riscv_gdbarch_init): Register riscv_type_align gdbarch function.
---
gdb/ChangeLog | 7 +++++++
gdb/riscv-tdep.c | 60 ++++++++++++--------------------------------------------
2 files changed, 19 insertions(+), 48 deletions(-)
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index ff5f36e7621..ed75dc59951 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -1620,55 +1620,18 @@ riscv_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
return sp;
}
-/* Compute the alignment of the type T. Used while setting up the
- arguments for a dummy call. */
+/* Implement the gdbarch type alignment method, overrides the generic
+ alignment algorithm for anything that is RISC-V specific. */
-static int
-riscv_type_alignment (struct type *t)
+static ULONGEST
+riscv_type_align (gdbarch *gdbarch, type *type)
{
- t = check_typedef (t);
- switch (TYPE_CODE (t))
- {
- default:
- error (_("Could not compute alignment of type"));
-
- case TYPE_CODE_RANGE:
- case TYPE_CODE_RVALUE_REF:
- case TYPE_CODE_PTR:
- case TYPE_CODE_ENUM:
- case TYPE_CODE_INT:
- case TYPE_CODE_FLT:
- case TYPE_CODE_REF:
- case TYPE_CODE_CHAR:
- case TYPE_CODE_BOOL:
- return TYPE_LENGTH (t);
+ type = check_typedef (type);
+ if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type))
+ return std::min (TYPE_LENGTH (type), (ULONGEST) BIGGEST_ALIGNMENT);
- case TYPE_CODE_ARRAY:
- if (TYPE_VECTOR (t))
- return std::min (TYPE_LENGTH (t), (ULONGEST) BIGGEST_ALIGNMENT);
- /* FALLTHROUGH */
-
- case TYPE_CODE_COMPLEX:
- return riscv_type_alignment (TYPE_TARGET_TYPE (t));
-
- case TYPE_CODE_STRUCT:
- case TYPE_CODE_UNION:
- {
- int i;
- int align = 1;
-
- for (i = 0; i < TYPE_NFIELDS (t); ++i)
- {
- if (TYPE_FIELD_LOC_KIND (t, i) == FIELD_LOC_KIND_BITPOS)
- {
- int a = riscv_type_alignment (TYPE_FIELD_TYPE (t, i));
- if (a > align)
- align = a;
- }
- }
- return align;
- }
- }
+ /* Anything else will be aligned by the generic code. */
+ return 0;
}
/* Holds information about a single argument either being passed to an
@@ -2231,7 +2194,7 @@ riscv_arg_location (struct gdbarch *gdbarch,
{
ainfo->type = type;
ainfo->length = TYPE_LENGTH (ainfo->type);
- ainfo->align = riscv_type_alignment (ainfo->type);
+ ainfo->align = type_align (ainfo->type);
ainfo->is_unnamed = is_unnamed;
ainfo->contents = nullptr;
@@ -2255,7 +2218,7 @@ riscv_arg_location (struct gdbarch *gdbarch,
}
/* Recalculate the alignment requirement. */
- ainfo->align = riscv_type_alignment (ainfo->type);
+ ainfo->align = type_align (ainfo->type);
riscv_call_arg_scalar_int (ainfo, cinfo);
break;
@@ -3156,6 +3119,7 @@ riscv_gdbarch_init (struct gdbarch_info info,
set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
set_gdbarch_ptr_bit (gdbarch, riscv_isa_xlen (gdbarch) * 8);
set_gdbarch_char_signed (gdbarch, 0);
+ set_gdbarch_type_align (gdbarch, riscv_type_align);
/* Information about the target architecture. */
set_gdbarch_return_value (gdbarch, riscv_return_value);
--
2.14.5
next prev parent reply other threads:[~2019-04-07 21:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-07 21:38 [PATCH 0/2] More type_align fixes Andrew Burgess
2019-04-07 21:38 ` Andrew Burgess [this message]
2019-04-07 21:38 ` [PATCH 1/2] gdb: Fix alignment computation for structs with only static fields Andrew Burgess
2019-04-07 22:36 ` Tom Tromey
2019-04-11 22:42 ` [PATCH 0/2] More type_align fixes 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=39e3d1f6667eddb68b5c5df74197ea6461e3d858.1554672870.git.andrew.burgess@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=jhb@freebsd.org \
--cc=jimw@sifive.com \
--cc=palmer@sifive.com \
--cc=tom@tromey.com \
/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