/* Support routines for building symbol tables in GDB's internal format.
- Copyright (C) 1986-2004, 2007-2012 Free Software Foundation, Inc.
+ Copyright (C) 1986-2014 Free Software Foundation, Inc.
This file is part of GDB.
#include "gdbtypes.h"
#include "gdb_assert.h"
#include "complaints.h"
-#include "gdb_string.h"
+#include <string.h>
#include "expression.h" /* For "enum exp_opcode" used by... */
#include "bcache.h"
#include "filenames.h" /* For DOSish file names. */
the end, then we just toss the addrmap. */
static int pending_addrmap_interesting;
-\f
+/* An obstack used for allocating pending blocks. */
+
+static struct obstack pending_block_obstack;
+
+/* List of blocks already made (lexical contexts already closed).
+ This is used at the end to make the blockvector. */
+
+struct pending_block
+ {
+ struct pending_block *next;
+ struct block *block;
+ };
+
+/* 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;
+
+struct subfile_stack
+ {
+ struct subfile_stack *next;
+ char *name;
+ };
+
+static struct subfile_stack *subfile_stack;
+
+/* The macro table for the compilation unit whose symbols we're
+ currently reading. All the symtabs for the CU will point to this. */
+static struct macro_table *pending_macros;
+
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
needed, and realloc'd down to the size actually used, when
void
free_pending_blocks (void)
{
- /* The links are made in the objfile_obstack, so we only need to
- reset PENDING_BLOCKS. */
- pending_blocks = NULL;
+ if (pending_blocks != NULL)
+ {
+ obstack_free (&pending_block_obstack, NULL);
+ pending_blocks = NULL;
+ }
}
/* Take one of the lists of symbols and make a block from it. Keep
{
struct pending_block *pblock;
+ if (pending_blocks == NULL)
+ obstack_init (&pending_block_obstack);
+
pblock = (struct pending_block *)
- obstack_alloc (&objfile->objfile_obstack, sizeof (struct pending_block));
+ obstack_alloc (&pending_block_obstack, sizeof (struct pending_block));
pblock->block = block;
if (opblock)
{
{
subfile->dirname = subfile->name;
subfile->name = xstrdup (name);
- last_source_file = name;
+ set_last_source_file (name);
/* Default the source language to whatever can be deduced from
the filename. If nothing can be deduced (such as for a C/C++
return ln1->line - ln2->line;
}
\f
+/* Return the macro table.
+ Initialize it if this is the first use. */
+
+struct macro_table *
+get_macro_table (struct objfile *objfile, const char *comp_dir)
+{
+ if (! pending_macros)
+ pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack,
+ objfile->per_bfd->macro_cache,
+ comp_dir);
+ return pending_macros;
+}
+\f
/* Start a new symtab for a new source file. Called, for example,
when a stabs symbol of type N_SO is seen, or when a DWARF
TAG_compile_unit DIE is seen. It indicates the start of data for
lowest address of objects in the file (or 0 if not known). */
void
-start_symtab (char *name, char *dirname, CORE_ADDR start_addr)
+start_symtab (const char *name, const char *dirname, CORE_ADDR start_addr)
{
restart_symtab (start_addr);
- last_source_file = name;
+ set_last_source_file (name);
start_subfile (name, dirname);
}
void
restart_symtab (CORE_ADDR start_addr)
{
- last_source_file = NULL;
+ set_last_source_file (NULL);
last_source_start_addr = start_addr;
file_symbols = NULL;
global_symbols = NULL;
static void
reset_symtab_globals (void)
{
- last_source_file = NULL;
+ set_last_source_file (NULL);
current_subfile = NULL;
pending_macros = NULL;
if (pending_addrmap)
}
}
-/* Finish the symbol definitions for one main source file, close off
- all the lexical contexts for that file (creating struct block's for
- them), then make the struct symtab for that file and put it in the
- list of all such.
+/* Implementation of the first part of end_symtab. It allows modifying
+ STATIC_BLOCK before it gets finalized by end_symtab_from_static_block.
+ If the returned value is NULL there is no blockvector created for
+ this symtab (you still must call end_symtab_from_static_block).
- END_ADDR is the address of the end of the file's text. SECTION is
- the section number (in objfile->section_offsets) of the blockvector
- and linetable.
+ END_ADDR is the same as for end_symtab: the address of the end of the
+ file's text.
- If EXPANDABLE is non-zero the dictionaries for the global and static
- blocks are made expandable.
+ If EXPANDABLE is non-zero the STATIC_BLOCK dictionary is made
+ expandable.
- Note that it is possible for end_symtab() to return NULL. In
- particular, for the DWARF case at least, it will return NULL when
- it finds a compilation unit that has exactly one DIE, a
- TAG_compile_unit DIE. This can happen when we link in an object
- file that was compiled from an empty source file. Returning NULL
- is probably not the correct thing to do, because then gdb will
- never know about this empty file (FIXME). */
+ If REQUIRED is non-zero, then a symtab is created even if it does
+ not contain any symbols. */
-static struct symtab *
-end_symtab_1 (CORE_ADDR end_addr, struct objfile *objfile, int section,
- int expandable)
+struct block *
+end_symtab_get_static_block (CORE_ADDR end_addr, struct objfile *objfile,
+ int expandable, int required)
{
- struct symtab *symtab = NULL;
- struct blockvector *blockvector;
- struct subfile *subfile;
- struct context_stack *cstk;
- struct subfile *nextsub;
-
/* Finish the lexical context of the last function in the file; pop
the context stack. */
if (context_stack_depth > 0)
{
- cstk = pop_context ();
+ struct context_stack *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);
cleanup_undefined_stabs_types (objfile);
finish_global_stabs (objfile);
- if (pending_blocks == NULL
+ if (!required
+ && pending_blocks == NULL
&& file_symbols == NULL
&& global_symbols == NULL
&& have_line_numbers == 0
&& pending_macros == NULL)
{
- /* Ignore symtabs that have no functions with real debugging
- info. */
+ /* Ignore symtabs that have no functions with real debugging info. */
+ return NULL;
+ }
+ else
+ {
+ /* Define the STATIC_BLOCK. */
+ return finish_block_internal (NULL, &file_symbols, NULL,
+ last_source_start_addr, end_addr, objfile,
+ 0, expandable);
+ }
+}
+
+/* Implementation of the second part of end_symtab. Pass STATIC_BLOCK
+ as value returned by end_symtab_get_static_block.
+
+ SECTION is the same as for end_symtab: the section number
+ (in objfile->section_offsets) of the blockvector and linetable.
+
+ If EXPANDABLE is non-zero the GLOBAL_BLOCK dictionary is made
+ expandable. */
+
+struct symtab *
+end_symtab_from_static_block (struct block *static_block,
+ struct objfile *objfile, int section,
+ int expandable)
+{
+ struct symtab *symtab = NULL;
+ struct blockvector *blockvector;
+ struct subfile *subfile;
+ struct subfile *nextsub;
+
+ if (static_block == NULL)
+ {
+ /* Ignore symtabs that have no functions with real debugging info. */
blockvector = NULL;
}
else
{
- /* Define the STATIC_BLOCK & GLOBAL_BLOCK, and build the
+ CORE_ADDR end_addr = BLOCK_END (static_block);
+
+ /* Define after STATIC_BLOCK also GLOBAL_BLOCK, and build the
blockvector. */
- finish_block_internal (0, &file_symbols, 0, last_source_start_addr,
- end_addr, objfile, 0, expandable);
- finish_block_internal (0, &global_symbols, 0, last_source_start_addr,
- end_addr, objfile, 1, expandable);
+ finish_block_internal (NULL, &global_symbols, NULL,
+ last_source_start_addr, end_addr, objfile,
+ 1, expandable);
blockvector = make_blockvector (objfile);
}
- /* Read the line table if it has to be read separately. */
+ /* Read the line table if it has to be read separately.
+ This is only used by xcoffread.c. */
if (objfile->sf->sym_read_linetable != NULL)
- objfile->sf->sym_read_linetable ();
+ objfile->sf->sym_read_linetable (objfile);
/* Handle the case where the debug info specifies a different path
for the main source file. It can cause us to lose track of its
if (subfile->dirname)
{
/* Reallocate the dirname on the symbol obstack. */
- symtab->dirname = (char *)
- obstack_alloc (&objfile->objfile_obstack,
- strlen (subfile->dirname) + 1);
- strcpy (symtab->dirname, subfile->dirname);
+ symtab->dirname =
+ obstack_copy0 (&objfile->objfile_obstack,
+ subfile->dirname,
+ strlen (subfile->dirname));
}
else
{
/* All symtabs for the main file and the subfiles share a
blockvector, so we need to clear primary for everything
but the main file. */
-
- symtab->primary = 0;
+ set_symtab_primary (symtab, 0);
}
else
{
/* Set this for the main source file. */
if (symtab)
{
- symtab->primary = 1;
+ set_symtab_primary (symtab, 1);
if (symtab->blockvector)
{
return symtab;
}
-/* See end_symtab_1 for details. */
+/* Finish the symbol definitions for one main source file, close off
+ all the lexical contexts for that file (creating struct block's for
+ them), then make the struct symtab for that file and put it in the
+ list of all such.
+
+ END_ADDR is the address of the end of the file's text. SECTION is
+ the section number (in objfile->section_offsets) of the blockvector
+ and linetable.
+
+ Note that it is possible for end_symtab() to return NULL. In
+ particular, for the DWARF case at least, it will return NULL when
+ it finds a compilation unit that has exactly one DIE, a
+ TAG_compile_unit DIE. This can happen when we link in an object
+ file that was compiled from an empty source file. Returning NULL
+ is probably not the correct thing to do, because then gdb will
+ never know about this empty file (FIXME).
+
+ If you need to modify STATIC_BLOCK before it is finalized you should
+ call end_symtab_get_static_block and end_symtab_from_static_block
+ yourself. */
struct symtab *
end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
{
- return end_symtab_1 (end_addr, objfile, section, 0);
+ struct block *static_block;
+
+ static_block = end_symtab_get_static_block (end_addr, objfile, 0, 0);
+ return end_symtab_from_static_block (static_block, objfile, section, 0);
}
-/* See end_symtab_1 for details. */
+/* Same as end_symtab except create a symtab that can be later added to. */
struct symtab *
end_expandable_symtab (CORE_ADDR end_addr, struct objfile *objfile,
int section)
{
- return end_symtab_1 (end_addr, objfile, section, 1);
+ struct block *static_block;
+
+ static_block = end_symtab_get_static_block (end_addr, objfile, 1, 0);
+ return end_symtab_from_static_block (static_block, objfile, section, 1);
}
/* Subroutine of augment_type_symtab to simplify it.
augment_type_symtab (struct objfile *objfile, struct symtab *primary_symtab)
{
struct blockvector *blockvector = primary_symtab->blockvector;
- int i;
if (context_stack_depth > 0)
{
new = &context_stack[context_stack_depth++];
new->depth = desc;
new->locals = local_symbols;
- new->params = param_symbols;
new->old_blocks = pending_blocks;
new->start_addr = valu;
new->using_directives = using_directives;
new->name = NULL;
local_symbols = NULL;
- param_symbols = NULL;
using_directives = NULL;
return new;
free_pendings = (*srclist);
}
\f
+
+/* Name of source file whose symbol data we are now processing. This
+ comes from a symbol of type N_SO for stabs. For Dwarf it comes
+ from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
+
+static char *last_source_file;
+
+/* See buildsym.h. */
+
+void
+set_last_source_file (const char *name)
+{
+ xfree (last_source_file);
+ last_source_file = name == NULL ? NULL : xstrdup (name);
+}
+
+/* See buildsym.h. */
+
+const char *
+get_last_source_file (void)
+{
+ return last_source_file;
+}
+
+\f
+
/* Initialize anything that needs initializing when starting to read a
fresh piece of a symbol file, e.g. reading in the stuff
corresponding to a psymtab. */
global_symbols = NULL;
pending_blocks = NULL;
pending_macros = NULL;
+ using_directives = NULL;
+ subfile_stack = NULL;
/* We shouldn't have any address map at this point. */
gdb_assert (! pending_addrmap);