gdb: LoongArch: Define LOONGARCH_LINUX_NUM_GREGSET as 45
[binutils-gdb.git] / gdb / elfread.c
index 1cf9b2addc4e5d9abdddf07086283534051ce999..32cb27c8967e3053cc6e276633be4a2e9f79c436 100644 (file)
@@ -1,6 +1,6 @@
 /* Read ELF (Executable and Linking Format) object files for GDB.
 
-   Copyright (C) 1991-2021 Free Software Foundation, Inc.
+   Copyright (C) 1991-2022 Free Software Foundation, Inc.
 
    Written by Fred Fish at Cygnus Support.
 
@@ -29,7 +29,6 @@
 #include "symfile.h"
 #include "objfiles.h"
 #include "stabsread.h"
-#include "complaints.h"
 #include "demangle.h"
 #include "psympriv.h"
 #include "filenames.h"
 #include "debuginfod-support.h"
 #include "dwarf2/public.h"
 
-/* A subclass of psymbol_functions that arranges to read the DWARF
-   partial symbols when needed.  */
-struct lazy_dwarf_reader : public psymbol_functions
-{
-  using psymbol_functions::psymbol_functions;
-
-  bool can_lazily_read_symbols () override
-  {
-    return true;
-  }
-
-  void read_partial_symbols (struct objfile *objfile) override
-  {
-    if (dwarf2_has_info (objfile, nullptr))
-      dwarf2_build_psymtabs (objfile);
-  }
-};
-
-extern const struct sym_fns elf_sym_fns_lazy_psyms;
-
 /* The struct elfinfo is available only during ELF symbol table and
    psymtab reading.  It is destroyed at the completion of psymtab-reading.
    It's local to elf_symfile_read.  */
@@ -287,6 +266,8 @@ elf_symtab_read (minimal_symbol_reader &reader,
          continue;
        }
 
+      elf_symbol_type *elf_sym = (elf_symbol_type *) sym;
+
       /* Skip "special" symbols, e.g. ARM mapping symbols.  These are
         symbols which do not correspond to objects in the symbol table,
         but have some other target-specific meaning.  */
@@ -394,7 +375,7 @@ elf_symtab_read (minimal_symbol_reader &reader,
                 NOTE: uweigand-20071112: Synthetic symbols do not
                 have an ELF-private part, so do not touch those.  */
              unsigned int shndx = type == ST_SYNTHETIC ? 0 :
-               ((elf_symbol_type *) sym)->internal_elf_sym.st_shndx;
+               elf_sym->internal_elf_sym.st_shndx;
 
              switch (shndx)
                {
@@ -502,8 +483,7 @@ elf_symtab_read (minimal_symbol_reader &reader,
              if (type != ST_SYNTHETIC)
                {
                  /* Pass symbol size field in via BFD.  FIXME!!!  */
-                 elf_symbol_type *elf_sym = (elf_symbol_type *) sym;
-                 SET_MSYMBOL_SIZE (msym, elf_sym->internal_elf_sym.st_size);
+                 msym->set_size (elf_sym->internal_elf_sym.st_size);
                }
 
              msym->filename = filesymname;
@@ -516,41 +496,39 @@ elf_symtab_read (minimal_symbol_reader &reader,
          if (msym != NULL)
            {
              const char *atsign = strchr (sym->name, '@');
-
-             if (atsign != NULL && atsign[1] == '@' && atsign > sym->name)
+             bool is_at_symbol = atsign != nullptr && atsign > sym->name;
+             bool is_plt = is_at_symbol && strcmp (atsign, "@plt") == 0;
+             int len = is_at_symbol ? atsign - sym->name : 0;
+
+             if (is_at_symbol
+                 && !is_plt
+                 && (elf_sym->version & VERSYM_HIDDEN) == 0)
+               record_minimal_symbol (reader,
+                                      gdb::string_view (sym->name, len),
+                                      true, symaddr, ms_type, sym->section,
+                                      objfile);
+             else if (is_plt)
                {
-                 int len = atsign - sym->name;
-
-                 record_minimal_symbol (reader,
-                                        gdb::string_view (sym->name, len),
-                                        true, symaddr, ms_type, sym->section,
-                                        objfile);
-               }
-           }
-
-         /* For @plt symbols, also record a trampoline to the
-            destination symbol.  The @plt symbol will be used in
-            disassembly, and the trampoline will be used when we are
-            trying to find the target.  */
-         if (msym && ms_type == mst_text && type == ST_SYNTHETIC)
-           {
-             int len = strlen (sym->name);
-
-             if (len > 4 && strcmp (sym->name + len - 4, "@plt") == 0)
-               {
-                 struct minimal_symbol *mtramp;
-
-                 mtramp = record_minimal_symbol
-                   (reader, gdb::string_view (sym->name, len - 4), true,
-                    symaddr, mst_solib_trampoline, sym->section, objfile);
-                 if (mtramp)
+                 /* For @plt symbols, also record a trampoline to the
+                    destination symbol.  The @plt symbol will be used
+                    in disassembly, and the trampoline will be used
+                    when we are trying to find the target.  */
+                 if (ms_type == mst_text && type == ST_SYNTHETIC)
                    {
-                     SET_MSYMBOL_SIZE (mtramp, MSYMBOL_SIZE (msym));
-                     mtramp->created_by_gdb = 1;
-                     mtramp->filename = filesymname;
-                     if (elf_make_msymbol_special_p)
-                       gdbarch_elf_make_msymbol_special (gdbarch,
-                                                         sym, mtramp);
+                     struct minimal_symbol *mtramp;
+
+                     mtramp = record_minimal_symbol
+                       (reader, gdb::string_view (sym->name, len), true,
+                        symaddr, mst_solib_trampoline, sym->section, objfile);
+                     if (mtramp)
+                       {
+                         mtramp->set_size (msym->size());
+                         mtramp->created_by_gdb = 1;
+                         mtramp->filename = filesymname;
+                         if (elf_make_msymbol_special_p)
+                           gdbarch_elf_make_msymbol_special (gdbarch,
+                                                             sym, mtramp);
+                       }
                    }
                }
            }
@@ -662,7 +640,7 @@ elf_rel_plt_read (minimal_symbol_reader &reader,
                                    true, address, mst_slot_got_plt,
                                    msym_section, objfile);
       if (msym)
-       SET_MSYMBOL_SIZE (msym, ptr_size);
+       msym->set_size (ptr_size);
     }
 }
 
@@ -725,7 +703,7 @@ elf_gnu_ifunc_record_cache (const char *name, CORE_ADDR addr)
   msym = lookup_minimal_symbol_by_pc (addr);
   if (msym.minsym == NULL)
     return 0;
-  if (BMSYMBOL_VALUE_ADDRESS (msym) != addr)
+  if (msym.value_address () != addr)
     return 0;
   objfile = msym.objfile;
 
@@ -850,21 +828,21 @@ elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
       msym = lookup_minimal_symbol (name_got_plt, NULL, objfile);
       if (msym.minsym == NULL)
        continue;
-      if (MSYMBOL_TYPE (msym.minsym) != mst_slot_got_plt)
+      if (msym.minsym->type () != mst_slot_got_plt)
        continue;
-      pointer_address = BMSYMBOL_VALUE_ADDRESS (msym);
+      pointer_address = msym.value_address ();
 
       plt = bfd_get_section_by_name (obfd, ".plt");
       if (plt == NULL)
        continue;
 
-      if (MSYMBOL_SIZE (msym.minsym) != ptr_size)
+      if (msym.minsym->size () != ptr_size)
        continue;
       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))
