* Makefile.am (libbfd.h): Add "Extracted from.." comment.
[deliverable/binutils-gdb.git] / gdb / buildsym.c
index 63888d70416884e91a42afd452c9846f6f391587..5078935fefebb98e2eb2615bb904857fb0bcae54 100644 (file)
@@ -1,21 +1,23 @@
 /* Support routines for building symbol tables in GDB's internal format.
-   Copyright 1986-1999 Free Software Foundation, Inc.
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
+   1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
-This file is part of GDB.
+   This file is part of GDB.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
 
 /* This module provides subroutines used for creating and adding to
    the symbol table.  These routines are called from various symbol-
@@ -33,9 +35,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "gdbtypes.h"
 #include "complaints.h"
 #include "gdb_string.h"
-
+#include "expression.h"                /* For "enum exp_opcode" used by... */
+#include "language.h"          /* For "local_hex_string" */
+#include "bcache.h"
+#include "filenames.h"         /* For DOSish file names */
+#include "macrotab.h"
 /* Ask buildsym.h to define the vars it normally declares `extern'.  */
-#define        EXTERN                  /**/
+#define        EXTERN
+/**/
 #include "buildsym.h"          /* Our own declarations */
 #undef EXTERN
 
@@ -53,8 +60,7 @@ static struct pending *free_pendings;
 
 static int have_line_numbers;
 \f
-static int
-compare_line_numbers PARAMS ((const void *, const void *));
+static int compare_line_numbers (const void *ln1p, const void *ln2p);
 \f
 
 /* Initial sizes of data structures.  These are realloc'd larger if
@@ -80,16 +86,28 @@ struct complaint innerblock_anon_complaint =
 {"inner block (0x%lx-0x%lx) not inside outer block (0x%lx-0x%lx)", 0, 0};
 
 struct complaint blockvector_complaint =
-{"block at 0x%lx out of order", 0, 0};
+{"block at %s out of order", 0, 0};
 \f
 /* maintain the lists of symbols and blocks */
 
+/* Add a pending list to free_pendings. */
+void
+add_free_pendings (struct pending *list)
+{
+  register struct pending *link = list;
+
+  if (list)
+    {
+      while (link->next) link = link->next;
+      link->next = free_pendings;
+      free_pendings = list;
+    }
+}
+      
 /* Add a symbol to one of the lists of symbols.  */
 
 void
