Just some cleanups noticed while working on PR 10760
authorFred Fish <fnf@specifix.com>
Tue, 8 Oct 1996 19:00:38 +0000 (19:00 +0000)
committerFred Fish <fnf@specifix.com>
Tue, 8 Oct 1996 19:00:38 +0000 (19:00 +0000)
* dbxread.c (dbx_symfile_read): Call free_pending_blocks rather
than poking global variable (which is now static).
* hpread.c (hpread_build_psymtabs): Ditto.
* os9kread.c (os9k_symfile_read): Ditto.
* xcoffread.c (xcoff_initial_scan): Ditto.

* buildsym.h (free_pending_blocks): Declare here.
(pending_blocks): Remove declaration of global symbol.
(free_pendings): Remove declaration of global symbol.
(make_blockvector): Declare here.
(record_pending_block): Declare here.

* dstread.c (make_blockvector): Remove static copy that was old
clone of version in buildsym.c.
(process_dst_block): Call record_pending_block rather than doing
it by hand.
(read_dst_symtab): Ditto.

* buildsym.c (make_blockvector): Make global rather than static,
(record_pending_block): New function, code moved from finish_block.
(finish_block): Use record_pending_block.
(free_pending_blocks): New function.
(really_free_pendings): Call free_pending_blocks.
(pending_blocks): Make static instead of global.
(free_pendings): Make static instead of global.

gdb/ChangeLog
gdb/buildsym.c
gdb/buildsym.h
gdb/dbxread.c
gdb/dstread.c
gdb/hpread.c
gdb/os9kread.c
gdb/xcoffread.c

index 46dc55991a7e7b2e63222568c7541650efa7dc3a..06b05c5221ab516f074eada6aeb98a92a4f59609 100644 (file)
@@ -1,3 +1,31 @@
+Tue Oct  8 11:47:13 1996  Fred Fish  <fnf@cygnus.com>
+
+       * dbxread.c (dbx_symfile_read): Call free_pending_blocks rather
+       than poking global variable (which is now static).
+       * hpread.c (hpread_build_psymtabs): Ditto.
+       * os9kread.c (os9k_symfile_read): Ditto.
+       * xcoffread.c (xcoff_initial_scan): Ditto.
+
+       * buildsym.h (free_pending_blocks): Declare here.
+       (pending_blocks): Remove declaration of global symbol.
+       (free_pendings): Remove declaration of global symbol.
+       (make_blockvector): Declare here.
+       (record_pending_block): Declare here.
+       
+       * dstread.c (make_blockvector): Remove static copy that was old
+       clone of version in buildsym.c.
+       (process_dst_block): Call record_pending_block rather than doing
+       it by hand.
+       (read_dst_symtab): Ditto.
+
+       * buildsym.c (make_blockvector): Make global rather than static,
+       (record_pending_block): New function, code moved from finish_block.
+       (finish_block): Use record_pending_block.
+       (free_pending_blocks): New function.
+       (really_free_pendings): Call free_pending_blocks.
+       (pending_blocks): Make static instead of global.
+       (free_pendings): Make static instead of global.
+       
 Tue Oct  8 09:03:22 1996  Stu Grossman  (grossman@critters.cygnus.com)
 
        * config/i386/windows.mh config/i386/xm-windows.h::  New config
index 1605ee5dcd1527ef3f136dfdace130eea33c53db..e28c727f39c8f9b22f9e8ca843904dc33ddeef63 100644 (file)
@@ -44,12 +44,21 @@ 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;
+
+\f
 static int
 compare_line_numbers PARAMS ((const void *, const void *));
 
-static struct blockvector *
-make_blockvector PARAMS ((struct objfile *));
-
 \f
 /* Initial sizes of data structures.  These are realloc'd larger if needed,
    and realloc'd down to the size actually used, when completed.  */
@@ -146,9 +155,6 @@ really_free_pendings (foo)
      int foo;
 {
   struct pending *next, *next1;
-#if 0
-  struct pending_block *bnext, *bnext1;
-#endif
 
   for (next = free_pendings; next; next = next1)
     {
@@ -157,14 +163,7 @@ really_free_pendings (foo)
     }
   free_pendings = NULL;
 
-#if 0 /* Now we make the links in the symbol_obstack, so don't free them.  */
-  for (bnext = pending_blocks; bnext; bnext = bnext1)
-    {
-      bnext1 = bnext->next;
-      free ((PTR)bnext);
-    }
-#endif
-  pending_blocks = NULL;
+  free_pending_blocks ();
 
   for (next = file_symbols; next != NULL; next = next1)
     {
@@ -181,6 +180,23 @@ really_free_pendings (foo)
   global_symbols = NULL;
 }
 
+/* This function is called to discard any pending blocks. */
+
+void
+free_pending_blocks ()
+{
+#if 0 /* Now we make the links in the symbol_obstack, so don't free them.  */
+  struct pending_block *bnext, *bnext1;
+
+  for (bnext = pending_blocks; bnext; bnext = bnext1)
+    {
+      bnext1 = bnext->next;
+      free ((PTR)bnext);
+    }
+#endif
+  pending_blocks = NULL;
+}
+
 /* Take one of the lists of symbols and make a block from it.
    Keep the order the symbols have in the list (reversed from the input file).
    Put the block on the list of pending blocks.  */
@@ -381,29 +397,44 @@ finish_block (symbol, listhead, old_blocks, start, end, objfile)
       opblock = pblock;
     }
 
