This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 3/11] Add MIPS_MAX_REGISTER_SIZE (2/4)
- From: Alan Hayward <Alan dot Hayward at arm dot com>
- To: Yao Qi <qiyaoltc at gmail dot com>
- Cc: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>, nd <nd at arm dot com>
- Date: Fri, 5 May 2017 08:04:04 +0000
- Subject: Re: [PATCH 3/11] Add MIPS_MAX_REGISTER_SIZE (2/4)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=arm.com;
- Nodisclaimer: True
- References: <3C00280E-37C9-4C0A-9DA6-F3B9DB1A6E8F@arm.com> <86y3v7uf9j.fsf@gmail.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
> On 11 Apr 2017, at 16:37, Yao Qi <qiyaoltc@gmail.com> wrote:
>
> Alan Hayward <Alan.Hayward@arm.com> writes:
>
> Hi Alan,
> There are different ways of getting rid of MAX_REGISTER_SIZE, let us try
> some simple approaches first. Some uses of MAX_REGISTER_SIZE still
> can't be removed, but let us start from easy part.
>
Patch split into multiple parts.
This part adds two new regcache functions: raw_supply_signed and
raw_collect_signed.
Tested on a --enable-targets=all build using make check with board files
unix and native-gdbserver.
I do not have a MIPS machine to test on.
Ok to commit?
2017-05-05 Alan Hayward <alan.hayward@arm.com>
* mips-fbsd-tdep.c (mips_fbsd_supply_reg): Use raw_supply_signed.
(mips_fbsd_collect_reg): Use raw_collect_signed.
* mips-linux-tdep.c (supply_32bit_reg): Use raw_supply_signed.
(mips64_fill_gregset): Use raw_collect_signed.
(mips64_fill_fpregset): Use raw_supply_signed.
* regcache.c (regcache::raw_supply_signed): New function.
(regcache::raw_collect_signed): New function.
* regcache.h (regcache::raw_supply_signed): New declaration.
(regcache::raw_collect_signed): New declaration.
Last login: Fri May 5 08:55:03 on ttys000
alahay01@C02N40NHFH04:~
[08:56:55] $ cat Downloads/rb7439.patch
diff --git a/gdb/mips-fbsd-tdep.c b/gdb/mips-fbsd-tdep.c
index 00fae0ec60ddc9e645d3236efe29f2f9e9ceab5c..4785bf9a115fa74fb7f48eac388a7e3df2f0304d 100644
--- a/gdb/mips-fbsd-tdep.c
+++ b/gdb/mips-fbsd-tdep.c
@@ -63,13 +63,10 @@ mips_fbsd_supply_reg (struct regcache *regcache, int regnum, const void *addr,
else
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
- gdb_byte buf[MAX_REGISTER_SIZE];
LONGEST val;
val = extract_signed_integer ((const gdb_byte *) addr, len, byte_order);
- store_signed_integer (buf, register_size (gdbarch, regnum), byte_order,
- val);
- regcache_raw_supply (regcache, regnum, buf);
+ regcache->raw_supply_signed (regnum, val);
}
}
@@ -90,12 +87,7 @@ mips_fbsd_collect_reg (const struct regcache *regcache, int regnum, void *addr,
else
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
- gdb_byte buf[MAX_REGISTER_SIZE];
- LONGEST val;
-
- regcache_raw_collect (regcache, regnum, buf);
- val = extract_signed_integer (buf, register_size (gdbarch, regnum),
- byte_order);
+ LONGEST val = regcache->raw_collect_signed (regnum);
store_signed_integer ((gdb_byte *) addr, len, byte_order, val);
}
}
diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
index 48a582a16c934abe6e8f87c46a6009649c606d49..5325d75420a71451b63cbadbf4e33d4fcf233fa4 100644
--- a/gdb/mips-linux-tdep.c
+++ b/gdb/mips-linux-tdep.c
@@ -118,11 +118,10 @@ supply_32bit_reg (struct regcache *regcache, int regnum, const void *addr)
{
struct gdbarch *gdbarch = get_regcache_arch (regcache);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
- gdb_byte buf[MAX_REGISTER_SIZE];
- store_signed_integer (buf, register_size (gdbarch, regnum), byte_order,
- extract_signed_integer ((const gdb_byte *) addr, 4,
- byte_order));
- regcache_raw_supply (regcache, regnum, buf);
+ LONGEST val;
+
+ val = extract_signed_integer ((const gdb_byte *) addr, 4, byte_order);
+ regcache->raw_supply_signed (regnum, val);
}
/* Unpack an elf_gregset_t into GDB's register cache. */
@@ -460,12 +459,7 @@ mips64_fill_gregset (const struct regcache *regcache,
if (regaddr != -1)
{
- gdb_byte buf[MAX_REGISTER_SIZE];
- LONGEST val;
-
- regcache_raw_collect (regcache, regno, buf);
- val = extract_signed_integer (buf, register_size (gdbarch, regno),
- byte_order);
+ LONGEST val = regcache->raw_collect_signed (regno);
dst = regp + regaddr;
store_signed_integer ((gdb_byte *) dst, 8, byte_order, val);
}
@@ -564,23 +558,13 @@ mips64_fill_fpregset (const struct regcache *regcache,
}
else if (regno == mips_regnum (gdbarch)->fp_control_status)
{
- gdb_byte buf[MAX_REGISTER_SIZE];
- LONGEST val;
-
- regcache_raw_collect (regcache, regno, buf);
- val = extract_signed_integer (buf, register_size (gdbarch, regno),
- byte_order);
+ LONGEST val = regcache->raw_collect_signed (regno);
to = (gdb_byte *) (*fpregsetp + 32);
store_signed_integer (to, 4, byte_order, val);
}
else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
{
- gdb_byte buf[MAX_REGISTER_SIZE];
- LONGEST val;
-
- regcache_raw_collect (regcache, regno, buf);
- val = extract_signed_integer (buf, register_size (gdbarch, regno),
- byte_order);
+ LONGEST val = regcache->raw_collect_signed (regno);
to = (gdb_byte *) (*fpregsetp + 32) + 4;
store_signed_integer (to, 4, byte_order, val);
}
diff --git a/gdb/regcache.h b/gdb/regcache.h
index 4dcfccbac70f0f962bf5e5596d035fda42322795..76f5bdfdf6cefd6d963be950aefcc275de7a820b 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -294,10 +294,14 @@ public:
void raw_collect (int regnum, void *buf) const;
+ LONGEST raw_collect_signed (int regnum) const;
+
void raw_supply (int regnum, const void *buf);
void raw_supply_zeroed (int regnum);
+ void raw_supply_signed (int regnum, LONGEST val);
+
void raw_copy (int regnum, struct regcache *src_regcache);
enum register_status get_register_status (int regnum) const;
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 957b265c28d929376c3b7d8c100ea355d8292b94..c9fbc997a3fa33fb576db7f57da4501043ff4e9d 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -1228,6 +1228,26 @@ regcache::raw_supply_zeroed (int regnum)
m_register_status[regnum] = REG_VALID;
}
+/* Supply register REGNUM, whose contents are stored in signed VAL, to
+ REGCACHE. */
+
+void
+regcache::raw_supply_signed (int regnum, LONGEST val)
+{
+ enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
+ gdb_byte *regbuf;
+ size_t size;
+
+ gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+ gdb_assert (!m_readonly_p);
+
+ regbuf = register_buffer (regnum);
+ size = m_descr->sizeof_register[regnum];
+
+ store_signed_integer (regbuf, size, byte_order, val);
+ m_register_status[regnum] = REG_VALID;
+}
+
/* Collect register REGNUM from REGCACHE and store its contents in BUF. */
void
@@ -1251,6 +1271,23 @@ regcache::raw_collect (int regnum, void *buf) const
memcpy (buf, regbuf, size);
}
+/* Collect register REGNUM from REGCACHE and extract its contents into a signed
+ LONGEST. */
+
+LONGEST
+regcache::raw_collect_signed (int regnum) const
+{
+ enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
+ const gdb_byte *regbuf;
+ size_t size;
+
+ gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+
+ regbuf = register_buffer (regnum);
+ size = m_descr->sizeof_register[regnum];
+ return extract_signed_integer (regbuf, size, byte_order);
+}
+
void
regcache::raw_copy (int regnum, struct regcache *src_regcache)
{