Make addrmap const-correct in cooked index
authorTom Tromey <tromey@adacore.com>
Mon, 30 Jan 2023 15:29:36 +0000 (10:29 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 30 Jan 2023 16:55:07 +0000 (11:55 -0500)
After the cooked index is created, the addrmaps should be const.

Change-Id: I8234520ab346ced40a8dd6e478ba21fc438c2ba2

gdb/dwarf2/cooked-index.c
gdb/dwarf2/cooked-index.h
gdb/dwarf2/index-write.c

index 1a568e6aae7659b1e1efc37a02abcdba0237b8c8..646bc76575cd858734b220ea1fb6bac0d6b803c6 100644 (file)
@@ -401,10 +401,10 @@ cooked_index_vector::lookup (CORE_ADDR addr)
 
 /* See cooked-index.h.  */
 
-std::vector<addrmap *>
-cooked_index_vector::get_addrmaps ()
+std::vector<const addrmap *>
+cooked_index_vector::get_addrmaps () const
 {
-  std::vector<addrmap *> result;
+  std::vector<const addrmap *> result;
   for (const auto &index : m_vector)
     result.push_back (index->m_addrmap);
   return result;
index 7a8c18975e5af2392177fe98a533b79905688b66..7299a4f77b44248cae6cc3426adbd9595f8e2eb5 100644 (file)
@@ -360,7 +360,7 @@ public:
 
   /* 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 () const;
 
   /* Return the entry that is believed to represent the program's
      "main".  This will return NULL if no such entry is available.  */
index 7b1b2d6520cb8f5891f9a8545c246170e69e6871..82cd3a8636d0004e30d2ba949d14c93e545aea1d 100644 (file)
@@ -433,7 +433,8 @@ write_hash_table (mapped_symtab *symtab, data_buf &output, data_buf &cpool)
     }
 }
 
-typedef std::unordered_map<dwarf2_per_cu_data *, unsigned int> cu_index_map;
+using cu_index_map
+  = std::unordered_map<const dwarf2_per_cu_data *, unsigned int>;
 
 /* Helper struct for building the address table.  */
 struct addrmap_index_data
@@ -446,7 +447,7 @@ struct addrmap_index_data
   data_buf &addr_vec;
   cu_index_map &cu_index_htab;
 
-  int operator() (CORE_ADDR start_addr, void *obj);
+  int operator() (CORE_ADDR start_addr, const void *obj);
 
   /* True if the previous_* fields are valid.
      We can't write an entry until we see the next entry (since it is only then
@@ -472,9 +473,10 @@ add_address_entry (data_buf &addr_vec,
 /* Worker function for traversing an addrmap to build the address table.  */
 
 int
-addrmap_index_data::operator() (CORE_ADDR start_addr, void *obj)
+addrmap_index_data::operator() (CORE_ADDR start_addr, const void *obj)
 {
-  dwarf2_per_cu_data *per_cu = static_cast<dwarf2_per_cu_data *> (obj);
+  const dwarf2_per_cu_data *per_cu
+    = static_cast<const dwarf2_per_cu_data *> (obj);
 
   if (previous_valid)
     add_address_entry (addr_vec,
@@ -500,7 +502,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);