[From nobody Tue Dec 17 20:32:48 2013 From: Jan Kratochvil <jan.kratochvil@redhat.com> Date: Tue, 17 Dec 2013 21:30:16 +0100 Subject: [PATCH] Use executable_for_core in dwfl_build_id_find_elf. libdwfl/ 2013-12-17 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. Signed-off-by: Jan Kratochvil <jan.kratochvil@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 ]