]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
2002-09-26 David Carlton <carlton@math.stanford.edu>
authorDavid Carlton <carlton@bactrian.org>
Fri, 27 Sep 2002 00:18:18 +0000 (00:18 +0000)
committerDavid Carlton <carlton@bactrian.org>
Fri, 27 Sep 2002 00:18:18 +0000 (00:18 +0000)
* dictionary.c (dict_iter_name_first): New function.
(dict_iter_name_next): New function.
Initialize new members of dict_hashed_vtbl, dict_linear_vtbl, and
dict_linear_expandable_vtbl.
(iter_name_first_hashed): New function.
(iter_name_next_hashed): New function.
(iter_name_first_linear): New function.
(iter_name_next_linear): New function.
(lookup_hashed): Rewrite following new declaration/semantics.
(lookup_linear): Ditto.
(dict_lookup): Ditto.
* symtab.c (lookup_block_symbol): Rewrite to use
dict_iter_name_first and dict_iter_name_next instead of
dict_lookup.
* dictionary.c (struct dict_vtbl): Change member 'lookup'; new
members 'iter_name_first' and 'iter_name_next'.
* dictionary.h: Delete all traces of block stuff.
Change declaration for dict_lookup; new declarations
dict_iter_name_first and dict_iter_name_next.
* dictionary.c: Delete all traces of block stuff.
* symtab.h (SYMBOL_BEST_NAME): New macro.
(SYMBOL_SOURCE_NAME): Rewrite in terms of SYMBOL_BEST_NAME.
(SYMBOL_LINKAGE_NAME): Ditto.
Comment questioning SYMBOL_MATCHES_NAME and
SYMBOL_MATCHES_REGEXP.
* Makefile.in (ns32knbsd-tdep.o): Depend on gdb_string_h.
* ns32knbsd-tdep.c: #include "gdb_string.h"

gdb/ChangeLog
gdb/Makefile.in
gdb/dictionary.c
gdb/dictionary.h
gdb/ns32knbsd-tdep.c
gdb/symtab.c
gdb/symtab.h

index 008a5ef5ceefc90508ac8ad2c9bdfef1cb20b9b4..336c0aa210da15462aa3474c34c000a01b8af3d0 100644 (file)
@@ -1,3 +1,33 @@
+2002-09-26  David Carlton  <carlton@math.stanford.edu>
+
+       * dictionary.c (dict_iter_name_first): New function.
+       (dict_iter_name_next): New function.
+       Initialize new members of dict_hashed_vtbl, dict_linear_vtbl, and
+       dict_linear_expandable_vtbl.
+       (iter_name_first_hashed): New function.
+       (iter_name_next_hashed): New function.
+       (iter_name_first_linear): New function.
+       (iter_name_next_linear): New function.
+       (lookup_hashed): Rewrite following new declaration/semantics.
+       (lookup_linear): Ditto.
+       (dict_lookup): Ditto.
+       * symtab.c (lookup_block_symbol): Rewrite to use
+       dict_iter_name_first and dict_iter_name_next instead of
+       dict_lookup.
+       * dictionary.c (struct dict_vtbl): Change member 'lookup'; new
+       members 'iter_name_first' and 'iter_name_next'.
+       * dictionary.h: Delete all traces of block stuff.
+       Change declaration for dict_lookup; new declarations
+       dict_iter_name_first and dict_iter_name_next.
+       * dictionary.c: Delete all traces of block stuff.
+       * symtab.h (SYMBOL_BEST_NAME): New macro.
+       (SYMBOL_SOURCE_NAME): Rewrite in terms of SYMBOL_BEST_NAME.
+       (SYMBOL_LINKAGE_NAME): Ditto.
+       Comment questioning SYMBOL_MATCHES_NAME and
+       SYMBOL_MATCHES_REGEXP.
+       * Makefile.in (ns32knbsd-tdep.o): Depend on gdb_string_h.
+       * ns32knbsd-tdep.c: #include "gdb_string.h"
+
 2002-09-25  David Carlton  <carlton@math.stanford.edu>
 
        * dictionary.c: Commented what needs to be done to add stuff to
index bcefadd7f89b99a7b5ee7acef38b7e5bf2531fd9..34ecbe49d5a00cafd5f6aaf536f168148b639e90 100644 (file)
@@ -1952,7 +1952,7 @@ ns32k-tdep.o: ns32k-tdep.c $(defs_h) $(frame_h) $(gdbtypes_h) $(gdbcore_h) \
        $(ns32k_tdep_h) $(gdb_string_h)
 ns32knbsd-nat.o: ns32knbsd-nat.c $(defs_h) $(inferior_h) $(target_h) \
        $(gdbcore_h) $(regcache_h)
-ns32knbsd-tdep.o: ns32knbsd-tdep.c $(defs_h) $(ns32k_tdep_h)
+ns32knbsd-tdep.o: ns32knbsd-tdep.c $(defs_h) $(ns32k_tdep_h) $(gdb_string_h)
 objfiles.o: objfiles.c $(defs_h) $(bfd_h) $(symtab_h) $(symfile_h) \
        $(objfiles_h) $(gdb_stabs_h) $(target_h) $(bcache_h) $(gdb_stat_h) \
        $(gdb_obstack_h) $(gdb_string_h) $(breakpoint_h) $(mmalloc_h) \
index 0e98be2fea91eb3bb6d2db492ee07dc157d32849..c960022fd51dd4846ff0c7ddf984ffbb6452319a 100644 (file)
@@ -106,13 +106,6 @@ enum dict_type
     DICT_LINEAR,
     /* Symbols are stored in an expandable array.  */
     DICT_LINEAR_EXPANDABLE,
