fbsd-nat: Add helper routines for register sets using PT_[G]SETREGSET.

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.
This commit is contained in:
John Baldwin
2022-05-03 16:05:10 -07:00
parent 3c688b9e38
commit 40c23d8803
2 changed files with 113 additions and 0 deletions

View File

@@ -49,6 +49,11 @@
#include <list>
#ifndef PT_GETREGSET
#define PT_GETREGSET 42 /* Get a target register set */
#define PT_SETREGSET 43 /* Set a target register set */
#endif
/* Return the name of a file that can be opened to get the symbols for
the child process identified by PID. */
@@ -1774,6 +1779,76 @@ fbsd_nat_target::store_register_set (struct regcache *regcache, int regnum,
/* 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;
}
/* See fbsd-nat.h. */
bool
fbsd_nat_get_siginfo (ptid_t ptid, siginfo_t *siginfo)
{

View File

@@ -151,6 +151,17 @@ private:
bool store_register_set (struct regcache *regcache, int regnum, int fetch_op,
int store_op, const struct regset *regset,
void *regs, size_t size);
/* 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);
protected:
/* Wrapper versions of the above helpers which accept a register set
type such as 'struct reg' or 'struct fpreg'. */
@@ -172,6 +183,33 @@ protected:
return store_register_set (regcache, regnum, fetch_op, store_op, regset,
&regs, sizeof (regs));
}
/* 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, &regs, 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, &regs, sizeof (regs));
}
};
/* Fetch the signal information for PTID and store it in *SIGINFO.