]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use the new symbol domains
authorTom Tromey <tom@tromey.com>
Thu, 2 Mar 2023 14:44:11 +0000 (07:44 -0700)
committerTom Tromey <tom@tromey.com>
Sun, 28 Jan 2024 17:58:16 +0000 (10:58 -0700)
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

21 files changed:
gdb/ada-tasks.c
gdb/coffread.c
gdb/ctfread.c
gdb/dwarf2/cooked-index.c
gdb/dwarf2/index-write.c
gdb/dwarf2/read-gdb-index.c
gdb/dwarf2/read.c
gdb/dwarf2/tag.h
gdb/gdbtypes.c
gdb/go-exp.y
gdb/jit.c
gdb/language.c
gdb/mdebugread.c
gdb/rust-parse.c
gdb/stabsread.c
gdb/sym-domains.def
gdb/symtab.c
gdb/testsuite/gdb.ada/info_auto_lang.exp
gdb/testsuite/gdb.ada/ptype-o.exp
gdb/testsuite/gdb.fortran/info-types.exp
gdb/xcoffread.c

index fd3f5d1ead9b40ccb12c8429dee0d7885049c3c6..8ae94dcdbab293be01a2c79e04b52a0b77d540b3 100644 (file)
@@ -520,17 +520,17 @@ ada_get_tcb_types_info (void)
      C-like) lookups to get the first match.  */
 
   struct symbol *atcb_sym =