-#if 0
-    /* Symbols are stored in a fixed-size block.  */
-    DICT_BLOCK,
-    /* Symbols are stored in an expandable block.  */
-    DICT_BLOCK_EXPANDABLE,
-    
-#endif
   };
 
 /* The virtual function table.  */
@@ -126,14 +119,17 @@ struct dict_vtbl
   void (*free) (struct dictionary *dict);
   /* The symbol lookup function.  */
   struct symbol *(*lookup) (const struct dictionary *dict,
-                           const char *name,
-                           const char *mangled_name,
-                           const namespace_enum namespace);
+                           const char *name);
   /* Iterator functions.  */
   struct symbol *(*iterator_first) (const struct dictionary *dict,
                                    struct dict_iterator *iterator);
   struct symbol *(*iterator_next) (struct dict_iterator *iterator);
   void (*add_symbol) (struct dictionary *dict, struct symbol *sym);
+  struct symbol *(*iter_name_first) (const struct dictionary *dict,
+                                    const char *name,
+                                    struct dict_iterator *iterator);
+  struct symbol *(*iter_name_next) (const char *name,
+                                   struct dict_iterator *iterator);
 };
 
 /* Now comes the structs used to store the data for different
@@ -166,19 +162,6 @@ struct dictionary_linear_expandable
   int capacity;
 };
 
-#if 0
-struct dictionary_block
-{
-  struct block *block;
-};
-
-struct dictionary_block_expandable
-{
-  struct block *block;
-  unsigned int capacity;
-};
-#endif
-
 /* And now, the star of our show.  */
 
 struct dictionary
@@ -189,10 +172,6 @@ struct dictionary
     struct dictionary_hashed hashed;
     struct dictionary_linear linear;
     struct dictionary_linear_expandable linear_expandable;
-#if 0
-    struct dictionary_block block;
-    struct dictionary_block_expandable block_expandable;
-#endif
   }
   data;
 };
@@ -214,24 +193,10 @@ struct dictionary
 #define DICT_LINEAR_EXPANDABLE_CAPACITY(d) \
                (d)->data.linear_expandable.capacity
 
-#if 0
-/* This can be used for DICT_BLOCK_EXPANDABLES, too.  */
-
-#define DICT_BLOCK_BLOCK(d)            (d)->data.block.block
-
-#define DICT_BLOCK_EXPANDABLE_CAPACITY(d) (d)->data.block_expandable.capacity
-
-#endif
 /* The initial size of a DICT_LINEAR_EXPANDABLE dictionary.  */
 
 #define DICT_LINEAR_EXPANDABLE_INITIAL_CAPACITY 10
 
-#if 0
-#define DICT_BLOCK_EXPANDABLE_INITIAL_CAPACITY \
-               DICT_LINEAR_EXPANDABLE_INITIAL_CAPACITY
-
-#endif
-
 /* This calculates the number of buckets we'll use in a hashtable,
    given the number of symbols that it will contain.  */
 
@@ -255,11 +220,6 @@ struct dictionary
 
 static struct symbol *iterator_hashed_advance (struct dict_iterator *iter);
 
-#if 0
-static struct symbol *iterator_block_hashed_advance (struct dict_iterator
-                                                    *iter);
-#endif
-
 /* Declarations of functions for vtbls.  */
 
 /* Functions that might work across a range of dictionary types.  */
@@ -272,28 +232,39 @@ static void free_obstack (struct dictionary *dict);
 /* Functions for DICT_HASHED dictionaries.  */
 
 static struct symbol *lookup_hashed (const struct dictionary *dict,
-                                    const char *name,
-                                    const char *mangled_name,
-                                    const namespace_enum namespace);
+                                    const char *name);
 
 static struct symbol *iterator_first_hashed (const struct dictionary *dict,
                                             struct dict_iterator *iterator);
 
 static struct symbol *iterator_next_hashed (struct dict_iterator *iterator);
 
+static struct symbol *iter_name_first_hashed (const struct dictionary *dict,
+                                             const char *name,
+                                             struct dict_iterator *iterator);
+
+static struct symbol *iter_name_next_hashed (const char *name,
+                                            struct dict_iterator *iterator);
+
 /* Functions for DICT_LINEAR and DICT_LINEAR_EXPANDABLE
    dictionaries.  */
 
 static struct symbol *lookup_linear (const struct dictionary *dict,
-                                    const char *name,
-                                    const char *mangled_name,
-                                    const namespace_enum namespace);
+                                    const char *name);
 
 static struct symbol *iterator_first_linear (const struct dictionary *dict,
                                             struct dict_iterator *iterator);
 
 static struct symbol *iterator_next_linear (struct dict_iterator *iterator);
 
+static struct symbol *iter_name_first_linear (const struct dictionary *dict,
+                                             const char *name,
+                                             struct dict_iterator *iterator);
+
+static struct symbol *iter_name_next_linear (const char *name,
+                                            struct dict_iterator *iterator);
+
+
 /* Functions only for DICT_LINEAR_EXPANDABLE.  */
 
 static void free_linear_expandable (struct dictionary *dict);
@@ -301,59 +272,30 @@ static void free_linear_expandable (struct dictionary *dict);
 static void add_symbol_linear_expandable (struct dictionary *dict,
                                          struct symbol *sym);
 
