public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 09/15] Remove regcache_save and regcache_cpy
Date: Fri, 01 Dec 2017 10:48:00 -0000	[thread overview]
Message-ID: <1512125286-29788-10-git-send-email-yao.qi@linaro.org> (raw)
In-Reply-To: <1512125286-29788-1-git-send-email-yao.qi@linaro.org>

... instead we start to use regcache methods save and restore.  It is
quite straightforward to replace regcache_save with regcache->save.

regcache_cpy has some asserts, some of them not necessary, like

 gdb_assert (src != dst);

because we already assert !m_readonly_p and src->m_readonly_p, so
src isn't dst.  Some of the asserts are moved to ::restore.

gdb:

2017-10-30  Yao Qi  <yao.qi@linaro.org>

	* frame.c (frame_save_as_regcache): Use regcache method save.
	(frame_pop): Use regcache method restore.
	* infrun.c (restore_infcall_suspend_state): Likewise.
	* linux-fork.c (fork_load_infrun_state): Likewise.
	* ppc-linux-tdep.c (ppu2spu_sniffer): User regcache method
	save.
	* regcache.c (regcache_save): Remove.
	(regcache::restore): More asserts.
	(regcache_cpy): Remove.
	* regcache.h (regcache_save): Remove the declaration.
	(regcache::restore): Move from private to public.
	Remove the friend declaration of regcache_cpy.
	(regcache_cpy): Remove declaration.
---
 gdb/frame.c          |  7 +++----
 gdb/infrun.c         |  2 +-
 gdb/linux-fork.c     |  2 +-
 gdb/ppc-linux-tdep.c |  2 +-
 gdb/regcache.c       | 22 ++++------------------
 gdb/regcache.h       | 30 +++++++++---------------------
 6 files changed, 19 insertions(+), 46 deletions(-)

diff --git a/gdb/frame.c b/gdb/frame.c
index e643823..4659cf5 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -1023,7 +1023,7 @@ frame_save_as_regcache (struct frame_info *this_frame)
   std::unique_ptr<struct regcache> regcache
     (new struct regcache (get_frame_arch (this_frame)));
 
-  regcache_save (regcache.get (), do_frame_register_read, this_frame);
+  regcache->save (do_frame_register_read, this_frame);
   return regcache;
 }
 
@@ -1068,9 +1068,8 @@ frame_pop (struct frame_info *this_frame)
      Unfortunately, they don't implement it.  Their lack of a formal
      definition can lead to targets writing back bogus values
      (arguably a bug in the target code mind).  */
-  /* Now copy those saved registers into the current regcache.
-     Here, regcache_cpy() calls regcache_restore().  */
-  regcache_cpy (get_current_regcache (), scratch.get ());
+  /* Now copy those saved registers into the current regcache.  */
+  get_current_regcache ()->restore (scratch.get ());
 
   /* We've made right mess of GDB's local state, just discard
      everything.  */
diff --git a/gdb/infrun.c b/gdb/infrun.c
index d7df3c7..5c128b5 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8867,7 +8867,7 @@ restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
      (and perhaps other times).  */
   if (target_has_execution)
     /* NB: The register write goes through to the target.  */
-    regcache_cpy (regcache, inf_state->registers);
+    regcache->restore (inf_state->registers);
 
   discard_infcall_suspend_state (inf_state);
 }
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index f55f743..5d05cb3 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -261,7 +261,7 @@ fork_load_infrun_state (struct fork_info *fp)
   linux_nat_switch_fork (fp->ptid);
 
   if (fp->savedregs && fp->clobber_regs)
-    regcache_cpy (get_current_regcache (), fp->savedregs);
+    get_current_regcache ()->restore (fp->savedregs);
 
   registers_changed ();
   reinit_frame_cache ();
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index 70e5b95..398ac24 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -1351,7 +1351,7 @@ ppu2spu_sniffer (const struct frame_unwind *self,
 	  std::unique_ptr<struct regcache> regcache
 	    (new struct regcache (data.gdbarch));
 
-	  regcache_save (regcache.get (), ppu2spu_unwind_register, &data);
+	  regcache->save (ppu2spu_unwind_register, &data);
 
 	  cache->frame_id = frame_id_build (base, func);
 	  cache->regcache = regcache.release ();
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 5ce6064..f4ef933 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -282,13 +282,6 @@ reg_buffer::register_buffer (int regnum) const
 }
 
 void
