public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/7] Add move operators for addrmap
Date: Wed, 17 Jan 2024 11:58:50 -0700	[thread overview]
Message-ID: <20240117-die-map-madness-v1-3-42fb435ad1ed@tromey.com> (raw)
In-Reply-To: <20240117-die-map-madness-v1-0-42fb435ad1ed@tromey.com>

A subsequent patch needs to move an addrmap.  This patch adds the
necessary support.  It also changes addrmap_fixed to take a 'const'
addrmap_mutable.  This is fine according to the contract of
addrmap_mutable; but it did require a compensating const_cast in the
implementation.
---
 gdb/addrmap.c | 12 +++++++-----
 gdb/addrmap.h | 19 ++++++++++++++++++-
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/gdb/addrmap.c b/gdb/addrmap.c
index 162ab84763b..682ffa98573 100644
--- a/gdb/addrmap.c
+++ b/gdb/addrmap.c
@@ -251,12 +251,13 @@ addrmap_mutable::do_find (CORE_ADDR addr) const
 }
 
 
-addrmap_fixed::addrmap_fixed (struct obstack *obstack, addrmap_mutable *mut)
+addrmap_fixed::addrmap_fixed (struct obstack *obstack,
+			      const addrmap_mutable *mut)
 {
   size_t transition_count = 0;
 
   /* Count the number of transitions in the tree.  */
-  mut->foreach ([&] (CORE_ADDR start, void *obj)
+  mut->foreach ([&] (CORE_ADDR start, const void *obj)
     {
       ++transition_count;
       return 0;
@@ -274,10 +275,10 @@ addrmap_fixed::addrmap_fixed (struct obstack *obstack, addrmap_mutable *mut)
 
   /* Copy all entries from the splay tree to the array, in order 
      of increasing address.  */
-  mut->foreach ([&] (CORE_ADDR start, void *obj)
+  mut->foreach ([&] (CORE_ADDR start, const void *obj)
     {
       transitions[num_transitions].addr = start;
-      transitions[num_transitions].value = obj;
+      transitions[num_transitions].value = const_cast<void *> (obj);
       ++num_transitions;
       return 0;
     });
@@ -345,7 +346,8 @@ addrmap_mutable::addrmap_mutable ()
 
 addrmap_mutable::~addrmap_mutable ()
 {
-  splay_tree_delete (tree);
+  if (tree != nullptr)
+    splay_tree_delete (tree);
 }
 
 
diff --git a/gdb/addrmap.h b/gdb/addrmap.h
index ba83607ad8c..1dd1e35ec11 100644
--- a/gdb/addrmap.h
+++ b/gdb/addrmap.h
@@ -84,9 +84,14 @@ struct addrmap_fixed : public addrmap,
 {
 public:
 
-  addrmap_fixed (struct obstack *obstack, addrmap_mutable *mut);
+  addrmap_fixed (struct obstack *obstack, const addrmap_mutable *mut);
   DISABLE_COPY_AND_ASSIGN (addrmap_fixed);
 
+  /* It's fine to use the default move operators, because this addrmap
+     does not own the storage for the elements.  */
+  addrmap_fixed (addrmap_fixed &&other) = default;
+  addrmap_fixed &operator= (addrmap_fixed &&) = default;
+
   void relocate (CORE_ADDR offset) override;
 
 private:
@@ -123,6 +128,18 @@ struct addrmap_mutable : public addrmap
   ~addrmap_mutable ();
   DISABLE_COPY_AND_ASSIGN (addrmap_mutable);
 
+  addrmap_mutable (addrmap_mutable &&other)
+    : tree (other.tree)
+  {
+    other.tree = nullptr;
+  }
+
+  addrmap_mutable &operator= (addrmap_mutable &&other)
+  {
+    std::swap (tree, other.tree);
+    return *this;
+  }
+
   /* In the mutable address map MAP, associate the addresses from START
      to END_INCLUSIVE that are currently associated with NULL with OBJ
      instead.  Addresses mapped to an object other than NULL are left

-- 
2.43.0


  parent reply	other threads:[~2024-01-17 18:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-17 18:58 [PATCH gdb/symtab 0/7] Compute DWARF entry parents across CUs Tom Tromey
2024-01-17 18:58 ` [PATCH gdb/symtab 1/7] Refactor condition in scan_attributes Tom Tromey
2024-01-17 18:58 ` [PATCH 2/7] Change handling of DW_TAG_enumeration_type in DWARF scanner Tom Tromey
2024-01-17 18:58 ` Tom Tromey [this message]
2024-01-17 18:58 ` [PATCH 4/7] Introduce class parent_map for DIE range map Tom Tromey
2024-01-17 18:58 ` [PATCH 5/7] Correctly handle DIE parent computations Tom Tromey
2024-01-17 18:58 ` [PATCH gdb/testsuite 6/7] Add gdb.dwarf2/forward-spec-inter-cu.exp Tom Tromey
2024-01-17 18:58 ` [PATCH gdb/testsuite 7/7] Add gdb.dwarf2/backward-spec-inter-cu.exp 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=20240117-die-map-madness-v1-3-42fb435ad1ed@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).