From: Yao Qi <qiyaoltc@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/8] New method regcache::assert_regnum
Date: Fri, 27 Oct 2017 09:31:00 -0000 [thread overview]
Message-ID: <1509096702-12202-4-git-send-email-yao.qi@linaro.org> (raw)
In-Reply-To: <1509096702-12202-1-git-send-email-yao.qi@linaro.org>
class regcache has some methods checking the range of register number,
this patch is to move it in a new method assert_regnum.
gdb:
2017-10-19 Yao Qi <yao.qi@linaro.org>
* regcache.c (regcache::assert_regnum): New method.
(regcache::invalidate): Call assert_regnum.
(regcache::raw_update): Likewise.
(regcache::raw_write): Likewise.
(regcache::raw_read_part): Likewise.
(regcache::raw_write_part): Likewise.
(regcache::raw_supply): Likewise.
(regcache::raw_supply_integer): Likewise.
(regcache::raw_supply_zeroed): Likewise.
(regcache::raw_collect): Likewise.
(regcache::raw_collect_integer): Likewise.
* regcache.h (regcache::assert_regnum): Declare.
---
gdb/regcache.c | 31 ++++++++++++++++++-------------
gdb/regcache.h | 3 +++
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 0d3fe3d..0aee934 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -393,12 +393,17 @@ regcache_invalidate (struct regcache *regcache, int regnum)
void
regcache::invalidate (int regnum)
{
- gdb_assert (regnum >= 0);
gdb_assert (!m_readonly_p);
- gdb_assert (regnum < m_descr->nr_raw_registers);
+ assert_regnum (regnum);
m_register_status[regnum] = REG_UNKNOWN;
}
+void
+regcache::assert_regnum (int regnum) const
+{
+ gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+}
+
/* Global structure containing the current regcache. */
/* NOTE: this is a write-through cache. There is no "dirty" bit for
@@ -546,7 +551,7 @@ regcache_raw_update (struct regcache *regcache, int regnum)
void
regcache::raw_update (int regnum)
{
- gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+ assert_regnum (regnum);
/* Make certain that the register cache is up-to-date with respect
to the current thread. This switching shouldn't be necessary
@@ -600,7 +605,7 @@ regcache::raw_read (int regnum, T *val)
gdb_byte *buf;
enum register_status status;
- gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+ assert_regnum (regnum);
buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
status = raw_read (regnum, buf);
if (status == REG_VALID)
@@ -633,7 +638,7 @@ regcache::raw_write (int regnum, T val)
{
gdb_byte *buf;
- gdb_assert (regnum >=0 && regnum < m_descr->nr_raw_registers);
+ assert_regnum (regnum);
buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
store_integer (buf, m_descr->sizeof_register[regnum],
gdbarch_byte_order (m_descr->gdbarch), val);
@@ -844,7 +849,7 @@ regcache::raw_write (int regnum, const gdb_byte *buf)
{
gdb_assert (buf != NULL);
- gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+ assert_regnum (regnum);
gdb_assert (!m_readonly_p);
/* On the sparc, writing %g0 is a no-op, so we don't even want to
@@ -953,7 +958,7 @@ regcache_raw_read_part (struct regcache *regcache, int regnum,
enum register_status
regcache::raw_read_part (int regnum, int offset, int len, gdb_byte *buf)
{
- gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+ assert_regnum (regnum);
return xfer_part (regnum, offset, len, buf, NULL, true);
}
@@ -968,7 +973,7 @@ void
regcache::raw_write_part (int regnum, int offset, int len,
const gdb_byte *buf)
{
- gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+ assert_regnum (regnum);
xfer_part (regnum, offset, len, NULL, buf, true);
}
@@ -1017,7 +1022,7 @@ regcache::raw_supply (int regnum, const void *buf)
void *regbuf;
size_t size;
- gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+ assert_regnum (regnum);
gdb_assert (!m_readonly_p);
regbuf = register_buffer (regnum);
@@ -1052,7 +1057,7 @@ regcache::raw_supply_integer (int regnum, const gdb_byte *addr, int addr_len,
gdb_byte *regbuf;
size_t regsize;
- gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+ assert_regnum (regnum);
gdb_assert (!m_readonly_p);
regbuf = register_buffer (regnum);
@@ -1073,7 +1078,7 @@ regcache::raw_supply_zeroed (int regnum)
void *regbuf;
size_t size;
- gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+ assert_regnum (regnum);
gdb_assert (!m_readonly_p);
regbuf = register_buffer (regnum);
@@ -1099,7 +1104,7 @@ regcache::raw_collect (int regnum, void *buf) const
size_t size;
gdb_assert (buf != NULL);
- gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+ assert_regnum (regnum);
regbuf = register_buffer (regnum);
size = m_descr->sizeof_register[regnum];
@@ -1124,7 +1129,7 @@ regcache::raw_collect_integer (int regnum, gdb_byte *addr, int addr_len,
const gdb_byte *regbuf;
size_t regsize;
- gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
+ assert_regnum (regnum);
regbuf = register_buffer (regnum);
regsize = m_descr->sizeof_register[regnum];
diff --git a/gdb/regcache.h b/gdb/regcache.h
index 0eea042..6fb790d 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -358,6 +358,9 @@ private:
int regnum, const void *in_buf,
void *out_buf, size_t size) const;
+ /* Assert on the range of REGNUM. */
+ void assert_regnum (int regnum) const;
+
struct regcache_descr *m_descr;
/* The address space of this register cache (for registers where it
--
1.9.1
next prev parent reply other threads:[~2017-10-27 9:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-27 9:31 [PATCH 0/8] regcache misc cleanup and refactor Yao Qi
2017-10-27 9:31 ` Yao Qi [this message]
2017-10-27 9:31 ` [PATCH 4/8] Remove regcache_descr::nr_raw_registers Yao Qi
2017-10-31 14:27 ` Simon Marchi
2017-11-02 15:20 ` Yao Qi
2017-10-27 9:31 ` [PATCH 1/8] Remove regcache_descr fields sizeof_raw_register_status and sizeof_cooked_register_status Yao Qi
2017-10-27 9:32 ` [PATCH 7/8] const-fy regcache::m_readonly_p Yao Qi
2017-10-27 9:32 ` [PATCH 6/8] const-fy regcache::m_aspace Yao Qi
2017-10-31 14:19 ` Simon Marchi
2017-11-01 9:43 ` Yao Qi
2017-11-01 14:00 ` Simon Marchi
2017-11-01 14:35 ` Yao Qi
2017-10-27 9:32 ` [PATCH 8/8] Construct readonly regcache without address space Yao Qi
2017-10-31 14:35 ` Simon Marchi
[not found] ` <CAH=s-PMFXtwS-3J9et_onyEOCUL9P-AgO9V=pBt60neQn67g9g@mail.gmail.com>
2017-10-31 18:04 ` Simon Marchi
2017-10-27 9:32 ` [PATCH 5/8] s/get_regcache_aspace (regcache)/regcache->aspace ()/g Yao Qi
2017-10-27 9:32 ` [PATCH 2/8] Remove code wrapped by "#if 0" Yao Qi
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=1509096702-12202-4-git-send-email-yao.qi@linaro.org \
--to=qiyaoltc@gmail.com \
--cc=gdb-patches@sourceware.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