gas/
[deliverable/binutils-gdb.git] / gdb / buildsym.c
index d86d58eeb1cccdef82214d3f4e19743ab50e1c97..ae7f90e976a7fd1ccb80eb1bca1e7c72f3ea0c58 100644 (file)
@@ -1,7 +1,5 @@
 /* Support routines for building symbol tables in GDB's internal format.
-   Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007, 2008, 2009,
-   2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1986-2004, 2007-2012 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -87,6 +85,10 @@ static int pending_addrmap_interesting;
 
 \f
 static int compare_line_numbers (const void *ln1p, const void *ln2p);
+
+static void record_pending_block (struct objfile *objfile,
+                                 struct block *block,
+                                 struct pending_block *opblock);
 \f
 
 /* Initial sizes of data structures.  These are realloc'd larger if
@@ -99,24 +101,7 @@ static int compare_line_numbers (const void *ln1p, const void *ln2p);
 
 /* Maintain the lists of symbols and blocks.  */
 
-/* Add a pending list to free_pendings.  */
-void
-add_free_pendings (struct pending *list)
-{
-  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.  While we're at it, if
-   we're in the C++ case and don't have full namespace debugging info,
-   check to see if it references an anonymous namespace; if so, add an
-   appropriate using directive.  */
+/* Add a symbol to one of the lists of symbols.  */
 
 void
 add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
@@ -156,7 +141,7 @@ struct symbol *
 find_symbol_in_list (struct pending *list, char *name, int length)
 {
   int j;
-  char *pp;
+  const char *pp;
 
   while (list != NULL)
     {
@@ -229,11 +214,12 @@ free_pending_blocks (void)
    the order the symbols have in the list (reversed from the input
    file).  Put the block on the list of pending blocks.  */
 
-struct block *
-finish_block (struct symbol *symbol, struct pending **listhead,
-             struct pending_block *old_blocks,
-             CORE_ADDR start, CORE_ADDR end,
-             struct objfile *objfile)
+static struct block *
+finish_block_internal (struct symbol *symbol, struct pending **listhead,
+                      struct pending_block *old_blocks,
+                      CORE_ADDR start, CORE_ADDR end,
+                      struct objfile *objfile,
+                      int is_global)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct pending *next, *next1;
@@ -241,7 +227,9 @@ finish_block (struct symbol *symbol, struct pending **listhead,
   struct pending_block *pblock;
   struct pending_block *opblock;
 
-  block = allocate_block (&objfile->objfile_obstack);
+  block = (is_global
+          ? allocate_global_block (&objfile->objfile_obstack)
+          : allocate_block (&objfile->objfile_obstack));
 
   if (symbol)
     {
@@ -256,9 +244,6 @@ finish_block (struct symbol *symbol, struct pending **listhead,
 
   BLOCK_START (block) = start;
   BLOCK_END (block) = end;
-  /* Superblock filled in when containing block is made.  */
-  BLOCK_SUPERBLOCK (block) = NULL;
-  BLOCK_NAMESPACE (block) = NULL;
 
   /* Put the block in as the value of the symbol that names it.  */
 
@@ -276,7 +261,10 @@ finish_block (struct symbol *symbol, struct pending **listhead,
             parameter symbols.  */
          int nparams = 0, iparams;
          struct symbol *sym;
-         ALL_BLOCK_SYMBOLS (block, iter, sym)
+
+         /* Here we want to directly access the dictionary, because
+            we haven't fully initialized the block yet.  */
+         ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
            {
              if (SYMBOL_IS_ARGUMENT (sym))
                nparams++;
@@ -288,7 +276,9 @@ finish_block (struct symbol *symbol, struct pending **listhead,
                TYPE_ALLOC (ftype, nparams * sizeof (struct field));
 
              iparams = 0;
-             ALL_BLOCK_SYMBOLS (block, iter, sym)
+             /* Here we want to directly access the dictionary, because
+                we haven't fully initialized the block yet.  */
+             ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
                {
                  if (iparams == nparams)
                    break;
@@ -326,13 +316,15 @@ finish_block (struct symbol *symbol, struct pending **listhead,
       if (symbol)
        {
          complaint (&symfile_complaints,
-                    _("block end address less than block start address in %s (patched it)"),
+                    _("block end address less than block "
+                      "start address in %s (patched it)"),
                     SYMBOL_PRINT_NAME (symbol));
        }
       else
        {
          complaint (&symfile_complaints,
-                    _("block end address %s less than block start address %s (patched it)"),
+                    _("block end address %s less than block "
+                      "start address %s (patched it)"),
                     paddress (gdbarch, BLOCK_END (block)),
                     paddress (gdbarch, BLOCK_START (block)));
        }
@@ -370,7 +362,8 @@ finish_block (struct symbol *symbol, struct pending **listhead,
              else
                {
                  complaint (&symfile_complaints,
-                            _("inner block (%s-%s) not inside outer block (%s-%s)"),
+                            _("inner block (%s-%s) not "
+                              "inside outer block (%s-%s)"),
                             paddress (gdbarch, BLOCK_START (pblock->block)),
                             paddress (gdbarch, BLOCK_END (pblock->block)),
                             paddress (gdbarch, BLOCK_START (block)),
@@ -394,6 +387,15 @@ finish_block (struct symbol *symbol, struct pending **listhead,
   return block;
 }
 
+struct block *
+finish_block (struct symbol *symbol, struct pending **listhead,
+             struct pending_block *old_blocks,
+             CORE_ADDR start, CORE_ADDR end,
+             struct objfile *objfile)
+{
+  return finish_block_internal (symbol, listhead, old_blocks,
+                               start, end, objfile, 0);
+}
 
 /* Record BLOCK on the list of all blocks in the file.  Put it after
    OPBLOCK, or at the beginning if opblock is NULL.  This puts the
@@ -402,7 +404,7 @@ finish_block (struct symbol *symbol, struct pending **listhead,
    Allocate the pending block struct in the objfile_obstack to save
    time.  This wastes a little space.  FIXME: Is it worth it?  */
 
-void
+static void
 record_pending_block (struct objfile *objfile, struct block *block,
                      struct pending_block *opblock)
 {
@@ -640,7 +642,7 @@ void
 patch_subfile_names (struct subfile *subfile, char *name)
 {
   if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
-      && subfile->name[strlen (subfile->name) - 1] == '/')
+      && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
     {
       subfile->dirname = subfile->name;
       subfile->name = xstrdup (name);
@@ -695,7 +697,8 @@ pop_subfile (void)
 
   if (link == NULL)
     {
-      internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
+      internal_error (__FILE__, __LINE__,
+                     _("failed internal consistency check"));
     }
   name = link->name;
   subfile_stack = link->next;
@@ -874,7 +877,7 @@ watch_main_source_file_lossage (void)
           subfile->next;
           subfile = subfile->next)
        {
-         if (strcmp (lbasename (subfile->name), mainbase) == 0)
+         if (filename_cmp (lbasename (subfile->name), mainbase) == 0)
            {
              ++nr_matches;
              mainsub_alias = subfile;
@@ -1023,8 +1026,8 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
          blockvector.  */
       finish_block (0, &file_symbols, 0, last_source_start_addr,
                    end_addr, objfile);
-      finish_block (0, &global_symbols, 0, last_source_start_addr,
-                   end_addr, objfile);
+      finish_block_internal (0, &global_symbols, 0, last_source_start_addr,
+                            end_addr, objfile, 1);
       blockvector = make_blockvector (objfile);
     }
 
@@ -1096,8 +1099,6 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
            {
              symtab->dirname = NULL;
            }
-         symtab->free_code = free_linetable;
-         symtab->free_func = NULL;
 
          /* Use whatever language we have been using for this
             subfile, not the one that was deduced in allocate_symtab
@@ -1108,18 +1109,10 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
          symtab->language = subfile->language;
 
          /* Save the debug format string (if any) in the symtab.  */
-         if (subfile->debugformat != NULL)
-           {
-             symtab->debugformat = obsavestring (subfile->debugformat,
-                                             strlen (subfile->debugformat),
-                                                 &objfile->objfile_obstack);
-           }
+         symtab->debugformat = subfile->debugformat;
 
          /* Similarly for the producer.  */
-         if (subfile->producer != NULL)
-           symtab->producer = obsavestring (subfile->producer,
-                                            strlen (subfile->producer),
-                                            &objfile->objfile_obstack);
+         symtab->producer = subfile->producer;
 
          /* All symtabs for the main file and the subfiles share a
             blockvector, so we need to clear primary for everything
@@ -1165,12 +1158,6 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
        {
          xfree ((void *) subfile->line_vector);
        }
-      if (subfile->debugformat != NULL)
-       {
-         xfree ((void *) subfile->debugformat);
-       }
-      if (subfile->producer != NULL)
-       xfree (subfile->producer);
 
       nextsub = subfile->next;
       xfree ((void *) subfile);
@@ -1180,6 +1167,14 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
   if (symtab)
     {
       symtab->primary = 1;
+
+      if (symtab->blockvector)
+       {
+         struct block *b = BLOCKVECTOR_BLOCK (symtab->blockvector,
+                                              GLOBAL_BLOCK);
+
+         set_block_symtab (b, symtab);
+       }
     }
 
   /* Default any symbols without a specified symtab to the primary
@@ -1200,9 +1195,9 @@ end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
            if (SYMBOL_SYMTAB (BLOCK_FUNCTION (block)) == NULL)
              SYMBOL_SYMTAB (BLOCK_FUNCTION (block)) = symtab;
 
-         for (sym = dict_iterator_first (BLOCK_DICT (block), &iter);
-              sym != NULL;
-              sym = dict_iterator_next (&iter))
+         /* Note that we only want to fix up symbols from the local
+            blocks, not blocks coming from included symtabs.  */
+         ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
            if (SYMBOL_SYMTAB (sym) == NULL)
              SYMBOL_SYMTAB (sym) = symtab;
        }
@@ -1268,27 +1263,22 @@ pop_context (void)
 /* Compute a small integer hash code for the given name.  */
 
 int
-hashname (char *name)
+hashname (const char *name)
 {
     return (hash(name,strlen(name)) % HASHSIZE);
 }
 \f
 
 void
-record_debugformat (char *format)
+record_debugformat (const char *format)
 {
-  current_subfile->debugformat = xstrdup (format);
+  current_subfile->debugformat = format;
 }
 
 void
 record_producer (const char *producer)
 {
-  /* The producer is not always provided in the debugging info.
-     Do nothing if PRODUCER is NULL.  */
-  if (producer == NULL)
-    return;
-
-  current_subfile->producer = xstrdup (producer);
+  current_subfile->producer = producer;
 }
 
 /* Merge the first symbol list SRCLIST into the second symbol list
This page took 0.03117 seconds and 4 git commands to generate.