gdb: resume ongoing step after handling fork or vfork
[deliverable/binutils-gdb.git] / gdb / elfread.c
index 4804d62074c47d10ec3ec65b477060a149f02355..8e937cbda1648aace79fcf455b7a8994eb90f8b5 100644 (file)
@@ -1,6 +1,6 @@
 /* Read ELF (Executable and Linking Format) object files for GDB.
 
-   Copyright (C) 1991-2020 Free Software Foundation, Inc.
+   Copyright (C) 1991-2022 Free Software Foundation, Inc.
 
    Written by Fred Fish at Cygnus Support.
 
 #include "gdbsupport/gdb_string_view.h"
 #include "gdbsupport/scoped_fd.h"
 #include "debuginfod-support.h"
-
-/* Forward declarations.  */
-extern const struct sym_fns elf_sym_fns_gdb_index;
-extern const struct sym_fns elf_sym_fns_debug_names;
-extern const struct sym_fns elf_sym_fns_lazy_psyms;
+#include "dwarf2/public.h"
 
 /* The struct elfinfo is available only during ELF symbol table and
    psymtab reading.  It is destroyed at the completion of psymtab-reading.
@@ -112,18 +108,15 @@ elf_symfile_segments (bfd *abfd)
     return NULL;
 
   symfile_segment_data_up data (new symfile_segment_data);
-  data->num_segments = num_segments;
-  data->segment_bases = XCNEWVEC (CORE_ADDR, num_segments);
-  data->segment_sizes = XCNEWVEC (CORE_ADDR, num_segments);
+  data->segments.reserve (num_segments);
 
   for (i = 0; i < num_segments; i++)
-    {
-      data->segment_bases[i] = segments[i]->p_vaddr;
-      data->segment_sizes[i] = segments[i]->p_memsz;
-    }
+    data->segments.emplace_back (segments[i]->p_vaddr, segments[i]->p_memsz);
 
   num_sections = bfd_count_sections (abfd);
-  data->segment_info = XCNEWVEC (int, num_sections);
+
+  /* All elements are initialized to 0 (map to no segment).  */
+  data->segment_info.resize (num_sections);
 
   for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
     {
@@ -150,10 +143,15 @@ elf_symfile_segments (bfd *abfd)
         RealView) use SHT_NOBITS for uninitialized data.  Since it is
         uninitialized, it doesn't need a program header.  Such
         binaries are not relocatable.  */
-      if (bfd_section_size (sect) > 0 && j == num_segments
+
+      /* Exclude debuginfo files from this warning, too, since those
+        are often not strictly compliant with the standard. See, e.g.,
+        ld/24717 for more discussion.  */
+      if (!is_debuginfo_file (abfd)
+         && bfd_section_size (sect) > 0 && j == num_segments
          && (bfd_section_flags (sect) & SEC_LOAD) != 0)
-       warning (_("Loadable section \"%s\" outside of ELF segments"),
-                bfd_section_name (sect));
+       warning (_("Loadable section \"%s\" outside of ELF segments\n  in %s"),
+                bfd_section_name (sect), bfd_get_filename (abfd));
     }
 
   return data;
@@ -179,11 +177,8 @@ elf_symfile_segments (bfd *abfd)
    -kingdon).  */
 
 static void
