From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/9] Privacy for addrmap_fixed
Date: Sat, 16 Apr 2022 10:58:14 -0600 [thread overview]
Message-ID: <20220416165821.3648899-3-tom@tromey.com> (raw)
In-Reply-To: <20220416165821.3648899-1-tom@tromey.com>
This changes addrmap_fixed so that its data members are private.
It also makes struct addrmap_transition private as well.
---
gdb/addrmap.c | 97 +++++++++++++++++++++++----------------------------
1 file changed, 44 insertions(+), 53 deletions(-)
diff --git a/gdb/addrmap.c b/gdb/addrmap.c
index f1df53cbe20..55a1b8c6fff 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) 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;
@@ -395,63 +403,46 @@ addrmap_mutable::find (CORE_ADDR addr)
}
-/* 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);
}
--
2.34.1
next prev parent reply other threads:[~2022-04-16 16:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-16 16:58 [PATCH 0/9] C++-ify addrmap Tom Tromey
2022-04-16 16:58 ` [PATCH 1/9] Use inheritance for addrmap Tom Tromey
2022-04-16 16:58 ` Tom Tromey [this message]
2022-04-16 16:58 ` [PATCH 3/9] Privacy for addrmap_mutable Tom Tromey
2022-04-16 16:58 ` [PATCH 4/9] Move addrmap classes to addrmap.h Tom Tromey
2022-04-16 16:58 ` [PATCH 5/9] Remove addrmap wrapper functions Tom Tromey
2022-04-16 16:58 ` [PATCH 6/9] Remove addrmap_create_mutable Tom Tromey
2022-04-16 16:58 ` [PATCH 7/9] Remove addrmap::create_fixed Tom Tromey
2022-04-16 16:58 ` [PATCH 8/9] Use malloc for mutable addrmaps Tom Tromey
2022-04-16 16:58 ` [PATCH 9/9] Remove psymtab_addrmap Tom Tromey
2022-06-12 16:48 ` [PATCH 0/9] C++-ify addrmap Tom Tromey
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=20220416165821.3648899-3-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@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: link
Be 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).