Sat Nov 7 18:30:20 1998 Peter Schauer <peter.schauer@regent.e-technik.tu-muenchen.de>
[deliverable/binutils-gdb.git] / gdb / buildsym.c
index e28c727f39c8f9b22f9e8ca843904dc33ddeef63..0ebebdb149c723bf4438cfe631eba6f9601eb90e 100644 (file)
@@ -44,17 +44,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    questionable--see comment where we call them).  */
 #include "stabsread.h"
 
-/* Pointer to the head of a linked list of symbol blocks which have
-   already been finalized (lexical contexts already closed) and which are
-   just waiting to be built into a blockvector when finalizing the
-   associated symtab. */
-
-static struct pending_block *pending_blocks = NULL;
-
 /* List of free `struct pending' structures for reuse.  */
 
 static struct pending *free_pendings;
 
+/* Non-zero if symtab has line number info.  This prevents an otherwise empty
+   symtab from being tossed.  */
+
+static int have_line_numbers;
 \f
 static int
 compare_line_numbers PARAMS ((const void *, const void *));
@@ -95,6 +92,10 @@ add_symbol_to_list (symbol, listhead)
      struct pending **listhead;
 {
   register struct pending *link;
+
+  /* If this is an alias for another symbol, don't add it.  */
+  if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
+    return;
       
   /* We keep PENDINGSIZE symbols in each link of the list.
      If we don't have a link with room in it, add a new link.  */
@@ -268,6 +269,8 @@ finish_block (symbol, listhead, old_blocks, start, end, objfile)
                case LOC_REF_ARG:
                case LOC_REGPARM:
                case LOC_REGPARM_ADDR:
+               case LOC_BASEREG_ARG:
+               case LOC_LOCAL_ARG:
                  nparams++;
                  break;
                case LOC_UNDEF:
@@ -279,9 +282,7 @@ finish_block (symbol, listhead, old_blocks, start, end, objfile)
                case LOC_LABEL:
                case LOC_BLOCK:
                case LOC_CONST_BYTES:
-               case LOC_LOCAL_ARG:
                case LOC_BASEREG:
-               case LOC_BASEREG_ARG:
                case LOC_UNRESOLVED:
                case LOC_OPTIMIZED_OUT:
                default:
@@ -303,6 +304,8 @@ finish_block (symbol, listhead, old_blocks, start, end, objfile)
                    case LOC_REF_ARG:
                    case LOC_REGPARM:
                    case LOC_REGPARM_ADDR:
+                   case LOC_BASEREG_ARG:
+                   case LOC_LOCAL_ARG:
                      TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
                      iparams++;
                      break;
@@ -315,9 +318,7 @@ finish_block (symbol, listhead, old_blocks, start, end, objfile)
                    case LOC_LABEL:
                    case LOC_BLOCK:
                    case LOC_CONST_BYTES:
-                   case LOC_LOCAL_ARG:
                    case LOC_BASEREG:
-                   case LOC_BASEREG_ARG:
                    case LOC_UNRESOLVED:
                    case LOC_OPTIMIZED_OUT:
                    default:
@@ -388,8 +389,10 @@ finish_block (symbol, listhead, old_blocks, start, end, objfile)
                            BLOCK_END (pblock->block), BLOCK_START (block),
                            BLOCK_END (block));
                }
-             BLOCK_START (pblock->block) = BLOCK_START (block);
-             BLOCK_END   (pblock->block) = BLOCK_END   (block);
+             if (BLOCK_START (pblock->block) < BLOCK_START (block))
+               BLOCK_START (pblock->block) = BLOCK_START (block);
+             if (BLOCK_END (pblock->block) > BLOCK_END (block))
+               BLOCK_END (pblock->block) = BLOCK_END (block);
            }
 #endif
          BLOCK_SUPERBLOCK (pblock->block) = block;
@@ -564,6 +567,10 @@ start_subfile (name, dirname)
       subfile->language = subfile->next->language;
     }
 
+  /* Initialize the debug format string to NULL.  We may supply it
+     later via a call to record_debugformat. */
+  subfile->debugformat = NULL;
+
   /* cfront output is a C program, so in most ways it looks like a C
      program.  But to demangle we need to set the language to C++.  We
      can distinguish cfront code by the fact that it has #line
@@ -703,6 +710,7 @@ record_line (subfile, line, pc)
        xmalloc (sizeof (struct linetable)
          + subfile->line_vector_length * sizeof (struct linetable_entry));
       subfile->line_vector->nitems = 0;
+      have_line_numbers = 1;
     }
 
   if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
@@ -759,6 +767,7 @@ start_symtab (name, dirname, start_addr)
   file_symbols = NULL;
   global_symbols = NULL;
   within_function = 0;
+  have_line_numbers = 0;
 
   /* Context stack is initially empty.  Allocate first one with room for
      10 levels; reuse it forever afterward.  */
@@ -811,8 +820,7 @@ end_symtab (end_addr, objfile, section)
 
   if (context_stack_depth > 0)
     {
-      context_stack_depth--;
-      cstk = &context_stack[context_stack_depth];
+      cstk = pop_context();
       /* Make a block for the local symbols within.  */
       finish_block (cstk->name, &local_symbols, cstk->old_blocks,
                    cstk->start_addr, end_addr, objfile);
@@ -834,8 +842,7 @@ end_symtab (end_addr, objfile, section)
      OBJF_REORDERED is true, then sort the pending blocks.  */
   if ((objfile->flags & OBJF_REORDERED) && pending_blocks)
     {
-      /* FIXME!  Remove this horrid bubble sort and use qsort!!!
-        It'd be a whole lot easier if they weren't in a linked list!!! */
+      /* FIXME!  Remove this horrid bubble sort and use merge sort!!! */
       int swapped;
       do
        {
@@ -877,7 +884,8 @@ end_symtab (end_addr, objfile, section)
 
   if (pending_blocks == NULL
       && file_symbols == NULL
-      && global_symbols == NULL)
+      && global_symbols == NULL
+      && have_line_numbers == 0)
     {
       /* Ignore symtabs that have no functions with real debugging info */
       blockvector = NULL;
@@ -968,6 +976,14 @@ end_symtab (end_addr, objfile, section)
             language it is from things we found in the symbols. */
          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 -> symbol_obstack);
+           }
+
          /* All symtabs for the main file and the subfiles share a
             blockvector, so we need to clear primary for everything but
             the main file.  */
@@ -986,6 +1002,10 @@ end_symtab (end_addr, objfile, section)
        {
          free ((PTR) subfile->line_vector);
        }
+      if (subfile->debugformat != NULL)
+       {
+         free ((PTR) subfile->debugformat);
+       }
 
       nextsub = subfile->next;
       free ((PTR)subfile);
@@ -1065,6 +1085,14 @@ hashname (name)
   return (total % HASHSIZE);
 }
 
+\f
+void
+record_debugformat (format)
+     char *format;
+{
+  current_subfile -> debugformat = savestring (format, strlen (format));
+}
+
 \f
 /* Initialize anything that needs initializing when starting to read
    a fresh piece of a symbol file, e.g. reading in the stuff corresponding
This page took 0.025156 seconds and 4 git commands to generate.