Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: Pedro Alves <palves@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/6] Add constructor and destructor to regcache
Date: Fri, 28 Apr 2017 13:42:00 -0000	[thread overview]
Message-ID: <86h918bqcs.fsf@gmail.com> (raw)
In-Reply-To: <24c71239-5b8f-5ca1-a140-146acef9c543@redhat.com> (Pedro Alves's	message of "Thu, 27 Apr 2017 18:34:03 +0100")

Pedro Alves <palves@redhat.com> writes:

>> +  explicit regcache (struct gdbarch *gdbarch, struct address_space *aspace_)
>> +    : regcache (gdbarch, aspace_, true)
>
> There's no real good reason to use "explicit" when you have more than
> one parameter.
>

Removed.

>> +
>> +private:
>> +  explicit regcache (struct gdbarch *gdbarch, struct address_space *aspace_,
>> +		     bool readonly_p_)
>
> Ditto.
>

Removed.

>> +    : aspace (aspace_), readonly_p (readonly_p_)
>> +  {
>> +    gdb_assert (gdbarch != NULL);
>> +    descr = regcache_descr (gdbarch);
>> +
>> +  if (readonly_p)
>> +    {
>> +      registers = XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers);
>> +      register_status = XCNEWVEC (signed char,
>> +				  descr->sizeof_cooked_register_status);
>> +    }
>> +  else
>> +    {
>> +      registers = XCNEWVEC (gdb_byte, descr->sizeof_raw_registers);
>> +      register_status = XCNEWVEC (signed char,
>> +				  descr->sizeof_raw_register_status);
>> +    }
>> +  ptid = minus_one_ptid;
>> +  }
>> +
>> +  friend struct regcache *
>> +  get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
>> +				   struct address_space *aspace);
>>  };
>
> (I'd drop the "struct" in the aspace parameters.)

Removed.

Patch below is pushed in.

-- 
Yao (齐尧)
From c35356d17072b89ae7d6b34c20f4b2cd69ed8468 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Thu, 20 Apr 2017 14:54:26 +0100
Subject: [PATCH] Add constructor and destructor to regcache

This patch adds ctor and dtor to regcache.

gdb:

2017-04-28  Yao Qi  <yao.qi@linaro.org>

	* regcache.c (regcache::regcache): New function.
	(regcache::~regcache): New function.
	(regcache_xmalloc_1): Remove.
	(regcache_xmalloc): Call new regcache.
	(regcache_xfree): Call delete regcache.
	(get_thread_arch_aspace_regcache): Call new regcache.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d99c5a2..efaf8bb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,14 @@
 2017-04-28  Yao Qi  <yao.qi@linaro.org>
 
+	* regcache.c (regcache::regcache): New function.
+	(regcache::~regcache): New function.
+	(regcache_xmalloc_1): Remove.
+	(regcache_xmalloc): Call new regcache.
+	(regcache_xfree): Call delete regcache.
+	(get_thread_arch_aspace_regcache): Call new regcache.
+
+2017-04-28  Yao Qi  <yao.qi@linaro.org>
+
 	* mips-linux-nat.c (mips_linux_new_thread): Use ptid method
 	lwp instead of ptid_get_lwp.
 
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 966f0c7..798812e 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -191,6 +191,17 @@ regcache_register_size (const struct regcache *regcache, int n)
 
 struct regcache
 {
+public:
+  regcache (gdbarch *gdbarch, address_space *aspace_)
+    : regcache (gdbarch, aspace_, true)
+  {}
+
+  ~regcache ()
+  {
+    xfree (registers);
+    xfree (register_status);
+  }
+
   struct regcache_descr *descr;
 
   /* The address space of this register cache (for registers where it
@@ -213,6 +224,32 @@ struct regcache
   /* If this is a read-write cache, which thread's registers is
      it connected to?  */
   ptid_t ptid;
+
+private:
+  regcache (gdbarch *gdbarch, address_space *aspace_, bool readonly_p_)
+    : aspace (aspace_), readonly_p (readonly_p_)
+  {
+    gdb_assert (gdbarch != NULL);
+    descr = regcache_descr (gdbarch);
+
+  if (readonly_p)
+    {
+      registers = XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers);
+      register_status = XCNEWVEC (signed char,
+				  descr->sizeof_cooked_register_status);
+    }
+  else
+    {
+      registers = XCNEWVEC (gdb_byte, descr->sizeof_raw_registers);
+      register_status = XCNEWVEC (signed char,
+				  descr->sizeof_raw_register_status);
+    }
+  ptid = minus_one_ptid;
+  }
+
+  friend regcache *
+  get_thread_arch_aspace_regcache (ptid_t ptid, gdbarch *gdbarch,
+				   address_space *aspace);
 };
 
 /* See regcache.h.  */
