public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] Make addrmap const-correct in cooked index
Date: Fri, 27 Jan 2023 09:26:03 -0700	[thread overview]
Message-ID: <20230127162603.4127820-1-tromey@adacore.com> (raw)

After the cooked index is created, the addrmaps should be const.  This
is slightly complicated by the fact that addrmap::foreach is not const
-- however, it should be.  The underlying splay tree might be
rearranged during a foreach, but if so, this is a classic case where
'mutable' semantics make sense.
---
 gdb/addrmap.c             | 4 ++--
 gdb/addrmap.h             | 6 +++---
 gdb/dwarf2/cooked-index.c | 4 ++--
 gdb/dwarf2/cooked-index.h | 2 +-
 gdb/dwarf2/index-write.c  | 2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/gdb/addrmap.c b/gdb/addrmap.c
index 0a6b2e5a25a..47ceaca48ad 100644
--- a/gdb/addrmap.c
+++ b/gdb/addrmap.c
@@ -82,7 +82,7 @@ addrmap_fixed::relocate (CORE_ADDR offset)
 
 
 int
-addrmap_fixed::foreach (addrmap_foreach_fn fn)
+addrmap_fixed::foreach (addrmap_foreach_fn fn) const
 {
   size_t i;
 
@@ -317,7 +317,7 @@ addrmap_mutable_foreach_worker (splay_tree_node node, void *data)
 
 
 int
-addrmap_mutable::foreach (addrmap_foreach_fn fn)
+addrmap_mutable::foreach (addrmap_foreach_fn fn) const
 {
   return splay_tree_foreach (tree, addrmap_mutable_foreach_worker, &fn);
 }
diff --git a/gdb/addrmap.h b/gdb/addrmap.h
index a5b784efaf2..659d3c977a8 100644
--- a/gdb/addrmap.h
+++ b/gdb/addrmap.h
@@ -95,7 +95,7 @@ struct addrmap
      If FN ever returns a non-zero value, the iteration ceases
      immediately, and the value is returned.  Otherwise, this function
      returns 0.  */
-  virtual int foreach (addrmap_foreach_fn fn) = 0;
+  virtual int foreach (addrmap_foreach_fn fn) const = 0;
 };
 
 struct addrmap_mutable;
@@ -113,7 +113,7 @@ struct addrmap_fixed : public addrmap,
 		  void *obj) override;
   void *find (CORE_ADDR addr) const override;
   void relocate (CORE_ADDR offset) override;
-  int foreach (addrmap_foreach_fn fn) override;
+  int foreach (addrmap_foreach_fn fn) const override;
 
 private:
 
@@ -151,7 +151,7 @@ struct addrmap_mutable : public addrmap
 		  void *obj) override;
   void *find (CORE_ADDR addr) const override;
   void relocate (CORE_ADDR offset) override;
-  int foreach (addrmap_foreach_fn fn) override;
+  int foreach (addrmap_foreach_fn fn) const override;
 
 private:
 
diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index 09b3fd70b26..6f228cdc749 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -401,10 +401,10 @@ cooked_index_vector::lookup (CORE_ADDR addr)
 
 /* See cooked-index.h.  */
 
-std::vector<addrmap *>
+std::vector<const addrmap *>
 cooked_index_vector::get_addrmaps ()
 {
-  std::vector<addrmap *> result;
+  std::vector<const addrmap *> result;
   for (const auto &index : m_vector)
     result.push_back (index->m_addrmap);
   return result;
diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index 55eaf9955ab..dc3fe6e262f 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -359,7 +359,7 @@ class cooked_index_vector : public dwarf_scanner_base
 
   /* Return a new vector of all the addrmaps used by all the indexes
      held by this object.  */
-  std::vector<addrmap *> get_addrmaps ();
+  std::vector<const addrmap *> get_addrmaps ();
 
   /* Return the entry that is believed to represent the program's
      "main".  This will return NULL if no such entry is available.  */
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index ced58eab661..9b4a02bc694 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -500,7 +500,7 @@ addrmap_index_data::operator() (CORE_ADDR start_addr, void *obj)
    in the index file.  */
 
 static void
-write_address_map (struct addrmap *addrmap, data_buf &addr_vec,
+write_address_map (const addrmap *addrmap, data_buf &addr_vec,
 		   cu_index_map &cu_index_htab)
 {
   struct addrmap_index_data addrmap_index_data (addr_vec, cu_index_htab);
-- 
2.38.1


             reply	other threads:[~2023-01-27 16:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-27 16:26 Tom Tromey [this message]
2023-01-27 19:58 ` Simon Marchi
2023-01-27 21:15   ` Tom Tromey
2023-01-27 21:18   ` Tom Tromey
2023-01-27 21:20     ` Simon Marchi
2023-01-27 21:26       ` Simon Marchi
2023-01-30 14:15         ` Tom Tromey
2023-01-27 22:00     ` Simon Marchi
2023-01-30 14:26       ` Tom Tromey
2023-01-30 15:22         ` Simon Marchi
2023-01-30 15:29           ` [PATCH v2] " Simon Marchi
2023-01-30 16:54             ` Tom Tromey
2023-01-30 16:55               ` Simon Marchi

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=20230127162603.4127820-1-tromey@adacore.com \
    --to=tromey@adacore.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).