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] Move addrmap classes to addrmap.h
Date: Sun, 12 Jun 2022 16:55:40 +0000 (GMT)	[thread overview]
Message-ID: <20220612165540.F169C3857374@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1b3261edfb7b0c66f538c778a07f0bf2547c906d

commit 1b3261edfb7b0c66f538c778a07f0bf2547c906d
Author: Tom Tromey <tom@tromey.com>
Date:   Sat Apr 16 09:23:26 2022 -0600

    Move addrmap classes to addrmap.h
    
    This moves the addrmap class definitions to addrmap.h.  This is safe
    to do now that the contents are private.

Diff:
---
 gdb/addrmap.c | 114 ----------------------------------------------------
 gdb/addrmap.h | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 118 insertions(+), 121 deletions(-)

diff --git a/gdb/addrmap.c b/gdb/addrmap.c
index 30db7e78408..eddf084d822 100644
--- a/gdb/addrmap.c
+++ b/gdb/addrmap.c
@@ -18,7 +18,6 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "splay-tree.h"
 #include "gdbsupport/gdb_obstack.h"
 #include "addrmap.h"
 #include "gdbsupport/selftest.h"
@@ -29,21 +28,6 @@ gdb_static_assert (sizeof (splay_tree_key) >= sizeof (CORE_ADDR *));
 gdb_static_assert (sizeof (splay_tree_value) >= sizeof (void *));
 
 \f
-/* The base class for addrmaps.  */
-
-struct addrmap : public allocate_on_obstack
-{
-  virtual ~addrmap () = default;
-
-  virtual void set_empty (CORE_ADDR start, CORE_ADDR end_inclusive,
-			  void *obj) = 0;
-  virtual void *find (CORE_ADDR addr) const = 0;
-  virtual struct addrmap *create_fixed (struct obstack *obstack) = 0;
-  virtual void relocate (CORE_ADDR offset) = 0;
-  virtual int foreach (addrmap_foreach_fn fn) = 0;
-};
-
-
 void
 addrmap_set_empty (struct addrmap *map,
 		   CORE_ADDR start, CORE_ADDR end_inclusive,
@@ -84,45 +68,6 @@ addrmap_foreach (struct addrmap *map, addrmap_foreach_fn fn)
 \f
 /* Fixed address maps.  */
 
-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;
-  struct addrmap *create_fixed (struct obstack *obstack) override;
-  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;
-
-  /* An array of transitions, sorted by address.  For every point in
-     the map where either ADDR == 0 or ADDR is mapped to one value and
-     ADDR - 1 is mapped to something different, we have an entry here
-     containing ADDR and VALUE.  (Note that this means we always have
-     an entry for address 0).  */
-  struct addrmap_transition *transitions;
-};
-
-
 void
 addrmap_fixed::set_empty (CORE_ADDR start, CORE_ADDR end_inclusive,
 			  void *obj)
@@ -204,65 +149,6 @@ addrmap_fixed::foreach (addrmap_foreach_fn fn)
 \f
 /* Mutable address maps.  */
 
-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;
-  struct addrmap *create_fixed (struct obstack *obstack) override;
-  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.
-
-     Any addresses below the first node map to NULL.  (Unlike
-     fixed maps, we have no entry at (CORE_ADDR) 0; it doesn't 
-     simplify enough.)
-
-     The last region is assumed to end at CORE_ADDR_MAX.
-
-     Since we can't know whether CORE_ADDR is larger or smaller than
-     splay_tree_key (unsigned long) --- I think both are possible,
-     given all combinations of 32- and 64-bit hosts and targets ---
-     our keys are pointers to CORE_ADDR values.  Since the splay tree
-     library doesn't pass any closure pointer to the key free
-     function, we can't keep a freelist for keys.  Since mutable
-     addrmaps are only used temporarily right now, we just leak keys
-     from deleted nodes; they'll be freed when the obstack is freed.  */
-  splay_tree tree;
-
-  /* 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);
-};
-
-
 /* Allocate a copy of CORE_ADDR in the obstack.  */
 splay_tree_key
 addrmap_mutable::allocate_key (CORE_ADDR addr)
