From patchwork Tue Apr 25 20:28:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 20155 Received: (qmail 118025 invoked by alias); 25 Apr 2017 20:28:54 -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 117987 invoked by uid 89); 25 Apr 2017 20:28:53 -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=Hx-languages-length:1240, 3786, friend 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:51 +0000 Received: by mail-wm0-f65.google.com with SMTP id d79so28226782wmi.2 for ; Tue, 25 Apr 2017 13:28:51 -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=mMoLQxTkXlcO7suJxSB0ALKR93FYQ2TzOU741lntFow=; b=g5ISEHgqO9c8RmxNfQtwIvfix1D6f0PTv7qrJXWvrfB4D83+zRubB1RvT20wGvdIQm DQfxiQnD/WdHtNPUvEkyUfpb0ySlhyVy2Y0WziLf3skt/u+G45TJbEL3lf/8oUuBrtHL oY9hoo0hZb+HGjvNbzaqOGg3mX2qgojHE6zgAJJkTvOCAAocW9tvRfpJvFJfh174OsKL rqmoCchp7fIkpQiVGJl85LXNPKNYHPop82iZBQJ3AMBCqKFHE7X/zG+aM15QuM2sM0Jq bPHHoZ9DZpCuH0d0x4C1GgsGg6FjOO6QKlEkisgC1c29rRleCldekFgvsesp51LvpsRb G9Bg== X-Gm-Message-State: AN3rC/5pzoH/Igd8gn6G2Dmzpd0z582Alm0hVAXL1stAq71Qf+rVfSwi vxocQ1Ka+QuQbegB X-Received: by 10.28.13.66 with SMTP id 63mr13750644wmn.2.1493152129572; Tue, 25 Apr 2017 13:28:49 -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.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Apr 2017 13:28:49 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 4/6] Simplify regcache_dup Date: Tue, 25 Apr 2017 21:28:24 +0100 Message-Id: <1493152106-3246-5-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 regcache_dup, in fact, is to create a readonly regcache from a non-readonly regcache. This patch adds an assert that src is not readonly. gdb: 2017-04-25 Yao Qi * regcache.c (regcache_dup): Assert !src->readonly_p and call method save instead of regcache_cpy. * regcache.h (struct regcache): Make regcache_dup a friend. --- gdb/regcache.c | 3 ++- gdb/regcache.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index f4fcf65..28163c2 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -422,8 +422,9 @@ regcache_dup (struct regcache *src) { struct regcache *newbuf; + gdb_assert (!src->readonly_p); newbuf = regcache_xmalloc (src->get_arch (), get_regcache_aspace (src)); - regcache_cpy (newbuf, src); + newbuf->save (do_cooked_read, src); return newbuf; } diff --git a/gdb/regcache.h b/gdb/regcache.h index 8794966..e6494a9 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -378,6 +378,9 @@ 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