Provide __libdwfl_module_getsym to get dwfl_file *
authorJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 13 Nov 2013 19:00:56 +0000 (20:00 +0100)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 13 Nov 2013 19:00:56 +0000 (20:00 +0100)
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
libdwfl/ChangeLog
libdwfl/dwfl_module_addrsym.c
libdwfl/dwfl_module_getsym.c
libdwfl/libdwflP.h

index 282f011..95e3cd7 100644 (file)
@@ -1,3 +1,14 @@
+2013-11-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       Provide __libdwfl_module_getsym to get dwfl_file *.
+       * dwfl_module_addrsym.c (dwfl_module_addrsym) (i_to_symfile): Remove.
+       (dwfl_module_addrsym) (search_table): New variable file.  Use
+       __libdwfl_module_getsym.  Use file.
+       * dwfl_module_getsym.c (dwfl_module_getsym): Rename to ...
+       (__libdwfl_module_getsym): ... here.  Add parameter filep.  Set it.
+       (dwfl_module_getsym): New wrapper.
+       * libdwflP.h (__libdwfl_module_getsym): New declaration.
+
 2013-11-13  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        Fix dwfl_module_addrsym for minidebuginfo.
index 3d19943..d9eb0a2 100644 (file)
@@ -86,20 +86,6 @@ dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
   /* Keep track of the lowest address a relevant sizeless symbol could have.  */
   GElf_Addr min_label = 0;
 
-  inline struct dwfl_file *i_to_symfile (int ndx)
-    {
-      int skip_aux_zero = (mod->syments > 0 && mod->aux_syments > 0) ? 1 : 0;
-      if (ndx < mod->first_global)
-       return mod->symfile;    // main symbol table (locals).
-      else if (ndx < mod->first_global + mod->aux_first_global - skip_aux_zero)
-       return &mod->aux_sym;   // aux symbol table (locals).
-      else if ((size_t) ndx
-              < mod->syments + mod->aux_first_global - skip_aux_zero)
-       return mod->symfile;    // main symbol table (globals).
-      else
-       return &mod->aux_sym;   // aux symbol table (globals).
-    }
-
   /* Look through the symbol table for a matching symbol.  */
   inline void search_table (int start, int end)
     {
@@ -107,7 +93,9 @@ dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
        {
          GElf_Sym sym;
          GElf_Word shndx;
-         const char *name = INTUSE(dwfl_module_getsym) (mod, i, &sym, &shndx);
+         struct dwfl_file *file;
+         const char *name = __libdwfl_module_getsym (mod, i, &sym, &shndx,
+                                                     &file);
          if (name != NULL && name[0] != '\0'
              && sym.st_shndx != SHN_UNDEF
              && sym.st_value <= addr
@@ -152,7 +140,7 @@ dwfl_module_addrsym (Dwfl_Module *mod, GElf_Addr addr,
                        }
                      else if (closest_name == NULL
                               && sym.st_value >= min_label
-                              && same_section (&sym, i_to_symfile (i), shndx))
+                              && same_section (&sym, file, shndx))
                        {
                          /* Handwritten assembly symbols sometimes have no
                             st_size.  If no symbol with proper size includes
index 07127b7..0f5dd37 100644 (file)
 #include "libdwflP.h"
 
 const char *
-dwfl_module_getsym (Dwfl_Module *mod, int ndx,
-                   GElf_Sym *sym, GElf_Word *shndxp)
+internal_function
+__libdwfl_module_getsym (Dwfl_Module *mod, int ndx,
+                        GElf_Sym *sym, GElf_Word *shndxp,
+                        struct dwfl_file **filep)
 {
   if (unlikely (mod == NULL))
     return NULL;
@@ -150,6 +152,15 @@ dwfl_module_getsym (Dwfl_Module *mod, int ndx,
       __libdwfl_seterrno (DWFL_E_BADSTROFF);
       return NULL;
     }
+  if (filep)
+    *filep = file;
   return (const char *) symstrdata->d_buf + sym->st_name;
 }
+
+const char *
+dwfl_module_getsym (Dwfl_Module *mod, int ndx,
+                   GElf_Sym *sym, GElf_Word *shndxp)
+{
+  return __libdwfl_module_getsym (mod, ndx, sym, shndxp, NULL);
+}
 INTDEF (dwfl_module_getsym)
index ff48813..0c862b3 100644 (file)
@@ -421,6 +421,13 @@ extern Dwfl_Error __libdwfl_relocate_value (Dwfl_Module *mod, Elf *elf,
                                            GElf_Addr *value)
      internal_function;
 
+/* See dwfl_module_getsym.  *FILEP will be set to the file of *SYM.
+   FILEP can be NULL.  */
+extern const char *__libdwfl_module_getsym (Dwfl_Module *mod, int ndx,
+                                           GElf_Sym *sym, GElf_Word *shndxp,
+                                           struct dwfl_file **filep)
+     internal_function;
+
 
 /* Ensure that MOD->ebl is set up.  */
 extern Dwfl_Error __libdwfl_module_getebl (Dwfl_Module *mod) internal_function;