From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1936) id BFB6E3853D45; Tue, 22 Nov 2022 22:43:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BFB6E3853D45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669157036; bh=Jrnq4Y5JnZWJ0iAKWrSiKVP0IaRRy3TrkNUAua65nMo=; h=From:To:Subject:Date:From; b=SkUkA8gZ2cTHzSsmldNb9dHKIBqV9XIS3W3Ka4QAqil1iSR+iDiYlGKsgSHyp5HQy WwHtEjtSgGje/TjqHekMuWM++slk4nlTbcMaYj+8EptMlUdS6INofnI9+poxiJGsfG LlFEiU3nZACV/93rWiaqMgVIm1G+JKoQRGRl3pmM= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: John Baldwin To: gdb-cvs@sourceware.org Subject: [binutils-gdb] fbsd-nat: Pass an optional register base to the register set helpers. X-Act-Checkin: binutils-gdb X-Git-Author: John Baldwin X-Git-Refname: refs/heads/master X-Git-Oldrev: 5dd6c79a323a9ca7bf8d5db3206532580365127e X-Git-Newrev: a141d32c6ef5c644c856d89de88f9980ec3d8ceb Message-Id: <20221122224356.BFB6E3853D45@sourceware.org> Date: Tue, 22 Nov 2022 22:43:56 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da141d32c6ef5= c644c856d89de88f9980ec3d8ceb commit a141d32c6ef5c644c856d89de88f9980ec3d8ceb Author: John Baldwin Date: Tue Nov 22 14:21:13 2022 -0800 fbsd-nat: Pass an optional register base to the register set helpers. =20 This is needed to permit using the helpers for register sets with a variable base. In particular regnum needs to be converted into a relative register number before passed to regcache_map_supplies. =20 Approved-By: Simon Marchi Diff: --- gdb/fbsd-nat.c | 34 +++++++++++++++++++--------------- gdb/fbsd-nat.h | 37 ++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index 7d279810483..1aec75050ae 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -1732,14 +1732,15 @@ fbsd_nat_target::supports_disable_randomization () bool fbsd_nat_target::fetch_register_set (struct regcache *regcache, int regnum, int fetch_op, const struct regset *regset, - void *regs, size_t size) + int regbase, void *regs, size_t size) { const struct regcache_map_entry *map =3D (const struct regcache_map_entry *) regset->regmap; pid_t pid =3D get_ptrace_pid (regcache->ptid ()); =20 - if (regnum =3D=3D -1 || regcache_map_supplies (map, regnum, regcache->ar= ch(), - size)) + if (regnum =3D=3D -1 + || (regnum >=3D regbase && regcache_map_supplies (map, regnum - regb= ase, + regcache->arch(), size))) { if (ptrace (fetch_op, pid, (PTRACE_TYPE_ARG3) regs, 0) =3D=3D -1) perror_with_name (_("Couldn't get registers")); @@ -1755,15 +1756,16 @@ fbsd_nat_target::fetch_register_set (struct regcach= e *regcache, int regnum, bool fbsd_nat_target::store_register_set (struct regcache *regcache, int regnum, int fetch_op, int store_op, - const struct regset *regset, void *regs, - size_t size) + const struct regset *regset, int regbase, + void *regs, size_t size) { const struct regcache_map_entry *map =3D (const struct regcache_map_entry *) regset->regmap; pid_t pid =3D get_ptrace_pid (regcache->ptid ()); =20 - if (regnum =3D=3D -1 || regcache_map_supplies (map, regnum, regcache->ar= ch(), - size)) + if (regnum =3D=3D -1 + || (regnum >=3D regbase && regcache_map_supplies (map, regnum - regb= ase, + regcache->arch(), size))) { if (ptrace (fetch_op, pid, (PTRACE_TYPE_ARG3) regs, 0) =3D=3D -1) perror_with_name (_("Couldn't get registers")); @@ -1796,15 +1798,16 @@ fbsd_nat_target::have_regset (ptid_t ptid, int note) =20 bool fbsd_nat_target::fetch_regset (struct regcache *regcache, int regnum, int = note, - const struct regset *regset, void *regs, - size_t size) + const struct regset *regset, int regbase, + void *regs, size_t size) { const struct regcache_map_entry *map =3D (const struct regcache_map_entry *) regset->regmap; pid_t pid =3D get_ptrace_pid (regcache->ptid ()); =20 - if (regnum =3D=3D -1 || regcache_map_supplies (map, regnum, regcache->ar= ch(), - size)) + if (regnum =3D=3D -1 + || (regnum >=3D regbase && regcache_map_supplies (map, regnum - regb= ase, + regcache->arch(), size))) { struct iovec iov; =20 @@ -1821,15 +1824,16 @@ fbsd_nat_target::fetch_regset (struct regcache *reg= cache, int regnum, int note, =20 bool fbsd_nat_target::store_regset (struct regcache *regcache, int regnum, int = note, - const struct regset *regset, void *regs, - size_t size) + const struct regset *regset, int regbase, + void *regs, size_t size) { const struct regcache_map_entry *map =3D (const struct regcache_map_entry *) regset->regmap; pid_t pid =3D get_ptrace_pid (regcache->ptid ()); =20 - if (regnum =3D=3D -1 || regcache_map_supplies (map, regnum, regcache->ar= ch(), - size)) + if (regnum =3D=3D -1 + || (regnum >=3D regbase && regcache_map_supplies (map, regnum - regb= ase, + regcache->arch(), size))) { struct iovec iov; =20 diff --git a/gdb/fbsd-nat.h b/gdb/fbsd-nat.h index 7a0510c32bd..311ed4ad43a 100644 --- a/gdb/fbsd-nat.h +++ b/gdb/fbsd-nat.h @@ -133,7 +133,8 @@ private: /* Helper routines for use in fetch_registers and store_registers in subclasses. These routines fetch and store a single set of registers described by REGSET. The REGSET's 'regmap' field must - point to an array of 'struct regcache_map_entry'. + point to an array of 'struct regcache_map_entry'. The valid + register numbers in the register map are relative to REGBASE. =20 FETCH_OP is a ptrace operation to fetch the set of registers from a native thread. STORE_OP is a ptrace operation to store the set @@ -143,24 +144,27 @@ private: and SIZE is the size of the storage. =20 Returns true if the register set was transferred due to a - matching REGNUM.*/ + matching REGNUM. */ =20 bool fetch_register_set (struct regcache *regcache, int regnum, int fetc= h_op, - const struct regset *regset, void *regs, size_t size); + const struct regset *regset, int regbase, void *regs, + size_t size); =20 bool store_register_set (struct regcache *regcache, int regnum, int fetc= h_op, int store_op, const struct regset *regset, - void *regs, size_t size); + int regbase, void *regs, size_t size); =20 /* Helper routines which use PT_GETREGSET and PT_SETREGSET for the specified NOTE instead of regset-specific fetch and store ops. */ =20 bool fetch_regset (struct regcache *regcache, int regnum, int note, - const struct regset *regset, void *regs, size_t size); + const struct regset *regset, int regbase, void *regs, + size_t size); =20 bool store_regset (struct regcache *regcache, int regnum, int note, - const struct regset *regset, void *regs, size_t size); + const struct regset *regset, int regbase, void *regs, + size_t size); =20 protected: /* Wrapper versions of the above helpers which accept a register set @@ -168,20 +172,21 @@ protected: =20 template bool fetch_register_set (struct regcache *regcache, int regnum, int fetc= h_op, - const struct regset *regset) + const struct regset *regset, int regbase =3D 0) { Regset regs; - return fetch_register_set (regcache, regnum, fetch_op, regset, ®s, - sizeof (regs)); + return fetch_register_set (regcache, regnum, fetch_op, regset, regbase, + ®s, sizeof (regs)); } =20 template bool store_register_set (struct regcache *regcache, int regnum, int fetc= h_op, - int store_op, const struct regset *regset) + int store_op, const struct regset *regset, + int regbase =3D 0) { Regset regs; return store_register_set (regcache, regnum, fetch_op, store_op, regse= t, - ®s, sizeof (regs)); + regbase, ®s, sizeof (regs)); } =20 /* Helper routine for use in read_description in subclasses. This @@ -197,18 +202,20 @@ protected: =20 template bool fetch_regset (struct regcache *regcache, int regnum, int note, - const struct regset *regset) + const struct regset *regset, int regbase =3D 0) { Regset regs; - return fetch_regset (regcache, regnum, note, regset, ®s, sizeof (re= gs)); + return fetch_regset (regcache, regnum, note, regset, regbase, ®s, + sizeof (regs)); } =20 template bool store_regset (struct regcache *regcache, int regnum, int note, - const struct regset *regset) + const struct regset *regset, int regbase =3D 0) { Regset regs; - return store_regset (regcache, regnum, note, regset, ®s, sizeof (re= gs)); + return store_regset (regcache, regnum, note, regset, regbase, ®s, + sizeof (regs)); } };