-#if 0
-/* Functions for blocks.  */
-
-static struct symbol *lookup_block (const struct dictionary *dict,
-                                   const char *name,
-                                   const char *mangled_name,
-                                   const namespace_enum namespace);
-
-
-static void free_block(struct dictionary *dict);
-
-static struct symbol *iterator_first_block (const struct dictionary *dict,
-                                           struct dict_iterator *iterator);
-
-static struct symbol *iterator_next_block (struct dict_iterator *iterator);
-
-#endif
-
 /* Various vtbls that we'll actually use.  */
 
 static const struct dict_vtbl dict_hashed_vtbl =
   {
     DICT_HASHED, free_obstack, lookup_hashed, iterator_first_hashed,
-    iterator_next_hashed, add_symbol_nonexpandable,
+    iterator_next_hashed, add_symbol_nonexpandable, iter_name_first_hashed,
+    iter_name_next_hashed,
   };
 
 static const struct dict_vtbl dict_linear_vtbl =
   {
     DICT_LINEAR, free_obstack, lookup_linear, iterator_first_linear,
-    iterator_next_linear, add_symbol_nonexpandable,
+    iterator_next_linear, add_symbol_nonexpandable, iter_name_first_linear,
+    iter_name_next_linear,
   };
 
 static const struct dict_vtbl dict_linear_expandable_vtbl =
   {
     DICT_LINEAR_EXPANDABLE, free_linear_expandable, lookup_linear,
     iterator_first_linear, iterator_next_linear,
-    add_symbol_linear_expandable,
-  };
-
-#if 0
-static const struct dict_vtbl dict_block_vtbl =
-  {
-    DICT_BLOCK, free_block, lookup_block, iterator_first_block,
-    iterator_next_block, add_symbol_nonexpandable,
+    add_symbol_linear_expandable, iter_name_first_linear,
+    iter_name_next_linear,
   };
 
-static const struct dict_vtbl dict_block_expandable_vtbl =
-  {
-    DICT_BLOCK_EXPANDABLE, free_block, lookup_block, iterator_first_block,
-    iterator_next_block, add_symbol_nonexpandable,
-  };
-#endif
-
 /* The creation functions.  */
 
 /* Create a dictionary implemented via a fixed-size hashtable.  All
@@ -394,10 +336,7 @@ dict_create_hashed (struct obstack *obstack,
        {
          struct symbol *sym = list_counter->symbol[i];
          unsigned int hash_index;
-         const char *name = SYMBOL_DEMANGLED_NAME (sym);
-         if (name == NULL)
-           name = SYMBOL_NAME (sym);
-         hash_index = msymbol_hash_iw (name) % nbuckets;
+         hash_index = msymbol_hash_iw (SYMBOL_BEST_NAME (sym)) % nbuckets;
          sym->hash_next = buckets[hash_index];
          buckets[hash_index] = sym;
        }
@@ -479,37 +418,6 @@ dict_create_linear_expandable (void)
   return retval;
 }
 
-#if 0
-/* Allocate a dictionary in which symbol lookup is implemented via
-   BLOCK.  Needs to be freed by dict_free; I won't worry about that,
-   however, since this will go away soon.  */
-
-struct dictionary *
-dict_create_block (struct block *block)
-{
-  struct dictionary *retval = xmalloc (sizeof (struct dictionary));
-
-  DICT_VTBL (retval) = &dict_block_vtbl;
-  DICT_BLOCK_BLOCK (retval) = block;
-
-  return retval;
-}
-
-struct dictionary *
-dict_create_block_expandable (struct block *block)
-{
-  struct dictionary *retval = xmalloc (sizeof (struct dictionary));
-
-  DICT_VTBL (retval) = &dict_block_expandable_vtbl;
-  DICT_BLOCK_BLOCK (retval) = block;
-  /* We'll resize the block the first time we add a symbol to it.  */
-  DICT_BLOCK_EXPANDABLE_CAPACITY (retval) = 0;
-
-  return retval;
-}
-
-#endif
-
 /* The functions providing the dictionary interface.  */
 
 /* Free the memory used by a dictionary that's not on an obstack.  (If
@@ -532,11 +440,9 @@ dict_free (struct dictionary *dict)
 
 struct symbol *
 dict_lookup (const struct dictionary *dict,
-            const char *name,
-            const char *mangled_name,
-            const namespace_enum namespace)
+            const char *name)
 {
-  return (DICT_VTBL (dict))->lookup (dict, name, mangled_name, namespace);
+  return (DICT_VTBL (dict))->lookup (dict, name);
 }
 
 /* Initialize ITERATOR to point at the first symbol in DICT, and
@@ -563,7 +469,7 @@ dict_iterator_next (struct dict_iterator *iterator)
    it's easy enough to do generically and doesn't get called a
    lot.  */
 
