]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Use executable_for_core in dwfl_build_id_find_elf.
authorJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 18 Dec 2013 14:02:19 +0000 (15:02 +0100)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 18 Dec 2013 14:02:19 +0000 (15:02 +0100)
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
libdwfl/ChangeLog
libdwfl/argp-std.c
libdwfl/dwfl_build_id_find_elf.c

index e719df929e04d69840af781672865f3b3eaddee6..b3c2b830ea37f34af8176f432677d47add03078a 100644 (file)
@@ -1,3 +1,10 @@
+2013-12-18  Jan Kratochvil  <jan.kratochvil@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.
+
 2013-12-18  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        unwinder: s390 and s390x
index 322cdf491f1c4ef4bdd2d73705babee74cd61913..cf178eee4a379c574e4672ff8e9a69aecc793372 100644 (file)
@@ -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 =
index 9272c1fdc1e6df4b291fe0ed3d5953e4b361dc2d..a4f03263890defcd221e5daec1f88449cba3d78e 100644 (file)
@@ -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 dwfl_core_file_report was called with a non-NULL executable file
+        name 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)
     {