public inbox for gdb-cvs@sourceware.org help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org> To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Privacy for addrmap_fixed Date: Sun, 12 Jun 2022 16:55:30 +0000 (GMT) [thread overview] Message-ID: <20220612165530.CF5AD385AE4C@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5427f03f9e0ab815ca5dbc73339ef27863a6f2df commit 5427f03f9e0ab815ca5dbc73339ef27863a6f2df Author: Tom Tromey <tom@tromey.com> Date: Sat Apr 16 09:10:29 2022 -0600 Privacy for addrmap_fixed 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_fn fn) \f /* Fixed address maps. */ -/* 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; 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; +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; @@ -396,63 +404,46 @@ addrmap_mutable::find (CORE_ADDR addr) const } -/* 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 = (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 = (struct addrmap_fixed *) closure; - struct addrmap_transition *t = &fixed->transitions[fixed->num_transitions]; - - t->addr = addrmap_node_key (n); - t->value = 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 *mut) { - struct addrmap_fixed *fixed; - size_t num_transitions; + size_t transition_count = 0; /* Count the number of transitions in the tree. */ - num_transitions = 0; - splay_tree_foreach (tree, splay_foreach_count, &num_transitions); + addrmap_foreach (mut, [&] (CORE_ADDR start, void *obj) + { + ++transition_count; + return 0; + }); /* Include an extra entry for the transition at zero (which fixed maps have, but mutable maps do not.) */ - num_transitions++; + transition_count++; - fixed = new (obstack) struct addrmap_fixed; - fixed->num_transitions = 1; - fixed->transitions = XOBNEWVEC (obstack, struct addrmap_transition, - num_transitions); - fixed->transitions[0].addr = 0; - fixed->transitions[0].value = NULL; + num_transitions = 1; + transitions = XOBNEWVEC (obstack, struct addrmap_transition, + transition_count); + transitions[0].addr = 0; + transitions[0].value = NULL; /* Copy all entries from the splay tree to the array, in order of increasing address. */ - splay_tree_foreach (tree, splay_foreach_copy, fixed); + addrmap_foreach (mut, [&] (CORE_ADDR start, void *obj) + { + transitions[num_transitions].addr = start; + transitions[num_transitions].value = obj; + ++num_transitions; + return 0; + }); /* We should have filled the array. */ - gdb_assert (fixed->num_transitions == num_transitions); + gdb_assert (num_transitions == transition_count); +} - return fixed; + +struct addrmap * +addrmap_mutable::create_fixed (struct obstack *obstack) +{ + return new (obstack) struct addrmap_fixed (obstack, this); }
reply other threads:[~2022-06-12 16:55 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220612165530.CF5AD385AE4C@sourceware.org \ --to=tromey@sourceware.org \ --cc=gdb-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).