-extern int
+int
 dict_empty (struct dictionary *dict)
 {
   struct dict_iterator iter;
@@ -573,12 +479,28 @@ dict_empty (struct dictionary *dict)
 
 /* Add SYM to DICT.  DICT had better be expandable.  */
 
-extern void
+void
 dict_add_symbol (struct dictionary *dict, struct symbol *sym)
 {
   (DICT_VTBL (dict))->add_symbol (dict, sym);
 }
 
+struct symbol *
+dict_iter_name_first (const struct dictionary *dict,
+                     const char *name,
+                     struct dict_iterator *iterator)
+{
+  return (DICT_VTBL (dict))->iter_name_first (dict, name, iterator);
+}
+
+struct symbol *
+dict_iter_name_next (const char *name, struct dict_iterator *iterator)
+{
+  return (DICT_VTBL (DICT_ITERATOR_DICT (iterator)))
+    ->iter_name_next (name, iterator);
+}
+
 
 /* The functions implementing the dictionary interface.  */
 
@@ -601,9 +523,7 @@ add_symbol_nonexpandable (struct dictionary *dict, struct symbol *sym)
 
 static struct symbol *
 lookup_hashed (const struct dictionary *dict,
-              const char *name,
-              const char *mangled_name,
-              const namespace_enum namespace)
+              const char *name)
 {
   unsigned int hash_index
     = msymbol_hash_iw (name) % DICT_HASHED_NBUCKETS (dict);
@@ -613,10 +533,8 @@ lookup_hashed (const struct dictionary *dict,
        sym;
        sym = sym->hash_next)
     {
-      if (SYMBOL_NAMESPACE (sym) == namespace
-         && (mangled_name
-             ? strcmp (SYMBOL_NAME (sym), mangled_name) == 0
-             : SYMBOL_MATCHES_NAME (sym, name)))
+      /* Warning: the order of arguments to strcmp_iw matters!  */
+      if (strcmp_iw (SYMBOL_BEST_NAME (sym), name) == 0)
        return sym;
     }
   
@@ -638,8 +556,9 @@ iterator_next_hashed (struct dict_iterator *iterator)
   const struct dictionary *dict = DICT_ITERATOR_DICT (iterator);
   struct symbol *next;
 
-  /* FIXME: carlton/2002-09-23: Should I assert that
-     DICT_ITERATOR_CURRENT (iterator) != NULL?  */
+  /* FIXME: carlton/2002-09-23: Should I gdb_assert that
+     DICT_ITERATOR_CURRENT (iterator) != NULL?  (Ditto for
+     iter_name_next_hashed.)  */
   next = DICT_ITERATOR_CURRENT (iterator)->hash_next;
   
   if (next == NULL)
@@ -673,97 +592,45 @@ iterator_hashed_advance (struct dict_iterator *iterator)
   return NULL;
 }
 
-/* Functions for DICT_LINEAR and DICT_LINEAR_EXPANDABLE.  */
+static struct symbol *
+iter_name_first_hashed (const struct dictionary *dict,
+                       const char *name,
+                       struct dict_iterator *iterator)
+{
+  DICT_ITERATOR_DICT (iterator) = dict;
+  DICT_ITERATOR_CURRENT (iterator) = lookup_hashed (dict, name);
+
+  return DICT_ITERATOR_CURRENT (iterator);
+}
 
 static struct symbol *
-lookup_linear (const struct dictionary *dict,
-              const char *name,
-              const char *mangled_name,
-              const namespace_enum namespace)
+iter_name_next_hashed (const char *name, struct dict_iterator *iterator)
 {
-  /* More or less copied from lookup_block_symbol() in symtab.c,
-     including the comments.  */
+  struct symbol *next;
 
-  int i, nsyms = DICT_LINEAR_NSYMS (dict);
-  struct symbol *sym, *sym_found = NULL;
-  
-  for (i = 0; i < nsyms; ++i)
+  for (next = DICT_ITERATOR_CURRENT (iterator)->hash_next;
+       next; next = next->hash_next)
     {
-      sym = DICT_LINEAR_SYM (dict, i);
+      if (strcmp_iw (SYMBOL_BEST_NAME (next), name) == 0)
+       break;
+    }
 
-      /* NOTE: carlton/2002-09-24: I copied the following comment here
-        from the sorted linear symbol case of lookup_block_symbol.
-        But Jim Blandy complained, and said it didn't belong in the
-        non-sorted case.  (Understandable, since it refers to
-        sorting!)  I wish I understood exactly what its purpose
-        had been.  */
-
-      /* If there is more than one symbol with the right name and
-        namespace, we return the first one; I believe it is now
-        impossible for us to encounter two symbols with the same name
-        and namespace here, because blocks containing argument
-        symbols are no longer sorted.  The exception is for C++,
-        where multiple functions (cloned constructors / destructors,
-        in particular) can have the same demangled name.  So if we
-        have a particular mangled name to match, try to do so.  */
-      if (SYMBOL_NAMESPACE (sym) == namespace
-         && (mangled_name
-             ? strcmp (SYMBOL_NAME (sym), mangled_name) == 0
-             : SYMBOL_MATCHES_NAME (sym, name)))
-       {
+  DICT_ITERATOR_CURRENT (iterator) = next;
 
-#if 0
-         /* FIXME: carlton/2002-09-11: According to
-            <http://sources.redhat.com/ml/gdb/2002-03/msg00232.html>,
-            the SYMBOL_ALIASES stuff is unused, and it makes the code
-            messier, so I'm #if'ing it out here.  */
-
-         /* If SYM has aliases, then use any alias that is active at
-            the current PC.  If no alias is active at the current PC,
-            then use the main symbol.
-            
-            ?!? Is checking the current pc correct?  Is this routine
-            ever called to look up a symbol from another context?
-                  
-            FIXME: No, it's not correct.  If someone sets a
-            conditional breakpoint at an address, then the
-            breakpoint's `struct expression' should refer to the
-            `struct symbol' appropriate for the breakpoint's address,
-            which may not be the PC.
-                  
-            Even if it were never called from another context, it's
-            totally bizarre for lookup_symbol's behavior to depend on
-            the value of the inferior's current PC.  We should pass
-            in the appropriate PC as well as the block.  The
-            interface to lookup_symbol should change to require the
-            caller to provide a PC.  */
-
-         if (SYMBOL_ALIASES (sym))
-           sym = find_active_alias (sym, read_pc ());
-#endif /* 0 */
-         /* NOTE: carlton/2002-09-11: I wish I understood exactly the
-            situations where this next bit is important.  Sigh.  */
-               
-         /* Note that parameter symbols do not always show up last in
-            the list; this loop makes sure to take anything else
-            other than parameter symbols first; it only uses
-            parameter symbols as a last resort.  Note that this only
-            takes up extra computation time on a match.  */
-
-         sym_found = sym;
-         if (SYMBOL_CLASS (sym) != LOC_ARG &&
-             SYMBOL_CLASS (sym) != LOC_LOCAL_ARG &&
-             SYMBOL_CLASS (sym) != LOC_REF_ARG &&
-             SYMBOL_CLASS (sym) != LOC_REGPARM &&
-             SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR &&
-             SYMBOL_CLASS (sym) != LOC_BASEREG_ARG)
-           {
-             break;
-           }
-       }
-    }
-  
-  return (sym_found);          /* Will be NULL if not found. */
+  return next;
+}
+
+/* Functions for DICT_LINEAR and DICT_LINEAR_EXPANDABLE.  */
+
+static struct symbol *
+lookup_linear (const struct dictionary *dict, const char *name)
+{
+  /* NOTE: carlton/2002-09-26: I don't expect this to get called much,
+     so let's just use iter_name_first_linear.  */
+
+  struct dict_iterator iter;
+
+  return iter_name_first_linear (dict, name, &iter);
 }
 
 static struct symbol *