-elf_locate_sections (bfd *ignore_abfd, asection *sectp, void *eip)
+elf_locate_sections (asection *sectp, struct elfinfo *ei)
 {
-  struct elfinfo *ei;
-
-  ei = (struct elfinfo *) eip;
   if (strcmp (sectp->name, ".stab") == 0)
     {
       ei->stabsect = sectp;
@@ -848,8 +843,8 @@ elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
       if (target_read_memory (pointer_address, buf, ptr_size) != 0)
        continue;
       addr = extract_typed_address (buf, ptr_type);
-      addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr,
-                                                current_top_target ());
+      addr = gdbarch_convert_from_func_ptr_addr
+       (gdbarch, addr, current_inferior ()->top_target ());
       addr = gdbarch_addr_bits_remove (gdbarch, addr);
 
       if (elf_gnu_ifunc_record_cache (name, addr))
@@ -916,12 +911,13 @@ elf_gnu_ifunc_resolve_addr (struct gdbarch *gdbarch, CORE_ADDR pc)
      parameter.  FUNCTION is the function entry address.  ADDRESS may be a
      function descriptor.  */
 
-  target_auxv_search (current_top_target (), AT_HWCAP, &hwcap);
+  target_auxv_search (current_inferior ()->top_target (), AT_HWCAP, &hwcap);
   hwcap_val = value_from_longest (builtin_type (gdbarch)
                                  ->builtin_unsigned_long, hwcap);
   address_val = call_function_by_hand (function, NULL, hwcap_val);
   address = value_as_address (address_val);
-  address = gdbarch_convert_from_func_ptr_addr (gdbarch, address, current_top_target ());
+  address = gdbarch_convert_from_func_ptr_addr
+    (gdbarch, address, current_inferior ()->top_target ());
   address = gdbarch_addr_bits_remove (gdbarch, address);
 
   if (name_at_pc)
@@ -1027,9 +1023,8 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
   gdbarch_return_value (gdbarch, func_func, value_type, regcache,
                        value_contents_raw (value), NULL);
   resolved_address = value_as_address (value);
-  resolved_pc = gdbarch_convert_from_func_ptr_addr (gdbarch,
-                                                   resolved_address,
-                                                   current_top_target ());
+  resolved_pc = gdbarch_convert_from_func_ptr_addr
+    (gdbarch, resolved_address, current_inferior ()->top_target ());
   resolved_pc = gdbarch_addr_bits_remove (gdbarch, resolved_pc);
 
   gdb_assert (current_program_space == b->pspace || b->pspace == NULL);
@@ -1214,7 +1209,10 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 
   memset ((char *) &ei, 0, sizeof (ei));
   if (!(objfile->flags & OBJF_READNEVER))
-    bfd_map_over_sections (abfd, elf_locate_sections, (void *) & ei);
+    {
+      for (asection *sect : gdb_bfd_sections (abfd))
+       elf_locate_sections (sect, &ei);
+    }
 
   elf_read_minimal_symbols (objfile, symfile_flags, &ei);
 
@@ -1235,7 +1233,7 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
       const struct ecoff_debug_swap *swap;
 
       /* .mdebug section, presumably holding ECOFF debugging
-         information.  */
+        information.  */
       swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
       if (swap)
        elfmdebug_build_psymtabs (objfile, swap, ei.mdebugsect);
@@ -1245,7 +1243,7 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
       asection *str_sect;
 
       /* Stab sections have an associated string table that looks like
-         a separate section.  */
+        a separate section.  */
       str_sect = bfd_get_section_by_name (abfd, ".stabstr");
 
       /* FIXME should probably warn about a stab section without a stabstr.  */
@@ -1257,47 +1255,20 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
     }
 
   if (dwarf2_has_info (objfile, NULL, true))
-    {
-      dw_index_kind index_kind;
-
-      /* elf_sym_fns_gdb_index cannot handle simultaneous non-DWARF
-        debug information present in OBJFILE.  If there is such debug
-        info present never use an index.  */
-      if (!objfile_has_partial_symbols (objfile)
-         && dwarf2_initialize_objfile (objfile, &index_kind))
-       {
-         switch (index_kind)
-           {
-           case dw_index_kind::GDB_INDEX:
-             objfile_set_sym_fns (objfile, &elf_sym_fns_gdb_index);
-             break;
-           case dw_index_kind::DEBUG_NAMES:
-             objfile_set_sym_fns (objfile, &elf_sym_fns_debug_names);
-             break;
-           }
-       }
-      else
-       {
-         /* It is ok to do this even if the stabs reader made some
-            partial symbols, because OBJF_PSYMTABS_READ has not been
-            set, and so our lazy reader function will still be called
-            when needed.  */
-         objfile_set_sym_fns (objfile, &elf_sym_fns_lazy_psyms);
-       }
-    }
+    dwarf2_initialize_objfile (objfile);
   /* If the file has its own symbol tables it has no separate debug
      info.  `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to
      SYMTABS/PSYMTABS.  `.gnu_debuglink' may no longer be present with
      `.note.gnu.build-id'.
 
-     .gnu_debugdata is !objfile_has_partial_symbols because it contains only
+     .gnu_debugdata is !objfile::has_partial_symbols because it contains only
      .symtab, not .debug_* section.  But if we already added .gnu_debugdata as
      an objfile via find_separate_debug_file_in_section there was no separate
      debug info available.  Therefore do not attempt to search for another one,
      objfile->separate_debug_objfile->separate_debug_objfile GDB guarantees to
      be NULL and we would possibly violate it.  */
 
