From patchwork Tue Apr 25 20:28:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 20154 Received: (qmail 117039 invoked by alias); 25 Apr 2017 20:28:41 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 116949 invoked by uid 89); 25 Apr 2017 20:28:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f65.google.com Received: from mail-wm0-f65.google.com (HELO mail-wm0-f65.google.com) (74.125.82.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Apr 2017 20:28:36 +0000 Received: by mail-wm0-f65.google.com with SMTP id d79so28225664wmi.2 for ; Tue, 25 Apr 2017 13:28:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=PglkfjEFXrl7UKbveJfZ8IQzz10JcXlyDh8wwEBCyq4=; b=K7TpTC+mfV/FPete2SBvonvLfutVz9SRfSv7IC1Y/9jwGyz5PyXfJrPvihxmZAUyTD Axxk3dTiK+kf+3+RWg3ROr7xhMQqQgbj4PN28fWlyiSwSgjrQoUPYmAy/AUkCgk6fUR+ xo8kSX54D2uVpUtwHQbAV6HMSHwEp2S2W5XciWL78ZDUtFMtWfluVmecpgR9hq4bJchx Ni1pa1nrvXdmuyVS4YpvyOrdHTRkVSNzXQrQ1AJoox2YEIoUf8dHCMtqpQArGz93KPm3 yXnyT1qjzi6HfFRQ704kF4M9+FgR3M5j0zeSUxDortSvKTKFpi61OSvOFiV9gAELD00D tOvA== X-Gm-Message-State: AN3rC/6LhGDexfHDduXdX+sw1iAgGZjpo5Tp+BuiAOjnBU8BkrnhYDEW IPt9psfxLSyi3czQ X-Received: by 10.28.67.68 with SMTP id q65mr3405513wma.142.1493152116532; Tue, 25 Apr 2017 13:28:36 -0700 (PDT) Received: from E107787-LIN.Home ([194.214.185.158]) by smtp.gmail.com with ESMTPSA id d17sm5635491wmi.21.2017.04.25.13.28.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Apr 2017 13:28:36 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 2/6] Add constructor and destructor to regcache Date: Tue, 25 Apr 2017 21:28:22 +0100 Message-Id: <1493152106-3246-3-git-send-email-yao.qi@linaro.org> In-Reply-To: <1493152106-3246-1-git-send-email-yao.qi@linaro.org> References: <1493152106-3246-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes This patch adds ctor and dtor to regcache. gdb: 2017-04-25 Yao Qi * 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. --- gdb/regcache.c | 78 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index 966f0c7..e0554c7 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: + explicit regcache (struct gdbarch *gdbarch, struct 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,33 @@ struct regcache /* If this is a read-write cache, which thread's registers is it connected to? */ ptid_t ptid; + +private: + explicit regcache (struct gdbarch *gdbarch, struct 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 struct regcache * + get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch, + struct address_space *aspace); }; /* See regcache.h. */ @@ -225,41 +263,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 +274,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 +513,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);