Automatic date update in version.in
[deliverable/binutils-gdb.git] / gdb / coffread.c
index 0b0cbace6ba709b71fa2b70b1d6e2946b5132b9e..0135363bc5a5d98d29bb84f4435d7a3fdc7a2383 100644 (file)
@@ -1,5 +1,5 @@
 /* Read coff symbol tables and convert to internal format, for GDB.
-   Copyright (C) 1987-2018 Free Software Foundation, Inc.
+   Copyright (C) 1987-2021 Free Software Foundation, Inc.
    Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu).
 
    This file is part of GDB.
 #include "coff/internal.h"     /* Internal format of COFF symbols in BFD */
 #include "libcoff.h"           /* FIXME secret internal data from BFD */
 #include "objfiles.h"
-#include "buildsym.h"
-#include "gdb-stabs.h"
+#include "buildsym-legacy.h"
 #include "stabsread.h"
 #include "complaints.h"
 #include "target.h"
 #include "block.h"
 #include "dictionary.h"
+#include "dwarf2/public.h"
 
 #include "coff-pe-read.h"
 
 #include "psymtab.h"
 #include "build-id.h"
 
-/* Key for COFF-associated data.  */
-
-static const struct objfile_data *coff_objfile_data_key;
-
 /* The objfile we are currently reading.  */
 
 static struct objfile *coffread_objfile;
 
 struct coff_symfile_info
   {
-    file_ptr min_lineno_offset;        /* Where in file lowest line#s are.  */
-    file_ptr max_lineno_offset;        /* 1+last byte of line#s in file.  */
-
-    CORE_ADDR textaddr;                /* Addr of .text section.  */
-    unsigned int textsize;     /* Size of .text section.  */
-    struct stab_section_list *stabsects;       /* .stab sections.  */
-    asection *stabstrsect;     /* Section pointer for .stab section.  */
-    char *stabstrdata;
+    file_ptr min_lineno_offset = 0;    /* Where in file lowest line#s are.  */
+    file_ptr max_lineno_offset = 0;    /* 1+last byte of line#s in file.  */
+
+    CORE_ADDR textaddr = 0;            /* Addr of .text section.  */
+    unsigned int textsize = 0; /* Size of .text section.  */
+    std::vector<asection *> *stabsects;        /* .stab sections.  */
+    asection *stabstrsect = nullptr;   /* Section pointer for .stab section.  */
+    char *stabstrdata = nullptr;
   };
 
+/* Key for COFF-associated data.  */
+
+static const struct objfile_key<coff_symfile_info> coff_objfile_data_key;
+
 /* Translate an external name string into a user-visible name.  */
 #define        EXTERNAL_NAME(string, abfd) \
        (string[0] == bfd_get_symbol_leading_char (abfd) \
@@ -155,6 +155,12 @@ static int type_vector_length;
 
 #define INITIAL_TYPE_VECTOR_LENGTH 160
 
+static char *linetab = NULL;
+static file_ptr linetab_offset;
+static file_ptr linetab_size;
+
+static char *stringtab = NULL;
+
 extern void stabsread_clear_cache (void);
 
 static struct type *coff_read_struct_type (int, int, int,
@@ -183,31 +189,23 @@ static struct symbol *process_coff_symbol (struct coff_symbol *,
 
 static void patch_opaque_types (struct symtab *);
 
-static void enter_linenos (long, int, int, struct objfile *);
-
-static void free_linetab (void);
-
-static void free_linetab_cleanup (void *ignore);
+static void enter_linenos (file_ptr, int, int, struct objfile *);
 
-static int init_lineno (bfd *, long, int);
+static int init_lineno (bfd *, file_ptr, file_ptr, gdb::unique_xmalloc_ptr<char> *);
 
 static char *getsymname (struct internal_syment *);
 
 static const char *coff_getfilename (union internal_auxent *);
 
-static void free_stringtab (void);
-
-static void free_stringtab_cleanup (void *ignore);
-
-static int init_stringtab (bfd *, long);
+static int init_stringtab (bfd *, file_ptr, gdb::unique_xmalloc_ptr<char> *);
 
 static void read_one_sym (struct coff_symbol *,
                          struct internal_syment *,
                          union internal_auxent *);
 
 static void coff_symtab_read (minimal_symbol_reader &,
-                             long, unsigned int, struct objfile *);
-\f
+                             file_ptr, unsigned int, struct objfile *);
+
 /* We are called once per section from coff_symfile_read.  We
    need to examine each section we are passed, check to see
    if it is something we are interested in processing, and
@@ -225,15 +223,15 @@ coff_locate_sections (bfd *abfd, asection *sectp, void *csip)
   const char *name;
 
   csi = (struct coff_symfile_info *) csip;
-  name = bfd_get_section_name (abfd, sectp);
+  name = bfd_section_name (sectp);
   if (strcmp (name, ".text") == 0)
     {
-      csi->textaddr = bfd_section_vma (abfd, sectp);
-      csi->textsize += bfd_section_size (abfd, sectp);
+      csi->textaddr = bfd_section_vma (sectp);
+      csi->textsize += bfd_section_size (sectp);
     }
   else if (startswith (name, ".text"))
     {
-      csi->textsize += bfd_section_size (abfd, sectp);
+      csi->textsize += bfd_section_size (sectp);
     }
   else if (strcmp (name, ".stabstr") == 0)
     {
@@ -244,26 +242,12 @@ coff_locate_sections (bfd *abfd, asection *sectp, void *csip)
       const char *s;
 
       /* We can have multiple .stab sections if linked with
-         --split-by-reloc.  */
+        --split-by-reloc.  */
       for (s = name + sizeof ".stab" - 1; *s != '\0'; s++)
        if (!isdigit (*s))
          break;
       if (*s == '\0')
-       {
-         struct stab_section_list *n, **pn;
-
-         n = XNEW (struct stab_section_list);
-         n->section = sectp;
-         n->next = NULL;
-         for (pn = &csi->stabsects; *pn != NULL; pn = &(*pn)->next)
-           ;
-         *pn = n;
-
-         /* This will be run after coffstab_build_psymtabs is called
-            in coff_symfile_read, at which point we no longer need
-            the information.  */
-         make_cleanup (xfree, n);
-       }
+       csi->stabsects->push_back (sectp);
     }
 }
 
@@ -324,7 +308,7 @@ cs_section_address (struct coff_symbol *cs, bfd *abfd)
   args.resultp = &sect;
   bfd_map_over_sections (abfd, find_targ_sec, &args);
   if (sect != NULL)