-add_symbol_to_list (symbol, listhead)
-     struct symbol *symbol;
-     struct pending **listhead;
+add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
 {
   register struct pending *link;
 
@@ -123,10 +141,7 @@ add_symbol_to_list (symbol, listhead)
    '\0'-terminated; LENGTH is the length of the name.  */
 
 struct symbol *
-find_symbol_in_list (list, name, length)
-     struct pending *list;
-     char *name;
-     int length;
+find_symbol_in_list (struct pending *list, char *name, int length)
 {
   int j;
   char *pp;
@@ -152,15 +167,14 @@ find_symbol_in_list (list, name, length)
 
 /* ARGSUSED */
 void
-really_free_pendings (foo)
-     int foo;
+really_free_pendings (PTR dummy)
 {
   struct pending *next, *next1;
 
   for (next = free_pendings; next; next = next1)
     {
       next1 = next->next;
-      free ((PTR) next);
+      xfree ((void *) next);
     }
   free_pendings = NULL;
 
@@ -169,22 +183,25 @@ really_free_pendings (foo)
   for (next = file_symbols; next != NULL; next = next1)
     {
       next1 = next->next;
-      free ((PTR) next);
+      xfree ((void *) next);
     }
   file_symbols = NULL;
 
   for (next = global_symbols; next != NULL; next = next1)
     {
       next1 = next->next;
-      free ((PTR) next);
+      xfree ((void *) next);
     }
   global_symbols = NULL;
+
+  if (pending_macros)
+    free_macro_table (pending_macros);
 }
 
 /* This function is called to discard any pending blocks. */
 
 void
-free_pending_blocks ()
+free_pending_blocks (void)
 {
 #if 0                          /* Now we make the links in the
                                   symbol_obstack, so don't free
@@ -194,7 +211,7 @@ free_pending_blocks ()
   for (bnext = pending_blocks; bnext; bnext = bnext1)
     {
       bnext1 = bnext->next;
-      free ((PTR) bnext);
+      xfree ((void *) bnext);
     }
 #endif
   pending_blocks = NULL;
@@ -205,12 +222,10 @@ free_pending_blocks ()
    file).  Put the block on the list of pending blocks.  */
 
 void
-finish_block (symbol, listhead, old_blocks, start, end, objfile)
-     struct symbol *symbol;
-     struct pending **listhead;
-     struct pending_block *old_blocks;
-     CORE_ADDR start, end;
-     struct objfile *objfile;
+finish_block (struct symbol *symbol, struct pending **listhead,
+             struct pending_block *old_blocks,
+             CORE_ADDR start, CORE_ADDR end,
+             struct objfile *objfile)
 {
   register struct pending *next, *next1;
   register struct block *block;
@@ -229,7 +244,7 @@ finish_block (symbol, listhead, old_blocks, start, end, objfile)
     }
 
   block = (struct block *) obstack_alloc (&objfile->symbol_obstack,
-    (sizeof (struct block) + ((i - 1) * sizeof (struct symbol *))));
+           (sizeof (struct block) + ((i - 1) * sizeof (struct symbol *))));
 
   /* Copy the symbols into the block.  */
 
@@ -264,9 +279,8 @@ finish_block (symbol, listhead, old_blocks, start, end, objfile)
             parameter symbols. */
          int nparams = 0, iparams;
          struct symbol *sym;
-         for (i = 0; i < BLOCK_NSYMS (block); i++)
+         ALL_BLOCK_SYMBOLS (block, i, sym)
            {
-             sym = BLOCK_SYM (block, i);
              switch (SYMBOL_CLASS (sym))
                {
                case LOC_ARG:
@@ -312,6 +326,7 @@ finish_block (symbol, listhead, old_blocks, start, end, objfile)
                    case LOC_BASEREG_ARG:
                    case LOC_LOCAL_ARG:
                      TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
+                     TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
                      iparams++;
                      break;
                    case LOC_UNDEF:
@@ -391,7 +406,7 @@ finish_block (symbol, listhead, old_blocks, start, end, objfile)
              else
                {
                  complain (&innerblock_anon_complaint, BLOCK_START (pblock->block),
-                    BLOCK_END (pblock->block), BLOCK_START (block),
+                           BLOCK_END (pblock->block), BLOCK_START (block),
                            BLOCK_END (block));
                }
              if (BLOCK_START (pblock->block) < BLOCK_START (block))
@@ -416,10 +431,8 @@ finish_block (symbol, listhead, old_blocks, start, end, objfile)
    time.  This wastes a little space.  FIXME: Is it worth it?  */
 
 void
-record_pending_block (objfile, block, opblock)
-     struct objfile *objfile;
-     struct block *block;
-     struct pending_block *opblock;
+record_pending_block (struct objfile *objfile, struct block *block,
+                     struct pending_block *opblock)
 {
   register struct pending_block *pblock;
 
@@ -443,8 +456,7 @@ record_pending_block (objfile, block, opblock)
    that is done, it can be made static again. */
 
 struct blockvector *
-make_blockvector (objfile)
-     struct objfile *objfile;
+make_blockvector (struct objfile *objfile)
 {
   register struct pending_block *next;
   register struct blockvector *blockvector;
@@ -480,7 +492,7 @@ make_blockvector (objfile)
   for (next = pending_blocks; next; next = next1)
     {
       next1 = next->next;
-      free (next);
+      xfree (next);
     }
 #endif
   pending_blocks = NULL;
@@ -497,17 +509,11 @@ make_blockvector (objfile)
          if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i - 1))
              > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)))
            {
-
-             /* FIXME-32x64: loses if CORE_ADDR doesn't fit in a
-                long.  Possible solutions include a version of
-                complain which takes a callback, a
-                sprintf_address_numeric to match
-                print_address_numeric, or a way to set up a GDB_FILE
-                which causes sprintf rather than fprintf to be
-                called.  */
+             CORE_ADDR start
+               = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i));
 
              complain (&blockvector_complaint,
-                       (unsigned long) BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)));
+                       local_hex_string ((LONGEST) start));
            }
        }
     }
@@ -522,9 +528,7 @@ make_blockvector (objfile)
    the directory in which it resides (or NULL if not known).  */
 
 void
