From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 90559 invoked by alias); 2 Jul 2018 15:35:45 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 90538 invoked by uid 89); 2 Jul 2018 15:35:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=hoping, mostly X-HELO: EUR04-DB3-obe.outbound.protection.outlook.com Received: from mail-eopbgr60045.outbound.protection.outlook.com (HELO EUR04-DB3-obe.outbound.protection.outlook.com) (40.107.6.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 02 Jul 2018 15:35:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YiOa9IWbvGFQ4R/SH/QvtOiL4QpvEe8EsoMzgz6E//M=; b=lt2du5yJ1HCI3sSKBUt6zJdTpr7ohk+V3g4jJQ04EYzsF7sfVr3D2D9EtAdzOB8xR452lo0CUiPD2Op/Xy+iUR99lO9hDCB5t89Ow5vlXNFu4Qd/9eOoFj5zv3m+jTts0f+ZuW1h20+v7XsgBlEa7fqnYeBXHsRUMLMpffJUIxg= Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com (10.172.226.148) by DB6PR0802MB2326.eurprd08.prod.outlook.com (10.172.228.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.906.26; Mon, 2 Jul 2018 15:35:38 +0000 Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::a152:f8f6:6608:7624]) by DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::a152:f8f6:6608:7624%6]) with mapi id 15.20.0906.026; Mon, 2 Jul 2018 15:35:38 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd Subject: [PING][RFC] Core file support for Aaarch64 SVE Date: Mon, 02 Jul 2018 15:35:00 -0000 Message-ID: References: <20180625151002.35415-1-alan.hayward@arm.com> In-Reply-To: <20180625151002.35415-1-alan.hayward@arm.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-IsSubscribed: yes X-SW-Source: 2018-07/txt/msg00015.txt.bz2 Ping. Hoping patch should mostly be fine, just need some advice on where to move functions to get the all-targets build working. Alan. > On 25 Jun 2018, at 16:10, Alan Hayward wrote: >=20 > The following patch fails to compile for an all targets build. > This is due to aarch64-linux-tdep.c requiring functions from > nat/aarch64-sve-linux-ptrace.c. This is used because the SVE > section of a aarch64 core file starts with a header structure > (the same as in a ptrace read), which is defined in the kernel. >=20 > I considered putting the nat/ file into an all targets build, but > this seemed wrong (in addition it would require additional .deps > dir adding for nat/). >=20 > What is the correct solution here? Should I move the required nat/ > functions into elsewhere? The arch/ still doesn't feel right. >=20 > Other than the above issue, the patch is ready and working. I thought > it best to ask here rather than guess the correct solution. >=20 > Thanks, > Alan >=20 > Support both the reading and writing of core files on aarch64 SVE. >=20 > SVE core files are doumented here: > https://github.com/torvalds/linux/blob/master/Documentation/arm64/sve.txt > * A NT_ARM_SVE note will be added to each coredump for each thread of the > dumped process. The contents will be equivalent to the data that would = have > been read if a PTRACE_GETREGSET of NT_ARM_SVE were executed for each thr= ead > when the coredump was generated. >=20 > When creating a core files target description, read the SVE section to fi= nd > the vector length. >=20 > When reading/writing core files, use the existing nat/ functions to parse > the structure. Given that the function is only called through the one call > chain, there is no need to support copying a single register or invalidat= ing > the set. >=20 > Dependant on binutils patch "[PATCH] Add BFD core support for Aarch64 SVE" > https://sourceware.org/ml/binutils/2018-06/msg00314.html >=20 > Checked with make check on x86 and aarch64. > Generated core files on SVE emulator both from gdb "generate-core-file" > command and a segfault. Loaded these back into gdb. >=20 > 2018-06-25 Alan Hayward >=20 > gdb/ > * aarch64-linux-tdep.c (aarch64_linux_core_read_vq): New function. > (aarch64_linux_supply_sve_regset): Likewise. > (aarch64_linux_collect_sve_regset): Likewise. > (aarch64_linux_iterate_over_regset_sections): Check for SVE. > (aarch64_linux_core_read_description): Likewise. > * nat/aarch64-sve-linux-sigcontext.h (struct _aarch64_ctx): Add for > build compatibility. > (struct user_fpsimd_state): Likewise. > --- > gdb/aarch64-linux-tdep.c | 114 ++++++++++++++++++++++++++++= ++++- > gdb/nat/aarch64-sve-linux-sigcontext.h | 14 ++++ > 2 files changed, 125 insertions(+), 3 deletions(-) >=20 > diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c > index 93b6d416a3..919873b816 100644 > --- a/gdb/aarch64-linux-tdep.c > +++ b/gdb/aarch64-linux-tdep.c > @@ -47,6 +47,7 @@ > #include "linux-record.h" > #include "auxv.h" > #include "elf/common.h" > +#include "nat/aarch64-sve-linux-ptrace.h" >=20 > /* Signal frame handling. >=20 > @@ -169,6 +170,100 @@ aarch64_linux_sigframe_init (const struct tramp_fra= me *self, > trad_frame_set_id (this_cache, frame_id_build (sp, func)); > } >=20 > + > +/* Get VG value from SVE section in the core dump. */ > + > +static uint64_t > +aarch64_linux_core_read_vq (bfd *abfd) > +{ > + struct user_sve_header header; > + asection *sve_section =3D bfd_get_section_by_name (abfd, ".reg-aarch-s= ve"); > + > + if (!sve_section) > + { > + /* No SVE state. */ > + return 0; > + } > + > + size_t size =3D bfd_section_size (abfd, sve_section); > + > + /* Check extended state size. */ > + if (size < sizeof (struct user_sve_header)) > + { > + warning (_("'.reg-aarch-sve' section in core file too small.")); > + return 0; > + } > + > + if (! bfd_get_section_contents (abfd, sve_section, &header, 0, > + sizeof (struct user_sve_header))) > + { > + warning (_("Couldn't read sve header from " > + "'.reg-aarch-sve' section in core file.")); > + return 0; > + } > + > + if (!sve_vl_valid (header.vl)) > + { > + warning (_("sve header invalid in" > + "'.reg-aarch-sve' section in core file.")); > + return 0; > + } > + > + return sve_vq_from_vl (header.vl); > +} > + > + > +/* Supply register REGNUM from BUF to REGCACHE, ignoring the register map > + in REGSET. */ > + > +static void > +aarch64_linux_supply_sve_regset (const struct regset *regset, > + struct regcache *regcache, > + int regnum, const void *buf, size_t size) > +{ > + /* Only called via aarch64_linux_iterate_over_regset_sections loop, so= no > + need to support anything other than a full regset, and no need to s= upport > + null buffers. */ > + gdb_assert (buf !=3D NULL); > + gdb_assert (regnum =3D=3D -1); > + > + aarch64_sve_regs_copy_to_reg_buf (regcache, buf); > +} > + > +/* Collect register REGNUM from REGCACHE to BUF, ignoring the register > + map in REGSET. If REGNUM is -1, do this for all registers in > + REGSET. */ > + > +static void > +aarch64_linux_collect_sve_regset (const struct regset *regset, > + const struct regcache *regcache, > + int regnum, void *buf, size_t size) > +{ > + /* Only called via aarch64_linux_iterate_over_regset_sections loop, so= no > + need to support anything other than a full regset, and no need to s= upport > + null buffers. */ > + gdb_assert (buf !=3D NULL); > + gdb_assert (regnum =3D=3D -1); > + > + /* Read vector size from regcache. */ > + uint64_t vg; > + regcache->raw_collect_integer (AARCH64_SVE_VG_REGNUM, (gdb_byte *)&vg, > + sizeof (uint64_t), false); > + uint64_t vq =3D sve_vq_from_vg (vg); > + > + /* Initialize a valid SVE header. */ > + struct user_sve_header *header =3D (struct user_sve_header *)buf; > + header->flags =3D SVE_PT_REGS_SVE; > + header->size =3D SVE_PT_SIZE (vq, header->flags); > + header->max_size =3D size; > + header->vl =3D sve_vl_from_vg (vg); > + header->max_vl =3D SVE_VL_MAX; > + > + gdb_assert (size >=3D header->size); > + > + aarch64_sve_regs_copy_from_reg_buf (regcache, buf); > +} > + > static const struct tramp_frame aarch64_linux_rt_sigframe =3D > { > SIGTRAMP_FRAME, > @@ -219,6 +314,12 @@ const struct regset aarch64_linux_fpregset =3D > regcache_supply_regset, regcache_collect_regset > }; >=20 > +const struct regset aarch64_linux_sve_regset =3D > + { > + NULL, aarch64_linux_supply_sve_regset, aarch64_linux_collect_sve_reg= set, > + REGSET_VARIABLE_SIZE > + }; > + > /* Implement the "regset_from_core_section" gdbarch method. */ >=20 > static void > @@ -227,10 +328,17 @@ aarch64_linux_iterate_over_regset_sections (struct = gdbarch *gdbarch, > void *cb_data, > const struct regcache *regcache) > { > + struct gdbarch_tdep *tdep =3D gdbarch_tdep (gdbarch); > + > cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, &aarch64_linux_gregset, > NULL, cb_data); > - cb (".reg2", AARCH64_LINUX_SIZEOF_FPREGSET, &aarch64_linux_fpregset, > - NULL, cb_data); > + > + if (tdep->has_sve ()) > + cb (".reg-aarch-sve", SVE_PT_SIZE (tdep->vq, 0), > + &aarch64_linux_sve_regset, "SVE registers", cb_data); > + else > + cb (".reg2", AARCH64_LINUX_SIZEOF_FPREGSET, &aarch64_linux_fpregset,= NULL, > + cb_data); > } >=20 > /* Implement the "core_read_description" gdbarch method. SVE not yet > @@ -245,7 +353,7 @@ aarch64_linux_core_read_description (struct gdbarch *= gdbarch, > if (target_auxv_search (target, AT_HWCAP, &aarch64_hwcap) !=3D 1) > return NULL; >=20 > - return aarch64_read_description (0); > + return aarch64_read_description (aarch64_linux_core_read_vq (abfd)); > } >=20 > /* Implementation of `gdbarch_stap_is_single_operand', as defined in > diff --git a/gdb/nat/aarch64-sve-linux-sigcontext.h b/gdb/nat/aarch64-sve= -linux-sigcontext.h > index bdece8e17d..ad6e111e71 100644 > --- a/gdb/nat/aarch64-sve-linux-sigcontext.h > +++ b/gdb/nat/aarch64-sve-linux-sigcontext.h > @@ -19,6 +19,20 @@ > #ifndef AARCH64_SVE_LINUX_SIGCONTEXT_H > #define AARCH64_SVE_LINUX_SIGCONTEXT_H >=20 > +#ifndef _aarch64_ctx > +struct _aarch64_ctx { > + __u32 magic; > + __u32 size; > +}; > + > +struct user_fpsimd_state { > + __uint128_t vregs[32]; > + __u32 fpsr; > + __u32 fpcr; > + __u32 __reserved[2]; > +}; > +#endif > + > #define SVE_MAGIC 0x53564501 >=20 > struct sve_context { > --=20 > 2.15.2 (Apple Git-101.1) >=20