From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from qproxy2-pub.mail.unifiedlayer.com (qproxy2-pub.mail.unifiedlayer.com [69.89.16.161]) by sourceware.org (Postfix) with ESMTPS id 5F610385735A for ; Sat, 16 Apr 2022 17:00:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5F610385735A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from outbound-ss-761.bluehost.com (outbound-ss-761.bluehost.com [74.220.211.250]) by qproxy2.mail.unifiedlayer.com (Postfix) with ESMTP id 84125802E1E9 for ; Sat, 16 Apr 2022 17:00:54 +0000 (UTC) Received: from cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway8.mail.pro1.eigbox.com (Postfix) with ESMTP id 347FC10052AFD for ; Sat, 16 Apr 2022 16:58:24 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id flkdnIanAQs3CflkdnOIRV; Sat, 16 Apr 2022 16:58:24 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=A+Opg4aG c=1 sm=1 tr=0 ts=625af5b0 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=z0gMJWrwH1QA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=w61J5dBCDReGwCIVLkgA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=ka/p+yaJtzEj5tZe9dNC1bzQfzzjjmGZ87E9sl05fek=; b=TRi9pfYj1z9o56zFS3Z00RT+Bd LDoqnq1zLXISgzRstZMHFwZEDnGsK/BXJPb/MGrnZEQNiAxXuZ1/ic36MbnTr2aew/6D6JgExqmjx reEhLYsuQ71a/IOuFPsKOyLg/; Received: from 71-211-154-204.hlrn.qwest.net ([71.211.154.204]:45548 helo=prentzel.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nflkd-003XP7-6w; Sat, 16 Apr 2022 10:58:23 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/9] Privacy for addrmap_mutable Date: Sat, 16 Apr 2022 10:58:15 -0600 Message-Id: <20220416165821.3648899-4-tom@tromey.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220416165821.3648899-1-tom@tromey.com> References: <20220416165821.3648899-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.154.204 X-Source-L: No X-Exim-ID: 1nflkd-003XP7-6w X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-154-204.hlrn.qwest.net (prentzel.Home) [71.211.154.204]:45548 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3029.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Sat, 16 Apr 2022 17:00:57 -0000 This changes addrmap_mutable so that its data members are private. --- gdb/addrmap.c | 141 ++++++++++++++++++++++++++++---------------------- 1 file changed, 78 insertions(+), 63 deletions(-) diff --git a/gdb/addrmap.c b/gdb/addrmap.c index 55a1b8c6fff..e372e0c6e06 100644 --- a/gdb/addrmap.c +++ b/gdb/addrmap.c @@ -206,6 +206,11 @@ addrmap_fixed::foreach (addrmap_foreach_fn fn) struct addrmap_mutable : public addrmap { +public: + + explicit addrmap_mutable (struct obstack *obs); + DISABLE_COPY_AND_ASSIGN (addrmap_mutable); + void set_empty (CORE_ADDR start, CORE_ADDR end_inclusive, void *obj) override; void *find (CORE_ADDR addr) override; @@ -213,9 +218,18 @@ struct addrmap_mutable : public addrmap void relocate (CORE_ADDR offset) override; int foreach (addrmap_foreach_fn fn) override; +private: + /* The obstack to use for allocations for this map. */ struct obstack *obstack; + /* A freelist for splay tree nodes, allocated on obstack, and + chained together by their 'right' pointers. */ + /* splay_tree_new_with_allocator uses the provided allocation + function to allocate the main splay_tree structure itself, so our + free list has to be initialized before we create the tree. */ + splay_tree_node free_nodes = nullptr; + /* A splay tree, with a node for each transition; there is a transition at address T if T-1 and T map to different objects. @@ -235,17 +249,25 @@ struct addrmap_mutable : public addrmap from deleted nodes; they'll be freed when the obstack is freed. */ splay_tree tree; - /* A freelist for splay tree nodes, allocated on obstack, and - chained together by their 'right' pointers. */ - splay_tree_node free_nodes; + /* Various helper methods. */ + splay_tree_key allocate_key (CORE_ADDR addr); + void force_transition (CORE_ADDR addr); + splay_tree_node splay_tree_lookup (CORE_ADDR addr); + splay_tree_node splay_tree_predecessor (CORE_ADDR addr); + splay_tree_node splay_tree_successor (CORE_ADDR addr); + void splay_tree_remove (CORE_ADDR addr); + void splay_tree_insert (CORE_ADDR key, void *value); + + static void *splay_obstack_alloc (int size, void *closure); + static void splay_obstack_free (void *obj, void *closure); }; -/* Allocate a copy of CORE_ADDR in MAP's obstack. */ -static splay_tree_key -allocate_key (struct addrmap_mutable *map, CORE_ADDR addr) +/* Allocate a copy of CORE_ADDR in the obstack. */ +splay_tree_key +addrmap_mutable::allocate_key (CORE_ADDR addr) { - CORE_ADDR *key = XOBNEW (map->obstack, CORE_ADDR); + CORE_ADDR *key = XOBNEW (obstack, CORE_ADDR); *key = addr; return (splay_tree_key) key; @@ -253,31 +275,31 @@ allocate_key (struct addrmap_mutable *map, CORE_ADDR addr) /* Type-correct wrappers for splay tree access. */ -static splay_tree_node -addrmap_splay_tree_lookup (struct addrmap_mutable *map, CORE_ADDR addr) +splay_tree_node +addrmap_mutable::splay_tree_lookup (CORE_ADDR addr) { - return splay_tree_lookup (map->tree, (splay_tree_key) &addr); + return ::splay_tree_lookup (tree, (splay_tree_key) &addr); } -static splay_tree_node -addrmap_splay_tree_predecessor (struct addrmap_mutable *map, CORE_ADDR addr) +splay_tree_node +addrmap_mutable::splay_tree_predecessor (CORE_ADDR addr) { - return splay_tree_predecessor (map->tree, (splay_tree_key) &addr); + return ::splay_tree_predecessor (tree, (splay_tree_key) &addr); } -static splay_tree_node -addrmap_splay_tree_successor (struct addrmap_mutable *map, CORE_ADDR addr) +splay_tree_node +addrmap_mutable::splay_tree_successor (CORE_ADDR addr) { - return splay_tree_successor (map->tree, (splay_tree_key) &addr); + return ::splay_tree_successor (tree, (splay_tree_key) &addr); } -static void -addrmap_splay_tree_remove (struct addrmap_mutable *map, CORE_ADDR addr) +void +addrmap_mutable::splay_tree_remove (CORE_ADDR addr) { - splay_tree_remove (map->tree, (splay_tree_key) &addr); + ::splay_tree_remove (tree, (splay_tree_key) &addr); } @@ -302,30 +324,27 @@ addrmap_node_set_value (splay_tree_node node, void *value) } -static void -addrmap_splay_tree_insert (struct addrmap_mutable *map, - CORE_ADDR key, void *value) +void +addrmap_mutable::splay_tree_insert (CORE_ADDR key, void *value) { - splay_tree_insert (map->tree, - allocate_key (map, key), - (splay_tree_value) value); + ::splay_tree_insert (tree, + allocate_key (key), + (splay_tree_value) value); } /* Without changing the mapping of any address, ensure that there is a tree node at ADDR, even if it would represent a "transition" from one value to the same value. */ -static void -force_transition (struct addrmap_mutable *self, CORE_ADDR addr) +void +addrmap_mutable::force_transition (CORE_ADDR addr) { - splay_tree_node n - = addrmap_splay_tree_lookup (self, addr); + splay_tree_node n = splay_tree_lookup (addr); if (! n) { - n = addrmap_splay_tree_predecessor (self, addr); - addrmap_splay_tree_insert (self, addr, - n ? addrmap_node_value (n) : NULL); + n = splay_tree_predecessor (addr); + splay_tree_insert (addr, n ? addrmap_node_value (n) : NULL); } } @@ -350,14 +369,14 @@ addrmap_mutable::set_empty (CORE_ADDR start, CORE_ADDR end_inclusive, - Second pass: remove any unnecessary transitions. */ /* Establish transitions at the start and end. */ - force_transition (this, start); + force_transition (start); if (end_inclusive < CORE_ADDR_MAX) - force_transition (this, end_inclusive + 1); + force_transition (end_inclusive + 1); /* Walk the area, changing all NULL regions to OBJ. */ - for (n = addrmap_splay_tree_lookup (this, start), gdb_assert (n); + for (n = splay_tree_lookup (start), gdb_assert (n); n && addrmap_node_key (n) <= end_inclusive; - n = addrmap_splay_tree_successor (this, addrmap_node_key (n))) + n = splay_tree_successor (addrmap_node_key (n))) { if (! addrmap_node_value (n)) addrmap_node_set_value (n, obj); @@ -366,16 +385,16 @@ addrmap_mutable::set_empty (CORE_ADDR start, CORE_ADDR end_inclusive, /* Walk the area again, removing transitions from any value to itself. Be sure to visit both the transitions we forced above. */ - n = addrmap_splay_tree_predecessor (this, start); + n = splay_tree_predecessor (start); prior_value = n ? addrmap_node_value (n) : NULL; - for (n = addrmap_splay_tree_lookup (this, start), gdb_assert (n); + for (n = splay_tree_lookup (start), gdb_assert (n); n && (end_inclusive == CORE_ADDR_MAX || addrmap_node_key (n) <= end_inclusive + 1); n = next) { - next = addrmap_splay_tree_successor (this, addrmap_node_key (n)); + next = splay_tree_successor (addrmap_node_key (n)); if (addrmap_node_value (n) == prior_value) - addrmap_splay_tree_remove (this, addrmap_node_key (n)); + splay_tree_remove (addrmap_node_key (n)); else prior_value = addrmap_node_value (n); } @@ -385,14 +404,14 @@ addrmap_mutable::set_empty (CORE_ADDR start, CORE_ADDR end_inclusive, void * addrmap_mutable::find (CORE_ADDR addr) { - splay_tree_node n = addrmap_splay_tree_lookup (this, addr); + splay_tree_node n = splay_tree_lookup (addr); if (n != nullptr) { gdb_assert (addrmap_node_key (n) == addr); return addrmap_node_value (n); } - n = addrmap_splay_tree_predecessor (this, addr); + n = splay_tree_predecessor (addr); if (n != nullptr) { gdb_assert (addrmap_node_key (n) < addr); @@ -474,8 +493,8 @@ addrmap_mutable::foreach (addrmap_foreach_fn fn) } -static void * -splay_obstack_alloc (int size, void *closure) +void * +addrmap_mutable::splay_obstack_alloc (int size, void *closure) { struct addrmap_mutable *map = (struct addrmap_mutable *) closure; splay_tree_node n; @@ -496,8 +515,8 @@ splay_obstack_alloc (int size, void *closure) } -static void -splay_obstack_free (void *obj, void *closure) +void +addrmap_mutable::splay_obstack_free (void *obj, void *closure) { struct addrmap_mutable *map = (struct addrmap_mutable *) closure; splay_tree_node n = (splay_tree_node) obj; @@ -527,26 +546,22 @@ splay_compare_CORE_ADDR_ptr (splay_tree_key ak, splay_tree_key bk) } -struct addrmap * -addrmap_create_mutable (struct obstack *obstack) +addrmap_mutable::addrmap_mutable (struct obstack *obs) + : obstack (obs), + tree (splay_tree_new_with_allocator (splay_compare_CORE_ADDR_ptr, + NULL, /* no delete key */ + NULL, /* no delete value */ + splay_obstack_alloc, + splay_obstack_free, + this)) { - struct addrmap_mutable *map = new (obstack) struct addrmap_mutable; - - map->obstack = obstack; - - /* splay_tree_new_with_allocator uses the provided allocation - function to allocate the main splay_tree structure itself, so our - free list has to be initialized before we create the tree. */ - map->free_nodes = NULL; +} - map->tree = splay_tree_new_with_allocator (splay_compare_CORE_ADDR_ptr, - NULL, /* no delete key */ - NULL, /* no delete value */ - splay_obstack_alloc, - splay_obstack_free, - map); - return map; +struct addrmap * +addrmap_create_mutable (struct obstack *obstack) +{ + return new (obstack) struct addrmap_mutable (obstack); } /* See addrmap.h. */ -- 2.34.1