This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Move current_regcache to regcache::current_regcache


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e521e87e8514b9d3497208b70bcd067f132c58ed

commit e521e87e8514b9d3497208b70bcd067f132c58ed
Author: Yao Qi <yao.qi@linaro.org>
Date:   Wed May 24 22:15:23 2017 +0100

    Move current_regcache to regcache::current_regcache
    
    This patches moves global variable current_regcache to a class regcache
    static variable (protected) so that the unit test I add in the following
    patch can access it (by means of extending class regcache in unit test).
    
    gdb:
    
    2017-05-24  Yao Qi  <yao.qi@linaro.org>
    
    	* regcache.c (current_regcache): Change it to
    	regcache::current_regcache.
    	(regcache_observer_target_changed): Update.
    	(regcache_thread_ptid_changed): Make it a regcache static
    	method.
    	(regcache_thread_ptid_changed): Update.
    	(class regcache_access): New.
    	(current_regcache_test): Update.
    	(_initialize_regcache): Update.
    	* regcache.h: Include forward_list.
    	(regcache): Declare regcache_thread_ptid_changed and declare
    	registers_changed_ptid as friend.

Diff:
---
 gdb/ChangeLog  | 15 +++++++++++++++
 gdb/regcache.c | 51 ++++++++++++++++++++++++++++-----------------------
 gdb/regcache.h | 10 +++++++++-
 3 files changed, 52 insertions(+), 24 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ea75f07..fc09819 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,20 @@
 2017-05-24  Yao Qi  <yao.qi@linaro.org>
 
+	* regcache.c (current_regcache): Change it to
+	regcache::current_regcache.
+	(regcache_observer_target_changed): Update.
+	(regcache_thread_ptid_changed): Make it a regcache static
+	method.
+	(regcache_thread_ptid_changed): Update.
+	(class regcache_access): New.
+	(current_regcache_test): Update.
+	(_initialize_regcache): Update.
+	* regcache.h: Include forward_list.
+	(regcache): Declare regcache_thread_ptid_changed and declare
+	registers_changed_ptid as friend.
+
+2017-05-24  Yao Qi  <yao.qi@linaro.org>
+
 	* i387-tdep.c (i387_register_to_value): Use register_size
 	instead of TYPE_LENGTH.
 	* m68k-tdep.c (m68k_register_to_value): Likewise.
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 7250763..7638eea 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -472,20 +472,19 @@ regcache::invalidate (int regnum)
    recording if the register values have been changed (eg. by the
    user).  Therefore all registers must be written back to the
    target when appropriate.  */
