]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Per-language symbol name hashing algorithm
authorPedro Alves <palves@redhat.com>
Wed, 8 Nov 2017 15:07:56 +0000 (15:07 +0000)
committerPedro Alves <palves@redhat.com>
Wed, 8 Nov 2017 16:02:24 +0000 (16:02 +0000)
Currently, we have a mess of symbol name hashing/comparison routines.
There's msymbol_hash for mangled names, and dict_hash and
msymbol_hash_iw for demangled names.  Then there's strcmp_iw,
strcmp_iw_ordered and Ada's full_match/wild_match, which all have to
agree with the hashing routines.  That's why dict_hash is really about
Ada names.  From the inconsistency department, minimal symbol hashing
doesn't go via dict_hash, so Ada's wild matching can't ever work with
minimal symbols.

This patch starts fixing this, by doing two things:

#1 - adds a language vector method to let each language decide how to
     compute a symbol name hash.

#2 - makes dictionaries know the language of the symbols they hold,
     and then use the dictionaries language to decide which hashing
     method to use.

For now, this is just scaffolding, since all languages install the
default method.  The series will make C++ install its own hashing
method later on, and will add per-language symbol name comparison
routines too.

This patch was originally based on a patch that Keith wrote for the
libcc1/C++ WIP support.

gdb/ChangeLog:
2017-11-08  Keith Seitz  <keiths@redhat.com>
    Pedro Alves  <palves@redhat.com>

* ada-lang.c (ada_language_defn): Install
default_search_name_hash.
* buildsym.c (struct buildsym_compunit): <language>: New field.
(finish_block_internal): Pass language when creating dictionaries.
(start_buildsym_compunit, start_symtab): New language parameters.
Use them.
(restart_symtab): Pass down compilation unit's language.
* buildsym.h (enum language): Forward declare.
(start_symtab): New 'language' parameter.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Install
default_search_name_hash.
* coffread.c (coff_start_symtab): Adjust.
* d-lang.c (d_language_defn): Install default_search_name_hash.
* dbxread.c (struct symloc): Add 'pst_language' field.
(PST_LANGUAGE): Define.
(start_psymtab, read_ofile_symtab): Use it.
(process_one_symbol): New 'language' parameter.  Pass it down.
* dictionary.c (struct dictionary) <language>: New field.
(DICT_LANGUAGE): Define.
(dict_create_hashed, dict_create_hashed_expandable)
(dict_create_linear, dict_create_linear_expandable): New parameter
'language'.  Set the dictionary's language.
(iter_match_first_hashed): Adjust to rename.
(insert_symbol_hashed): Assert we don't see mismatching
languages.  Adjust to rename.
(dict_hash): Rename to ...
(default_search_name_hash): ... this and make extern.
* dictionary.h (struct language_defn): Forward declare.
(dict_create_hashed): New parameter 'language'.
* dwarf2read.c (dwarf2_start_symtab): Pass down language.
* f-lang.c (f_language_defn): Install default_search_name_hash.
* go-lang.c (go_language_defn): Install default_search_name_hash.
* jit.c (finalize_symtab): Pass compunit's language to dictionary
creation.
* language.c (unknown_language_defn, auto_language_defn):
* language.h (language_defn::la_search_name_hash): New field.
(default_search_name_hash): Declare.
* m2-lang.c (m2_language_defn): Install default_search_name_hash.
* mdebugread.c (new_block): New parameter 'language'.
* mdebugread.c (parse_symbol): Pass symbol language to block
allocation.
(psymtab_to_symtab_1): Pass down language.
(new_symtab): Pass compunit's language to block allocation.
* objc-lang.c (objc_language_defn): Install
default_search_name_hash.
* opencl-lang.c (opencl_language_defn):
* p-lang.c (pascal_language_defn): Install
default_search_name_hash.
* rust-lang.c (rust_language_defn): Install
default_search_name_hash.
* stabsread.h (enum language): Forward declare.
(process_one_symbol): Add 'language' parameter.
* symtab.c (search_name_hash): New function.
* symtab.h (search_name_hash): Declare.
* xcoffread.c (read_xcoff_symtab): Pass language to start_symtab.

26 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/buildsym.c
gdb/buildsym.h
gdb/c-lang.c
gdb/coffread.c
gdb/d-lang.c
gdb/dbxread.c
gdb/dictionary.c
gdb/dictionary.h
gdb/dwarf2read.c
gdb/f-lang.c
gdb/go-lang.c
gdb/jit.c
gdb/language.c
gdb/language.h
gdb/m2-lang.c
gdb/mdebugread.c
gdb/objc-lang.c
gdb/opencl-lang.c
gdb/p-lang.c
gdb/rust-lang.c
gdb/stabsread.h
gdb/symtab.c
gdb/symtab.h
gdb/xcoffread.c