-    lookup_symbol_in_language (atcb_name, NULL, SEARCH_STRUCT_DOMAIN,
+    lookup_symbol_in_language (atcb_name, NULL, SEARCH_TYPE_DOMAIN,
                               language_c, NULL).symbol;
   const struct symbol *common_atcb_sym =
-    lookup_symbol_in_language (common_atcb_name, NULL, SEARCH_STRUCT_DOMAIN,
+    lookup_symbol_in_language (common_atcb_name, NULL, SEARCH_TYPE_DOMAIN,
                               language_c, NULL).symbol;
   const struct symbol *private_data_sym =
-    lookup_symbol_in_language (private_data_name, NULL, SEARCH_STRUCT_DOMAIN,
+    lookup_symbol_in_language (private_data_name, NULL, SEARCH_TYPE_DOMAIN,
                               language_c, NULL).symbol;
   const struct symbol *entry_call_record_sym =
     lookup_symbol_in_language (entry_call_record_name, NULL,
-                              SEARCH_STRUCT_DOMAIN,
+                              SEARCH_TYPE_DOMAIN,
                               language_c, NULL).symbol;
 
   if (atcb_sym == NULL || atcb_sym->type () == NULL)
@@ -538,7 +538,7 @@ ada_get_tcb_types_info (void)
       /* In Ravenscar run-time libs, the  ATCB does not have a dynamic
         size, so the symbol name differs.  */
       atcb_sym = lookup_symbol_in_language (atcb_name_fixed, NULL,
-                                           SEARCH_STRUCT_DOMAIN, language_c,
+                                           SEARCH_TYPE_DOMAIN, language_c,
                                            NULL).symbol;
 
       if (atcb_sym == NULL || atcb_sym->type () == NULL)
index 30a38035c52b0a967f0a0c628632207a3bb455dd..abb1c1880d6841b44c678fbadb935e048a39fed9 100644 (file)
@@ -1473,7 +1473,7 @@ patch_opaque_types (struct symtab *s)
         but search the whole chain, as there may be several syms
         from different files with the same name.  */
       if (real_sym->aclass () == LOC_TYPEDEF
-         && real_sym->domain () == VAR_DOMAIN
+         && real_sym->domain () == TYPE_DOMAIN
          && real_sym->type ()->code () == TYPE_CODE_PTR
          && real_sym->type ()->target_type ()->length () != 0)
        {
@@ -1544,6 +1544,7 @@ process_coff_symbol (struct coff_symbol *cs,
 
   if (ISFCN (cs->c_type))
     {
+      sym->set_domain (FUNCTION_DOMAIN);
       sym->set_value_longest
        (sym->value_longest () + objfile->text_section_offset ());
       sym->set_type
@@ -1626,7 +1627,7 @@ process_coff_symbol (struct coff_symbol *cs,
 
        case C_TPDEF:
          sym->set_aclass_index (LOC_TYPEDEF);
-         sym->set_domain (VAR_DOMAIN);
+         sym->set_domain (TYPE_DOMAIN);
 
          /* If type has no name, give it one.  */
          if (sym->type ()->name () == 0)
index 50bac18232ed6437c8c2123c8601cf88dfec7ff8..cbb8c3f2b8a6a5787dde963f71895009556e05d3 100644 (file)
@@ -505,7 +505,7 @@ new_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid)
          case CTF_K_INTEGER:
          case CTF_K_FLOAT:
            sym->set_aclass_index (LOC_TYPEDEF);
-           sym->set_domain (VAR_DOMAIN);
+           sym->set_domain (TYPE_DOMAIN);
            break;
          case CTF_K_POINTER:
            break;
index 4831accc9cb47b43024f57003243801b39c4a0ae..dc8b6f08ff451454f3500bf934b786bda0fa9cb8 100644 (file)
@@ -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.  */
index 3b655dc308eba973aa28f60f15ade3258efb9b84..0123e7f2435b1579796b2ceb1673565754b7ac1c 100644 (file)
@@ -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);
index d4741166e61cde910110c0f28ca5bc469ec5254e..bf4f828b007b7023aac65d3b7ac6e7b79d4092b2 100644 (file)
@@ -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;
index dfd50a057f50797484575f6833fc5522f38fa0dc..ca72cbfb7ff16b6aab41b0a22adcd82aaba681ae 100644 (file)
@@ -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;
index 2fae4cced78e917de1592cc0ff4ee69ab727e3f4..2ceae5393b5fee321ac35ffb3cab201fc8ae60b2 100644 (file)
@@ -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 */
index f4eff650799b635b8fd7d4ccd63fa78693487863..970a9e4a4a52744b4c431cda70726a357b1c80b8 100644 (file)
@@ -2988,15 +2988,19 @@ check_typedef (struct type *type)
            return make_qualified_type (type, instance_flags, NULL);
 
          name = type->name ();
-         /* FIXME: shouldn't we look in STRUCT_DOMAIN and/or
-            VAR_DOMAIN as appropriate?  */
          if (name == NULL)
            {
              stub_noname_complaint ();
              return make_qualified_type (type, instance_flags, NULL);
            }
-         sym = lookup_symbol (name, nullptr, SEARCH_STRUCT_DOMAIN,
-                              nullptr).symbol;
+         domain_search_flag flag
+           = ((type->language () == language_c
+               || type->language () == language_objc
+               || type->language () == language_opencl
+               || type->language () == language_minimal)
+              ? SEARCH_STRUCT_DOMAIN
+              : SEARCH_TYPE_DOMAIN);
+         sym = lookup_symbol (name, nullptr, flag, nullptr).symbol;
          if (sym)
            type->set_target_type (sym->type ());
          else                                  /* TYPE_CODE_UNDEF */
@@ -3077,8 +3081,6 @@ check_typedef (struct type *type)
   else if (type->is_stub () && !currently_reading_symtab)
     {
       const char *name = type->name ();
-      /* FIXME: shouldn't we look in STRUCT_DOMAIN and/or VAR_DOMAIN
-        as appropriate?  */
       struct symbol *sym;
 
       if (name == NULL)
@@ -3086,8 +3088,14 @@ check_typedef (struct type *type)
          stub_noname_complaint ();
          return make_qualified_type (type, instance_flags, NULL);
        }
-      sym = lookup_symbol (name, nullptr, SEARCH_STRUCT_DOMAIN,
-                          nullptr).symbol;
+      domain_search_flag flag
+       = ((type->language () == language_c
+           || type->language () == language_objc
+           || type->language () == language_opencl
+           || type->language () == language_minimal)
+          ? SEARCH_STRUCT_DOMAIN
+          : SEARCH_TYPE_DOMAIN);
+      sym = lookup_symbol (name, nullptr, flag, nullptr).symbol;
       if (sym)
        {
          /* Same as above for opaque types, we can replace the stub
index a3afbbb8514a7c4add3322c5e81d54d274119401..2e56e4bff6105f613504a9ef58742637d0b644cb 100644 (file)
@@ -1293,7 +1293,7 @@ package_name_p (const char *name, const struct block *block)
   struct symbol *sym;
   struct field_of_this_result is_a_field_of_this;
 
-  sym = lookup_symbol (name, block, SEARCH_STRUCT_DOMAIN,
+  sym = lookup_symbol (name, block, SEARCH_TYPE_DOMAIN,
                       &is_a_field_of_this).symbol;
 
   if (sym
index 7960d32acd14f5e802257036d395c6d4cf2ac002..f1dbf39f73fda82052012d222c12ced10738042b 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -581,7 +581,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
       new_block->set_end (gdb_block_iter.end);
 
       /* The name.  */
-      block_name->set_domain (VAR_DOMAIN);
+      block_name->set_domain (FUNCTION_DOMAIN);
       block_name->set_aclass_index (LOC_BLOCK);
       block_name->set_symtab (filetab);
       block_name->set_type (lookup_function_type (block_type));
index d6f6831c190924f0337c04f69f3d2c21ea15166e..c5bbc31996376048ac04f47ae26e37c86dc75b11 100644 (file)
@@ -974,7 +974,7 @@ language_arch_info::type_and_symbol::alloc_type_symbol
   symbol->set_is_objfile_owned (0);
   symbol->set_section_index (0);
   symbol->set_type (type);
-  symbol->set_domain (VAR_DOMAIN);
+  symbol->set_domain (TYPE_DOMAIN);
   symbol->set_aclass_index (LOC_TYPEDEF);
   return symbol;
 }
index 13c9401d1714daa2426df1f07db6272c59750aa9..4748b0cd7aa84ea9c2d41f56af6ae9caca4b4bc6 100644 (file)
@@ -753,7 +753,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
          break;
        }
       s = new_symbol (name);
-      s->set_domain (VAR_DOMAIN);
+      s->set_domain (FUNCTION_DOMAIN);
       s->set_aclass_index (LOC_BLOCK);
       s->set_section_index (section_index);
       /* Type of the return value.  */
@@ -1297,7 +1297,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
       if (has_opaque_xref (cur_fdr, sh))
        break;
       s = new_symbol (name);
-      s->set_domain (VAR_DOMAIN);
+      s->set_domain (TYPE_DOMAIN);
       s->set_aclass_index (LOC_TYPEDEF);
       s->set_value_block (top_stack->cur_block);
       s->set_type (t);
index af1b76f738a1d6ca1be628e22ca026a3a58b7735..66263b91bdc9cb7bcab2aa81230c63c63c34e561 100644 (file)
@@ -454,7 +454,7 @@ rust_parser::rust_lookup_type (const char *name)
   const struct block *block = pstate->expression_context_block;
   munge_name_and_block (&name, &block);
 
-  result = ::lookup_symbol (name, block, SEARCH_STRUCT_DOMAIN, NULL);
+  result = ::lookup_symbol (name, block, SEARCH_TYPE_DOMAIN, nullptr);
   if (result.symbol != NULL)
     {
       update_innermost_block (result);
index 071290fbe1287cbaebc483a8dd54aa6743f9fd2e..025cb2120d1956c8eed6b9c034240624ec24cd21 100644 (file)
@@ -940,7 +940,7 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
       /* A static function definition.  */
       sym->set_type (read_type (&p, objfile));
       sym->set_aclass_index (LOC_BLOCK);
-      sym->set_domain (VAR_DOMAIN);
+      sym->set_domain (FUNCTION_DOMAIN);
       add_symbol_to_list (sym, get_file_symbols ());
       /* fall into process_function_types.  */
 
@@ -1011,7 +1011,7 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
       /* A global function definition.  */
       sym->set_type (read_type (&p, objfile));
       sym->set_aclass_index (LOC_BLOCK);
-      sym->set_domain (VAR_DOMAIN);
+      sym->set_domain (FUNCTION_DOMAIN);
       add_symbol_to_list (sym, get_global_symbols ());
       goto process_function_types;
 
@@ -1209,7 +1209,7 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
 
       sym->set_aclass_index (LOC_TYPEDEF);
       sym->set_value_longest (valu);
-      sym->set_domain (VAR_DOMAIN);
+      sym->set_domain (TYPE_DOMAIN);
       /* C++ vagaries: we may have a type which is derived from
         a base type which did not have its name defined when the
         derived class was output.  We fill in the derived class's
@@ -1328,7 +1328,7 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
          *typedef_sym = *sym;
          typedef_sym->set_aclass_index (LOC_TYPEDEF);
          typedef_sym->set_value_longest (valu);
-         typedef_sym->set_domain (VAR_DOMAIN);
+         typedef_sym->set_domain (TYPE_DOMAIN);
          if (sym->type ()->name () == 0)
            sym->type ()->set_name
              (obconcat (&objfile->objfile_obstack, sym->linkage_name (),
index cea25a5f5b3fc42d048a05d021ddda10ac6172e3..7545631063b27517a41e8b79ed8a17f702922a98 100644 (file)
@@ -47,7 +47,9 @@ DOMAIN (LABEL)
 DOMAIN (COMMON_BLOCK)
 
 /* TYPE_DOMAIN is for types and typedefs.  Note that tags are not
-   found here, see STRUCT_DOMAIN above.  */
+   found here, see STRUCT_DOMAIN above.  If a language does not have a
+   tag namespace, then all types (including structures, etc) are
+   here.  */
 
 DOMAIN (TYPE)
 
index b85883559212438028a26ec0e3bd80b1e7b3982d..30b12d6f4ebb705f5f0118d240b940d7a2362315 100644 (file)
@@ -2681,32 +2681,10 @@ lookup_global_symbol (const char *name,
 bool
 symbol::matches (domain_search_flags flags) const
 {
-  if (language () != language_c
-      && language () != language_objc
-      && language () != language_opencl)
-    {
-      /* Only C languages distinguish tag and type namespaces.  */
-      if ((flags & SEARCH_TYPE_DOMAIN) != 0)
-       flags |= SEARCH_STRUCT_DOMAIN;
-    }
-
-  if ((flags & SEARCH_FUNCTION_DOMAIN) != 0
-      && domain () == VAR_DOMAIN
-      && aclass () == LOC_BLOCK)
-    return true;
-
-  if ((flags & SEARCH_VAR_DOMAIN) != 0
-      && domain () == VAR_DOMAIN)
-    return true;
-
-  if ((flags & SEARCH_TYPE_DOMAIN) != 0
-      && domain () == VAR_DOMAIN
-      && aclass () == LOC_TYPEDEF)
-    return true;
-
-  if ((flags & SEARCH_STRUCT_DOMAIN) != 0
-      && domain () == STRUCT_DOMAIN)
-    return true;
+  /* C++ has a typedef for every tag, and the types are in the struct
+     domain.  */
+  if (language () == language_cplus && (flags & SEARCH_TYPE_DOMAIN) != 0)
+    flags |= SEARCH_STRUCT_DOMAIN;
 
   return search_flags_matches (flags, m_domain);
 }
@@ -4908,59 +4886,42 @@ global_symbol_searcher::add_matching_symbols
                                         filenames, false))))
                continue;
 
+             if (!sym->matches (kind))
+               continue;
+
              if (preg.has_value () && !preg->exec (sym->natural_name (), 0,
                                                    nullptr, 0) == 0)
                continue;
 
-             bool matches = false;
-             if (!matches && (kind & SEARCH_VAR_DOMAIN) != 0)
+             if (((sym->domain () == VAR_DOMAIN
+                   || sym->domain () == FUNCTION_DOMAIN)
+                  && treg.has_value ()
+                  && !treg_matches_sym_type_name (*treg, sym)))
+               continue;
+
+             if ((kind & SEARCH_VAR_DOMAIN) != 0)
                {
-                 if (sym->aclass () != LOC_TYPEDEF
-                     && sym->aclass () != LOC_UNRESOLVED
-                     && sym->aclass () != LOC_BLOCK
+                 if (sym->aclass () == LOC_UNRESOLVED
                      /* LOC_CONST can be used for more than
                         just enums, e.g., c++ static const
                         members.  We only want to skip enums
                         here.  */
-                     && !(sym->aclass () == LOC_CONST
-                          && (sym->type ()->code ()
-                              == TYPE_CODE_ENUM))
-                     && (!treg.has_value ()
-                         || treg_matches_sym_type_name (*treg, sym)))
-                   matches = true;
-               }
-             if (!matches && (kind & SEARCH_FUNCTION_DOMAIN) != 0)
-               {
-                 if (sym->aclass () == LOC_BLOCK
-                     && (!treg.has_value ()
-                         || treg_matches_sym_type_name (*treg,
-                                                        sym)))
-                   matches = true;
-               }
-             if (!matches && (kind & SEARCH_TYPE_DOMAIN) != 0)
-               {
-                 if (sym->aclass () == LOC_TYPEDEF
-                     && sym->domain () != MODULE_DOMAIN)
-                   matches = true;
-               }
-             if (!matches && (kind & SEARCH_MODULE_DOMAIN) != 0)
-               {
-                 if (sym->domain () == MODULE_DOMAIN
-                     && sym->line () != 0)
-                   matches = true;
+                     || (sym->aclass () == LOC_CONST
+                         && (sym->type ()->code () == TYPE_CODE_ENUM)))
+                   continue;
                }
-             if (matches)
+             if (sym->domain () == MODULE_DOMAIN && sym->line () == 0)
+               continue;
+
+             if (result_set->size () < m_max_search_results)
                {
-                 if (result_set->size () < m_max_search_results)
-                   {
-                     /* Match, insert if not already in the results.  */
-                     symbol_search ss (block, sym);
-                     if (result_set->find (ss) == result_set->end ())
-                       result_set->insert (ss);
-                   }
-                 else
-                   return false;
+                 /* Match, insert if not already in the results.  */
+                 symbol_search ss (block, sym);
+                 if (result_set->find (ss) == result_set->end ())
+                   result_set->insert (ss);
                }
+             else
+               return false;
            }
        }
     }
