This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch 2/4] Provide __libdwfl_module_getsym to get dwfl_file *


Hi Mark,

jankratochvil/xauxfile-filep

it is either a possible cleanup of [patch 1/4] but definitely a pre-requisite
for [patch 4/4].


Thanks,
Jan

commit ff9c14003f5785e6f021cff6ddf18e3f0564f4d5
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Wed Nov 6 21:08:25 2013 +0100

    Provide __libdwfl_module_getsym to get dwfl_file *
    
    libdwfl/
    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.
    
    Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>

diff --git a/libdwfl/dwfl_module_addrsym.c b/libdwfl/dwfl_module_addrsym.c
index 3d19943..d9eb0a2 100644
--- a/libdwfl/dwfl_module_addrsym.c
+++ b/libdwfl/dwfl_module_addrsym.c
@@ -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
diff --git a/libdwfl/dwfl_module_getsym.c b/libdwfl/dwfl_module_getsym.c
index 07127b7..0f5dd37 100644
--- a/libdwfl/dwfl_module_getsym.c
+++ b/libdwfl/dwfl_module_getsym.c
@@ -29,8 +29,10 @@
 #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)
diff --git a/libdwfl/libdwflP.h b/libdwfl/libdwflP.h
index 1d4899b..fe30472 100644
--- a/libdwfl/libdwflP.h
+++ b/libdwfl/libdwflP.h
@@ -339,6 +339,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;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]