darwin: Don't use sbrk
[deliverable/binutils-gdb.git] / gdb / coffread.c
index 3b5a968c346b6d13bfcdb2a23e4221d330d9b5d7..30583e1dda46fb6460ee54635b5de176d4aab33e 100644 (file)
@@ -1,5 +1,5 @@
 /* Read coff symbol tables and convert to internal format, for GDB.
-   Copyright (C) 1987-2015 Free Software Foundation, Inc.
+   Copyright (C) 1987-2018 Free Software Foundation, Inc.
    Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu).
 
    This file is part of GDB.
@@ -41,8 +41,7 @@
 #include "coff-pe-read.h"
 
 #include "psymtab.h"
-
-extern void _initialize_coffread (void);
+#include "build-id.h"
 
 /* Key for COFF-associated data.  */
 
@@ -206,7 +205,8 @@ static void read_one_sym (struct coff_symbol *,
                          struct internal_syment *,
                          union internal_auxent *);
 
-static void coff_symtab_read (long, unsigned int, struct objfile *);
+static void coff_symtab_read (minimal_symbol_reader &,
+                             long, unsigned int, struct objfile *);
 \f
 /* We are called once per section from coff_symfile_read.  We
    need to examine each section we are passed, check to see
@@ -252,8 +252,7 @@ coff_locate_sections (bfd *abfd, asection *sectp, void *csip)
        {
          struct stab_section_list *n, **pn;
 
-         n = ((struct stab_section_list *)
-              xmalloc (sizeof (struct stab_section_list)));
+         n = XNEW (struct stab_section_list);
          n->section = sectp;
          n->next = NULL;
          for (pn = &csi->stabsects; *pn != NULL; pn = &(*pn)->next)
@@ -393,7 +392,9 @@ coff_start_symtab (struct objfile *objfile, const char *name)
                 NULL,
   /* The start address is irrelevant, since we set
      last_source_start_addr in coff_end_symtab.  */
-                0);
+                0,
+  /* Let buildsym.c deduce the language for this symtab.  */
+                language_unknown);
   record_debugformat ("COFF");
 }
 
@@ -461,7 +462,8 @@ is_import_fixup_symbol (struct coff_symbol *cs,
 }
 
 static struct minimal_symbol *
