Make free_pending_blocks static
[deliverable/binutils-gdb.git] / gdb / buildsym.c
index 56be8ac929ec9c70ed9c4e277076a2bc1791293e..4e5da073723e3d05305b3eb97fe315191aa4f35b 100644 (file)
@@ -1,5 +1,5 @@
 /* Support routines for building symbol tables in GDB's internal format.
-   Copyright (C) 1986-2016 Free Software Foundation, Inc.
+   Copyright (C) 1986-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    The basic way this module is used is as follows:
 
    buildsym_init ();
-   cleanups = make_cleanup (really_free_pendings, NULL);
+   scoped_free_pendings free_pending;
    cust = start_symtab (...);
    ... read debug info ...
    cust = end_symtab (...);
-   do_cleanups (cleanups);
 
    The compunit symtab pointer ("cust") is returned from both start_symtab
    and end_symtab to simplify the debug info readers.
    Reading DWARF Type Units is another variation:
 
    buildsym_init ();
-   cleanups = make_cleanup (really_free_pendings, NULL);
+   scoped_free_pendings free_pending;
    cust = start_symtab (...);
    ... read debug info ...
    cust = end_expandable_symtab (...);
-   do_cleanups (cleanups);
 
    And then reading subsequent Type Units within the containing "Comp Unit"
    will use a second flow:
 
    buildsym_init ();
-   cleanups = make_cleanup (really_free_pendings, NULL);
+   scoped_free_pendings free_pending;
    cust = restart_symtab (...);
    ... read debug info ...
    cust = augment_type_symtab (...);
-   do_cleanups (cleanups);
 
    dbxread.c and xcoffread.c use another variation:
 
    buildsym_init ();
-   cleanups = make_cleanup (really_free_pendings, NULL);
+   scoped_free_pendings free_pending;
    cust = start_symtab (...);
    ... read debug info ...
    cust = end_symtab (...);
    ... start_symtab + read + end_symtab repeated ...
-   do_cleanups (cleanups);
 */
 
 #include "defs.h"
@@ -78,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.  */
@@ -86,6 +81,7 @@
 #include "cp-support.h"
 #include "dictionary.h"
 #include "addrmap.h"
+#include <algorithm>
 
 /* Ask buildsym.h to define the vars it normally declares `extern'.  */
 #define        EXTERN
 
 struct buildsym_compunit
 {
+  /* Start recording information about a primary source file (IOW, not an
+     included source file).
+     COMP_DIR is the directory in which the compilation unit was compiled
+     (or NULL if not known).  */
+
+  buildsym_compunit (struct objfile *objfile_, const char *name,
+                    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_),
+      m_last_source_start_addr (last_addr)
+  {
+  }
+
+  ~buildsym_compunit ()
+  {
+    struct subfile *subfile, *nextsub;
+
+    if (m_pending_macros != nullptr)
+      free_macro_table (m_pending_macros);
+
+    for (subfile = subfiles;
+        subfile != NULL;
+        subfile = nextsub)
+      {
+       nextsub = subfile->next;
+       xfree (subfile->name);
+       xfree (subfile->line_vector);
+       xfree (subfile);
+      }
+  }
+
+  void set_last_source_file (const char *name)
+  {
+    char *new_name = name == NULL ? NULL : xstrdup (name);
+    m_last_source_file.reset (new_name);
+  }
+
+  struct macro_table *get_macro_table ()
+  {
+    if (m_pending_macros == nullptr)
+      m_pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack,
+                                         objfile->per_bfd->macro_cache,
+                                         compunit_symtab);
+    return m_pending_macros;
+  }
+
+  struct macro_table *release_macros ()
+  {
+    struct macro_table *result = m_pending_macros;
+    m_pending_macros = nullptr;
+    return result;
+  }
+
   /* The objfile we're reading debug info from.  */
   struct objfile *objfile;
 
@@ -110,24 +162,48 @@ struct buildsym_compunit
      Files are added to the front of the list.
      This is important mostly for the language determination hacks we use,
      which iterate over previously added files.  */
-  struct subfile *subfiles;
+  struct subfile *subfiles = nullptr;
 
   /* The subfile of the main source file.  */