@@ -5123,12 +5084,12 @@ symbol_to_info_string (struct symbol *sym, int block)
   gdb_assert (block == GLOBAL_BLOCK || block == STATIC_BLOCK);
 
   if (block == STATIC_BLOCK
-      && sym->domain () == VAR_DOMAIN
-      && sym->aclass () != LOC_TYPEDEF)
+      && (sym->domain () == VAR_DOMAIN
+         || sym->domain () == FUNCTION_DOMAIN))
     str += "static ";
 
   /* Typedef that is not a C++ class.  */
-  if (sym->domain () == VAR_DOMAIN && sym->aclass () == LOC_TYPEDEF)
+  if (sym->domain () == TYPE_DOMAIN)
     {
       string_file tmp_stream;
 
@@ -5147,7 +5108,8 @@ symbol_to_info_string (struct symbol *sym, int block)
       str += tmp_stream.string ();
     }
   /* variable, func, or typedef-that-is-c++-class.  */
-  else if (sym->domain () == VAR_DOMAIN || sym->domain () == STRUCT_DOMAIN)
+  else if (sym->domain () == VAR_DOMAIN || sym->domain () == STRUCT_DOMAIN
+          || sym->domain () == FUNCTION_DOMAIN)
     {
       string_file tmp_stream;
 
index dc92659670b920c8c98066841e43ebd0c0d95b0d..cb2a5a7a172b1dc52e00873e64331e9c42690b7d 100644 (file)
@@ -65,8 +65,8 @@ set type_in_c(ada_syntax) [multi_line \
                              "${decimal}:      record" \
                              "    some_component_in_c: int;" \
                              "end record" ]
-set type_in_ada(c_syntax) "${decimal}: struct global_pack__some_type_in_ada;"
-set type_in_ada(ada_syntax)  "${decimal}:      global_pack.some_type_in_ada;"
+set type_in_ada(c_syntax) "${decimal}: struct global_pack__some_type_in_ada"
+set type_in_ada(ada_syntax)  "${decimal}:      global_pack.some_type_in_ada"
 
 set var_in_c(c_syntax)     "${decimal}:        some_type_in_c some_struct_in_c;"
 set var_in_c(ada_syntax)   "${decimal}:        some_struct_in_c: some_type_in_c;"
index 1a2817da6bcd5d9576b21f7b2f503f7145ac2c51..f7782199d5818ac47152117830c13ee84816d76a 100644 (file)
@@ -43,5 +43,5 @@ foreach_with_prefix scenario {all minimal} {
        # crash.
        set exp ".*"
     }
-    gdb_test "ptype/o struct prog__rec" $exp
+    gdb_test "ptype/o prog__rec" $exp
 }