@@ -225,41 +262,10 @@ regcache_get_ptid (const struct regcache *regcache)
   return regcache->ptid;
 }
 
-static struct regcache *
-regcache_xmalloc_1 (struct gdbarch *gdbarch, struct address_space *aspace,
-		    bool readonly_p)
-{
-  struct regcache_descr *descr;
-  struct regcache *regcache;
-
-  gdb_assert (gdbarch != NULL);
-  descr = regcache_descr (gdbarch);
-  regcache = XNEW (struct regcache);
-  regcache->descr = descr;
-  regcache->readonly_p = readonly_p;
-  if (readonly_p)
-    {
-      regcache->registers
-	= XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers);
-      regcache->register_status
-	= XCNEWVEC (signed char, descr->sizeof_cooked_register_status);
-    }
-  else
-    {
-      regcache->registers
-	= XCNEWVEC (gdb_byte, descr->sizeof_raw_registers);
-      regcache->register_status
-	= XCNEWVEC (signed char, descr->sizeof_raw_register_status);
-    }
-  regcache->aspace = aspace;
-  regcache->ptid = minus_one_ptid;
-  return regcache;
-}
-
 struct regcache *
 regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace)
 {
-  return regcache_xmalloc_1 (gdbarch, aspace, true);
+  return new regcache (gdbarch, aspace);
 }
 
 void
@@ -267,9 +273,8 @@ regcache_xfree (struct regcache *regcache)
 {
   if (regcache == NULL)
     return;
-  xfree (regcache->registers);
-  xfree (regcache->register_status);
-  xfree (regcache);
+
+  delete regcache;
 }
 
 static void
@@ -507,7 +512,7 @@ get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
 	&& get_regcache_arch (list->regcache) == gdbarch)
       return list->regcache;
 
-  new_regcache = regcache_xmalloc_1 (gdbarch, aspace, false);
+  new_regcache = new regcache (gdbarch, aspace, false);
   new_regcache->ptid = ptid;
 
   list = XNEW (struct regcache_list);


  reply	other threads:[~2017-04-28 13:42 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-25 20:28 [PATCH 0/6] Class-fy regcache in GDB Yao Qi
2017-04-25 20:28 ` [PATCH 2/6] Add constructor and destructor to regcache Yao Qi
2017-04-27 17:34   ` Pedro Alves
2017-04-28 13:42     ` Yao Qi [this message]
2017-04-25 20:28 ` [PATCH 6/6] Remove cleanup in get_return_value Yao Qi
2017-04-25 20:28 ` [PATCH 1/6 OBV] Change readonly_p to bool Yao Qi
2017-04-25 20:28 ` [PATCH 4/6] Simplify regcache_dup Yao Qi
2017-04-25 20:29 ` [PATCH 3/6] Class-fy regcache Yao Qi
2017-04-27 17:35   ` Pedro Alves
2017-04-25 20:29 ` [PATCH 5/6] Use copy ctor in regcache_dup Yao Qi
2017-04-27 17:37   ` Pedro Alves
2017-04-28  9:11     ` Yao Qi
2017-04-28  9:51       ` Pedro Alves
2017-04-28 13:20         ` Yao Qi
2017-04-28 14:26 ` [PATCH 0/4 v2] Class-fy regcache in GDB Yao Qi
2017-04-28 14:26   ` [PATCH 2/4] Simplify regcache_dup Yao Qi
2017-04-28 15:03     ` Pedro Alves
2017-04-28 14:26   ` [PATCH 3/4] Use tag dispatch regcache ctor in regcache_dup Yao Qi
2017-04-28 15:04     ` Pedro Alves
2017-04-28 14:26   ` [PATCH 1/4] Class-fy regcache Yao Qi
2017-04-28 15:03     ` Pedro Alves
2017-04-28 21:44       ` Yao Qi
2017-04-28 14:26   ` [PATCH 4/4] Remove cleanup in get_return_value Yao Qi
2017-04-28 15:05     ` Pedro Alves

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=86h918bqcs.fsf@gmail.com \
    --to=qiyaoltc@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /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