@@ -786,6 +653,39 @@ iterator_next_linear (struct dict_iterator *iterator)
     return DICT_LINEAR_SYM (dict, DICT_ITERATOR_INDEX (iterator));
 }
 
+static struct symbol *
+iter_name_first_linear (const struct dictionary *dict,
+                       const char *name,
+                       struct dict_iterator *iterator)
+{
+  DICT_ITERATOR_DICT (iterator) = dict;
+  DICT_ITERATOR_INDEX (iterator) = -1;
+
+  return iter_name_next_linear (name, iterator);
+}
+
+static struct symbol *
+iter_name_next_linear (const char *name, struct dict_iterator *iterator)
+{
+  const struct dictionary *dict = DICT_ITERATOR_DICT (iterator);
+  int i, nsyms = DICT_LINEAR_NSYMS (dict);
+  struct symbol *sym, *retval = NULL;
+
+  for (i = DICT_ITERATOR_INDEX (iterator) + 1; i < nsyms; ++i)
+    {
+      sym = DICT_LINEAR_SYM (dict, i);
+      if (strcmp_iw (SYMBOL_BEST_NAME (sym), name) == 0)
+       {
+         retval = sym;
+         break;
+       }
+    }
+
+  DICT_ITERATOR_INDEX (iterator) = i;
+  
+  return retval;
+}
+
 /* Functions only for DICT_LINEAR_EXPANDABLE.  */
 
 static void
@@ -813,220 +713,3 @@ add_symbol_linear_expandable (struct dictionary *dict,
 
   DICT_LINEAR_SYM (dict, nsyms - 1) = sym;
 }