-start_subfile (name, dirname)
-     char *name;
-     char *dirname;
+start_subfile (char *name, char *dirname)
 {
   register struct subfile *subfile;
 
@@ -533,7 +537,7 @@ start_subfile (name, dirname)
 
   for (subfile = subfiles; subfile; subfile = subfile->next)
     {
-      if (STREQ (subfile->name, name))
+      if (FILENAME_CMP (subfile->name, name) == 0)
        {
          current_subfile = subfile;
          return;
@@ -545,6 +549,7 @@ start_subfile (name, dirname)
      source file.  */
 
   subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
+  memset ((char *) subfile, 0, sizeof (struct subfile));
   subfile->next = subfiles;
   subfiles = subfile;
   current_subfile = subfile;
@@ -583,7 +588,7 @@ start_subfile (name, dirname)
      program.  But to demangle we need to set the language to C++.  We
      can distinguish cfront code by the fact that it has #line
      directives which specify a file name ending in .C.
-  
+
      So if the filename of this subfile ends in .C, then change the
      language of any pending subfiles from C to C++.  We also accept
      any other C++ suffixes accepted by deduce_language_from_filename
@@ -624,9 +629,7 @@ start_subfile (name, dirname)
    directory name actually is (by checking for a trailing '/'). */
 
 void
-patch_subfile_names (subfile, name)
-     struct subfile *subfile;
-     char *name;
+patch_subfile_names (struct subfile *subfile, char *name)
 {
   if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
       && subfile->name[strlen (subfile->name) - 1] == '/')
@@ -661,7 +664,7 @@ patch_subfile_names (subfile, name)
    order.  */
 
 void
-push_subfile ()
+push_subfile (void)
 {
   register struct subfile_stack *tem
   = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
@@ -670,24 +673,24 @@ push_subfile ()
   subfile_stack = tem;
   if (current_subfile == NULL || current_subfile->name == NULL)
     {
-      abort ();
+      internal_error (__FILE__, __LINE__, "failed internal consistency check");
     }
   tem->name = current_subfile->name;
 }
 
 char *
-pop_subfile ()
+pop_subfile (void)
 {
   register char *name;
   register struct subfile_stack *link = subfile_stack;
 
   if (link == NULL)
     {
-      abort ();
+      internal_error (__FILE__, __LINE__, "failed internal consistency check");
     }
   name = link->name;
   subfile_stack = link->next;
-  free ((PTR) link);
+  xfree ((void *) link);
   return (name);
 }
 \f
@@ -695,10 +698,7 @@ pop_subfile ()
    line vector for SUBFILE.  */
 
 void
-record_line (subfile, line, pc)
-     register struct subfile *subfile;
-     int line;
-     CORE_ADDR pc;
+record_line (register struct subfile *subfile, int line, CORE_ADDR pc)
 {
   struct linetable_entry *e;
   /* Ignore the dummy line number in libg.o */
@@ -714,7 +714,7 @@ record_line (subfile, line, pc)
       subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
       subfile->line_vector = (struct linetable *)
        xmalloc (sizeof (struct linetable)
-                + subfile->line_vector_length * sizeof (struct linetable_entry));
+          + subfile->line_vector_length * sizeof (struct linetable_entry));
       subfile->line_vector->nitems = 0;
       have_line_numbers = 1;
     }
@@ -731,15 +731,13 @@ record_line (subfile, line, pc)
 
   e = subfile->line_vector->item + subfile->line_vector->nitems++;
   e->line = line;
-  e->pc = pc;
+  e->pc = ADDR_BITS_REMOVE(pc);
 }
 
 /* Needed in order to sort line tables from IBM xcoff files.  Sigh!  */
 
 static int
-compare_line_numbers (ln1p, ln2p)
-     const void *ln1p;
-     const void *ln2p;
+compare_line_numbers (const void *ln1p, const void *ln2p)
 {
   struct linetable_entry *ln1 = (struct linetable_entry *) ln1p;
   struct linetable_entry *ln2 = (struct linetable_entry *) ln2p;
@@ -763,10 +761,7 @@ compare_line_numbers (ln1p, ln2p)
    one original source file.  */
 
 void
-start_symtab (name, dirname, start_addr)
-     char *name;
-     char *dirname;
-     CORE_ADDR start_addr;
+start_symtab (char *name, char *dirname, CORE_ADDR start_addr)
 {
 
   last_source_file = name;
@@ -812,10 +807,7 @@ start_symtab (name, dirname, start_addr)
    never know about this empty file (FIXME). */
 
 struct symtab *
-end_symtab (end_addr, objfile, section)
-     CORE_ADDR end_addr;
-     struct objfile *objfile;
-     int section;
+end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
 {
   register struct symtab *symtab = NULL;
   register struct blockvector *blockvector;
@@ -882,7 +874,7 @@ end_symtab (end_addr, objfile, section)
   /* Cleanup any undefined types that have been left hanging around
      (this needs to be done before the finish_blocks so that
      file_symbols is still good).
-  
+
      Both cleanup_undefined_types and finish_global_stabs are stabs
      specific, but harmless for other symbol readers, since on gdb
      startup or when finished reading stabs, the state is set so these
@@ -895,7 +887,8 @@ end_symtab (end_addr, objfile, section)
   if (pending_blocks == NULL
       && file_symbols == NULL
       && global_symbols == NULL
-      && have_line_numbers == 0)
+      && have_line_numbers == 0
+      && pending_macros == NULL)
     {
       /* Ignore symtabs that have no functions with real debugging
          info.  */
@@ -948,7 +941,7 @@ end_symtab (end_addr, objfile, section)
              if (objfile->flags & OBJF_REORDERED)
                qsort (subfile->line_vector->item,
                       subfile->line_vector->nitems,
-                      sizeof (struct linetable_entry), compare_line_numbers);
+                    sizeof (struct linetable_entry), compare_line_numbers);
            }
 
          /* Now, allocate a symbol table.  */
@@ -956,6 +949,7 @@ end_symtab (end_addr, objfile, section)
 
          /* Fill in its components.  */
          symtab->blockvector = blockvector;
+          symtab->macro_table = pending_macros;
          if (subfile->line_vector)
            {
              /* Reallocate the line table on the symbol obstack */
@@ -995,8 +989,8 @@ end_symtab (end_addr, objfile, section)
          if (subfile->debugformat != NULL)
            {
              symtab->debugformat = obsavestring (subfile->debugformat,
-                                     strlen (subfile->debugformat),
-                                         &objfile->symbol_obstack);
+                                             strlen (subfile->debugformat),
+                                                 &objfile->symbol_obstack);
            }
 
          /* All symtabs for the main file and the subfiles share a
@@ -1007,23 +1001,23 @@ end_symtab (end_addr, objfile, section)
        }
       if (subfile->name != NULL)
        {
-         free ((PTR) subfile->name);
+         xfree ((void *) subfile->name);
        }
       if (subfile->dirname != NULL)
        {
-         free ((PTR) subfile->dirname);
+         xfree ((void *) subfile->dirname);
        }
       if (subfile->line_vector != NULL)
        {
-         free ((PTR) subfile->line_vector);
+         xfree ((void *) subfile->line_vector);
        }
       if (subfile->debugformat != NULL)
        {
-         free ((PTR) subfile->debugformat);
+         xfree ((void *) subfile->debugformat);
        }
 
       nextsub = subfile->next;
-      free ((PTR) subfile);
+      xfree ((void *) subfile);
     }
 
   /* Set this for the main source file.  */
@@ -1034,6 +1028,7 @@ end_symtab (end_addr, objfile, section)
 
   last_source_file = NULL;
   current_subfile = NULL;
+  pending_macros = NULL;
 
   return symtab;
 }
@@ -1043,9 +1038,7 @@ end_symtab (end_addr, objfile, section)
    context.  */
 
 struct context_stack *
-push_context (desc, valu)
-     int desc;
-     CORE_ADDR valu;
+push_context (int desc, CORE_ADDR valu)
 {
   register struct context_stack *new;
 
@@ -1054,7 +1047,7 @@ push_context (desc, valu)
       context_stack_size *= 2;
       context_stack = (struct context_stack *)
        xrealloc ((char *) context_stack,
-             (context_stack_size * sizeof (struct context_stack)));
+                 (context_stack_size * sizeof (struct context_stack)));
     }
 
   new = &context_stack[context_stack_depth++];
