diff options
author | Tom Tromey <tom@tromey.com> | 2023-03-02 07:44:11 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2024-01-28 10:58:16 -0700 |
commit | 974b36c2ae2b351d022cc62579656f722da6e17a (patch) | |
tree | 1d7d813ffba23ac283f502e655460d52156a7d18 /gdb/dwarf2/read.c | |
parent | 10d6e9413e7ab9b30fbdb69e03262dc327831f84 (diff) | |
download | gdb-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/read.c')
-rw-r--r-- | gdb/dwarf2/read.c | 31 |
1 files changed, 25 insertions, 6 deletions
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; |