-
-
-#if 0
-
-/* Functions for DICT_BLOCK and DICT_BLOCK_EXPANDABLE.  */
-
-static void
-free_block (struct dictionary *dict)
-{
-  xfree (dict);
-}
-
-static struct symbol *
-lookup_block (const struct dictionary *dict,
-             const char *name,
-             const char *mangled_name,
-             const namespace_enum namespace)
-{
-  struct block *block = DICT_BLOCK_BLOCK (dict);
-  register int bot, top;
-  register struct symbol *sym;
-  register struct symbol *sym_found = NULL;
-
-  if (BLOCK_HASHTABLE (block))
-    {
-      unsigned int hash_index;
-      hash_index = msymbol_hash_iw (name);
-      hash_index = hash_index % BLOCK_BUCKETS (block);
-      for (sym = BLOCK_BUCKET (block, hash_index); sym; sym = sym->hash_next)
-       {
-         if (SYMBOL_NAMESPACE (sym) == namespace 
-             && (mangled_name
-                 ? strcmp (SYMBOL_NAME (sym), mangled_name) == 0
-                 : SYMBOL_MATCHES_NAME (sym, name)))
-           return sym;
-       }
-      return NULL;
-    }
-  else
-    {
-      /* Note that parameter symbols do not always show up last in the
-        list.  This loop makes sure to take anything else other than
-        parameter symbols first; it only uses parameter symbols as a
-        last resort.  Note that this only takes up extra computation
-        time on a match.  */
-      top = BLOCK_NSYMS (block);
-      bot = 0;
-      while (bot < top)
-       {
-         sym = BLOCK_SYM (block, bot);
-         /* If there is more than one symbol with the right name and
-            namespace, we return the first one; I believe it is now
-            impossible for us to encounter two symbols with the same
-            name and namespace here, because blocks containing
-            argument symbols are no longer sorted.  The exception is
-            for C++, where multiple functions (cloned constructors /
-            destructors, in particular) can have the same demangled
-            name.  So if we have a particular mangled name to match,
-            try to do so.  */
-         if (SYMBOL_NAMESPACE (sym) == namespace
-             && (mangled_name
-                 ? strcmp (SYMBOL_NAME (sym), mangled_name) == 0
-                 : SYMBOL_MATCHES_NAME (sym, name)))
-           {
-#if 0
-             /* FIXME: carlton/2002-09-11: According to
-                <http://sources.redhat.com/ml/gdb/2002-03/msg00232.html>,
-                the SYMBOL_ALIASES stuff is unused, and it makes
-                the code messier, so I'm #if'ing it out here.  */
-
-             /* If SYM has aliases, then use any alias that is active
-                at the current PC.  If no alias is active at the current
-                PC, then use the main symbol.
-
-                ?!? Is checking the current pc correct?  Is this routine
-                ever called to look up a symbol from another context?
-
-                FIXME: No, it's not correct.  If someone sets a
-                conditional breakpoint at an address, then the
-                breakpoint's `struct expression' should refer to the
-                `struct symbol' appropriate for the breakpoint's
-                address, which may not be the PC.
-
-                Even if it were never called from another context,
-                it's totally bizarre for lookup_symbol's behavior to
-                depend on the value of the inferior's current PC.  We
-                should pass in the appropriate PC as well as the
-                block.  The interface to lookup_symbol should change
-                to require the caller to provide a PC.  */
-
-             if (SYMBOL_ALIASES (sym))
-               sym = find_active_alias (sym, read_pc ());
-#endif /* 0 */
-
-             sym_found = sym;
-             if (SYMBOL_CLASS (sym) != LOC_ARG &&
-                 SYMBOL_CLASS (sym) != LOC_LOCAL_ARG &&
-                 SYMBOL_CLASS (sym) != LOC_REF_ARG &&
-                 SYMBOL_CLASS (sym) != LOC_REGPARM &&
-                 SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR &&
-                 SYMBOL_CLASS (sym) != LOC_BASEREG_ARG)
-               {
-                 break;
-               }
-           }
-         bot++;
-       }
-      return (sym_found);              /* Will be NULL if not found. */
-    }  
-}
-
-static struct symbol *
-iterator_first_block (const struct dictionary *dict,
-                     struct dict_iterator *iterator)
-{
-  struct block *block = DICT_BLOCK_BLOCK (dict);
-
-  DICT_ITERATOR_DICT (iterator) = dict;
-       
-  if (BLOCK_HASHTABLE (block))
-    {
-      DICT_ITERATOR_INDEX (iterator) = -1;
-      return iterator_block_hashed_advance (iterator);
-    }
-  else
-    {
-      DICT_ITERATOR_INDEX (iterator) = 0;
-      return BLOCK_NSYMS (block) ? BLOCK_SYM (block, 0) : NULL;
-    }
-}
-
-static struct symbol *
-iterator_next_block (struct dict_iterator *iterator)
-{
-  const struct dictionary *dict = DICT_ITERATOR_DICT (iterator);
-  struct block *block = DICT_BLOCK_BLOCK (dict);
-       
-  if (BLOCK_HASHTABLE (block))
-    {
-      struct symbol *next = DICT_ITERATOR_CURRENT (iterator)->hash_next;
-           
-      if (next == NULL)
-       return iterator_block_hashed_advance (iterator);
-      else
-       {
-         DICT_ITERATOR_CURRENT (iterator) = next;
-         return next;
-       }
-    }
-  else
-    {
-      if (++(DICT_ITERATOR_INDEX (iterator)) >= BLOCK_NSYMS (block))
-       return NULL;
-      else
-       return BLOCK_SYM (block, DICT_ITERATOR_INDEX (iterator));
-    }
-}
-
-/* A helper function for iterator_first_block and
-   iterator_first_block_next_block.  Search for the next nonempty
-   bucket; update iterator accordingly, and return it.  */
-
-static struct symbol *
-iterator_block_hashed_advance (struct dict_iterator *iterator)
-{
-  struct block *block =
-    DICT_BLOCK_BLOCK (DICT_ITERATOR_DICT (iterator));
-  int nbuckets = BLOCK_BUCKETS (block);
-  int i;
-
-  for (i = DICT_ITERATOR_INDEX (iterator) + 1; i < nbuckets; ++i)
-    {
-      struct symbol *sym = BLOCK_BUCKET (block, i);
-      
-      if (sym != NULL)
-       {
-         DICT_ITERATOR_INDEX (iterator) = i;
-         DICT_ITERATOR_CURRENT (iterator) = sym;
-         return sym;
-       }
-    }
-
-  return NULL;
-}
-
-/* A special-case function for DICT_BLOCK_EXPANDABLE.  */
-
-/* FIXME: carlton/2002-09-20: But some callers use xmmalloc!!!
-   Crap.  */
-
-struct block *
-dict_add_symbol_block (struct dictionary *dict, struct symbol *sym)
-{
-  gdb_assert ((DICT_VTBL (dict))->type == DICT_BLOCK_EXPANDABLE);
-
-  struct block *block = DICT_BLOCK_BLOCK (dict);
-
-  if (++BLOCK_NSYMS (block) > DICT_BLOCK_EXPANDABLE_CAPACITY (dict))
-    {
-      if (DICT_BLOCK_EXPANDABLE_CAPACITY (dict))
-       DICT_BLOCK_EXPANDABLE_CAPACITY (dict) *= 2;
-      else
-       DICT_BLOCK_EXPANDABLE_CAPACITY (dict)
-         = DICT_BLOCK_EXPANDABLE_INITIAL_CAPACITY;
-
-      block = xrealloc (block,
-                       sizeof (struct block)
-                       + ((DICT_BLOCK_EXPANDABLE_CAPACITY (dict) -1)
-                          * sizeof (struct symbol)));
-      DICT_BLOCK_BLOCK (dict) = block;
-    }
-
-  BLOCK_SYM (block, BLOCK_NSYMS (block) - 1) = sym;
-
-  return block;
-}
-#endif
index ea39922e429a0e8f8d1434b90d04b50d65f4cf1a..d4f36479137a9dadd13f00c1136f6c49b89ab586 100644 (file)
    Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
-/* FIXME: carlton/2002-09-24: because of namespace_enum, you have to
-   include symtab.h before including this file.  But I'm leaving in
-   opaque declarations as if that weren't true.  (Probably the
-   'namespace' argument to dict_lookup should eventually be moved back
-   into lookup_block_symbol, I think.)  */
-
 /* An opaque type for dictionaries; only dictionary.c should know
    about its innards.  */
 
@@ -37,7 +31,6 @@ struct dictionary;
 struct symbol;
 struct obstack;
 struct pending;