-  struct subfile *main_subfile;
+  struct subfile *main_subfile = nullptr;
+
+  /* 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.  */
+  gdb::unique_xmalloc_ptr<char> m_last_source_file;
 
   /* E.g., DW_AT_comp_dir if DWARF.  Space for this is malloc'd.  */
-  char *comp_dir;
+  gdb::unique_xmalloc_ptr<char> comp_dir;
 
   /* Space for this is not malloc'd, and is assumed to have at least
      the same lifetime as objfile.  */
-  const char *producer;
+  const char *producer = nullptr;
 
   /* Space for this is not malloc'd, and is assumed to have at least
      the same lifetime as objfile.  */
-  const char *debugformat;
+  const char *debugformat = nullptr;
 
   /* The compunit we are building.  */
-  struct compunit_symtab *compunit_symtab;
+  struct compunit_symtab *compunit_symtab = nullptr;
+
+  /* Language of this compunit_symtab.  */
+  enum language language;
+
+  /* The macro table for the compilation unit whose symbols we're
+     currently reading.  */
+  struct macro_table *m_pending_macros = nullptr;
+
+  /* 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.
@@ -139,11 +215,6 @@ static struct buildsym_compunit *buildsym_compunit;
 
 static struct pending *free_pendings;
 
-/* Non-zero if symtab has line number info.  This prevents an
-   otherwise empty symtab from being tossed.  */
-
-static int have_line_numbers;
-
 /* The mutable address map for the compilation unit whose symbols
    we're currently reading.  The symtabs' shared blockvector will
    point to a fixed copy of this.  */
@@ -180,17 +251,9 @@ struct pending_block
 
 static struct pending_block *pending_blocks;
 
-struct subfile_stack
-  {
-    struct subfile_stack *next;
-    char *name;
-  };
-
-static struct subfile_stack *subfile_stack;
+/* Currently allocated size of context stack.  */
 
-/* The macro table for the compilation unit whose symbols we're
-   currently reading.  */
-static struct macro_table *pending_macros;
+static int context_stack_size;
 
 static void free_buildsym_compunit (void);
 
@@ -200,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.  */
@@ -268,15 +333,18 @@ find_symbol_in_list (struct pending *list, char *name, int length)
   return (NULL);
 }
 
-/* At end of reading syms, or in case of quit, ensure everything associated
-   with building symtabs is freed.  This is intended to be registered as a
-   cleanup before doing psymtab->symtab expansion.
+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.
 
    N.B. This is *not* intended to be used when building psymtabs.  Some debug
    info readers call this anyway, which is harmless if confusing.  */
 
-void
-really_free_pendings (void *dummy)
+scoped_free_pendings::~scoped_free_pendings ()
 {
   struct pending *next, *next1;
 
@@ -303,10 +371,6 @@ really_free_pendings (void *dummy)
     }
   global_symbols = NULL;
 
-  if (pending_macros)
-    free_macro_table (pending_macros);
-  pending_macros = NULL;
-
   if (pending_addrmap)
     obstack_free (&pending_addrmap_obstack, NULL);
   pending_addrmap = NULL;
@@ -316,8 +380,8 @@ really_free_pendings (void *dummy)
 
 /* This function is called to discard any pending blocks.  */
 