index 80dbb669b7e894a0070899d2a43301d9112738e4..f793c21dcb34f3e2fd1e65bb8ea59dba84f09a93 100644 (file)
@@ -1,3 +1,63 @@
+2017-11-08  Keith Seitz  <keiths@redhat.com>
+           Pedro Alves  <palves@redhat.com>
+
+       * ada-lang.c (ada_language_defn): Install
+       default_search_name_hash.
+       * buildsym.c (struct buildsym_compunit): <language>: New field.
+       (finish_block_internal): Pass language when creating dictionaries.
+       (start_buildsym_compunit, start_symtab): New language parameters.
+       Use them.
+       (restart_symtab): Pass down compilation unit's language.
+       * buildsym.h (enum language): Forward declare.
+       (start_symtab): New 'language' parameter.
+       * c-lang.c (c_language_defn, cplus_language_defn)
+       (asm_language_defn, minimal_language_defn): Install
+       default_search_name_hash.
+       * coffread.c (coff_start_symtab): Adjust.
+       * d-lang.c (d_language_defn): Install default_search_name_hash.
+       * dbxread.c (struct symloc): Add 'pst_language' field.
+       (PST_LANGUAGE): Define.
+       (start_psymtab, read_ofile_symtab): Use it.
+       (process_one_symbol): New 'language' parameter.  Pass it down.
+       * dictionary.c (struct dictionary) <language>: New field.
+       (DICT_LANGUAGE): Define.
+       (dict_create_hashed, dict_create_hashed_expandable)
+       (dict_create_linear, dict_create_linear_expandable): New parameter
+       'language'.  Set the dictionary's language.
+       (iter_match_first_hashed): Adjust to rename.
+       (insert_symbol_hashed): Assert we don't see mismatching
+       languages.  Adjust to rename.
+       (dict_hash): Rename to ...
+       (default_search_name_hash): ... this and make extern.
+       * dictionary.h (struct language_defn): Forward declare.
+       (dict_create_hashed): New parameter 'language'.
+       * dwarf2read.c (dwarf2_start_symtab): Pass down language.
+       * f-lang.c (f_language_defn): Install default_search_name_hash.
+       * go-lang.c (go_language_defn): Install default_search_name_hash.
+       * jit.c (finalize_symtab): Pass compunit's language to dictionary
+       creation.
+       * language.c (unknown_language_defn, auto_language_defn):
+       * language.h (language_defn::la_search_name_hash): New field.
+       (default_search_name_hash): Declare.
+       * m2-lang.c (m2_language_defn): Install default_search_name_hash.
+       * mdebugread.c (new_block): New parameter 'language'.
+       * mdebugread.c (parse_symbol): Pass symbol language to block
+       allocation.
+       (psymtab_to_symtab_1): Pass down language.
+       (new_symtab): Pass compunit's language to block allocation.
+       * objc-lang.c (objc_language_defn): Install
+       default_search_name_hash.
+       * opencl-lang.c (opencl_language_defn):
+       * p-lang.c (pascal_language_defn): Install
+       default_search_name_hash.
+       * rust-lang.c (rust_language_defn): Install
+       default_search_name_hash.
+       * stabsread.h (enum language): Forward declare.
+       (process_one_symbol): Add 'language' parameter.
+       * symtab.c (search_name_hash): New function.
+       * symtab.h (search_name_hash): Declare.
+       * xcoffread.c (read_xcoff_symtab): Pass language to start_symtab.
+
 2017-11-08  Pedro Alves  <palves@redhat.com>
 
        * cp-name-parser.y (main): Don't initialize extra_chars.
index bc3b6359198f688fa8609d97244050b59fa51da1..7126b25b0e5e60358178a26b44237128718429bf 100644 (file)
@@ -13941,6 +13941,7 @@ extern const struct language_defn ada_language_defn = {
   c_watch_location_expression,
   ada_get_symbol_name_cmp,     /* la_get_symbol_name_cmp */
   ada_iterate_over_symbols,
+  default_search_name_hash,
   &ada_varobj_ops,
   NULL,
   NULL,
index d07bfb3d1375ea029c45fe04225f1b11f6609cc2..e3f281a4c556c821b9a6a80b310da3ac835b9a39 100644 (file)
@@ -125,6 +125,9 @@ struct buildsym_compunit
 
   /* The compunit we are building.  */
   struct compunit_symtab *compunit_symtab;
+
+  /* Language of this compunit_symtab.  */
+  enum language language;
 };
 
 /* The work-in-progress of the compunit we are building.
@@ -346,20 +349,23 @@ finish_block_internal (struct symbol *symbol,
 
   if (symbol)
     {
-      BLOCK_DICT (block) = dict_create_linear (&objfile->objfile_obstack,
-                                              *listhead);
+      BLOCK_DICT (block)
+       = dict_create_linear (&objfile->objfile_obstack,
+                             buildsym_compunit->language, *listhead);
     }
   else
     {
       if (expandable)
        {
-         BLOCK_DICT (block) = dict_create_hashed_expandable ();
+         BLOCK_DICT (block)
+           = dict_create_hashed_expandable (buildsym_compunit->language);
          dict_add_pending (BLOCK_DICT (block), *listhead);
        }
       else
        {
          BLOCK_DICT (block) =
-           dict_create_hashed (&objfile->objfile_obstack, *listhead);
+           dict_create_hashed (&objfile->objfile_obstack,
+                               buildsym_compunit->language, *listhead);
        }
     }
 
@@ -763,7 +769,8 @@ start_subfile (const char *name)
    (or NULL if not known).  */
 
 static struct buildsym_compunit *