@@ -931,12 +909,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)
@@ -948,7 +927,7 @@ elf_gnu_ifunc_resolve_addr (struct gdbarch *gdbarch, CORE_ADDR pc)
 /* Handle inferior hit of bp_gnu_ifunc_resolver, see its definition.  */
 
 static void
-elf_gnu_ifunc_resolver_stop (struct breakpoint *b)
+elf_gnu_ifunc_resolver_stop (code_breakpoint *b)
 {
   struct breakpoint *b_return;
   struct frame_info *prev_frame = get_prev_frame (get_current_frame ());
@@ -999,7 +978,7 @@ elf_gnu_ifunc_resolver_stop (struct breakpoint *b)
 /* Handle inferior hit of bp_gnu_ifunc_resolver_return, see its definition.  */
 
 static void
-elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
+elf_gnu_ifunc_resolver_return_stop (code_breakpoint *b)
 {
   thread_info *thread = inferior_thread ();
   struct gdbarch *gdbarch = get_frame_arch (get_current_frame ());
@@ -1029,7 +1008,7 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
                            "gnu-indirect-function breakpoint type %d"),
                          (int) b->type);
        }
-      b = b_next;
+      b = (code_breakpoint *) b_next;
     }
   gdb_assert (b->type == bp_gnu_ifunc_resolver);
   gdb_assert (b->loc->next == NULL);
@@ -1040,11 +1019,10 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
 
   value = allocate_value (value_type);
   gdbarch_return_value (gdbarch, func_func, value_type, regcache,
-                       value_contents_raw (value), NULL);
+                       value_contents_raw (value).data (), 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);
@@ -1071,9 +1049,9 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
 
   if (symtab_create_debug)
     {
-      fprintf_unfiltered (gdb_stdlog,
-                         "Reading minimal symbols of objfile %s ...\n",
-                         objfile_name (objfile));
+      gdb_printf (gdb_stdlog,
+                 "Reading minimal symbols of objfile %s ...\n",
+                 objfile_name (objfile));
     }
 
   /* If we already have minsyms, then we can skip some work here.
@@ -1087,8 +1065,8 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
       && ei->ctfsect == NULL)
     {
       if (symtab_create_debug)
-       fprintf_unfiltered (gdb_stdlog,
-                           "... minimal symbols previously read\n");
+       gdb_printf (gdb_stdlog,
+                   "... minimal symbols previously read\n");
       return;
     }
 
@@ -1193,7 +1171,7 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
   reader.install ();
 
   if (symtab_create_debug)
-    fprintf_unfiltered (gdb_stdlog, "Done reading minimal symbols.\n");
+    gdb_printf (gdb_stdlog, "Done reading minimal symbols.\n");
 }
 
 /* Scan and build partial symbols for a symbol file.
@@ -1275,38 +1253,7 @@ 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 ()
-         && dwarf2_initialize_objfile (objfile, &index_kind))
-       {
-         switch (index_kind)
-           {
-           case dw_index_kind::GDB_INDEX:
-             objfile->qf.clear ();
-             objfile->qf.push_front (make_dwarf_gdb_index ());
-             break;
-           case dw_index_kind::DEBUG_NAMES:
-             objfile->qf.clear ();
-             objfile->qf.push_front (make_dwarf_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->qf.clear ();
-         objfile->qf.emplace_front
-           (new lazy_dwarf_reader (objfile->partial_symtabs));
-       }
-    }
+    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