#include "gdbtypes.h"
#include "complaints.h"
#include "expression.h" /* For "enum exp_opcode" used by... */
-#include "bcache.h"
#include "filenames.h" /* For DOSish file names. */
#include "macrotab.h"
#include "demangle.h" /* Needed by SYMBOL_INIT_DEMANGLED_NAME. */
(or NULL if not known). */
buildsym_compunit (struct objfile *objfile_, const char *name,
- const char *comp_dir_, enum language language_)
+ const char *comp_dir_, enum language language_,
+ CORE_ADDR last_addr)
: objfile (objfile_),
m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)),
- language (language_)
+ language (language_),
+ m_last_source_start_addr (last_addr)
{
}
/* True if symtab has line number info. This prevents an otherwise
empty symtab from being tossed. */
bool m_have_line_numbers = false;
+
+ /* Core address of start of text of current source file. This too
+ comes from the N_SO symbol. For Dwarf it typically comes from the
+ DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
+ CORE_ADDR m_last_source_start_addr;
+
+ /* Stack of subfile names. */
+ std::vector<const char *> m_subfile_stack;
};
/* The work-in-progress of the compunit we are building.
static struct pending_block *pending_blocks;
-struct subfile_stack
- {
- struct subfile_stack *next;
- char *name;
- };
+/* Currently allocated size of context stack. */
-static struct subfile_stack *subfile_stack;
+static int context_stack_size;
static void free_buildsym_compunit (void);
struct block *block,
struct pending_block *opblock);
+static void free_pending_blocks ();
+
/* Initial sizes of data structures. These are realloc'd larger if
needed, and realloc'd down to the size actually used, when
completed. */
return (NULL);
}
+scoped_free_pendings::scoped_free_pendings ()
+{
+ gdb_assert (pending_blocks == nullptr);
+}
+
/* At end of reading syms, or in case of quit, ensure everything
associated with building symtabs is freed.
/* This function is called to discard any pending blocks. */
-void
-free_pending_blocks (void)
+static void
+free_pending_blocks ()
{
if (pending_blocks != NULL)
{
order. */
void
-push_subfile (void)
+push_subfile ()
{
- struct subfile_stack *tem = XNEW (struct subfile_stack);
-
- tem->next = subfile_stack;
- subfile_stack = tem;
- if (current_subfile == NULL || current_subfile->name == NULL)
- {
- internal_error (__FILE__, __LINE__,
- _("failed internal consistency check"));
- }
- tem->name = current_subfile->name;
+ gdb_assert (buildsym_compunit != nullptr);
+ gdb_assert (current_subfile != NULL && current_subfile->name != NULL);
+ buildsym_compunit->m_subfile_stack.push_back (current_subfile->name);
}
-char *
-pop_subfile (void)
+const char *
+pop_subfile ()
{
- char *name;
- struct subfile_stack *link = subfile_stack;
-
- if (link == NULL)
- {
- internal_error (__FILE__, __LINE__,
- _("failed internal consistency check"));
- }
- name = link->name;
- subfile_stack = link->next;
- xfree ((void *) link);
- return (name);
+ gdb_assert (buildsym_compunit != nullptr);
+ gdb_assert (!buildsym_compunit->m_subfile_stack.empty ());
+ const char *name = buildsym_compunit->m_subfile_stack.back ();
+ buildsym_compunit->m_subfile_stack.pop_back ();
+ return name;
}
\f
/* Add a linetable entry for line number LINE and address PC to the
buildsym_init. */
static void
-prepare_for_building (CORE_ADDR start_addr)
+prepare_for_building ()
{
- last_source_start_addr = start_addr;
-
local_symbols = NULL;
local_using_directives = NULL;
- within_function = 0;
context_stack_depth = 0;
start_symtab (struct objfile *objfile, const char *name, const char *comp_dir,
CORE_ADDR start_addr, enum language language)
{
- prepare_for_building (start_addr);
+ prepare_for_building ();
buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir,
- language);
+ language, start_addr);
/* Allocate the compunit symtab now. The caller needs it to allocate
non-primary symtabs. It is also needed by get_macro_table. */
restart_symtab (struct compunit_symtab *cust,
const char *name, CORE_ADDR start_addr)
{
- prepare_for_building (start_addr);
+ prepare_for_building ();
buildsym_compunit
= new struct buildsym_compunit (COMPUNIT_OBJFILE (cust),
name,
COMPUNIT_DIRNAME (cust),
- compunit_language (cust));
+ compunit_language (cust),
+ start_addr);
buildsym_compunit->compunit_symtab = cust;
}
{
/* Define the STATIC_BLOCK. */
return finish_block_internal (NULL, &file_symbols, NULL, NULL,
- last_source_start_addr, end_addr,
- 0, expandable);
+ buildsym_compunit->m_last_source_start_addr,
+ end_addr, 0, expandable);
}
}
/* Create the GLOBAL_BLOCK and build the blockvector. */
finish_block_internal (NULL, &global_symbols, NULL, NULL,
- last_source_start_addr, end_addr,
+ buildsym_compunit->m_last_source_start_addr, end_addr,
1, expandable);
blockvector = make_blockvector ();
\f
-/* Compute a small integer hash code for the given name. */
-
-int
-hashname (const char *name)
-{
- return (hash(name,strlen(name)) % HASHSIZE);
-}
-\f
-
void
record_debugformat (const char *format)
{
buildsym_compunit->producer = producer;
}
-/* Merge the first symbol list SRCLIST into the second symbol list
- TARGETLIST by repeated calls to add_symbol_to_list(). This
- procedure "frees" each link of SRCLIST by adding it to the
- free_pendings list. Caller must set SRCLIST to a null list after
- calling this function.
-
- Void return. */
-
-void
-merge_symbol_lists (struct pending **srclist, struct pending **targetlist)
-{
- int i;
-
- if (!srclist || !*srclist)
- return;
-
- /* Merge in elements from current link. */
- for (i = 0; i < (*srclist)->nsyms; i++)
- add_symbol_to_list ((*srclist)->symbol[i], targetlist);
-
- /* Recurse on next. */
- merge_symbol_lists (&(*srclist)->next, targetlist);
-
- /* "Free" the current link. */
- (*srclist)->next = free_pendings;
- free_pendings = (*srclist);
-}
\f
/* See buildsym.h. */
return buildsym_compunit->m_last_source_file.get ();
}
+/* See buildsym.h. */
+
+void
+set_last_source_start_addr (CORE_ADDR addr)
+{
+ gdb_assert (buildsym_compunit != nullptr);
+ buildsym_compunit->m_last_source_start_addr = addr;
+}
+
+/* See buildsym.h. */
+
+CORE_ADDR
+get_last_source_start_addr ()
+{
+ gdb_assert (buildsym_compunit != nullptr);
+ return buildsym_compunit->m_last_source_start_addr;
+}
+
\f
/* Initialize anything that needs initializing when starting to read a
corresponding to a psymtab. */
void
-buildsym_init (void)
+buildsym_init ()
{
- subfile_stack = NULL;
-
pending_addrmap_interesting = 0;
/* Context stack is initially empty. Allocate first one with room
gdb_assert (pending_addrmap == NULL);
gdb_assert (buildsym_compunit == NULL);
}
-
-/* Initialize anything that needs initializing when a completely new
- symbol file is specified (not just adding some symbols from another
- file, e.g. a shared library). */
-
-void
-buildsym_new_init (void)
-{
- buildsym_init ();
-}