aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2023-03-02 07:44:11 -0700
committerTom Tromey <tom@tromey.com>2024-01-28 10:58:16 -0700
commit974b36c2ae2b351d022cc62579656f722da6e17a (patch)
tree1d7d813ffba23ac283f502e655460d52156a7d18 /gdb/dwarf2
parent10d6e9413e7ab9b30fbdb69e03262dc327831f84 (diff)
downloadgdb-974b36c2ae2b351d022cc62579656f722da6e17a.zip
gdb-974b36c2ae2b351d022cc62579656f722da6e17a.tar.gz
gdb-974b36c2ae2b351d022cc62579656f722da6e17a.tar.bz2
Use the new symbol domains
This patch changes the DWARF reader to use the new symbol domains. It also adjusts many bits of associated code to adapt to this change. The non-DWARF readers are updated on a best-effort basis. This is somewhat simpler since most of them only support C and C++. I have no way to test a few of these. I went back and forth a few times on how to handle the "tag" situation. The basic problem is that C has a special namespace for tags, which is separate from the type namespace. Other languages don't do this. So, the question is, should a DW_TAG_structure_type end up in the tag domain, or the type domain, or should it be language-dependent? I settled on making it language-dependent using a thought experiment. Suppose there was a Rust compiler that only emitted nameless DW_TAG_structure_type objects, and specified all structure type names using DW_TAG_typedef. This DWARF would be correct, in that it faithfully represents the source language -- but would not work with a purely struct-domain implementation in gdb. Therefore gdb would be wrong. Now, this approach is a little tricky for C++, which uses tags but also enters a typedef for them. I notice that some other readers -- like stabsread -- actually emit a typedef symbol as well. And, I think this is a reasonable approach. It uses more memory, but it makes the internals simpler. However, DWARF never did this for whatever reason, and so in the interest of keeping the series slightly shorter, I've left some C++-specific hacks in place here. Note that this patch includes language_minimal as a language that uses tags. I did this to avoid regressing gdb.dwarf2/debug-names-tu.exp, which doesn't specify the language for a type unit. Arguably this test case is wrong. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30164
Diffstat (limited to 'gdb/dwarf2')
-rw-r--r--gdb/dwarf2/cooked-index.c26
-rw-r--r--gdb/dwarf2/index-write.c7
-rw-r--r--gdb/dwarf2/read-gdb-index.c2
-rw-r--r--gdb/dwarf2/read.c31
-rw-r--r--gdb/dwarf2/tag.h79
5 files changed, 109 insertions, 36 deletions
diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index 4831acc..dc8b6f0 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -205,31 +205,7 @@ cooked_index_entry::matches (domain_search_flags kind) const
if ((flags & IS_TYPE_DECLARATION) != 0)
return false;
- if ((kind & SEARCH_VAR_DOMAIN) != 0
- && (tag == DW_TAG_variable
- || tag == DW_TAG_constant
- || tag == DW_TAG_enumerator))
- return true;
-
- if ((kind & SEARCH_STRUCT_DOMAIN) != 0
- && (tag == DW_TAG_structure_type
- || tag == DW_TAG_class_type
- || tag == DW_TAG_union_type
- || tag == DW_TAG_enumeration_type))
- return true;
-
- if ((kind & SEARCH_MODULE_DOMAIN) != 0 && tag == DW_TAG_module)
- return true;
-
- if ((kind & SEARCH_TYPE_DOMAIN) != 0 && tag_is_type (tag))
- return true;
-
- if ((kind & SEARCH_FUNCTION_DOMAIN) != 0
- && (tag == DW_TAG_subprogram
- || tag == DW_TAG_entry_point))
- return true;
-
- return false;
+ return tag_matches_domain (tag, kind, lang);
}
/* See cooked-index.h. */
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 3b655dc..0123e7f 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1232,11 +1232,10 @@ write_cooked_index (cooked_index *table,
|| entry->tag == DW_TAG_constant
|| entry->tag == DW_TAG_enumerator)
kind = GDB_INDEX_SYMBOL_KIND_VARIABLE;
- else if (entry->tag == DW_TAG_module
- || entry->tag == DW_TAG_common_block)
- kind = GDB_INDEX_SYMBOL_KIND_OTHER;
- else
+ else if (tag_is_type (entry->tag))
kind = GDB_INDEX_SYMBOL_KIND_TYPE;
+ else
+ kind = GDB_INDEX_SYMBOL_KIND_OTHER;
symtab->add_index_entry (name, (entry->flags & IS_STATIC) != 0,
kind, it->second);
diff --git a/gdb/dwarf2/read-gdb-index.c b/gdb/dwarf2/read-gdb-index.c
index d474116..bf4f828 100644
--- a/gdb/dwarf2/read-gdb-index.c
+++ b/gdb/dwarf2/read-gdb-index.c
@@ -236,7 +236,7 @@ dw2_expand_marked_cus
mask = SEARCH_FUNCTION_DOMAIN;
break;
case GDB_INDEX_SYMBOL_KIND_TYPE:
- mask = SEARCH_TYPE_DOMAIN;
+ mask = SEARCH_TYPE_DOMAIN | SEARCH_STRUCT_DOMAIN;
break;
case GDB_INDEX_SYMBOL_KIND_OTHER:
mask = SEARCH_MODULE_DOMAIN;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index dfd50a0..ca72cbf 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -5684,9 +5684,7 @@ fixup_go_packaging (struct dwarf2_cu *cu)
sym = new (&objfile->objfile_obstack) symbol;
sym->set_language (language_go, &objfile->objfile_obstack);
sym->compute_and_set_names (saved_package_name, false, objfile->per_bfd);
- /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
- e.g., "main" finds the "main" module and not C's main(). */
- sym->set_domain (STRUCT_DOMAIN);
+ sym->set_domain (TYPE_DOMAIN);
sym->set_aclass_index (LOC_TYPEDEF);
sym->set_type (type);
@@ -18828,7 +18826,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
/* Default assumptions.
Use the passed type or decode it from the die. */
- sym->set_domain (VAR_DOMAIN);
+ sym->set_domain (UNDEF_DOMAIN);
sym->set_aclass_index (LOC_OPTIMIZED_OUT);
if (type != NULL)
sym->set_type (type);
@@ -18880,6 +18878,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
case DW_TAG_entry_point:
/* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
finish_block. */
+ sym->set_domain (FUNCTION_DOMAIN);
sym->set_aclass_index (LOC_BLOCK);
/* DW_TAG_entry_point provides an additional entry_point to an
existing sub_program. Therefore, we inherit the "external"
@@ -18894,6 +18893,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
case DW_TAG_subprogram:
/* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
finish_block. */
+ sym->set_domain (FUNCTION_DOMAIN);
sym->set_aclass_index (LOC_BLOCK);
attr2 = dwarf2_attr (die, DW_AT_external, cu);
if ((attr2 != nullptr && attr2->as_boolean ())
@@ -18938,6 +18938,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
case DW_TAG_inlined_subroutine:
/* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
finish_block. */
+ sym->set_domain (FUNCTION_DOMAIN);
sym->set_aclass_index (LOC_BLOCK);
sym->set_is_inlined (1);
list_to_add = cu->list_in_scope;
@@ -18948,6 +18949,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
case DW_TAG_constant:
case DW_TAG_variable:
case DW_TAG_member:
+ sym->set_domain (VAR_DOMAIN);
/* Compilation with minimal debug info may result in
variables with missing type entries. Change the
misleading `void' type to something sensible. */
@@ -19096,6 +19098,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
when we do not have enough information to show inlined frames;
pretend it's a local variable in that case so that the user can
still see it. */
+ sym->set_domain (VAR_DOMAIN);
struct context_stack *curr
= cu->get_builder ()->get_current_context_stack ();
if (curr != nullptr && curr->name != nullptr)
@@ -19134,11 +19137,25 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
sym->set_aclass_index (LOC_STATIC);
sym->set_domain (VAR_DOMAIN);
}
- else
+ else if (cu->lang () == language_c
+ || cu->lang () == language_cplus
+ || cu->lang () == language_objc
+ || cu->lang () == language_opencl
+ || cu->lang () == language_minimal)
{
+ /* These languages have a tag namespace. Note that
+ there's a special hack for C++ in the matching code,
+ so we don't need to enter a separate typedef for the
+ tag. */
sym->set_aclass_index (LOC_TYPEDEF);
sym->set_domain (STRUCT_DOMAIN);
}
+ else
+ {
+ /* Other languages don't have a tag namespace. */
+ sym->set_aclass_index (LOC_TYPEDEF);
+ sym->set_domain (TYPE_DOMAIN);
+ }
/* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
really ever be static objects: otherwise, if you try
@@ -19182,10 +19199,11 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
case DW_TAG_subrange_type:
case DW_TAG_generic_subrange:
sym->set_aclass_index (LOC_TYPEDEF);
- sym->set_domain (VAR_DOMAIN);
+ sym->set_domain (TYPE_DOMAIN);
list_to_add = cu->list_in_scope;
break;
case DW_TAG_enumerator:
+ sym->set_domain (VAR_DOMAIN);
attr = dwarf2_attr (die, DW_AT_const_value, cu);
if (attr != nullptr)
{
@@ -19203,6 +19221,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
break;
case DW_TAG_imported_declaration:
case DW_TAG_namespace:
+ sym->set_domain (TYPE_DOMAIN);
sym->set_aclass_index (LOC_TYPEDEF);
list_to_add = cu->get_builder ()->get_global_symbols ();
break;
diff --git a/gdb/dwarf2/tag.h b/gdb/dwarf2/tag.h
index 2fae4cc..2ceae53 100644
--- a/gdb/dwarf2/tag.h
+++ b/gdb/dwarf2/tag.h
@@ -21,6 +21,7 @@
#define GDB_DWARF2_TAG_H
#include "dwarf2.h"
+#include "symtab.h"
/* Return true if TAG represents a type, false otherwise. */
@@ -64,4 +65,82 @@ tag_is_type (dwarf_tag tag)
}
}
+/* Return true if the given DWARF tag matches the specified search
+ domain flags. LANG may affect the result, due to the "C++ tag
+ hack". */
+
+static inline bool
+tag_matches_domain (dwarf_tag tag, domain_search_flags search, language lang)
+{
+ domain_search_flags flags = 0;
+ switch (tag)
+ {
+ case DW_TAG_variable:
+ case DW_TAG_enumerator:
+ case DW_TAG_constant:
+ flags = SEARCH_VAR_DOMAIN;
+ break;
+
+ case DW_TAG_subprogram:
+ case DW_TAG_entry_point:
+ flags = SEARCH_FUNCTION_DOMAIN;
+ break;
+
+ case DW_TAG_structure_type:
+ case DW_TAG_class_type:
+ case DW_TAG_union_type:
+ case DW_TAG_enumeration_type:
+ {
+ if (lang == language_c
+ || lang == language_objc
+ || lang == language_opencl
+ || lang == language_minimal)
+ flags = SEARCH_STRUCT_DOMAIN;
+ else if (lang == language_cplus)
+ flags = SEARCH_STRUCT_DOMAIN | SEARCH_TYPE_DOMAIN;
+ else
+ flags = SEARCH_TYPE_DOMAIN;
+ }
+ break;
+
+ case DW_TAG_padding:
+ case DW_TAG_array_type:
+ case DW_TAG_pointer_type:
+ case DW_TAG_reference_type:
+ case DW_TAG_string_type:
+ case DW_TAG_subroutine_type:
+ case DW_TAG_ptr_to_member_type:
+ case DW_TAG_set_type:
+ case DW_TAG_subrange_type:
+ case DW_TAG_base_type:
+ case DW_TAG_const_type:
+ case DW_TAG_packed_type:
+ case DW_TAG_template_type_param:
+ case DW_TAG_volatile_type:
+ case DW_TAG_restrict_type:
+ case DW_TAG_interface_type:
+ case DW_TAG_namespace:
+ case DW_TAG_unspecified_type:
+ case DW_TAG_shared_type:
+ case DW_TAG_rvalue_reference_type:
+ case DW_TAG_coarray_type:
+ case DW_TAG_dynamic_type:
+ case DW_TAG_atomic_type:
+ case DW_TAG_immutable_type:
+ case DW_TAG_typedef:
+ flags = SEARCH_TYPE_DOMAIN;
+ break;
+
+ case DW_TAG_label:
+ flags = SEARCH_LABEL_DOMAIN;
+ break;
+
+ case DW_TAG_module:
+ flags = SEARCH_MODULE_DOMAIN;
+ break;
+ }
+
+ return (flags & search) != 0;
+}
+
#endif /* GDB_DWARF2_TAG_H */