-start_buildsym_compunit (struct objfile *objfile, const char *comp_dir)
+start_buildsym_compunit (struct objfile *objfile, const char *comp_dir,
+                        enum language language)
 {
   struct buildsym_compunit *bscu;
 
@@ -772,6 +779,7 @@ start_buildsym_compunit (struct objfile *objfile, const char *comp_dir)
 
   bscu->objfile = objfile;
   bscu->comp_dir = (comp_dir == NULL) ? NULL : xstrdup (comp_dir);
+  bscu->language = language;
 
   /* Initialize the debug format string to NULL.  We may supply it
      later via a call to record_debugformat.  */
@@ -1036,17 +1044,20 @@ prepare_for_building (const char *name, CORE_ADDR start_addr)
    TAG_compile_unit DIE is seen.  It indicates the start of data for
    one original source file.
 
-   NAME is the name of the file (cannot be NULL).  COMP_DIR is the directory in
-   which the file was compiled (or NULL if not known).  START_ADDR is the
-   lowest address of objects in the file (or 0 if not known).  */
+   NAME is the name of the file (cannot be NULL).  COMP_DIR is the
+   directory in which the file was compiled (or NULL if not known).
+   START_ADDR is the lowest address of objects in the file (or 0 if
+   not known).  LANGUAGE is the language of the source file, or
+   language_unknown if not known, in which case it'll be deduced from
+   the filename.  */
 
 struct compunit_symtab *
 start_symtab (struct objfile *objfile, const char *name, const char *comp_dir,
-             CORE_ADDR start_addr)
+             CORE_ADDR start_addr, enum language language)
 {
   prepare_for_building (name, start_addr);
 
-  buildsym_compunit = start_buildsym_compunit (objfile, comp_dir);
+  buildsym_compunit = start_buildsym_compunit (objfile, comp_dir, language);
 
   /* Allocate the compunit symtab now.  The caller needs it to allocate
      non-primary symtabs.  It is also needed by get_macro_table.  */
@@ -1083,7 +1094,8 @@ restart_symtab (struct compunit_symtab *cust,
   prepare_for_building (name, start_addr);
 
   buildsym_compunit = start_buildsym_compunit (COMPUNIT_OBJFILE (cust),
-                                              COMPUNIT_DIRNAME (cust));
+                                              COMPUNIT_DIRNAME (cust),
+                                              compunit_language (cust));
   buildsym_compunit->compunit_symtab = cust;
 }
 
index accb1f03471730b794a4eba99a9116d893f4c1b2..811702ed8cb220c2b8a4180ee8a3cf2bc44eda02 100644 (file)
@@ -23,6 +23,7 @@ struct objfile;
 struct symbol;
 struct addrmap;
 struct compunit_symtab;
+enum language;
 
 /* This module provides definitions used for creating and adding to
    the symbol table.  These routines are called from various symbol-
@@ -262,7 +263,8 @@ extern record_line_ftype record_line;
 extern struct compunit_symtab *start_symtab (struct objfile *objfile,
                                             const char *name,
                                             const char *comp_dir,
-                                            CORE_ADDR start_addr);
+                                            CORE_ADDR start_addr,
+                                            enum language language);
 
 extern void restart_symtab (struct compunit_symtab *cust,
                            const char *name, CORE_ADDR start_addr);
index f86e26ed5f7eae1b43bf81ba3de84c3e231cf5e1..9749935dac5be2caf9b14538a9eb8d383621048d 100644 (file)
@@ -871,6 +871,7 @@ extern const struct language_defn c_language_defn =
   c_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &c_varobj_ops,
   c_get_compile_context,
   c_compute_program,
@@ -1015,6 +1016,7 @@ extern const struct language_defn cplus_language_defn =
   c_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &cplus_varobj_ops,
   NULL,
   NULL,
@@ -1068,6 +1070,7 @@ extern const struct language_defn asm_language_defn =
   c_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   NULL,
@@ -1121,6 +1124,7 @@ extern const struct language_defn minimal_language_defn =
   c_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   NULL,
index 4b5edf0919ed605f5ec3d823ed18bb66a83c4030..62b6d7945a861510897f851e33aa5b9324fc23c0 100644 (file)
@@ -392,7 +392,9 @@ coff_start_symtab (struct objfile *objfile, const char *name)
                 NULL,
   /* The start address is irrelevant, since we set
      last_source_start_addr in coff_end_symtab.  */
-                0);
+                0,
+  /* Let buildsym.c deduce the language for this symtab.  */
+                language_unknown);
   record_debugformat ("COFF");
 }
 
index e3220d41f6e51b192d6347694a281b0af9b155ff..2fa429b4bac1e2efa9c927e17f8b1ce5a8b3141d 100644 (file)
@@ -247,6 +247,7 @@ extern const struct language_defn d_language_defn =
   c_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   NULL,
index 1618a561369407d75e0d948bf8cf15bc97c36bd3..697aa6e8ed501cc3eb0dcd45a4311aecc8e81f05 100644 (file)
@@ -54,7 +54,6 @@
 #include "cp-support.h"
 #include "psympriv.h"
 #include "block.h"
-
 #include "aout/aout64.h"
 #include "aout/stab_gnu.h"     /* We always use GNU stabs, not
                                   native, now.  */
@@ -92,6 +91,7 @@ struct symloc
     int symbol_offset;
     int string_offset;
     int file_string_offset;