-  else if (!objfile_has_partial_symbols (objfile)
+  else if (!objfile->has_partial_symbols ()
           && objfile->separate_debug_objfile == NULL
           && objfile->separate_debug_objfile_backlink == NULL)
     {
@@ -1352,15 +1323,6 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
     }
 }
 
-/* Callback to lazily read psymtabs.  */
-
-static void
-read_psyms (struct objfile *objfile)
-{
-  if (dwarf2_has_info (objfile, NULL))
-    dwarf2_build_psymtabs (objfile);
-}
-
 /* 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).  */
@@ -1427,66 +1389,12 @@ static const struct sym_fns elf_sym_fns =
   elf_new_init,                        /* init anything gbl to entire symtab */
   elf_symfile_init,            /* read initial info, setup for sym_read() */
   elf_symfile_read,            /* read a symbol file into symtab */
-  NULL,                                /* sym_read_psymbols */
-  elf_symfile_finish,          /* finished with file, cleanup */
-  default_symfile_offsets,     /* Translate ext. to int. relocation */
-  elf_symfile_segments,                /* Get segment information from a file.  */
-  NULL,
-  default_symfile_relocate,    /* Relocate a debug section.  */
-  &elf_probe_fns,              /* sym_probe_fns */
-  &psym_functions
-};
-
-/* The same as elf_sym_fns, but not registered and lazily reads
-   psymbols.  */
-
-const struct sym_fns elf_sym_fns_lazy_psyms =
-{
-  elf_new_init,                        /* init anything gbl to entire symtab */
-  elf_symfile_init,            /* read initial info, setup for sym_read() */
-  elf_symfile_read,            /* read a symbol file into symtab */
-  read_psyms,                  /* sym_read_psymbols */
-  elf_symfile_finish,          /* finished with file, cleanup */
-  default_symfile_offsets,     /* Translate ext. to int. relocation */
-  elf_symfile_segments,                /* Get segment information from a file.  */
-  NULL,
-  default_symfile_relocate,    /* Relocate a debug section.  */
-  &elf_probe_fns,              /* sym_probe_fns */
-  &psym_functions
-};
-
-/* The same as elf_sym_fns, but not registered and uses the
-   DWARF-specific GNU index rather than psymtab.  */
-const struct sym_fns elf_sym_fns_gdb_index =
-{
-  elf_new_init,                        /* init anything gbl to entire symab */
-  elf_symfile_init,            /* read initial info, setup for sym_red() */
-  elf_symfile_read,            /* read a symbol file into symtab */
-  NULL,                                /* sym_read_psymbols */
-  elf_symfile_finish,          /* finished with file, cleanup */
-  default_symfile_offsets,     /* Translate ext. to int. relocation */
-  elf_symfile_segments,                /* Get segment information from a file.  */
-  NULL,
-  default_symfile_relocate,    /* Relocate a debug section.  */
-  &elf_probe_fns,              /* sym_probe_fns */
-  &dwarf2_gdb_index_functions
-};
-
-/* The same as elf_sym_fns, but not registered and uses the
-   DWARF-specific .debug_names index rather than psymtab.  */
-const struct sym_fns elf_sym_fns_debug_names =
-{
-  elf_new_init,                        /* init anything gbl to entire symab */
-  elf_symfile_init,            /* read initial info, setup for sym_red() */
-  elf_symfile_read,            /* read a symbol file into symtab */
-  NULL,                                /* sym_read_psymbols */
   elf_symfile_finish,          /* finished with file, cleanup */
   default_symfile_offsets,     /* Translate ext. to int. relocation */
   elf_symfile_segments,                /* Get segment information from a file.  */
   NULL,
   default_symfile_relocate,    /* Relocate a debug section.  */
   &elf_probe_fns,              /* sym_probe_fns */
-  &dwarf2_debug_names_functions
 };
 
 /* STT_GNU_IFUNC resolver vector to be installed to gnu_ifunc_fns_p.  */
This page took 0.027626 seconds and 4 git commands to generate.