From: Luis Machado via Gdb-patches <gdb-patches@sourceware.org>
To: Andrew Burgess <andrew.burgess@embecosm.com>,
gdb-patches@sourceware.org, binutils@sourceware.org
Cc: Fredrik Hederstierna <fredrik@hederstierna.com>
Subject: Re: [PATCHv2 8/9] gdb/riscv: write CSRs into baremetal core dumps
Date: Mon, 1 Feb 2021 11:33:41 -0300 [thread overview]
Message-ID: <84f8a899-7669-6d24-ae00-0439df13ddad@linaro.org> (raw)
In-Reply-To: <e49e0602c0d0119860e7100b34239e235bb111da.1611172468.git.andrew.burgess@embecosm.com>
On 1/20/21 5:23 PM, Andrew Burgess wrote:
> Use the current target description to include CSRs into the RISC-V
> baremetal core dumps.
>
> Every CSR declared in the current target description will be included
> in the core dump. If a CSR fails to read then the value 0 will be
> placed into the core dump instead.
>
> It will be critical for users that they have the same target
> description in use when loading the core file as was in use when
> writing the core file. This should be fine if the user allows the
> target description to be written into the core file.
>
> In more detail, this commit adds a NT_RISCV_CSR note type. The
> contents of this section is a series of either 4-byte (on RV32
> targets), or 8-byte (on RV64 targets) regions. Every CSR that
> is mentioned in the current target description is written into one of
> these regions in the order that the registers appear in the target
> description. As a consequence it is critical that the exact same
> target description, including the same register order, is in use when
> the CSRs are loaded from the core file.
>
> gdb/ChangeLog:
>
> * riscv-non-tdep.c (riscv_csrset): New static global.
> (riscv_update_csrmap): New function.
> (riscv_iterate_over_regset_sections): Process CSRs.
> ---
> gdb/ChangeLog | 7 +++++
> gdb/riscv-none-tdep.c | 60 +++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 67 insertions(+)
>
> diff --git a/gdb/riscv-none-tdep.c b/gdb/riscv-none-tdep.c
> index e06ee0981fe..2392c132e69 100644
> --- a/gdb/riscv-none-tdep.c
> +++ b/gdb/riscv-none-tdep.c
> @@ -24,6 +24,8 @@
> #include "elf-bfd.h"
> #include "regset.h"
> #include "none-tdep.h"
> +#include "user-regs.h"
> +#include "target-descriptions.h"
>
> /* Define the general register mapping. This follows the same format as
> the RISC-V linux corefile. The linux kernel puts the PC at offset 0,
> @@ -62,6 +64,42 @@ static const struct regset riscv_fregset =
> riscv_fregmap, riscv_supply_regset, regcache_collect_regset
> };
>
> +/* Define the CSR regset, this is not constant as the regmap field is
> + updated dynamically based on the current target description. */
> +
> +static struct regset riscv_csrset =
> +{
> + nullptr, regcache_supply_regset, regcache_collect_regset
> +};
> +
> +/* Update the regmap field of RISCV_CSRSET based on the CSRs available in
> + the current target description. */
> +
> +static void
> +riscv_update_csrmap (struct gdbarch *gdbarch,
> + const struct tdesc_feature *feature_csr)
> +{
> + int i = 0;
> +
> + /* Release any previously defined map. */
> + delete[] ((struct regcache_map_entry *) riscv_csrset.regmap);
> +
> + /* Now create a register map for every csr found in the target
> + description. */
> + struct regcache_map_entry *riscv_csrmap
> + = new struct regcache_map_entry[feature_csr->registers.size() + 1];
> + for (auto &csr : feature_csr->registers)
> + {
> + int regnum = user_reg_map_name_to_regnum (gdbarch, csr->name.c_str(),
> + csr->name.length());
> + riscv_csrmap[i++] = {1, regnum, 0};
> + }
> +
> + /* Mark the end of the array. */
> + riscv_csrmap[i] = {0};
> + riscv_csrset.regmap = riscv_csrmap;
> +}
> +
> /* Implement the "iterate_over_regset_sections" gdbarch method. */
>
> static void
> @@ -81,6 +119,28 @@ riscv_iterate_over_regset_sections (struct gdbarch *gdbarch,
> + register_size (gdbarch, RISCV_CSR_FCSR_REGNUM));
> cb (".reg2", sz, sz, &riscv_fregset, NULL, cb_data);
> }
> +
> + /* Read or write the CSRs. The set of CSRs is defined by the current
> + target description. The user is responsible for ensuring that the
> + same target description is in use when reading the core file as was
> + in use when writing the core file. */
> + const struct target_desc *tdesc = gdbarch_target_desc (gdbarch);
> +
> + /* Do not dump/load any CSRs if there is no target description or the target
> + description does not contain any CSRs. */
> + if (tdesc != nullptr)
> + {
> + const struct tdesc_feature *feature_csr
> + = tdesc_find_feature (tdesc, riscv_feature_name_csr);
> + if (feature_csr != nullptr && feature_csr->registers.size () > 0)
> + {
> + riscv_update_csrmap (gdbarch, feature_csr);
> + cb (".reg-riscv-csr",
> + (feature_csr->registers.size() * riscv_isa_xlen (gdbarch)),
> + (feature_csr->registers.size() * riscv_isa_xlen (gdbarch)),
> + &riscv_csrset, NULL, cb_data);
> + }
> + }
> }
>
> /* Initialize RISC-V bare-metal ABI info. */
>
Looks OK to me.
next prev parent reply other threads:[~2021-02-01 14:33 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-20 20:23 [PATCHv2 0/9] Bare-metal core dumps for RISC-V Andrew Burgess
2021-01-20 20:23 ` [PATCHv2 1/9] gdb: unify parts of the Linux and FreeBSD core dumping code Andrew Burgess
2021-01-22 12:01 ` Strasuns, Mihails via Gdb-patches
2021-01-22 18:50 ` Tom Tromey
2021-02-01 11:56 ` Andrew Burgess
2021-02-09 21:52 ` Andrew Burgess
2021-01-20 20:23 ` [PATCHv2 2/9] bfd/binutils: support for gdb target descriptions in the core file Andrew Burgess
2021-01-22 10:47 ` Strasuns, Mihails via Gdb-patches
2021-01-22 19:30 ` Andrew Burgess
2021-01-25 10:11 ` Strasuns, Mihails via Gdb-patches
2021-01-25 11:20 ` Andrew Burgess
2021-02-01 12:05 ` PING: " Andrew Burgess
2021-02-01 15:10 ` Strasuns, Mihails via Gdb-patches
2021-02-01 13:29 ` Luis Machado via Gdb-patches
2021-02-10 20:45 ` Jim Wilson
2021-01-20 20:23 ` [PATCHv2 3/9] gdb: write target description into " Andrew Burgess
2021-01-22 19:15 ` Tom Tromey
2021-02-01 13:37 ` Luis Machado via Gdb-patches
2021-01-20 20:23 ` [PATCHv2 4/9] bfd/riscv: prepare to handle bare metal core dump creation Andrew Burgess
2021-02-01 12:03 ` PING: " Andrew Burgess
2021-02-01 13:48 ` Luis Machado via Gdb-patches
2021-02-01 14:44 ` Andrew Burgess
2021-02-10 20:57 ` Jim Wilson
2021-01-20 20:23 ` [PATCHv2 5/9] gdb/riscv: introduce bare metal core dump support Andrew Burgess
2021-02-01 14:05 ` Luis Machado via Gdb-patches
2021-02-03 3:04 ` Palmer Dabbelt
2021-01-20 20:23 ` [PATCHv2 6/9] bfd/binutils: add support for RISC-V CSRs in core files Andrew Burgess
2021-02-01 12:00 ` Andrew Burgess
2021-02-01 14:08 ` Luis Machado via Gdb-patches
2021-02-10 21:00 ` Jim Wilson
2021-01-20 20:23 ` [PATCHv2 7/9] gdb/riscv: make riscv target description names global Andrew Burgess
2021-02-01 14:22 ` Luis Machado via Gdb-patches
2021-01-20 20:23 ` [PATCHv2 8/9] gdb/riscv: write CSRs into baremetal core dumps Andrew Burgess
2021-02-01 14:33 ` Luis Machado via Gdb-patches [this message]
2021-01-20 20:23 ` [PATCHv2 9/9] gdb/arm: add support for bare-metal " Andrew Burgess
2021-02-01 14:51 ` Luis Machado via Gdb-patches
2021-01-22 19:28 ` [PATCHv2 0/9] Bare-metal core dumps for RISC-V Tom Tromey
2021-02-15 17:29 ` [PATCHv3 " Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 1/9] gdb: unify parts of the Linux and FreeBSD core dumping code Andrew Burgess
2021-02-15 22:56 ` Lancelot SIX via Gdb-patches
2021-02-16 16:55 ` Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 2/9] bfd/binutils: support for gdb target descriptions in the core file Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 3/9] gdb: write target description into " Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 4/9] bfd/riscv: prepare to handle bare metal core dump creation Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 5/9] gdb/riscv: introduce bare metal core dump support Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 6/9] bfd/binutils: add support for RISC-V CSRs in core files Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 7/9] gdb/riscv: make riscv target description names global Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 8/9] gdb/riscv: write CSRs into baremetal core dumps Andrew Burgess
2021-02-15 17:29 ` [PATCHv3 9/9] gdb/arm: add support for bare-metal " Andrew Burgess
2021-05-13 13:42 ` Andrew Burgess
2021-05-13 13:51 ` Luis Machado via Gdb-patches
2021-05-13 13:56 ` Andrew Burgess
2021-05-15 13:52 ` SV: " sarah@hederstierna.com
2021-06-01 9:00 ` Andrew Burgess
2021-03-01 10:32 ` [PATCHv3 0/9] Bare-metal core dumps for RISC-V Andrew Burgess
2021-03-01 14:45 ` Nick Clifton via Gdb-patches
2021-03-05 17:35 ` 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=84f8a899-7669-6d24-ae00-0439df13ddad@linaro.org \
--to=gdb-patches@sourceware.org \
--cc=andrew.burgess@embecosm.com \
--cc=binutils@sourceware.org \
--cc=fredrik@hederstierna.com \
--cc=luis.machado@linaro.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