@@ -1071,40 +1064,18 @@ push_context (desc, valu)
   return new;
 }
 \f
+
 /* Compute a small integer hash code for the given name. */
 
 int
-hashname (name)
-     char *name;
+hashname (char *name)
 {
-  register char *p = name;
-  register int total = p[0];
-  register int c;
-
-  c = p[1];
-  total += c << 2;
-  if (c)
-    {
-      c = p[2];
-      total += c << 4;
-      if (c)
-       {
-         total += p[3] << 6;
-       }
-    }
-
-  /* Ensure result is positive.  */
-  if (total < 0)
-    {
-      total += (1000 << 6);
-    }
-  return (total % HASHSIZE);
+    return (hash(name,strlen(name)) % HASHSIZE);
 }
 \f
 
 void
-record_debugformat (format)
-     char *format;
+record_debugformat (char *format)
 {
   current_subfile->debugformat = savestring (format, strlen (format));
 }
@@ -1118,9 +1089,7 @@ record_debugformat (format)
    Void return. */
 
 void
-merge_symbol_lists (srclist, targetlist)
-     struct pending **srclist;
-     struct pending **targetlist;
+merge_symbol_lists (struct pending **srclist, struct pending **targetlist)
 {
   register int i;
 
@@ -1144,12 +1113,13 @@ merge_symbol_lists (srclist, targetlist)
    corresponding to a psymtab.  */
 
 void
-buildsym_init ()
+buildsym_init (void)
 {
   free_pendings = NULL;
   file_symbols = NULL;
   global_symbols = NULL;
   pending_blocks = NULL;
+  pending_macros = NULL;
 }
 
 /* Initialize anything that needs initializing when a completely new
@@ -1157,7 +1127,7 @@ buildsym_init ()
    file, e.g. a shared library).  */
 
 void
-buildsym_new_init ()
+buildsym_new_init (void)
 {
   buildsym_init ();
 }
This page took 0.033213 seconds and 4 git commands to generate.