public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Alan Hayward <alan.hayward@arm.com>
To: gdb-patches@sourceware.org
Cc: nd@arm.com,	Alan Hayward <alan.hayward@arm.com>
Subject: [PATCH v3 2/3] Detect SVE when reading aarch64 core files
Date: Fri, 10 Aug 2018 16:09:00 -0000	[thread overview]
Message-ID: <20180810160849.68985-3-alan.hayward@arm.com> (raw)
In-Reply-To: <20180810160849.68985-1-alan.hayward@arm.com>

Add a function which reads the vector length from the SVE section within an
aarch64 core file.

The SVE section in a core file contains a header followed by the registers.
Add defines to easily access the header fields within a buffer.

2018-08-10  Alan Hayward  <alan.hayward@arm.com>

	* aarch64-linux-tdep.c (SVE_HEADER_SIZE_LENGTH): Add define.
	(SVE_HEADER_MAX_SIZE_LENGTH): Likewise.
	(SVE_HEADER_VL_LENGTH): Likewise.
	(SVE_HEADER_MAX_VL_LENGTH): Likewise.
	(SVE_HEADER_FLAGS_LENGTH): Likewise.
	(SVE_HEADER_RESERVED_LENGTH): Likewise.
	(SVE_HEADER_SIZE_OFFSET): Likewise.
	(SVE_HEADER_MAX_SIZE_OFFSET): Likewise.
	(SVE_HEADER_VL_OFFSET): Likewise.
	(SVE_HEADER_MAX_VL_OFFSET): Likewise.
	(SVE_HEADER_FLAGS_OFFSET): Likewise.
	(SVE_HEADER_RESERVED_OFFSET): Likewise.
	(SVE_HEADER_SIZE): Likewise.
	(aarch64_linux_core_read_vq): Add function.
	(aarch64_linux_core_read_description): Check for SVE section.
---
 gdb/aarch64-linux-tdep.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 70 insertions(+), 3 deletions(-)

diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index 7b63cddbe6..73cb9ea714 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -219,6 +219,74 @@ const struct regset aarch64_linux_fpregset =
     regcache_supply_regset, regcache_collect_regset
   };
 
+/* The fields in an SVE header at the start of a SVE regset.  */
+
+#define SVE_HEADER_SIZE_LENGTH		4
+#define SVE_HEADER_MAX_SIZE_LENGTH	4
+#define SVE_HEADER_VL_LENGTH		2
+#define SVE_HEADER_MAX_VL_LENGTH	2
+#define SVE_HEADER_FLAGS_LENGTH		2
+#define SVE_HEADER_RESERVED_LENGTH	2
+
+#define SVE_HEADER_SIZE_OFFSET		0
+#define SVE_HEADER_MAX_SIZE_OFFSET	\
+  (SVE_HEADER_SIZE_OFFSET + SVE_HEADER_SIZE_LENGTH)
+#define SVE_HEADER_VL_OFFSET		\
+  (SVE_HEADER_MAX_SIZE_OFFSET + SVE_HEADER_MAX_SIZE_LENGTH)
+#define SVE_HEADER_MAX_VL_OFFSET	\
+  (SVE_HEADER_VL_OFFSET + SVE_HEADER_VL_LENGTH)
+#define SVE_HEADER_FLAGS_OFFSET		\
+  (SVE_HEADER_MAX_VL_OFFSET + SVE_HEADER_MAX_VL_LENGTH)
+#define SVE_HEADER_RESERVED_OFFSET	\
+  (SVE_HEADER_FLAGS_OFFSET + SVE_HEADER_FLAGS_LENGTH)
+#define SVE_HEADER_SIZE			\
+  (SVE_HEADER_RESERVED_OFFSET + SVE_HEADER_RESERVED_LENGTH)
+
+/* Get VQ value from SVE section in the core dump.  */
+
+static uint64_t
+aarch64_linux_core_read_vq (struct gdbarch *gdbarch, bfd *abfd)
+{
+  gdb_byte header[SVE_HEADER_SIZE];
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  asection *sve_section = bfd_get_section_by_name (abfd, ".reg-aarch-sve");
+
+  if (sve_section == nullptr)
+    {
+      /* No SVE state.  */
+      return 0;
+    }
+
+  size_t size = bfd_section_size (abfd, sve_section);
+
+  /* Check extended state size.  */
+  if (size < SVE_HEADER_SIZE)
+    {
+      warning (_("'.reg-aarch-sve' section in core file too small."));
+      return 0;
+    }
+
+  if (!bfd_get_section_contents (abfd, sve_section, header, 0, SVE_HEADER_SIZE))
+    {
+      warning (_("Couldn't read sve header from "
+		 "'.reg-aarch-sve' section in core file."));
+      return 0;
+    }
+
+  uint64_t vl = extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET,
+					  SVE_HEADER_VL_LENGTH, byte_order);
+  uint64_t vq = sve_vq_from_vl (vl);
+
+  if (vq > AARCH64_MAX_SVE_VQ || vq == 0)
+    {
+      warning (_("sve header invalid in "
+		 "'.reg-aarch-sve' section in core file."));
+      return 0;
+    }
+
+  return vq;
+}
+
 /* Implement the "regset_from_core_section" gdbarch method.  */
 
 static void
@@ -233,8 +301,7 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
       &aarch64_linux_fpregset, NULL, cb_data);
 }
 
-/* Implement the "core_read_description" gdbarch method.  SVE not yet
-   supported.  */
+/* Implement the "core_read_description" gdbarch method.  */
 
 static const struct target_desc *
 aarch64_linux_core_read_description (struct gdbarch *gdbarch,
@@ -245,7 +312,7 @@ aarch64_linux_core_read_description (struct gdbarch *gdbarch,
   if (target_auxv_search (target, AT_HWCAP, &aarch64_hwcap) != 1)
     return NULL;
 
-  return aarch64_read_description (0);
+  return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd));
 }
 
 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
-- 
2.15.2 (Apple Git-101.1)

  reply	other threads:[~2018-08-10 16:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-10 16:09 [PATCH v3 0/3] " Alan Hayward
2018-08-10 16:09 ` Alan Hayward [this message]
2018-08-10 19:08   ` [PATCH v3 2/3] " Simon Marchi
2018-08-10 16:09 ` [PATCH v3 1/3] Split size in regset section iterators Alan Hayward
2018-08-10 18:57   ` Simon Marchi
2018-08-10 16:09 ` [PATCH v3 3/3] Parse SVE registers in aarch64 core file reading/writing Alan Hayward
2018-08-10 19:25   ` Simon Marchi

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=20180810160849.68985-3-alan.hayward@arm.com \
    --to=alan.hayward@arm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=nd@arm.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).