Rename to allow_rust_tests
[binutils-gdb.git] / gdb / coffread.c
index 75cf646c9804c7b051a2dec740099480954bf30f..4950a7324c8a737c12890c09420c482403eef8bf 100644 (file)
@@ -1,5 +1,5 @@
 /* Read coff symbol tables and convert to internal format, for GDB.
-   Copyright (C) 1987-2022 Free Software Foundation, Inc.
+   Copyright (C) 1987-2023 Free Software Foundation, Inc.
    Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu).
 
    This file is part of GDB.
@@ -61,7 +61,7 @@ struct coff_symfile_info
 
 /* Key for COFF-associated data.  */
 
-static const struct objfile_key<coff_symfile_info> coff_objfile_data_key;
+static const registry<objfile>::key<coff_symfile_info> coff_objfile_data_key;
 
 /* Translate an external name string into a user-visible name.  */
 #define        EXTERNAL_NAME(string, abfd) \
@@ -254,7 +254,7 @@ coff_locate_sections (bfd *abfd, asection *sectp, void *csip)
 /* Return the section_offsets* that CS points to.  */
 static int cs_to_section (struct coff_symbol *, struct objfile *);
 
-struct find_targ_sec_arg
+struct coff_find_targ_sec_arg
   {
     int targ_index;
     asection **resultp;
@@ -263,7 +263,7 @@ struct find_targ_sec_arg
 static void
 find_targ_sec (bfd *abfd, asection *sect, void *obj)
 {
-  struct find_targ_sec_arg *args = (struct find_targ_sec_arg *) obj;
+  struct coff_find_targ_sec_arg *args = (struct coff_find_targ_sec_arg *) obj;
 
   if (sect->target_index == args->targ_index)
     *args->resultp = sect;
@@ -274,11 +274,11 @@ static struct bfd_section*
 cs_to_bfd_section (struct coff_symbol *cs, struct objfile *objfile)
 {
   asection *sect = NULL;
-  struct find_targ_sec_arg args;
+  struct coff_find_targ_sec_arg args;
 
   args.targ_index = cs->c_secnum;
   args.resultp = &sect;
-  bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
+  bfd_map_over_sections (objfile->obfd.get (), find_targ_sec, &args);
   return sect;
 }
 
@@ -290,7 +290,7 @@ cs_to_section (struct coff_symbol *cs, struct objfile *objfile)
 
   if (sect == NULL)
     return SECT_OFF_TEXT (objfile);
-  return gdb_bfd_section_index (objfile->obfd, sect);
+  return gdb_bfd_section_index (objfile->obfd.get (), sect);
 }
 
 /* Return the address of the section of a COFF symbol.  */
@@ -301,7 +301,7 @@ static CORE_ADDR
 cs_section_address (struct coff_symbol *cs, bfd *abfd)
 {
   asection *sect = NULL;
-  struct find_targ_sec_arg args;
+  struct coff_find_targ_sec_arg args;
   CORE_ADDR addr = 0;
 
   args.targ_index = cs->c_secnum;
@@ -579,7 +579,8 @@ coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms,
                name1 = name + 6;
              if (name1 != NULL)
                {
-                 int lead = bfd_get_symbol_leading_char (objfile->obfd);
+                 int lead
+                   = bfd_get_symbol_leading_char (objfile->obfd.get ());
                  struct bound_minimal_symbol found;
 
                  if (lead != '\0' && *name1 == lead)
@@ -610,7 +611,7 @@ static void
 coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 {
   struct coff_symfile_info *info;
-  bfd *abfd = objfile->obfd;
+  bfd *abfd = objfile->obfd.get ();
   coff_data_type *cdata = coff_data (abfd);
   const char *filename = bfd_get_filename (abfd);
   int val;
@@ -655,8 +656,8 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
      FIXME: We should use BFD to read the symbol table, and thus avoid
      this problem.  */
   pe_file =
-    startswith (bfd_get_target (objfile->obfd), "pe")
-    || startswith (bfd_get_target (objfile->obfd), "epoc-pe");
+    startswith (bfd_get_target (objfile->obfd.get ()), "pe")
+    || startswith (bfd_get_target (objfile->obfd.get ()), "epoc-pe");
 
   /* End of warning.  */
 
@@ -742,7 +743,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
        {
          gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (debugfile.c_str ()));
 
-         symbol_file_add_separate (debug_bfd.get (), debugfile.c_str (),
+         symbol_file_add_separate (debug_bfd, debugfile.c_str (),
                                    symfile_flags, objfile);
        }
     }
@@ -817,15 +818,15 @@ coff_symtab_read (minimal_symbol_reader &reader,
      FIXME: Find out if this has been reported to Sun, whether it has
      been fixed in a later release, etc.  */
 
-  bfd_seek (objfile->obfd, 0, 0);
+  bfd_seek (objfile->obfd.get (), 0, 0);
 
   /* Position to read the symbol table.  */
-  val = bfd_seek (objfile->obfd, symtab_offset, 0);
+  val = bfd_seek (objfile->obfd.get (), symtab_offset, 0);
   if (val < 0)
     perror_with_name (objfile_name (objfile));
 
   coffread_objfile = objfile;
-  nlist_bfd_global = objfile->obfd;
+  nlist_bfd_global = objfile->obfd.get ();
   nlist_nsyms_global = nsyms;
   set_last_source_file (NULL);
   memset (opaque_type_chain, 0, sizeof opaque_type_chain);
@@ -1359,7 +1360,7 @@ coff_getfilename (union internal_auxent *aux_entry)
   if (aux_entry->x_file.x_n.x_n.x_zeroes == 0)
     {
       if (strlen (stringtab + aux_entry->x_file.x_n.x_n.x_offset) >= BUFSIZ)
-       internal_error (__FILE__, __LINE__, _("coff file name too long"));
+       internal_error (_("coff file name too long"));
       strcpy (buffer, stringtab + aux_entry->x_file.x_n.x_n.x_offset);
     }
   else
@@ -1467,11 +1468,11 @@ enter_linenos (file_ptr file_offset, int first_line,
 static void
 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);
+  struct type *target = type->target_type ();
+  struct type *real_target = real_type->target_type ();
   int field_size = real_target->num_fields () * sizeof (struct field);
 
-  TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
+  target->set_length (real_target->length ());
   target->set_num_fields (real_target->num_fields ());
 
   field *fields = (struct field *) TYPE_ALLOC (target, field_size);
@@ -1508,7 +1509,7 @@ patch_opaque_types (struct symtab *s)
       if (real_sym->aclass () == LOC_TYPEDEF
          && real_sym->domain () == VAR_DOMAIN
          && real_sym->type ()->code () == TYPE_CODE_PTR
-         && TYPE_LENGTH (TYPE_TARGET_TYPE (real_sym->type ())) != 0)
+         && real_sym->type ()->target_type ()->length () != 0)
        {
          const char *name = real_sym->linkage_name ();
          int hash = hashname (name);
@@ -1565,7 +1566,7 @@ process_coff_symbol (struct coff_symbol *cs,
   char *name;
 
   name = cs->c_name;
-  name = EXTERNAL_NAME (name, objfile->obfd);
+  name = EXTERNAL_NAME (name, objfile->obfd.get ());
   sym->set_language (get_current_subfile ()->language,
                     &objfile->objfile_obstack);
   sym->compute_and_set_names (name, true, objfile->per_bfd);
@@ -1698,8 +1699,8 @@ process_coff_symbol (struct coff_symbol *cs,
             references work themselves out via the magic of
             coff_lookup_type.  */
          if (sym->type ()->code () == TYPE_CODE_PTR
-             && TYPE_LENGTH (TYPE_TARGET_TYPE (sym->type ())) == 0
-             && TYPE_TARGET_TYPE (sym->type ())->code ()
+             && sym->type ()->target_type ()->length () == 0
+             && sym->type ()->target_type ()->code ()
              != TYPE_CODE_UNDEF)
            {
              int i = hashname (sym->linkage_name ());
@@ -1886,7 +1887,7 @@ decode_base_type (struct coff_symbol *cs,
          type->set_code (TYPE_CODE_STRUCT);
          type->set_name (NULL);
          INIT_CPLUS_SPECIFIC (type);
-         TYPE_LENGTH (type) = 0;
+         type->set_length (0);
          type->set_fields (nullptr);
          type->set_num_fields (0);
        }
@@ -1906,7 +1907,7 @@ decode_base_type (struct coff_symbol *cs,
          type = coff_alloc_type (cs->c_symnum);
          type->set_name (NULL);
          INIT_CPLUS_SPECIFIC (type);
-         TYPE_LENGTH (type) = 0;
+         type->set_length (0);
          type->set_fields (nullptr);
          type->set_num_fields (0);
        }
@@ -1927,7 +1928,7 @@ decode_base_type (struct coff_symbol *cs,
          type = coff_alloc_type (cs->c_symnum);
          type->set_code (TYPE_CODE_ENUM);
          type->set_name (NULL);
-         TYPE_LENGTH (type) = 0;
+         type->set_length (0);
          type->set_fields (nullptr);
          type->set_num_fields (0);
        }
@@ -1995,13 +1996,13 @@ coff_read_struct_type (int index, int length, int lastsym,
   type = coff_alloc_type (index);
   type->set_code (TYPE_CODE_STRUCT);
   INIT_CPLUS_SPECIFIC (type);
-  TYPE_LENGTH (type) = length;
+  type->set_length (length);
 
   while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
     {
       read_one_sym (ms, &sub_sym, &sub_aux);
       name = ms->c_name;
-      name = EXTERNAL_NAME (name, objfile->obfd);
+      name = EXTERNAL_NAME (name, objfile->obfd.get ());
 
       switch (ms->c_sclass)
        {
@@ -2095,7 +2096,7 @@ coff_read_enum_type (int index, int length, int lastsym,
     {
       read_one_sym (ms, &sub_sym, &sub_aux);
       name = ms->c_name;
-      name = EXTERNAL_NAME (name, objfile->obfd);
+      name = EXTERNAL_NAME (name, objfile->obfd.get ());
 
       switch (ms->c_sclass)
        {
@@ -2123,9 +2124,9 @@ coff_read_enum_type (int index, int length, int lastsym,
   /* Now fill in the fields of the type-structure.  */
 
   if (length > 0)
-    TYPE_LENGTH (type) = length;
+    type->set_length (length);
   else /* Assume ints.  */
-    TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
+    type->set_length (gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT);
   type->set_code (TYPE_CODE_ENUM);
   type->set_num_fields (nsyms);
   type->set_fields