[PATCH v2 05/28] Fix index's handling of DW_TAG_imported_declaration

Tom Tromey
2025-04-02T23:53:38Z

Currently the full symbol reader puts DW_TAG_imported_declaration in
TYPE_DOMAIN, in the global scope. This patch changes the cooked
indexer to follow.

Without this patch, a later patch in the series would cause
nsalias.exp to regress.

This also updates read-gdb-index.c to do something similar.
---
gdb/dwarf2/cooked-indexer.c | 5 +++++
gdb/dwarf2/read-gdb-index.c | 2 +-
gdb/dwarf2/tag.h | 4 ++++
3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2/cooked-indexer.c b/gdb/dwarf2/cooked-indexer.c
index 7b9ffa79fe8fd6575a7d8c57424895073e790fba..bf9f1384781c54e067cb7e8441a5900613207a20 100644
--- a/gdb/dwarf2/cooked-indexer.c
+++ b/gdb/dwarf2/cooked-indexer.c
@@ -552,6 +552,11 @@ cooked_indexer::index_dies (cutu_reader *reader,
flags &= ~IS_STATIC;
flags |= parent_entry->flags & IS_STATIC;
}
+ else if (abbrev->tag == DW_TAG_imported_declaration)
+ {
+ /* Match the full reader. */
+ flags &= ~IS_STATIC;
+ }

if (abbrev->tag == DW_TAG_namespace
&& m_language == language_cplus
diff --git a/gdb/dwarf2/read-gdb-index.c b/gdb/dwarf2/read-gdb-index.c
index 343916309d7c4ca1072d3b11e4fa144d5ec435f4..eeaa38a502c09a0acdd1b60a1c0b8403843aa9fe 100644
--- a/gdb/dwarf2/read-gdb-index.c
+++ b/gdb/dwarf2/read-gdb-index.c
@@ -1098,7 +1098,7 @@ dw2_expand_marked_cus (dwarf2_per_objfile *per_objfile, offset_type idx,
mask = SEARCH_TYPE_DOMAIN | SEARCH_STRUCT_DOMAIN;
break;
case GDB_INDEX_SYMBOL_KIND_OTHER:
- mask = SEARCH_MODULE_DOMAIN;
+ mask = SEARCH_MODULE_DOMAIN | SEARCH_TYPE_DOMAIN;
break;
}
if ((kind & mask) == 0)
diff --git a/gdb/dwarf2/tag.h b/gdb/dwarf2/tag.h
index 865c2bc109d1bf41aa4365a5cf9bda66a1ced65b..ef1ad217c6d34fbacdf5f6372b0d29ad3b6e7bbd 100644
--- a/gdb/dwarf2/tag.h
+++ b/gdb/dwarf2/tag.h
@@ -102,6 +102,10 @@ tag_matches_domain (dwarf_tag tag, domain_search_flags search, language lang)
}
break;

+ case DW_TAG_imported_declaration:
+ /* DW_TAG_imported_declaration isn't necessarily a type, but the
+ scanner doesn't track the referent, and the full reader
+ also currently puts it in TYPE_DOMAIN. */
case DW_TAG_padding:
case DW_TAG_array_type:
case DW_TAG_pointer_type:

--
2.46.1