/* Support routines for building symbol tables in GDB's internal format.
- Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1995
+ Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1995, 1996
Free Software Foundation, Inc.
This file is part of GDB.
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. */
\f
/* Complaints about the symbols we have encountered. */
+struct complaint block_end_complaint =
+ {"block end address less than block start address in %s (patched it)", 0, 0};
+
+struct complaint anon_block_end_complaint =
+ {"block end address 0x%lx less than block start address 0x%lx (patched it)", 0, 0};
+
struct complaint innerblock_complaint =
{"inner block not inside outer block in %s", 0, 0};
struct complaint innerblock_anon_complaint =
- {"inner block not inside outer block", 0, 0};
+ {"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};
int foo;
{
struct pending *next, *next1;
-#if 0
- struct pending_block *bnext, *bnext1;
-#endif
for (next = free_pendings; next; next = next1)
{
}
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)
{
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. */
case LOC_REF_ARG:
case LOC_REGPARM:
case LOC_REGPARM_ADDR:
+ case LOC_BASEREG_ARG:
+ case LOC_LOCAL_ARG:
nparams++;
break;
case LOC_UNDEF:
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:
break;
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;
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:
break;
}
*listhead = NULL;
+#if 1
+ /* Check to be sure that the blocks have an end address that is
+ greater than starting address */
+
+ if (BLOCK_END (block) < BLOCK_START (block))
+ {
+ if (symbol)
+ {
+ complain (&block_end_complaint, SYMBOL_SOURCE_NAME (symbol));
+ }
+ else
+ {
+ complain (&anon_block_end_complaint, BLOCK_END (block), BLOCK_START (block));
+ }
+ /* Better than nothing */
+ BLOCK_END (block) = BLOCK_START (block);
+ }
+#endif
+
/* Install this block as the superblock
of all blocks made since the start of this scope
that don't have superblocks yet. */
}
else
{
- complain (&innerblock_anon_complaint);
+ complain (&innerblock_anon_complaint, BLOCK_START (pblock->block),
+ 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;
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;
{
static int
compare_line_numbers (ln1p, ln2p)
- const PTR ln1p;
- const PTR ln2p;
+ const void *ln1p;
+ const void *ln2p;
{
struct linetable_entry *ln1 = (struct linetable_entry *) ln1p;
struct linetable_entry *ln2 = (struct linetable_entry *) ln2p;
because then gdb will never know about this empty file (FIXME). */
struct symtab *
-end_symtab (end_addr, sort_pending, sort_linevec, objfile, section)
+end_symtab (end_addr, objfile, section)
CORE_ADDR end_addr;
- int sort_pending;
- int sort_linevec;
struct objfile *objfile;
int 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);
}
}
- /* It is unfortunate that in xcoff, pending blocks might not be ordered
- in this stage. Especially, blocks for static functions will show up at
- the end. We need to sort them, so tools like `find_pc_function' and
- `find_pc_block' can work reliably. */
-
- if (sort_pending && pending_blocks)
+ /* Reordered executables may have out of order pending blocks; if
+ 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!!! */
+ /* FIXME! Remove this horrid bubble sort and use qsort!!!
+ It'd be a whole lot easier if they weren't in a linked list!!! */
int swapped;
do
{
subfile->line_vector = (struct linetable *)
xrealloc ((char *) subfile->line_vector, linetablesize);
#endif
- /* If sort_linevec is false, we might want just check to make
- sure they are sorted and complain() if not, as a way of
- tracking down compilers/symbol readers which don't get
- them sorted right. */
- if (sort_linevec)
+ /* Like the pending blocks, the line table may be scrambled
+ in reordered executables. Sort it if OBJF_REORDERED is
+ true. */
+ if (objfile->flags & OBJF_REORDERED)
qsort (subfile->line_vector->item,
subfile->line_vector->nitems,
sizeof (struct linetable_entry), compare_line_numbers);