-struct block;
 
 
 /* The creation functions for various implementations of
@@ -73,33 +66,20 @@ extern struct dictionary *dict_create_linear (struct obstack *obstack,
 
 extern struct dictionary *dict_create_linear_expandable (void);
 
-#if 0
-
-/* Create a DICT_BLOCK dictionary pointing BLOCK.  */
-
-extern struct dictionary *
-dict_create_block (struct block *block);
-
-/* Create a DICT_BLOCK_EXPANDABLE dictionary pointing at BLOCK.  */
-
-extern struct dictionary *
-dict_create_block_expandable (struct block *block);
-
-#endif
-
 
 /* The functions providing the interface to dictionaries.  */
 
-/* Search DICT for symbol NAME in NAMESPACE.
+/* Search DICT for symbol whose SYMBOL_BEST_NAME is NAME, as tested
+   using strcmp_iw.  Returns NULL if there is no such symbol.  If
+   there might be multiple such symbols, use dict_iter_name_first and
+   dict_iter_name_next.  */
 
-   If MANGLED_NAME is non-NULL, verify that any symbol we find has this
-   particular mangled name.
-*/
+/* FIXME: carlton/2002-09-26: Given the presence of
+   dict_iter_name_first and dict_iter_name_next, should this function
+   go away?  Currently, it's never called.  */
 
 extern struct symbol *dict_lookup (const struct dictionary *dict,
-                                  const char *name,
-                                  const char *mangled_name,
-                                  const namespace_enum namespace);
+                                  const char *name);
 
 /* Free the memory used by a dictionary that's not on an obstack.  (If
    any.)  */
@@ -114,15 +94,6 @@ extern void dict_add_symbol (struct dictionary *dict, struct symbol *sym);
 
 extern int dict_empty (struct dictionary *dict);
 
-#if 0
-
-/* Special case.  */
-
-extern struct block *dict_add_symbol_block (struct dictionary *dict,
-                                           struct symbol *sym);
-
-#endif
-
 /* A type containing data that is used when iterating over all symbols
    in a dictionary.  */
 
@@ -157,6 +128,26 @@ extern struct symbol *dict_iterator_first (const struct dictionary *dict,
 
 extern struct symbol *dict_iterator_next (struct dict_iterator *iterator);
 
+/* Initialize ITERATOR to point at the first symbol in DICT whose
+   SYMBOL_BEST_NAME is NAME (as tested using strcmp_iw), and return
+   that first symbol, or NULL if there are no such symbols.  */
+
+extern struct symbol *dict_iter_name_first (const struct dictionary *dict,
+                                           const char *name,
+                                           struct dict_iterator *iterator);
+
+/* Advance ITERATOR to point at the next symbol in DICT whose
+   SYMBOL_BEST_NAME is NAME (as tested using strcmp_iw), or NULL if
+   there are no more such symbols.  Don't call this if you've
+   previously received NULL from dict_iterator_first or
+   dict_iterator_next on this iteration.  And don't call it unless
+   ITERATOR was created by a previous call to dict_iter_name_first
+   with the same NAME.  */
+
+extern struct symbol *dict_iter_name_next (const char *name,
+                                          struct dict_iterator *iterator);
+
+
 /* Macro to loop through all symbols in a dictionary DICT, in no
    particular order.  ITER is a struct dict_iterator (NOTE: __not__ a
    struct dict_iterator *), and SYM points to the current symbol.
index 1ca0b3b39ac20c1158ce14caedc5dfc50a6fc29e..d5ec8282453eb14ee7ff801d0d45241d28eb9cd1 100644 (file)
@@ -22,6 +22,7 @@
 #include "defs.h"
 
 #include "ns32k-tdep.h"
+#include "gdb_string.h"
 
 static int
 ns32knbsd_aout_in_solib_call_trampoline (CORE_ADDR pc, char *name)
index 19983397819a3870330194a04cb710f1173b9e63..7ad831ce38a8602dbd0aae550e3941938a9c4510 100644 (file)
@@ -1331,12 +1331,95 @@ find_main_psymtab (void)
    particular mangled name.
 */
 
+/* FIXME: carlton/2002-09-26: I've slightly changed the semantics: I
+   replaced a call to SYMBOL_MATCHES_NAME (sym, name) with a call to
+   strcmp_iw (SYMBOL_BEST_NAME (sym), name) (inside the dict_iter_name
+   functions).  I think this is okay: the only situations where the
+   new behavior should differ from the old behavior are where NAME is
+   mangled (which shouldn't happen, right??? lookup_symbol always
+   tries to demangle appropriately) or where the symbol we find
+   doesn't have a demangled name and where the symbol's name is such
+   that strcmp and strcmp_iw don't match on it (which seems unlikely
+   to me).  */
+
 struct symbol *
 lookup_block_symbol (register const struct block *block, const char *name,
                     const char *mangled_name,
                     const namespace_enum namespace)
 {
-  dict_lookup (BLOCK_DICT (block), name, mangled_name, namespace);
+  struct dict_iterator iter;
+  struct symbol *sym;
+
+  if (!BLOCK_FUNCTION (block))
+    {
+      for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter);
+          sym;
+          sym = dict_iter_name_next (name, &iter))
+       {
+         if (SYMBOL_NAMESPACE (sym) == namespace 
+             && (mangled_name
+                 ? strcmp (SYMBOL_NAME (sym), mangled_name) == 0
+                 : 1))
+           return sym;
+       }
+      return NULL;
+    }
+  else
+    {
+      /* Note that parameter symbols do not always show up last in the
+        list.  This loop makes sure to take anything else other than
+        parameter symbols first; it only uses parameter symbols as a
+        last resort.  Note that this only takes up extra computation
+        time on a match.  */
+      
+      struct symbol *sym_found = NULL;
+
+      for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter);
+          sym;
+          sym = dict_iter_name_next (name, &iter))
+       {
+         if (SYMBOL_NAMESPACE (sym) == namespace
+             && (mangled_name
+                 ? strcmp (SYMBOL_NAME (sym), mangled_name) == 0
+                 : 1))
+           {
+             /* If SYM has aliases, then use any alias that is active
+                at the current PC.  If no alias is active at the current
+                PC, then use the main symbol.
+
+                ?!? Is checking the current pc correct?  Is this routine
+                ever called to look up a symbol from another context?
+
+                FIXME: No, it's not correct.  If someone sets a
+                conditional breakpoint at an address, then the
+                breakpoint's `struct expression' should refer to the
+                `struct symbol' appropriate for the breakpoint's
+                address, which may not be the PC.
+
+                Even if it were never called from another context,
+                it's totally bizarre for lookup_symbol's behavior to
+                depend on the value of the inferior's current PC.  We
+                should pass in the appropriate PC as well as the
+                block.  The interface to lookup_symbol should change
+                to require the caller to provide a PC.  */
+
+             if (SYMBOL_ALIASES (sym))
+               sym = find_active_alias (sym, read_pc ());
+
+             sym_found = sym;
+             if (SYMBOL_CLASS (sym) != LOC_ARG &&
+                 SYMBOL_CLASS (sym) != LOC_LOCAL_ARG &&
+                 SYMBOL_CLASS (sym) != LOC_REF_ARG &&
+                 SYMBOL_CLASS (sym) != LOC_REGPARM &&
+                 SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR &&
+                 SYMBOL_CLASS (sym) != LOC_BASEREG_ARG)
+               {
+                 break;
+               }
+           }
+       }
+      return (sym_found);              /* Will be NULL if not found. */
+    }
 }
 
 /* Given a main symbol SYM and ADDR, search through the alias
index b9f4879c4b54ed3f555556ddf8ab5a1c966ae03a..4a5186761d24ecd84884b175c67fb8db9ecb58e7 100644 (file)
@@ -175,6 +175,20 @@ extern void symbol_init_demangled_name (struct general_symbol_info *symbol,
      /* OBSOLETE ? SYMBOL_CHILL_DEMANGLED_NAME (symbol) */             \
      NULL)
 
