From patchwork Fri Apr 28 14:26:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 20196 Received: (qmail 83225 invoked by alias); 28 Apr 2017 14:26:44 -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 83131 invoked by uid 89); 28 Apr 2017 14:26:43 -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-wr0-f196.google.com Received: from mail-wr0-f196.google.com (HELO mail-wr0-f196.google.com) (209.85.128.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Apr 2017 14:26:41 +0000 Received: by mail-wr0-f196.google.com with SMTP id w50so7286903wrc.0 for ; Fri, 28 Apr 2017 07:26:42 -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=sLEtmj5d8MnRpcHDbsDitnxykUDVgVMMORZ72Wzx5wo=; b=gClcP6uhsbyaqi9KgPnIl7U7EqjTMKDKeRhpqLL8arAy53pBLuwVyeXiHUvJo5tsHg aAijvSEkWwnyL9SheE6Gy08jaJHMVJWRgqlxKHijWFhTnua79JpKyHQtB1/2ksiIkyQI CSLOSnwQHRacJZ9OE0rvpWrDRIAm/AL34Wi6FAojgM2JDHullqEdkPshVr4tbwtyzyul OAQ6USO7b2UcYgw9xJ3OkTcT15Frdw1A1LKJNk7zahGN7GMa2B27ocbEgu5hMqSROPd6 detst53IYxGhIlczV/0Q+gnr6nuK+ByaE75rOqegB3OHU9NGFgyTREL6DS1OXfyeLKXQ lm4A== X-Gm-Message-State: AN3rC/63IYzgU15jWx1cHeLp1+ZN640+qibsPKqhrjPVUVxIkMMk/ry3 Vgp7rkRyq33nRDbk X-Received: by 10.223.174.209 with SMTP id y75mr7850674wrc.82.1493389599206; Fri, 28 Apr 2017 07:26:39 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com ([194.214.185.158]) by smtp.gmail.com with ESMTPSA id 133sm6888691wms.22.2017.04.28.07.26.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 28 Apr 2017 07:26:38 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 3/4] Use tag dispatch regcache ctor in regcache_dup Date: Fri, 28 Apr 2017 15:26:33 +0100 Message-Id: <1493389594-24434-4-git-send-email-yao.qi@linaro.org> In-Reply-To: <1493389594-24434-1-git-send-email-yao.qi@linaro.org> References: <1493152106-3246-1-git-send-email-yao.qi@linaro.org> <1493389594-24434-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes This patch adds a tag dispatch ctor to create read-only regcache from a write-through regcache, also this patch deletes copy ctor and assignment operator. gdb: 2017-04-27 Yao Qi Pedro Alves * regcache.c (regcache::regcache): New tag dispatch ctor. (do_cooked_read): Moved above. (regcache_dup): Use the tag dispatch ctor.. * regcache.h (regcache): Declare ctor, delete copy ctor and assignment operator, remove friend regcache_dup. --- gdb/regcache.c | 30 ++++++++++++++++-------------- gdb/regcache.h | 12 +++++++++--- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index 0be5fdb..882573c 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -209,6 +209,21 @@ regcache::regcache (gdbarch *gdbarch, address_space *aspace_, m_ptid = minus_one_ptid; } +static enum register_status +do_cooked_read (void *src, int regnum, gdb_byte *buf) +{ + struct regcache *regcache = (struct regcache *) src; + + return regcache_cooked_read (regcache, regnum, buf); +} + +regcache::regcache (readonly_t, const regcache &src) + : regcache (src.get_gdbarch (), src.aspace (), true) +{ + gdb_assert (!src.m_readonly_p); + save (do_cooked_read, (void *) &src); +} + gdbarch * regcache::get_gdbarch () const { @@ -371,14 +386,6 @@ regcache::restore (struct regcache *src) } } -static enum register_status -do_cooked_read (void *src, int regnum, gdb_byte *buf) -{ - struct regcache *regcache = (struct regcache *) src; - - return regcache_cooked_read (regcache, regnum, buf); -} - void regcache_cpy (struct regcache *dst, struct regcache *src) { @@ -420,12 +427,7 @@ regcache::cpy_no_passthrough (struct regcache *src) struct regcache * regcache_dup (struct regcache *src) { - struct regcache *newbuf; - - gdb_assert (!src->readonly_p); - newbuf = regcache_xmalloc (src->get_gdbarch (), get_regcache_aspace (src)); - newbuf->save (do_cooked_read, src); - return newbuf; + return new regcache (regcache::readonly, *src); } enum register_status diff --git a/gdb/regcache.h b/gdb/regcache.h index 713fd41..92defdd 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -240,6 +240,15 @@ public: : regcache (gdbarch, aspace_, true) {} + struct readonly_t {}; + static constexpr readonly_t readonly {}; + + /* Create a readonly regcache from a non-readonly regcache. */ + regcache (readonly_t, const regcache &src); + + regcache (const regcache &) = delete; + void operator= (const regcache &) = delete; + ~regcache () { xfree (m_registers); @@ -373,9 +382,6 @@ private: friend void regcache_cpy (struct regcache *dst, struct regcache *src); - - friend struct regcache * - regcache_dup (struct regcache *src); }; /* Copy/duplicate the contents of a register cache. By default, the