Fix my last change to actually compile.
[deliverable/binutils-gdb.git] / gdb / minsyms.c
index a032dd35115cffafcd2ee08609b925cf55203005..94faccb014cb7321a72c60d0b2e3f1b382c3e50f 100644 (file)
@@ -75,12 +75,10 @@ static int msym_count;
 
 /* Prototypes for local functions. */
 
-static int
-compare_minimal_symbols PARAMS ((const void *, const void *));
+static int compare_minimal_symbols (const void *, const void *);
 
 static int
-compact_minimal_symbols PARAMS ((struct minimal_symbol *, int,
-                                struct objfile *));
+compact_minimal_symbols (struct minimal_symbol *, int, struct objfile *);
 
 static void add_minsym_to_demangled_hash_table (struct minimal_symbol *sym,
                                                struct minimal_symbol **table);
@@ -153,10 +151,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;
@@ -266,10 +262,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;
@@ -343,10 +337,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;
@@ -394,9 +386,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;
@@ -512,18 +502,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;
@@ -570,11 +557,10 @@ find_stab_function_addr (namestring, filename, objfile)
 /* Return leading symbol character for a BFD. If BFD is NULL,
    return the leading symbol character from the main objfile.  */
 
-static int get_symbol_leading_char PARAMS ((bfd *));
+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);
@@ -588,7 +574,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;
@@ -596,11 +582,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;
 
@@ -631,15 +615,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;
@@ -700,9 +680,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;
@@ -743,10 +721,8 @@ compare_minimal_symbols (fn1p, fn2p)
    obstack and then simply blow the obstack away when we are done with
    it.  Is it worth the extra trouble though? */
 
-/* ARGSUSED */
-void
-discard_minimal_symbols (foo)
-     int foo;
+static void
+do_discard_minimal_symbols_cleanup (void *arg)
 {
   register struct msym_bunch *next;
 
@@ -758,6 +734,13 @@ discard_minimal_symbols (foo)
     }
 }
 
+struct cleanup *
+make_cleanup_discard_minimal_symbols (void)
+{
+  return make_cleanup (do_discard_minimal_symbols_cleanup, 0);
+}
+
+
 
 /* Compact duplicate entries out of a minimal symbol table by walking
    through the table and compacting out entries with duplicate addresses
@@ -796,10 +779,8 @@ discard_minimal_symbols (foo)
    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;
@@ -820,11 +801,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;
@@ -832,6 +809,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
@@ -856,8 +865,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;
@@ -948,23 +956,24 @@ install_minimal_symbols (objfile)
          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.
@@ -972,8 +981,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);
 
@@ -993,8 +1001,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.027591 seconds and 4 git commands to generate.