-regcache_save (struct regcache *regcache,
-	       regcache_cooked_read_ftype *cooked_read, void *src)
-{
-  regcache->save (cooked_read, src);
-}
-
-void
 regcache::save (regcache_cooked_read_ftype *cooked_read,
 		void *src)
 {
@@ -329,10 +322,14 @@ regcache::restore (struct regcache *src)
   struct gdbarch *gdbarch = m_descr->gdbarch;
   int regnum;
 
+  gdb_assert (src != NULL);
   /* The dst had better not be read-only.  If it is, the `restore'
      doesn't make much sense.  */
   gdb_assert (!m_readonly_p);
   gdb_assert (src->m_readonly_p);
+
+  gdb_assert (gdbarch == src->arch ());
+
   /* Copy over any registers, being careful to only restore those that
      were both saved and need to be restored.  The full [0 .. gdbarch_num_regs
      + gdbarch_num_pseudo_regs) range is checked since some architectures need
@@ -347,17 +344,6 @@ regcache::restore (struct regcache *src)
     }
 }
 
-void
-regcache_cpy (struct regcache *dst, struct regcache *src)
-{
-  gdb_assert (src != NULL && dst != NULL);
-  gdb_assert (src->m_descr->gdbarch == dst->m_descr->gdbarch);
-  gdb_assert (src != dst);
-  gdb_assert (src->m_readonly_p && !dst->m_readonly_p);
-
-  dst->restore (src);
-}
-
 struct regcache *
 regcache_dup (struct regcache *src)
 {
diff --git a/gdb/regcache.h b/gdb/regcache.h
index b107bbd..d8054b2 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -198,20 +198,10 @@ extern struct type *register_type (struct gdbarch *gdbarch, int regnum);
    
 extern int register_size (struct gdbarch *gdbarch, int regnum);
 
-
-/* Save/restore a register cache.  The set of registers saved /
-   restored into the DST regcache determined by the save_reggroup /
-   restore_reggroup respectively.  COOKED_READ returns zero iff the
-   register's value can't be returned.  */
-
 typedef enum register_status (regcache_cooked_read_ftype) (void *src,
 							   int regnum,
 							   gdb_byte *buf);
 
-extern void regcache_save (struct regcache *dst,
-			   regcache_cooked_read_ftype *cooked_read,
-			   void *cooked_read_context);
-
 enum regcache_dump_what
 {
   regcache_dump_none, regcache_dump_raw,
@@ -315,7 +305,14 @@ public:
     return m_aspace;
   }
 
+/* Save/restore a register cache.  The set of registers saved /
+   restored into the regcache determined by the save_reggroup /
+   restore_reggroup respectively.  COOKED_READ returns zero iff the
+   register's value can't be returned.  */
   void save (regcache_cooked_read_ftype *cooked_read, void *src);
+  /* Writes to regcache will go through to the target.  SRC is a
+     read-only register cache.  */
+  void restore (struct regcache *src);
 
   void cooked_write (int regnum, const gdb_byte *buf);
 
@@ -381,7 +378,6 @@ protected:
   static std::forward_list<regcache *> current_regcache;
 
 private:
-  void restore (struct regcache *src);
 
   void transfer_regset (const struct regset *regset,
 			struct regcache *out_regcache,
@@ -399,9 +395,8 @@ private:
   /* 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
-     cache can only be updated via the methods regcache_dup() and
-     regcache_cpy().  The actual contents are determined by the
-     reggroup_save and reggroup_restore methods.  */
+     cache can only be created via a constructor.  The actual contents
+     are determined by the save and restore methods.  */
   const bool m_readonly_p;
   /* If this is a read-write cache, which thread's registers is
      it connected to?  */
@@ -413,19 +408,12 @@ private:
 
   friend void
   registers_changed_ptid (ptid_t ptid);
-
-  friend void
-  regcache_cpy (struct regcache *dst, struct regcache *src);
 };
 
 /* Duplicate the contents of a register cache to a read-only register
    cache.  The operation is pass-through.  */
 extern struct regcache *regcache_dup (struct regcache *regcache);
 
-/* Writes to DEST will go through to the target.  SRC is a read-only
-   register cache.  */
-extern void regcache_cpy (struct regcache *dest, struct regcache *src);
-
 extern void registers_changed (void);
 extern void registers_changed_ptid (ptid_t);
 
-- 
1.9.1

  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 15/15] Move register_dump to regcache-dump.c 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 13/15] No longer create readonly regcache Yao Qi
2017-12-01 10:48 ` [PATCH 05/15] regcache_cooked_read -> regcache->cooked_read Yao Qi
2017-12-01 10:48 ` [PATCH 03/15] Remove mt port 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 ` [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 11/15] Class reg_buffer_rw Yao Qi
2017-12-01 10:48 ` [PATCH 14/15] Remove regcache::m_readonly_p 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 12/15] Replace regcache::dump with class register_dump Yao Qi
2017-12-01 10:48 ` [PATCH 07/15] Class reg_buffer Yao Qi
2017-12-01 10:48 ` Yao Qi [this message]
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 04/15] Replace regcache_raw_read with regcache->raw_read Yao Qi
2018-01-16 16:18 ` [RFC 00/15] Remove regcache::m_readonly_p 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-10-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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).