From: Luis Machado <luis.machado@arm.com>
To: John Baldwin <jhb@FreeBSD.org>,
binutils@sourceware.org, gdb-patches@sourceware.org
Subject: Re: [PATCH 02/12] fbsd-nat: Add helper routines for register sets using PT_[G]SETREGSET.
Date: Thu, 24 Mar 2022 08:51:08 +0000 [thread overview]
Message-ID: <b2ff95e7-56b0-a4a6-5e0b-b0a2f69dcf9a@arm.com> (raw)
In-Reply-To: <20220323210048.25525-3-jhb@FreeBSD.org>
On 3/23/22 21:00, John Baldwin wrote:
> FreeBSD's kernel has recently added PT_GETREGSET and PT_SETREGSET
> operations to fetch a register set named by an ELF note type. These
> helper routines provide helpers to check for a register set's
> existence, fetch registers for a register set, and store registers to
> a register set.
> ---
> gdb/fbsd-nat.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++
> gdb/fbsd-nat.h | 42 +++++++++++++++++++++++++++++
> 2 files changed, 114 insertions(+)
>
> diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
> index 934fdbad6ef..84abdd9a322 100644
> --- a/gdb/fbsd-nat.c
> +++ b/gdb/fbsd-nat.c
> @@ -1772,6 +1772,78 @@ fbsd_nat_target::store_register_set (struct regcache *regcache, int regnum,
> return false;
> }
>
> +#ifdef PT_GETREGSET
Instead of ifdef-ing the entire block of code, wouldn't it be better to
conditionally define the constant and have the code do checks at runtime?
If GDB is built on a machine without the proper headers and copied onto
a machine with support for PT_GETREGSET, it won't be able to use this
improvement. On the other hand, if we build GDB on a machine with the
headers, but copy it into a machine without support for PT_GETREGSET,
things will break, no?
> +/* See fbsd-nat.h. */
> +
> +bool
> +fbsd_nat_target::have_regset (ptid_t ptid, int note)
> +{
> + pid_t pid = get_ptrace_pid (ptid);
> + struct iovec iov;
> +
> + iov.iov_base = nullptr;
> + iov.iov_len = 0;
> + if (ptrace (PT_GETREGSET, pid, (PTRACE_TYPE_ARG3) &iov, note) == -1)
> + return 0;
> + return iov.iov_len;
> +}
> +
> +/* See fbsd-nat.h. */
> +
> +bool
> +fbsd_nat_target::fetch_regset (struct regcache *regcache, int regnum, int note,
> + const struct regset *regset, void *regs,
> + size_t size)
> +{
> + const struct regcache_map_entry *map
> + = (const struct regcache_map_entry *) regset->regmap;
> + pid_t pid = get_ptrace_pid (regcache->ptid ());
> +
> + if (regnum == -1 || regcache_map_supplies (map, regnum, regcache->arch(),
> + size))
> + {
> + struct iovec iov;
> +
> + iov.iov_base = regs;
> + iov.iov_len = size;
> + if (ptrace (PT_GETREGSET, pid, (PTRACE_TYPE_ARG3) &iov, note) == -1)
> + perror_with_name (_("Couldn't get registers"));
> +
> + regcache->supply_regset (regset, regnum, regs, size);
> + return true;
> + }
> + return false;
> +}
> +
> +bool
> +fbsd_nat_target::store_regset (struct regcache *regcache, int regnum, int note,
> + const struct regset *regset, void *regs,
> + size_t size)
> +{
> + const struct regcache_map_entry *map
> + = (const struct regcache_map_entry *) regset->regmap;
> + pid_t pid = get_ptrace_pid (regcache->ptid ());
> +
> + if (regnum == -1 || regcache_map_supplies (map, regnum, regcache->arch(),
> + size))
> + {
> + struct iovec iov;
> +
> + iov.iov_base = regs;
> + iov.iov_len = size;
> + if (ptrace (PT_GETREGSET, pid, (PTRACE_TYPE_ARG3) &iov, note) == -1)
> + perror_with_name (_("Couldn't get registers"));
> +
> + regcache->collect_regset (regset, regnum, regs, size);
> +
> + if (ptrace (PT_SETREGSET, pid, (PTRACE_TYPE_ARG3) &iov, note) == -1)
> + perror_with_name (_("Couldn't write registers"));
> + return true;
> + }
> + return false;
> +}
> +#endif
> +
> /* See fbsd-nat.h. */
>
> bool
> diff --git a/gdb/fbsd-nat.h b/gdb/fbsd-nat.h
> index 82f7ee47949..6a4003627e4 100644
> --- a/gdb/fbsd-nat.h
> +++ b/gdb/fbsd-nat.h
> @@ -151,6 +151,19 @@ class fbsd_nat_target : public inf_ptrace_target
> bool store_register_set (struct regcache *regcache, int regnum, int fetch_op,
> int store_op, const struct regset *regset,
> void *regs, size_t size);
> +
> +#ifdef PT_GETREGSET
> + /* Helper routines which use PT_GETREGSET and PT_SETREGSET for the
> + specified NOTE instead of regset-specific fetch and store
> + ops. */
> +
> + bool fetch_regset (struct regcache *regcache, int regnum, int note,
> + const struct regset *regset, void *regs, size_t size);
> +
> + bool store_regset (struct regcache *regcache, int regnum, int note,
> + const struct regset *regset, void *regs, size_t size);
> +#endif
> +
> protected:
> /* Wrapper versions of the above helpers which accept a register set
> type such as 'struct reg' or 'struct fpreg'. */
> @@ -172,6 +185,35 @@ class fbsd_nat_target : public inf_ptrace_target
> return store_register_set (regcache, regnum, fetch_op, store_op, regset,
> ®s, sizeof (regs));
> }
> +
> +#ifdef PT_GETREGSET
> + /* Helper routine for use in read_description in subclasses. This
> + routine checks if the register set for the specified NOTE is
> + present for a given PTID. If the register set is present, the
> + the size of the register set is returned. If the register set is
> + not present, zero is returned. */
> +
> + bool have_regset (ptid_t ptid, int note);
> +
> + /* Wrapper versions of the PT_GETREGSET and PT_REGSET helpers which
> + accept a register set type. */
> +
> + template <class Regset>
> + bool fetch_regset (struct regcache *regcache, int regnum, int note,
> + const struct regset *regset)
> + {
> + Regset regs;
> + return fetch_regset (regcache, regnum, note, regset, ®s, sizeof (regs));
> + }
> +
> + template <class Regset>
> + bool store_regset (struct regcache *regcache, int regnum, int note,
> + const struct regset *regset)
> + {
> + Regset regs;
> + return store_regset (regcache, regnum, note, regset, ®s, sizeof (regs));
> + }
> +#endif
> };
>
> /* Fetch the signal information for PTID and store it in *SIGINFO.
next prev parent reply other threads:[~2022-03-24 8:51 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-23 21:00 [PATCH 00/12] * Support for Thread Local Storage (TLS) variables on FreeBSD arm and aarch64 architectures John Baldwin
2022-03-23 21:00 ` [PATCH 01/12] Handle another edge case for TLS variable lookups John Baldwin
2022-03-23 23:55 ` John Baldwin
2022-03-24 0:26 ` John Baldwin
2022-03-23 21:00 ` [PATCH 02/12] fbsd-nat: Add helper routines for register sets using PT_[G]SETREGSET John Baldwin
2022-03-24 8:51 ` Luis Machado [this message]
2022-03-24 17:45 ` John Baldwin
2022-03-23 21:00 ` [PATCH 03/12] Create pseudo sections for NT_ARM_TLS notes on FreeBSD John Baldwin
2022-03-23 21:00 ` [PATCH 04/12] Add an arm-tls feature which includes the tpidruro register from CP15 John Baldwin
2022-04-04 8:01 ` Luis Machado
2022-04-12 23:36 ` John Baldwin
2022-04-14 10:23 ` Luis Machado
2022-04-19 16:18 ` John Baldwin
2022-04-20 6:59 ` Luis Machado
2022-03-23 21:00 ` [PATCH 05/12] Read the tpidruro register from NT_ARM_TLS core dump notes on FreeBSD/arm John Baldwin
2022-03-23 21:00 ` [PATCH 06/12] Support TLS variables " John Baldwin
2022-03-23 21:00 ` [PATCH 07/12] Fetch the NT_ARM_TLS register set for native FreeBSD/arm processes John Baldwin
2022-03-23 21:00 ` [PATCH 08/12] Add an aarch64-tls feature which includes the tpidr register John Baldwin
2022-03-28 10:16 ` Luis Machado
2022-04-01 23:30 ` John Baldwin
2022-04-04 8:06 ` Luis Machado
2022-04-04 12:18 ` Luis Machado
2022-05-03 21:14 ` Luis Machado
2022-05-03 21:30 ` John Baldwin
2022-05-03 21:34 ` Luis Machado
2022-03-23 21:00 ` [PATCH 09/12] Read the tpidr register from NT_ARM_TLS core dump notes on FreeBSD/Aarch64 John Baldwin
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=b2ff95e7-56b0-a4a6-5e0b-b0a2f69dcf9a@arm.com \
--to=luis.machado@arm.com \
--cc=binutils@sourceware.org \
--cc=gdb-patches@sourceware.org \
--cc=jhb@FreeBSD.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).