]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Store new Ada entries in cooked_index_shard::m_entries
authorTom Tromey <tromey@adacore.com>
Wed, 12 Jun 2024 17:24:27 +0000 (11:24 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 6 Mar 2025 21:17:18 +0000 (14:17 -0700)
handle_gnat_encoded_entry might create synthetic cooked index entries
for Ada packages.  These aren't currently kept in m_entries, but it
seems to me that they should be, particularly because a forthcoming
GNAT will emit explicit DW_TAG_module for these names -- with this
change, the indexes will be roughly equivalent regardless of which
compiler was used.

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

index a3d5288a26485901ab5f606fad9df7aab3fb71c0..f630d34b92861f79ec475d897837ad858a3be826 100644 (file)
@@ -327,8 +327,10 @@ cooked_index_shard::add (sect_offset die_offset, enum dwarf_tag tag,
 /* See cooked-index.h.  */
 
 void
-cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry,
-                                              htab_t gnat_entries)
+cooked_index_shard::handle_gnat_encoded_entry
+     (cooked_index_entry *entry,
+      htab_t gnat_entries,
+      std::vector<cooked_index_entry *> &new_entries)
 {
   /* We decode Ada names in a particular way: operators and wide
      characters are left as-is.  This is done to make name matching a
@@ -363,6 +365,7 @@ cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry,
                         entry->per_cu);
          last->canonical = last->name;
          m_names.push_back (std::move (new_name));
+         new_entries.push_back (last);
          *slot = last;
        }
 
@@ -416,6 +419,7 @@ cooked_index_shard::finalize (const parent_map_map *parent_maps)
 
   htab_up gnat_entries (htab_create_alloc (10, hash_entry, eq_entry,
                                           nullptr, xcalloc, xfree));
+  std::vector<cooked_index_entry *> new_gnat_entries;
 
   for (cooked_index_entry *entry : m_entries)
     {
@@ -432,7 +436,8 @@ cooked_index_shard::finalize (const parent_map_map *parent_maps)
       if ((entry->flags & IS_LINKAGE) != 0)
        entry->canonical = entry->name;
       else if (entry->lang == language_ada)
-       handle_gnat_encoded_entry (entry, gnat_entries.get ());
+       handle_gnat_encoded_entry (entry, gnat_entries.get (),
+                                  new_gnat_entries);
       else if (entry->lang == language_cplus || entry->lang == language_c)
        {
          void **slot = htab_find_slot (seen_names.get (), entry,
@@ -463,6 +468,12 @@ cooked_index_shard::finalize (const parent_map_map *parent_maps)
        entry->canonical = entry->name;
     }
 
+  /* Make sure any new Ada entries end up in the results.  This isn't
+     done when creating these new entries to avoid invalidating the
+     m_entries iterator used in the foreach above.  */
+  m_entries.insert (m_entries.end (), new_gnat_entries.begin (),
+                   new_gnat_entries.end ());
+
   m_names.shrink_to_fit ();
   m_entries.shrink_to_fit ();
   std::sort (m_entries.begin (), m_entries.end (),
index 0930805cf04b938c90a4e77476e4ec2eb62496ce..c47f84e7cc8885859fe94ed716ac4b3f1be54b01 100644 (file)
@@ -338,12 +338,14 @@ private:
                              cooked_index_entry_ref parent_entry,
                              dwarf2_per_cu *per_cu);
 
-  /* GNAT only emits mangled ("encoded") names in the DWARF, and does
-     not emit the module structure.  However, we need this structure
-     to do lookups.  This function recreates that structure for an
-     existing entry, modifying ENTRY as appropriate.  */
+  /* When GNAT emits mangled ("encoded") names in the DWARF, and does
+     not emit the module structure, we still need this structuring to
+     do lookups.  This function recreates that information for an
+     existing entry, modifying ENTRY as appropriate.  Any new entries
+     are added to NEW_ENTRIES.  */
   void handle_gnat_encoded_entry
-       (cooked_index_entry *entry, htab_t gnat_entries);
+       (cooked_index_entry *entry, htab_t gnat_entries,
+       std::vector<cooked_index_entry *> &new_entries);
 
   /* Finalize the index.  This should be called a single time, when
      the index has been fully populated.  It enters all the entries