+/* Macro that returns the demangled name of the symbol if if possible
+   and the symbol name if not possible.  This is like
+   SYMBOL_SOURCE_NAME except that it doesn't depend on the value of
+   'demangle' (and is hence more suitable for internal usage).  The
+   result should never be NULL.  */
+
+/* FIXME: carlton/2002-09-26: Probably the situation with this and
+   SYMBOL_SOURCE_NAME should be rethought.  */
+
+#define SYMBOL_BEST_NAME(symbol)                                       \
+  (SYMBOL_DEMANGLED_NAME (symbol) != NULL                              \
+   ? SYMBOL_DEMANGLED_NAME (symbol)                                    \
+   : SYMBOL_NAME (symbol))
+
 /* OBSOLETE #define SYMBOL_CHILL_DEMANGLED_NAME(symbol) */
 /* OBSOLETE (symbol)->ginfo.language_specific.chill_specific.demangled_name */
 
@@ -183,10 +197,11 @@ extern void symbol_init_demangled_name (struct general_symbol_info *symbol,
    of the name if demangle is off.  In other languages this is just the
    symbol name.  The result should never be NULL. */
 
+/* NOTE: carlton/2002-09-26: For external use only; in many
+   situations, SYMBOL_BEST_NAME is more appropriate.  */
+
 #define SYMBOL_SOURCE_NAME(symbol)                                     \
-  (demangle && SYMBOL_DEMANGLED_NAME (symbol) != NULL                  \
-   ? SYMBOL_DEMANGLED_NAME (symbol)                                    \
-   : SYMBOL_NAME (symbol))
+  (demangle ? SYMBOL_BEST_NAME (symbol) : SYMBOL_NAME (symbol))
 
 /* Macro that returns the "natural assembly name" of a symbol.  In C++ this is
    the "mangled" form of the name if demangle is off, or if demangle is on and
@@ -195,8 +210,7 @@ extern void symbol_init_demangled_name (struct general_symbol_info *symbol,
    never be NULL. */
 
 #define SYMBOL_LINKAGE_NAME(symbol)                                    \
-  (demangle && asm_demangle && SYMBOL_DEMANGLED_NAME (symbol) != NULL  \
-   ? SYMBOL_DEMANGLED_NAME (symbol)                                    \
+  (demangle && asm_demangle ? SYMBOL_BEST_NAME (symbol)                        \
    : SYMBOL_NAME (symbol))
 
 /* Macro that tests a symbol for a match against a specified name string.
@@ -206,6 +220,12 @@ extern void symbol_init_demangled_name (struct general_symbol_info *symbol,
    "foo :: bar (int, long)".
    Evaluates to zero if the match fails, or nonzero if it succeeds. */
 
+/* FIXME: carlton/2002-09-26: Should these two be rewritten to always
+   match against SYMBOL_BEST_NAME (symbol) instead?  Or should there
+   be separate SYMBOL_BMATCHES_BEST_NAME and
+   SYMBOL_MATCHES_BEST_REGEXP macros?  I'm worried about false
+   positive matches against mangled names.  */
+
 #define SYMBOL_MATCHES_NAME(symbol, name)                              \
   (STREQ (SYMBOL_NAME (symbol), (name))                                        \
    || (SYMBOL_DEMANGLED_NAME (symbol) != NULL                          \