Approved by Jim Blandy:
[binutils-gdb.git] / gdb / minsyms.c
index 9070b6fee8ffc0f64cf37f296454ae9e902fc0dc..36d695acaab0c68ff25e8430f4eed25882ed38c9 100644 (file)
@@ -1,5 +1,6 @@
 /* GDB routines for manipulating the minimal symbol tables.
-   Copyright 1992, 93, 94, 96, 97, 1998 Free Software Foundation, Inc.
+   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+   Free Software Foundation, Inc.
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
    This file is part of GDB.
@@ -46,7 +47,8 @@
 #include "symfile.h"
 #include "objfiles.h"
 #include "demangle.h"
-#include "gdb-stabs.h"
+#include "value.h"
+#include "cp-abi.h"
 
 /* Accumulate the minimal symbols for each objfile in bunches of BUNCH_SIZE.
    At the end, copy them all into one newly allocated location on an objfile's
@@ -75,7 +77,7 @@ static int msym_count;
 
 /* Prototypes for local functions. */
 
-static int compare_minimal_symbols (const void *, const void *);
+static int compare_minimal_symbols (const PTR, const PTR);
 
 static int
 compact_minimal_symbols (struct minimal_symbol *, int, struct objfile *);
@@ -94,8 +96,10 @@ msymbol_hash_iw (const char *string)
       while (isspace (*string))
        ++string;
       if (*string && *string != '(')
-       hash = (31 * hash) + *string;
-      ++string;
+       {
+         hash = hash * 67 + *string - 113;
+         ++string;
+       }
     }
   return hash % MINIMAL_SYMBOL_HASH_SIZE;
 }
@@ -107,7 +111,7 @@ msymbol_hash (const char *string)
 {
   unsigned int hash = 0;
   for (; *string; ++string)
-    hash = (31 * hash) + *string;
+    hash = hash * 67 + *string - 113;
   return hash % MINIMAL_SYMBOL_HASH_SIZE;
 }
 
@@ -482,6 +486,10 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc, asection *section)
              /* This is the new code that distinguishes it from the old function */
              if (section)
                while (hi >= 0
+                      /* Some types of debug info, such as COFF,
+                         don't fill the bfd_section member, so don't
+                         throw away symbols on those platforms.  */
+                      && SYMBOL_BFD_SECTION (&msymbol[hi]) != NULL
                       && SYMBOL_BFD_SECTION (&msymbol[hi]) != section)
                  --hi;
 
@@ -539,14 +547,14 @@ find_stab_function_addr (char *namestring, char *filename,
     {
       /* Try again without the filename. */
       p[n] = 0;
-      msym = lookup_minimal_symbol (p, 0, objfile);
+      msym = lookup_minimal_symbol (p, NULL, objfile);
     }
   if (msym == NULL && filename != NULL)
     {
       /* And try again for Sun Fortran, but without the filename. */
       p[n] = '_';
       p[n + 1] = 0;
-      msym = lookup_minimal_symbol (p, 0, objfile);
+      msym = lookup_minimal_symbol (p, NULL, objfile);
     }
 
   return msym == NULL ? 0 : SYMBOL_VALUE_ADDRESS (msym);
@@ -952,9 +960,24 @@ install_minimal_symbols (struct objfile *objfile)
       objfile->minimal_symbol_count = mcount;
       objfile->msymbols = msymbols;
 
+      /* Try to guess the appropriate C++ ABI by looking at the names 
+        of the minimal symbols in the table.  */
+      {
+       int i;
+
+       for (i = 0; i < mcount; i++)
+         {
+           const char *name = SYMBOL_NAME (&objfile->msymbols[i]);
+           if (name[0] == '_' && name[1] == 'Z')
+             {
+               switch_to_cp_abi ("gnu-v3");
+               break;
+             }
+         }
+      }
+      
       /* Now walk through all the minimal symbols, selecting the newly added
          ones and attempting to cache their C++ demangled names. */
-
       for (; mcount-- > 0; msymbols++)
        SYMBOL_INIT_DEMANGLED_NAME (msymbols, &objfile->symbol_obstack);