-  /* Record this block on the list of all blocks in the file.
-     Put it after opblock, or at the beginning if opblock is 0.
-     This puts the block in the list after all its subblocks.  */
+  record_pending_block (objfile, block, opblock);
+}
+
+/* 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 block
+   in the list after all its subblocks.
+
+   Allocate the pending block struct in the symbol_obstack to save
+   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;
+{
+  register struct pending_block *pblock;
 
-  /* Allocate in the symbol_obstack to save time.
-     It wastes a little space.  */
   pblock = (struct pending_block *)
-    obstack_alloc (&objfile -> symbol_obstack,
-                  sizeof (struct pending_block));
-  pblock->block = block;
+    obstack_alloc (&objfile -> symbol_obstack, sizeof (struct pending_block));
+  pblock -> block = block;
   if (opblock)
     {
-      pblock->next = opblock->next;
-      opblock->next = pblock;
+      pblock -> next = opblock -> next;
+      opblock -> next = pblock;
     }
   else
     {
-      pblock->next = pending_blocks;
+      pblock -> next = pending_blocks;
       pending_blocks = pblock;
     }
 }
 
-static struct blockvector *
+/* Note that this is only used in this file and in dstread.c, which should be
+   fixed to not need direct access to this function.  When that is done, it can
+   be made static again. */
+
+struct blockvector *
 make_blockvector (objfile)
      struct objfile *objfile;
 {
index 58529c709b3d13446b15d70cf744388b13e9e56b..b50f9d8a9cc9d4f963270da2c1bedbe307e42f0d 100644 (file)
@@ -96,10 +96,6 @@ struct pending
   struct symbol *symbol[PENDINGSIZE];
 };
 
-/* List of free `struct pending' structures for reuse.  */
-
-EXTERN struct pending *free_pendings;
-
 /* Here are the three lists that symbols are put on.  */
 
 EXTERN struct pending *file_symbols;   /* static at top level, and types */
@@ -169,8 +165,6 @@ struct pending_block
   struct block *block;
 };
 
-EXTERN struct pending_block *pending_blocks;
-
 \f
 struct subfile_stack
 {
@@ -254,6 +248,22 @@ start_symtab PARAMS ((char *, char *, CORE_ADDR));
 extern int
 hashname PARAMS ((char *));
 
+extern void
+free_pending_blocks PARAMS ((void));
+
+/* FIXME: Note that this is used only in buildsym.c and dstread.c,
+   which should be fixed to not need direct access to make_blockvector. */
+
+extern struct blockvector *
+make_blockvector PARAMS ((struct objfile *));
+
+/* FIXME: Note that this is used only in buildsym.c and dstread.c,
+   which should be fixed to not need direct access to record_pending_block. */
+
+extern void
+record_pending_block PARAMS ((struct objfile *, struct block *,
+                             struct pending_block *));
+
 #undef EXTERN
 
 #endif /* defined (BUILDSYM_H) */
index 35884bb8cf3d196737e60334e1c0368b3d0543b4..38c8b4eefc992af0eaa81e716cb8454d1ed16e27 100644 (file)
@@ -546,7 +546,7 @@ dbx_symfile_read (objfile, section_offsets, mainline)
   symbol_size = DBX_SYMBOL_SIZE (objfile);
   symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);
 
-  pending_blocks = 0;
+  free_pending_blocks ();
   back_to = make_cleanup (really_free_pendings, 0);
 
   init_minimal_symbol_collection ();
index c5a79b8cb3759a94c3fd264803ea159c613fc45a..faa375ddacea8c701eafdbf28d31e4653951a992 100644 (file)
@@ -51,9 +51,6 @@ static int prev_line_number;
 
 static int line_vector_length;
 
-static struct blockvector *
-make_blockvector PARAMS ((struct objfile *));
-
 static int
 init_dst_sections PARAMS ((int));
 
@@ -87,42 +84,6 @@ dst_start_symtab PARAMS ((void));
 static void
 dst_record_line PARAMS ((int, CORE_ADDR));
 
