Make free_pending_blocks static
[deliverable/binutils-gdb.git] / gdb / buildsym.c
index 8fd100921b0e829752c625fad122c13a4dea6214..4e5da073723e3d05305b3eb97fe315191aa4f35b 100644 (file)
@@ -74,7 +74,6 @@
 #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.  */
@@ -106,11 +105,13 @@ struct buildsym_compunit
      (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)
   {
   }
 
@@ -195,6 +196,14 @@ struct buildsym_compunit
   /* 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.
@@ -242,13 +251,9 @@ struct pending_block
 
 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);
 
@@ -258,6 +263,8 @@ static void record_pending_block (struct objfile *objfile,
                                  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.  */
@@ -326,6 +333,11 @@ find_symbol_in_list (struct pending *list, char *name, int length)
   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.
 
@@ -368,8 +380,8 @@ scoped_free_pendings::~scoped_free_pendings ()
 
 /* This function is called to discard any pending blocks.  */
 
-void
-free_pending_blocks (void)
+static void
+free_pending_blocks ()
 {
   if (pending_blocks != NULL)
     {
@@ -875,35 +887,21 @@ patch_subfile_names (struct subfile *subfile, const char *name)
    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
@@ -1017,13 +1015,10 @@ get_macro_table (void)
    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;
 
@@ -1053,10 +1048,10 @@ struct compunit_symtab *
 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.  */
@@ -1090,13 +1085,14 @@ void
 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;
 }
 
@@ -1291,8 +1287,8 @@ end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required)
     {
       /* 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);
     }
 }
 
@@ -1319,7 +1315,7 @@ end_symtab_with_blockvector (struct block *static_block,
 
   /* 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 ();
 
@@ -1657,15 +1653,6 @@ pop_context (void)
 
 \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)
 {
@@ -1678,33 +1665,6 @@ record_producer (const char *producer)
   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.  */
@@ -1727,6 +1687,24 @@ get_last_source_file (void)
   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
@@ -1734,10 +1712,8 @@ get_last_source_file (void)
    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
@@ -1758,13 +1734,3 @@ buildsym_init (void)
   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 ();
-}
This page took 0.02836 seconds and 4 git commands to generate.