Make target_terminal_inferior/ours almost nops on non-main UIs
[deliverable/binutils-gdb.git] / gdb / dictionary.c
index 9d53ff0e3012e298b9bd5a1f3e6a2891e4c7c9a1..a6f80dca50f56f825b377ba87783c60bc13057ab 100644 (file)
@@ -1,6 +1,6 @@
 /* Routines for name->symbol lookups in GDB.
    
-   Copyright (C) 2003, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2003-2016 Free Software Foundation, Inc.
 
    Contributed by David Carlton <carlton@bactrian.org> and by Kealia,
    Inc.
@@ -25,7 +25,6 @@
 #include "gdb_obstack.h"
 #include "symtab.h"
 #include "buildsym.h"
-#include "gdb_assert.h"
 #include "dictionary.h"
 
 /* This file implements dictionaries, which are tables that associate
@@ -82,9 +81,7 @@
 
    * Define a function dict_<op> that looks up <op> in the dict_vector
    and calls the appropriate function.  Add a declaration for
-   dict_<op> to dictionary.h.
-   
-*/
+   dict_<op> to dictionary.h.  */
 
 /* An enum representing the various implementations of dictionaries.
    Used only for debugging.  */
@@ -118,13 +115,11 @@ struct dict_vector
   struct symbol *(*iterator_next) (struct dict_iterator *iterator);
   /* Functions to iterate over symbols with a given name.  */
   struct symbol *(*iter_match_first) (const struct dictionary *dict,
-                                    const char *name,
-                                    int (*equiv) (const char *,
-                                                  const char *),
-                                    struct dict_iterator *iterator);
+                                     const char *name,
+                                     symbol_compare_ftype *equiv,
+                                     struct dict_iterator *iterator);
   struct symbol *(*iter_match_next) (const char *name,
-                                    int (*equiv) (const char *,
-                                                  const char *),
+                                    symbol_compare_ftype *equiv,
                                     struct dict_iterator *iterator);
   /* A size function, for maint print symtabs.  */
   int (*size) (const struct dictionary *dict);
@@ -243,13 +238,11 @@ static struct symbol *iterator_next_hashed (struct dict_iterator *iterator);
 
 static struct symbol *iter_match_first_hashed (const struct dictionary *dict,
                                               const char *name,
-                                              int (*compare) (const char *,
-                                                              const char *),
+                                              symbol_compare_ftype *compare,
                                              struct dict_iterator *iterator);
 
 static struct symbol *iter_match_next_hashed (const char *name,
-                                             int (*compare) (const char *,
-                                                             const char *),
+                                             symbol_compare_ftype *compare,
                                              struct dict_iterator *iterator);
 
 static unsigned int dict_hash (const char *string);
@@ -277,13 +270,11 @@ static struct symbol *iterator_next_linear (struct dict_iterator *iterator);
 
 static struct symbol *iter_match_first_linear (const struct dictionary *dict,
                                               const char *name,
-                                              int (*compare) (const char *,
-                                                              const char *),
+                                              symbol_compare_ftype *compare,
                                               struct dict_iterator *iterator);
 
 static struct symbol *iter_match_next_linear (const char *name,
-                                             int (*compare) (const char *,
-                                                             const char *),
+                                             symbol_compare_ftype *compare,
                                              struct dict_iterator *iterator);
 
 static int size_linear (const struct dictionary *dict);