+    enum language pst_language;
   };
 
 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
@@ -101,6 +101,7 @@ struct symloc
 #define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset)
 #define STRING_OFFSET(p) (SYMLOC(p)->string_offset)
 #define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset)
+#define PST_LANGUAGE(p) (SYMLOC(p)->pst_language)
 \f
 
 /* The objfile we are currently reading.  */
@@ -2013,6 +2014,7 @@ start_psymtab (struct objfile *objfile, const char *filename, CORE_ADDR textlow,
 
   /* Deduce the source language from the filename for this psymtab.  */
   psymtab_language = deduce_language_from_filename (filename);
+  PST_LANGUAGE (result) = psymtab_language;
 
   return result;
 }
@@ -2396,7 +2398,8 @@ read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst)
                 positive offsets.  */
            nlist.n_value = (nlist.n_value ^ 0x80000000) - 0x80000000;
          process_one_symbol (type, nlist.n_desc, nlist.n_value,
-                             namestring, section_offsets, objfile);
+                             namestring, section_offsets, objfile,
+                             PST_LANGUAGE (pst));
        }
       /* We skip checking for a new .o or -l file; that should never
          happen in this routine.  */
@@ -2491,12 +2494,14 @@ cp_set_block_scope (const struct symbol *symbol,
    the pst->section_offsets.  All symbols that refer to memory
    locations need to be offset by these amounts.
    OBJFILE is the object file from which we are reading symbols.  It
-   is used in end_symtab.  */
+   is used in end_symtab.
+   LANGUAGE is the language of the symtab.
+*/
 
 void
 process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name,
                    const struct section_offsets *section_offsets,
-                   struct objfile *objfile)
+                   struct objfile *objfile, enum language language)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct context_stack *newobj;
@@ -2710,7 +2715,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name,
       function_start_offset = 0;
 
       start_stabs ();
-      start_symtab (objfile, name, NULL, valu);
+      start_symtab (objfile, name, NULL, valu, language);
       record_debugformat ("stabs");
       break;
 