-
-static std::forward_list<regcache *> current_regcache;
+std::forward_list<regcache *> regcache::current_regcache;
 
 struct regcache *
 get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
 				 struct address_space *aspace)
 {
-  for (const auto &regcache : current_regcache)
+  for (const auto &regcache : regcache::current_regcache)
     if (ptid_equal (regcache->ptid (), ptid) && regcache->arch () == gdbarch)
       return regcache;
 
   regcache *new_regcache = new regcache (gdbarch, aspace, false);
 
-  current_regcache.push_front (new_regcache);
+  regcache::current_regcache.push_front (new_regcache);
   new_regcache->set_ptid (ptid);
 
   return new_regcache;
@@ -548,10 +547,10 @@ regcache_observer_target_changed (struct target_ops *target)
 
 /* Update global variables old ptids to hold NEW_PTID if they were
    holding OLD_PTID.  */
-static void
-regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
+void
+regcache::regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
 {
-  for (auto &regcache : current_regcache)
+  for (auto &regcache : regcache::current_regcache)
     {
       if (ptid_equal (regcache->ptid (), old_ptid))
 	regcache->set_ptid (new_ptid);
@@ -572,15 +571,15 @@ regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
 void
 registers_changed_ptid (ptid_t ptid)
 {
-  for (auto oit = current_regcache.before_begin (),
+  for (auto oit = regcache::current_regcache.before_begin (),
 	 it = std::next (oit);
-       it != current_regcache.end ();
+       it != regcache::current_regcache.end ();
        )
     {
       if (ptid_match ((*it)->ptid (), ptid))
 	{
 	  delete *it;
-	  it = current_regcache.erase_after (oit);
+	  it = regcache::current_regcache.erase_after (oit);
 	}
       else
 	oit = it++;
@@ -1685,19 +1684,25 @@ maintenance_print_remote_registers (char *args, int from_tty)
 
 namespace selftests {
 
-/* Return the number of elements in current_regcache.  */
-
-static size_t
-current_regcache_size ()
+class regcache_access : public regcache
 {
-  return std::distance (current_regcache.begin (), current_regcache.end ());
-}
+public:
+
+  /* Return the number of elements in current_regcache.  */
+
+  static size_t
+  current_regcache_size ()
+  {
+    return std::distance (regcache::current_regcache.begin (),
+			  regcache::current_regcache.end ());
+  }
+};
 
 static void
 current_regcache_test (void)
 {
   /* It is empty at the start.  */
-  SELF_CHECK (current_regcache_size () == 0);
+  SELF_CHECK (regcache_access::current_regcache_size () == 0);
 
   ptid_t ptid1 (1), ptid2 (2), ptid3 (3);
 
@@ -1709,7 +1714,7 @@ current_regcache_test (void)
 
   SELF_CHECK (regcache != NULL);
   SELF_CHECK (regcache->ptid () == ptid1);
-  SELF_CHECK (current_regcache_size () == 1);
+  SELF_CHECK (regcache_access::current_regcache_size () == 1);
 
   /* Get regcache from ptid2, a new regcache is added to
      current_regcache.  */
@@ -1718,7 +1723,7 @@ current_regcache_test (void)
 					      NULL);
   SELF_CHECK (regcache != NULL);
   SELF_CHECK (regcache->ptid () == ptid2);
-  SELF_CHECK (current_regcache_size () == 2);
+  SELF_CHECK (regcache_access::current_regcache_size () == 2);
 
   /* Get regcache from ptid3, a new regcache is added to
      current_regcache.  */
@@ -1727,7 +1732,7 @@ current_regcache_test (void)
 					      NULL);
   SELF_CHECK (regcache != NULL);
   SELF_CHECK (regcache->ptid () == ptid3);
-  SELF_CHECK (current_regcache_size () == 3);
+  SELF_CHECK (regcache_access::current_regcache_size () == 3);
 
   /* Get regcache from ptid2 again, nothing is added to
      current_regcache.  */
@@ -1736,12 +1741,12 @@ current_regcache_test (void)
 					      NULL);
   SELF_CHECK (regcache != NULL);
   SELF_CHECK (regcache->ptid () == ptid2);
-  SELF_CHECK (current_regcache_size () == 3);
+  SELF_CHECK (regcache_access::current_regcache_size () == 3);
 
   /* Mark ptid2 is changed, so regcache of ptid2 should be removed from
      current_regcache.  */
   registers_changed_ptid (ptid2);
-  SELF_CHECK (current_regcache_size () == 2);
+  SELF_CHECK (regcache_access::current_regcache_size () == 2);
 }
 
 } // namespace selftests
@@ -1756,7 +1761,7 @@ _initialize_regcache (void)
     = gdbarch_data_register_post_init (init_regcache_descr);
 
   observer_attach_target_changed (regcache_observer_target_changed);
-  observer_attach_thread_ptid_changed (regcache_thread_ptid_changed);
+  observer_attach_thread_ptid_changed (regcache::regcache_thread_ptid_changed);
 
   add_com ("flushregs", class_maintenance, reg_flush_command,
 	   _("Force gdb to flush its register cache (maintainer command)"));
diff --git a/gdb/regcache.h b/gdb/regcache.h
index da00abd..fdc47ba 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -21,6 +21,7 @@
 #define REGCACHE_H
 
 #include "common-regcache.h"
+#include <forward_list>
 
 struct regcache;
 struct regset;
@@ -336,9 +337,13 @@ public:
    debug.  */
   void debug_print_register (const char *func, int regno);
 
-private:
+  static void regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid);
+protected:
   regcache (gdbarch *gdbarch, address_space *aspace_, bool readonly_p_);
 
+  static std::forward_list<regcache *> current_regcache;
+
+private:
   gdb_byte *register_buffer (int regnum) const;
 
   void restore (struct regcache *src);
@@ -383,6 +388,9 @@ private:
 				   struct address_space *aspace);
 
   friend void
+  registers_changed_ptid (ptid_t ptid);
+
+  friend void
   regcache_cpy (struct regcache *dst, struct regcache *src);
 };


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]