index ab1d89477294cbb9221d06aa0a8e91c0ed8f876a..52ce7ace89d9e20ceb50a4ba3c90e8e7eb8a81ed 100644 (file)
@@ -44,7 +44,7 @@ GDBInfoSymbols::check_header "All defined types:"
 GDBInfoSymbols::check_optional_entry "${srcfile}" "" "${character1}"
 GDBInfoSymbols::check_entry "${srcfile}" "" "${integer4}"
 GDBInfoSymbols::check_entry "${srcfile}" "" "${logical4}"
-GDBInfoSymbols::check_entry "${srcfile}" "$decimal" "Type m1t1;"
+GDBInfoSymbols::check_entry "${srcfile}" "$decimal" "Type m1t1"
 GDBInfoSymbols::check_entry "${srcfile}" "" "${real4}"
 
 # The emission of the 'Type s1' at global scope is actually not expected.  The
index d161ad34c2fc61ef88cf8b145e9684d5049be3a5..589208cda68542e68573bb764037c8f5df5a9910 100644 (file)
@@ -1491,6 +1491,7 @@ process_xcoff_symbol (struct xcoff_symbol *cs, struct objfile *objfile)
       sym->set_linkage_name (SYMNAME_ALLOC (name, symname_alloced));
       sym->set_type (builtin_type (objfile)->nodebug_text_symbol);
 
