Remove duplicate or commented-out #includes
[deliverable/binutils-gdb.git] / gdb / minsyms.c
index 9b2c80041a493d8ac9acaab83c2e0eeb6b753f31..7cd7ba9f676de3f93f6d98c03f4206e763eecc16 100644 (file)
@@ -1,5 +1,5 @@
 /* GDB routines for manipulating the minimal symbol tables.
-   Copyright (C) 1992-2018 Free Software Foundation, Inc.
+   Copyright (C) 1992-2019 Free Software Foundation, Inc.
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
    This file is part of GDB.
@@ -73,8 +73,9 @@ msymbol_is_function (struct objfile *objfile, minimal_symbol *minsym,
     case mst_data_gnu_ifunc:
       {
        struct gdbarch *gdbarch = get_objfile_arch (objfile);
-       CORE_ADDR pc = gdbarch_convert_from_func_ptr_addr (gdbarch, msym_addr,
-                                                          target_stack);
+       CORE_ADDR pc
+         = gdbarch_convert_from_func_ptr_addr (gdbarch, msym_addr,
+                                               current_top_target ());
        if (pc != msym_addr)
          {
            if (func_address_p != NULL)
@@ -655,6 +656,27 @@ frob_address (struct objfile *objfile, CORE_ADDR *pc)
   return 0;
 }
 
+/* Helper for lookup_minimal_symbol_by_pc_section.  Convert a
+   lookup_msym_prefer to a minimal_symbol_type.  */
+
+static minimal_symbol_type
+msym_prefer_to_msym_type (lookup_msym_prefer prefer)
+{
+  switch (prefer)
+    {
+    case lookup_msym_prefer::TEXT:
+      return mst_text;
+    case lookup_msym_prefer::TRAMPOLINE:
+      return mst_solib_trampoline;
+    case lookup_msym_prefer::GNU_IFUNC:
+      return mst_text_gnu_ifunc;
+    }
+
+  /* Assert here instead of in a default switch case above so that
+     -Wswitch warns if a new enumerator is added.  */
+  gdb_assert_not_reached ("unhandled lookup_msym_prefer");
+}
+
 /* Search through the minimal symbol table for each objfile and find
    the symbol whose address is the largest address that is still less
    than or equal to PC, and matches SECTION (which is not NULL).
@@ -682,7 +704,6 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
   struct minimal_symbol *best_symbol = NULL;
   struct objfile *best_objfile = NULL;
   struct bound_minimal_symbol result;
-  enum minimal_symbol_type want_type;
 
   if (section == NULL)
     {
@@ -691,18 +712,7 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
        return {};
     }
 
-  switch (prefer)
-    {
-    case lookup_msym_prefer::TEXT:
-      want_type = mst_text;
-      break;
-    case lookup_msym_prefer::TRAMPOLINE:
-      want_type = mst_solib_trampoline;
-      break;
-    case lookup_msym_prefer::GNU_IFUNC:
-      want_type = mst_text_gnu_ifunc;
-      break;
-    }
+  minimal_symbol_type want_type = msym_prefer_to_msym_type (prefer);
 
   /* We can not require the symbol found to be in section, because
      e.g. IRIX 6.5 mdebug relies on this code returning an absolute
@@ -1070,6 +1080,33 @@ minimal_symbol_reader::record (const char *name, CORE_ADDR address,
   record_with_info (name, address, ms_type, section);
 }
 
+/* Convert an enumerator of type minimal_symbol_type to its string
+   representation.  */
+
+static const char *
+mst_str (minimal_symbol_type t)
+{
+#define MST_TO_STR(x) case x: return #x;
+  switch (t)
+  {
+    MST_TO_STR (mst_unknown);
+    MST_TO_STR (mst_text);
+    MST_TO_STR (mst_text_gnu_ifunc);
+    MST_TO_STR (mst_slot_got_plt);
+    MST_TO_STR (mst_data);
+    MST_TO_STR (mst_bss);
+    MST_TO_STR (mst_abs);
+    MST_TO_STR (mst_solib_trampoline);
+    MST_TO_STR (mst_file_text);
+    MST_TO_STR (mst_file_data);
+    MST_TO_STR (mst_file_bss);
+
+    default:
+      return "mst_???";
+  }
+#undef MST_TO_STR
+}
+
 /* See minsyms.h.  */
 
 struct minimal_symbol *
