gdb: LoongArch: Define LOONGARCH_LINUX_NUM_GREGSET as 45
[binutils-gdb.git] / gdb / elfread.c
index 463e09179f7c6eeb2194c540fdb4cf7fb4d8e7f5..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.
 
@@ -266,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.  */
@@ -373,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)
                {
@@ -481,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;
@@ -495,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)
-               {
-                 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)
+             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)
                {
-                 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);
+                       }
                    }
                }
            }
@@ -641,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);
     }
 }
 
@@ -704,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;
 
@@ -829,15 +828,15 @@ 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;
@@ -928,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 ());
@@ -979,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 ());
@@ -1009,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);
@@ -1050,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.
@@ -1066,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;
     }
 
@@ -1172,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.