* d10v-dis.c: Fix formatting.
[deliverable/binutils-gdb.git] / gdb / minsyms.c
index e6978e7909f9115a8efc9fcd8f2099033e4b42fa..94817474318624be4245081d0bd6bff27ed0734e 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 *);
@@ -151,10 +153,8 @@ add_minsym_to_demangled_hash_table (struct minimal_symbol *sym,
    names (the dynamic linker deals with the duplication). */
 
 struct minimal_symbol *
-lookup_minimal_symbol (name, sfile, objf)
-     register const char *name;
-     const char *sfile;
-     struct objfile *objf;
+lookup_minimal_symbol (register const char *name, const char *sfile,
+                      struct objfile *objf)
 {
   struct objfile *objfile;
   struct minimal_symbol *msymbol;
@@ -264,10 +264,8 @@ lookup_minimal_symbol (name, sfile, objf)
  */
 
 struct minimal_symbol *
-lookup_minimal_symbol_text (name, sfile, objf)
-     register const char *name;
-     const char *sfile;
-     struct objfile *objf;
+lookup_minimal_symbol_text (register const char *name, const char *sfile,
+                           struct objfile *objf)
 {
   struct objfile *objfile;
   struct minimal_symbol *msymbol;
@@ -341,10 +339,8 @@ lookup_minimal_symbol_text (name, sfile, objf)
  */
 
 struct minimal_symbol *
-lookup_minimal_symbol_solib_trampoline (name, sfile, objf)
-     register const char *name;
-     const char *sfile;
-     struct objfile *objf;
+lookup_minimal_symbol_solib_trampoline (register const char *name,
+                                       const char *sfile, struct objfile *objf)
 {
   struct objfile *objfile;
   struct minimal_symbol *msymbol;
@@ -392,9 +388,7 @@ lookup_minimal_symbol_solib_trampoline (name, sfile, objf)
    0x40000 and objfile B has .text at 0x234 and .data at 0x40048.  */
 
 struct minimal_symbol *
-lookup_minimal_symbol_by_pc_section (pc, section)
-     CORE_ADDR pc;
-     asection *section;
+lookup_minimal_symbol_by_pc_section (CORE_ADDR pc, asection *section)
 {
   int lo;
   int hi;
@@ -490,6 +484,10 @@ lookup_minimal_symbol_by_pc_section (pc, 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;
 
@@ -510,18 +508,15 @@ lookup_minimal_symbol_by_pc_section (pc, section)
    for a matching PC (no section given) */
 
 struct minimal_symbol *
-lookup_minimal_symbol_by_pc (pc)
-     CORE_ADDR pc;
+lookup_minimal_symbol_by_pc (CORE_ADDR pc)
 {
   return lookup_minimal_symbol_by_pc_section (pc, find_pc_mapped_section (pc));
 }
 
 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
 CORE_ADDR
-find_stab_function_addr (namestring, filename, objfile)
-     char *namestring;
-     char *filename;
-     struct objfile *objfile;
+find_stab_function_addr (char *namestring, char *filename,
+                        struct objfile *objfile)
 {
   struct minimal_symbol *msym;
   char *p;
@@ -571,8 +566,7 @@ find_stab_function_addr (namestring, filename, objfile)
 static int get_symbol_leading_char (bfd *);
 
 static int
-get_symbol_leading_char (abfd)
-     bfd *abfd;
+get_symbol_leading_char (bfd *abfd)
 {
   if (abfd != NULL)
     return bfd_get_symbol_leading_char (abfd);
@@ -586,7 +580,7 @@ get_symbol_leading_char (abfd)
    symbol to allocate the memory for the first bunch. */
 
 void
-init_minimal_symbol_collection ()
+init_minimal_symbol_collection (void)
 {
   msym_count = 0;
   msym_bunch = NULL;
@@ -594,11 +588,9 @@ init_minimal_symbol_collection ()
 }
 
 void
-prim_record_minimal_symbol (name, address, ms_type, objfile)
-     const char *name;
-     CORE_ADDR address;
-     enum minimal_symbol_type ms_type;
-     struct objfile *objfile;
+prim_record_minimal_symbol (const char *name, CORE_ADDR address,
+                           enum minimal_symbol_type ms_type,
+                           struct objfile *objfile)
 {
   int section;
 
@@ -629,15 +621,11 @@ prim_record_minimal_symbol (name, address, ms_type, objfile)
    newly created.  */
 
 struct minimal_symbol *
-prim_record_minimal_symbol_and_info (name, address, ms_type, info, section,
-                                    bfd_section, objfile)
-     const char *name;
-     CORE_ADDR address;
-     enum minimal_symbol_type ms_type;
-     char *info;
-     int section;
-     asection *bfd_section;
-     struct objfile *objfile;
+prim_record_minimal_symbol_and_info (const char *name, CORE_ADDR address,
+                                    enum minimal_symbol_type ms_type,
+                                    char *info, int section,
+                                    asection *bfd_section,
+                                    struct objfile *objfile)
 {
   register struct msym_bunch *new;
   register struct minimal_symbol *msymbol;
@@ -698,9 +686,7 @@ prim_record_minimal_symbol_and_info (name, address, ms_type, info, section,
    Within groups with the same address, sort by name.  */
 
 static int
-compare_minimal_symbols (fn1p, fn2p)
-     const PTR fn1p;
-     const PTR fn2p;
+compare_minimal_symbols (const PTR fn1p, const PTR fn2p)
 {
   register const struct minimal_symbol *fn1;
   register const struct minimal_symbol *fn2;
@@ -749,7 +735,7 @@ do_discard_minimal_symbols_cleanup (void *arg)
   while (msym_bunch != NULL)
     {
       next = msym_bunch->next;
-      free ((PTR) msym_bunch);
+      xfree (msym_bunch);
       msym_bunch = next;
     }
 }
@@ -799,10 +785,8 @@ make_cleanup_discard_minimal_symbols (void)
    overwrite its type with the type from the one we are compacting out.  */
 
 static int
-compact_minimal_symbols (msymbol, mcount, objfile)
-     struct minimal_symbol *msymbol;
-     int mcount;
-     struct objfile *objfile;
+compact_minimal_symbols (struct minimal_symbol *msymbol, int mcount,
+                        struct objfile *objfile)
 {
   struct minimal_symbol *copyfrom;
   struct minimal_symbol *copyto;
@@ -823,11 +807,7 @@ compact_minimal_symbols (msymbol, mcount, objfile)
              copyfrom++;
            }
          else
-           {
-             *copyto++ = *copyfrom++;
-
-             add_minsym_to_hash_table (copyto - 1, objfile->msymbol_hash);
-           }
+           *copyto++ = *copyfrom++;
        }
       *copyto++ = *copyfrom++;
       mcount = copyto - msymbol;
@@ -835,6 +815,38 @@ compact_minimal_symbols (msymbol, mcount, objfile)
   return (mcount);
 }
 
+/* Build (or rebuild) the minimal symbol hash tables.  This is necessary
+   after compacting or sorting the table since the entries move around
+   thus causing the internal minimal_symbol pointers to become jumbled. */
+  
+static void
+build_minimal_symbol_hash_tables (struct objfile *objfile)
+{
+  int i;
+  struct minimal_symbol *msym;
+
+  /* Clear the hash tables. */
+  for (i = 0; i < MINIMAL_SYMBOL_HASH_SIZE; i++)
+    {
+      objfile->msymbol_hash[i] = 0;
+      objfile->msymbol_demangled_hash[i] = 0;
+    }
+
+  /* Now, (re)insert the actual entries. */
+  for (i = objfile->minimal_symbol_count, msym = objfile->msymbols;
+       i > 0;
+       i--, msym++)
+    {
+      msym->hash_next = 0;
+      add_minsym_to_hash_table (msym, objfile->msymbol_hash);
+
+      msym->demangled_hash_next = 0;
+      if (SYMBOL_DEMANGLED_NAME (msym) != NULL)
+       add_minsym_to_demangled_hash_table (msym,
+                                            objfile->msymbol_demangled_hash);
+    }
+}
+
 /* Add the minimal symbols in the existing bunches to the objfile's official
    minimal symbol table.  In most cases there is no minimal symbol table yet
    for this objfile, and the existing bunches are used to create one.  Once
@@ -859,8 +871,7 @@ compact_minimal_symbols (msymbol, mcount, objfile)
    attempts to demangle them if we later add more minimal symbols. */
 
 void
-install_minimal_symbols (objfile)
-     struct objfile *objfile;
+install_minimal_symbols (struct objfile *objfile)
 {
   register int bindex;
   register int mcount;
@@ -947,27 +958,43 @@ install_minimal_symbols (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);
-         if (SYMBOL_DEMANGLED_NAME (msymbols) != NULL)
-          add_minsym_to_demangled_hash_table (msymbols,
-                                              objfile->msymbol_demangled_hash);
-       }
+       SYMBOL_INIT_DEMANGLED_NAME (msymbols, &objfile->symbol_obstack);
+
+      /* Now build the hash tables; we can't do this incrementally
+         at an earlier point since we weren't finished with the obstack
+        yet.  (And if the msymbol obstack gets moved, all the internal
+        pointers to other msymbols need to be adjusted.) */
+      build_minimal_symbol_hash_tables (objfile);
     }
 }
 
 /* Sort all the minimal symbols in OBJFILE.  */
 
 void
-msymbols_sort (objfile)
-     struct objfile *objfile;
+msymbols_sort (struct objfile *objfile)
 {
   qsort (objfile->msymbols, objfile->minimal_symbol_count,
         sizeof (struct minimal_symbol), compare_minimal_symbols);
+  build_minimal_symbol_hash_tables (objfile);
 }
 
 /* Check if PC is in a shared library trampoline code stub.
@@ -975,8 +1002,7 @@ msymbols_sort (objfile)
    in a trampoline code stub.  */
 
 struct minimal_symbol *
-lookup_solib_trampoline_symbol_by_pc (pc)
-     CORE_ADDR pc;
+lookup_solib_trampoline_symbol_by_pc (CORE_ADDR pc)
 {
   struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
 
@@ -996,8 +1022,7 @@ lookup_solib_trampoline_symbol_by_pc (pc)
    a duplicate function in case this matters someday.  */
 
 CORE_ADDR
-find_solib_trampoline_target (pc)
-     CORE_ADDR pc;
+find_solib_trampoline_target (CORE_ADDR pc)
 {
   struct objfile *objfile;
   struct minimal_symbol *msymbol;
This page took 0.02943 seconds and 4 git commands to generate.