From patchwork Wed May 10 13:10:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 20372 Received: (qmail 29602 invoked by alias); 10 May 2017 13:10:31 -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 29496 invoked by uid 89); 10 May 2017 13:10:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=AWL, 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-pf0-f179.google.com Received: from mail-pf0-f179.google.com (HELO mail-pf0-f179.google.com) (209.85.192.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 10 May 2017 13:10:27 +0000 Received: by mail-pf0-f179.google.com with SMTP id v14so15734762pfd.2 for ; Wed, 10 May 2017 06:10:30 -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=LzUX5DYWjKYSe9sCrKGLeSbxcrYkF/S0rNqP9HcEHoI=; b=BZjXJUhruDyG7OriRQPssFn1Ahn90ipy2lyCMk+JKVzmSiP8OAdB6MtyWHycjploZb w+Fdxtl0ypRbsi9qYJXm8d9Qnt8dXMot9gM6GnmXg35h7NhwKYjAYcX782VDewuDExb6 ib4/nlJBFLjZ6Rw54gXLdKBD5ZG0HgXe7teAGGjnPfXdgP45uRhGMqwsxVxTDCizuSGF hRUirrB/Bf7QBkaD1hGquo4PdsKaSvwMieXRtDSDyOpLqMaa5OYVy7iWcXdrWczbpvL2 81BRo7022P020rWyY7u0eVgIy3xjI12tpN/5CjHNnJDhUEBUTC8zRE1+AVdfv7al7v+T aRSA== X-Gm-Message-State: AODbwcC0ge1I/GY/U7yyPif2aphNjBeQSR0NYvfvhA09/0IME538dDad LBKRxxCSJne37BXp X-Received: by 10.98.57.212 with SMTP id u81mr6168584pfj.9.1494421827679; Wed, 10 May 2017 06:10:27 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id 194sm5625928pgf.62.2017.05.10.06.10.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 May 2017 06:10:27 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 8/9] Move current_regcache to regcache::current_regcache Date: Wed, 10 May 2017 14:10:12 +0100 Message-Id: <1494421813-7268-9-git-send-email-yao.qi@linaro.org> In-Reply-To: <1494421813-7268-1-git-send-email-yao.qi@linaro.org> References: <1494421813-7268-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes This patches moves global variable current_regcache to a class regcache static variable (protected) so that the unit test I add in the following patch can access it (by means of extending class regcache in unit test). gdb: 2017-05-09 Yao Qi * regcache.c (current_regcache): Change it to regcache::current_regcache. (regcache_observer_target_changed): Update. (regcache_thread_ptid_changed): Make it a regcache static method. (regcache_thread_ptid_changed): Update. (class regcache_access): New. (current_regcache_test): Update. (_initialize_regcache): Update. * regcache.h: Include forward_list. (regcache): Declare regcache_thread_ptid_changed and declare registers_changed_ptid as friend. --- gdb/regcache.c | 51 ++++++++++++++++++++++++++++----------------------- gdb/regcache.h | 10 +++++++++- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index 7250763..7638eea 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -472,20 +472,19 @@ regcache::invalidate (int regnum) recording if the register values have been changed (eg. by the user). Therefore all registers must be written back to the target when appropriate. */ - -static std::forward_list current_regcache; +std::forward_list regcache::current_regcache; struct regcache * get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch, struct address_space *aspace) { - for (const auto ®cache : current_regcache) + for (const auto ®cache : regcache::current_regcache) if (ptid_equal (regcache->ptid (), ptid) && regcache->arch () == gdbarch) return regcache; regcache *new_regcache = new regcache (gdbarch, aspace, false); - current_regcache.push_front (new_regcache); + regcache::current_regcache.push_front (new_regcache); new_regcache->set_ptid (ptid); return new_regcache; @@ -548,10 +547,10 @@ regcache_observer_target_changed (struct target_ops *target) /* Update global variables old ptids to hold NEW_PTID if they were holding OLD_PTID. */ -static void -regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) +void +regcache::regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) { - for (auto ®cache : current_regcache) + for (auto ®cache : regcache::current_regcache) { if (ptid_equal (regcache->ptid (), old_ptid)) regcache->set_ptid (new_ptid); @@ -572,15 +571,15 @@ regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) void registers_changed_ptid (ptid_t ptid) { - for (auto oit = current_regcache.before_begin (), + for (auto oit = regcache::current_regcache.before_begin (), it = std::next (oit); - it != current_regcache.end (); + it != regcache::current_regcache.end (); ) { if (ptid_match ((*it)->ptid (), ptid)) { delete *it; - it = current_regcache.erase_after (oit); + it = regcache::current_regcache.erase_after (oit); } else oit = it++; @@ -1685,19 +1684,25 @@ maintenance_print_remote_registers (char *args, int from_tty) namespace selftests { -/* Return the number of elements in current_regcache. */ - -static size_t -current_regcache_size () +class regcache_access : public regcache { - return std::distance (current_regcache.begin (), current_regcache.end ()); -} +public: + + /* Return the number of elements in current_regcache. */ + + static size_t + current_regcache_size () + { + return std::distance (regcache::current_regcache.begin (), + regcache::current_regcache.end ()); + } +}; static void current_regcache_test (void) { /* It is empty at the start. */ - SELF_CHECK (current_regcache_size () == 0); + SELF_CHECK (regcache_access::current_regcache_size () == 0); ptid_t ptid1 (1), ptid2 (2), ptid3 (3); @@ -1709,7 +1714,7 @@ current_regcache_test (void) SELF_CHECK (regcache != NULL); SELF_CHECK (regcache->ptid () == ptid1); - SELF_CHECK (current_regcache_size () == 1); + SELF_CHECK (regcache_access::current_regcache_size () == 1); /* Get regcache from ptid2, a new regcache is added to current_regcache. */ @@ -1718,7 +1723,7 @@ current_regcache_test (void) NULL); SELF_CHECK (regcache != NULL); SELF_CHECK (regcache->ptid () == ptid2); - SELF_CHECK (current_regcache_size () == 2); + SELF_CHECK (regcache_access::current_regcache_size () == 2); /* Get regcache from ptid3, a new regcache is added to current_regcache. */ @@ -1727,7 +1732,7 @@ current_regcache_test (void) NULL); SELF_CHECK (regcache != NULL); SELF_CHECK (regcache->ptid () == ptid3); - SELF_CHECK (current_regcache_size () == 3); + SELF_CHECK (regcache_access::current_regcache_size () == 3); /* Get regcache from ptid2 again, nothing is added to current_regcache. */ @@ -1736,12 +1741,12 @@ current_regcache_test (void) NULL); SELF_CHECK (regcache != NULL); SELF_CHECK (regcache->ptid () == ptid2); - SELF_CHECK (current_regcache_size () == 3); + SELF_CHECK (regcache_access::current_regcache_size () == 3); /* Mark ptid2 is changed, so regcache of ptid2 should be removed from current_regcache. */ registers_changed_ptid (ptid2); - SELF_CHECK (current_regcache_size () == 2); + SELF_CHECK (regcache_access::current_regcache_size () == 2); } } // namespace selftests @@ -1756,7 +1761,7 @@ _initialize_regcache (void) = gdbarch_data_register_post_init (init_regcache_descr); observer_attach_target_changed (regcache_observer_target_changed); - observer_attach_thread_ptid_changed (regcache_thread_ptid_changed); + observer_attach_thread_ptid_changed (regcache::regcache_thread_ptid_changed); add_com ("flushregs", class_maintenance, reg_flush_command, _("Force gdb to flush its register cache (maintainer command)")); diff --git a/gdb/regcache.h b/gdb/regcache.h index da00abd..fdc47ba 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -21,6 +21,7 @@ #define REGCACHE_H #include "common-regcache.h" +#include struct regcache; struct regset; @@ -336,9 +337,13 @@ public: debug. */ void debug_print_register (const char *func, int regno); -private: + static void regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid); +protected: regcache (gdbarch *gdbarch, address_space *aspace_, bool readonly_p_); + static std::forward_list current_regcache; + +private: gdb_byte *register_buffer (int regnum) const; void restore (struct regcache *src); @@ -383,6 +388,9 @@ private: struct address_space *aspace); friend void + registers_changed_ptid (ptid_t ptid); + + friend void regcache_cpy (struct regcache *dst, struct regcache *src); };