index b2cfca28ab0fff076f659c472e45473e3ad6b6f0..1ffa4f321802a11eeff0415bba3ebf3cc23efef9 100644 (file)
@@ -165,6 +165,7 @@ struct dictionary_linear_expandable
 
 struct dictionary
 {
+  const struct language_defn *language;
   const struct dict_vector *vector;
   union
   {
@@ -179,6 +180,7 @@ struct dictionary
 /* Accessor macros.  */
 
 #define DICT_VECTOR(d)                 (d)->vector
+#define DICT_LANGUAGE(d)                (d)->language
 
 /* These can be used for DICT_HASHED_EXPANDABLE, too.  */
 
@@ -245,8 +247,6 @@ static struct symbol *iter_match_next_hashed (const char *name,
                                              symbol_compare_ftype *compare,
                                              struct dict_iterator *iterator);
 
-static unsigned int dict_hash (const char *string);
-
 /* Functions only for DICT_HASHED.  */
 
 static int size_hashed (const struct dictionary *dict);
@@ -348,12 +348,11 @@ static void expand_hashtable (struct dictionary *dict);
 
 /* The creation functions.  */
 
-/* Create a dictionary implemented via a fixed-size hashtable.  All
-   memory it uses is allocated on OBSTACK; the environment is
-   initialized from SYMBOL_LIST.  */
+/* See dictionary.h.  */
 
 struct dictionary *
 dict_create_hashed (struct obstack *obstack,
+                   enum language language,
                    const struct pending *symbol_list)
 {
   struct dictionary *retval;
@@ -363,6 +362,7 @@ dict_create_hashed (struct obstack *obstack,
 
   retval = XOBNEW (obstack, struct dictionary);
   DICT_VECTOR (retval) = &dict_hashed_vector;
+  DICT_LANGUAGE (retval) = language_def (language);
 
   /* Calculate the number of symbols, and allocate space for them.  */
   for (list_counter = symbol_list;
@@ -391,17 +391,15 @@ dict_create_hashed (struct obstack *obstack,
   return retval;
 }
 
-/* Create a dictionary implemented via a hashtable that grows as
-   necessary.  The dictionary is initially empty; to add symbols to
-   it, call dict_add_symbol().  Call dict_free() when you're done with
-   it.  */
+/* See dictionary.h.  */
 
 extern struct dictionary *
-dict_create_hashed_expandable (void)
+dict_create_hashed_expandable (enum language language)
 {
   struct dictionary *retval = XNEW (struct dictionary);
 
   DICT_VECTOR (retval) = &dict_hashed_expandable_vector;
+  DICT_LANGUAGE (retval) = language_def (language);
   DICT_HASHED_NBUCKETS (retval) = DICT_EXPANDABLE_INITIAL_CAPACITY;
   DICT_HASHED_BUCKETS (retval) = XCNEWVEC (struct symbol *,
                                           DICT_EXPANDABLE_INITIAL_CAPACITY);
@@ -410,13 +408,11 @@ dict_create_hashed_expandable (void)
   return retval;
 }
 
-/* Create a dictionary implemented via a fixed-size array.  All memory
-   it uses is allocated on OBSTACK; the environment is initialized
-   from the SYMBOL_LIST.  The symbols are ordered in the same order
-   that they're found in SYMBOL_LIST.  */
+/* See dictionary.h.  */
 
 struct dictionary *
 dict_create_linear (struct obstack *obstack,
+                   enum language language,
                    const struct pending *symbol_list)
 {
   struct dictionary *retval;
@@ -426,6 +422,7 @@ dict_create_linear (struct obstack *obstack,
 
   retval = XOBNEW (obstack, struct dictionary);
   DICT_VECTOR (retval) = &dict_linear_vector;
+  DICT_LANGUAGE (retval) = language_def (language);
 
   /* Calculate the number of symbols, and allocate space for them.  */
   for (list_counter = symbol_list;
@@ -455,17 +452,15 @@ dict_create_linear (struct obstack *obstack,
   return retval;
 }
 
-/* Create a dictionary implemented via an array that grows as
-   necessary.  The dictionary is initially empty; to add symbols to
-   it, call dict_add_symbol().  Call dict_free() when you're done with
-   it.  */
+/* See dictionary.h.  */
 
 struct dictionary *
-dict_create_linear_expandable (void)
+dict_create_linear_expandable (enum language language)
 {
   struct dictionary *retval = XNEW (struct dictionary);
 
   DICT_VECTOR (retval) = &dict_linear_expandable_vector;
+  DICT_LANGUAGE (retval) = language_def (language);
   DICT_LINEAR_NSYMS (retval) = 0;
   DICT_LINEAR_EXPANDABLE_CAPACITY (retval) = DICT_EXPANDABLE_INITIAL_CAPACITY;
   DICT_LINEAR_SYMS (retval)
@@ -638,7 +633,9 @@ iter_match_first_hashed (const struct dictionary *dict, const char *name,
                         symbol_compare_ftype *compare,
                         struct dict_iterator *iterator)
 {
-  unsigned int hash_index = dict_hash (name) % DICT_HASHED_NBUCKETS (dict);
+  unsigned int hash_index
+    = (search_name_hash (DICT_LANGUAGE (dict)->la_language, name)
+       % DICT_HASHED_NBUCKETS (dict));
   struct symbol *sym;
 
   DICT_ITERATOR_DICT (iterator) = dict;
@@ -689,10 +686,15 @@ insert_symbol_hashed (struct dictionary *dict,
                      struct symbol *sym)
 {
   unsigned int hash_index;
+  unsigned int hash;
   struct symbol **buckets = DICT_HASHED_BUCKETS (dict);
 
-  hash_index = 
-    dict_hash (SYMBOL_SEARCH_NAME (sym)) % DICT_HASHED_NBUCKETS (dict);
+  /* We don't want to insert a symbol into a dictionary of a different
+     language.  The two may not use the same hashing algorithm.  */
+  gdb_assert (SYMBOL_LANGUAGE (sym) == DICT_LANGUAGE (dict)->la_language);
+
+  hash = search_name_hash (SYMBOL_LANGUAGE (sym), SYMBOL_SEARCH_NAME (sym));
+  hash_index = hash % DICT_HASHED_NBUCKETS (dict);
   sym->hash_next = buckets[hash_index];
   buckets[hash_index] = sym;
 }
@@ -765,13 +767,10 @@ expand_hashtable (struct dictionary *dict)
   xfree (old_buckets);
 }
 
-/* Produce an unsigned hash value from STRING0 that is consistent
-   with strcmp_iw, strcmp, and, at least on Ada symbols, wild_match.
-   That is, two identifiers equivalent according to any of those three
-   comparison operators hash to the same value.  */
+/* See dictionary.h.  */
 
-static unsigned int
-dict_hash (const char *string0)
+unsigned int
+default_search_name_hash (const char *string0)
 {
   /* The Ada-encoded version of a name P1.P2...Pn has either the form
      P1__P2__...Pn<suffix> or _ada_P1__P2__...Pn<suffix> (where the Pi
index 4f4f160b9314b181514e0861a50e2cdeceb3bbd3..e4a9315be8c50e11dbed119ef46b5dcd72b4cfcb 100644 (file)
@@ -35,42 +35,46 @@ struct dictionary;
 struct symbol;
 struct obstack;
 struct pending;
-
+struct language_defn;
 
 /* The creation functions for various implementations of
    dictionaries.  */
 
-/* Create a dictionary implemented via a fixed-size hashtable.  All
-   memory it uses is allocated on OBSTACK; the environment is
-   initialized from SYMBOL_LIST.  */
+/* Create a dictionary of symbols of language LANGUAGE implemented via
+   a fixed-size hashtable.  All memory it uses is allocated on
+   OBSTACK; the environment is initialized from SYMBOL_LIST.  */
 
 extern struct dictionary *dict_create_hashed (struct obstack *obstack,
+                                             enum language language,
                                              const struct pending
                                              *symbol_list);
 
-/* Create a dictionary implemented via a hashtable that grows as
-   necessary.  The dictionary is initially empty; to add symbols to
-   it, call dict_add_symbol().  Call dict_free() when you're done with
-   it.  */
+/* Create a dictionary of symbols of language LANGUAGE, implemented
+   via a hashtable that grows as necessary.  The dictionary is
+   initially empty; to add symbols to it, call dict_add_symbol().
+   Call dict_free() when you're done with it.  */
 
-extern struct dictionary *dict_create_hashed_expandable (void);
+extern struct dictionary *
+  dict_create_hashed_expandable (enum language language);
 
-/* Create a dictionary implemented via a fixed-size array.  All memory
-   it uses is allocated on OBSTACK; the environment is initialized
-   from the SYMBOL_LIST.  The symbols are ordered in the same order
-   that they're found in SYMBOL_LIST.  */
+/* Create a dictionary of symbols of language LANGUAGE, implemented
+   via a fixed-size array.  All memory it uses is allocated on
+   OBSTACK; the environment is initialized from the SYMBOL_LIST.  The
+   symbols are ordered in the same order that they're found in
+   SYMBOL_LIST.  */
 
 extern struct dictionary *dict_create_linear (struct obstack *obstack,
+                                             enum language language,
                                              const struct pending
                                              *symbol_list);
 
-/* Create a dictionary implemented via an array that grows as
-   necessary.  The dictionary is initially empty; to add symbols to
-   it, call dict_add_symbol().  Call dict_free() when you're done with
-   it.  */
-
-extern struct dictionary *dict_create_linear_expandable (void);
+/* Create a dictionary of symbols of language LANGUAGE, implemented
+   via an array that grows as necessary.  The dictionary is initially
+   empty; to add symbols to it, call dict_add_symbol().  Call
+   dict_free() when you're done with it.  */
 
+extern struct dictionary *
+  dict_create_linear_expandable (enum language language);
 
 /* The functions providing the interface to dictionaries.  Note that
    the most common parts of the interface, namely symbol lookup, are
index 433a9272b8ed429dae838c33688515ecdb290e91..544d1e44861d27ebc02fabf80183605741937961 100644 (file)
@@ -18926,7 +18926,7 @@ dwarf2_start_symtab (struct dwarf2_cu *cu,
                     const char *name, const char *comp_dir, CORE_ADDR low_pc)
 {
   struct compunit_symtab *cust
-    = start_symtab (cu->objfile, name, comp_dir, low_pc);
+    = start_symtab (cu->objfile, name, comp_dir, low_pc, cu->language);
 
   record_debugformat ("DWARF 2");
   record_producer (cu->producer);
index 073d5291f7498b55301ba47718b3dc6d05dcdd67..0d78e5a57929e8f73b25628985d414b05f59bad4 100644 (file)
@@ -291,6 +291,7 @@ extern const struct language_defn f_language_defn =
   c_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   NULL,
index f66535ee61ea69938733383ca4568cba608cde69..87ad0631bf2e30abb3600ab9fdd1bd959f98b03c 100644 (file)
@@ -608,6 +608,7 @@ extern const struct language_defn go_language_defn =
   c_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   NULL,
index 28f63b083b25bb5741a5dd7b7da560ccae497513..98afdf2b6fd7b33e686d5cd4387686ca8ad33329 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -651,12 +651,14 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
   size_t blockvector_size;
   CORE_ADDR begin, end;
   struct blockvector *bv;
+  enum language language;
 
   actual_nblocks = FIRST_LOCAL_BLOCK + stab->nblocks;
 
   cust = allocate_compunit_symtab (objfile, stab->file_name);
   allocate_symtab (cust, stab->file_name);
   add_compunit_symtab_to_objfile (cust);
+  language = compunit_language (cust);
 
   /* JIT compilers compile in memory.  */
   COMPUNIT_DIRNAME (cust) = NULL;
@@ -701,7 +703,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
                                           "void");
 
       BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack,
-                                                   NULL);
+                                                  language, NULL);
       /* The address range.  */
       BLOCK_START (new_block) = (CORE_ADDR) gdb_block_iter->begin;
       BLOCK_END (new_block) = (CORE_ADDR) gdb_block_iter->end;
@@ -739,7 +741,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
                   ? allocate_global_block (&objfile->objfile_obstack)
                   : allocate_block (&objfile->objfile_obstack));
       BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack,
-                                                   NULL);
+                                                  language, NULL);
       BLOCK_SUPERBLOCK (new_block) = block_iter;
       block_iter = new_block;
 
index e67f9aea34e1aa4fa5469787afc94f6c3ac58472..a53119cc7951002625112636a638e4dae3be41f3 100644 (file)
@@ -839,6 +839,7 @@ const struct language_defn unknown_language_defn =
   c_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   NULL,
@@ -889,6 +890,7 @@ const struct language_defn auto_language_defn =
   c_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   NULL,
index d4ca900834dcb7a4519ada07ccc537fe8b68b42f..64ccfccdab64f2a61c8b0b930ad014e2e8f1661a 100644 (file)
@@ -392,6 +392,11 @@ struct language_defn
       (const struct block *block, const char *name, domain_enum domain,
        gdb::function_view<symbol_found_callback_ftype> callback);
 
+    /* Hash the given symbol search name.  Use
+       default_search_name_hash if no special treatment is
+       required.  */
+    unsigned int (*la_search_name_hash) (const char *name);
+
     /* Various operations on varobj.  */
     const struct lang_varobj_ops *la_varobj_ops;
 
@@ -611,6 +616,14 @@ void default_print_typedef (struct type *type, struct symbol *new_symbol,
 void default_get_string (struct value *value, gdb_byte **buffer, int *length,
                         struct type **char_type, const char **charset);
 
+/* Default name hashing function.  */
+
+/* Produce an unsigned hash value from SEARCH_NAME that is consistent
+   with strcmp_iw, strcmp, and, at least on Ada symbols, wild_match.
+   That is, two identifiers equivalent according to any of those three
+   comparison operators hash to the same value.  */
+extern unsigned int default_search_name_hash (const char *search_name);
+
 void c_get_string (struct value *value, gdb_byte **buffer, int *length,
                   struct type **char_type, const char **charset);
 
index ddd50af54cb622dad2d6a9477ace5bef20057147..4170ae92c26301518894fde23263f4773a75e89c 100644 (file)
@@ -395,6 +395,7 @@ extern const struct language_defn m2_language_defn =
   c_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   NULL,
index 3f53e1a68536cfed5d12df8234aeec36377de091..debf46dc61697425283b027c9f8e88f0fda94e10 100644 (file)
@@ -234,7 +234,7 @@ static struct type *new_type (char *);
 
 enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK };
 
-static struct block *new_block (enum block_type);
+static struct block *new_block (enum block_type, enum language);
 
 static struct compunit_symtab *new_symtab (const char *, int, struct objfile *);
 
@@ -809,7 +809,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
        TYPE_PROTOTYPED (SYMBOL_TYPE (s)) = 1;
 
       /* Create and enter a new lexical context.  */
-      b = new_block (FUNCTION_BLOCK);
+      b = new_block (FUNCTION_BLOCK, SYMBOL_LANGUAGE (s));
       SYMBOL_BLOCK_VALUE (s) = b;
       BLOCK_FUNCTION (b) = s;
       BLOCK_START (b) = BLOCK_END (b) = sh->value;
@@ -1142,7 +1142,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
        }
 
       top_stack->blocktype = stBlock;
-      b = new_block (NON_FUNCTION_BLOCK);
+      b = new_block (NON_FUNCTION_BLOCK, psymtab_language);
       BLOCK_START (b) = sh->value + top_stack->procadr;
       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
       top_stack->cur_block = b;
@@ -4023,6 +4023,7 @@ psymtab_to_symtab_1 (struct objfile *objfile,
          if (ECOFF_IS_STAB (&sh) || (name[0] == '#'))
            {
              int type_code = ECOFF_UNMARK_STAB (sh.index);
+             enum language language = PST_PRIVATE (pst)->pst_language;
 
              /* We should never get non N_STAB symbols here, but they
                 should be harmless, so keep process_one_symbol from
@@ -4050,14 +4051,14 @@ psymtab_to_symtab_1 (struct objfile *objfile,
                    {
                      last_symtab_ended = 0;
                      process_one_symbol (type_code, 0, valu, name,
-                                         section_offsets, objfile);
+                                         section_offsets, objfile, language);
                    }
                }
              /* Similarly a hack.  */
              else if (name[0] == '#')
                {
                  process_one_symbol (N_SLINE, 0, valu, name,
-                                     section_offsets, objfile);
+                                     section_offsets, objfile, language);
                }
              if (type_code == N_FUN)
                {
@@ -4718,16 +4719,18 @@ new_symtab (const char *name, int maxlines, struct objfile *objfile)
   struct compunit_symtab *cust = allocate_compunit_symtab (objfile, name);
   struct symtab *symtab;
   struct blockvector *bv;
+  enum language lang;
 
   add_compunit_symtab_to_objfile (cust);
   symtab = allocate_symtab (cust, name);
 
   SYMTAB_LINETABLE (symtab) = new_linetable (maxlines);
+  lang = compunit_language (cust);
 
   /* All symtabs must have at least two blocks.  */
   bv = new_bvect (2);
-  BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = new_block (NON_FUNCTION_BLOCK);
-  BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = new_block (NON_FUNCTION_BLOCK);
+  BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = new_block (NON_FUNCTION_BLOCK, lang);
+  BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = new_block (NON_FUNCTION_BLOCK, lang);
   BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
     BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
   COMPUNIT_BLOCKVECTOR (cust) = bv;
@@ -4809,13 +4812,13 @@ new_bvect (int nblocks)
   return bv;
 }
 
-/* Allocate and zero a new block, and set its BLOCK_DICT.  If function
-   is non-zero, assume the block is associated to a function, and make
-   sure that the symbols are stored linearly; otherwise, store them
-   hashed.  */
+/* Allocate and zero a new block of language LANGUAGE, and set its
+   BLOCK_DICT.  If function is non-zero, assume the block is
+   associated to a function, and make sure that the symbols are stored
+   linearly; otherwise, store them hashed.  */
 
 static struct block *
-new_block (enum block_type type)
+new_block (enum block_type type, enum language language)
 {
   /* FIXME: carlton/2003-09-11: This should use allocate_block to
      allocate the block.  Which, in turn, suggests that the block
@@ -4823,9 +4826,9 @@ new_block (enum block_type type)
   struct block *retval = XCNEW (struct block);
 
   if (type == FUNCTION_BLOCK)
-    BLOCK_DICT (retval) = dict_create_linear_expandable ();
+    BLOCK_DICT (retval) = dict_create_linear_expandable (language);
   else
-    BLOCK_DICT (retval) = dict_create_hashed_expandable ();
+    BLOCK_DICT (retval) = dict_create_hashed_expandable (language);
 
   return retval;
 }
index eb9da74e7c680375cc34f35b5f6a5f093084c7a2..df2923bd04d8daf108f44d4cf881ad2f29b9cf1b 100644 (file)
@@ -407,6 +407,7 @@ extern const struct language_defn objc_language_defn = {
   c_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   NULL,
index 6a7232733adfeadadc42d08c75ea195bc1ad9300..ffd4c926de100d6e078df5ec71a0552484147868 100644 (file)
@@ -1083,6 +1083,7 @@ extern const struct language_defn opencl_language_defn =
   c_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   NULL,
index 439a3772cbff6553c8a04831c3b0636e35ce056e..2dca923a377e7360573cf8056a5f17de593d08c4 100644 (file)
@@ -456,6 +456,7 @@ extern const struct language_defn pascal_language_defn =
   c_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   NULL,
index 261ddb1a10970cea89881638646d131eb1f22f13..466eb20ab1494d62cb87ea58930320c9db81a0ea 100644 (file)
@@ -2252,6 +2252,7 @@ extern const struct language_defn rust_language_defn =
   rust_watch_location_expression,
   NULL,                                /* la_get_symbol_name_cmp */
   iterate_over_symbols,
+  default_search_name_hash,
   &default_varobj_ops,
   NULL,
   NULL,
index b37be1a0421592e92b406e5236ca645a09676d5b..b803cf9ac7c79dbe10138bc07c11b010ec95434b 100644 (file)
@@ -17,6 +17,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 struct objfile;
+enum language;
 
 /* Definitions, prototypes, etc for stabs debugging format support
    functions.
@@ -169,7 +170,7 @@ extern struct partial_symtab *dbx_end_psymtab
 
 extern void process_one_symbol (int, int, CORE_ADDR, const char *,
                                const struct section_offsets *,
-                               struct objfile *);
+                               struct objfile *, enum language);
 
 extern void elfstab_build_psymtabs (struct objfile *objfile,
                                    asection *stabsect,
index 0c24f2be0680d60458ffdbcc355f9d766e286236..1e58770b8b816169f384ed5d8e135ddcd366d3e8 100644 (file)
@@ -1795,6 +1795,14 @@ demangle_for_lookup (const char *name, enum language lang,
   return name;
 }
 
+/* See symtab.h.  */
+
+unsigned int
+search_name_hash (enum language language, const char *search_name)
+{
+  return language_def (language)->la_search_name_hash (search_name);
+}
+
 /* See symtab.h.
 
    This function (or rather its subordinates) have a bunch of loops and
index cd6dbaea480599a06b099043923c4769f8e349aa..d5c929d1b502f54dcc06cd569d8339ea31745dcf 100644 (file)
@@ -277,6 +277,11 @@ extern const char *symbol_search_name (const struct general_symbol_info *);
 #define SYMBOL_MATCHES_SEARCH_NAME(symbol, name)                       \
   (strcmp_iw (SYMBOL_SEARCH_NAME (symbol), (name)) == 0)
 
+/* Compute the hash of the given symbol search name of a symbol of
+   language LANGUAGE.  */
+extern unsigned int search_name_hash (enum language language,
+                                     const char *search_name);
+
 /* Classification types for a minimal symbol.  These should be taken as
    "advisory only", since if gdb can't easily figure out a
    classification it simply selects mst_unknown.  It may also have to
index 2e4f30f291230b08f1735be223d1f4cba77a075e..46a43bc9ae389fb20eebda0fb059566787b0edef 100644 (file)
@@ -1044,7 +1044,8 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst)
   last_csect_name = 0;
 
   start_stabs ();
-  start_symtab (objfile, filestring, (char *) NULL, file_start_addr);
+  start_symtab (objfile, filestring, (char *) NULL, file_start_addr,
+               language_unknown);
   record_debugformat (debugfmt);
   symnum = ((struct symloc *) pst->read_symtab_private)->first_symnum;
   max_symnum =
@@ -1137,7 +1138,8 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst)
            }
 
          start_stabs ();
-         start_symtab (objfile, "_globals_", (char *) NULL, (CORE_ADDR) 0);
+         start_symtab (objfile, "_globals_", (char *) NULL, (CORE_ADDR) 0,
+                       language_unknown);
          record_debugformat (debugfmt);
          cur_src_end_addr = first_object_file_end;
          /* Done with all files, everything from here on is globals.  */
@@ -1227,7 +1229,7 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst)
                          /* Give all csects for this source file the same
                             name.  */
                          start_symtab (objfile, filestring, NULL,
-                                       (CORE_ADDR) 0);
+                                       (CORE_ADDR) 0, language_unknown);
                          record_debugformat (debugfmt);
                        }
 
@@ -1347,7 +1349,8 @@ read_xcoff_symtab (struct objfile *objfile, struct partial_symtab *pst)
            filestring = cs->c_name;
 
          start_stabs ();
-         start_symtab (objfile, filestring, (char *) NULL, (CORE_ADDR) 0);
+         start_symtab (objfile, filestring, (char *) NULL, (CORE_ADDR) 0,
+                       language_unknown);
          record_debugformat (debugfmt);
          last_csect_name = 0;