diff --git a/gdb/addrmap.h b/gdb/addrmap.h
index 412e4288897..c530200e4a9 100644
--- a/gdb/addrmap.h
+++ b/gdb/addrmap.h
@@ -20,6 +20,7 @@
 #ifndef ADDRMAP_H
 #define ADDRMAP_H
 
+#include "splay-tree.h"
 #include "gdbsupport/function-view.h"
 
 /* An address map is essentially a table mapping CORE_ADDRs onto GDB
@@ -33,8 +34,123 @@
    A fixed address map, once constructed (from a mutable address map),
    can't be edited.  Both kinds of map are allocated in obstacks.  */
 
-/* The opaque type representing address maps.  */
-struct addrmap;
+/* The type of a function used to iterate over the map.
+   OBJ is NULL for unmapped regions.  */
+typedef gdb::function_view<int (CORE_ADDR start_addr, void *obj)>
+     addrmap_foreach_fn;
+
+/* The base class for addrmaps.  */
+struct addrmap : public allocate_on_obstack
+{
+  virtual ~addrmap () = default;
+
+  virtual void set_empty (CORE_ADDR start, CORE_ADDR end_inclusive,
+			  void *obj) = 0;
+  virtual void *find (CORE_ADDR addr) const = 0;
+  virtual struct addrmap *create_fixed (struct obstack *obstack) = 0;
+  virtual void relocate (CORE_ADDR offset) = 0;
+  virtual int foreach (addrmap_foreach_fn fn) = 0;
+};
+
+struct addrmap_mutable;
+
+/* Fixed address maps.  */
+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;
+  struct addrmap *create_fixed (struct obstack *obstack) override;
+  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;
+
+  /* An array of transitions, sorted by address.  For every point in
+     the map where either ADDR == 0 or ADDR is mapped to one value and
+     ADDR - 1 is mapped to something different, we have an entry here
+     containing ADDR and VALUE.  (Note that this means we always have
+     an entry for address 0).  */
+  struct addrmap_transition *transitions;
+};
+
+/* Mutable address maps.  */
+
+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;
+  struct addrmap *create_fixed (struct obstack *obstack) override;
+  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.
+
+     Any addresses below the first node map to NULL.  (Unlike
+     fixed maps, we have no entry at (CORE_ADDR) 0; it doesn't 
+     simplify enough.)
+
+     The last region is assumed to end at CORE_ADDR_MAX.
+
+     Since we can't know whether CORE_ADDR is larger or smaller than
+     splay_tree_key (unsigned long) --- I think both are possible,
+     given all combinations of 32- and 64-bit hosts and targets ---
+     our keys are pointers to CORE_ADDR values.  Since the splay tree
+     library doesn't pass any closure pointer to the key free
+     function, we can't keep a freelist for keys.  Since mutable
+     addrmaps are only used temporarily right now, we just leak keys
+     from deleted nodes; they'll be freed when the obstack is freed.  */
+  splay_tree tree;
+
+  /* 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);
+};
+
 
 /* Create a mutable address map which maps every address to NULL.
    Allocate entries in OBSTACK.  */
@@ -93,11 +209,6 @@ struct addrmap *addrmap_create_fixed (struct addrmap *original,
    to either mutable or immutable maps.)  */
 void addrmap_relocate (struct addrmap *map, CORE_ADDR offset);
 
-/* The type of a function used to iterate over the map.
-   OBJ is NULL for unmapped regions.  */
-typedef gdb::function_view<int (CORE_ADDR start_addr, void *obj)>
-     addrmap_foreach_fn;
-
 /* Call FN for every address in MAP, following an in-order traversal.
    If FN ever returns a non-zero value, the iteration ceases
    immediately, and the value is returned.  Otherwise, this function


                 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=20220612165540.F169C3857374@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: 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).