From patchwork Tue Apr 25 20:28:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 20157 Received: (qmail 118414 invoked by alias); 25 Apr 2017 20:28:58 -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 118330 invoked by uid 89); 25 Apr 2017 20:28:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=friend X-HELO: mail-wm0-f50.google.com Received: from mail-wm0-f50.google.com (HELO mail-wm0-f50.google.com) (74.125.82.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Apr 2017 20:28:54 +0000 Received: by mail-wm0-f50.google.com with SMTP id w64so32947461wma.0 for ; Tue, 25 Apr 2017 13:28:55 -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=9kYZaDgilbsGsDw7qHHV7s90Qjbu6qvza10ASRrd4CU=; b=YqeJVP5CI858qNnwZvLdMm0LM72fwY3SvSF05a3DIvCcFRBbYrtFM2ZfLX6khmz2cA FC4QGgCEcfVnpES71dLnv01OypA8anVtqVdELsEFmYehAWeOBAdLPtCvUBVPKXyHYCqs gkc6+Lc+ykw8LcWureZhMD59PcLYkmRPxjPnZJaiamD55X7LQavlMVGpEuoW1A3/fCc3 EHG2/cJ0q0ZxgliWwcsHfGS6mmT7YkAGT8yXX27KPY49m0m6y2khTm6ad+mbs730ICiH VCRim/OdsGKYq2qiUMoYUA6JMwU6CCWzcmtvWnS1qOMWBMRUV5k2wTFm0MdKc+FbJ92o TfCA== X-Gm-Message-State: AN3rC/7vTaAcHBUY6r0VCi4m1612EVDAJvwB2AhzOBOuimBgH4s7F3dq ci7Gu729lGjNyqtY X-Received: by 10.28.209.13 with SMTP id i13mr2968446wmg.31.1493152133774; Tue, 25 Apr 2017 13:28:53 -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.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Apr 2017 13:28:53 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 5/6] Use copy ctor in regcache_dup Date: Tue, 25 Apr 2017 21:28:25 +0100 Message-Id: <1493152106-3246-6-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 gdb: 2017-04-25 Yao Qi * regcache.c (regcache::regcache): New copy ctor. (do_cooked_read): Moved above. (regcache_dup): Use copy ctor. * regcache.h (struct regcache): Declare copy ctor and remove friend regcache_dup. --- gdb/regcache.c | 30 ++++++++++++++++-------------- gdb/regcache.h | 7 ++++--- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index 28163c2..3fc0aee 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -209,6 +209,21 @@ regcache::regcache (struct gdbarch *gdbarch, struct address_space *aspace_, 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 (const regcache &origin) + : regcache (origin.get_arch (), origin.get_aspace (), true) +{ + gdb_assert (!origin.readonly_p); + save (do_cooked_read, (void *) &origin); +} + struct gdbarch * regcache::get_arch () 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_arch (), get_regcache_aspace (src)); - newbuf->save (do_cooked_read, src); - return newbuf; + return new regcache (*src); } enum register_status diff --git a/gdb/regcache.h b/gdb/regcache.h index e6494a9..0d302a7 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -240,6 +240,10 @@ public: : regcache (gdbarch, aspace_, true) {} + /* Copy constructor, create a readonly regcache from a non-readonly + regcache. */ + regcache (const regcache &); + ~regcache () { xfree (registers); @@ -378,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