+      sym->set_domain (FUNCTION_DOMAIN);
       sym->set_aclass_index (LOC_BLOCK);
       sym2 = new (&objfile->objfile_obstack) symbol (*sym);
 
@@ -2546,7 +2547,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
                        /* Also a typedef with the same name.  */
                        pst->add_psymbol (std::string_view (namestring,
                                                            p - namestring),
-                                         true, VAR_DOMAIN, LOC_TYPEDEF, -1,
+                                         true, TYPE_DOMAIN, LOC_TYPEDEF, -1,
                                          psymbol_placement::STATIC,
                                          unrelocated_addr (0),
                                          psymtab_language,
@@ -2561,7 +2562,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
                  {
                    pst->add_psymbol (std::string_view (namestring,
                                                        p - namestring),
-                                     true, VAR_DOMAIN, LOC_TYPEDEF, -1,
+                                     true, TYPE_DOMAIN, LOC_TYPEDEF, -1,
                                      psymbol_placement::STATIC,
                                      unrelocated_addr (0),
                                      psymtab_language,
@@ -2661,7 +2662,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
                  }
                pst->add_psymbol (std::string_view (namestring,
                                                    p - namestring),
-                                 true, VAR_DOMAIN, LOC_BLOCK,
+                                 true, FUNCTION_DOMAIN, LOC_BLOCK,
                                  SECT_OFF_TEXT (objfile),
                                  psymbol_placement::STATIC,
                                  unrelocated_addr (symbol.n_value),
@@ -2688,7 +2689,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 
                pst->add_psymbol (std::string_view (namestring,
                                                    p - namestring),
-                                 true, VAR_DOMAIN, LOC_BLOCK,
+                                 true, FUNCTION_DOMAIN, LOC_BLOCK,
                                  SECT_OFF_TEXT (objfile),
                                  psymbol_placement::GLOBAL,
                                  unrelocated_addr (symbol.n_value),