@@ -370,7 +361,7 @@ dict_create_hashed (struct obstack *obstack,
   struct symbol **buckets;
   const struct pending *list_counter;
 
-  retval = obstack_alloc (obstack, sizeof (struct dictionary));
+  retval = XOBNEW (obstack, struct dictionary);
   DICT_VECTOR (retval) = &dict_hashed_vector;
 
   /* Calculate the number of symbols, and allocate space for them.  */
@@ -382,7 +373,7 @@ dict_create_hashed (struct obstack *obstack,
     }
   nbuckets = DICT_HASHTABLE_SIZE (nsyms);
   DICT_HASHED_NBUCKETS (retval) = nbuckets;
-  buckets = obstack_alloc (obstack, nbuckets * sizeof (struct symbol *));
+  buckets = XOBNEWVEC (obstack, struct symbol *, nbuckets);
   memset (buckets, 0, nbuckets * sizeof (struct symbol *));
   DICT_HASHED_BUCKETS (retval) = buckets;
 
@@ -408,13 +399,12 @@ dict_create_hashed (struct obstack *obstack,
 extern struct dictionary *
 dict_create_hashed_expandable (void)
 {
-  struct dictionary *retval;
+  struct dictionary *retval = XNEW (struct dictionary);
 
-  retval = xmalloc (sizeof (struct dictionary));
   DICT_VECTOR (retval) = &dict_hashed_expandable_vector;
   DICT_HASHED_NBUCKETS (retval) = DICT_EXPANDABLE_INITIAL_CAPACITY;
-  DICT_HASHED_BUCKETS (retval) = xcalloc (DICT_EXPANDABLE_INITIAL_CAPACITY,
-                                         sizeof (struct symbol *));
+  DICT_HASHED_BUCKETS (retval) = XCNEWVEC (struct symbol *,
+                                          DICT_EXPANDABLE_INITIAL_CAPACITY);
   DICT_HASHED_EXPANDABLE_NSYMS (retval) = 0;
 
   return retval;
@@ -434,7 +424,7 @@ dict_create_linear (struct obstack *obstack,
   struct symbol **syms;
   const struct pending *list_counter;
 
-  retval = obstack_alloc (obstack, sizeof (struct dictionary));
+  retval = XOBNEW (obstack, struct dictionary);
   DICT_VECTOR (retval) = &dict_linear_vector;
 
   /* Calculate the number of symbols, and allocate space for them.  */
@@ -445,7 +435,7 @@ dict_create_linear (struct obstack *obstack,
       nsyms += list_counter->nsyms;
     }
   DICT_LINEAR_NSYMS (retval) = nsyms;
-  syms = obstack_alloc (obstack, nsyms * sizeof (struct symbol *));
+  syms = XOBNEWVEC (obstack, struct symbol *, nsyms );
   DICT_LINEAR_SYMS (retval) = syms;
 
   /* Now fill in the symbols.  Start filling in from the back, so as
@@ -473,16 +463,13 @@ dict_create_linear (struct obstack *obstack,
 struct dictionary *
 dict_create_linear_expandable (void)
 {
-  struct dictionary *retval;
+  struct dictionary *retval = XNEW (struct dictionary);
 
-  retval = xmalloc (sizeof (struct dictionary));
   DICT_VECTOR (retval) = &dict_linear_expandable_vector;
   DICT_LINEAR_NSYMS (retval) = 0;
-  DICT_LINEAR_EXPANDABLE_CAPACITY (retval)
-    = DICT_EXPANDABLE_INITIAL_CAPACITY;
+  DICT_LINEAR_EXPANDABLE_CAPACITY (retval) = DICT_EXPANDABLE_INITIAL_CAPACITY;
   DICT_LINEAR_SYMS (retval)
-    = xmalloc (DICT_LINEAR_EXPANDABLE_CAPACITY (retval)
-              * sizeof (struct symbol *));
+    = XNEWVEC (struct symbol *, DICT_LINEAR_EXPANDABLE_CAPACITY (retval));
 
   return retval;
 }
@@ -506,6 +493,22 @@ dict_add_symbol (struct dictionary *dict, struct symbol *sym)
   (DICT_VECTOR (dict))->add_symbol (dict, sym);
 }
 
+/* Utility to add a list of symbols to a dictionary.
+   DICT must be an expandable dictionary.  */
+
+void
+dict_add_pending (struct dictionary *dict, const struct pending *symbol_list)
+{
+  const struct pending *list;
+  int i;
+
+  for (list = symbol_list; list != NULL; list = list->next)
+    {
+      for (i = 0; i < list->nsyms; ++i)
+       dict_add_symbol (dict, list->symbol[i]);
+    }
+}
+
 /* Initialize ITERATOR to point at the first symbol in DICT, and
    return that first symbol, or NULL if DICT is empty.  */
 
@@ -542,16 +545,15 @@ dict_iter_name_next (const char *name, struct dict_iterator *iterator)
 
 struct symbol *
 dict_iter_match_first (const struct dictionary *dict,
-                      const char *name,
-                      int (*compare) (const char *, const char *),
+                      const char *name, symbol_compare_ftype *compare,
                       struct dict_iterator *iterator)
 {
-  return (DICT_VECTOR (dict))->iter_match_first (dict, name, compare, iterator);
+  return (DICT_VECTOR (dict))->iter_match_first (dict, name,
+                                                compare, iterator);
 }
 
 struct symbol *
-dict_iter_match_next (const char *name,
-                     int (*compare) (const char *, const char *),
+dict_iter_match_next (const char *name, symbol_compare_ftype *compare,
                      struct dict_iterator *iterator)
 {
   return (DICT_VECTOR (DICT_ITERATOR_DICT (iterator)))
@@ -646,9 +648,8 @@ iterator_hashed_advance (struct dict_iterator *iterator)
 }
 
 static struct symbol *
-iter_match_first_hashed (const struct dictionary *dict,
-                        const char *name,
-                        int (*compare) (const char *, const char *),
+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);
@@ -677,8 +678,7 @@ iter_match_first_hashed (const struct dictionary *dict,
 }
 
 static struct symbol *
-iter_match_next_hashed (const char *name,
-                       int (*compare) (const char *, const char *),
+iter_match_next_hashed (const char *name, symbol_compare_ftype *compare,
                        struct dict_iterator *iterator)
 {
   struct symbol *next;
@@ -750,9 +750,8 @@ expand_hashtable (struct dictionary *dict)
 {
   int old_nbuckets = DICT_HASHED_NBUCKETS (dict);
   struct symbol **old_buckets = DICT_HASHED_BUCKETS (dict);
-  int new_nbuckets = 2*old_nbuckets + 1;
-  struct symbol **new_buckets = xcalloc (new_nbuckets,
-                                        sizeof (struct symbol *));
+  int new_nbuckets = 2 * old_nbuckets + 1;
+  struct symbol **new_buckets = XCNEWVEC (struct symbol *, new_nbuckets);
   int i;
 
   DICT_HASHED_NBUCKETS (dict) = new_nbuckets;
@@ -802,7 +801,7 @@ dict_hash (const char *string0)
   string = string0;
   if (*string == '_')
     {
-      if (strncmp (string, "_ada_", 5) == 0)
+      if (startswith (string, "_ada_"))
        string += 5;
       else
        return msymbol_hash_iw (string0);
@@ -811,6 +810,17 @@ dict_hash (const char *string0)
   hash = 0;
   while (*string)
     {
+      /* Ignore "TKB" suffixes.
+
+        These are used by Ada for subprograms implementing a task body.
+        For instance for a task T inside package Pck, the name of the
+        subprogram implementing T's body is `pck__tTKB'.  We need to
+        ignore the "TKB" suffix because searches for this task body
+        subprogram are going to be performed using `pck__t' (the encoded
+        version of the natural name `pck.t').  */
+      if (strcmp (string, "TKB") == 0)
+       return hash;
+
       switch (*string)
        {
        case '$':
@@ -836,7 +846,7 @@ dict_hash (const char *string0)
            }
          /* FALL THROUGH */
        default:
-         hash = hash * 67 + *string - 113;
+         hash = SYMBOL_HASH_NEXT (hash, *string);
          string += 1;
          break;
        }
@@ -868,8 +878,7 @@ iterator_next_linear (struct dict_iterator *iterator)
 
 static struct symbol *
 iter_match_first_linear (const struct dictionary *dict,
-                        const char *name,
-                        int (*compare) (const char *, const char *),
+                        const char *name, symbol_compare_ftype *compare,
                         struct dict_iterator *iterator)
 {
   DICT_ITERATOR_DICT (iterator) = dict;
@@ -879,8 +888,7 @@ iter_match_first_linear (const struct dictionary *dict,
 }
 
 static struct symbol *
-iter_match_next_linear (const char *name,
-                       int (*compare) (const char *, const char *),
+iter_match_next_linear (const char *name, symbol_compare_ftype *compare,
                        struct dict_iterator *iterator)
 {
   const struct dictionary *dict = DICT_ITERATOR_DICT (iterator);
@@ -929,9 +937,8 @@ add_symbol_linear_expandable (struct dictionary *dict,
     {
       DICT_LINEAR_EXPANDABLE_CAPACITY (dict) *= 2;
       DICT_LINEAR_SYMS (dict)
-       = xrealloc (DICT_LINEAR_SYMS (dict),
-                   DICT_LINEAR_EXPANDABLE_CAPACITY (dict)
-                   * sizeof (struct symbol *));
+       = XRESIZEVEC (struct symbol *, DICT_LINEAR_SYMS (dict),
+                     DICT_LINEAR_EXPANDABLE_CAPACITY (dict));
     }
 
   DICT_LINEAR_SYM (dict, nsyms - 1) = sym;
This page took 0.056851 seconds and 4 git commands to generate.