From patchwork Fri Apr 28 14:26:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 20195 Received: (qmail 83181 invoked by alias); 28 Apr 2017 14:26:43 -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 82922 invoked by uid 89); 28 Apr 2017 14:26: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=3736, Hx-languages-length:1243, friend X-HELO: mail-wm0-f68.google.com Received: from mail-wm0-f68.google.com (HELO mail-wm0-f68.google.com) (74.125.82.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Apr 2017 14:26:38 +0000 Received: by mail-wm0-f68.google.com with SMTP id d79so11284350wmi.2 for ; Fri, 28 Apr 2017 07:26:40 -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=eTLrPwY/f+MFnqv2OmNYfvtjsmFCEo5Q3k/DnLFc8dY=; b=pzWXER+Yg2jMJ3duQnDPczbP5gHxX2kmldyUSQcQM2pb026z/dUuvg9I4/NOWsbi0T c3lHShDV6HEWc0RPnMKHJYSIzCMiG0VdUZrlwiCbkPdFndwVCCJsQ/HenheAYf9Vkdsk QlGg7jd2S6khdBHHaehFBz7K3C71z2tujaldTCs4CQcQAlweBlMuh/4aogDVZxG7HRVQ 9Btx2qTt5LyP+/IDjGNZaEFC2w5FHlq23gdO316fRC5hkVJ/3ueJxvuAPKmPO3N2fU2O csAVcuinMh9ek01KuwKO2KK584WG7tMq+KgKhsH1Ku2Cz4yW5zZBALHgAlmJyxE15umI dW7A== X-Gm-Message-State: AN3rC/6JebnKfkoTHJ+j0MSghjX1FKC+H1el8H0yKgKuO9HxRIaw80g8 QMr67Os4vorQjm8x X-Received: by 10.28.148.147 with SMTP id w141mr5697481wmd.19.1493389598321; Fri, 28 Apr 2017 07:26:38 -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.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 28 Apr 2017 07:26:37 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 2/4] Simplify regcache_dup Date: Fri, 28 Apr 2017 15:26:32 +0100 Message-Id: <1493389594-24434-3-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 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 6c3603e..0be5fdb 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_gdbarch (), 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 992f0f1..713fd41 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -373,6 +373,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