gdb/
[deliverable/binutils-gdb.git] / gdb / minsyms.c
index 8497991f04aad83e04656d0e43c8734210cdc15d..8ac5014a54cc980fa690c1cf110ed47b8d7037bd 100644 (file)
@@ -43,6 +43,7 @@
 #include "gdb_string.h"
 #include "symtab.h"
 #include "bfd.h"
+#include "filenames.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "demangle.h"
@@ -90,7 +91,7 @@ msymbol_hash_iw (const char *string)
        ++string;
       if (*string && *string != '(')
        {
-         hash = hash * 67 + *string - 113;
+         hash = SYMBOL_HASH_NEXT (hash, *string);
          ++string;
        }
     }
@@ -105,12 +106,12 @@ msymbol_hash (const char *string)
   unsigned int hash = 0;
 
   for (; *string; ++string)
-    hash = hash * 67 + *string - 113;
+    hash = SYMBOL_HASH_NEXT (hash, *string);
   return hash;
 }
 
 /* Add the minimal symbol SYM to an objfile's minsym hash table, TABLE.  */
-void
+static void
 add_minsym_to_hash_table (struct minimal_symbol *sym,
                          struct minimal_symbol **table)
 {
@@ -198,12 +199,7 @@ lookup_minimal_symbol (const char *name, const char *sfile,
   const char *modified_name;
 
   if (sfile != NULL)
-    {
-      char *p = strrchr (sfile, '/');
-
-      if (p != NULL)
-       sfile = p + 1;
-    }
+    sfile = lbasename (sfile);
 
   /* For C++, canonicalize the input name.  */
   modified_name = name;
@@ -243,11 +239,16 @@ lookup_minimal_symbol (const char *name, const char *sfile,
 
                  if (pass == 1)
                    {
-                     match = strcmp (SYMBOL_LINKAGE_NAME (msymbol),
-                                     modified_name) == 0;
+                     int (*cmp) (const char *, const char *);
+
+                     cmp = (case_sensitivity == case_sensitive_on
+                            ? strcmp : strcasecmp);
+                     match = cmp (SYMBOL_LINKAGE_NAME (msymbol),
+                                  modified_name) == 0;
                    }
                  else
                    {
+                     /* The function respects CASE_SENSITIVITY.  */
                      match = SYMBOL_MATCHES_SEARCH_NAME (msymbol,
                                                          modified_name);
                    }
@@ -260,7 +261,7 @@ lookup_minimal_symbol (const char *name, const char *sfile,
                       case mst_file_data:
                       case mst_file_bss:
                         if (sfile == NULL
-                           || strcmp (msymbol->filename, sfile) == 0)
+                           || filename_cmp (msymbol->filename, sfile) == 0)
                           found_file_symbol = msymbol;
                         break;
 
@@ -309,6 +310,46 @@ lookup_minimal_symbol (const char *name, const char *sfile,
   return NULL;
 }
 
+/* Iterate over all the minimal symbols in the objfile OBJF which
+   match NAME.  Both the ordinary and demangled names of each symbol
+   are considered.  The caller is responsible for canonicalizing NAME,
+   should that need to be done.
+   
+   For each matching symbol, CALLBACK is called with the symbol and
+   USER_DATA as arguments.  */
+
+void
+iterate_over_minimal_symbols (struct objfile *objf, const char *name,
+                             void (*callback) (struct minimal_symbol *,
+                                               void *),
+                             void *user_data)
+{
+  unsigned int hash;
+  struct minimal_symbol *iter;
+  int (*cmp) (const char *, const char *);
+
+  /* The first pass is over the ordinary hash table.  */
+  hash = msymbol_hash (name) % MINIMAL_SYMBOL_HASH_SIZE;
+  iter = objf->msymbol_hash[hash];
+  cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
+  while (iter)
+    {
+      if (cmp (SYMBOL_LINKAGE_NAME (iter), name) == 0)
+       (*callback) (iter, user_data);
+      iter = iter->hash_next;
+    }
+
+  /* The second pass is over the demangled table.  */
+  hash = msymbol_hash_iw (name) % MINIMAL_SYMBOL_HASH_SIZE;
+  iter = objf->msymbol_demangled_hash[hash];
+  while (iter)
+    {
+      if (SYMBOL_MATCHES_SEARCH_NAME (iter, name))
+       (*callback) (iter, user_data);
+      iter = iter->demangled_hash_next;
+    }
+}
+
 /* Look through all the current minimal symbol tables and find the
    first minimal symbol that matches NAME and has text type.  If OBJF
    is non-NULL, limit the search to that objfile.  Returns a pointer
@@ -338,8 +379,9 @@ lookup_minimal_symbol_text (const char *name, struct objfile *objf)
               msymbol = msymbol->hash_next)
            {
              if (strcmp (SYMBOL_LINKAGE_NAME (msymbol), name) == 0 &&
-                 (MSYMBOL_TYPE (msymbol) == mst_text ||
-                  MSYMBOL_TYPE (msymbol) == mst_file_text))
+                 (MSYMBOL_TYPE (msymbol) == mst_text
+                  || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc
+                  || MSYMBOL_TYPE (msymbol) == mst_file_text))
                {
                  switch (MSYMBOL_TYPE (msymbol))
                    {
@@ -581,7 +623,7 @@ lookup_minimal_symbol_by_pc_section_1 (CORE_ADDR pc,
 
                  /* If we are looking for a trampoline and this is a
                     text symbol, or the other way around, check the
-                    preceeding symbol too.  If they are otherwise
+                    preceding symbol too.  If they are otherwise
                     identical prefer that one.  */
                  if (hi > 0
                      && MSYMBOL_TYPE (&msymbol[hi]) == other_type
@@ -701,6 +743,69 @@ lookup_minimal_symbol_by_pc (CORE_ADDR pc)
   return lookup_minimal_symbol_by_pc_section (pc, NULL);
 }
 
+/* Return non-zero iff PC is in an STT_GNU_IFUNC function resolver.  */
+
+int
+in_gnu_ifunc_stub (CORE_ADDR pc)
+{
+  struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (pc);
+
+  return msymbol && MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc;
+}
+
+/* See elf_gnu_ifunc_resolve_addr for its real implementation.  */
+
+static CORE_ADDR
+stub_gnu_ifunc_resolve_addr (struct gdbarch *gdbarch, CORE_ADDR pc)
+{
+  error (_("GDB cannot resolve STT_GNU_IFUNC symbol at address %s without "
+          "the ELF support compiled in."),
+        paddress (gdbarch, pc));
+}
+
+/* See elf_gnu_ifunc_resolve_name for its real implementation.  */
+
+static int
+stub_gnu_ifunc_resolve_name (const char *function_name,
+                            CORE_ADDR *function_address_p)
+{
+  error (_("GDB cannot resolve STT_GNU_IFUNC symbol \"%s\" without "
+          "the ELF support compiled in."),
+        function_name);
+}
+
+/* See elf_gnu_ifunc_resolver_stop for its real implementation.  */
+
+static void
+stub_gnu_ifunc_resolver_stop (struct breakpoint *b)
+{
+  internal_error (__FILE__, __LINE__,
+                 _("elf_gnu_ifunc_resolver_stop cannot be reached."));
+}
+
+/* See elf_gnu_ifunc_resolver_return_stop for its real implementation.  */
+
+static void
+stub_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
+{
+  internal_error (__FILE__, __LINE__,
+                 _("elf_gnu_ifunc_resolver_return_stop cannot be reached."));
+}
+
+/* See elf_gnu_ifunc_fns for its real implementation.  */
+
+static const struct gnu_ifunc_fns stub_gnu_ifunc_fns =
+{
+  stub_gnu_ifunc_resolve_addr,
+  stub_gnu_ifunc_resolve_name,
+  stub_gnu_ifunc_resolver_stop,
+  stub_gnu_ifunc_resolver_return_stop,
+};
+
+/* A placeholder for &elf_gnu_ifunc_fns.  */
+
+const struct gnu_ifunc_fns *gnu_ifunc_fns_p = &stub_gnu_ifunc_fns;
+
 /* Find the minimal symbol named NAME, and return both the minsym
    struct and its objfile.  This only checks the linkage name.  Sets
    *OBJFILE_P and returns the minimal symbol, if it is found.  If it
@@ -770,6 +875,7 @@ prim_record_minimal_symbol (const char *name, CORE_ADDR address,
   switch (ms_type)
     {
     case mst_text:
+    case mst_text_gnu_ifunc:
     case mst_file_text:
     case mst_solib_trampoline:
       section = SECT_OFF_TEXT (objfile);
@@ -1235,7 +1341,8 @@ find_solib_trampoline_target (struct frame_info *frame, CORE_ADDR pc)
     {
       ALL_MSYMBOLS (objfile, msymbol)
       {
-       if (MSYMBOL_TYPE (msymbol) == mst_text
+       if ((MSYMBOL_TYPE (msymbol) == mst_text
+           || MSYMBOL_TYPE (msymbol) == mst_text_gnu_ifunc)
            && strcmp (SYMBOL_LINKAGE_NAME (msymbol),
                       SYMBOL_LINKAGE_NAME (tsymbol)) == 0)
          return SYMBOL_VALUE_ADDRESS (msymbol);
This page took 0.026066 seconds and 4 git commands to generate.