-void
-free_pending_blocks (void)
+static void
+free_pending_blocks ()
 {
   if (pending_blocks != NULL)
     {
@@ -351,20 +415,23 @@ finish_block_internal (struct symbol *symbol,
 
   if (symbol)
     {
-      BLOCK_DICT (block) = dict_create_linear (&objfile->objfile_obstack,
-                                              *listhead);
+      BLOCK_DICT (block)
+       = dict_create_linear (&objfile->objfile_obstack,
+                             buildsym_compunit->language, *listhead);
     }
   else
     {
       if (expandable)
        {
-         BLOCK_DICT (block) = dict_create_hashed_expandable ();
+         BLOCK_DICT (block)
+           = dict_create_hashed_expandable (buildsym_compunit->language);
          dict_add_pending (BLOCK_DICT (block), *listhead);
        }
       else
        {
          BLOCK_DICT (block) =
-           dict_create_hashed (&objfile->objfile_obstack, *listhead);
+           dict_create_hashed (&objfile->objfile_obstack,
+                               buildsym_compunit->language, *listhead);
        }
     }
 
@@ -444,15 +511,13 @@ finish_block_internal (struct symbol *symbol,
     {
       if (symbol)
        {
-         complaint (&symfile_complaints,
-                    _("block end address less than block "
+         complaint (_("block end address less than block "
                       "start address in %s (patched it)"),
                     SYMBOL_PRINT_NAME (symbol));
        }
       else
        {
-         complaint (&symfile_complaints,
-                    _("block end address %s less than block "
+         complaint (_("block end address %s less than block "
                       "start address %s (patched it)"),
                     paddress (gdbarch, BLOCK_END (block)),
                     paddress (gdbarch, BLOCK_START (block)));
@@ -484,14 +549,12 @@ finish_block_internal (struct symbol *symbol,
            {
              if (symbol)
                {
-                 complaint (&symfile_complaints,
-                            _("inner block not inside outer block in %s"),
+                 complaint (_("inner block not inside outer block in %s"),
                             SYMBOL_PRINT_NAME (symbol));
                }
              else
                {
-                 complaint (&symfile_complaints,
-                            _("inner block (%s-%s) not "
+                 complaint (_("inner block (%s-%s) not "
                               "inside outer block (%s-%s)"),
                             paddress (gdbarch, BLOCK_START (pblock->block)),
                             paddress (gdbarch, BLOCK_END (pblock->block)),
@@ -652,7 +715,7 @@ make_blockvector (void)
              CORE_ADDR start
                = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i));
 
-             complaint (&symfile_complaints, _("block at %s out of order"),
+             complaint (_("block at %s out of order"),
                         hex_string ((LONGEST) start));
            }
        }
@@ -673,7 +736,7 @@ start_subfile (const char *name)
 
   gdb_assert (buildsym_compunit != NULL);
 
-  subfile_dirname = buildsym_compunit->comp_dir;
+  subfile_dirname = buildsym_compunit->comp_dir.get ();
 
   /* See if this subfile is already registered.  */
 
@@ -762,52 +825,14 @@ start_subfile (const char *name)
     }
 }
 
-/* Start recording information about a primary source file (IOW, not an
-   included source file).
-   COMP_DIR is the directory in which the compilation unit was compiled
-   (or NULL if not known).  */
-
-static struct buildsym_compunit *
-start_buildsym_compunit (struct objfile *objfile, const char *comp_dir)
-{
-  struct buildsym_compunit *bscu;
-
-  bscu = XNEW (struct buildsym_compunit);
-  memset (bscu, 0, sizeof (struct buildsym_compunit));
-
-  bscu->objfile = objfile;
-  bscu->comp_dir = (comp_dir == NULL) ? NULL : xstrdup (comp_dir);
-
-  /* Initialize the debug format string to NULL.  We may supply it
-     later via a call to record_debugformat.  */
-  bscu->debugformat = NULL;
-
-  /* Similarly for the producer.  */
-  bscu->producer = NULL;
-
-  return bscu;
-}
-
 /* Delete the buildsym compunit.  */
 
 static void
 free_buildsym_compunit (void)
 {
-  struct subfile *subfile, *nextsub;
-
   if (buildsym_compunit == NULL)
     return;
-  for (subfile = buildsym_compunit->subfiles;
-       subfile != NULL;
-       subfile = nextsub)
-    {
-      nextsub = subfile->next;
-      xfree (subfile->name);
-      xfree (subfile->line_vector);
-      xfree (subfile);
-    }
-  xfree (buildsym_compunit->comp_dir);
-  xfree (buildsym_compunit);
+  delete buildsym_compunit;
   buildsym_compunit = NULL;
   current_subfile = NULL;
 }
@@ -825,14 +850,14 @@ free_buildsym_compunit (void)
    directory name actually is (by checking for a trailing '/').  */
 
 void
-patch_subfile_names (struct subfile *subfile, char *name)
+patch_subfile_names (struct subfile *subfile, const char *name)
 {
   if (subfile != NULL
       && buildsym_compunit->comp_dir == NULL
       && subfile->name != NULL
       && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
     {
-      buildsym_compunit->comp_dir = subfile->name;
+      buildsym_compunit->comp_dir.reset (subfile->name);
       subfile->name = xstrdup (name);
       set_last_source_file (name);
 
@@ -862,35 +887,21 @@ patch_subfile_names (struct subfile *subfile, 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
@@ -915,7 +926,7 @@ record_line (struct subfile *subfile, int line, CORE_ADDR pc)
        xmalloc (sizeof (struct linetable)
           + subfile->line_vector_length * sizeof (struct linetable_entry));
       subfile->line_vector->nitems = 0;
-      have_line_numbers = 1;
+      buildsym_compunit->m_have_line_numbers = true;
     }
 
   if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
@@ -995,17 +1006,7 @@ get_macro_table (void)
   struct objfile *objfile;
 
   gdb_assert (buildsym_compunit != NULL);
-
-  objfile = buildsym_compunit->objfile;
-
-  if (! pending_macros)
-    {
-      pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack,
-                                       objfile->per_bfd->macro_cache,
-                                       buildsym_compunit->compunit_symtab);
-    }
-
-  return pending_macros;
+  return buildsym_compunit->get_macro_table ();
 }
 \f
 /* Init state to prepare for building a symtab.
@@ -1014,26 +1015,21 @@ get_macro_table (void)
    buildsym_init.  */
 
 static void
-prepare_for_building (const char *name, CORE_ADDR start_addr)
+prepare_for_building ()
 {
-  set_last_source_file (name);
-  last_source_start_addr = start_addr;
-
   local_symbols = NULL;
   local_using_directives = NULL;
-  within_function = 0;
-  have_line_numbers = 0;
 
   context_stack_depth = 0;
 
   /* These should have been reset either by successful completion of building
-     a symtab, or by the really_free_pendings cleanup.  */
+     a symtab, or by the scoped_free_pendings destructor.  */
   gdb_assert (file_symbols == NULL);
   gdb_assert (global_symbols == NULL);
   gdb_assert (global_using_directives == NULL);
-  gdb_assert (pending_macros == NULL);
   gdb_assert (pending_addrmap == NULL);
   gdb_assert (current_subfile == NULL);
+  gdb_assert (buildsym_compunit == nullptr);
 }
 
 /* Start a new symtab for a new source file in OBJFILE.  Called, for example,
@@ -1041,17 +1037,21 @@ prepare_for_building (const char *name, CORE_ADDR start_addr)
    TAG_compile_unit DIE is seen.  It indicates the start of data for
    one original source file.
 
-   NAME is the name of the file (cannot be NULL).  COMP_DIR is the directory in
-   which the file was compiled (or NULL if not known).  START_ADDR is the
-   lowest address of objects in the file (or 0 if not known).  */
+   NAME is the name of the file (cannot be NULL).  COMP_DIR is the
+   directory in which the file was compiled (or NULL if not known).
+   START_ADDR is the lowest address of objects in the file (or 0 if
+   not known).  LANGUAGE is the language of the source file, or
+   language_unknown if not known, in which case it'll be deduced from
+   the filename.  */
 
 struct compunit_symtab *
 start_symtab (struct objfile *objfile, const char *name, const char *comp_dir,
-             CORE_ADDR start_addr)
+             CORE_ADDR start_addr, enum language language)
 {
-  prepare_for_building (name, start_addr);
+  prepare_for_building ();
 
-  buildsym_compunit = start_buildsym_compunit (objfile, comp_dir);
+  buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir,
+                                                   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.  */
@@ -1085,10 +1085,14 @@ void
 restart_symtab (struct compunit_symtab *cust,
                const char *name, CORE_ADDR start_addr)
 {
-  prepare_for_building (name, start_addr);
-
-  buildsym_compunit = start_buildsym_compunit (COMPUNIT_OBJFILE (cust),
-                                              COMPUNIT_DIRNAME (cust));
+  prepare_for_building ();
+
+  buildsym_compunit
+    = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust),
+                                   name,
+                                   COMPUNIT_DIRNAME (cust),
+                                   compunit_language (cust),
+                                   start_addr);
   buildsym_compunit->compunit_symtab = cust;
 }
 
@@ -1165,40 +1169,21 @@ watch_main_source_file_lossage (void)
     }
 }
 
-/* Helper function for qsort.  Parameters are `struct block *' pointers,
-   function sorts them in descending order by their BLOCK_START.  */
-
-static int
-block_compar (const void *ap, const void *bp)
-{
-  const struct block *a = *(const struct block **) ap;
-  const struct block *b = *(const struct block **) bp;
-
-  return ((BLOCK_START (b) > BLOCK_START (a))
-         - (BLOCK_START (b) < BLOCK_START (a)));
-}
-
 /* Reset state after a successful building of a symtab.
    This exists because dbxread.c and xcoffread.c can call
    start_symtab+end_symtab multiple times after one call to buildsym_init,
-   and before the really_free_pendings cleanup is called.
+   and before the scoped_free_pendings destructor is called.
    We keep the free_pendings list around for dbx/xcoff sake.  */
 
 static void
 reset_symtab_globals (void)
 {
-  set_last_source_file (NULL);
-
   local_symbols = NULL;
   local_using_directives = NULL;
   file_symbols = NULL;
   global_symbols = NULL;
   global_using_directives = NULL;
 
-  /* We don't free pending_macros here because if the symtab was successfully
-     built then ownership was transferred to the symtab.  */
-  pending_macros = NULL;
-
   if (pending_addrmap)
     obstack_free (&pending_addrmap_obstack, NULL);
   pending_addrmap = NULL;
@@ -1243,8 +1228,7 @@ end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required)
             same.  FIXME: Find out why it is happening.  This is not
             believed to happen in most cases (even for coffread.c);
             it used to be an abort().  */
-         complaint (&symfile_complaints,
-                    _("Context stack not empty in end_symtab"));
+         complaint (_("Context stack not empty in end_symtab"));
          context_stack_depth = 0;
        }
     }
@@ -1254,28 +1238,25 @@ end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required)
 
   if ((objfile->flags & OBJF_REORDERED) && pending_blocks)
     {
-      unsigned count = 0;
       struct pending_block *pb;
-      struct block **barray, **bp;
-      struct cleanup *back_to;
 
-      for (pb = pending_blocks; pb != NULL; pb = pb->next)
-       count++;
+      std::vector<block *> barray;
 
-      barray = XNEWVEC (struct block *, count);
-      back_to = make_cleanup (xfree, barray);
-
-      bp = barray;
       for (pb = pending_blocks; pb != NULL; pb = pb->next)
-       *bp++ = pb->block;
-
-      qsort (barray, count, sizeof (*barray), block_compar);
-
-      bp = barray;
+       barray.push_back (pb->block);
+
+      /* Sort blocks by start address in descending order.  Blocks with the
+        same start address must remain in the original order to preserve
+        inline function caller/callee relationships.  */
+      std::stable_sort (barray.begin (), barray.end (),
+                       [] (const block *a, const block *b)
+                       {
+                         return BLOCK_START (a) > BLOCK_START (b);
+                       });
+
+      int i = 0;
       for (pb = pending_blocks; pb != NULL; pb = pb->next)
-       pb->block = *bp++;
-
-      do_cleanups (back_to);
+       pb->block = barray[i++];
     }
 
   /* Cleanup any undefined types that have been left hanging around
@@ -1295,8 +1276,8 @@ end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required)
       && pending_blocks == NULL
       && file_symbols == NULL
       && global_symbols == NULL
-      && have_line_numbers == 0
-      && pending_macros == NULL
+      && !buildsym_compunit->m_have_line_numbers
+      && buildsym_compunit->m_pending_macros == NULL
       && global_using_directives == NULL)
     {
       /* Ignore symtabs that have no functions with real debugging info.  */
@@ -1306,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);
     }
 }
 
@@ -1334,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 ();
 
@@ -1428,10 +1409,10 @@ end_symtab_with_blockvector (struct block *static_block,
   if (buildsym_compunit->comp_dir != NULL)
     {
       /* Reallocate the dirname on the symbol obstack.  */
+      const char *comp_dir = buildsym_compunit->comp_dir.get ();
       COMPUNIT_DIRNAME (cu)
        = (const char *) obstack_copy0 (&objfile->objfile_obstack,
-                                       buildsym_compunit->comp_dir,
-                                       strlen (buildsym_compunit->comp_dir));
+                                       comp_dir, strlen (comp_dir));
     }
 
   /* Save the debug format string (if any) in the symtab.  */
@@ -1449,7 +1430,7 @@ end_symtab_with_blockvector (struct block *static_block,
 
   COMPUNIT_BLOCK_LINE_SECTION (cu) = section;
 
-  COMPUNIT_MACRO_TABLE (cu) = pending_macros;
+  COMPUNIT_MACRO_TABLE (cu) = buildsym_compunit->release_macros ();
 
   /* Default any symbols without a specified symtab to the primary symtab.  */
   {
@@ -1594,17 +1575,15 @@ augment_type_symtab (void)
 
   if (context_stack_depth > 0)
     {
-      complaint (&symfile_complaints,
-                _("Context stack not empty in augment_type_symtab"));
+      complaint (_("Context stack not empty in augment_type_symtab"));
       context_stack_depth = 0;
     }
   if (pending_blocks != NULL)
-    complaint (&symfile_complaints, _("Blocks in a type symtab"));
-  if (pending_macros != NULL)
-    complaint (&symfile_complaints, _("Macro in a type symtab"));
-  if (have_line_numbers)
-    complaint (&symfile_complaints,
-              _("Line numbers recorded in a type symtab"));
+    complaint (_("Blocks in a type symtab"));
+  if (buildsym_compunit->m_pending_macros != NULL)
+    complaint (_("Macro in a type symtab"));
+  if (buildsym_compunit->m_have_line_numbers)
+    complaint (_("Line numbers recorded in a type symtab"));
 
   if (file_symbols != NULL)
     {
@@ -1674,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)
 {
@@ -1695,56 +1665,44 @@ 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.
+\f
 
-   Void return.  */
+/* See buildsym.h.  */
 
 void
-merge_symbol_lists (struct pending **srclist, struct pending **targetlist)
+set_last_source_file (const char *name)
 {
-  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);
+  gdb_assert (buildsym_compunit != nullptr || name == nullptr);
+  if (buildsym_compunit != nullptr)
+    buildsym_compunit->set_last_source_file (name);
 }
-\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.  */
+/* See buildsym.h.  */
 
-static char *last_source_file;
+const char *
+get_last_source_file (void)
+{
+  if (buildsym_compunit == nullptr)
+    return nullptr;
+  return buildsym_compunit->m_last_source_file.get ();
+}
 
 /* See buildsym.h.  */
 
 void
-set_last_source_file (const char *name)
+set_last_source_start_addr (CORE_ADDR addr)
 {
-  xfree (last_source_file);
-  last_source_file = name == NULL ? NULL : xstrdup (name);
+  gdb_assert (buildsym_compunit != nullptr);
+  buildsym_compunit->m_last_source_start_addr = addr;
 }
 
 /* See buildsym.h.  */
 
-const char *
-get_last_source_file (void)
+CORE_ADDR
+get_last_source_start_addr ()
 {
-  return last_source_file;
+  gdb_assert (buildsym_compunit != nullptr);
+  return buildsym_compunit->m_last_source_start_addr;
 }
 
 \f
@@ -1754,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
@@ -1768,24 +1724,13 @@ buildsym_init (void)
       context_stack = XNEWVEC (struct context_stack, context_stack_size);
     }
 
-  /* Ensure the really_free_pendings cleanup was called after
+  /* Ensure the scoped_free_pendings destructor was called after
      the last time.  */
   gdb_assert (free_pendings == NULL);
   gdb_assert (pending_blocks == NULL);
   gdb_assert (file_symbols == NULL);
   gdb_assert (global_symbols == NULL);
   gdb_assert (global_using_directives == NULL);
-  gdb_assert (pending_macros == NULL);
   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.035884 seconds and 4 git commands to generate.