-record_minimal_symbol (struct coff_symbol *cs, CORE_ADDR address,
+record_minimal_symbol (minimal_symbol_reader &reader,
+                      struct coff_symbol *cs, CORE_ADDR address,
                       enum minimal_symbol_type type, int section, 
                       struct objfile *objfile)
 {
@@ -479,8 +481,7 @@ record_minimal_symbol (struct coff_symbol *cs, CORE_ADDR address,
       return NULL;
     }
 
-  return prim_record_minimal_symbol_and_info (cs->c_name, address,
-                                             type, section, objfile);
+  return reader.record_with_info (cs->c_name, address, type, section);
 }
 \f
 /* coff_symfile_init ()
@@ -558,10 +559,9 @@ static bfd *symfile_bfd;
 /* Read a symbol file, after initialization by coff_symfile_init.  */
 
 static void
-coff_symfile_read (struct objfile *objfile, int symfile_flags)
+coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 {
   struct coff_symfile_info *info;
-  struct dbx_symfile_info *dbxinfo;
   bfd *abfd = objfile->obfd;
   coff_data_type *cdata = coff_data (abfd);
   char *name = bfd_get_filename (abfd);
@@ -569,11 +569,11 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
   unsigned int num_symbols;
   int symtab_offset;
   int stringtab_offset;
-  struct cleanup *back_to, *cleanup_minimal_symbols;
+  struct cleanup *back_to;
   int stabstrsize;
   
-  info = objfile_data (objfile, coff_objfile_data_key);
-  dbxinfo = DBX_SYMFILE_INFO (objfile);
+  info = (struct coff_symfile_info *) objfile_data (objfile,
+                                                   coff_objfile_data_key);
   symfile_bfd = abfd;          /* Kludge for swap routines.  */
 
 /* WARNING WILL ROBINSON!  ACCESSING BFD-PRIVATE DATA HERE!  FIXME!  */
@@ -646,18 +646,17 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
   if (val < 0)
     error (_("\"%s\": can't get string table"), name);
 
-  init_minimal_symbol_collection ();
-  cleanup_minimal_symbols = make_cleanup_discard_minimal_symbols ();
+  minimal_symbol_reader reader (objfile);
 
   /* Now that the executable file is positioned at symbol table,
      process it and define symbols accordingly.  */
 
-  coff_symtab_read ((long) symtab_offset, num_symbols, objfile);
+  coff_symtab_read (reader, (long) symtab_offset, num_symbols, objfile);
 
   /* Install any minimal symbols that have been collected as the
      current minimal symbols for this objfile.  */
 
-  install_minimal_symbols (objfile);
+  reader.install ();
 
   if (pe_file)
     {
@@ -700,10 +699,8 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
        }
     }
 
-  /* Free the installed minimal symbol data.  */
-  do_cleanups (cleanup_minimal_symbols);
-
-  bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
+  if (!(objfile->flags & OBJF_READNEVER))
+    bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
 
   if (info->stabsects)
     {
@@ -736,17 +733,17 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
   /* Try to add separate debug file if no symbols table found.   */
   if (!objfile_has_partial_symbols (objfile))
     {
-      char *debugfile;
+      std::string debugfile = find_separate_debug_file_by_buildid (objfile);
 
-      debugfile = find_separate_debug_file_by_debuglink (objfile);
-      make_cleanup (xfree, debugfile);
+      if (debugfile.empty ())
+       debugfile = find_separate_debug_file_by_debuglink (objfile);
 
-      if (debugfile)
+      if (!debugfile.empty ())
        {
-         bfd *abfd = symfile_bfd_open (debugfile);
+         gdb_bfd_ref_ptr abfd (symfile_bfd_open (debugfile.c_str ()));
 
-         make_cleanup_bfd_unref (abfd);
-         symbol_file_add_separate (abfd, debugfile, symfile_flags, objfile);
+         symbol_file_add_separate (abfd.get (), debugfile.c_str (),
+                                   symfile_flags, objfile);
        }
     }
 
@@ -769,8 +766,6 @@ coff_symfile_finish (struct objfile *objfile)
 {
   /* Let stabs reader clean up.  */
   stabsread_clear_cache ();
-
-  dwarf2_free_objfile (objfile);
 }
 \f
 
@@ -780,7 +775,8 @@ coff_symfile_finish (struct objfile *objfile)
    We read them one at a time using read_one_sym ().  */
 
 static void
-coff_symtab_read (long symtab_offset, unsigned int nsyms,
+coff_symtab_read (minimal_symbol_reader &reader,
+                 long symtab_offset, unsigned int nsyms,
                  struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
@@ -837,9 +833,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
   if (type_vector)             /* Get rid of previous one.  */
     xfree (type_vector);
   type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
-  type_vector = (struct type **)
-    xmalloc (type_vector_length * sizeof (struct type *));
-  memset (type_vector, 0, type_vector_length * sizeof (struct type *));
+  type_vector = XCNEWVEC (struct type *, type_vector_length);
 
   coff_start_symtab (objfile, "");
 
@@ -880,7 +874,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
          int section = cs_to_section (cs, objfile);
 
          tmpaddr = cs->c_value;
-         record_minimal_symbol (cs, tmpaddr, mst_text,
+         record_minimal_symbol (reader, cs, tmpaddr, mst_text,
                                 section, objfile);
 
          fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
@@ -900,8 +894,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
        case C_LINE:
        case C_ALIAS:
        case C_HIDDEN:
-         complaint (&symfile_complaints,
-                    _("Bad n_sclass for symbol %s"),
+         complaint (_("Bad n_sclass for symbol %s"),
                     cs->c_name);
          break;
 
@@ -932,6 +925,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
             backtraces, so filter them out (from phdm@macqel.be).  */
          if (within_function)
            break;
+         /* Fall through.  */
        case C_STAT:
        case C_THUMBLABEL:
        case C_THUMBSTAT:
@@ -968,7 +962,8 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
            /* At least on a 3b1, gcc generates swbeg and string labels
               that look like this.  Ignore them.  */
            break;
-         /* Fall in for static symbols that don't start with '.'  */
+         /* For static symbols that don't start with '.'...  */
+         /* Fall through.  */
        case C_THUMBEXT:
        case C_THUMBEXTFUNC:
        case C_EXT:
@@ -1040,7 +1035,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
                  ms_type = mst_unknown;
              }
 
-           msym = record_minimal_symbol (cs, tmpaddr, ms_type,
+           msym = record_minimal_symbol (reader, cs, tmpaddr, ms_type,
                                          sec, objfile);
            if (msym)
              gdbarch_coff_make_msymbol_special (gdbarch,
@@ -1068,8 +1063,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
              /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
                 contains line number of '{' }.  */
              if (cs->c_naux != 1)
-               complaint (&symfile_complaints,
-                          _("`.bf' symbol %d has no aux entry"),
+               complaint (_("`.bf' symbol %d has no aux entry"),
                           cs->c_symnum);
              fcn_first_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
              fcn_first_line_addr = cs->c_value;
@@ -1095,8 +1089,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
 
              if (context_stack_depth <= 0)
                {       /* We attempted to pop an empty context stack.  */
-                 complaint (&symfile_complaints,
-                            _("`.ef' symbol without matching `.bf' "
+                 complaint (_("`.ef' symbol without matching `.bf' "
                               "symbol ignored starting at symnum %d"),
                             cs->c_symnum);
                  within_function = 0;
@@ -1107,8 +1100,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
              /* Stack must be empty now.  */
              if (context_stack_depth > 0 || newobj == NULL)
                {
-                 complaint (&symfile_complaints,
-                            _("Unmatched .ef symbol(s) ignored "
+                 complaint (_("Unmatched .ef symbol(s) ignored "
                               "starting at symnum %d"),
                             cs->c_symnum);
                  within_function = 0;
@@ -1116,8 +1108,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
                }
              if (cs->c_naux != 1)
                {
-                 complaint (&symfile_complaints,
-                            _("`.ef' symbol %d has no aux entry"),
+                 complaint (_("`.ef' symbol %d has no aux entry"),
                             cs->c_symnum);
                  fcn_last_line = 0x7FFFFFFF;
                }
@@ -1140,8 +1131,8 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
                enter_linenos (fcn_line_ptr, fcn_first_line,
                               fcn_last_line, objfile);
 
-             finish_block (newobj->name, &local_symbols,
-                           newobj->old_blocks, newobj->start_addr,
+             finish_block (newobj->name, &local_symbols, newobj->old_blocks,
+                           NULL, newobj->start_addr,
                            fcn_cs_saved.c_value
                            + fcn_aux_saved.x_sym.x_misc.x_fsize
                            + ANOFFSET (objfile->section_offsets,
@@ -1162,8 +1153,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
            {
              if (context_stack_depth <= 0)
                {       /* We attempted to pop an empty context stack.  */
-                 complaint (&symfile_complaints,
-                            _("`.eb' symbol without matching `.bb' "
+                 complaint (_("`.eb' symbol without matching `.bb' "
                               "symbol ignored starting at symnum %d"),
                             cs->c_symnum);
                  break;
@@ -1172,8 +1162,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
              newobj = pop_context ();
              if (depth-- != newobj->depth)
                {
-                 complaint (&symfile_complaints,
-                            _("Mismatched .eb symbol ignored "
+                 complaint (_("Mismatched .eb symbol ignored "
                               "starting at symnum %d"),
                             symnum);
                  break;
@@ -1184,7 +1173,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
                    cs->c_value + ANOFFSET (objfile->section_offsets,
                                            SECT_OFF_TEXT (objfile));
                  /* Make a block for the local symbols within.  */
-                 finish_block (0, &local_symbols, newobj->old_blocks,
+                 finish_block (0, &local_symbols, newobj->old_blocks, NULL,
                                newobj->start_addr, tmpaddr);
                }
              /* Now pop locals of block just finished.  */
@@ -1202,7 +1191,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
     {
       /* We've got no debugging symbols, but it's a portable
         executable, so try to read the export table.  */
-      read_pe_exported_syms (objfile);
+      read_pe_exported_syms (reader, objfile);
     }
 
   if (get_last_source_file ())
@@ -1482,8 +1471,7 @@ enter_linenos (long file_offset, int first_line,
     return;
   if (file_offset < linetab_offset)
     {
-      complaint (&symfile_complaints,
-                _("Line number pointer %ld lower than start of line numbers"),
+      complaint (_("Line number pointer %ld lower than start of line numbers"),
                 file_offset);
       if (file_offset > linetab_size)  /* Too big to be an offset?  */
        return;
@@ -1791,11 +1779,11 @@ 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_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
+         if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
            if (SYMBOL_LINKAGE_NAME (sym) != NULL
                && *SYMBOL_LINKAGE_NAME (sym) != '~'
                && *SYMBOL_LINKAGE_NAME (sym) != '.')
-             TYPE_TAG_NAME (SYMBOL_TYPE (sym)) =
+             TYPE_NAME (SYMBOL_TYPE (sym)) =
                concat (SYMBOL_LINKAGE_NAME (sym), (char *)NULL);
 
          add_symbol_to_list (sym, &file_symbols);
@@ -1879,8 +1867,7 @@ decode_type (struct coff_symbol *cs, unsigned int c_type,
        }
       else
        {
-         complaint (&symfile_complaints,
-                    _("Symbol table entry for %s has bad tagndx value"),
+         complaint (_("Symbol table entry for %s has bad tagndx value"),
                     cs->c_name);
          /* And fall through to decode_base_type...  */
        }
@@ -1961,10 +1948,6 @@ decode_base_type (struct coff_symbol *cs,
          type = coff_alloc_type (cs->c_symnum);
          TYPE_CODE (type) = TYPE_CODE_STRUCT;
          TYPE_NAME (type) = NULL;
-         /* This used to set the tag to "<opaque>".  But I think
-            setting it to NULL is right, and the printing code can
-            print it as "struct {...}".  */
-         TYPE_TAG_NAME (type) = NULL;
          INIT_CPLUS_SPECIFIC (type);
          TYPE_LENGTH (type) = 0;
          TYPE_FIELDS (type) = 0;
@@ -1985,10 +1968,6 @@ decode_base_type (struct coff_symbol *cs,
          /* Anonymous union type.  */
          type = coff_alloc_type (cs->c_symnum);
          TYPE_NAME (type) = NULL;
-         /* This used to set the tag to "<opaque>".  But I think
-            setting it to NULL is right, and the printing code can
-            print it as "union {...}".  */
-         TYPE_TAG_NAME (type) = NULL;
          INIT_CPLUS_SPECIFIC (type);
          TYPE_LENGTH (type) = 0;
          TYPE_FIELDS (type) = 0;
@@ -2011,10 +1990,6 @@ decode_base_type (struct coff_symbol *cs,
          type = coff_alloc_type (cs->c_symnum);
          TYPE_CODE (type) = TYPE_CODE_ENUM;
          TYPE_NAME (type) = NULL;
-         /* This used to set the tag to "<opaque>".  But I think
-            setting it to NULL is right, and the printing code can
-            print it as "enum {...}".  */
-         TYPE_TAG_NAME (type) = NULL;
          TYPE_LENGTH (type) = 0;
          TYPE_FIELDS (type) = 0;
          TYPE_NFIELDS (type) = 0;
@@ -2049,8 +2024,7 @@ decode_base_type (struct coff_symbol *cs,
       else
        return objfile_type (objfile)->builtin_unsigned_long;
     }
-  complaint (&symfile_complaints, 
-            _("Unexpected type for symbol %s"), cs->c_name);
+  complaint (_("Unexpected type for symbol %s"), cs->c_name);
   return objfile_type (objfile)->builtin_void;
 }
 \f
@@ -2098,12 +2072,13 @@ coff_read_struct_type (int index, int length, int lastsym,
        case C_MOU:
 
          /* Get space to record the next field's data.  */
-         newobj = (struct nextfield *) alloca (sizeof (struct nextfield));
+         newobj = XALLOCA (struct nextfield);
          newobj->next = list;
          list = newobj;
 
          /* Save the data.  */
-         list->field.name = obstack_copy0 (&objfile->objfile_obstack,
+         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);
@@ -2115,12 +2090,13 @@ coff_read_struct_type (int index, int length, int lastsym,
        case C_FIELD:
 
          /* Get space to record the next field's data.  */
-         newobj = (struct nextfield *) alloca (sizeof (struct nextfield));
+         newobj = XALLOCA (struct nextfield);
          newobj->next = list;
          list = newobj;
 
          /* Save the data.  */
-         list->field.name = obstack_copy0 (&objfile->objfile_obstack,
+         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);
@@ -2191,9 +2167,9 @@ coff_read_enum_type (int index, int length, int lastsym,
        case C_MOE:
          sym = allocate_symbol (objfile);
 
-         SYMBOL_SET_LINKAGE_NAME (sym,
-                                  obstack_copy0 (&objfile->objfile_obstack,
-                                                 name, strlen (name)));
+         name = (char *) obstack_copy0 (&objfile->objfile_obstack, name,
+                                        strlen (name));
+         SYMBOL_SET_LINKAGE_NAME (sym, name);
          SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
          SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
          SYMBOL_VALUE (sym) = ms->c_value;
This page took 0.030436 seconds and 4 git commands to generate.