This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] convert blocks to dictionaries, phase 1, mdebugread.c


This patch does phase 1 of converting blocks to dictionaries in the
file mdebugread.c.  It depends on the patches in
<http://sources.redhat.com/ml/gdb-patches/2002-09/msg00325.html>.

I've run it through the testsuite, but that says absolutely nothing
about this code, because it involves a debug format that I don't use.
So, in a reasonably ideal world, somebody would test this patch on a
machine that actually uses that debugging format.  In a slightly less
ideal world but one that should be just as good in practice, somebody
would eventually test all my patches to mdebugread.c once the whole
process of converting blocks to dictionaries was completed; it should
be fine to catch bugs then as opposed to catching them along the way.

And, of course, in a completely ideal world either mdebugread.c would
be converted over to buildsym.c or else would become obsolete.

Here's what this code should be doing:

1) Make sure that the blocks that mdebugread.c creates have a
   BLOCK_DICT member that's initialized correctly.

2) Make sure that all the code to add symbols to those blocks does it
   by calling DICT_TEMP_add_block_symbol.  (This should take care of
   resizing the block when necessary.)

Incidentally, I grouped the ChangeLog entries by kind of fix rather
than by function name: so there are multiple entries that refer to,
say, the procedure parse_symbol.  Is that okay?

David Carlton
carlton@math.stanford.edu

2002-09-16  David Carlton  <carlton@math.stanford.edu>

	* mdebugread.c: Delete 'maxsyms' member of parse_stack.
	(new_block): Remove argument.
	(new_symtab): Remove 'maxsyms' argument.
	(parse_symbol): Update calls to new_block.
	(parse_procedure): Ditto.
	(fixup_sigtramp): Ditto.
	(psymtab_to_symtab_1): Update calls to new_symtab; don't set
	maxsyms.
	(shrink_block): Comment out entire function.
	(parse_symbol): Remove calls to shrink_block.
	(add_symbol): Add symbol via DICT_TEMP_add_block_symbol.
	(parse_symbol): Initialize BLOCK_DICT (b) after creating new
	blocks.
	(parse_procedure): Ditto.
	(new_symtab): Ditto.
	(fixup_sigtramp): Ditto.

Index: mdebugread.c
===================================================================
RCS file: /cvs/src/src/gdb/mdebugread.c,v
retrieving revision 1.28
diff -u -p -r1.28 mdebugread.c
--- mdebugread.c	29 Jul 2002 22:55:26 -0000	1.28
+++ mdebugread.c	16 Sep 2002 21:48:44 -0000
@@ -41,6 +41,11 @@
    This module can read all four of the known byte-order combinations,
    on any type of host.  */
 
+/* FIXME: carlton/2002-09-16: This is the only symbol table reader
+   that doesn't use the functions in buildsym.c to build the blocks.
+   Until this file is rewritten, it will get more and more fragile and
+   inefficient as code elsewhere changes.  */
+
 #include "defs.h"
 #include "symtab.h"
 #include "gdbtypes.h"