-static struct blockvector *
-make_blockvector (objfile)
-     struct objfile *objfile;
-{
-  register struct pending_block *next, *next1;
-  register struct blockvector *blockvector;
-  register int i;
-
-  /* Count the length of the list of blocks.  */
-
-  for (next = pending_blocks, i = 0; next; next = next->next, i++);
-
-  blockvector = (struct blockvector *)
-                 obstack_alloc (&objfile->symbol_obstack, sizeof (struct blockvector) + (i - 1) * sizeof (struct block *));
-
-  /* Copy the blocks into the blockvector.
-     This is done in reverse order, which happens to put
-     the blocks into the proper order (ascending starting address).
-   */
-
-  BLOCKVECTOR_NBLOCKS (blockvector) = i;
-  for (next = pending_blocks; next; next = next->next)
-    BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
-
-  /* Now free the links of the list, and empty the list.  */
-
-  for (next = pending_blocks; next; next = next1)
-    {
-      next1 = next->next;
-      free ((PTR)next);
-    }
-  pending_blocks = 0;
-
-  return blockvector;
-}
-
 /* Manage the vector of line numbers.  */
 /* FIXME: Use record_line instead.  */
 
@@ -1426,7 +1387,6 @@ process_dst_block(objfile, entry)
        dst_rec_ptr_t child_entry, symbol_entry;
        struct block *child_block;
        int     total_symbols = 0;
-       struct pending_block *pblock;
        char    fake_name[20];
        static  long    fake_seq = 0;
        struct symbol_list *symlist, *nextsym;
@@ -1509,11 +1469,6 @@ process_dst_block(objfile, entry)
        else
                BLOCK_FUNCTION (block) = 0;
 
-       pblock = (struct pending_block *)
-                       xmalloc (sizeof (struct pending_block));
-       pblock->block = block;
-       pblock->next = pending_blocks;
-       pending_blocks = pblock;
        if (DST_block(entry).child_block_off)
        {
                child_entry = (dst_rec_ptr_t) DST_OFFSET(entry,
@@ -1543,6 +1498,7 @@ process_dst_block(objfile, entry)
                                child_entry = NULL;
                }
        }
+       record_pending_block (objfile, block, NULL);
        return block;
 }
 
@@ -1555,7 +1511,6 @@ read_dst_symtab (objfile)
        dst_rec_ptr_t entry, file_table, root_block;
        char    *source_file;
        struct  block *block, *global_block;
-       struct  pending_block *pblock;
        int     symnum;
        struct symbol_list *nextsym;
        int     module_num = 0;
@@ -1580,11 +1535,6 @@ read_dst_symtab (objfile)
                                        DST_comp_unit(entry).data_size);
                        dst_start_symtab();
 
-                       pblock = (struct pending_block *)
-                               xmalloc (sizeof (struct pending_block));
-                       pblock->next = NULL;
-                       pending_blocks = pblock;
-       
                        block = process_dst_block(objfile, root_block);
 
                        global_block = (struct block *)
@@ -1610,7 +1560,7 @@ read_dst_symtab (objfile)
                        BLOCK_END(global_block) = BLOCK_END(block);
                        BLOCK_SUPERBLOCK(global_block) = 0;
                        BLOCK_SUPERBLOCK(block) = global_block;
-                       pblock->block = global_block;
+                       record_pending_block (objfile, global_block, NULL);
 
                        complete_symtab(source_file,
                                        BLOCK_START(block), 
index 56d7b921d930fb55b17b7211297c9fce35a4407c..9aa1fb10af21e1f51be9a14139c29f675f6e185b 100644 (file)
@@ -340,7 +340,7 @@ hpread_build_psymtabs (objfile, section_offsets, mainline)
   int dependencies_used, dependencies_allocated;
 
   /* Just in case the stabs reader left turds lying around.  */
-  pending_blocks = 0;
+  free_pending_blocks ();
   make_cleanup (really_free_pendings, 0);
 
   pst = (struct partial_symtab *) 0;
index 8614678e1799d1a11f0367550cc08693924a0e5d..5b9489bee89df59f89ad1d68ec73391b75af5df7 100644 (file)
@@ -332,7 +332,7 @@ os9k_symfile_read (objfile, section_offsets, mainline)
     objfile->static_psymbols.size == 0)
     init_psymbol_list (objfile, DBX_SYMCOUNT (objfile));
 
-  pending_blocks = 0;
+  free_pending_blocks ();
   back_to = make_cleanup (really_free_pendings, 0);
 
   make_cleanup (discard_minimal_symbols, 0);
index 731e90b0195855362e63750eed57982fa1323768..c4b868fe4cfd38e24f7884683c1e6bf784f7d6d9 100644 (file)
@@ -2718,7 +2718,7 @@ xcoff_initial_scan (objfile, section_offsets, mainline)
        include N_SLINE.  */
     init_psymbol_list (objfile, num_symbols);
 
-  pending_blocks = 0;
+  free_pending_blocks ();
   back_to = make_cleanup (really_free_pendings, 0);
 
   init_minimal_symbol_collection ();