New method regcache::assert_regnum

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-11-02  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.
This commit is contained in:
Yao Qi 2017-11-02 15:15:41 +00:00
parent 2e1b49b32a
commit 4e888c281c
3 changed files with 36 additions and 13 deletions

View File

@ -1,3 +1,18 @@
2017-11-02 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.
2017-11-02 Yao Qi <yao.qi@linaro.org> 2017-11-02 Yao Qi <yao.qi@linaro.org>
* regcache.c (regcache::dump): Remove code. * regcache.c (regcache::dump): Remove code.

View File

@ -393,12 +393,17 @@ regcache_invalidate (struct regcache *regcache, int regnum)
void void
regcache::invalidate (int regnum) regcache::invalidate (int regnum)
{ {
gdb_assert (regnum >= 0);
gdb_assert (!m_readonly_p); gdb_assert (!m_readonly_p);
gdb_assert (regnum < m_descr->nr_raw_registers); assert_regnum (regnum);
m_register_status[regnum] = REG_UNKNOWN; 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. */ /* Global structure containing the current regcache. */
/* NOTE: this is a write-through cache. There is no "dirty" bit for /* 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 void
regcache::raw_update (int regnum) 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 /* Make certain that the register cache is up-to-date with respect
to the current thread. This switching shouldn't be necessary to the current thread. This switching shouldn't be necessary
@ -600,7 +605,7 @@ regcache::raw_read (int regnum, T *val)
gdb_byte *buf; gdb_byte *buf;
enum register_status status; 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]); buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
status = raw_read (regnum, buf); status = raw_read (regnum, buf);
if (status == REG_VALID) if (status == REG_VALID)
@ -633,7 +638,7 @@ regcache::raw_write (int regnum, T val)
{ {
gdb_byte *buf; 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]); buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
store_integer (buf, m_descr->sizeof_register[regnum], store_integer (buf, m_descr->sizeof_register[regnum],
gdbarch_byte_order (m_descr->gdbarch), val); 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 (buf != NULL);
gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); assert_regnum (regnum);
gdb_assert (!m_readonly_p); gdb_assert (!m_readonly_p);
/* On the sparc, writing %g0 is a no-op, so we don't even want to /* 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 enum register_status
regcache::raw_read_part (int regnum, int offset, int len, gdb_byte *buf) 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); return xfer_part (regnum, offset, len, buf, NULL, true);
} }
@ -968,7 +973,7 @@ void
regcache::raw_write_part (int regnum, int offset, int len, regcache::raw_write_part (int regnum, int offset, int len,
const gdb_byte *buf) 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); xfer_part (regnum, offset, len, NULL, buf, true);
} }
@ -1017,7 +1022,7 @@ regcache::raw_supply (int regnum, const void *buf)
void *regbuf; void *regbuf;
size_t size; size_t size;
gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); assert_regnum (regnum);
gdb_assert (!m_readonly_p); gdb_assert (!m_readonly_p);
regbuf = register_buffer (regnum); regbuf = register_buffer (regnum);
@ -1052,7 +1057,7 @@ regcache::raw_supply_integer (int regnum, const gdb_byte *addr, int addr_len,
gdb_byte *regbuf; gdb_byte *regbuf;
size_t regsize; size_t regsize;
gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); assert_regnum (regnum);
gdb_assert (!m_readonly_p); gdb_assert (!m_readonly_p);
regbuf = register_buffer (regnum); regbuf = register_buffer (regnum);
@ -1073,7 +1078,7 @@ regcache::raw_supply_zeroed (int regnum)
void *regbuf; void *regbuf;
size_t size; size_t size;
gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); assert_regnum (regnum);
gdb_assert (!m_readonly_p); gdb_assert (!m_readonly_p);
regbuf = register_buffer (regnum); regbuf = register_buffer (regnum);
@ -1099,7 +1104,7 @@ regcache::raw_collect (int regnum, void *buf) const
size_t size; size_t size;
gdb_assert (buf != NULL); gdb_assert (buf != NULL);
gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); assert_regnum (regnum);
regbuf = register_buffer (regnum); regbuf = register_buffer (regnum);
size = m_descr->sizeof_register[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; const gdb_byte *regbuf;
size_t regsize; size_t regsize;
gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); assert_regnum (regnum);
regbuf = register_buffer (regnum); regbuf = register_buffer (regnum);
regsize = m_descr->sizeof_register[regnum]; regsize = m_descr->sizeof_register[regnum];

View File

@ -358,6 +358,9 @@ private:
int regnum, const void *in_buf, int regnum, const void *in_buf,
void *out_buf, size_t size) const; void *out_buf, size_t size) const;
/* Assert on the range of REGNUM. */
void assert_regnum (int regnum) const;
struct regcache_descr *m_descr; struct regcache_descr *m_descr;
/* The address space of this register cache (for registers where it /* The address space of this register cache (for registers where it