@@ -343,9 +348,9 @@ static struct symbol *new_symbol (char *
 
 static struct type *new_type (char *);
 
-static struct block *new_block (int);
+static struct block *new_block (void);
 
-static struct symtab *new_symtab (char *, int, int, struct objfile *);
+static struct symtab *new_symtab (char *, int, struct objfile *);
 
 static struct linetable *new_linetable (int);
 
@@ -357,7 +362,9 @@ static struct type *parse_type (int, uni
 static struct symbol *mylookup_symbol (char *, struct block *, namespace_enum,
 				       enum address_class);
 
+#if 0
 static struct block *shrink_block (struct block *, struct symtab *);
+#endif
 
 static void sort_blocks (struct symtab *);
 
@@ -555,7 +562,6 @@ static struct parse_stack
 
     int blocktype;
 
-    int maxsyms;		/* Max symbols in this block. */
     struct type *cur_type;	/* Type we parse fields for. */
     int cur_field;		/* Field number in cur_type. */
     CORE_ADDR procadr;		/* Start addres of this procedure */
@@ -869,11 +875,12 @@ parse_symbol (SYMR *sh, union aux_ext *a
       SYMBOL_TYPE (s) = lookup_function_type (t);
 
       /* Create and enter a new lexical context */
-      b = new_block (top_stack->maxsyms);
+      b = new_block ();
       SYMBOL_BLOCK_VALUE (s) = b;
       BLOCK_FUNCTION (b) = s;
       BLOCK_START (b) = BLOCK_END (b) = sh->value;
       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
+      BLOCK_DICT (b) = DICT_TEMP_create_block_expandable (b);
       add_block (b, top_stack->cur_st);
 
       /* Not if we only have partial info */
@@ -1180,9 +1187,10 @@ parse_symbol (SYMR *sh, union aux_ext *a
 	}
 
       top_stack->blocktype = stBlock;
-      b = new_block (top_stack->maxsyms);
+      b = new_block ();
       BLOCK_START (b) = sh->value + top_stack->procadr;
       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
+      BLOCK_DICT (b) = DICT_TEMP_create_block_expandable (b);
       top_stack->cur_block = b;
       add_block (b, top_stack->cur_st);
       break;
@@ -1220,8 +1228,7 @@ parse_symbol (SYMR *sh, union aux_ext *a
 	  e->pdr.framereg = -1;
 	  add_symbol (s, top_stack->cur_block);
 
-	  /* Reallocate symbols, saving memory */
-	  b = shrink_block (top_stack->cur_block, top_stack->cur_st);
+	  b = top_stack->cur_block;
 
 	  /* f77 emits proc-level with address bounds==[0,0],
 	     So look for such child blocks, and patch them.  */
@@ -1277,7 +1284,6 @@ parse_symbol (SYMR *sh, union aux_ext *a
 	     displacement from the procedure`s start address of the
 	     end of this block. */
 	  BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
-	  shrink_block (top_stack->cur_block, top_stack->cur_st);
 	}
       else if (sh->sc == scText && top_stack->blocktype == stNil)
 	{
@@ -1957,8 +1963,7 @@ parse_procedure (PDR *pr, struct symtab 
       /* Donno its type, hope int is ok */
       SYMBOL_TYPE (s) = lookup_function_type (mdebug_type_int);
       add_symbol (s, top_stack->cur_block);
-      /* Wont have symbols for this one */
-      b = new_block (2);
+      b = new_block ();
       SYMBOL_BLOCK_VALUE (s) = b;
       BLOCK_FUNCTION (b) = s;
       BLOCK_START (b) = pr->adr;
@@ -1966,6 +1971,7 @@ parse_procedure (PDR *pr, struct symtab 
          argument is no longer passed in.  */
       BLOCK_END (b) = bound;
       BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
+      BLOCK_DICT (b) = DICT_TEMP_create_block_expandable (b);
       add_block (b, top_stack->cur_st);
 #endif
     }
@@ -4034,23 +4040,18 @@ psymtab_to_symtab_1 (struct partial_symt
     {
       /* This symbol table contains ordinary ecoff entries.  */
 
-      int f_max;
       int maxlines;
       EXTR *ext_ptr;
 
-      /* How many symbols will we need */
-      /* FIXME, this does not count enum values. */
-      f_max = pst->n_global_syms + pst->n_static_syms;
       if (fh == 0)
 	{
 	  maxlines = 0;
-	  st = new_symtab ("unknown", f_max, 0, pst->objfile);
+	  st = new_symtab ("unknown", 0, pst->objfile);
 	}
       else
 	{
-	  f_max += fh->csym + fh->cpd;
 	  maxlines = 2 * fh->cline;
-	  st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile);
+	  st = new_symtab (pst->filename, maxlines, pst->objfile);
 
 	  /* The proper language was already determined when building
 	     the psymtab, use it.  */
@@ -4070,7 +4071,6 @@ psymtab_to_symtab_1 (struct partial_symt
       BLOCK_START (top_stack->cur_block) = TEXTLOW (pst);
       BLOCK_END (top_stack->cur_block) = 0;
       top_stack->blocktype = stFile;
-      top_stack->maxsyms = 2 * f_max;
       top_stack->cur_type = 0;
       top_stack->procadr = 0;
       top_stack->numargs = 0;
@@ -4154,10 +4154,6 @@ psymtab_to_symtab_1 (struct partial_symt
       top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
 						GLOBAL_BLOCK);
       top_stack->blocktype = stFile;
-      top_stack->maxsyms
-	= (debug_info->symbolic_header.isymMax
-	   + debug_info->symbolic_header.ipdMax
-	   + debug_info->symbolic_header.iextMax);
 
       ext_ptr = PST_PRIVATE (pst)->extern_tab;
       for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
@@ -4457,32 +4453,38 @@ mylookup_symbol (char *name, register st
 static void
 add_symbol (struct symbol *s, struct block *b)
 {
-  int nsyms = BLOCK_NSYMS (b)++;
-  struct block *origb;
-  struct parse_stack *stackp;
-
-  if (b == top_stack->cur_block &&
-      nsyms >= top_stack->maxsyms)
-    {
-      complain (&block_overflow_complaint, SYMBOL_NAME (s));
-      /* In this case shrink_block is actually grow_block, since
-         BLOCK_NSYMS(b) is larger than its current size.  */
-      origb = b;
-      b = shrink_block (top_stack->cur_block, top_stack->cur_st);
-
-      /* Now run through the stack replacing pointers to the
-         original block.  shrink_block has already done this
-         for the blockvector and BLOCK_FUNCTION.  */
+  struct block *newb;
+
+  newb = DICT_TEMP_add_block_symbol (BLOCK_DICT (b), s);
+
+  /* Did that expand and move the block?  If so, update references
+     accordingly.  */
+
+  if (newb != b)
+    {
+      int i;
+      struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
+      struct parse_stack *stackp;
+      
+      if (BLOCK_FUNCTION (newb)
+	  && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (newb)) == b)
+	SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (newb)) = newb;
+      for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
+	if (BLOCKVECTOR_BLOCK (bv, i) == b)
+	  BLOCKVECTOR_BLOCK (bv, i) = newb;
+	else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) == b)
+	  BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) = newb;
+      
+      /* Now run through the stack replacing pointers to the original
+	 block.  */
       for (stackp = top_stack; stackp; stackp = stackp->next)
 	{
-	  if (stackp->cur_block == origb)
+	  if (stackp->cur_block == b)
 	    {
-	      stackp->cur_block = b;
-	      stackp->maxsyms = BLOCK_NSYMS (b);
+	      stackp->cur_block = newb;
 	    }
 	}
     }
-  BLOCK_SYM (b, nsyms) = s;
 }
 
 /* Add a new block B to a symtab S */
@@ -4604,22 +4606,26 @@ sort_blocks (struct symtab *s)
 
 /* Constructor/restructor/destructor procedures */
 
-/* Allocate a new symtab for NAME.  Needs an estimate of how many symbols
-   MAXSYMS and linenumbers MAXLINES we'll put in it */
+/* Allocate a new symtab for NAME.  Needs an estimate of how many
+   linenumbers MAXLINES we'll put in it.  */
 
 static struct symtab *
-new_symtab (char *name, int maxsyms, int maxlines, struct objfile *objfile)
+new_symtab (char *name, int maxlines, struct objfile *objfile)
 {
   struct symtab *s = allocate_symtab (name, objfile);
+  struct block *b;
 
   LINETABLE (s) = new_linetable (maxlines);
 
   /* All symtabs must have at least two blocks */
   BLOCKVECTOR (s) = new_bvect (2);
-  BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = new_block (maxsyms);
-  BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = new_block (maxsyms);
-  BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) =
-    BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
+  b = new_block ();
+  BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = b;
+  BLOCK_DICT (b) = DICT_TEMP_create_block_expandable (b);
+  b = new_block ();
+  BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = b;
+  BLOCK_DICT (b) = DICT_TEMP_create_block_expandable (b);
+  BLOCK_SUPERBLOCK (b) = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
 
   s->free_code = free_linetable;
   s->debugformat = obsavestring ("ECOFF", 5,
@@ -4701,16 +4707,19 @@ new_bvect (int nblocks)
   return bv;
 }
 
-/* Allocate and zero a new block of MAXSYMS symbols */
+/* Allocate and zero a new block.  */
 
 static struct block *
-new_block (int maxsyms)
+new_block (void)
 {
-  int size = sizeof (struct block) + (maxsyms - 1) * sizeof (struct symbol *);
-
-  return (struct block *) xzalloc (size);
+  return (struct block *) xzalloc (sizeof (struct block));
 }
 
+#if 0
+
+/* FIXME: carlton/2002-09-16: Delete this once the transition to
+   dictionaries is complete.  */
+
 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
    Shrink_block can also be used by add_symbol to grow a block.  */
 
@@ -4745,6 +4754,8 @@ shrink_block (struct block *b, struct sy
   return new;
 }
 
+#endif /* 0 */
+
 /* Create a new symbol with printname NAME */
 
 static struct symbol *
@@ -4870,12 +4881,13 @@ fixup_sigtramp (void)
   TYPE_TARGET_TYPE (SYMBOL_TYPE (s)) = mdebug_type_void;
 
   /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
-  b = new_block (1);
+  b = new_block ();
   SYMBOL_BLOCK_VALUE (s) = b;
   BLOCK_START (b) = sigtramp_address;
   BLOCK_END (b) = sigtramp_end;
   BLOCK_FUNCTION (b) = s;
   BLOCK_SUPERBLOCK (b) = BLOCK_SUPERBLOCK (b0);
+  BLOCK_DICT (b) = DICT_TEMP_create_block_expandable (b);
   add_block (b, st);
   sort_blocks (st);
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]