From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id CF5AD385AE4C; Sun, 12 Jun 2022 16:55:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF5AD385AE4C 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_fixed X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: a692aa3f1dc1106edaa0b93b23bd1179a8833548 X-Git-Newrev: 5427f03f9e0ab815ca5dbc73339ef27863a6f2df Message-Id: <20220612165530.CF5AD385AE4C@sourceware.org> Date: Sun, 12 Jun 2022 16:55:30 +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:30 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D5427f03f9e0a= b815ca5dbc73339ef27863a6f2df commit 5427f03f9e0ab815ca5dbc73339ef27863a6f2df Author: Tom Tromey Date: Sat Apr 16 09:10:29 2022 -0600 Privacy for addrmap_fixed =20 This changes addrmap_fixed so that its data members are private. It also makes struct addrmap_transition private as well. Diff: --- gdb/addrmap.c | 97 +++++++++++++++++++++++++++----------------------------= ---- 1 file changed, 44 insertions(+), 53 deletions(-) diff --git a/gdb/addrmap.c b/gdb/addrmap.c index 3f3629f3bb2..915dc88c1ec 100644 --- a/gdb/addrmap.c +++ b/gdb/addrmap.c @@ -84,18 +84,15 @@ addrmap_foreach (struct addrmap *map, addrmap_foreach_f= n fn) =0C /* Fixed address maps. */ =20 -/* A transition: a point in an address map where the value changes. - The map maps ADDR to VALUE, but if ADDR > 0, it maps ADDR-1 to - something else. */ -struct addrmap_transition -{ - CORE_ADDR addr; - void *value; -}; - +struct addrmap_mutable; =20 struct addrmap_fixed : public addrmap { +public: + + addrmap_fixed (struct obstack *obstack, addrmap_mutable *mut); + DISABLE_COPY_AND_ASSIGN (addrmap_fixed); + void set_empty (CORE_ADDR start, CORE_ADDR end_inclusive, void *obj) override; void *find (CORE_ADDR addr) const override; @@ -103,6 +100,17 @@ struct addrmap_fixed : public addrmap void relocate (CORE_ADDR offset) override; int foreach (addrmap_foreach_fn fn) override; =20 +private: + + /* A transition: a point in an address map where the value changes. + The map maps ADDR to VALUE, but if ADDR > 0, it maps ADDR-1 to + something else. */ + struct addrmap_transition + { + CORE_ADDR addr; + void *value; + }; + /* The number of transitions in TRANSITIONS. */ size_t num_transitions; =20 @@ -396,63 +404,46 @@ addrmap_mutable::find (CORE_ADDR addr) const } =20 =20 -/* A function to pass to splay_tree_foreach to count the number of nodes - in the tree. */ -static int -splay_foreach_count (splay_tree_node n, void *closure) -{ - size_t *count =3D (size_t *) closure; - - (*count)++; - return 0; -} - - -/* A function to pass to splay_tree_foreach to copy entries into a - fixed address map. */ -static int -splay_foreach_copy (splay_tree_node n, void *closure) -{ - struct addrmap_fixed *fixed =3D (struct addrmap_fixed *) closure; - struct addrmap_transition *t =3D &fixed->transitions[fixed->num_transiti= ons]; - - t->addr =3D addrmap_node_key (n); - t->value =3D addrmap_node_value (n); - fixed->num_transitions++; - - return 0; -} - - -struct addrmap * -addrmap_mutable::create_fixed (struct obstack *obstack) +addrmap_fixed::addrmap_fixed (struct obstack *obstack, addrmap_mutable *mu= t) { - struct addrmap_fixed *fixed; - size_t num_transitions; + size_t transition_count =3D 0; =20 /* Count the number of transitions in the tree. */ - num_transitions =3D 0; - splay_tree_foreach (tree, splay_foreach_count, &num_transitions); + addrmap_foreach (mut, [&] (CORE_ADDR start, void *obj) + { + ++transition_count; + return 0; + }); =20 /* Include an extra entry for the transition at zero (which fixed maps have, but mutable maps do not.) */ - num_transitions++; + transition_count++; =20 - fixed =3D new (obstack) struct addrmap_fixed; - fixed->num_transitions =3D 1; - fixed->transitions =3D XOBNEWVEC (obstack, struct addrmap_transition, - num_transitions); - fixed->transitions[0].addr =3D 0; - fixed->transitions[0].value =3D NULL; + num_transitions =3D 1; + transitions =3D XOBNEWVEC (obstack, struct addrmap_transition, + transition_count); + transitions[0].addr =3D 0; + transitions[0].value =3D NULL; =20 /* Copy all entries from the splay tree to the array, in order=20 of increasing address. */ - splay_tree_foreach (tree, splay_foreach_copy, fixed); + addrmap_foreach (mut, [&] (CORE_ADDR start, void *obj) + { + transitions[num_transitions].addr =3D start; + transitions[num_transitions].value =3D obj; + ++num_transitions; + return 0; + }); =20 /* We should have filled the array. */ - gdb_assert (fixed->num_transitions =3D=3D num_transitions); + gdb_assert (num_transitions =3D=3D transition_count); +} =20 - return fixed; + +struct addrmap * +addrmap_mutable::create_fixed (struct obstack *obstack) +{ + return new (obstack) struct addrmap_fixed (obstack, this); }