From 34e2c15681edf0ebb9d81dba8a51a2922e21a38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Stelmach?= Date: Wed, 14 Dec 2016 16:26:54 +0100 Subject: crash-stack: print executable file path Change-Id: Ib5946bcfb5bbad8af7b7bbfc7c8568a3cb3ab207 --- src/crash-stack/crash-stack.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/crash-stack/crash-stack.c b/src/crash-stack/crash-stack.c index a377306..2507055 100644 --- a/src/crash-stack/crash-stack.c +++ b/src/crash-stack/crash-stack.c @@ -792,10 +792,25 @@ void callstack_destructor(Callstack *callstack) fprintf(outputfile, "End of Call Stack\n"); } +/** + * @brief Print full path of executable file + */ +static void __crash_stack_print_exe(FILE* outputfile, pid_t pid) +{ + char file_path[PATH_MAX]; + char link_path[PATH_MAX]; + + snprintf(link_path, PATH_MAX, "/proc/%d/exe", pid); + if (readlink(link_path, file_path, PATH_MAX) == -1) { + return; + } + fprintf(outputfile, "Executable File Path: %s\n", file_path); +} + /** * @brief Print thread information * - * @param outputfile File handle for printing report. + * @param outputfile File handle for printing report * @param pid PID of the inspected process * @param tid TID of the inspected thread */ @@ -927,6 +942,9 @@ int main(int argc, char **argv) dwfl_getmodules(dwfl, __module_callback, &mappings, 0); Elf_Data *notes = 0; + /* Executable File Path */ + __crash_stack_print_exe(outputfile, pid); + /* Now, get registers */ if (pid > 1) { if (-1 == __get_signal_ptrace(pid)) -- cgit v1.2.3