From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id A073C3861031 for ; Mon, 20 Jul 2020 20:41:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A073C3861031 X-ASG-Debug-ID: 1595277676-0c856e181010be00001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id KwybEgHS7F2Yt8Mw (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 20 Jul 2020 16:41:16 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from smarchi-efficios.internal.efficios.com (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) by smtp.ebox.ca (Postfix) with ESMTP id DC222441D64; Mon, 20 Jul 2020 16:41:15 -0400 (EDT) From: Simon Marchi X-Barracuda-RBL-IP: 192.222.181.218 X-Barracuda-Effective-Source-IP: 192-222-181-218.qc.cable.ebox.net[192.222.181.218] X-Barracuda-Apparent-Source-IP: 192.222.181.218 To: gdb-patches@sourceware.org Cc: Morichetti, Laurent , Simon Marchi Subject: [PATCH 2/4] gdb: move regcache::regcaches to regcache.c Date: Mon, 20 Jul 2020 16:40:59 -0400 X-ASG-Orig-Subj: [PATCH 2/4] gdb: move regcache::regcaches to regcache.c Message-Id: <20200720204101.2849535-3-simon.marchi@efficios.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200720204101.2849535-1-simon.marchi@efficios.com> References: <20200720204101.2849535-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1595277676 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 10704 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.83339 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-Spam-Status: No, score=-23.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jul 2020 20:41:25 -0000 I don't really understand why `regcache_thread_ptid_changed` is a static method of `struct regcache` instead of being a static free function in regcache.c. And I don't understand why `current_regcache` is a static member of `struct regcache` instead of being a static global in regcache.c. It's not wrong per-se, but there's no other place where we do it like this in GDB (as far as I remember) and it just exposes things unnecessarily in the .h. Move them to be just static in regcache.c. As a result, registers_changed_ptid doesn't need to be friend of the regcache class anymore. Removing the include of forward_list in regcache.h showed that we were missing an include for it in dwarf2/index-write.c, record-btrace.c and sparc64-tdep.c. gdb/ChangeLog: * regcache.h (class regcache): Remove friend registers_changed_ptid. : Remove. : Remove. * regcache.c (regcache::regcaches): Rename to... (regcaches): ... this. Make static. (get_thread_arch_aspace_regcache): Update. (regcache::regcache_thread_ptid_changed): Rename to... (regcache_thread_ptid_changed): ... this. Update. (class regcache_access): Remove. (regcaches_test): Update. (_initialize_regcache): Update. * sparc64-tdep.c, dwarf2/index-write.c, record-btrace.c: Include . Change-Id: Iabc25759848010cfbb7ee7e27f60eaca17d61c12 --- gdb/dwarf2/index-write.c | 1 + gdb/record-btrace.c | 1 + gdb/regcache.c | 74 +++++++++++++++++----------------------- gdb/regcache.h | 7 ---- gdb/sparc64-tdep.c | 2 +- 5 files changed, 35 insertions(+), 50 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 97b2310656ca..aa7a37e4ef2a 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -41,6 +41,7 @@ #include #include +#include #include #include #include diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index 36ae671fa904..2a0bf7979582 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -43,6 +43,7 @@ #include "gdbarch.h" #include "cli/cli-style.h" #include "async-event.h" +#include static const target_info record_btrace_target_info = { "record-btrace", diff --git a/gdb/regcache.c b/gdb/regcache.c index 3d8e4adf0efd..54354fe2c161 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -319,7 +319,7 @@ reg_buffer::assert_regnum (int regnum) const recording if the register values have been changed (eg. by the user). Therefore all registers must be written back to the target when appropriate. */ -std::forward_list regcache::regcaches; +static std::forward_list regcaches; struct regcache * get_thread_arch_aspace_regcache (process_stratum_target *target, @@ -328,7 +328,7 @@ get_thread_arch_aspace_regcache (process_stratum_target *target, { gdb_assert (target != nullptr); - for (const auto ®cache : regcache::regcaches) + for (const auto ®cache : regcaches) if (regcache->target () == target && regcache->ptid () == ptid && regcache->arch () == gdbarch) @@ -336,7 +336,7 @@ get_thread_arch_aspace_regcache (process_stratum_target *target, regcache *new_regcache = new regcache (target, gdbarch, aspace); - regcache::regcaches.push_front (new_regcache); + regcaches.push_front (new_regcache); new_regcache->set_ptid (ptid); return new_regcache; @@ -412,12 +412,11 @@ regcache_observer_target_changed (struct target_ops *target) registers_changed (); } -/* Update global variables old ptids to hold NEW_PTID if they were - holding OLD_PTID. */ -void -regcache::regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) +/* Update regcaches related to OLD_PTID to now use NEW_PTID. */ +static void +regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) { - for (auto ®cache : regcache::regcaches) + for (auto ®cache : regcaches) { if (regcache->ptid () == old_ptid) regcache->set_ptid (new_ptid); @@ -438,15 +437,15 @@ regcache::regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) void registers_changed_ptid (process_stratum_target *target, ptid_t ptid) { - for (auto oit = regcache::regcaches.before_begin (), it = std::next (oit); - it != regcache::regcaches.end (); ) + for (auto oit = regcaches.before_begin (), it = std::next (oit); + it != regcaches.end (); ) { struct regcache *regcache = *it; if ((target == nullptr || regcache->target () == target) && regcache->ptid ().matches (ptid)) { delete regcache; - it = regcache::regcaches.erase_after (oit); + it = regcaches.erase_after (oit); } else oit = it++; @@ -1431,19 +1430,12 @@ register_dump::dump (ui_file *file) namespace selftests { -class regcache_access : public regcache +static size_t +regcaches_size () { -public: - - /* Return the number of elements in regcache::regcaches. */ - - static size_t - regcaches_size () - { - return std::distance (regcache::regcaches.begin (), - regcache::regcaches.end ()); - } -}; + return std::distance (regcaches.begin (), + regcaches.end ()); +} /* Wrapper around get_thread_arch_aspace_regcache that does some self checks. */ @@ -1464,7 +1456,7 @@ static void regcaches_test (void) { /* It is empty at the start. */ - SELF_CHECK (regcache_access::regcaches_size () == 0); + SELF_CHECK (regcaches_size () == 0); ptid_t ptid1 (1), ptid2 (2), ptid3 (3); @@ -1472,57 +1464,56 @@ regcaches_test (void) test_target_ops test_target2; /* Get regcache from (target1,ptid1), a new regcache is added to - regcache::regcaches. */ + REGCACHES. */ test_get_thread_arch_aspace_regcache (&test_target1, ptid1, target_gdbarch (), NULL); - SELF_CHECK (regcache_access::regcaches_size () == 1); + SELF_CHECK (regcaches_size () == 1); /* Get regcache from (target1,ptid2), a new regcache is added to - regcache::regcaches. */ + REGCACHES. */ test_get_thread_arch_aspace_regcache (&test_target1, ptid2, target_gdbarch (), NULL); - SELF_CHECK (regcache_access::regcaches_size () == 2); + SELF_CHECK (regcaches_size () == 2); /* Get regcache from (target1,ptid3), a new regcache is added to - regcache::regcaches. */ + REGCACHES. */ test_get_thread_arch_aspace_regcache (&test_target1, ptid3, target_gdbarch (), NULL); - SELF_CHECK (regcache_access::regcaches_size () == 3); + SELF_CHECK (regcaches_size () == 3); /* Get regcache from (target1,ptid2) again, nothing is added to - regcache::regcaches. */ + REGCACHES. */ test_get_thread_arch_aspace_regcache (&test_target1, ptid2, target_gdbarch (), NULL); - SELF_CHECK (regcache_access::regcaches_size () == 3); + SELF_CHECK (regcaches_size () == 3); /* Get regcache from (target2,ptid2), a new regcache is added to - regcache::regcaches, since this time we're using a differen - target. */ + REGCACHES, since this time we're using a different target. */ test_get_thread_arch_aspace_regcache (&test_target2, ptid2, target_gdbarch (), NULL); - SELF_CHECK (regcache_access::regcaches_size () == 4); + SELF_CHECK (regcaches_size () == 4); /* Mark that (target1,ptid2) changed. The regcache of (target1, - ptid2) should be removed from regcache::regcaches. */ + ptid2) should be removed from REGCACHES. */ registers_changed_ptid (&test_target1, ptid2); - SELF_CHECK (regcache_access::regcaches_size () == 3); + SELF_CHECK (regcaches_size () == 3); /* Get the regcache from (target2,ptid2) again, confirming the registers_changed_ptid call above did not delete it. */ test_get_thread_arch_aspace_regcache (&test_target2, ptid2, target_gdbarch (), NULL); - SELF_CHECK (regcache_access::regcaches_size () == 3); + SELF_CHECK (regcaches_size () == 3); /* Confirm that marking all regcaches of all targets as changed - clears regcache::regcaches. */ + clears REGCACHES. */ registers_changed_ptid (nullptr, minus_one_ptid); - SELF_CHECK (regcache_access::regcaches_size () == 0); + SELF_CHECK (regcaches_size () == 0); } class target_ops_no_register : public test_target_ops @@ -1837,8 +1828,7 @@ _initialize_regcache () = gdbarch_data_register_post_init (init_regcache_descr); gdb::observers::target_changed.attach (regcache_observer_target_changed); - gdb::observers::thread_ptid_changed.attach - (regcache::regcache_thread_ptid_changed); + gdb::observers::thread_ptid_changed.attach (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 f2627958aa12..dd0c2f27f95a 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -22,7 +22,6 @@ #include "gdbsupport/common-regcache.h" #include "gdbsupport/function-view.h" -#include struct regcache; struct regset; @@ -397,13 +396,10 @@ class regcache : public detached_regcache debug. */ void debug_print_register (const char *func, int regno); - static void regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid); protected: regcache (process_stratum_target *target, gdbarch *gdbarch, const address_space *aspace); - static std::forward_list regcaches; - private: /* Helper function for transfer_regset. Copies across a single register. */ @@ -437,9 +433,6 @@ class regcache : public detached_regcache get_thread_arch_aspace_regcache (process_stratum_target *target, ptid_t ptid, struct gdbarch *gdbarch, struct address_space *aspace); - - friend void - registers_changed_ptid (process_stratum_target *target, ptid_t ptid); }; class readonly_detached_regcache : public readable_regcache diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c index f4810523dfaa..95979ab76f50 100644 --- a/gdb/sparc64-tdep.c +++ b/gdb/sparc64-tdep.c @@ -33,8 +33,8 @@ #include "target-descriptions.h" #include "target.h" #include "value.h" - #include "sparc64-tdep.h" +#include /* This file implements the SPARC 64-bit ABI as defined by the section "Low-Level System Information" of the SPARC Compliance -- 2.26.2