@@ -1102,6 +1139,10 @@ minimal_symbol_reader::record_full (const char *name, int name_len,
   if (ms_type == mst_file_text && startswith (name, "__gnu_compiled"))
     return (NULL);
 
+  if (symtab_create_debug >= 2)
+    printf_unfiltered ("Recording minsym:  %-21s  %18s  %4d  %s\n",
+               mst_str (ms_type), hex_string (address), section, name);
+
   if (m_msym_bunch_index == BUNCH_SIZE)
     {
       newobj = XCNEW (struct msym_bunch);
@@ -1365,8 +1406,9 @@ minimal_symbol_reader::install ()
 
       mcount = compact_minimal_symbols (msymbols, mcount, m_objfile);
 
-      obstack_blank_fast (&m_objfile->per_bfd->storage_obstack,
-              (mcount + 1 - alloc_count) * sizeof (struct minimal_symbol));
+      ssize_t shrink_bytes
+       = (mcount + 1 - alloc_count) * sizeof (struct minimal_symbol);
+      obstack_blank_fast (&m_objfile->per_bfd->storage_obstack, shrink_bytes);
       msymbols = (struct minimal_symbol *)
        obstack_finish (&m_objfile->per_bfd->storage_obstack);
 
@@ -1446,30 +1488,32 @@ lookup_solib_trampoline_symbol_by_pc (CORE_ADDR pc)
 CORE_ADDR
 find_solib_trampoline_target (struct frame_info *frame, CORE_ADDR pc)
 {
-  struct objfile *objfile;
-  struct minimal_symbol *msymbol;
   struct minimal_symbol *tsymbol = lookup_solib_trampoline_symbol_by_pc (pc);
 
   if (tsymbol != NULL)
     {
-      ALL_MSYMBOLS (objfile, msymbol)
-      {
-       /* Also handle minimal symbols pointing to function descriptors.  */
-       if ((MSYMBOL_TYPE (msymbol) == mst_text
-            || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc
-            || MSYMBOL_TYPE (msymbol) == mst_data
-            || MSYMBOL_TYPE (msymbol) == mst_data_gnu_ifunc)
-           && strcmp (MSYMBOL_LINKAGE_NAME (msymbol),
-                      MSYMBOL_LINKAGE_NAME (tsymbol)) == 0)
-         {
-           CORE_ADDR func;
+      for (objfile *objfile : current_program_space->objfiles ())
+       {
+         for (minimal_symbol *msymbol : objfile->msymbols ())
+           {
+             /* Also handle minimal symbols pointing to function
+                descriptors.  */
+             if ((MSYMBOL_TYPE (msymbol) == mst_text
+                  || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc
+                  || MSYMBOL_TYPE (msymbol) == mst_data
+                  || MSYMBOL_TYPE (msymbol) == mst_data_gnu_ifunc)
+                 && strcmp (MSYMBOL_LINKAGE_NAME (msymbol),
+                            MSYMBOL_LINKAGE_NAME (tsymbol)) == 0)
+               {
+                 CORE_ADDR func;
 
-           /* Ignore data symbols that are not function
-              descriptors.  */
-           if (msymbol_is_function (objfile, msymbol, &func))
-             return func;
-         }
-      }
+                 /* Ignore data symbols that are not function
+                    descriptors.  */
+                 if (msymbol_is_function (objfile, msymbol, &func))
+                   return func;
+               }
+           }
+       }
     }
   return 0;
 }
This page took 0.025726 seconds and 4 git commands to generate.