From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id E0796385AE43; Sun, 12 Jun 2022 16:55:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0796385AE43 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Privacy for addrmap_mutable X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 5427f03f9e0ab815ca5dbc73339ef27863a6f2df X-Git-Newrev: 9d45ec63a5e60aae846dfc9dc8ee950c3bce2ad4 Message-Id: <20220612165535.E0796385AE43@sourceware.org> Date: Sun, 12 Jun 2022 16:55:35 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Jun 2022 16:55:36 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D9d45ec63a5e6= 0aae846dfc9dc8ee950c3bce2ad4 commit 9d45ec63a5e60aae846dfc9dc8ee950c3bce2ad4 Author: Tom Tromey Date: Sat Apr 16 09:15:43 2022 -0600 Privacy for addrmap_mutable =20 This changes addrmap_mutable so that its data members are private. Diff: --- gdb/addrmap.c | 142 ++++++++++++++++++++++++++++++++----------------------= ---- 1 file changed, 78 insertions(+), 64 deletions(-) diff --git a/gdb/addrmap.c b/gdb/addrmap.c index 915dc88c1ec..30db7e78408 100644 --- a/gdb/addrmap.c +++ b/gdb/addrmap.c @@ -206,6 +206,11 @@ addrmap_fixed::foreach (addrmap_foreach_fn fn) =20 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) const override; @@ -213,9 +218,18 @@ struct addrmap_mutable : public addrmap void relocate (CORE_ADDR offset) override; int foreach (addrmap_foreach_fn fn) override; =20 +private: + /* The obstack to use for allocations for this map. */ struct obstack *obstack; =20 + /* 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 =3D 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. =20 @@ -235,17 +249,25 @@ struct addrmap_mutable : public addrmap from deleted nodes; they'll be freed when the obstack is freed. */ splay_tree tree; =20 - /* 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) const; + splay_tree_node splay_tree_predecessor (CORE_ADDR addr) const; + 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); }; =20 =20 -/* 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 =3D XOBNEW (map->obstack, CORE_ADDR); + CORE_ADDR *key =3D XOBNEW (obstack, CORE_ADDR); =20 *key =3D addr; return (splay_tree_key) key; @@ -253,32 +275,31 @@ allocate_key (struct addrmap_mutable *map, CORE_ADDR = addr) =20 =20 /* Type-correct wrappers for splay tree access. */ -static splay_tree_node -addrmap_splay_tree_lookup (const struct addrmap_mutable *map, CORE_ADDR ad= dr) +splay_tree_node +addrmap_mutable::splay_tree_lookup (CORE_ADDR addr) const { - return splay_tree_lookup (map->tree, (splay_tree_key) &addr); + return ::splay_tree_lookup (tree, (splay_tree_key) &addr); } =20 =20 -static splay_tree_node -addrmap_splay_tree_predecessor (const struct addrmap_mutable *map, - CORE_ADDR addr) +splay_tree_node +addrmap_mutable::splay_tree_predecessor (CORE_ADDR addr) const { - return splay_tree_predecessor (map->tree, (splay_tree_key) &addr); + return ::splay_tree_predecessor (tree, (splay_tree_key) &addr); } =20 =20 -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); } =20 =20 -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); } =20 =20 @@ -303,30 +324,27 @@ addrmap_node_set_value (splay_tree_node node, void *v= alue) } =20 =20 -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); } =20 =20 /* 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 - =3D addrmap_splay_tree_lookup (self, addr); + splay_tree_node n =3D splay_tree_lookup (addr); =20 if (! n) { - n =3D addrmap_splay_tree_predecessor (self, addr); - addrmap_splay_tree_insert (self, addr, - n ? addrmap_node_value (n) : NULL); + n =3D splay_tree_predecessor (addr); + splay_tree_insert (addr, n ? addrmap_node_value (n) : NULL); } } =20 @@ -351,14 +369,14 @@ addrmap_mutable::set_empty (CORE_ADDR start, CORE_ADD= R end_inclusive, - Second pass: remove any unnecessary transitions. */ =20 /* 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); =20 /* Walk the area, changing all NULL regions to OBJ. */ - for (n =3D addrmap_splay_tree_lookup (this, start), gdb_assert (n); + for (n =3D splay_tree_lookup (start), gdb_assert (n); n && addrmap_node_key (n) <=3D end_inclusive; - n =3D addrmap_splay_tree_successor (this, addrmap_node_key (n))) + n =3D splay_tree_successor (addrmap_node_key (n))) { if (! addrmap_node_value (n)) addrmap_node_set_value (n, obj); @@ -367,16 +385,16 @@ addrmap_mutable::set_empty (CORE_ADDR start, CORE_ADD= R end_inclusive, /* Walk the area again, removing transitions from any value to itself. Be sure to visit both the transitions we forced above. */ - n =3D addrmap_splay_tree_predecessor (this, start); + n =3D splay_tree_predecessor (start); prior_value =3D n ? addrmap_node_value (n) : NULL; - for (n =3D addrmap_splay_tree_lookup (this, start), gdb_assert (n); + for (n =3D splay_tree_lookup (start), gdb_assert (n); n && (end_inclusive =3D=3D CORE_ADDR_MAX || addrmap_node_key (n) <=3D end_inclusive + 1); n =3D next) { - next =3D addrmap_splay_tree_successor (this, addrmap_node_key (n)); + next =3D splay_tree_successor (addrmap_node_key (n)); if (addrmap_node_value (n) =3D=3D prior_value) - addrmap_splay_tree_remove (this, addrmap_node_key (n)); + splay_tree_remove (addrmap_node_key (n)); else prior_value =3D addrmap_node_value (n); } @@ -386,14 +404,14 @@ addrmap_mutable::set_empty (CORE_ADDR start, CORE_ADD= R end_inclusive, void * addrmap_mutable::find (CORE_ADDR addr) const { - splay_tree_node n =3D addrmap_splay_tree_lookup (this, addr); + splay_tree_node n =3D splay_tree_lookup (addr); if (n !=3D nullptr) { gdb_assert (addrmap_node_key (n) =3D=3D addr); return addrmap_node_value (n); } =20 - n =3D addrmap_splay_tree_predecessor (this, addr); + n =3D splay_tree_predecessor (addr); if (n !=3D nullptr) { gdb_assert (addrmap_node_key (n) < addr); @@ -475,8 +493,8 @@ addrmap_mutable::foreach (addrmap_foreach_fn fn) } =20 =20 -static void * -splay_obstack_alloc (int size, void *closure) +void * +addrmap_mutable::splay_obstack_alloc (int size, void *closure) { struct addrmap_mutable *map =3D (struct addrmap_mutable *) closure; splay_tree_node n; @@ -497,8 +515,8 @@ splay_obstack_alloc (int size, void *closure) } =20 =20 -static void -splay_obstack_free (void *obj, void *closure) +void +addrmap_mutable::splay_obstack_free (void *obj, void *closure) { struct addrmap_mutable *map =3D (struct addrmap_mutable *) closure; splay_tree_node n =3D (splay_tree_node) obj; @@ -528,26 +546,22 @@ splay_compare_CORE_ADDR_ptr (splay_tree_key ak, splay= _tree_key bk) } =20 =20 -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 =3D new (obstack) struct addrmap_mutable; - - map->obstack =3D 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 =3D NULL; +} =20 - map->tree =3D 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); =20 - return map; +struct addrmap * +addrmap_create_mutable (struct obstack *obstack) +{ + return new (obstack) struct addrmap_mutable (obstack); } =20 /* See addrmap.h. */