From: Tom Tromey Date: Wed, 12 Jun 2024 17:24:27 +0000 (-0600) Subject: Store new Ada entries in cooked_index_shard::m_entries X-Git-Tag: binutils-2_45~1341 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c70ac07a791bf50ae9322a3096a3b8b1220e60c9;p=thirdparty%2Fbinutils-gdb.git Store new Ada entries in cooked_index_shard::m_entries 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. --- diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index a3d5288a264..f630d34b928 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -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 &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 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 (), diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 0930805cf04..c47f84e7cc8 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -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 &new_entries); /* Finalize the index. This should be called a single time, when the index has been fully populated. It enters all the entries