Hi Mark,

I believe if executable_for_core is set it means the Dwfl is really for a core
file and the executable has been explicitly set by the user.  Therefore it
should override/precede any searches.

I was experimenting also with replacing [exe]/[pie] by executable_for_core but
I do not see any end-user visible benefit from it and it is also an unrelated
patch.

OK for check-in?


Thanks,
Jan
--- Begin Message ---
libdwfl/
2013-12-17  Jan Kratochvil  <jan.kratoch...@redhat.com>

        * argp-std.c (offline_find_elf): Remove.
        (offline_callbacks): Use dwfl_build_id_find_elf instead.
        * dwfl_build_id_find_elf.c (dwfl_build_id_find_elf): Move here the code
        removed above.

Signed-off-by: Jan Kratochvil <jan.kratoch...@redhat.com>
---
 libdwfl/argp-std.c               | 28 +---------------------------
 libdwfl/dwfl_build_id_find_elf.c | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/libdwfl/argp-std.c b/libdwfl/argp-std.c
index 322cdf4..cf178ee 100644
--- a/libdwfl/argp-std.c
+++ b/libdwfl/argp-std.c
@@ -60,32 +60,6 @@ static const struct argp_option options[] =
   { NULL, 0, NULL, 0, NULL, 0 }
 };
 
-/* Wrapper to provide proper FILE_NAME for -e|--executable.  */
-static int
-offline_find_elf (Dwfl_Module *mod, void **userdata, const char *modname,
-                 Dwarf_Addr base, char **file_name, Elf **elfp)
-{
-  if (modname != NULL && (strcmp (modname, "[exe]") == 0
-                         || strcmp (modname, "[pie]") == 0)
-      && mod->dwfl->executable_for_core)
-    {
-      /* When both --core and --executable are given in whatever order
-        dwfl_core_file_report is called first and this callback will replace
-        the Dwfl_Module main.name with the recorded --executable file when the
-        modname is [exe] or [pie] (which then triggers opening and reporting
-        of the executable).  */
-      char *e_dup = strdup (mod->dwfl->executable_for_core);
-      if (e_dup)
-       {
-         free (*file_name);
-         *file_name = e_dup;
-         return -1;
-       }
-    }
-  return INTUSE(dwfl_build_id_find_elf) (mod, userdata, modname, base,
-                                         file_name, elfp);
-}
-
 static char *debuginfo_path;
 
 static const Dwfl_Callbacks offline_callbacks =
@@ -96,7 +70,7 @@ static const Dwfl_Callbacks offline_callbacks =
     .section_address = INTUSE(dwfl_offline_section_address),
 
     /* We use this table for core files too.  */
-    .find_elf = offline_find_elf,
+    .find_elf = INTUSE(dwfl_build_id_find_elf),
   };
 
 static const Dwfl_Callbacks proc_callbacks =
diff --git a/libdwfl/dwfl_build_id_find_elf.c b/libdwfl/dwfl_build_id_find_elf.c
index 9272c1f..86e97d0 100644
--- a/libdwfl/dwfl_build_id_find_elf.c
+++ b/libdwfl/dwfl_build_id_find_elf.c
@@ -116,6 +116,23 @@ dwfl_build_id_find_elf (Dwfl_Module *mod,
                        char **file_name, Elf **elfp)
 {
   *elfp = NULL;
+  if (modname != NULL && mod->dwfl->executable_for_core != NULL
+      && (strcmp (modname, "[exe]") == 0 || strcmp (modname, "[pie]") == 0))
+    {
+      /* When both --core and --executable are given dwfl_core_file_report is
+         called first and this callback will replace the Dwfl_Module main.name
+         with the recorded --executable file when the modname is [exe] or [pie]
+         (which then triggers opening and reporting of the executable).  */
+      int fd = open64 (mod->dwfl->executable_for_core, O_RDONLY);
+      if (fd >= 0)
+       {
+         *file_name = strdup (mod->dwfl->executable_for_core);
+         if (*file_name != NULL)
+           return fd;
+         else
+           close (fd);
+       }
+    }
   int fd = __libdwfl_open_by_build_id (mod, false, file_name);
   if (fd >= 0)
     {
-- 
1.8.3.1

--- End Message ---

Reply via email to