-    addr = bfd_get_section_vma (abfd, sect);
+    addr = bfd_section_vma (sect);
   return addr;
 }
 
@@ -383,11 +367,9 @@ coff_alloc_type (int index)
 static void
 coff_start_symtab (struct objfile *objfile, const char *name)
 {
+  within_function = 0;
   start_symtab (objfile,
-  /* We fill in the filename later.  start_symtab puts this pointer
-     into last_source_file and we put it in subfiles->name, which
-     end_symtab frees; that's why it must be malloc'd.  */
-                xstrdup (name),
+               name,
   /* We never know the directory name for COFF.  */
                 NULL,
   /* The start address is irrelevant, since we call
@@ -436,7 +418,7 @@ static int
 is_import_fixup_symbol (struct coff_symbol *cs,
                        enum minimal_symbol_type type)
 {
-  /* The following is a bit of a heuristic using the characterictics
+  /* The following is a bit of a heuristic using the characteristics
      of these fixup symbols, but should work well in practice...  */
   int i;
 
@@ -475,13 +457,13 @@ record_minimal_symbol (minimal_symbol_reader &reader,
     {
       /* Because the value of these symbols is within a function code
         range, these symbols interfere with the symbol-from-address
-        reverse lookup; this manifests itselfs in backtraces, or any
+        reverse lookup; this manifests itself in backtraces, or any
         other commands that prints symbolic addresses.  Just pretend
         these symbols do not exist.  */
       return NULL;
     }
 
-  return reader.record_with_info (cs->c_name, address, type, section);
+  return reader.record_full (cs->c_name, true, address, type, section);
 }
 \f
 /* coff_symfile_init ()
@@ -501,16 +483,8 @@ record_minimal_symbol (minimal_symbol_reader &reader,
 static void
 coff_symfile_init (struct objfile *objfile)
 {
-  struct dbx_symfile_info *dbx;
-  struct coff_symfile_info *coff;
-
-  /* Allocate struct to keep track of stab reading.  */
-  dbx = XCNEW (struct dbx_symfile_info);
-  set_objfile_data (objfile, dbx_objfile_data_key, dbx);
-
   /* Allocate struct to keep track of the symfile.  */
-  coff = XCNEW (struct coff_symfile_info);
-  set_objfile_data (objfile, coff_objfile_data_key, coff);
+  coff_objfile_data_key.emplace (objfile);
 
   /* COFF objects may be reordered, so set OBJF_REORDERED.  If we
      find this causes a significant slowdown in gdb then we could
@@ -564,18 +538,20 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
   struct coff_symfile_info *info;
   bfd *abfd = objfile->obfd;
   coff_data_type *cdata = coff_data (abfd);
-  char *name = bfd_get_filename (abfd);
+  const char *filename = bfd_get_filename (abfd);
   int val;
   unsigned int num_symbols;
-  int symtab_offset;
-  int stringtab_offset;
-  struct cleanup *back_to;
-  int stabstrsize;
+  file_ptr symtab_offset;
+  file_ptr stringtab_offset;
+  unsigned int stabstrsize;
   
-  info = (struct coff_symfile_info *) objfile_data (objfile,
-                                                   coff_objfile_data_key);
+  info = coff_objfile_data_key.get (objfile);
   symfile_bfd = abfd;          /* Kludge for swap routines.  */
 
+  std::vector<asection *> stabsects;
+  scoped_restore restore_stabsects
+    = make_scoped_restore (&info->stabsects, &stabsects);
+
 /* WARNING WILL ROBINSON!  ACCESSING BFD-PRIVATE DATA HERE!  FIXME!  */
   num_symbols = bfd_get_symcount (abfd);       /* How many syms */
   symtab_offset = cdata->sym_filepos;  /* Symbol table file offset */
@@ -594,10 +570,10 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 
   /* Allocate space for raw symbol and aux entries, based on their
      space requirements as reported by BFD.  */
-  temp_sym = (char *) xmalloc
-    (cdata->local_symesz + cdata->local_auxesz);
+  gdb::def_vector<char> temp_storage (cdata->local_symesz
+                                     + cdata->local_auxesz);
+  temp_sym = temp_storage.data ();
   temp_aux = temp_sym + cdata->local_symesz;
-  back_to = make_cleanup (free_current_contents, &temp_sym);
 
   /* We need to know whether this is a PE file, because in PE files,
      unlike standard COFF files, symbol values are stored as offsets
@@ -627,24 +603,27 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
      can avoid spurious error messages (and maybe run a little
      faster!) by not even reading the line number table unless we have
      symbols.  */
+  scoped_restore restore_linetab = make_scoped_restore (&linetab);
+  gdb::unique_xmalloc_ptr<char> linetab_storage;
   if (num_symbols > 0)
     {
       /* Read the line number table, all at once.  */
       bfd_map_over_sections (abfd, find_linenos, (void *) info);
 
-      make_cleanup (free_linetab_cleanup, 0 /*ignore*/);
       val = init_lineno (abfd, info->min_lineno_offset,
-                         info->max_lineno_offset - info->min_lineno_offset);
+                        info->max_lineno_offset - info->min_lineno_offset,
+                        &linetab_storage);
       if (val < 0)
-        error (_("\"%s\": error reading line numbers."), name);
+       error (_("\"%s\": error reading line numbers."), filename);
     }
 
   /* Now read the string table, all at once.  */
 
-  make_cleanup (free_stringtab_cleanup, 0 /*ignore*/);
-  val = init_stringtab (abfd, stringtab_offset);
+  scoped_restore restore_stringtab = make_scoped_restore (&stringtab);
+  gdb::unique_xmalloc_ptr<char> stringtab_storage;
+  val = init_stringtab (abfd, stringtab_offset, &stringtab_storage);
   if (val < 0)
-    error (_("\"%s\": can't get string table"), name);
+    error (_("\"%s\": can't get string table"), filename);
 
   minimal_symbol_reader reader (objfile);
 
@@ -660,11 +639,9 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 
   if (pe_file)
     {
-      struct minimal_symbol *msym;
-
-      ALL_OBJFILE_MSYMBOLS (objfile, msym)
+      for (minimal_symbol *msym : objfile->msymbols ())
        {
-         const char *name = MSYMBOL_LINKAGE_NAME (msym);
+         const char *name = msym->linkage_name ();
 
          /* If the minimal symbols whose name are prefixed by "__imp_"
             or "_imp_", get rid of the prefix, and search the minimal
@@ -683,7 +660,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
                  int lead = bfd_get_symbol_leading_char (objfile->obfd);
                  struct bound_minimal_symbol found;
 
-                  if (lead != '\0' && *name1 == lead)
+                 if (lead != '\0' && *name1 == lead)
                    name1 += 1;
 
                  found = lookup_minimal_symbol (name1, NULL, objfile);
@@ -702,24 +679,24 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
   if (!(objfile->flags & OBJF_READNEVER))
     bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
 
-  if (info->stabsects)
+  if (!info->stabsects->empty())
     {
       if (!info->stabstrsect)
        {
          error (_("The debugging information in `%s' is corrupted.\nThe "
                   "file has a `.stabs' section, but no `.stabstr' section."),
-                name);
+                filename);
        }
 
       /* FIXME: dubious.  Why can't we use something normal like
-         bfd_get_section_contents?  */
+        bfd_get_section_contents?  */
       bfd_seek (abfd, abfd->where, 0);
 
-      stabstrsize = bfd_section_size (abfd, info->stabstrsect);
+      stabstrsize = bfd_section_size (info->stabstrsect);
 
       coffstab_build_psymtabs (objfile,
                               info->textaddr, info->textsize,
-                              info->stabsects,
+                              *info->stabsects,
                               info->stabstrsect->filepos, stabstrsize);
     }
   if (dwarf2_has_info (objfile, NULL))
@@ -731,7 +708,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
   dwarf2_build_frame_info (objfile);
 
   /* Try to add separate debug file if no symbols table found.   */
-  if (!objfile_has_partial_symbols (objfile))
+  if (!objfile->has_partial_symbols ())
     {
       std::string debugfile = find_separate_debug_file_by_buildid (objfile);
 
@@ -740,14 +717,12 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 
       if (!debugfile.empty ())
        {
-         gdb_bfd_ref_ptr abfd (symfile_bfd_open (debugfile.c_str ()));
+         gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (debugfile.c_str ()));
 
-         symbol_file_add_separate (abfd.get (), debugfile.c_str (),
+         symbol_file_add_separate (debug_bfd.get (), debugfile.c_str (),
                                    symfile_flags, objfile);
        }
     }
-
-  do_cleanups (back_to);
 }
 
 static void
@@ -776,11 +751,11 @@ coff_symfile_finish (struct objfile *objfile)
 
 static void
 coff_symtab_read (minimal_symbol_reader &reader,
-                 long symtab_offset, unsigned int nsyms,
+                 file_ptr symtab_offset, unsigned int nsyms,
                  struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
-  struct context_stack *newobj;
+  struct gdbarch *gdbarch = objfile->arch ();
+  struct context_stack *newobj = nullptr;
   struct coff_symbol coff_symbol;
   struct coff_symbol *cs = &coff_symbol;
   static struct internal_syment main_sym;
@@ -803,6 +778,8 @@ coff_symtab_read (minimal_symbol_reader &reader,
   CORE_ADDR tmpaddr;
   struct minimal_symbol *msym;
 
+  scoped_free_pendings free_pending;
+
   /* Work around a stdio bug in SunOS4.1.1 (this makes me nervous....
      it's hard to know I've really worked around it.  The fix should
      be harmless, anyway).  The symptom of the bug is that the first
@@ -820,7 +797,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
   bfd_seek (objfile->obfd, 0, 0);
 
   /* Position to read the symbol table.  */
-  val = bfd_seek (objfile->obfd, (long) symtab_offset, 0);
+  val = bfd_seek (objfile->obfd, symtab_offset, 0);
   if (val < 0)
     perror_with_name (objfile_name (objfile));
 
@@ -854,7 +831,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
             language_unknown, since such a ``file name'' is not
             recognized.  Override that with the minimal language to
             allow printing values in this symtab.  */
-         current_subfile->language = language_minimal;
+         get_current_subfile ()->language = language_minimal;
          complete_symtab ("_globals_", 0, 0);
          /* Done with all files, everything from here on out is
             globals.  */
@@ -874,8 +851,10 @@ coff_symtab_read (minimal_symbol_reader &reader,
          int section = cs_to_section (cs, objfile);
 
          tmpaddr = cs->c_value;
-         record_minimal_symbol (reader, cs, tmpaddr, mst_text,
-                                section, objfile);
+         /* Don't record unresolved symbols.  */
+         if (!(cs->c_secnum <= 0 && cs->c_value == 0))
+           record_minimal_symbol (reader, cs, tmpaddr, mst_text,
+                                  section, objfile);
 
          fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
          fcn_start_addr = tmpaddr;
@@ -941,8 +920,8 @@ coff_symtab_read (minimal_symbol_reader &reader,
                     file with no symbols.  */
                  if (in_source_file)
                    complete_symtab (filestring,
-                   cs->c_value + ANOFFSET (objfile->section_offsets,
-                                           SECT_OFF_TEXT (objfile)),
+                                    (cs->c_value
+                                     + objfile->text_section_offset ()),
                                     main_aux.x_scn.x_scnlen);
                  in_source_file = 0;
                }
@@ -989,26 +968,26 @@ coff_symtab_read (minimal_symbol_reader &reader,
                   symbol lookup which returned no match.  */
                break;
              }
-           else if (cs->c_secnum == N_ABS)
-             {
-               /* Use the correct minimal symbol type (and don't
-                  relocate) for absolute values.  */
-               ms_type = mst_abs;
-               sec = cs_to_section (cs, objfile);
-               tmpaddr = cs->c_value;
-             }
+           else if (cs->c_secnum == N_ABS)
+             {
+               /* Use the correct minimal symbol type (and don't
+                  relocate) for absolute values.  */
+               ms_type = mst_abs;
+               sec = cs_to_section (cs, objfile);
+               tmpaddr = cs->c_value;
+             }
            else
              {
                asection *bfd_section = cs_to_bfd_section (cs, objfile);
 
                sec = cs_to_section (cs, objfile);
                tmpaddr = cs->c_value;
-               /* Statics in a PE file also get relocated.  */
-               if (cs->c_sclass == C_EXT
-                   || cs->c_sclass == C_THUMBEXTFUNC
-                   || cs->c_sclass == C_THUMBEXT
-                   || (pe_file && (cs->c_sclass == C_STAT)))
-                 offset = ANOFFSET (objfile->section_offsets, sec);
+               /* Statics in a PE file also get relocated.  */
+               if (cs->c_sclass == C_EXT
+                   || cs->c_sclass == C_THUMBEXTFUNC
+                   || cs->c_sclass == C_THUMBEXT
+                   || (pe_file && (cs->c_sclass == C_STAT)))
+                 offset = objfile->section_offsets[sec];
 
                if (bfd_section->flags & SEC_CODE)
                  {
@@ -1048,7 +1027,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
                sym = process_coff_symbol
                  (cs, &main_aux, objfile);
                SYMBOL_VALUE (sym) = tmpaddr + offset;
-               SYMBOL_SECTION (sym) = sec;
+               sym->set_section_index (sec);
              }
          }
          break;
@@ -1061,7 +1040,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
              /* Value contains address of first non-init type
                 code.  */
              /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
-                contains line number of '{' }.  */
+                contains line number of '{' }.  */
              if (cs->c_naux != 1)
                complaint (_("`.bf' symbol %d has no aux entry"),
                           cs->c_symnum);
@@ -1069,7 +1048,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
              fcn_first_line_addr = cs->c_value;
 
              /* Might want to check that locals are 0 and
-                context_stack_depth is zero, and complain if not.  */
+                context_stack_depth is zero, and complain if not.  */
 
              depth = 0;
              newobj = push_context (depth, fcn_start_addr);
@@ -1083,11 +1062,11 @@ coff_symtab_read (minimal_symbol_reader &reader,
              if (!within_function)
                error (_("Bad coff function information."));
              /* The value of .ef is the address of epilogue code;
-                not useful for gdb.  */
+                not useful for gdb.  */
              /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
-                contains number of lines to '}' */
+                contains number of lines to '}' */
 
-             if (context_stack_depth <= 0)
+             if (outermost_context_p ())
                {       /* We attempted to pop an empty context stack.  */
                  complaint (_("`.ef' symbol without matching `.bf' "
                               "symbol ignored starting at symnum %d"),
@@ -1096,9 +1075,9 @@ coff_symtab_read (minimal_symbol_reader &reader,
                  break;
                }
 
-             newobj = pop_context ();
+             struct context_stack cstk = pop_context ();
              /* Stack must be empty now.  */
-             if (context_stack_depth > 0 || newobj == NULL)
+             if (!outermost_context_p () || newobj == NULL)
                {
                  complaint (_("Unmatched .ef symbol(s) ignored "
                               "starting at symnum %d"),
@@ -1117,26 +1096,25 @@ coff_symtab_read (minimal_symbol_reader &reader,
                  fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
                }
              /* fcn_first_line is the line number of the opening '{'.
-                Do not record it - because it would affect gdb's idea
-                of the line number of the first statement of the
-                function - except for one-line functions, for which
-                it is also the line number of all the statements and
-                of the closing '}', and for which we do not have any
-                other statement-line-number.  */
+                Do not record it - because it would affect gdb's idea
+                of the line number of the first statement of the
+                function - except for one-line functions, for which
+                it is also the line number of all the statements and
+                of the closing '}', and for which we do not have any
+                other statement-line-number.  */
              if (fcn_last_line == 1)
-               record_line (current_subfile, fcn_first_line,
+               record_line (get_current_subfile (), fcn_first_line,
                             gdbarch_addr_bits_remove (gdbarch,
                                                       fcn_first_line_addr));
              else
                enter_linenos (fcn_line_ptr, fcn_first_line,
                               fcn_last_line, objfile);
 
-             finish_block (newobj->name, &local_symbols, newobj->old_blocks,
-                           NULL, newobj->start_addr,
+             finish_block (cstk.name, cstk.old_blocks,
+                           NULL, cstk.start_addr,
                            fcn_cs_saved.c_value
                            + fcn_aux_saved.x_sym.x_misc.x_fsize
-                           + ANOFFSET (objfile->section_offsets,
-                                       SECT_OFF_TEXT (objfile)));
+                           + objfile->text_section_offset ());
              within_function = 0;
            }
          break;
@@ -1145,13 +1123,12 @@ coff_symtab_read (minimal_symbol_reader &reader,
          if (strcmp (cs->c_name, ".bb") == 0)
            {
              tmpaddr = cs->c_value;
-             tmpaddr += ANOFFSET (objfile->section_offsets,
-                                  SECT_OFF_TEXT (objfile));
+             tmpaddr += objfile->text_section_offset ();
              push_context (++depth, tmpaddr);
            }
          else if (strcmp (cs->c_name, ".eb") == 0)
            {
-             if (context_stack_depth <= 0)
+             if (outermost_context_p ())
                {       /* We attempted to pop an empty context stack.  */
                  complaint (_("`.eb' symbol without matching `.bb' "
                               "symbol ignored starting at symnum %d"),
@@ -1159,25 +1136,23 @@ coff_symtab_read (minimal_symbol_reader &reader,
                  break;
                }
 
-             newobj = pop_context ();
-             if (depth-- != newobj->depth)
+             struct context_stack cstk = pop_context ();
+             if (depth-- != cstk.depth)
                {
                  complaint (_("Mismatched .eb symbol ignored "
                               "starting at symnum %d"),
                             symnum);
                  break;
                }
-             if (local_symbols && context_stack_depth > 0)
+             if (*get_local_symbols () && !outermost_context_p ())
                {
-                 tmpaddr =
-                   cs->c_value + ANOFFSET (objfile->section_offsets,
-                                           SECT_OFF_TEXT (objfile));
+                 tmpaddr = cs->c_value + objfile->text_section_offset ();
                  /* Make a block for the local symbols within.  */
-                 finish_block (0, &local_symbols, newobj->old_blocks, NULL,
-                               newobj->start_addr, tmpaddr);
+                 finish_block (0, cstk.old_blocks, NULL,
+                               cstk.start_addr, tmpaddr);
                }
              /* Now pop locals of block just finished.  */
-             local_symbols = newobj->locals;
+             *get_local_symbols () = cstk.locals;
            }
          break;
 
@@ -1200,11 +1175,11 @@ coff_symtab_read (minimal_symbol_reader &reader,
   /* Patch up any opaque types (references to types that are not defined
      in the file where they are referenced, e.g. "struct foo *bar").  */
   {
-    struct compunit_symtab *cu;
-    struct symtab *s;
-
-    ALL_OBJFILE_FILETABS (objfile, cu, s)
-      patch_opaque_types (s);
+    for (compunit_symtab *cu : objfile->compunits ())
+      {
+       for (symtab *s : compunit_filetabs (cu))
+         patch_opaque_types (s);
+      }
   }
 
   coffread_objfile = NULL;
@@ -1240,7 +1215,7 @@ read_one_sym (struct coff_symbol *cs,
                            sym->n_type, sym->n_sclass,
                            0, cs->c_naux, (char *) aux);
       /* If more than one aux entry, read past it (only the first aux
-         is important).  */
+        is important).  */
       for (i = 1; i < cs->c_naux; i++)
        {
          bytes = bfd_bread (temp_aux, local_auxesz, nlist_bfd_global);
@@ -1295,17 +1270,13 @@ read_one_sym (struct coff_symbol *cs,
 \f
 /* Support for string table handling.  */
 
-static char *stringtab = NULL;
-
 static int
-init_stringtab (bfd *abfd, long offset)
+init_stringtab (bfd *abfd, file_ptr offset, gdb::unique_xmalloc_ptr<char> *storage)
 {
   long length;
   int val;
   unsigned char lengthbuf[4];
 
-  free_stringtab ();
-
   /* If the file is stripped, the offset might be zero, indicating no
      string table.  Just return with `stringtab' set to null.  */
   if (offset == 0)
@@ -1322,7 +1293,8 @@ init_stringtab (bfd *abfd, long offset)
   if (val != sizeof lengthbuf || length < sizeof lengthbuf)
     return 0;
 
-  stringtab = (char *) xmalloc (length);
+  storage->reset ((char *) xmalloc (length));
+  stringtab = storage->get ();
   /* This is in target format (probably not very useful, and not
      currently used), not host format.  */
   memcpy (stringtab, lengthbuf, sizeof lengthbuf);
@@ -1337,20 +1309,6 @@ init_stringtab (bfd *abfd, long offset)
   return 0;
 }
 
-static void
-free_stringtab (void)
-{
-  if (stringtab)
-    xfree (stringtab);
-  stringtab = NULL;
-}
-
-static void
-free_stringtab_cleanup (void *ignore)
-{
-  free_stringtab ();
-}
-
 static char *
 getsymname (struct internal_syment *symbol_entry)
 {
@@ -1360,7 +1318,7 @@ getsymname (struct internal_syment *symbol_entry)
   if (symbol_entry->_n._n_n._n_zeroes == 0)
     {
       /* FIXME: Probably should be detecting corrupt symbol files by
-         seeing whether offset points to within the stringtab.  */
+        seeing whether offset points to within the stringtab.  */
       result = stringtab + symbol_entry->_n._n_n._n_offset;
     }
   else
@@ -1404,24 +1362,19 @@ coff_getfilename (union internal_auxent *aux_entry)
 \f
 /* Support for line number handling.  */
 
-static char *linetab = NULL;
-static long linetab_offset;
-static unsigned long linetab_size;
-
 /* Read in all the line numbers for fast lookups later.  Leave them in
    external (unswapped) format in memory; we'll swap them as we enter
    them into GDB's data structures.  */
 
 static int
-init_lineno (bfd *abfd, long offset, int size)
+init_lineno (bfd *abfd, file_ptr offset, file_ptr size,
+            gdb::unique_xmalloc_ptr<char> *storage)
 {
   int val;
 
   linetab_offset = offset;
   linetab_size = size;
 
-  free_linetab ();
-
   if (size == 0)
     return 0;
 
@@ -1429,9 +1382,10 @@ init_lineno (bfd *abfd, long offset, int size)
     return -1;
 
   /* Allocate the desired table, plus a sentinel.  */
-  linetab = (char *) xmalloc (size + local_linesz);
+  storage->reset ((char *) xmalloc (size + local_linesz));
+  linetab = storage->get ();
 
-  val = bfd_bread (linetab, size, abfd);
+  val = bfd_bread (storage->get (), size, abfd);
   if (val != size)
     return -1;
 
@@ -1441,29 +1395,15 @@ init_lineno (bfd *abfd, long offset, int size)
   return 0;
 }
 
-static void
-free_linetab (void)
-{
-  if (linetab)
-    xfree (linetab);
-  linetab = NULL;
-}
-
-static void
-free_linetab_cleanup (void *ignore)
-{
-  free_linetab ();
-}
-
 #if !defined (L_LNNO32)
 #define L_LNNO32(lp) ((lp)->l_lnno)
 #endif
 
 static void
-enter_linenos (long file_offset, int first_line,
+enter_linenos (file_ptr file_offset, int first_line,
               int last_line, struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   char *rawptr;
   struct internal_lineno lptr;
 
@@ -1471,8 +1411,8 @@ enter_linenos (long file_offset, int first_line,
     return;
   if (file_offset < linetab_offset)
     {
-      complaint (_("Line number pointer %ld lower than start of line numbers"),
-                file_offset);
+      complaint (_("Line number pointer %s lower than start of line numbers"),
+                plongest (file_offset));
       if (file_offset > linetab_size)  /* Too big to be an offset?  */
        return;
       file_offset += linetab_offset;   /* Try reading at that linetab
@@ -1498,9 +1438,8 @@ enter_linenos (long file_offset, int first_line,
       if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line)
        {
          CORE_ADDR addr = lptr.l_addr.l_paddr;
-         addr += ANOFFSET (objfile->section_offsets,
-                           SECT_OFF_TEXT (objfile));
-         record_line (current_subfile,
+         addr += objfile->text_section_offset ();
+         record_line (get_current_subfile (),
                       first_line + L_LNNO32 (&lptr),
                       gdbarch_addr_bits_remove (gdbarch, addr));
        }
@@ -1514,24 +1453,21 @@ patch_type (struct type *type, struct type *real_type)
 {
   struct type *target = TYPE_TARGET_TYPE (type);
   struct type *real_target = TYPE_TARGET_TYPE (real_type);
-  int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field);
+  int field_size = real_target->num_fields () * sizeof (struct field);
 
   TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
-  TYPE_NFIELDS (target) = TYPE_NFIELDS (real_target);
-  TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target,
-                                                     field_size);
+  target->set_num_fields (real_target->num_fields ());
 
-  memcpy (TYPE_FIELDS (target), 
-         TYPE_FIELDS (real_target), 
-         field_size);
+  field *fields = (struct field *) TYPE_ALLOC (target, field_size);
+  memcpy (fields, real_target->fields (), field_size);
+  target->set_fields (fields);
 
-  if (TYPE_NAME (real_target))
+  if (real_target->name ())
     {
       /* The previous copy of TYPE_NAME is allocated by
         process_coff_symbol.  */
-      if (TYPE_NAME (target))
-       xfree ((char*) TYPE_NAME (target));
-      TYPE_NAME (target) = xstrdup (TYPE_NAME (real_target));
+      xfree ((char *) target->name ());
+      target->set_name (xstrdup (real_target->name ()));
     }
 }
 
@@ -1542,7 +1478,7 @@ patch_type (struct type *type, struct type *real_type)
 static void
 patch_opaque_types (struct symtab *s)
 {
-  struct block *b;
+  const struct block *b;
   struct block_iterator iter;
   struct symbol *real_sym;
 
@@ -1551,23 +1487,23 @@ patch_opaque_types (struct symtab *s)
   ALL_BLOCK_SYMBOLS (b, iter, real_sym)
     {
       /* Find completed typedefs to use to fix opaque ones.
-         Remove syms from the chain when their types are stored,
-         but search the whole chain, as there may be several syms
-         from different files with the same name.  */
+        Remove syms from the chain when their types are stored,
+        but search the whole chain, as there may be several syms
+        from different files with the same name.  */
       if (SYMBOL_CLASS (real_sym) == LOC_TYPEDEF
          && SYMBOL_DOMAIN (real_sym) == VAR_DOMAIN
-         && TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR
+         && SYMBOL_TYPE (real_sym)->code () == TYPE_CODE_PTR
          && TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0)
        {
-         const char *name = SYMBOL_LINKAGE_NAME (real_sym);
+         const char *name = real_sym->linkage_name ();
          int hash = hashname (name);
          struct symbol *sym, *prev;
 
          prev = 0;
          for (sym = opaque_type_chain[hash]; sym;)
            {
-             if (name[0] == SYMBOL_LINKAGE_NAME (sym)[0]
-                 && strcmp (name + 1, SYMBOL_LINKAGE_NAME (sym) + 1) == 0)
+             if (name[0] == sym->linkage_name ()[0]
+                 && strcmp (name + 1, sym->linkage_name () + 1) == 0)
                {
                  if (prev)
                    {
@@ -1618,24 +1554,23 @@ process_coff_symbol (struct coff_symbol *cs,
                     union internal_auxent *aux,
                     struct objfile *objfile)
 {
-  struct symbol *sym = allocate_symbol (objfile);
+  struct symbol *sym = new (&objfile->objfile_obstack) symbol;
   char *name;
 
   name = cs->c_name;
   name = EXTERNAL_NAME (name, objfile->obfd);
-  SYMBOL_SET_LANGUAGE (sym, current_subfile->language,
-                      &objfile->objfile_obstack);
-  SYMBOL_SET_NAMES (sym, name, strlen (name), 1, objfile);
+  sym->set_language (get_current_subfile ()->language,
+                    &objfile->objfile_obstack);
+  sym->compute_and_set_names (name, true, objfile->per_bfd);
 
   /* default assumptions */
   SYMBOL_VALUE (sym) = cs->c_value;
   SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
-  SYMBOL_SECTION (sym) = cs_to_section (cs, objfile);
+  sym->set_section_index (cs_to_section (cs, objfile));
 
   if (ISFCN (cs->c_type))
     {
-      SYMBOL_VALUE (sym) += ANOFFSET (objfile->section_offsets,
-                                     SECT_OFF_TEXT (objfile));
+      SYMBOL_VALUE (sym) += objfile->text_section_offset ();
       SYMBOL_TYPE (sym) =
        lookup_function_type (decode_function_type (cs, cs->c_type,
                                                    aux, objfile));
@@ -1643,10 +1578,10 @@ process_coff_symbol (struct coff_symbol *cs,
       SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
       if (cs->c_sclass == C_STAT || cs->c_sclass == C_THUMBSTAT
          || cs->c_sclass == C_THUMBSTATFUNC)
-       add_symbol_to_list (sym, &file_symbols);
+       add_symbol_to_list (sym, get_file_symbols ());
       else if (cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXT
               || cs->c_sclass == C_THUMBEXTFUNC)
-       add_symbol_to_list (sym, &global_symbols);
+       add_symbol_to_list (sym, get_global_symbols ());
     }
   else
     {
@@ -1658,35 +1593,35 @@ process_coff_symbol (struct coff_symbol *cs,
 
        case C_AUTO:
          SYMBOL_ACLASS_INDEX (sym) = LOC_LOCAL;
-         add_symbol_to_list (sym, &local_symbols);
+         add_symbol_to_list (sym, get_local_symbols ());
          break;
 
        case C_THUMBEXT:
        case C_THUMBEXTFUNC:
        case C_EXT:
          SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
-         SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
-         SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
-                                                 SECT_OFF_TEXT (objfile));
-         add_symbol_to_list (sym, &global_symbols);
+         SET_SYMBOL_VALUE_ADDRESS (sym,
+                                   (CORE_ADDR) cs->c_value
+                                   + objfile->section_offsets[SECT_OFF_TEXT (objfile)]);
+         add_symbol_to_list (sym, get_global_symbols ());
          break;
 
        case C_THUMBSTAT:
        case C_THUMBSTATFUNC:
        case C_STAT:
          SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
-         SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
-         SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
-                                                 SECT_OFF_TEXT (objfile));
+         SET_SYMBOL_VALUE_ADDRESS (sym,
+                                   (CORE_ADDR) cs->c_value
+                                   + objfile->section_offsets[SECT_OFF_TEXT (objfile)]);
          if (within_function)
            {
              /* Static symbol of local scope.  */
-             add_symbol_to_list (sym, &local_symbols);
+             add_symbol_to_list (sym, get_local_symbols ());
            }
          else
            {
              /* Static symbol at top level of file.  */
-             add_symbol_to_list (sym, &file_symbols);
+             add_symbol_to_list (sym, get_file_symbols ());
            }
          break;
 
@@ -1696,7 +1631,7 @@ process_coff_symbol (struct coff_symbol *cs,
        case C_REG:
          SYMBOL_ACLASS_INDEX (sym) = coff_register_index;
          SYMBOL_VALUE (sym) = cs->c_value;
-         add_symbol_to_list (sym, &local_symbols);
+         add_symbol_to_list (sym, get_local_symbols ());
          break;
 
        case C_THUMBLABEL:
@@ -1706,14 +1641,14 @@ process_coff_symbol (struct coff_symbol *cs,
        case C_ARG:
          SYMBOL_ACLASS_INDEX (sym) = LOC_ARG;
          SYMBOL_IS_ARGUMENT (sym) = 1;
-         add_symbol_to_list (sym, &local_symbols);
+         add_symbol_to_list (sym, get_local_symbols ());
          break;
 
        case C_REGPARM:
          SYMBOL_ACLASS_INDEX (sym) = coff_register_index;
          SYMBOL_IS_ARGUMENT (sym) = 1;
          SYMBOL_VALUE (sym) = cs->c_value;
-         add_symbol_to_list (sym, &local_symbols);
+         add_symbol_to_list (sym, get_local_symbols ());
          break;
 
        case C_TPDEF:
@@ -1721,10 +1656,10 @@ process_coff_symbol (struct coff_symbol *cs,
          SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
 
          /* If type has no name, give it one.  */
-         if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
+         if (SYMBOL_TYPE (sym)->name () == 0)
            {
-             if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
-                 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
+             if (SYMBOL_TYPE (sym)->code () == TYPE_CODE_PTR
+                 || SYMBOL_TYPE (sym)->code () == TYPE_CODE_FUNC)
                {
                  /* If we are giving a name to a type such as
                     "pointer to foo" or "function returning foo", we
@@ -1747,8 +1682,7 @@ process_coff_symbol (struct coff_symbol *cs,
                  ;
                }
              else
-               TYPE_NAME (SYMBOL_TYPE (sym)) =
-                 xstrdup (SYMBOL_LINKAGE_NAME (sym));
+               SYMBOL_TYPE (sym)->set_name (xstrdup (sym->linkage_name ()));
            }
 
          /* Keep track of any type which points to empty structured
@@ -1757,17 +1691,17 @@ process_coff_symbol (struct coff_symbol *cs,
             not an empty structured type, though; the forward
             references work themselves out via the magic of
             coff_lookup_type.  */
-         if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
+         if (SYMBOL_TYPE (sym)->code () == TYPE_CODE_PTR
              && TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) == 0
-             && TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym)))
-                != TYPE_CODE_UNDEF)
+             && TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))->code ()
+             != TYPE_CODE_UNDEF)
            {
-             int i = hashname (SYMBOL_LINKAGE_NAME (sym));
+             int i = hashname (sym->linkage_name ());
 
              SYMBOL_VALUE_CHAIN (sym) = opaque_type_chain[i];
              opaque_type_chain[i] = sym;
            }
-         add_symbol_to_list (sym, &file_symbols);
+         add_symbol_to_list (sym, get_file_symbols ());
          break;
 
        case C_STRTAG:
@@ -1779,14 +1713,13 @@ process_coff_symbol (struct coff_symbol *cs,
          /* Some compilers try to be helpful by inventing "fake"
             names for anonymous enums, structures, and unions, like
             "~0fake" or ".0fake".  Thanks, but no thanks...  */
-         if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
-           if (SYMBOL_LINKAGE_NAME (sym) != NULL
-               && *SYMBOL_LINKAGE_NAME (sym) != '~'
-               && *SYMBOL_LINKAGE_NAME (sym) != '.')
-             TYPE_NAME (SYMBOL_TYPE (sym)) =
-               concat (SYMBOL_LINKAGE_NAME (sym), (char *)NULL);
-
-         add_symbol_to_list (sym, &file_symbols);
+         if (SYMBOL_TYPE (sym)->name () == 0)
+           if (sym->linkage_name () != NULL
+               && *sym->linkage_name () != '~'
+               && *sym->linkage_name () != '.')
+             SYMBOL_TYPE (sym)->set_name (xstrdup (sym->linkage_name ()));
+
+         add_symbol_to_list (sym, get_file_symbols ());
          break;
 
        default:
@@ -1840,11 +1773,9 @@ decode_type (struct coff_symbol *cs, unsigned int c_type,
          base_type = decode_type (cs, new_c_type, aux, objfile);
          index_type = objfile_type (objfile)->builtin_int;
          range_type
-           = create_static_range_type ((struct type *) NULL,
-                                       index_type, 0, n - 1);
+           = create_static_range_type (NULL, index_type, 0, n - 1);
          type =
-           create_array_type ((struct type *) NULL, 
-                              base_type, range_type);
+           create_array_type (NULL, base_type, range_type);
        }
       return type;
     }
@@ -1900,7 +1831,7 @@ decode_base_type (struct coff_symbol *cs,
                  union internal_auxent *aux, 
                  struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct type *type;
 
   switch (c_type)
@@ -1946,12 +1877,12 @@ decode_base_type (struct coff_symbol *cs,
        {
          /* Anonymous structure type.  */
          type = coff_alloc_type (cs->c_symnum);
-         TYPE_CODE (type) = TYPE_CODE_STRUCT;
-         TYPE_NAME (type) = NULL;
+         type->set_code (TYPE_CODE_STRUCT);
+         type->set_name (NULL);
          INIT_CPLUS_SPECIFIC (type);
          TYPE_LENGTH (type) = 0;
-         TYPE_FIELDS (type) = 0;
-         TYPE_NFIELDS (type) = 0;
+         type->set_fields (nullptr);
+         type->set_num_fields (0);
        }
       else
        {
@@ -1967,11 +1898,11 @@ decode_base_type (struct coff_symbol *cs,
        {
          /* Anonymous union type.  */
          type = coff_alloc_type (cs->c_symnum);
-         TYPE_NAME (type) = NULL;
+         type->set_name (NULL);
          INIT_CPLUS_SPECIFIC (type);
          TYPE_LENGTH (type) = 0;
-         TYPE_FIELDS (type) = 0;
-         TYPE_NFIELDS (type) = 0;
+         type->set_fields (nullptr);
+         type->set_num_fields (0);
        }
       else
        {
@@ -1980,7 +1911,7 @@ decode_base_type (struct coff_symbol *cs,
                                        aux->x_sym.x_fcnary.x_fcn.x_endndx.l,
                                        objfile);
        }
-      TYPE_CODE (type) = TYPE_CODE_UNION;
+      type->set_code (TYPE_CODE_UNION);
       return type;
 
     case T_ENUM:
@@ -1988,11 +1919,11 @@ decode_base_type (struct coff_symbol *cs,
        {
          /* Anonymous enum type.  */
          type = coff_alloc_type (cs->c_symnum);
-         TYPE_CODE (type) = TYPE_CODE_ENUM;
-         TYPE_NAME (type) = NULL;
+         type->set_code (TYPE_CODE_ENUM);
+         type->set_name (NULL);
          TYPE_LENGTH (type) = 0;
-         TYPE_FIELDS (type) = 0;
-         TYPE_NFIELDS (type) = 0;
+         type->set_fields (nullptr);
+         type->set_num_fields (0);
        }
       else
        {
@@ -2056,7 +1987,7 @@ coff_read_struct_type (int index, int length, int lastsym,
   int done = 0;
 
   type = coff_alloc_type (index);
-  TYPE_CODE (type) = TYPE_CODE_STRUCT;
+  type->set_code (TYPE_CODE_STRUCT);
   INIT_CPLUS_SPECIFIC (type);
   TYPE_LENGTH (type) = length;
 
@@ -2077,11 +2008,9 @@ coff_read_struct_type (int index, int length, int lastsym,
          list = newobj;
 
          /* Save the data.  */
-         list->field.name
-           = (const char *) obstack_copy0 (&objfile->objfile_obstack,
-                                           name, strlen (name));
-         FIELD_TYPE (list->field) = decode_type (ms, ms->c_type,
-                                                 &sub_aux, objfile);
+         list->field.name = obstack_strdup (&objfile->objfile_obstack, name);
+         list->field.set_type (decode_type (ms, ms->c_type, &sub_aux,
+                                            objfile));
          SET_FIELD_BITPOS (list->field, 8 * ms->c_value);
          FIELD_BITSIZE (list->field) = 0;
          nfields++;
@@ -2095,11 +2024,9 @@ coff_read_struct_type (int index, int length, int lastsym,
          list = newobj;
 
          /* Save the data.  */
-         list->field.name
-           = (const char *) obstack_copy0 (&objfile->objfile_obstack,
-                                           name, strlen (name));
-         FIELD_TYPE (list->field) = decode_type (ms, ms->c_type,
-                                                 &sub_aux, objfile);
+         list->field.name = obstack_strdup (&objfile->objfile_obstack, name);
+         list->field.set_type (decode_type (ms, ms->c_type, &sub_aux,
+                                            objfile));
          SET_FIELD_BITPOS (list->field, ms->c_value);
          FIELD_BITSIZE (list->field) = sub_aux.x_sym.x_misc.x_lnsz.x_size;
          nfields++;
@@ -2112,14 +2039,14 @@ coff_read_struct_type (int index, int length, int lastsym,
     }
   /* Now create the vector of fields, and record how big it is.  */
 
-  TYPE_NFIELDS (type) = nfields;
-  TYPE_FIELDS (type) = (struct field *)
-    TYPE_ALLOC (type, sizeof (struct field) * nfields);
+  type->set_num_fields (nfields);
+  type->set_fields
+    ((struct field *) TYPE_ALLOC (type, sizeof (struct field) * nfields));
 
   /* Copy the saved-up fields into the field vector.  */
 
   for (n = nfields; list; list = list->next)
-    TYPE_FIELD (type, --n) = list->field;
+    type->field (--n) = list->field;
 
   return type;
 }
@@ -2132,7 +2059,7 @@ static struct type *
 coff_read_enum_type (int index, int length, int lastsym,
                     struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct symbol *sym;
   struct type *type;
   int nsyms = 0;
@@ -2150,9 +2077,9 @@ coff_read_enum_type (int index, int length, int lastsym,
 
   type = coff_alloc_type (index);
   if (within_function)
-    symlist = &local_symbols;
+    symlist = get_local_symbols ();
   else
-    symlist = &file_symbols;
+    symlist = get_file_symbols ();
   osyms = *symlist;
   o_nsyms = osyms ? osyms->nsyms : 0;
 
@@ -2165,11 +2092,10 @@ coff_read_enum_type (int index, int length, int lastsym,
       switch (ms->c_sclass)
        {
        case C_MOE:
-         sym = allocate_symbol (objfile);
+         sym = new (&objfile->objfile_obstack) symbol;
 
-         name = (char *) obstack_copy0 (&objfile->objfile_obstack, name,
-                                        strlen (name));
-         SYMBOL_SET_LINKAGE_NAME (sym, name);
+         name = obstack_strdup (&objfile->objfile_obstack, name);
+         sym->set_linkage_name (name);
          SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
          SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
          SYMBOL_VALUE (sym) = ms->c_value;
@@ -2192,10 +2118,10 @@ coff_read_enum_type (int index, int length, int lastsym,
     TYPE_LENGTH (type) = length;
   else /* Assume ints.  */
     TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
-  TYPE_CODE (type) = TYPE_CODE_ENUM;
-  TYPE_NFIELDS (type) = nsyms;
-  TYPE_FIELDS (type) = (struct field *)
-    TYPE_ALLOC (type, sizeof (struct field) * nsyms);
+  type->set_code (TYPE_CODE_ENUM);
+  type->set_num_fields (nsyms);
+  type->set_fields
+    ((struct field *) TYPE_ALLOC (type, sizeof (struct field) * nsyms));
 
   /* Find the symbols for the values and put them into the type.
      The symbols can be found in the symlist that we put them on
@@ -2216,8 +2142,8 @@ coff_read_enum_type (int index, int length, int lastsym,
          struct symbol *xsym = syms->symbol[j];
 
          SYMBOL_TYPE (xsym) = type;
-         TYPE_FIELD_NAME (type, n) = SYMBOL_LINKAGE_NAME (xsym);
-         SET_FIELD_ENUMVAL (TYPE_FIELD (type, n), SYMBOL_VALUE (xsym));
+         TYPE_FIELD_NAME (type, n) = xsym->linkage_name ();
+         SET_FIELD_ENUMVAL (type->field (n), SYMBOL_VALUE (xsym));
          if (SYMBOL_VALUE (xsym) < 0)
            unsigned_enum = 0;
          TYPE_FIELD_BITSIZE (type, n) = 0;
@@ -2227,7 +2153,7 @@ coff_read_enum_type (int index, int length, int lastsym,
     }
 
   if (unsigned_enum)
-    TYPE_UNSIGNED (type) = 1;
+    type->set_is_unsigned (true);
 
   return type;
 }
@@ -2242,7 +2168,6 @@ static const struct sym_fns coff_sym_fns =
                                   for sym_read() */
   coff_symfile_read,           /* sym_read: read a symbol file into
                                   symtab */
-  NULL,                                /* sym_read_psymbols */
   coff_symfile_finish,         /* sym_finish: finished with file,
                                   cleanup */
   default_symfile_offsets,     /* sym_offsets: xlate external to
@@ -2254,25 +2179,14 @@ static const struct sym_fns coff_sym_fns =
   default_symfile_relocate,    /* sym_relocate: Relocate a debug
                                   section.  */
   NULL,                                /* sym_probe_fns */
-  &psym_functions
 };
 
-/* Free the per-objfile COFF data.  */
-
-static void
-coff_free_info (struct objfile *objfile, void *arg)
-{
-  xfree (arg);
-}
-
+void _initialize_coffread ();
 void
-_initialize_coffread (void)
+_initialize_coffread ()
 {
   add_symtab_fns (bfd_target_coff_flavour, &coff_sym_fns);
 
-  coff_objfile_data_key = register_objfile_data_with_cleanup (NULL,
-                                                             coff_free_info);
-
   coff_register_index
     = register_symbol_register_impl (LOC_REGISTER, &coff_register_funcs);
 }
This page took 0.051847 seconds and 4 git commands to generate.