From: Yao Qi <qiyaoltc@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 07/15] Class reg_buffer
Date: Fri, 01 Dec 2017 10:48:00 -0000 [thread overview]
Message-ID: <1512125286-29788-8-git-send-email-yao.qi@linaro.org> (raw)
In-Reply-To: <1512125286-29788-1-git-send-email-yao.qi@linaro.org>
This patch adds a new class reg_buffer, and regcache inherits it. Class
reg_buffer is a very simple class, which has the buffer for register
contents and status only. It doesn't have any methods to set contents and
status, and it is expected that its children classes can inherit it and
add different access methods.
Another reason I keep class reg_buffer so simple is that I think
reg_buffer can be even reused in other classes which need to record the
registers contents and status, like frame cache for example.
gdb:
2017-11-27 Yao Qi <yao.qi@linaro.org>
* regcache.c (regcache::regcache): Call reg_buffer ctor.
(regcache::arch): Move it to reg_buffer::arch.
(regcache::register_buffer): Likewise.
(regcache::assert_regnum): Likewise.
(regcache::num_raw_registers): Likewise.
* regcache.h (reg_buffer): New class.
(regcache): Inherit reg_buffer.
---
gdb/regcache.c | 31 ++++++++++++++++++++---------
gdb/regcache.h | 62 ++++++++++++++++++++++++++++++++++------------------------
2 files changed, 58 insertions(+), 35 deletions(-)
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 4577913..8cc9c98 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -181,14 +181,13 @@ regcache_register_size (const struct regcache *regcache, int n)
return register_size (regcache->arch (), n);
}
-regcache::regcache (gdbarch *gdbarch, const address_space *aspace_,
- bool readonly_p_)
- : m_aspace (aspace_), m_readonly_p (readonly_p_)
+reg_buffer::reg_buffer (gdbarch *gdbarch, bool has_pseudo)
+ : m_has_pseudo (has_pseudo)
{
gdb_assert (gdbarch != NULL);
m_descr = regcache_descr (gdbarch);
- if (m_readonly_p)
+ if (has_pseudo)
{
m_registers = XCNEWVEC (gdb_byte, m_descr->sizeof_cooked_registers);
m_register_status = XCNEWVEC (signed char,
@@ -199,6 +198,16 @@ regcache::regcache (gdbarch *gdbarch, const address_space *aspace_,
m_registers = XCNEWVEC (gdb_byte, m_descr->sizeof_raw_registers);
m_register_status = XCNEWVEC (signed char, gdbarch_num_regs (gdbarch));
}
+}
+
+regcache::regcache (gdbarch *gdbarch, const address_space *aspace_,
+ bool readonly_p_)
+/* The register buffers. A read-only register cache can hold the
+ full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a
+ read/write register cache can only hold [0 .. gdbarch_num_regs). */
+ : reg_buffer (gdbarch, readonly_p_),
+ m_aspace (aspace_), m_readonly_p (readonly_p_)
+{
m_ptid = minus_one_ptid;
}
@@ -218,7 +227,7 @@ regcache::regcache (readonly_t, const regcache &src)
}
gdbarch *
-regcache::arch () const
+reg_buffer::arch () const
{
return m_descr->gdbarch;
}
@@ -267,7 +276,7 @@ private:
/* Return a pointer to register REGNUM's buffer cache. */
gdb_byte *
-regcache::register_buffer (int regnum) const
+reg_buffer::register_buffer (int regnum) const
{
return m_registers + m_descr->register_offset[regnum];
}
@@ -390,9 +399,13 @@ regcache::invalidate (int regnum)
}
void
-regcache::assert_regnum (int regnum) const
+reg_buffer::assert_regnum (int regnum) const
{
- gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (arch ()));
+ gdb_assert (regnum >= 0);
+ if (m_has_pseudo)
+ gdb_assert (regnum < m_descr->nr_cooked_registers);
+ else
+ gdb_assert (regnum < gdbarch_num_regs (arch ()));
}
/* Global structure containing the current regcache. */
@@ -1272,7 +1285,7 @@ regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
}
int
-regcache::num_raw_registers () const
+reg_buffer::num_raw_registers () const
{
return gdbarch_num_regs (arch ());
}
diff --git a/gdb/regcache.h b/gdb/regcache.h
index c5ef41b..a133de1 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -227,9 +227,44 @@ typedef struct cached_reg
gdb_byte *data;
} cached_reg_t;
+/* Buffer of registers. */
+
+class reg_buffer
+{
+public:
+ reg_buffer (gdbarch *gdbarch, bool has_pseudo);
+
+ DISABLE_COPY_AND_ASSIGN (reg_buffer);
+
+ /* Return regcache's architecture. */
+ gdbarch *arch () const;
+
+ virtual ~reg_buffer ()
+ {
+ xfree (m_registers);
+ xfree (m_register_status);
+ }
+
+protected:
+ /* Assert on the range of REGNUM. */
+ void assert_regnum (int regnum) const;
+
+ int num_raw_registers () const;
+
+ gdb_byte *register_buffer (int regnum) const;
+
+ struct regcache_descr *m_descr;
+
+ bool m_has_pseudo;
+ /* The register buffers. */
+ gdb_byte *m_registers;
+ /* Register cache status. */
+ signed char *m_register_status;
+};
+
/* The register cache for storing raw register values. */
-class regcache
+class regcache : public reg_buffer
{
public:
regcache (gdbarch *gdbarch)
@@ -244,15 +279,6 @@ public:
DISABLE_COPY_AND_ASSIGN (regcache);
- ~regcache ()
- {
- xfree (m_registers);
- xfree (m_register_status);
- }
-
- /* Return regcache's architecture. */
- gdbarch *arch () const;
-
/* Return REGCACHE's address space. */
const address_space *aspace () const
{
@@ -339,14 +365,9 @@ public:
static void regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid);
protected:
regcache (gdbarch *gdbarch, const address_space *aspace_, bool readonly_p_);
-
- int num_raw_registers () const;
-
static std::forward_list<regcache *> current_regcache;
private:
- gdb_byte *register_buffer (int regnum) const;
-
void restore (struct regcache *src);
enum register_status xfer_part (int regnum, int offset, int len, void *in,
@@ -357,21 +378,10 @@ 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
makes sense, like PC or SP). */
const address_space * const m_aspace;
- /* The register buffers. A read-only register cache can hold the
- full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write
- register cache can only hold [0 .. gdbarch_num_regs). */
- gdb_byte *m_registers;
- /* Register cache status. */
- signed char *m_register_status;
/* Is this a read-only cache? A read-only cache is used for saving
the target's register state (e.g, across an inferior function
call or just before forcing a function return). A read-only
--
1.9.1
next prev parent reply other threads:[~2017-12-01 10:48 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-01 10:48 [RFC 00/15] Remove regcache::m_readonly_p Yao Qi
2017-12-01 10:48 ` [PATCH 06/15] regcache::cooked_write test Yao Qi
2018-01-18 16:13 ` Simon Marchi
2018-01-22 11:12 ` Yao Qi
2017-12-01 10:48 ` [PATCH 09/15] Remove regcache_save and regcache_cpy Yao Qi
2017-12-01 10:48 ` [PATCH 01/15] Call cooked_read in ppu2spu_prev_register Yao Qi
2018-01-16 16:19 ` Yao Qi
2018-01-16 18:05 ` Ulrich Weigand
2018-01-18 12:22 ` Yao Qi
2017-12-01 10:48 ` [PATCH 10/15] Class regcache_readonly Yao Qi
2018-01-24 3:05 ` Simon Marchi
2018-01-24 9:43 ` Yao Qi
2018-01-24 16:57 ` Simon Marchi
2018-01-24 17:37 ` Yao Qi
2018-01-24 18:01 ` Simon Marchi
2018-01-24 21:01 ` Yao Qi
2017-12-01 10:48 ` [PATCH 05/15] regcache_cooked_read -> regcache->cooked_read Yao Qi
2017-12-01 10:48 ` [PATCH 13/15] No longer create readonly regcache Yao Qi
2017-12-01 10:48 ` [PATCH 15/15] Move register_dump to regcache-dump.c Yao Qi
2017-12-01 10:48 ` [PATCH 03/15] Remove mt port Yao Qi
2017-12-01 10:48 ` [PATCH 12/15] Replace regcache::dump with class register_dump Yao Qi
2017-12-01 10:48 ` [PATCH 08/15] class regcache_read and Pass regcache_read to gdbarch methods Yao Qi
2018-01-23 21:51 ` Simon Marchi
2018-01-23 22:28 ` Yao Qi
2017-12-01 10:48 ` [PATCH 02/15] Don't call gdbarch_pseudo_register_read_value in jit.c Yao Qi
2017-12-01 10:48 ` Yao Qi [this message]
2017-12-01 10:48 ` [PATCH 11/15] Class reg_buffer_rw Yao Qi
2017-12-01 10:48 ` [PATCH 04/15] Replace regcache_raw_read with regcache->raw_read Yao Qi
2017-12-01 10:48 ` [PATCH 14/15] Remove regcache::m_readonly_p Yao Qi
2018-01-16 16:18 ` [RFC 00/15] " Yao Qi
2018-01-18 16:56 ` Simon Marchi
2018-01-22 14:58 ` 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=1512125286-29788-8-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