From patchwork Wed May 3 16:18:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 20236 Received: (qmail 82830 invoked by alias); 3 May 2017 16:18:37 -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 82708 invoked by uid 89); 3 May 2017 16:18:36 -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-spam-relays-external:74.125.82.67, depositing, H*RU:74.125.82.67, STRUCTURE X-HELO: mail-wm0-f67.google.com Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 03 May 2017 16:18:34 +0000 Received: by mail-wm0-f67.google.com with SMTP id z129so14044069wmb.1 for ; Wed, 03 May 2017 09:18:36 -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=C0PaEqsiomKyX9pGOWUP66rBtkC56ksXYXCH7Mnondc=; b=BPV/BLQQYxQQhFncusEirHHGLAYOGBkpPvxtNR2408XLe93AeG3UgqoIkmp2vwbTGf K9jcCRnpCoCQ93k+9pN9liH81fX89WdZh4rnCFnM6XthNM8djy+FRm5/3i+Pkifd6nAY LjkSvChLXNs37yAFH52gqEEToWFVmzmtRtAbULxV3ia2AN9AM6H47nFyLynqB5+0MeMt 6PEi/1HRCcxDMvRMkPzCs6EDsATGV4epyzbaX6fgkM8VFhha11UJPwIr/1IwgHo9Vhhn lmPbujnxTazXvD+UQhZMYLN0KLj6XkvkoNisxhJukkDTCak+1sFCVBKH304c4HYMzFO0 H4Vw== X-Gm-Message-State: AN3rC/4pU3K+oAns54KTHSKiwqVi5g/CKG0ZHV3zuzoJjilrh4H5G1u0 CIUFOswMfQGuyYxv X-Received: by 10.28.236.210 with SMTP id h79mr6747252wmi.92.1493828314470; Wed, 03 May 2017 09:18:34 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com ([194.214.185.158]) by smtp.gmail.com with ESMTPSA id k18sm17524044wre.9.2017.05.03.09.18.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 May 2017 09:18:33 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 2/2] Use std::forward_list for current_regcache Date: Wed, 3 May 2017 17:18:30 +0100 Message-Id: <1493828310-15731-3-git-send-email-yao.qi@linaro.org> In-Reply-To: <1493828310-15731-1-git-send-email-yao.qi@linaro.org> References: <1493828310-15731-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes gdb: 2017-05-02 Yao Qi * regcache.c: Include . (struct regcache_list): Remove. (current_regcache): Update. (get_thread_arch_aspace_regcache): Update for std::forward_list. (regcache_thread_ptid_changed): Likewise. (registers_changed_ptid): Likewise. (current_regcache_size): Likewise. --- gdb/regcache.c | 67 +++++++++++++++++++--------------------------------------- 1 file changed, 22 insertions(+), 45 deletions(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index 40781bc..95b4b53 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -28,6 +28,7 @@ #include "remote.h" #include "valprint.h" #include "regset.h" +#include /* * DATA STRUCTURE @@ -472,34 +473,21 @@ regcache::invalidate (int regnum) user). Therefore all registers must be written back to the target when appropriate. */ -struct regcache_list -{ - struct regcache *regcache; - struct regcache_list *next; -}; - -static struct regcache_list *current_regcache; +static std::forward_list current_regcache; struct regcache * get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch, struct address_space *aspace) { - struct regcache_list *list; - struct regcache *new_regcache; + for (const auto ®cache : current_regcache) + if (ptid_equal (regcache->ptid (), ptid) && regcache->arch () == gdbarch) + return regcache; - for (list = current_regcache; list; list = list->next) - if (ptid_equal (list->regcache->ptid (), ptid) - && get_regcache_arch (list->regcache) == gdbarch) - return list->regcache; + regcache *new_regcache = new regcache (gdbarch, aspace, false); - new_regcache = new regcache (gdbarch, aspace, false); + current_regcache.push_front (new_regcache); new_regcache->set_ptid (ptid); - list = XNEW (struct regcache_list); - list->regcache = new_regcache; - list->next = current_regcache; - current_regcache = list; - return new_regcache; } @@ -563,11 +551,11 @@ regcache_observer_target_changed (struct target_ops *target) static void regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) { - struct regcache_list *list; - - for (list = current_regcache; list; list = list->next) - if (ptid_equal (list->regcache->ptid (), old_ptid)) - list->regcache->set_ptid (new_ptid); + for (auto ®cache : current_regcache) + { + if (ptid_equal (regcache->ptid (), old_ptid)) + regcache->set_ptid (new_ptid); + } } /* Low level examining and depositing of registers. @@ -584,25 +572,18 @@ regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) void registers_changed_ptid (ptid_t ptid) { - struct regcache_list *list, **list_link; - - list = current_regcache; - list_link = ¤t_regcache; - while (list) + for (auto oit = current_regcache.before_begin (), + it = std::next (oit); + it != current_regcache.end (); + ) { - if (ptid_match (list->regcache->ptid (), ptid)) + if (ptid_match ((*it)->ptid (), ptid)) { - struct regcache_list *dead = list; - - *list_link = list->next; - regcache_xfree (list->regcache); - list = *list_link; - xfree (dead); - continue; + delete *it; + it = current_regcache.erase_after (oit); } - - list_link = &list->next; - list = *list_link; + else + oit = it++; } if (ptid_match (current_thread_ptid, ptid)) @@ -1689,11 +1670,7 @@ namespace selftests { static size_t current_regcache_size () { - size_t i = 0; - for (auto list = current_regcache; list; list = list->next) - i++; - - return i; + return std::distance (current_regcache.begin (), current_regcache.end ()); } static void